Working in part placement

This commit is contained in:
Sebastian Hartte
2020-07-01 21:27:37 +02:00
parent 8e031ca8d6
commit f2e3d81fd7
134 changed files with 1553 additions and 1494 deletions
-457
View File
@@ -1,457 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.parts;
import java.io.IOException;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.Optional;
import java.util.Random;
import com.google.common.base.Preconditions;
import net.fabricmc.api.EnvType;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.util.crash.CrashReportSection;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.util.math.Direction;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.text.Text;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.fabricmc.api.Environment;
import alexiil.mc.lib.attributes.item.FixedItemInv;
import appeng.api.AEApi;
import appeng.api.config.Upgrades;
import appeng.api.definitions.IDefinitions;
import appeng.api.implementations.IUpgradeableHost;
import appeng.api.implementations.items.IMemoryCard;
import appeng.api.implementations.items.MemoryCardMessages;
import appeng.api.networking.IGridNode;
import appeng.api.networking.security.IActionHost;
import appeng.api.parts.BusSupport;
import appeng.api.parts.IPart;
import appeng.api.parts.IPartCollisionHelper;
import appeng.api.parts.IPartHost;
import appeng.api.parts.PartItemStack;
import appeng.api.util.AECableType;
import appeng.api.util.AEColor;
import appeng.api.util.AEPartLocation;
import appeng.api.util.DimensionalCoord;
import appeng.api.util.IConfigManager;
import appeng.helpers.ICustomNameObject;
import appeng.helpers.IPriorityHost;
import appeng.me.helpers.AENetworkProxy;
import appeng.me.helpers.IGridProxyable;
import appeng.parts.networking.CablePart;
import appeng.tile.inventory.AppEngInternalAEInventory;
import appeng.util.Platform;
import appeng.util.SettingsFrom;
public abstract class AEBasePart implements IPart, IGridProxyable, IActionHost, IUpgradeableHost, ICustomNameObject {
private final AENetworkProxy proxy;
private final ItemStack is;
private BlockEntity tile = null;
private IPartHost host = null;
private AEPartLocation side = null;
public AEBasePart(final ItemStack is) {
Preconditions.checkNotNull(is);
this.is = is;
this.proxy = new AENetworkProxy(this, "part", is, this instanceof CablePart);
this.proxy.setValidSides(EnumSet.noneOf(Direction.class));
}
public IPartHost getHost() {
return this.host;
}
@Override
public IGridNode getGridNode(final AEPartLocation dir) {
return this.proxy.getNode();
}
@Override
public AECableType getCableConnectionType(final AEPartLocation dir) {
return AECableType.GLASS;
}
@Override
public void securityBreak() {
if (this.getItemStack().getCount() > 0 && this.getGridNode() != null) {
final List<ItemStack> items = new ArrayList<>();
items.add(this.is.copy());
this.host.removePart(this.side, false);
Platform.spawnDrops(this.tile.getWorld(), this.tile.getPos(), items);
this.is.setCount(0);
}
}
protected AEColor getColor() {
if (this.host == null) {
return AEColor.TRANSPARENT;
}
return this.host.getColor();
}
@Override
public void getBoxes(final IPartCollisionHelper bch) {
}
@Override
public int getInstalledUpgrades(final Upgrades u) {
return 0;
}
@Override
public BlockEntity getTile() {
return this.tile;
}
@Override
public AENetworkProxy getProxy() {
return this.proxy;
}
@Override
public DimensionalCoord getLocation() {
return new DimensionalCoord(this.tile);
}
@Override
public void gridChanged() {
}
@Override
public IGridNode getActionableNode() {
return this.proxy.getNode();
}
public void saveChanges() {
this.host.markForSave();
}
@Override
public Text getCustomInventoryName() {
return this.getItemStack().getName();
}
@Override
public boolean hasCustomInventoryName() {
return this.getItemStack().hasCustomName();
}
@Override
public void addEntityCrashInfo(final CrashReportSection section) {
section.add("Part Side", this.getSide());
}
@Override
public ItemStack getItemStack(final PartItemStack type) {
if (type == PartItemStack.NETWORK) {
final ItemStack copy = this.is.copy();
copy.setTag(null);
return copy;
}
return this.is;
}
@Override
public boolean isSolid() {
return false;
}
@Override
public void onneighborUpdate(BlockView w, BlockPos pos, BlockPos neighbor) {
}
@Override
public boolean canConnectRedstone() {
return false;
}
@Override
public void readFromNBT(final CompoundTag data) {
this.proxy.readFromNBT(data);
}
@Override
public void writeToNBT(final CompoundTag data) {
this.proxy.writeToNBT(data);
}
@Override
public int isProvidingStrongPower() {
return 0;
}
@Override
public int isProvidingWeakPower() {
return 0;
}
@Override
public void writeToStream(final PacketByteBuf data) throws IOException {
}
@Override
public boolean readFromStream(final PacketByteBuf data) throws IOException {
return false;
}
@Override
public IGridNode getGridNode() {
return this.proxy.getNode();
}
@Override
public void onEntityCollision(final Entity entity) {
}
@Override
public void removeFromWorld() {
this.proxy.remove();
}
@Override
public void addToWorld() {
this.proxy.onReady();
}
@Override
public void setPartHostInfo(final AEPartLocation side, final IPartHost host, final BlockEntity tile) {
this.setSide(side);
this.tile = tile;
this.host = host;
}
@Override
public IGridNode getExternalFacingNode() {
return null;
}
@Override
@Environment(EnvType.CLIENT)
public void randomDisplayTick(final World world, final BlockPos pos, final Random r) {
}
@Override
public int getLightLevel() {
return 0;
}
@Override
public void getDrops(final List<ItemStack> drops, final boolean wrenched) {
}
@Override
public float getCableConnectionLength(AECableType cable) {
return 3;
}
@Override
public boolean isLadder(final LivingEntity entity) {
return false;
}
@Override
public IConfigManager getConfigManager() {
return null;
}
@Override
public FixedItemInv getInventoryByName(final String name) {
return null;
}
/**
* depending on the from, different settings will be accepted, don't call this
* with null
*
* @param from source of settings
* @param compound compound of source
*/
private void uploadSettings(final SettingsFrom from, final CompoundTag compound) {
if (compound != null) {
final IConfigManager cm = this.getConfigManager();
if (cm != null) {
cm.readFromNBT(compound);
}
}
if (this instanceof IPriorityHost) {
final IPriorityHost pHost = (IPriorityHost) this;
pHost.setPriority(compound.getInt("priority"));
}
final FixedItemInv inv = this.getInventoryByName("config");
if (inv instanceof AppEngInternalAEInventory) {
final AppEngInternalAEInventory target = (AppEngInternalAEInventory) inv;
final AppEngInternalAEInventory tmp = new AppEngInternalAEInventory(null, target.getSlotCount());
tmp.readFromNBT(compound, "config");
for (int x = 0; x < tmp.getSlotCount(); x++) {
target.setInvStack(x, tmp.getInvStack(x));
}
}
}
/**
* null means nothing to store...
*
* @param from source of settings
*
* @return compound of source
*/
private CompoundTag downloadSettings(final SettingsFrom from) {
final CompoundTag output = new CompoundTag();
final IConfigManager cm = this.getConfigManager();
if (cm != null) {
cm.writeToNBT(output);
}
if (this instanceof IPriorityHost) {
final IPriorityHost pHost = (IPriorityHost) this;
output.putInt("priority", pHost.getPriority());
}
final FixedItemInv inv = this.getInventoryByName("config");
if (inv instanceof AppEngInternalAEInventory) {
((AppEngInternalAEInventory) inv).writeToNBT(output, "config");
}
return output.isEmpty() ? null : output;
}
public boolean useStandardMemoryCard() {
return true;
}
private boolean useMemoryCard(final PlayerEntity player) {
final ItemStack memCardIS = player.inventory.getCurrentItem();
if (!memCardIS.isEmpty() && this.useStandardMemoryCard() && memCardIS.getItem() instanceof IMemoryCard) {
final IMemoryCard memoryCard = (IMemoryCard) memCardIS.getItem();
ItemStack is = this.getItemStack(PartItemStack.NETWORK);
// Blocks and parts share the same soul!
final IDefinitions definitions = AEApi.instance().definitions();
if (definitions.parts().iface().isSameAs(is)) {
Optional<ItemStack> iface = definitions.blocks().iface().maybeStack(1);
if (iface.isPresent()) {
is = iface.get();
}
}
final String name = is.getTranslationKey();
if (player.isInSneakingPose()) {
final CompoundTag data = this.downloadSettings(SettingsFrom.MEMORY_CARD);
if (data != null) {
memoryCard.setMemoryCardContents(memCardIS, name, data);
memoryCard.notifyUser(player, MemoryCardMessages.SETTINGS_SAVED);
}
} else {
final String storedName = memoryCard.getSettingsName(memCardIS);
final CompoundTag data = memoryCard.getData(memCardIS);
if (name.equals(storedName)) {
this.uploadSettings(SettingsFrom.MEMORY_CARD, data);
memoryCard.notifyUser(player, MemoryCardMessages.SETTINGS_LOADED);
} else {
memoryCard.notifyUser(player, MemoryCardMessages.INVALID_MACHINE);
}
}
return true;
}
return false;
}
@Override
public final boolean onActivate(final PlayerEntity player, final Hand hand, final Vec3d pos) {
if (this.useMemoryCard(player)) {
return true;
}
return this.onPartActivate(player, hand, pos);
}
@Override
public final boolean onShiftActivate(final PlayerEntity player, final Hand hand, final Vec3d pos) {
if (this.useMemoryCard(player)) {
return true;
}
return this.onPartShiftActivate(player, hand, pos);
}
public boolean onPartActivate(final PlayerEntity player, final Hand hand, final Vec3d pos) {
return false;
}
public boolean onPartShiftActivate(final PlayerEntity player, final Hand hand, final Vec3d pos) {
return false;
}
@Override
public void onPlacement(final PlayerEntity player, final Hand hand, final ItemStack held,
final AEPartLocation side) {
this.proxy.setOwner(player);
}
@Override
public boolean canBePlacedOn(final BusSupport what) {
return what == BusSupport.CABLE;
}
@Override
public boolean requireDynamicRender() {
return false;
}
public AEPartLocation getSide() {
return this.side;
}
private void setSide(final AEPartLocation side) {
this.side = side;
}
public ItemStack getItemStack() {
return this.is;
}
}
@@ -1,153 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.parts;
import java.util.List;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Direction;
import appeng.api.parts.IPartCollisionHelper;
import appeng.api.util.AEPartLocation;
public class BusCollisionHelper implements IPartCollisionHelper {
private final List<Box> boxes;
private final Direction x;
private final Direction y;
private final Direction z;
private final boolean isVisual;
public BusCollisionHelper(final List<Box> boxes, final Direction x, final Direction y, final Direction z,
final boolean visual) {
this.boxes = boxes;
this.x = x;
this.y = y;
this.z = z;
this.isVisual = visual;
}
public BusCollisionHelper(final List<Box> boxes, final AEPartLocation s, final boolean visual) {
this.boxes = boxes;
this.isVisual = visual;
switch (s) {
case DOWN:
this.x = Direction.EAST;
this.y = Direction.NORTH;
this.z = Direction.DOWN;
break;
case UP:
this.x = Direction.EAST;
this.y = Direction.SOUTH;
this.z = Direction.UP;
break;
case EAST:
this.x = Direction.SOUTH;
this.y = Direction.UP;
this.z = Direction.EAST;
break;
case WEST:
this.x = Direction.NORTH;
this.y = Direction.UP;
this.z = Direction.WEST;
break;
case NORTH:
this.x = Direction.WEST;
this.y = Direction.UP;
this.z = Direction.NORTH;
break;
case SOUTH:
this.x = Direction.EAST;
this.y = Direction.UP;
this.z = Direction.SOUTH;
break;
case INTERNAL:
default:
this.x = Direction.EAST;
this.y = Direction.UP;
this.z = Direction.SOUTH;
break;
}
}
@Override
public void addBox(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) {
minX /= 16.0;
minY /= 16.0;
minZ /= 16.0;
maxX /= 16.0;
maxY /= 16.0;
maxZ /= 16.0;
double aX = minX * this.x.getOffsetX() + minY * this.y.getOffsetX() + minZ * this.z.getOffsetX();
double aY = minX * this.x.getOffsetY() + minY * this.y.getOffsetY() + minZ * this.z.getOffsetY();
double aZ = minX * this.x.getOffsetZ() + minY * this.y.getOffsetZ() + minZ * this.z.getOffsetZ();
double bX = maxX * this.x.getOffsetX() + maxY * this.y.getOffsetX() + maxZ * this.z.getOffsetX();
double bY = maxX * this.x.getOffsetY() + maxY * this.y.getOffsetY() + maxZ * this.z.getOffsetY();
double bZ = maxX * this.x.getOffsetZ() + maxY * this.y.getOffsetZ() + maxZ * this.z.getOffsetZ();
if (this.x.getOffsetX() + this.y.getOffsetX() + this.z.getOffsetX() < 0) {
aX += 1;
bX += 1;
}
if (this.x.getOffsetY() + this.y.getOffsetY() + this.z.getOffsetY() < 0) {
aY += 1;
bY += 1;
}
if (this.x.getOffsetZ() + this.y.getOffsetZ() + this.z.getOffsetZ() < 0) {
aZ += 1;
bZ += 1;
}
minX = Math.min(aX, bX);
minY = Math.min(aY, bY);
minZ = Math.min(aZ, bZ);
maxX = Math.max(aX, bX);
maxY = Math.max(aY, bY);
maxZ = Math.max(aZ, bZ);
this.boxes.add(new Box(minX, minY, minZ, maxX, maxY, maxZ));
}
@Override
public Direction getWorldX() {
return this.x;
}
@Override
public Direction getWorldY() {
return this.y;
}
@Override
public Direction getWorldZ() {
return this.z;
}
@Override
public boolean isBBCollision() {
return !this.isVisual;
}
}
File diff suppressed because it is too large Load Diff
@@ -1,121 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.parts;
import javax.annotation.Nullable;
import appeng.api.implementations.parts.ICablePart;
import appeng.api.parts.IFacadePart;
import appeng.api.parts.IPart;
import appeng.api.util.AEPartLocation;
/**
* Thin data storage to optimize memory usage for cables.
*/
public class CableBusStorage {
private ICablePart center;
private IPart[] sides;
private IFacadePart[] facades;
protected ICablePart getCenter() {
return this.center;
}
protected void setCenter(final ICablePart center) {
this.center = center;
}
protected IPart getSide(final AEPartLocation side) {
final int x = side.ordinal();
if (this.sides != null && this.sides.length > x) {
return this.sides[x];
}
return null;
}
protected void setSide(final AEPartLocation side, final IPart part) {
final int x = side.ordinal();
if (this.sides != null && this.sides.length > x && part == null) {
this.sides[x] = null;
this.sides = this.decrement(this.sides, true);
} else if (part != null) {
this.sides = this.expand(this.sides, x, true);
this.sides[x] = part;
}
}
private <T> T[] shrink(final T[] in, final boolean parts) {
int newSize = -1;
for (int x = 0; x < in.length; x++) {
if (in[x] != null) {
newSize = x;
}
}
if (newSize == -1) {
return null;
}
newSize++;
if (newSize == in.length) {
return in;
}
final T[] newArray = (T[]) (parts ? new IPart[newSize] : new IFacadePart[newSize]);
System.arraycopy(in, 0, newArray, 0, newSize);
return newArray;
}
private <T> T[] grow(final T[] in, final int newValue, final boolean parts) {
if (in != null && in.length > newValue) {
return in;
}
final int newSize = newValue + 1;
final T[] newArray = (T[]) (parts ? new IPart[newSize] : new IFacadePart[newSize]);
if (in != null) {
System.arraycopy(in, 0, newArray, 0, in.length);
}
return newArray;
}
public IFacadePart getFacade(final int x) {
if (this.facades != null && this.facades.length > x) {
return this.facades[x];
}
return null;
}
public void setFacade(final int x, @Nullable final IFacadePart facade) {
if (this.facades != null && this.facades.length > x && facade == null) {
this.facades[x] = null;
this.facades = this.decrement(this.facades, false);
} else {
this.facades = this.expand(this.facades, x, false);
this.facades[x] = facade;
}
}
}
@@ -1,71 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.parts;
import java.util.EnumSet;
import java.util.Random;
import net.fabricmc.api.EnvType;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.Direction;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.fabricmc.api.Environment;
import appeng.api.parts.SelectedPart;
import appeng.api.util.AEColor;
import appeng.client.render.cablebus.CableBusRenderState;
public interface ICableBusContainer {
int isProvidingStrongPower(Direction opposite);
int isProvidingWeakPower(Direction opposite);
boolean canConnectRedstone(EnumSet<Direction> of);
void onEntityCollision(Entity e);
boolean activate(PlayerEntity player, Hand hand, Vec3d vecFromPool);
boolean clicked(PlayerEntity player, Hand hand, Vec3d hitVec);
void onneighborUpdate(BlockView w, BlockPos pos, BlockPos neighbor);
boolean isEmpty();
SelectedPart selectPart(Vec3d v3);
boolean recolourBlock(Direction side, AEColor colour, PlayerEntity who);
boolean isLadder(LivingEntity entity);
@Environment(EnvType.CLIENT)
void randomDisplayTick(World world, BlockPos pos, Random r);
int getLightValue();
CableBusRenderState getRenderState();
}
@@ -1,110 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.parts;
import java.util.EnumSet;
import java.util.Random;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.Direction;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import appeng.api.parts.SelectedPart;
import appeng.api.util.AEColor;
import appeng.client.render.cablebus.CableBusRenderState;
public class NullCableBusContainer implements ICableBusContainer {
@Override
public int isProvidingStrongPower(final Direction opposite) {
return 0;
}
@Override
public int isProvidingWeakPower(final Direction opposite) {
return 0;
}
@Override
public boolean canConnectRedstone(final EnumSet<Direction> of) {
return false;
}
@Override
public void onEntityCollision(final Entity e) {
}
@Override
public boolean activate(final PlayerEntity player, final Hand hand, final Vec3d vecFromPool) {
return false;
}
@Override
public void onneighborUpdate(BlockView w, BlockPos pos, BlockPos neighbor) {
}
@Override
public boolean isEmpty() {
return true;
}
@Override
public SelectedPart selectPart(final Vec3d v3) {
return new SelectedPart();
}
@Override
public boolean recolourBlock(final Direction side, final AEColor colour, final PlayerEntity who) {
return false;
}
@Override
public boolean isLadder(final LivingEntity entity) {
return false;
}
@Override
public void randomDisplayTick(final World world, final BlockPos pos, final Random r) {
}
@Override
public int getLightValue() {
return 0;
}
@Override
public CableBusRenderState getRenderState() {
return new CableBusRenderState();
}
@Override
public boolean clicked(PlayerEntity player, Hand hand, Vec3d hitVec) {
return false;
}
}
-69
View File
@@ -1,69 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.parts;
import java.util.List;
import com.google.common.collect.ImmutableList;
import net.minecraft.util.Identifier;
import appeng.api.parts.IPartModel;
public class PartModel implements IPartModel {
private final boolean isSolid;
private final List<Identifier> resources;
public PartModel(Identifier resource) {
this(true, resource);
}
public PartModel(Identifier... resources) {
this(true, resources);
}
public PartModel(boolean isSolid, Identifier resource) {
this(isSolid, ImmutableList.of(resource));
}
public PartModel(boolean isSolid, Identifier... resources) {
this(isSolid, ImmutableList.copyOf(resources));
}
public PartModel(List<Identifier> resources) {
this(true, resources);
}
public PartModel(boolean isSolid, List<Identifier> resources) {
this.isSolid = isSolid;
this.resources = resources;
}
@Override
public boolean requireCableConnection() {
return this.isSolid;
}
@Override
public List<Identifier> getModels() {
return this.resources;
}
}
@@ -1,421 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.parts;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.client.MinecraftClient;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.BlockItem;
import net.minecraft.item.DirectionalPlaceContext;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsageContext;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.util.ActionResult;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.Direction;
import net.minecraft.util.Hand;
import net.minecraft.sound.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.RayTraceContext;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import appeng.api.AEApi;
import appeng.api.definitions.IBlockDefinition;
import appeng.api.definitions.IItems;
import appeng.api.parts.IFacadePart;
import appeng.api.parts.IPartHost;
import appeng.api.parts.IPartItem;
import appeng.api.parts.PartItemStack;
import appeng.api.parts.SelectedPart;
import appeng.api.util.AEPartLocation;
import appeng.api.util.DimensionalCoord;
import appeng.core.AppEng;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.ClickPacket;
import appeng.core.sync.packets.PartPlacementPacket;
import appeng.facade.IFacadeItem;
import appeng.util.LookDirection;
import appeng.util.Platform;
public class PartPlacement {
private static float eyeHeight = 0.0f;
private final ThreadLocal<Object> placing = new ThreadLocal<>();
private boolean wasCanceled = false;
public static ActionResult place(final ItemStack held, final BlockPos pos, Direction side,
final PlayerEntity player, final Hand hand, final World world, PlaceType pass, final int depth) {
if (depth > 3) {
return ActionResult.FAIL;
}
// FIXME: This was changed alot.
final LookDirection dir = Platform.getPlayerRay(player);
RayTraceContext rtc = new RayTraceContext(dir.getA(), dir.getB(), RayTraceContext.ShapeType.OUTLINE,
RayTraceContext.FluidHandling.NONE, player);
final BlockHitResult mop = world.rayTrace(rtc);
ItemPlacementContext useContext = new ItemPlacementContext(new ItemUsageContext(player, hand, mop));
if (!held.isEmpty() && Platform.isWrench(player, held, pos) && player.isInSneakingPose()) {
if (!Platform.hasPermissions(new DimensionalCoord(world, pos), player)) {
return ActionResult.FAIL;
}
final BlockEntity tile = world.getBlockEntity(pos);
IPartHost host = null;
if (tile instanceof IPartHost) {
host = (IPartHost) tile;
}
if (host != null) {
if (!world.isClient) {
if (mop.getType() == HitResult.Type.BLOCK) {
final List<ItemStack> is = new ArrayList<>();
final SelectedPart sp = selectPart(player, host,
mop.getPos().add(-mop.getPos().getX(), -mop.getPos().getY(), -mop.getPos().getZ()));
if (sp.part != null) {
is.add(sp.part.getItemStack(PartItemStack.WRENCH));
sp.part.getDrops(is, true);
host.removePart(sp.side, false);
}
if (sp.facade != null) {
is.add(sp.facade.getItemStack());
host.getFacadeContainer().removeFacade(host, sp.side);
Platform.notifyBlocksOfNeighbors(world, pos);
}
if (host.isEmpty()) {
host.cleanup();
}
if (!is.isEmpty()) {
Platform.spawnDrops(world, pos, is);
}
}
} else {
player.swingHand(hand);
NetworkHandler.instance()
.sendToServer(new PartPlacementPacket(pos, side, getEyeOffset(player), hand));
}
return ActionResult.SUCCESS;
}
return ActionResult.FAIL;
}
BlockEntity tile = world.getBlockEntity(pos);
IPartHost host = null;
if (tile instanceof IPartHost) {
host = (IPartHost) tile;
}
if (!held.isEmpty()) {
final IFacadePart fp = isFacade(held, AEPartLocation.fromFacing(side));
if (fp != null) {
if (host != null) {
if (!world.isClient) {
if (host.getPart(AEPartLocation.INTERNAL) == null) {
return ActionResult.FAIL;
}
if (host.canAddPart(held, AEPartLocation.fromFacing(side))) {
if (host.getFacadeContainer().addFacade(fp)) {
host.markForSave();
host.markForUpdate();
if (!player.isCreative()) {
held.increment(-1);
;
if (held.getCount() == 0) {
player.inventory.mainInventory.set(player.inventory.currentItem,
ItemStack.EMPTY);
MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(player, held, hand));
}
}
return ActionResult.CONSUME;
}
}
} else {
player.swingHand(hand);
NetworkHandler.instance()
.sendToServer(new PartPlacementPacket(pos, side, getEyeOffset(player), hand));
return ActionResult.SUCCESS;
}
}
return ActionResult.FAIL;
}
}
if (held.isEmpty()) {
if (host != null && player.isInSneakingPose() && world.isAirBlock(pos)) {
if (mop.getType() == HitResult.Type.BLOCK) {
Vec3d hitVec = mop.getPos().add(-mop.getPos().getX(), -mop.getPos().getY(),
-mop.getPos().getZ());
final SelectedPart sPart = selectPart(player, host, hitVec);
if (sPart != null && sPart.part != null) {
if (sPart.part.onShiftActivate(player, hand, hitVec)) {
if (world.isClient) {
NetworkHandler.instance()
.sendToServer(new PartPlacementPacket(pos, side, getEyeOffset(player), hand));
}
return ActionResult.SUCCESS;
}
}
}
}
}
if (held.isEmpty() || !(held.getItem() instanceof IPartItem)) {
return ActionResult.PASS;
}
BlockPos te_pos = pos;
final IBlockDefinition multiPart = AEApi.instance().definitions().blocks().multiPart();
if (host == null && pass == PlaceType.PLACE_ITEM) {
Direction offset = null;
BlockState blockState = world.getBlockState(pos);
// FIXME isReplacable on the block state allows for more control, but requires
// an item use context
if (!blockState.isAir(world, pos) && !blockState.isReplaceable(useContext)) {
offset = side;
if (Platform.isServer()) {
side = side.getOpposite();
}
}
te_pos = offset == null ? pos : pos.offset(offset);
tile = world.getBlockEntity(te_pos);
if (tile instanceof IPartHost) {
host = (IPartHost) tile;
}
final Optional<ItemStack> maybeMultiPartStack = multiPart.maybeStack(1);
final Optional<Block> maybeMultiPartBlock = multiPart.maybeBlock();
final Optional<BlockItem> maybeMultiPartBlockItem = multiPart.maybeBlockItem();
final boolean hostIsNotPresent = host == null;
final boolean multiPartPresent = maybeMultiPartBlock.isPresent() && maybeMultiPartStack.isPresent()
&& maybeMultiPartBlockItem.isPresent();
BlockState multiPartBlockState = maybeMultiPartBlock.get().getDefaultState();
final boolean canMultiPartBePlaced = multiPartBlockState.canPlaceAt(world, te_pos);
// We cannot override the item stack of normal use context, so we use this hack
ItemPlacementContext mpUseCtx = new ItemPlacementContext(
new DirectionalPlaceContext(world, te_pos, side, maybeMultiPartStack.get(), side));
// FIXME: This is super-fishy and all needs to be re-checked. what does this
// even do???
if (hostIsNotPresent && multiPartPresent && canMultiPartBePlaced
&& maybeMultiPartBlockItem.get().place(mpUseCtx) == ActionResult.SUCCESS) {
if (!world.isClient) {
tile = world.getBlockEntity(te_pos);
if (tile instanceof IPartHost) {
host = (IPartHost) tile;
}
pass = PlaceType.INTERACT_SECOND_PASS;
} else {
player.swingHand(hand);
NetworkHandler.instance()
.sendToServer(new PartPlacementPacket(pos, side, getEyeOffset(player), hand));
return ActionResult.SUCCESS;
}
} else if (host != null && !host.canAddPart(held, AEPartLocation.fromFacing(side))) {
return ActionResult.FAIL;
}
}
if (host == null) {
return ActionResult.PASS;
}
if (!host.canAddPart(held, AEPartLocation.fromFacing(side))) {
if (pass == PlaceType.INTERACT_FIRST_PASS || pass == PlaceType.PLACE_ITEM) {
te_pos = pos.offset(side);
final BlockState blkState = world.getBlockState(te_pos);
// FIXME: this is always true (host was de-referenced above)
if (blkState.isAir(world, te_pos) || blkState.isReplaceable(useContext) || host != null) {
return place(held, te_pos, side.getOpposite(), player, hand, world,
pass == PlaceType.INTERACT_FIRST_PASS ? PlaceType.INTERACT_SECOND_PASS
: PlaceType.PLACE_ITEM,
depth + 1);
}
}
return ActionResult.PASS;
}
if (!world.isClient) {
if (mop.getType() != HitResult.Type.MISS) {
final SelectedPart sp = selectPart(player, host,
mop.getPos().add(-mop.getPos().getX(), -mop.getPos().getY(), -mop.getPos().getZ()));
if (sp.part != null) {
if (!player.isInSneakingPose() && sp.part.onActivate(player, hand, mop.getPos())) {
return ActionResult.FAIL;
}
}
}
final DimensionalCoord dc = host.getLocation();
if (!Platform.hasPermissions(dc, player)) {
return ActionResult.FAIL;
}
final AEPartLocation mySide = host.addPart(held, AEPartLocation.fromFacing(side), player, hand);
if (mySide != null) {
multiPart.maybeBlock().ifPresent(multiPartBlock -> {
BlockState blockState = world.getBlockState(pos);
final BlockSoundGroup ss = multiPartBlock.getSoundType(blockState, world, pos, player);
world.playSound(null, pos, ss.getPlaceSound(), SoundCategory.BLOCKS, (ss.getVolume() + 1.0F) / 2.0F,
ss.getPitch() * 0.8F);
});
if (!player.isCreative()) {
held.increment(-1);
if (held.getCount() == 0) {
player.setStackInHand(hand, ItemStack.EMPTY);
MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(player, held, hand));
}
}
}
} else {
player.swingHand(hand);
}
return ActionResult.SUCCESS;
}
private static float getEyeOffset(final PlayerEntity p) {
if (p.world.isClient) {
return Platform.getEyeOffset(p);
}
return getEyeHeight();
}
private static SelectedPart selectPart(final PlayerEntity player, final IPartHost host, final Vec3d pos) {
AppEng.proxy.updateRenderMode(player);
final SelectedPart sp = host.selectPart(pos);
AppEng.proxy.updateRenderMode(null);
return sp;
}
public static IFacadePart isFacade(final ItemStack held, final AEPartLocation side) {
if (held.getItem() instanceof IFacadeItem) {
return ((IFacadeItem) held.getItem()).createPartFromItemStack(held, side);
}
return null;
}
@SubscribeEvent
public void playerInteract(final TickEvent.ClientTickEvent event) {
this.wasCanceled = false;
}
@SubscribeEvent
public void playerInteract(final PlayerInteractEvent event) {
// Only handle the main hand event
if (event.getHand() != Hand.MAIN_HAND) {
return;
}
if (event instanceof PlayerInteractEvent.RightClickEmpty && event.getPlayer().world.isClient) {
// re-check to see if this event was already channeled, cause these two events
// are really stupid...
final HitResult mop = Platform.rayTrace(event.getPlayer(), true, false);
final MinecraftClient mc = MinecraftClient.getInstance();
final float f = 1.0F;
final double d0 = mc.playerController.getBlockReachDistance();
final Vec3d vec3 = mc.getRenderViewEntity().getEyePosition(f);
if (mop instanceof BlockHitResult && mop.getPos().distanceTo(vec3) < d0) {
BlockHitResult brtr = (BlockHitResult) mop;
final World w = event.getEntity().world;
final BlockEntity te = w.getBlockEntity(brtr.getPos());
if (te instanceof IPartHost && this.wasCanceled) {
event.setCanceled(true);
}
} else {
final ItemStack held = event.getPlayer().getStackInHand(event.getHand());
final IItems items = AEApi.instance().definitions().items();
boolean supportedItem = items.memoryCard().isSameAs(held);
supportedItem |= items.colorApplicator().isSameAs(held);
if (event.getPlayer().isInSneakingPose() && !held.isEmpty() && supportedItem) {
NetworkHandler.instance().sendToServer(new ClickPacket(event.getHand()));
}
}
} else if (event instanceof PlayerInteractEvent.RightClickBlock && !event.getPlayer().world.isClient) {
if (this.placing.get() != null) {
return;
}
this.placing.set(event);
final ItemStack held = event.getPlayer().getStackInHand(event.getHand());
if (place(held, event.getPos(), event.getFace(), event.getPlayer(), event.getHand(),
event.getPlayer().world, PlaceType.INTERACT_FIRST_PASS, 0) == ActionResult.SUCCESS) {
event.setCanceled(true);
this.wasCanceled = true;
}
this.placing.set(null);
}
}
private static float getEyeHeight() {
return eyeHeight;
}
public static void setEyeHeight(final float eyeHeight) {
PartPlacement.eyeHeight = eyeHeight;
}
public enum PlaceType {
PLACE_ITEM, INTERACT_FIRST_PASS, INTERACT_SECOND_PASS
}
}
@@ -284,7 +284,7 @@ public class AnnihilationPlanePart extends BasicStatePart implements IGridTickab
final boolean changed = this.storeEntityItem(itemEntity);
if (changed) {
AppEng.proxy.sendToAllNearExcept(null, pos.getX(), pos.getY(), pos.getZ(), 64,
AppEng.instance().sendToAllNearExcept(null, pos.getX(), pos.getY(), pos.getZ(), 64,
this.getTile().getWorld(), new ItemTransitionEffectPacket(entity.getX(),
entity.getY(), entity.getZ(), this.getSide().getOpposite()));
}
@@ -444,7 +444,7 @@ public class AnnihilationPlanePart extends BasicStatePart implements IGridTickab
energy.extractAEPower(requiredPower, Actionable.MODULATE, PowerMultiplier.CONFIG);
AppEng.proxy.sendToAllNearExcept(null, pos.getX(), pos.getY(), pos.getZ(), 64, w,
AppEng.instance().sendToAllNearExcept(null, pos.getX(), pos.getY(), pos.getZ(), 64, w,
new BlockTransitionEffectPacket(pos, blockState, this.getSide().getOpposite(),
BlockTransitionEffectPacket.SoundMode.NONE));
}
@@ -620,7 +620,7 @@ public class AnnihilationPlanePart extends BasicStatePart implements IGridTickab
}
public static boolean isBlockBlacklisted(Block b) {
Tag<Block> tag = BlockTags.getCollection().getOrCreate(TAG_BLACKLIST);
Tag<Block> tag = BlockTags.getContainer().getOrCreate(TAG_BLACKLIST);
return b.isIn(tag);
}
@@ -32,7 +32,7 @@ import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.item.BlockItem;
import net.minecraft.item.DirectionalPlaceContext;
import net.minecraft.item.AutomaticItemPlacementContext;
import net.minecraft.item.FireworkRocketItem;
import net.minecraft.item.FireworkStarItem;
import net.minecraft.item.Item;
@@ -243,31 +243,31 @@ public class FormationPlanePart extends AbstractFormationPlanePart<IAEItemStack>
// Up or Down, Attempt 1??
if (side.xOffset == 0 && side.zOffset == 0) {
Worked = i.onItemUse(new DirectionalPlaceContext(w, placePos.offset(side.getFacing()),
Worked = i.onItemUse(new AutomaticItemPlacementContext(w, placePos.offset(side.getFacing()),
lookDirection, is, side.getFacing())) == ActionResult.SUCCESS;
}
// Up or Down, Attempt 2??
if (!Worked && side.xOffset == 0 && side.zOffset == 0) {
Worked = i.onItemUse(new DirectionalPlaceContext(w,
Worked = i.onItemUse(new AutomaticItemPlacementContext(w,
placePos.offset(side.getFacing().getOpposite()), lookDirection, is,
side.getFacing().getOpposite())) == ActionResult.SUCCESS;
}
// Horizontal, attempt 1??
if (!Worked && side.yOffset == 0) {
Worked = i.onItemUse(new DirectionalPlaceContext(w, placePos.offset(Direction.DOWN),
Worked = i.onItemUse(new AutomaticItemPlacementContext(w, placePos.offset(Direction.DOWN),
lookDirection, is, Direction.DOWN)) == ActionResult.SUCCESS;
}
if (!Worked) {
i.onItemUse(new DirectionalPlaceContext(w, placePos, lookDirection, is,
i.onItemUse(new AutomaticItemPlacementContext(w, placePos, lookDirection, is,
lookDirection.getOpposite()));
}
maxStorage -= is.getCount();
} else {
i.onItemUse(new DirectionalPlaceContext(w, placePos, lookDirection, is,
i.onItemUse(new AutomaticItemPlacementContext(w, placePos, lookDirection, is,
lookDirection.getOpposite()));
maxStorage -= is.getCount();
}
@@ -1,220 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.parts.misc;
import java.io.IOException;
import java.util.List;
import java.util.Random;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import appeng.api.networking.IGridNode;
import appeng.api.parts.BusSupport;
import appeng.api.parts.IPart;
import appeng.api.parts.IPartCollisionHelper;
import appeng.api.parts.IPartHost;
import appeng.api.parts.IPartModel;
import appeng.api.parts.PartItemStack;
import appeng.api.util.AECableType;
import appeng.api.util.AEPartLocation;
import appeng.core.AppEng;
import appeng.items.parts.PartModels;
import appeng.parts.PartModel;
public class CableAnchorPart implements IPart {
@PartModels
public static final PartModel DEFAULT_MODELS = new PartModel(false,
new Identifier(AppEng.MOD_ID, "part/cable_anchor"));
@PartModels
public static final PartModel FACADE_MODELS = new PartModel(false,
new Identifier(AppEng.MOD_ID, "part/cable_anchor_short"));
private ItemStack is = ItemStack.EMPTY;
private IPartHost host = null;
private AEPartLocation mySide = AEPartLocation.UP;
public CableAnchorPart(final ItemStack is) {
this.is = is;
}
@Override
public void getBoxes(final IPartCollisionHelper bch) {
if (this.host != null && this.host.getFacadeContainer().getFacade(this.mySide) != null) {
bch.addBox(7, 7, 10, 9, 9, 14);
} else {
bch.addBox(7, 7, 10, 9, 9, 16);
}
}
@Override
public ItemStack getItemStack(final PartItemStack wrenched) {
return this.is;
}
@Override
public boolean requireDynamicRender() {
return false;
}
@Override
public boolean isSolid() {
return false;
}
@Override
public boolean canConnectRedstone() {
return false;
}
@Override
public void writeToNBT(final CompoundTag data) {
}
@Override
public void readFromNBT(final CompoundTag data) {
}
@Override
public int getLightLevel() {
return 0;
}
@Override
public boolean isLadder(final LivingEntity entity) {
return this.mySide.yOffset == 0 && (entity.horizontalCollision || !entity.isOnGround());
}
@Override
public void onneighborUpdate(BlockView w, BlockPos pos, BlockPos neighbor) {
}
@Override
public int isProvidingStrongPower() {
return 0;
}
@Override
public int isProvidingWeakPower() {
return 0;
}
@Override
public void writeToStream(final PacketByteBuf data) throws IOException {
}
@Override
public boolean readFromStream(final PacketByteBuf data) throws IOException {
return false;
}
@Override
public IGridNode getGridNode() {
return null;
}
@Override
public void onEntityCollision(final Entity entity) {
}
@Override
public void removeFromWorld() {
}
@Override
public void addToWorld() {
}
@Override
public IGridNode getExternalFacingNode() {
return null;
}
@Override
public void setPartHostInfo(final AEPartLocation side, final IPartHost host, final BlockEntity tile) {
this.host = host;
this.mySide = side;
}
@Override
public boolean onActivate(final PlayerEntity player, final Hand hand, final Vec3d pos) {
return false;
}
@Override
public boolean onShiftActivate(final PlayerEntity player, final Hand hand, final Vec3d pos) {
return false;
}
@Override
public void getDrops(final List<ItemStack> drops, final boolean wrenched) {
}
@Override
public float getCableConnectionLength(AECableType cable) {
return 0;
}
@Override
public void randomDisplayTick(final World world, final BlockPos pos, final Random r) {
}
@Override
public void onPlacement(final PlayerEntity player, final Hand hand, final ItemStack held,
final AEPartLocation side) {
}
@Override
public boolean canBePlacedOn(final BusSupport what) {
return what == BusSupport.CABLE || what == BusSupport.DENSE_CABLE;
}
@Override
public IPartModel getStaticModels() {
if (this.host != null && this.host.getFacadeContainer().getFacade(this.mySide) != null) {
return FACADE_MODELS;
} else {
return DEFAULT_MODELS;
}
}
}
@@ -1,355 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.parts.networking;
import java.io.IOException;
import java.util.EnumSet;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.util.math.Direction;
import appeng.api.AEApi;
import appeng.api.config.SecurityPermissions;
import appeng.api.definitions.IParts;
import appeng.api.implementations.parts.ICablePart;
import appeng.api.networking.GridFlags;
import appeng.api.networking.IGridConnection;
import appeng.api.networking.IGridHost;
import appeng.api.networking.IGridNode;
import appeng.api.parts.BusSupport;
import appeng.api.parts.IPart;
import appeng.api.parts.IPartCollisionHelper;
import appeng.api.parts.IPartHost;
import appeng.api.util.AECableType;
import appeng.api.util.AEColor;
import appeng.api.util.AEPartLocation;
import appeng.api.util.IReadOnlyCollection;
import appeng.items.parts.ColoredPartItem;
import appeng.me.GridAccessException;
import appeng.parts.AEBasePart;
import appeng.util.Platform;
public class CablePart extends AEBasePart implements ICablePart {
private final int[] channelsOnSide = { 0, 0, 0, 0, 0, 0 };
private EnumSet<AEPartLocation> connections = EnumSet.noneOf(AEPartLocation.class);
private boolean powered = false;
public CablePart(final ItemStack is) {
super(is);
this.getProxy().setFlags(GridFlags.PREFERRED);
this.getProxy().setIdlePowerUsage(0.0);
if (is.getItem() instanceof ColoredPartItem) {
ColoredPartItem<?> coloredPartItem = (ColoredPartItem<?>) is.getItem();
this.getProxy().setColor(coloredPartItem.getColor());
}
}
@Override
public BusSupport supportsBuses() {
return BusSupport.CABLE;
}
@Override
public AEColor getCableColor() {
return this.getProxy().getColor();
}
@Override
public AECableType getCableConnectionType() {
return AECableType.GLASS;
}
@Override
public float getCableConnectionLength(AECableType cable) {
if (cable == this.getCableConnectionType()) {
return 4;
} else if (cable.ordinal() >= this.getCableConnectionType().ordinal()) {
return -1;
} else {
return 8;
}
}
@Override
public boolean changeColor(final AEColor newColor, final PlayerEntity who) {
if (this.getCableColor() != newColor) {
ItemStack newPart = null;
final IParts parts = AEApi.instance().definitions().parts();
if (this.getCableConnectionType() == AECableType.GLASS) {
newPart = parts.cableGlass().stack(newColor, 1);
} else if (this.getCableConnectionType() == AECableType.COVERED) {
newPart = parts.cableCovered().stack(newColor, 1);
} else if (this.getCableConnectionType() == AECableType.SMART) {
newPart = parts.cableSmart().stack(newColor, 1);
} else if (this.getCableConnectionType() == AECableType.DENSE_COVERED) {
newPart = parts.cableDenseCovered().stack(newColor, 1);
} else if (this.getCableConnectionType() == AECableType.DENSE_SMART) {
newPart = parts.cableDenseSmart().stack(newColor, 1);
}
boolean hasPermission = true;
try {
hasPermission = this.getProxy().getSecurity().hasPermission(who, SecurityPermissions.BUILD);
} catch (final GridAccessException e) {
// :P
}
if (newPart != null && hasPermission) {
if (Platform.isClient()) {
return true;
}
this.getHost().removePart(AEPartLocation.INTERNAL, true);
this.getHost().addPart(newPart, AEPartLocation.INTERNAL, who, null);
return true;
}
}
return false;
}
@Override
public void setValidSides(final EnumSet<Direction> sides) {
this.getProxy().setValidSides(sides);
}
@Override
public boolean isConnected(final Direction side) {
return this.getConnections().contains(AEPartLocation.fromFacing(side));
}
public void markForUpdate() {
this.getHost().markForUpdate();
}
@Override
public void getBoxes(final IPartCollisionHelper bch) {
bch.addBox(6.0, 6.0, 6.0, 10.0, 10.0, 10.0);
if (Platform.isServer()) {
final IGridNode n = this.getGridNode();
if (n != null) {
this.setConnections(n.getConnectedSides());
} else {
this.getConnections().clear();
}
}
final IPartHost ph = this.getHost();
if (ph != null) {
for (final AEPartLocation dir : AEPartLocation.SIDE_LOCATIONS) {
final IPart p = ph.getPart(dir);
if (p instanceof IGridHost) {
final double dist = p.getCableConnectionLength(this.getCableConnectionType());
if (dist > 8) {
continue;
}
switch (dir) {
case DOWN:
bch.addBox(6.0, dist, 6.0, 10.0, 6.0, 10.0);
break;
case EAST:
bch.addBox(10.0, 6.0, 6.0, 16.0 - dist, 10.0, 10.0);
break;
case NORTH:
bch.addBox(6.0, 6.0, dist, 10.0, 10.0, 6.0);
break;
case SOUTH:
bch.addBox(6.0, 6.0, 10.0, 10.0, 10.0, 16.0 - dist);
break;
case UP:
bch.addBox(6.0, 10.0, 6.0, 10.0, 16.0 - dist, 10.0);
break;
case WEST:
bch.addBox(dist, 6.0, 6.0, 6.0, 10.0, 10.0);
break;
default:
}
}
}
}
for (final AEPartLocation of : this.getConnections()) {
switch (of) {
case DOWN:
bch.addBox(6.0, 0.0, 6.0, 10.0, 6.0, 10.0);
break;
case EAST:
bch.addBox(10.0, 6.0, 6.0, 16.0, 10.0, 10.0);
break;
case NORTH:
bch.addBox(6.0, 6.0, 0.0, 10.0, 10.0, 6.0);
break;
case SOUTH:
bch.addBox(6.0, 6.0, 10.0, 10.0, 10.0, 16.0);
break;
case UP:
bch.addBox(6.0, 10.0, 6.0, 10.0, 16.0, 10.0);
break;
case WEST:
bch.addBox(0.0, 6.0, 6.0, 6.0, 10.0, 10.0);
break;
default:
}
}
}
@Override
public void writeToNBT(final CompoundTag data) {
super.writeToNBT(data);
if (Platform.isServer()) {
final IGridNode node = this.getGridNode();
if (node != null) {
int howMany = 0;
for (final IGridConnection gc : node.getConnections()) {
howMany = Math.max(gc.getUsedChannels(), howMany);
}
data.putByte("usedChannels", (byte) howMany);
}
}
}
@Override
public void writeToStream(final PacketByteBuf data) throws IOException {
int flags = 0;
boolean[] writeSide = new boolean[Direction.values().length];
int[] channelsPerSide = new int[Direction.values().length];
for (Direction thisSide : Direction.values()) {
final IPart part = this.getHost().getPart(thisSide);
if (part != null) {
writeSide[thisSide.ordinal()] = true;
int channels = 0;
if (part.getGridNode() != null) {
final IReadOnlyCollection<IGridConnection> set = part.getGridNode().getConnections();
for (final IGridConnection gc : set) {
channels = Math.max(channels, gc.getUsedChannels());
}
}
channelsPerSide[thisSide.ordinal()] = channels;
}
}
IGridNode n = this.getGridNode();
if (n != null) {
for (final IGridConnection gc : n.getConnections()) {
final AEPartLocation side = gc.getDirection(n);
if (side != AEPartLocation.INTERNAL) {
writeSide[side.ordinal()] = true;
channelsPerSide[side.ordinal()] = gc.getUsedChannels();
flags |= (1 << side.ordinal());
}
}
}
try {
if (this.getProxy().getEnergy().isNetworkPowered()) {
flags |= (1 << AEPartLocation.INTERNAL.ordinal());
}
} catch (final GridAccessException e) {
// aww...
}
data.writeByte((byte) flags);
// Only write the used channels for sides where we have a part or another cable
for (int i = 0; i < writeSide.length; i++) {
if (writeSide[i]) {
data.writeByte(channelsPerSide[i]);
}
}
}
@Override
public boolean readFromStream(final PacketByteBuf data) throws IOException {
int cs = data.readByte();
final EnumSet<AEPartLocation> myC = this.getConnections().clone();
final boolean wasPowered = this.powered;
this.powered = false;
boolean channelsChanged = false;
for (final AEPartLocation d : AEPartLocation.values()) {
if (d == AEPartLocation.INTERNAL) {
final int id = 1 << d.ordinal();
if (id == (cs & id)) {
this.powered = true;
}
} else {
boolean conOnSide = (cs & (1 << d.ordinal())) != 0;
if (conOnSide) {
this.getConnections().add(d);
} else {
this.getConnections().remove(d);
}
int ch = 0;
// Only read channels if there's a part on this side or a cable connection
// This works only because cables are always read *last* from the packet update
// for
// a cable bus
if (conOnSide || this.getHost().getPart(d) != null) {
ch = (data.readByte()) & 0xFF;
}
if (ch != this.getChannelsOnSide(d.ordinal())) {
channelsChanged = true;
this.setChannelsOnSide(d.ordinal(), ch);
}
}
}
return !myC.equals(this.getConnections()) || wasPowered != this.powered || channelsChanged;
}
int getChannelsOnSide(final int i) {
return this.channelsOnSide[i];
}
public int getChannelsOnSide(Direction side) {
if (!this.powered) {
return 0;
}
return this.channelsOnSide[side.ordinal()];
}
void setChannelsOnSide(final int i, final int channels) {
this.channelsOnSide[i] = channels;
}
EnumSet<AEPartLocation> getConnections() {
return this.connections;
}
void setConnections(final EnumSet<AEPartLocation> connections) {
this.connections = connections;
}
}
@@ -1,91 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.parts.networking;
import net.minecraft.item.ItemStack;
import appeng.api.networking.IGridNode;
import appeng.api.networking.events.MENetworkChannelsChanged;
import appeng.api.networking.events.MENetworkEventSubscribe;
import appeng.api.networking.events.MENetworkPowerStatusChange;
import appeng.api.parts.IPartCollisionHelper;
import appeng.api.util.AECableType;
import appeng.api.util.AEPartLocation;
import appeng.helpers.Reflected;
import appeng.util.Platform;
public class CoveredCablePart extends CablePart {
@Reflected
public CoveredCablePart(final ItemStack is) {
super(is);
}
@MENetworkEventSubscribe
public void channelUpdated(final MENetworkChannelsChanged c) {
this.getHost().markForUpdate();
}
@MENetworkEventSubscribe
public void powerRender(final MENetworkPowerStatusChange c) {
this.getHost().markForUpdate();
}
@Override
public AECableType getCableConnectionType() {
return AECableType.COVERED;
}
@Override
public void getBoxes(final IPartCollisionHelper bch) {
bch.addBox(5.0, 5.0, 5.0, 11.0, 11.0, 11.0);
if (Platform.isServer()) {
final IGridNode n = this.getGridNode();
if (n != null) {
this.setConnections(n.getConnectedSides());
} else {
this.getConnections().clear();
}
}
for (final AEPartLocation of : this.getConnections()) {
switch (of) {
case DOWN:
bch.addBox(5.0, 0.0, 5.0, 11.0, 5.0, 11.0);
break;
case EAST:
bch.addBox(11.0, 5.0, 5.0, 16.0, 11.0, 11.0);
break;
case NORTH:
bch.addBox(5.0, 5.0, 0.0, 11.0, 11.0, 5.0);
break;
case SOUTH:
bch.addBox(5.0, 5.0, 11.0, 11.0, 11.0, 16.0);
break;
case UP:
bch.addBox(5.0, 11.0, 5.0, 11.0, 16.0, 11.0);
break;
case WEST:
bch.addBox(0.0, 5.0, 5.0, 5.0, 11.0, 11.0);
break;
default:
}
}
}
}
@@ -1,36 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.parts.networking;
import net.minecraft.item.ItemStack;
import appeng.api.util.AECableType;
public class CoveredDenseCablePart extends DenseCablePart {
public CoveredDenseCablePart(ItemStack is) {
super(is);
}
@Override
public AECableType getCableConnectionType() {
return AECableType.DENSE_COVERED;
}
}
@@ -1,136 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.parts.networking;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.item.ItemStack;
import appeng.api.networking.GridFlags;
import appeng.api.networking.IGridHost;
import appeng.api.networking.IGridNode;
import appeng.api.networking.events.MENetworkChannelsChanged;
import appeng.api.networking.events.MENetworkEventSubscribe;
import appeng.api.networking.events.MENetworkPowerStatusChange;
import appeng.api.parts.BusSupport;
import appeng.api.parts.IPartCollisionHelper;
import appeng.api.util.AECableType;
import appeng.api.util.AEPartLocation;
import appeng.helpers.Reflected;
import appeng.util.Platform;
public abstract class DenseCablePart extends CablePart {
@Reflected
public DenseCablePart(final ItemStack is) {
super(is);
this.getProxy().setFlags(GridFlags.DENSE_CAPACITY, GridFlags.PREFERRED);
}
@Override
public BusSupport supportsBuses() {
return BusSupport.DENSE_CABLE;
}
@Override
public void getBoxes(final IPartCollisionHelper bch) {
final boolean noLadder = !bch.isBBCollision();
final double min = noLadder ? 3.0 : 4.9;
final double max = noLadder ? 13.0 : 11.1;
bch.addBox(min, min, min, max, max, max);
if (Platform.isServer()) {
final IGridNode n = this.getGridNode();
if (n != null) {
this.setConnections(n.getConnectedSides());
} else {
this.getConnections().clear();
}
}
for (final AEPartLocation of : this.getConnections()) {
if (this.isDense(of)) {
switch (of) {
case DOWN:
bch.addBox(min, 0.0, min, max, min, max);
break;
case EAST:
bch.addBox(max, min, min, 16.0, max, max);
break;
case NORTH:
bch.addBox(min, min, 0.0, max, max, min);
break;
case SOUTH:
bch.addBox(min, min, max, max, max, 16.0);
break;
case UP:
bch.addBox(min, max, min, max, 16.0, max);
break;
case WEST:
bch.addBox(0.0, min, min, min, max, max);
break;
default:
}
} else {
switch (of) {
case DOWN:
bch.addBox(5.0, 0.0, 5.0, 11.0, 5.0, 11.0);
break;
case EAST:
bch.addBox(11.0, 5.0, 5.0, 16.0, 11.0, 11.0);
break;
case NORTH:
bch.addBox(5.0, 5.0, 0.0, 11.0, 11.0, 5.0);
break;
case SOUTH:
bch.addBox(5.0, 5.0, 11.0, 11.0, 11.0, 16.0);
break;
case UP:
bch.addBox(5.0, 11.0, 5.0, 11.0, 16.0, 11.0);
break;
case WEST:
bch.addBox(0.0, 5.0, 5.0, 5.0, 11.0, 11.0);
break;
default:
}
}
}
}
private boolean isDense(final AEPartLocation of) {
final BlockEntity te = this.getTile().getWorld().getBlockEntity(this.getTile().getPos().offset(of.getFacing()));
if (te instanceof IGridHost) {
final AECableType t = ((IGridHost) te).getCableConnectionType(of.getOpposite());
return t.isDense();
}
return false;
}
@MENetworkEventSubscribe
public void channelUpdated(final MENetworkChannelsChanged c) {
this.getHost().markForUpdate();
}
@MENetworkEventSubscribe
public void powerRender(final MENetworkPowerStatusChange c) {
this.getHost().markForUpdate();
}
}
@@ -1,30 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.parts.networking;
import net.minecraft.item.ItemStack;
import appeng.helpers.Reflected;
public class GlassCablePart extends CablePart {
@Reflected
public GlassCablePart(final ItemStack is) {
super(is);
}
}
@@ -1,174 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.parts.networking;
import java.util.ArrayList;
import java.util.Collection;
import java.util.EnumSet;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import appeng.api.config.Actionable;
import appeng.api.networking.GridFlags;
import appeng.api.networking.IGridNode;
import appeng.api.networking.energy.IEnergyGrid;
import appeng.api.networking.energy.IEnergyGridProvider;
import appeng.api.parts.IPartCollisionHelper;
import appeng.api.parts.IPartHost;
import appeng.api.parts.IPartModel;
import appeng.api.util.AECableType;
import appeng.api.util.AEPartLocation;
import appeng.core.AppEng;
import appeng.items.parts.PartModels;
import appeng.me.GridAccessException;
import appeng.me.helpers.AENetworkProxy;
import appeng.parts.AEBasePart;
import appeng.parts.PartModel;
public class QuartzFiberPart extends AEBasePart implements IEnergyGridProvider {
@PartModels
private static final IPartModel MODELS = new PartModel(new Identifier(AppEng.MOD_ID, "part/quartz_fiber"));
private final AENetworkProxy outerProxy = new AENetworkProxy(this, "outer",
this.getProxy().getMachineRepresentation(), true);
public QuartzFiberPart(final ItemStack is) {
super(is);
this.getProxy().setIdlePowerUsage(0);
this.getProxy().setFlags(GridFlags.CANNOT_CARRY);
this.outerProxy.setIdlePowerUsage(0);
this.outerProxy.setFlags(GridFlags.CANNOT_CARRY);
}
@Override
public AECableType getCableConnectionType(final AEPartLocation dir) {
return AECableType.GLASS;
}
@Override
public void getBoxes(final IPartCollisionHelper bch) {
bch.addBox(6, 6, 10, 10, 10, 16);
}
@Override
public void readFromNBT(final CompoundTag extra) {
super.readFromNBT(extra);
this.outerProxy.readFromNBT(extra);
}
@Override
public void writeToNBT(final CompoundTag extra) {
super.writeToNBT(extra);
this.outerProxy.writeToNBT(extra);
}
@Override
public void removeFromWorld() {
super.removeFromWorld();
this.outerProxy.remove();
}
@Override
public void addToWorld() {
super.addToWorld();
this.outerProxy.onReady();
}
@Override
public void setPartHostInfo(final AEPartLocation side, final IPartHost host, final BlockEntity tile) {
super.setPartHostInfo(side, host, tile);
this.outerProxy.setValidSides(EnumSet.of(side.getFacing()));
}
@Override
public IGridNode getExternalFacingNode() {
return this.outerProxy.getNode();
}
@Override
public float getCableConnectionLength(AECableType cable) {
return 16;
}
@Override
public void onPlacement(final PlayerEntity player, final Hand hand, final ItemStack held,
final AEPartLocation side) {
super.onPlacement(player, hand, held, side);
this.outerProxy.setOwner(player);
}
@Override
public Collection<IEnergyGridProvider> providers() {
Collection<IEnergyGridProvider> providers = new ArrayList<>();
try {
final IEnergyGrid eg = this.getProxy().getEnergy();
providers.add(eg);
} catch (final GridAccessException e) {
// :P
}
try {
final IEnergyGrid eg = this.outerProxy.getEnergy();
providers.add(eg);
} catch (final GridAccessException e) {
// :P
}
return providers;
}
@Override
public double extractProviderPower(final double amt, final Actionable mode) {
return 0;
}
@Override
public double injectProviderPower(final double amt, final Actionable mode) {
return amt;
}
@Override
public double getProviderEnergyDemand(final double amt) {
return 0;
}
@Override
public double getProviderStoredEnergy() {
return 0;
}
@Override
public double getProviderMaxEnergy() {
return 0;
}
@Override
public IPartModel getStaticModels() {
return MODELS;
}
}
@@ -1,91 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.parts.networking;
import net.minecraft.item.ItemStack;
import appeng.api.networking.IGridNode;
import appeng.api.networking.events.MENetworkChannelsChanged;
import appeng.api.networking.events.MENetworkEventSubscribe;
import appeng.api.networking.events.MENetworkPowerStatusChange;
import appeng.api.parts.IPartCollisionHelper;
import appeng.api.util.AECableType;
import appeng.api.util.AEPartLocation;
import appeng.helpers.Reflected;
import appeng.util.Platform;
public class SmartCablePart extends CablePart {
@Reflected
public SmartCablePart(final ItemStack is) {
super(is);
}
@MENetworkEventSubscribe
public void channelUpdated(final MENetworkChannelsChanged c) {
this.getHost().markForUpdate();
}
@MENetworkEventSubscribe
public void powerRender(final MENetworkPowerStatusChange c) {
this.getHost().markForUpdate();
}
@Override
public AECableType getCableConnectionType() {
return AECableType.SMART;
}
@Override
public void getBoxes(final IPartCollisionHelper bch) {
bch.addBox(5.0, 5.0, 5.0, 11.0, 11.0, 11.0);
if (Platform.isServer()) {
final IGridNode n = this.getGridNode();
if (n != null) {
this.setConnections(n.getConnectedSides());
} else {
this.getConnections().clear();
}
}
for (final AEPartLocation of : this.getConnections()) {
switch (of) {
case DOWN:
bch.addBox(5.0, 0.0, 5.0, 11.0, 5.0, 11.0);
break;
case EAST:
bch.addBox(11.0, 5.0, 5.0, 16.0, 11.0, 11.0);
break;
case NORTH:
bch.addBox(5.0, 5.0, 0.0, 11.0, 11.0, 5.0);
break;
case SOUTH:
bch.addBox(5.0, 5.0, 11.0, 11.0, 11.0, 16.0);
break;
case UP:
bch.addBox(5.0, 11.0, 5.0, 11.0, 16.0, 11.0);
break;
case WEST:
bch.addBox(0.0, 5.0, 5.0, 5.0, 11.0, 11.0);
break;
default:
}
}
}
}
@@ -1,35 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.parts.networking;
import net.minecraft.item.ItemStack;
import appeng.api.util.AECableType;
public class SmartDenseCablePart extends DenseCablePart {
public SmartDenseCablePart(ItemStack is) {
super(is);
}
@Override
public AECableType getCableConnectionType() {
return AECableType.DENSE_SMART;
}
}