diff --git a/electrical/src/main/scala/resonantinduction/electrical/battery/TileBattery.java b/electrical/src/main/scala/resonantinduction/electrical/battery/TileBattery.java index 46af6ad37..85e8a6c1b 100644 --- a/electrical/src/main/scala/resonantinduction/electrical/battery/TileBattery.java +++ b/electrical/src/main/scala/resonantinduction/electrical/battery/TileBattery.java @@ -17,101 +17,101 @@ import calclavia.lib.network.IPacketSender; import com.google.common.io.ByteArrayDataInput; -/** - * A modular battery box that allows shared connections with boxes next to it. +/** A modular battery box that allows shared connections with boxes next to it. * - * @author Calclavia - */ + * @author Calclavia */ public class TileBattery extends TileEnergyDistribution implements IVoltageInput, IVoltageOutput, IPacketSender, IPacketReceiver, IEnergyInterface, IEnergyContainer { - /** - * Tiers: 0, 1, 2 - */ - public static final int MAX_TIER = 2; + /** Tiers: 0, 1, 2 */ + public static final int MAX_TIER = 2; - /** The transfer rate **/ - public static final long DEFAULT_WATTAGE = getEnergyForTier(0); + /** The transfer rate **/ + public static final long DEFAULT_WATTAGE = getEnergyForTier(0); - public TileBattery() - { - this.setEnergyHandler(new EnergyStorageHandler(0)); - this.getEnergyHandler().setCapacity(Long.MAX_VALUE); - this.ioMap = 0; - this.saveIOMap = true; - } + public TileBattery() + { + this.setEnergyHandler(new EnergyStorageHandler(0)); + this.getEnergyHandler().setCapacity(Long.MAX_VALUE); + this.ioMap = 0; + this.saveIOMap = true; + } - /** - * @param tier - 0, 1, 2 - * @return - */ - public static long getEnergyForTier(int tier) - { - return Math.round(Math.pow(500000000, (tier / (MAX_TIER + 0.7f)) + 1) / (500000000)) * (500000000); - } + /** @param tier - 0, 1, 2 + * @return */ + public static long getEnergyForTier(int tier) + { + return Math.round(Math.pow(500000000, (tier / (MAX_TIER + 0.7f)) + 1) / (500000000)) * (500000000); + } - @Override - public void initiate() - { - super.initiate(); - getEnergyHandler().setCapacity(getEnergyForTier(getBlockMetadata())); - getEnergyHandler().setMaxTransfer(getEnergyHandler().getEnergyCapacity()); - } + @Override + public void initiate() + { + super.initiate(); + getEnergyHandler().setCapacity(getEnergyForTier(getBlockMetadata())); + getEnergyHandler().setMaxTransfer(getEnergyHandler().getEnergyCapacity()); + } - @Override - public void updateEntity() - { - if (!this.worldObj.isRemote) - { - markDistributionUpdate |= produce() > 0; - } + @Override + public void updateEntity() + { + if (!this.worldObj.isRemote) + { + markDistributionUpdate |= produce() > 0; + } - super.updateEntity(); - } + super.updateEntity(); + } - @Override - public Packet getDescriptionPacket() - { - return ResonantInduction.PACKET_TILE.getPacket(this, getPacketData(0).toArray()); - } + @Override + public Packet getDescriptionPacket() + { + return ResonantInduction.PACKET_TILE.getPacket(this, getPacketData(0).toArray()); + } - @Override - public void onReceivePacket(ByteArrayDataInput data, EntityPlayer player, Object... extra) - { - getEnergyHandler().setEnergy(data.readLong()); - ioMap = data.readShort(); - } + @Override + public void onReceivePacket(ByteArrayDataInput data, EntityPlayer player, Object... extra) + { + getEnergyHandler().setEnergy(data.readLong()); + ioMap = data.readShort(); + } - @Override - public ArrayList getPacketData(int type) - { - ArrayList data = new ArrayList(); - data.add(renderEnergyAmount); - data.add(ioMap); - return data; - } + @Override + public ArrayList getPacketData(int type) + { + ArrayList data = new ArrayList(); + data.add(renderEnergyAmount); + data.add(ioMap); + return data; + } - @Override - public long getVoltageOutput(ForgeDirection side) - { - return UniversalElectricity.DEFAULT_VOLTAGE; - } + @Override + public long getVoltageOutput(ForgeDirection side) + { + return UniversalElectricity.DEFAULT_VOLTAGE; + } - @Override - public long getVoltageInput(ForgeDirection direction) - { - return UniversalElectricity.DEFAULT_VOLTAGE; - } + @Override + public long getVoltageInput(ForgeDirection direction) + { + return UniversalElectricity.DEFAULT_VOLTAGE; + } - @Override - public void onWrongVoltage(ForgeDirection direction, long voltage) - { + @Override + public void onWrongVoltage(ForgeDirection direction, long voltage) + { - } + } - @Override - public void setIO(ForgeDirection dir, int type) - { - super.setIO(dir, type); - worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); - } + @Override + public void setIO(ForgeDirection dir, int type) + { + super.setIO(dir, type); + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + } + + @Override + public String toString() + { + return "[TileBattery]" + x() + "x " + y() + "y " + z() + "z "; + } } diff --git a/electrical/src/main/scala/resonantinduction/electrical/charger/PartCharger.java b/electrical/src/main/scala/resonantinduction/electrical/charger/PartCharger.java index 787262c3b..1af7ce968 100644 --- a/electrical/src/main/scala/resonantinduction/electrical/charger/PartCharger.java +++ b/electrical/src/main/scala/resonantinduction/electrical/charger/PartCharger.java @@ -140,4 +140,10 @@ public class PartCharger extends PartInventoryPanel implements IEnergyInterface { return slot < this.getSizeInventory() && stack != null && CompatibilityModule.isHandler(stack.getItem()); } + + @Override + public String toString() + { + return "[PartCharger]" + x() + "x " + y() + "y " + z() + "z " + getSlotMask() + "s "; + } } diff --git a/electrical/src/main/scala/resonantinduction/electrical/multimeter/PartMultimeter.java b/electrical/src/main/scala/resonantinduction/electrical/multimeter/PartMultimeter.java index 71a21c2c6..c64e94a24 100644 --- a/electrical/src/main/scala/resonantinduction/electrical/multimeter/PartMultimeter.java +++ b/electrical/src/main/scala/resonantinduction/electrical/multimeter/PartMultimeter.java @@ -39,549 +39,548 @@ import cpw.mods.fml.common.network.PacketDispatcher; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -/** - * Block that detects power. +/** Block that detects power. * - * @author Calclavia - * - */ + * @author Calclavia */ public class PartMultimeter extends PartFace implements IConnector, IRedstonePart, IPacketReceiver { - public enum DetectMode - { - NONE("none"), LESS_THAN("lessThan"), LESS_THAN_EQUAL("lessThanOrEqual"), EQUAL("equal"), - GREATER_THAN_EQUAL("greaterThanOrEqual"), GREATER_THAN("greaterThan"); - - public String display; - - private DetectMode(String s) - { - display = s; - } - } - - public Set playersUsing = new HashSet(); - - /** - * Detection - */ - public double redstoneTriggerLimit; - public byte detectType = 0; - public byte graphType = 0; - private DetectMode detectMode = DetectMode.NONE; - public boolean redstoneOn; - private boolean doDetect = true; - - public boolean isPrimary; - private MultimeterNetwork network; - - public boolean hasMultimeter(int x, int y, int z) - { - return getMultimeter(x, y, z) != null; - } - - @Override - public void preRemove() - { - if (!world().isRemote) - getNetwork().split(this); - } - - public void refresh() - { - if (world() != null) - { - if (!world().isRemote) - { - for (Object obj : getConnections()) - { - if (obj instanceof PartMultimeter) - { - getNetwork().merge(((PartMultimeter) obj).getNetwork()); - } - } - - getNetwork().reconstruct(); - } - } - } - - public void updateDesc() - { - writeDesc(getWriteStream()); - } - - public void updateGraph() - { - writeGraph(getWriteStream()); - } - - @Override - public void onWorldJoin() - { - refresh(); - } - - @Override - public void onNeighborChanged() - { - refresh(); - } - - @Override - public void onPartChanged(TMultiPart part) - { - refresh(); - } - - /** - * Gets the multimeter on the same plane. - */ - public PartMultimeter getMultimeter(int x, int y, int z) - { - TileEntity tileEntity = world().getBlockTileEntity(x, y, z); - - if (tileEntity instanceof TileMultipart) - { - TMultiPart part = ((TileMultipart) tileEntity).partMap(placementSide.ordinal()); - - if (part instanceof PartMultimeter) - { - return (PartMultimeter) part; - } - } - - return null; - } - - @Override - public boolean activate(EntityPlayer player, MovingObjectPosition part, ItemStack item) - { - if (WrenchUtility.isUsableWrench(player, player.inventory.getCurrentItem(), x(), y(), z())) - { - if (!this.world().isRemote) - { - doDetect = !doDetect; - player.addChatMessage("Multimeter detection set to: " + doDetect); - WrenchUtility.damageWrench(player, player.inventory.getCurrentItem(), x(), y(), z()); - } - return true; - } - - player.openGui(Electrical.INSTANCE, placementSide.ordinal(), world(), x(), y(), z()); - return true; - } - - @Override - public void update() - { - super.update(); - - this.ticks++; - - if (!world().isRemote) - { - if (doDetect) - updateDetections(); - - double detectedValue = getNetwork().graphs.get(detectType).getDouble(); - - boolean outputRedstone = false; - - switch (detectMode) - { - default: - break; - case EQUAL: - outputRedstone = detectedValue == redstoneTriggerLimit; - break; - case GREATER_THAN: - outputRedstone = detectedValue > redstoneTriggerLimit; - break; - case GREATER_THAN_EQUAL: - outputRedstone = detectedValue >= redstoneTriggerLimit; - break; - case LESS_THAN: - outputRedstone = detectedValue < redstoneTriggerLimit; - break; - case LESS_THAN_EQUAL: - outputRedstone = detectedValue <= redstoneTriggerLimit; - break; - } - - getNetwork().markUpdate(); - - if (ticks % 20 == 0) - { - if (outputRedstone != redstoneOn) - { - redstoneOn = outputRedstone; - tile().notifyPartChange(this); - } - - updateGraph(); - } - } - - if (!world().isRemote) - { - for (EntityPlayer player : playersUsing) - { - updateGraph(); - } - } - } - - public void updateDetections() - { - ForgeDirection receivingSide = getDirection().getOpposite(); - TileEntity tileEntity = getDetectedTile(); - - /** - * Update Energy Graph - */ - if (tileEntity instanceof IConductor) - { - IConnector instance = ((IConductor) tileEntity).getInstance(receivingSide); - - for (ForgeDirection dir : ForgeDirection.values()) - { - if (instance != null) - { - break; - } - - instance = ((IConnector) tileEntity).getInstance(dir); - } - - if (instance != null) - { - if (instance.getNetwork() instanceof IEnergyNetwork) - { - IEnergyNetwork network = instance.getNetwork(); - getNetwork().energyGraph.queue(Math.max(network.getBuffer(), network.getLastBuffer())); - getNetwork().powerGraph.queue(getNetwork().energyGraph.getAverage() * 20); - - if (instance.getNetwork() instanceof IElectricalNetwork) - getNetwork().voltageGraph.queue(((IElectricalNetwork) network).getVoltage()); - } - } - } - - if (tileEntity instanceof INodeProvider) - { - IMechanicalNode instance = ((INodeProvider) tileEntity).getNode(IMechanicalNode.class, receivingSide); - - for (ForgeDirection dir : ForgeDirection.values()) - { - if (instance != null) - { - break; - } - - instance = ((INodeProvider) tileEntity).getNode(IMechanicalNode.class, dir); - } - - if (instance != null) - { - getNetwork().torqueGraph.queue(instance.getTorque()); - getNetwork().angularVelocityGraph.queue(instance.getAngularVelocity()); - getNetwork().powerGraph.queue((long) instance.getPower()); - } - } - - if (tileEntity instanceof IFluidHandler) - { - FluidTankInfo[] fluidInfo = ((IFluidHandler) tileEntity).getTankInfo(receivingSide); - - if (fluidInfo != null) - { - for (FluidTankInfo info : fluidInfo) - { - if (info != null) - if (info.fluid != null) - getNetwork().fluidGraph.queue(info.fluid.amount); - } - } - } - - if (tileEntity instanceof IPressureNodeProvider) - { - getNetwork().pressureGraph.queue(((IPressureNodeProvider) tileEntity).getNode(FluidPressureNode.class, receivingSide).getPressure(receivingSide)); - } - - getNetwork().energyGraph.queue(CompatibilityModule.getEnergy(tileEntity, receivingSide)); - - /** - * Update Energy Capacity Graph - */ - getNetwork().energyCapacityGraph.queue(CompatibilityModule.getMaxEnergy(tileEntity, receivingSide)); - } - - @Override - public void readDesc(MCDataInput packet) - { - packet.readByte(); - placementSide = ForgeDirection.getOrientation(packet.readByte()); - facing = packet.readByte(); - detectMode = DetectMode.values()[packet.readByte()]; - detectType = packet.readByte(); - graphType = packet.readByte(); - getNetwork().center = new universalelectricity.api.vector.Vector3(packet.readNBTTagCompound()); - getNetwork().size = new universalelectricity.api.vector.Vector3(packet.readNBTTagCompound()); - getNetwork().isEnabled = packet.readBoolean(); - } - - @Override - public void writeDesc(MCDataOutput packet) - { - packet.writeByte(0); - packet.writeByte(placementSide.ordinal()); - packet.writeByte(facing); - packet.writeByte(detectMode.ordinal()); - packet.writeByte(detectType); - packet.writeByte(graphType); - packet.writeNBTTagCompound(getNetwork().center.writeToNBT(new NBTTagCompound())); - packet.writeNBTTagCompound(getNetwork().size.writeToNBT(new NBTTagCompound())); - packet.writeBoolean(getNetwork().isEnabled); - } - - public void writeGraph(MCDataOutput packet) - { - packet.writeByte(2); - isPrimary = getNetwork().isPrimary(this); - packet.writeBoolean(isPrimary); - - if (isPrimary) - packet.writeNBTTagCompound(getNetwork().save()); - } - - @Override - public void read(MCDataInput packet) - { - read(packet, packet.readUByte()); - } - - public void read(MCDataInput packet, int packetID) - { - switch (packetID) - { - case 0: - { - placementSide = ForgeDirection.getOrientation(packet.readByte()); - facing = packet.readByte(); - detectMode = DetectMode.values()[packet.readByte()]; - detectType = packet.readByte(); - graphType = packet.readByte(); - getNetwork().center = new universalelectricity.api.vector.Vector3(packet.readNBTTagCompound()); - getNetwork().size = new universalelectricity.api.vector.Vector3(packet.readNBTTagCompound()); - getNetwork().isEnabled = packet.readBoolean(); - refresh(); - break; - } - case 1: - { - redstoneTriggerLimit = packet.readLong(); - break; - } - case 2: - { - isPrimary = packet.readBoolean(); - - if (isPrimary) - getNetwork().load(packet.readNBTTagCompound()); - break; - } - } - } - - @Override - public void onReceivePacket(ByteArrayDataInput data, EntityPlayer player, Object... extra) - { - detectMode = DetectMode.values()[data.readByte()]; - detectType = data.readByte(); - graphType = data.readByte(); - redstoneTriggerLimit = data.readDouble(); - } - - public TileEntity getDetectedTile() - { - ForgeDirection direction = getDirection(); - return world().getBlockTileEntity(x() + direction.offsetX, y() + direction.offsetY, z() + direction.offsetZ); - } - - public ForgeDirection getDirection() - { - return ForgeDirection.getOrientation(this.placementSide.ordinal()); - } - - public void toggleGraphType() - { - graphType = (byte) ((graphType + 1) % getNetwork().graphs.size()); - updateServer(); - } - - public void toggleMode() - { - detectMode = DetectMode.values()[(detectMode.ordinal() + 1) % DetectMode.values().length]; - updateServer(); - } - - public void toggleDetectionValue() - { - detectType = (byte) ((detectType + 1) % getNetwork().graphs.size()); - updateServer(); - } - - public void updateServer() - { - PacketDispatcher.sendPacketToServer(ResonantInduction.PACKET_MULTIPART.getPacket(new universalelectricity.api.vector.Vector3(x(), y(), z()), placementSide.ordinal(), (byte) detectMode.ordinal(), detectType, graphType, redstoneTriggerLimit)); - } - - @Override - public void load(NBTTagCompound nbt) - { - super.load(nbt); - placementSide = ForgeDirection.getOrientation(nbt.getByte("side")); - detectMode = DetectMode.values()[nbt.getByte("detectMode")]; - detectType = nbt.getByte("detectionType"); - graphType = nbt.getByte("graphType"); - doDetect = nbt.getBoolean("doDetect"); - redstoneTriggerLimit = nbt.getDouble("triggerLimit"); - } - - @Override - public void save(NBTTagCompound nbt) - { - super.save(nbt); - nbt.setByte("side", (byte) placementSide.ordinal()); - nbt.setByte("detectMode", (byte) detectMode.ordinal()); - nbt.setByte("detectionType", detectType); - nbt.setByte("graphType", graphType); - nbt.setBoolean("doDetect", doDetect); - nbt.setDouble("triggerLimit", redstoneTriggerLimit); - } - - public DetectMode getMode() - { - return detectMode; - } - - @Override - public String getType() - { - return "resonant_induction_multimeter"; - } - - @Override - public int redstoneConductionMap() - { - return 0x1F; - } - - @Override - public boolean solid(int arg0) - { - return true; - } - - @Override - protected ItemStack getItem() - { - return new ItemStack(Electrical.itemMultimeter); - } - - @Override - @SideOnly(Side.CLIENT) - public void renderDynamic(Vector3 pos, float frame, int pass) - { - if (pass == 0) - { - RenderMultimeter.render(this, pos.x, pos.y, pos.z); - } - } - - @Override - public boolean canConnectRedstone(int arg0) - { - return true; - } - - @Override - public int strongPowerLevel(int arg0) - { - return redstoneOn ? 14 : 0; - } - - @Override - public int weakPowerLevel(int arg0) - { - return redstoneOn ? 14 : 0; - } - - @Override - public MultimeterNetwork getNetwork() - { - if (network == null) - { - network = new MultimeterNetwork(); - network.addConnector(this); - } - - return network; - } - - @Override - public void setNetwork(MultimeterNetwork network) - { - this.network = network; - } - - @Override - public boolean canConnect(ForgeDirection direction, Object obj) - { - return obj instanceof PartMultimeter; - } - - @Override - public Object[] getConnections() - { - Object[] connections = new Object[6]; - - for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) - { - if (dir != getDirection() && dir != getDirection().getOpposite()) - { - universalelectricity.api.vector.Vector3 vector = getPosition().translate(dir); - - if (hasMultimeter(vector.intX(), vector.intY(), vector.intZ())) - { - connections[dir.ordinal()] = getMultimeter(vector.intX(), vector.intY(), vector.intZ()); - } - } - } - - return connections; - } - - @Override - public IConnector getInstance(ForgeDirection dir) - { - return this; - } - - public universalelectricity.api.vector.Vector3 getPosition() - { - return new universalelectricity.api.vector.Vector3(x(), y(), z()); - } - - @Override - @SideOnly(Side.CLIENT) - public Cuboid6 getRenderBounds() - { - if (isPrimary) - return Cuboid6.full.copy().expand(new Vector3(getNetwork().size.x, getNetwork().size.y, getNetwork().size.z)); - return Cuboid6.full; - } + public enum DetectMode + { + NONE("none"), + LESS_THAN("lessThan"), + LESS_THAN_EQUAL("lessThanOrEqual"), + EQUAL("equal"), + GREATER_THAN_EQUAL("greaterThanOrEqual"), + GREATER_THAN("greaterThan"); + + public String display; + + private DetectMode(String s) + { + display = s; + } + } + + public Set playersUsing = new HashSet(); + + /** Detection */ + public double redstoneTriggerLimit; + public byte detectType = 0; + public byte graphType = 0; + private DetectMode detectMode = DetectMode.NONE; + public boolean redstoneOn; + private boolean doDetect = true; + + public boolean isPrimary; + private MultimeterNetwork network; + + public boolean hasMultimeter(int x, int y, int z) + { + return getMultimeter(x, y, z) != null; + } + + @Override + public void preRemove() + { + if (!world().isRemote) + getNetwork().split(this); + } + + public void refresh() + { + if (world() != null) + { + if (!world().isRemote) + { + for (Object obj : getConnections()) + { + if (obj instanceof PartMultimeter) + { + getNetwork().merge(((PartMultimeter) obj).getNetwork()); + } + } + + getNetwork().reconstruct(); + } + } + } + + public void updateDesc() + { + writeDesc(getWriteStream()); + } + + public void updateGraph() + { + writeGraph(getWriteStream()); + } + + @Override + public void onWorldJoin() + { + refresh(); + } + + @Override + public void onNeighborChanged() + { + refresh(); + } + + @Override + public void onPartChanged(TMultiPart part) + { + refresh(); + } + + /** Gets the multimeter on the same plane. */ + public PartMultimeter getMultimeter(int x, int y, int z) + { + TileEntity tileEntity = world().getBlockTileEntity(x, y, z); + + if (tileEntity instanceof TileMultipart) + { + TMultiPart part = ((TileMultipart) tileEntity).partMap(placementSide.ordinal()); + + if (part instanceof PartMultimeter) + { + return (PartMultimeter) part; + } + } + + return null; + } + + @Override + public boolean activate(EntityPlayer player, MovingObjectPosition part, ItemStack item) + { + if (WrenchUtility.isUsableWrench(player, player.inventory.getCurrentItem(), x(), y(), z())) + { + if (!this.world().isRemote) + { + doDetect = !doDetect; + player.addChatMessage("Multimeter detection set to: " + doDetect); + WrenchUtility.damageWrench(player, player.inventory.getCurrentItem(), x(), y(), z()); + } + return true; + } + + player.openGui(Electrical.INSTANCE, placementSide.ordinal(), world(), x(), y(), z()); + return true; + } + + @Override + public void update() + { + super.update(); + + this.ticks++; + + if (!world().isRemote) + { + if (doDetect) + updateDetections(); + + double detectedValue = getNetwork().graphs.get(detectType).getDouble(); + + boolean outputRedstone = false; + + switch (detectMode) + { + default: + break; + case EQUAL: + outputRedstone = detectedValue == redstoneTriggerLimit; + break; + case GREATER_THAN: + outputRedstone = detectedValue > redstoneTriggerLimit; + break; + case GREATER_THAN_EQUAL: + outputRedstone = detectedValue >= redstoneTriggerLimit; + break; + case LESS_THAN: + outputRedstone = detectedValue < redstoneTriggerLimit; + break; + case LESS_THAN_EQUAL: + outputRedstone = detectedValue <= redstoneTriggerLimit; + break; + } + + getNetwork().markUpdate(); + + if (ticks % 20 == 0) + { + if (outputRedstone != redstoneOn) + { + redstoneOn = outputRedstone; + tile().notifyPartChange(this); + } + + updateGraph(); + } + } + + if (!world().isRemote) + { + for (EntityPlayer player : playersUsing) + { + updateGraph(); + } + } + } + + public void updateDetections() + { + ForgeDirection receivingSide = getDirection().getOpposite(); + TileEntity tileEntity = getDetectedTile(); + + /** Update Energy Graph */ + if (tileEntity instanceof IConductor) + { + IConnector instance = ((IConductor) tileEntity).getInstance(receivingSide); + + for (ForgeDirection dir : ForgeDirection.values()) + { + if (instance != null) + { + break; + } + + instance = ((IConnector) tileEntity).getInstance(dir); + } + + if (instance != null) + { + if (instance.getNetwork() instanceof IEnergyNetwork) + { + IEnergyNetwork network = instance.getNetwork(); + getNetwork().energyGraph.queue(Math.max(network.getBuffer(), network.getLastBuffer())); + getNetwork().powerGraph.queue(getNetwork().energyGraph.getAverage() * 20); + + if (instance.getNetwork() instanceof IElectricalNetwork) + getNetwork().voltageGraph.queue(((IElectricalNetwork) network).getVoltage()); + } + } + } + + if (tileEntity instanceof INodeProvider) + { + IMechanicalNode instance = ((INodeProvider) tileEntity).getNode(IMechanicalNode.class, receivingSide); + + for (ForgeDirection dir : ForgeDirection.values()) + { + if (instance != null) + { + break; + } + + instance = ((INodeProvider) tileEntity).getNode(IMechanicalNode.class, dir); + } + + if (instance != null) + { + getNetwork().torqueGraph.queue(instance.getTorque()); + getNetwork().angularVelocityGraph.queue(instance.getAngularVelocity()); + getNetwork().powerGraph.queue((long) instance.getPower()); + } + } + + if (tileEntity instanceof IFluidHandler) + { + FluidTankInfo[] fluidInfo = ((IFluidHandler) tileEntity).getTankInfo(receivingSide); + + if (fluidInfo != null) + { + for (FluidTankInfo info : fluidInfo) + { + if (info != null) + if (info.fluid != null) + getNetwork().fluidGraph.queue(info.fluid.amount); + } + } + } + + if (tileEntity instanceof IPressureNodeProvider) + { + getNetwork().pressureGraph.queue(((IPressureNodeProvider) tileEntity).getNode(FluidPressureNode.class, receivingSide).getPressure(receivingSide)); + } + + getNetwork().energyGraph.queue(CompatibilityModule.getEnergy(tileEntity, receivingSide)); + + /** Update Energy Capacity Graph */ + getNetwork().energyCapacityGraph.queue(CompatibilityModule.getMaxEnergy(tileEntity, receivingSide)); + } + + @Override + public void readDesc(MCDataInput packet) + { + packet.readByte(); + placementSide = ForgeDirection.getOrientation(packet.readByte()); + facing = packet.readByte(); + detectMode = DetectMode.values()[packet.readByte()]; + detectType = packet.readByte(); + graphType = packet.readByte(); + getNetwork().center = new universalelectricity.api.vector.Vector3(packet.readNBTTagCompound()); + getNetwork().size = new universalelectricity.api.vector.Vector3(packet.readNBTTagCompound()); + getNetwork().isEnabled = packet.readBoolean(); + } + + @Override + public void writeDesc(MCDataOutput packet) + { + packet.writeByte(0); + packet.writeByte(placementSide.ordinal()); + packet.writeByte(facing); + packet.writeByte(detectMode.ordinal()); + packet.writeByte(detectType); + packet.writeByte(graphType); + packet.writeNBTTagCompound(getNetwork().center.writeToNBT(new NBTTagCompound())); + packet.writeNBTTagCompound(getNetwork().size.writeToNBT(new NBTTagCompound())); + packet.writeBoolean(getNetwork().isEnabled); + } + + public void writeGraph(MCDataOutput packet) + { + packet.writeByte(2); + isPrimary = getNetwork().isPrimary(this); + packet.writeBoolean(isPrimary); + + if (isPrimary) + packet.writeNBTTagCompound(getNetwork().save()); + } + + @Override + public void read(MCDataInput packet) + { + read(packet, packet.readUByte()); + } + + public void read(MCDataInput packet, int packetID) + { + switch (packetID) + { + case 0: + { + placementSide = ForgeDirection.getOrientation(packet.readByte()); + facing = packet.readByte(); + detectMode = DetectMode.values()[packet.readByte()]; + detectType = packet.readByte(); + graphType = packet.readByte(); + getNetwork().center = new universalelectricity.api.vector.Vector3(packet.readNBTTagCompound()); + getNetwork().size = new universalelectricity.api.vector.Vector3(packet.readNBTTagCompound()); + getNetwork().isEnabled = packet.readBoolean(); + refresh(); + break; + } + case 1: + { + redstoneTriggerLimit = packet.readLong(); + break; + } + case 2: + { + isPrimary = packet.readBoolean(); + + if (isPrimary) + getNetwork().load(packet.readNBTTagCompound()); + break; + } + } + } + + @Override + public void onReceivePacket(ByteArrayDataInput data, EntityPlayer player, Object... extra) + { + detectMode = DetectMode.values()[data.readByte()]; + detectType = data.readByte(); + graphType = data.readByte(); + redstoneTriggerLimit = data.readDouble(); + } + + public TileEntity getDetectedTile() + { + ForgeDirection direction = getDirection(); + return world().getBlockTileEntity(x() + direction.offsetX, y() + direction.offsetY, z() + direction.offsetZ); + } + + public ForgeDirection getDirection() + { + return ForgeDirection.getOrientation(this.placementSide.ordinal()); + } + + public void toggleGraphType() + { + graphType = (byte) ((graphType + 1) % getNetwork().graphs.size()); + updateServer(); + } + + public void toggleMode() + { + detectMode = DetectMode.values()[(detectMode.ordinal() + 1) % DetectMode.values().length]; + updateServer(); + } + + public void toggleDetectionValue() + { + detectType = (byte) ((detectType + 1) % getNetwork().graphs.size()); + updateServer(); + } + + public void updateServer() + { + PacketDispatcher.sendPacketToServer(ResonantInduction.PACKET_MULTIPART.getPacket(new universalelectricity.api.vector.Vector3(x(), y(), z()), placementSide.ordinal(), (byte) detectMode.ordinal(), detectType, graphType, redstoneTriggerLimit)); + } + + @Override + public void load(NBTTagCompound nbt) + { + super.load(nbt); + placementSide = ForgeDirection.getOrientation(nbt.getByte("side")); + detectMode = DetectMode.values()[nbt.getByte("detectMode")]; + detectType = nbt.getByte("detectionType"); + graphType = nbt.getByte("graphType"); + doDetect = nbt.getBoolean("doDetect"); + redstoneTriggerLimit = nbt.getDouble("triggerLimit"); + } + + @Override + public void save(NBTTagCompound nbt) + { + super.save(nbt); + nbt.setByte("side", (byte) placementSide.ordinal()); + nbt.setByte("detectMode", (byte) detectMode.ordinal()); + nbt.setByte("detectionType", detectType); + nbt.setByte("graphType", graphType); + nbt.setBoolean("doDetect", doDetect); + nbt.setDouble("triggerLimit", redstoneTriggerLimit); + } + + public DetectMode getMode() + { + return detectMode; + } + + @Override + public String getType() + { + return "resonant_induction_multimeter"; + } + + @Override + public int redstoneConductionMap() + { + return 0x1F; + } + + @Override + public boolean solid(int arg0) + { + return true; + } + + @Override + protected ItemStack getItem() + { + return new ItemStack(Electrical.itemMultimeter); + } + + @Override + @SideOnly(Side.CLIENT) + public void renderDynamic(Vector3 pos, float frame, int pass) + { + if (pass == 0) + { + RenderMultimeter.render(this, pos.x, pos.y, pos.z); + } + } + + @Override + public boolean canConnectRedstone(int arg0) + { + return true; + } + + @Override + public int strongPowerLevel(int arg0) + { + return redstoneOn ? 14 : 0; + } + + @Override + public int weakPowerLevel(int arg0) + { + return redstoneOn ? 14 : 0; + } + + @Override + public MultimeterNetwork getNetwork() + { + if (network == null) + { + network = new MultimeterNetwork(); + network.addConnector(this); + } + + return network; + } + + @Override + public void setNetwork(MultimeterNetwork network) + { + this.network = network; + } + + @Override + public boolean canConnect(ForgeDirection direction, Object obj) + { + return obj instanceof PartMultimeter; + } + + @Override + public Object[] getConnections() + { + Object[] connections = new Object[6]; + + for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) + { + if (dir != getDirection() && dir != getDirection().getOpposite()) + { + universalelectricity.api.vector.Vector3 vector = getPosition().translate(dir); + + if (hasMultimeter(vector.intX(), vector.intY(), vector.intZ())) + { + connections[dir.ordinal()] = getMultimeter(vector.intX(), vector.intY(), vector.intZ()); + } + } + } + + return connections; + } + + @Override + public IConnector getInstance(ForgeDirection dir) + { + return this; + } + + public universalelectricity.api.vector.Vector3 getPosition() + { + return new universalelectricity.api.vector.Vector3(x(), y(), z()); + } + + @Override + @SideOnly(Side.CLIENT) + public Cuboid6 getRenderBounds() + { + if (isPrimary) + return Cuboid6.full.copy().expand(new Vector3(getNetwork().size.x, getNetwork().size.y, getNetwork().size.z)); + return Cuboid6.full; + } + + @Override + public String toString() + { + return "[PartMultimeter]" + x() + "x " + y() + "y " + z() + "z " + getSlotMask() + "s "; + } } diff --git a/electrical/src/main/scala/resonantinduction/electrical/wire/PartAdvancedWire.java b/electrical/src/main/scala/resonantinduction/electrical/wire/PartAdvancedWire.java index 040a5ec4f..05bdfa948 100644 --- a/electrical/src/main/scala/resonantinduction/electrical/wire/PartAdvancedWire.java +++ b/electrical/src/main/scala/resonantinduction/electrical/wire/PartAdvancedWire.java @@ -343,4 +343,10 @@ public abstract class PartAdvancedWire extends PartConductor return false; } + + @Override + public String toString() + { + return "[PartAdvancedWire]" + x() + "x " + y() + "y " + z() + "z "; + } } diff --git a/electrical/src/main/scala/resonantinduction/electrical/wire/PartConductor.java b/electrical/src/main/scala/resonantinduction/electrical/wire/PartConductor.java index 3f2beb2d0..17a38214e 100644 --- a/electrical/src/main/scala/resonantinduction/electrical/wire/PartConductor.java +++ b/electrical/src/main/scala/resonantinduction/electrical/wire/PartConductor.java @@ -22,173 +22,169 @@ import codechicken.multipart.TMultiPart; @Deprecated public abstract class PartConductor extends PartAdvanced implements IConductor { - private IEnergyNetwork network; + private IEnergyNetwork network; - protected Object[] connections = new Object[6]; + protected Object[] connections = new Object[6]; - /** - * Universal Electricity conductor functions. - */ - @Override - public long onReceiveEnergy(ForgeDirection from, long receive, boolean doReceive) - { - return this.getNetwork().produce(this, from.getOpposite(), receive, doReceive); - } + /** Universal Electricity conductor functions. */ + @Override + public long onReceiveEnergy(ForgeDirection from, long receive, boolean doReceive) + { + return this.getNetwork().produce(this, from.getOpposite(), receive, doReceive); + } - @Override - public long onExtractEnergy(ForgeDirection from, long request, boolean doExtract) - { - return 0; - } + @Override + public long onExtractEnergy(ForgeDirection from, long request, boolean doExtract) + { + return 0; + } - @Override - public IEnergyNetwork getNetwork() - { - if (this.network == null) - { - this.setNetwork(EnergyNetworkLoader.getNewNetwork(this)); - } + @Override + public IEnergyNetwork getNetwork() + { + if (this.network == null) + { + this.setNetwork(EnergyNetworkLoader.getNewNetwork(this)); + } - return this.network; - } + return this.network; + } - @Override - public void setNetwork(IEnergyNetwork network) - { - this.network = network; - } + @Override + public void setNetwork(IEnergyNetwork network) + { + this.network = network; + } - @Override - public boolean doesTick() - { - return false; - } + @Override + public boolean doesTick() + { + return false; + } - @Override - public Object[] getConnections() - { - return this.connections; - } + @Override + public Object[] getConnections() + { + return this.connections; + } - /** - * EXTERNAL USE Can this wire be connected by another block? - */ - @Override - public boolean canConnect(ForgeDirection direction, Object source) - { - Vector3 connectPos = new Vector3(tile()).translate(direction); - TileEntity connectTile = connectPos.getTileEntity(world()); + /** EXTERNAL USE Can this wire be connected by another block? */ + @Override + public boolean canConnect(ForgeDirection direction, Object source) + { + Vector3 connectPos = new Vector3(tile()).translate(direction); + TileEntity connectTile = connectPos.getTileEntity(world()); - if (connectTile instanceof IConductor) - { - return false; - } + if (connectTile instanceof IConductor) + { + return false; + } - return CompatibilityModule.isHandler(connectTile); - } + return CompatibilityModule.isHandler(connectTile); + } - public abstract boolean canConnectTo(Object obj); + public abstract boolean canConnectTo(Object obj); - /** - * Recalculates all the network connections - */ - protected void recalculateConnections() - { - this.connections = new Object[6]; - /** - * Calculate all external connections with this conductor. - */ - for (byte i = 0; i < 6; i++) - { - ForgeDirection side = ForgeDirection.getOrientation(i); + /** Recalculates all the network connections */ + protected void recalculateConnections() + { + this.connections = new Object[6]; + /** Calculate all external connections with this conductor. */ + for (byte i = 0; i < 6; i++) + { + ForgeDirection side = ForgeDirection.getOrientation(i); - if (this.canConnect(side, this)) - { - TileEntity tileEntity = VectorHelper.getTileEntityFromSide(world(), new Vector3(tile()), side); - connections[i] = tileEntity; - } - } - } + if (this.canConnect(side, this)) + { + TileEntity tileEntity = VectorHelper.getTileEntityFromSide(world(), new Vector3(tile()), side); + connections[i] = tileEntity; + } + } + } - /** - * IC2 Functions - */ - @Override - public void onWorldJoin() - { - if (tile() instanceof IEnergyTile && !world().isRemote) - { - // Check if there's another part that's an IEnergyTile - boolean foundAnotherPart = false; + /** IC2 Functions */ + @Override + public void onWorldJoin() + { + if (tile() instanceof IEnergyTile && !world().isRemote) + { + // Check if there's another part that's an IEnergyTile + boolean foundAnotherPart = false; - for (int i = 0; i < tile().partList().size(); i++) - { - TMultiPart part = tile().partMap(i); + for (int i = 0; i < tile().partList().size(); i++) + { + TMultiPart part = tile().partMap(i); - if (part instanceof IEnergyTile && part != this) - { - foundAnotherPart = true; - break; - } - } + if (part instanceof IEnergyTile && part != this) + { + foundAnotherPart = true; + break; + } + } - if (!foundAnotherPart) - { - MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent((IEnergyTile) tile())); - } - } - } + if (!foundAnotherPart) + { + MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent((IEnergyTile) tile())); + } + } + } - @Override - public void preRemove() - { - if (!world().isRemote) - { - this.getNetwork().split(this); + @Override + public void preRemove() + { + if (!world().isRemote) + { + this.getNetwork().split(this); - if (tile() instanceof IEnergyTile) - { - // Check if there's another part that's an IEnergyTile - boolean foundAnotherPart = false; + if (tile() instanceof IEnergyTile) + { + // Check if there's another part that's an IEnergyTile + boolean foundAnotherPart = false; - for (int i = 0; i < tile().partList().size(); i++) - { - TMultiPart part = tile().partMap(i); + for (int i = 0; i < tile().partList().size(); i++) + { + TMultiPart part = tile().partMap(i); - if (part instanceof IEnergyTile && part != this) - { - foundAnotherPart = true; - break; - } - } + if (part instanceof IEnergyTile && part != this) + { + foundAnotherPart = true; + break; + } + } - if (!foundAnotherPart) - { - MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent((IEnergyTile) tile())); - } - } - } + if (!foundAnotherPart) + { + MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent((IEnergyTile) tile())); + } + } + } - super.preRemove(); - } + super.preRemove(); + } - @Override - public IConnector getInstance(ForgeDirection dir) - { - return this; - } + @Override + public IConnector getInstance(ForgeDirection dir) + { + return this; + } - @Override - public void save(NBTTagCompound nbt) - { - super.save(nbt); - nbt.setLong("savedBuffer", getNetwork().getBufferOf(this)); - } + @Override + public void save(NBTTagCompound nbt) + { + super.save(nbt); + nbt.setLong("savedBuffer", getNetwork().getBufferOf(this)); + } - @Override - public void load(NBTTagCompound nbt) - { - super.load(nbt); - getNetwork().setBufferFor(this, nbt.getLong("savedBuffer")); - } + @Override + public void load(NBTTagCompound nbt) + { + super.load(nbt); + getNetwork().setBufferFor(this, nbt.getLong("savedBuffer")); + } + + @Override + public String toString() + { + return "[PartConductor]" + x() + "x " + y() + "y " + z() + "z "; + } } diff --git a/electrical/src/main/scala/resonantinduction/electrical/wire/flat/PartFlatWire.java b/electrical/src/main/scala/resonantinduction/electrical/wire/flat/PartFlatWire.java index c09eed39b..b11926df0 100644 --- a/electrical/src/main/scala/resonantinduction/electrical/wire/flat/PartFlatWire.java +++ b/electrical/src/main/scala/resonantinduction/electrical/wire/flat/PartFlatWire.java @@ -41,935 +41,925 @@ import codechicken.multipart.TileMultipart; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -/** - * This is the base class for all wire types. It can be used for any sub type, as it contains the +/** This is the base class for all wire types. It can be used for any sub type, as it contains the * base calculations necessary to create a working wire. This calculates all possible connections to * sides, around corners, and inside corners, while checking for microblock obstructions. * - * @author Modified by Calclavia, MrTJP - */ + * @author Modified by Calclavia, MrTJP */ public class PartFlatWire extends PartAdvancedWire implements TFacePart, JNormalOcclusion { - public static Cuboid6[][] selectionBounds = new Cuboid6[3][6]; - public static Cuboid6[][] occlusionBounds = new Cuboid6[3][6]; - - static - { - for (int t = 0; t < 3; t++) - { - // Subtract the box a little because we'd like things like posts to get first hit - Cuboid6 selection = new Cuboid6(0, 0, 0, 1, (t + 2) / 16D, 1).expand(-0.005); - Cuboid6 occlusion = new Cuboid6(2 / 8D, 0, 2 / 8D, 6 / 8D, (t + 2) / 16D, 6 / 8D); - for (int s = 0; s < 6; s++) - { - selectionBounds[t][s] = selection.copy().apply(Rotation.sideRotations[s].at(Vector3.center)); - occlusionBounds[t][s] = occlusion.copy().apply(Rotation.sideRotations[s].at(Vector3.center)); - } - } - } - - public byte side; - - /** - * A map of the corners. - * - * - * Currently split into 4 nybbles (from lowest) 0 = Corner connections (this wire should connect - * around a corner to something external) 1 = Straight connections (this wire should connect to - * something external) 2 = Internal connections (this wire should connect to something internal) - * 3 = Internal open connections (this wire is not blocked by a cover/edge part and *could* - * connect through side) bit 16 = connection to the centerpart 5 = Render corner connections. - * Like corner connections but set to low if the other wire part is smaller than this (they - * render to us not us to them) - */ - public int connMap; - - public PartFlatWire() - { - - } - - public PartFlatWire(int typeID) - { - this(EnumWireMaterial.values()[typeID]); - } - - public PartFlatWire(EnumWireMaterial type) - { - material = type; - } - - public void preparePlacement(int side, int meta) - { - this.side = (byte) (side ^ 1); - this.setMaterial(meta); - } - - /** PACKET and NBT Methods */ - @Override - public void load(NBTTagCompound tag) - { - super.load(tag); - this.side = tag.getByte("side"); - this.connMap = tag.getInteger("connMap"); - } - - @Override - public void save(NBTTagCompound tag) - { - super.save(tag); - tag.setByte("side", this.side); - tag.setInteger("connMap", this.connMap); - } - - @Override - public void readDesc(MCDataInput packet) - { - super.readDesc(packet); - this.side = packet.readByte(); - this.connMap = packet.readInt(); - } - - @Override - public void writeDesc(MCDataOutput packet) - { - super.writeDesc(packet); - packet.writeByte(this.side); - packet.writeInt(this.connMap); - } - - @Override - public void read(MCDataInput packet) - { - read(packet, packet.readUByte()); - } - - @Override - public void read(MCDataInput packet, int packetID) - { - if (packetID == 0) - { - this.connMap = packet.readInt(); - tile().markRender(); - } - else - { - super.read(packet, packetID); - } - } - - public void sendConnUpdate() - { - tile().getWriteStream(this).writeByte(0).writeInt(this.connMap); - } - - /* WORLD EVENTS */ - @Override - public void onRemoved() - { - super.onRemoved(); - - if (!world().isRemote) - { - for (int r = 0; r < 4; r++) - { - if (maskConnects(r)) - { - if ((connMap & 1 << r) != 0) - { - notifyCornerChange(r); - } - else if ((connMap & 0x10 << r) != 0) - { - notifyStraightChange(r); - } - } - } - } - } - - @Override - public void onChunkLoad() - { - if ((connMap & 0x80000000) != 0) // compat with converters, recalc connections - { - if (dropIfCantStay()) - { - return; - } - - connMap = 0; - - updateInternalConnections(); - - if (updateOpenConnections()) - { - updateExternalConnections(); - } - - tile().markDirty(); - } - - this.recalculateConnections(); - - super.onChunkLoad(); - } - - @Override - public void onAdded() - { - super.onAdded(); - - if (!world().isRemote) - { - updateOpenConnections(); - boolean changed = updateInternalConnections(); - // don't use || because it's fail fast - changed |= updateExternalConnections(); - - if (changed) - { - sendConnUpdate(); - } - - this.recalculateConnections(); - } - } - - @Override - public void onPartChanged(TMultiPart part) - { - if (!world().isRemote) - { - boolean changed = updateInternalConnections(); - - if (updateOpenConnections()) - { - changed |= updateExternalConnections(); - } - - if (changed) - { - sendConnUpdate(); - } - - this.recalculateConnections(); - } - - super.onPartChanged(part); - } - - @Override - public void onNeighborChanged() - { - if (!world().isRemote) - { - if (dropIfCantStay()) - { - return; - } - - if (updateExternalConnections()) - { - sendConnUpdate(); - } - - this.recalculateConnections(); - } - super.onNeighborChanged(); - } - - @Override - public boolean activate(EntityPlayer player, MovingObjectPosition part, ItemStack item) - { - if (item != null) - { - if (item.getItem().itemID == Block.lever.blockID) - { - TileMultipart tile = tile(); - World w = world(); - - if (!w.isRemote) - { - PartFlatSwitchWire wire = (PartFlatSwitchWire) MultiPartRegistry.createPart("resonant_induction_flat_switch_wire", false); - wire.copyFrom(this); - - if (tile.canReplacePart(this, wire)) - { - tile.remPart(this); - TileMultipart.addPart(w, new BlockCoord(tile), wire); - - if (!player.capabilities.isCreativeMode) - { - player.inventory.decrStackSize(player.inventory.currentItem, 1); - } - } - } - return true; - } - } - - return super.activate(player, part, item); - } - - @Override - public void recalculateConnections() - { - this.updateOpenConnections(); - - boolean[] calculatedSides = new boolean[6]; - - /** Check external connections. */ - for (byte r = 0; r < 4; r++) - { - if (maskOpen(r)) - { - int absDir = Rotation.rotateSide(this.side, r); - - // Check direct connection. - if (this.setExternalConnection(r, absDir)) - { - calculatedSides[absDir] = true; - } - - // Check Corner Connection - BlockCoord cornerPos = new BlockCoord(tile()); - cornerPos.offset(absDir); - - if (canConnectThroughCorner(cornerPos, absDir ^ 1, this.side)) - { - cornerPos.offset(this.side); - TileMultipart tpCorner = MultipartUtility.getMultipartTile(world(), cornerPos); - - if (tpCorner != null) - { - TMultiPart tp = tpCorner.partMap(absDir ^ 1); - - if (this.canConnectTo(tp, ForgeDirection.getOrientation(absDir))) - { - this.connections[absDir] = tp; - - if (tp instanceof PartFlatWire) - { - // We found a wire, merge networks! - this.getNetwork().merge(((PartFlatWire) tp).getNetwork()); - } - - calculatedSides[absDir] = true; - continue; - } - } - } - - if (!calculatedSides[absDir]) - { - this.disconnect(absDir); - } - } - } - - /** Check internal connections. */ - for (byte r = 0; r < 4; r++) - { - int absDir = Rotation.rotateSide(this.side, r); - - /** Look for an internal straight connection. */ - if (tile().partMap(PartMap.edgeBetween(absDir, this.side)) == null) - { - TMultiPart tp = tile().partMap(absDir); - - if (this.canConnectTo(tp)) - { - // We found a wire! Merge networks! - this.connections[absDir] = tp; - - if (tp instanceof PartFlatWire) - { - this.getNetwork().merge(((PartFlatWire) tp).getNetwork()); - } - continue; - } - } - - if (!calculatedSides[absDir]) - { - this.disconnect(absDir); - } - } - - // Connect to the face of the block the wire is placed on. - this.setExternalConnection(-1, this.side); - - this.getNetwork().reconstruct(); - } - - public boolean setExternalConnection(int r, int absSide) - { - BlockCoord pos = new BlockCoord(tile()).offset(absSide); - - /** Look for an external wire connection. */ - TileMultipart tileMultiPart = MultipartUtility.getMultipartTile(world(), pos); - - if (tileMultiPart != null && r != -1) - { - TMultiPart tp = tileMultiPart.partMap(this.side); - - if (this.canConnectTo(tp, ForgeDirection.getOrientation(absSide))) - { - // Check the wire we are connecting to and see if THAT block can accept this one. - int otherR = (r + 2) % 4; - - if (tp instanceof PartFlatWire && ((PartFlatWire) tp).canConnectTo(this, ForgeDirection.getOrientation(absSide).getOpposite()) && ((PartFlatWire) tp).maskOpen(otherR)) - { - // We found a wire! Merge connection. - connections[absSide] = tp; - getNetwork().merge(((PartFlatWire) tp).getNetwork()); - return true; - } - - /** - * Check for a micro-energy block - */ - if (canConnectTo(tp)) - { - connections[absSide] = tp; - return true; - } - } - - this.disconnect(absSide); - } - - /** Look for an external energy handler. */ - TileEntity tileEntity = world().getBlockTileEntity(pos.x, pos.y, pos.z); - - if (this.canConnectTo(tileEntity, ForgeDirection.getOrientation(absSide))) - { - this.connections[absSide] = tileEntity; - return true; - } - - this.disconnect(absSide); - - return false; - } - - private synchronized void disconnect(int i) - { - if (!this.world().isRemote) - { - if (this.connections[i] != null) - { - if (this.connections[i] instanceof PartFlatWire) - { - PartFlatWire wire = (PartFlatWire) this.connections[i]; - this.connections[i] = null; - this.getNetwork().split(this, wire); - } - else - { - this.connections[i] = null; - } - } - } - } - - @Override - public Object[] getConnections() - { - return this.connections; - } - - public boolean canStay() - { - BlockCoord pos = new BlockCoord(tile()).offset(side); - return MultipartUtility.canPlaceWireOnSide(world(), pos.x, pos.y, pos.z, ForgeDirection.getOrientation(side ^ 1), false); - } - - public boolean dropIfCantStay() - { - if (!canStay()) - { - drop(); - return true; - } - return false; - } - - public void drop() - { - TileMultipart.dropItem(getItem(), world(), Vector3.fromTileEntityCenter(tile())); - tile().remPart(this); - } - - /** - * Recalculates connections to blocks outside this space - * - * @return true if a new connection was added or one was removed - */ - protected boolean updateExternalConnections() - { - int newConn = 0; - - for (int r = 0; r < 4; r++) - { - if (!maskOpen(r)) - { - continue; - } - - if (connectStraight(r)) - { - newConn |= 0x10 << r; - } - else - { - int cnrMode = connectCorner(r); - - if (cnrMode != 0) - { - newConn |= 1 << r; - - if (cnrMode == 2) - { - newConn |= 0x100000 << r;// render flag - } - } - } - } - - if (newConn != (connMap & 0xF000FF)) - { - int diff = connMap ^ newConn; - connMap = connMap & ~0xF000FF | newConn; - - // Notify corner disconnections - for (int r = 0; r < 4; r++) - { - if ((diff & 1 << r) != 0) - { - notifyCornerChange(r); - } - } - - return true; - } - - return false; - } - - /** - * Recalculates connections to other parts within this space - * - * @return true if a new connection was added or one was removed - */ - protected boolean updateInternalConnections() - { - int newConn = 0; - for (int r = 0; r < 4; r++) - { - if (connectInternal(r)) - { - newConn |= 0x100 << r; - } - } - - if (connectCenter()) - { - newConn |= 0x10000; - } - - if (newConn != (connMap & 0x10F00)) - { - connMap = connMap & ~0x10F00 | newConn; - return true; - } - return false; - } - - /** - * Recalculates connections that can be made to other parts outside of this space - * - * @return true if external connections should be recalculated - */ - protected boolean updateOpenConnections() - { - int newConn = 0; - for (int r = 0; r < 4; r++) - if (connectionOpen(r)) - newConn |= 0x1000 << r; - - if (newConn != (connMap & 0xF000)) - { - connMap = connMap & ~0xF000 | newConn; - return true; - } - return false; - } - - public boolean connectionOpen(int r) - { - int absDir = Rotation.rotateSide(side, r); - TMultiPart facePart = tile().partMap(absDir); - if (facePart != null && (!(facePart instanceof PartFlatWire) || !canConnectTo(facePart, ForgeDirection.getOrientation(absDir)))) - return false; - - if (tile().partMap(PartMap.edgeBetween(side, absDir)) != null) - return false; - - return true; - } - - /** - * Return a corner connection state. 0 = No connection 1 = Physical connection 2 = Render - * connection - */ - public int connectCorner(int r) - { - int absDir = Rotation.rotateSide(side, r); - - BlockCoord pos = new BlockCoord(tile()); - pos.offset(absDir); - - if (!canConnectThroughCorner(pos, absDir ^ 1, side)) - return 0; - - pos.offset(side); - TileMultipart t = MultipartUtility.getMultipartTile(world(), pos); - if (t != null) - { - TMultiPart tp = t.partMap(absDir ^ 1); - - if (canConnectTo(tp, ForgeDirection.getOrientation(absDir))) - { - if (tp instanceof PartFlatWire) - { - boolean b = ((PartFlatWire) tp).connectCorner(this, Rotation.rotationTo(absDir ^ 1, side ^ 1)); - - if (b) - { - // let them connect to us - if (!renderThisCorner((PartFlatWire) tp)) - { - return 1; - } - - return 2; - } - } - - return 2; - } - } - return 0; - } - - public boolean canConnectThroughCorner(BlockCoord pos, int side1, int side2) - { - if (world().isAirBlock(pos.x, pos.y, pos.z)) - { - return true; - } - - TileMultipart t = MultipartUtility.getMultipartTile(world(), pos); - if (t != null) - { - return t.partMap(side1) == null && t.partMap(side2) == null && t.partMap(PartMap.edgeBetween(side1, side2)) == null; - } - - return false; - } - - public boolean connectStraight(int r) - { - int absDir = Rotation.rotateSide(side, r); - - BlockCoord pos = new BlockCoord(tile()).offset(absDir); - - TileMultipart t = MultipartUtility.getMultipartTile(world(), pos); - if (t != null) - { - TMultiPart tp = t.partMap(side); - - if (this.canConnectTo(tp, ForgeDirection.getOrientation(absDir))) - { - if (tp instanceof PartFlatWire) - { - return ((PartFlatWire) tp).connectStraight(this, (r + 2) % 4); - } - - return true; - } - } - else - { - TileEntity tileEntity = world().getBlockTileEntity(pos.x, pos.y, pos.z); - return this.canConnectTo(tileEntity, ForgeDirection.getOrientation(absDir)); - } - - return false; - } - - public boolean connectInternal(int r) - { - int absDir = Rotation.rotateSide(side, r); - - if (tile().partMap(PartMap.edgeBetween(absDir, side)) != null) - return false; - - TMultiPart tp = tile().partMap(absDir); - - if (this.canConnectTo(tp, ForgeDirection.getOrientation(absDir))) - { - return ((PartFlatWire) tp).connectInternal(this, Rotation.rotationTo(absDir, side)); - } - - return connectInternalOverride(tp, r); - } - - public boolean connectInternalOverride(TMultiPart p, int r) - { - return false; - } - - public boolean connectCenter() - { - TMultiPart tp = tile().partMap(6); - - if (this.canConnectTo(tp)) - { - if (tp instanceof PartFlatWire) - { - return ((PartFlatWire) tp).connectInternal(this, side); - } - - return true; - } - - return false; - } - - public boolean renderThisCorner(PartFlatWire part) - { - if (!(part instanceof PartFlatWire)) - return false; - - PartFlatWire wire = part; - if (wire.getThickness() == getThickness()) - return side < wire.side; - - return wire.getThickness() > getThickness(); - } - - public boolean connectCorner(PartFlatWire wire, int r) - { - int absDir = Rotation.rotateSide(side, r); - - if (this.canConnectTo(wire, ForgeDirection.getOrientation(absDir)) && maskOpen(r)) - { - int oldConn = connMap; - connMap |= 0x1 << r; - if (renderThisCorner(wire))// render connection - connMap |= 0x100000 << r; - - if (oldConn != connMap) - sendConnUpdate(); - return true; - } - return false; - } - - public boolean connectStraight(PartFlatWire wire, int r) - { - int absDir = Rotation.rotateSide(side, r); - - if (this.canConnectTo(wire, ForgeDirection.getOrientation(absDir)) && maskOpen(r)) - { - int oldConn = connMap; - connMap |= 0x10 << r; - if (oldConn != connMap) - sendConnUpdate(); - return true; - } - return false; - } - - public boolean connectInternal(PartFlatWire wire, int r) - { - int absDir = Rotation.rotateSide(side, r); - - if (this.canConnectTo(wire, ForgeDirection.getOrientation(absDir))) - { - int oldConn = connMap; - connMap |= 0x100 << r; - if (oldConn != connMap) - sendConnUpdate(); - return true; - } - return false; - } - - public boolean canConnectCorner(int r) - { - return true; - } - - public void notifyCornerChange(int r) - { - int absDir = Rotation.rotateSide(side, r); - - BlockCoord pos = new BlockCoord(tile()).offset(absDir).offset(side); - world().notifyBlockOfNeighborChange(pos.x, pos.y, pos.z, tile().getBlockType().blockID); - } - - public void notifyStraightChange(int r) - { - int absDir = Rotation.rotateSide(side, r); - - BlockCoord pos = new BlockCoord(tile()).offset(absDir); - world().notifyBlockOfNeighborChange(pos.x, pos.y, pos.z, tile().getBlockType().blockID); - } - - public boolean maskConnects(int r) - { - return (connMap & 0x111 << r) != 0; - } - - public boolean maskOpen(int r) - { - return (connMap & 0x1000 << r) != 0; - } - - /** START TILEMULTIPART INTERACTIONS **/ - @Override - public float getStrength(MovingObjectPosition hit, EntityPlayer player) - { - return 4; - } - - @Override - public int getSlotMask() - { - return 1 << this.side; - } - - @Override - public Iterable getSubParts() - { - return Arrays.asList(new IndexedCuboid6(0, selectionBounds[getThickness()][side])); - } - - @Override - public boolean occlusionTest(TMultiPart npart) - { - return NormalOcclusionTest.apply(this, npart); - } - - @Override - public Iterable getOcclusionBoxes() - { - return Arrays.asList(occlusionBounds[getThickness()][side]); - } - - public int getThickness() - { - return this.isInsulated ? 2 : 1; - } - - @Override - public int redstoneConductionMap() - { - return 0; - } - - @Override - public boolean solid(int arg0) - { - return false; - } - - @Override - public String getType() - { - return "resonant_induction_flat_wire"; - } - - /** RENDERING */ - @SideOnly(Side.CLIENT) - public Icon getIcon() - { - return RenderFlatWire.flatWireTexture; - } - - public Colour getColour() - { - if (isInsulated) - { - Colour color = new ColourARGB(ItemDye.dyeColors[this.color]); - color.a = (byte) 255; - return color; - } - - return getMaterial().color; - } - - public boolean useStaticRenderer() - { - return true; - } - - @Override - @SideOnly(Side.CLIENT) - public void renderStatic(Vector3 pos, LazyLightMatrix olm, int pass) - { - if (pass == 0 && useStaticRenderer()) - { - CCRenderState.setBrightness(world(), x(), y(), z()); - RenderFlatWire.render(this, pos); - CCRenderState.setColour(-1); - } - } - - @Override - @SideOnly(Side.CLIENT) - public void renderDynamic(Vector3 pos, float frame, int pass) - { - if (pass == 0 && !useStaticRenderer()) - { - GL11.glDisable(GL11.GL_LIGHTING); - TextureUtils.bindAtlas(0); - CCRenderState.useModelColours(true); - CCRenderState.startDrawing(7); - RenderFlatWire.render(this, pos); - CCRenderState.draw(); - CCRenderState.setColour(-1); - GL11.glEnable(GL11.GL_LIGHTING); - } - } - - @Override - @SideOnly(Side.CLIENT) - public void drawBreaking(RenderBlocks renderBlocks) - { - CCRenderState.reset(); - RenderFlatWire.renderBreakingOverlay(renderBlocks.overrideBlockTexture, this); - } - - /** - * Utility method to aid in initializing this or subclasses, usually when you need to change the - * wire to another type - * - * @param otherCable the wire to copy from - */ - public void copyFrom(PartFlatWire otherCable) - { - this.isInsulated = otherCable.isInsulated; - this.color = otherCable.color; - this.connections = otherCable.connections; - this.material = otherCable.material; - this.side = otherCable.side; - this.connMap = otherCable.connMap; - this.setNetwork(otherCable.getNetwork()); - this.getNetwork().setBufferFor(this, otherCable.getNetwork().getBufferOf(otherCable)); - } + public static Cuboid6[][] selectionBounds = new Cuboid6[3][6]; + public static Cuboid6[][] occlusionBounds = new Cuboid6[3][6]; + + static + { + for (int t = 0; t < 3; t++) + { + // Subtract the box a little because we'd like things like posts to get first hit + Cuboid6 selection = new Cuboid6(0, 0, 0, 1, (t + 2) / 16D, 1).expand(-0.005); + Cuboid6 occlusion = new Cuboid6(2 / 8D, 0, 2 / 8D, 6 / 8D, (t + 2) / 16D, 6 / 8D); + for (int s = 0; s < 6; s++) + { + selectionBounds[t][s] = selection.copy().apply(Rotation.sideRotations[s].at(Vector3.center)); + occlusionBounds[t][s] = occlusion.copy().apply(Rotation.sideRotations[s].at(Vector3.center)); + } + } + } + + public byte side; + + /** A map of the corners. + * + * + * Currently split into 4 nybbles (from lowest) 0 = Corner connections (this wire should connect + * around a corner to something external) 1 = Straight connections (this wire should connect to + * something external) 2 = Internal connections (this wire should connect to something internal) + * 3 = Internal open connections (this wire is not blocked by a cover/edge part and *could* + * connect through side) bit 16 = connection to the centerpart 5 = Render corner connections. + * Like corner connections but set to low if the other wire part is smaller than this (they + * render to us not us to them) */ + public int connMap; + + public PartFlatWire() + { + + } + + public PartFlatWire(int typeID) + { + this(EnumWireMaterial.values()[typeID]); + } + + public PartFlatWire(EnumWireMaterial type) + { + material = type; + } + + public void preparePlacement(int side, int meta) + { + this.side = (byte) (side ^ 1); + this.setMaterial(meta); + } + + /** PACKET and NBT Methods */ + @Override + public void load(NBTTagCompound tag) + { + super.load(tag); + this.side = tag.getByte("side"); + this.connMap = tag.getInteger("connMap"); + } + + @Override + public void save(NBTTagCompound tag) + { + super.save(tag); + tag.setByte("side", this.side); + tag.setInteger("connMap", this.connMap); + } + + @Override + public void readDesc(MCDataInput packet) + { + super.readDesc(packet); + this.side = packet.readByte(); + this.connMap = packet.readInt(); + } + + @Override + public void writeDesc(MCDataOutput packet) + { + super.writeDesc(packet); + packet.writeByte(this.side); + packet.writeInt(this.connMap); + } + + @Override + public void read(MCDataInput packet) + { + read(packet, packet.readUByte()); + } + + @Override + public void read(MCDataInput packet, int packetID) + { + if (packetID == 0) + { + this.connMap = packet.readInt(); + tile().markRender(); + } + else + { + super.read(packet, packetID); + } + } + + public void sendConnUpdate() + { + tile().getWriteStream(this).writeByte(0).writeInt(this.connMap); + } + + /* WORLD EVENTS */ + @Override + public void onRemoved() + { + super.onRemoved(); + + if (!world().isRemote) + { + for (int r = 0; r < 4; r++) + { + if (maskConnects(r)) + { + if ((connMap & 1 << r) != 0) + { + notifyCornerChange(r); + } + else if ((connMap & 0x10 << r) != 0) + { + notifyStraightChange(r); + } + } + } + } + } + + @Override + public void onChunkLoad() + { + if ((connMap & 0x80000000) != 0) // compat with converters, recalc connections + { + if (dropIfCantStay()) + { + return; + } + + connMap = 0; + + updateInternalConnections(); + + if (updateOpenConnections()) + { + updateExternalConnections(); + } + + tile().markDirty(); + } + + this.recalculateConnections(); + + super.onChunkLoad(); + } + + @Override + public void onAdded() + { + super.onAdded(); + + if (!world().isRemote) + { + updateOpenConnections(); + boolean changed = updateInternalConnections(); + // don't use || because it's fail fast + changed |= updateExternalConnections(); + + if (changed) + { + sendConnUpdate(); + } + + this.recalculateConnections(); + } + } + + @Override + public void onPartChanged(TMultiPart part) + { + if (!world().isRemote) + { + boolean changed = updateInternalConnections(); + + if (updateOpenConnections()) + { + changed |= updateExternalConnections(); + } + + if (changed) + { + sendConnUpdate(); + } + + this.recalculateConnections(); + } + + super.onPartChanged(part); + } + + @Override + public void onNeighborChanged() + { + if (!world().isRemote) + { + if (dropIfCantStay()) + { + return; + } + + if (updateExternalConnections()) + { + sendConnUpdate(); + } + + this.recalculateConnections(); + } + super.onNeighborChanged(); + } + + @Override + public boolean activate(EntityPlayer player, MovingObjectPosition part, ItemStack item) + { + if (item != null) + { + if (item.getItem().itemID == Block.lever.blockID) + { + TileMultipart tile = tile(); + World w = world(); + + if (!w.isRemote) + { + PartFlatSwitchWire wire = (PartFlatSwitchWire) MultiPartRegistry.createPart("resonant_induction_flat_switch_wire", false); + wire.copyFrom(this); + + if (tile.canReplacePart(this, wire)) + { + tile.remPart(this); + TileMultipart.addPart(w, new BlockCoord(tile), wire); + + if (!player.capabilities.isCreativeMode) + { + player.inventory.decrStackSize(player.inventory.currentItem, 1); + } + } + } + return true; + } + } + + return super.activate(player, part, item); + } + + @Override + public void recalculateConnections() + { + this.updateOpenConnections(); + + boolean[] calculatedSides = new boolean[6]; + + /** Check external connections. */ + for (byte r = 0; r < 4; r++) + { + if (maskOpen(r)) + { + int absDir = Rotation.rotateSide(this.side, r); + + // Check direct connection. + if (this.setExternalConnection(r, absDir)) + { + calculatedSides[absDir] = true; + } + + // Check Corner Connection + BlockCoord cornerPos = new BlockCoord(tile()); + cornerPos.offset(absDir); + + if (canConnectThroughCorner(cornerPos, absDir ^ 1, this.side)) + { + cornerPos.offset(this.side); + TileMultipart tpCorner = MultipartUtility.getMultipartTile(world(), cornerPos); + + if (tpCorner != null) + { + TMultiPart tp = tpCorner.partMap(absDir ^ 1); + + if (this.canConnectTo(tp, ForgeDirection.getOrientation(absDir))) + { + this.connections[absDir] = tp; + + if (tp instanceof PartFlatWire) + { + // We found a wire, merge networks! + this.getNetwork().merge(((PartFlatWire) tp).getNetwork()); + } + + calculatedSides[absDir] = true; + continue; + } + } + } + + if (!calculatedSides[absDir]) + { + this.disconnect(absDir); + } + } + } + + /** Check internal connections. */ + for (byte r = 0; r < 4; r++) + { + int absDir = Rotation.rotateSide(this.side, r); + + /** Look for an internal straight connection. */ + if (tile().partMap(PartMap.edgeBetween(absDir, this.side)) == null) + { + TMultiPart tp = tile().partMap(absDir); + + if (this.canConnectTo(tp)) + { + // We found a wire! Merge networks! + this.connections[absDir] = tp; + + if (tp instanceof PartFlatWire) + { + this.getNetwork().merge(((PartFlatWire) tp).getNetwork()); + } + continue; + } + } + + if (!calculatedSides[absDir]) + { + this.disconnect(absDir); + } + } + + // Connect to the face of the block the wire is placed on. + this.setExternalConnection(-1, this.side); + + this.getNetwork().reconstruct(); + } + + public boolean setExternalConnection(int r, int absSide) + { + BlockCoord pos = new BlockCoord(tile()).offset(absSide); + + /** Look for an external wire connection. */ + TileMultipart tileMultiPart = MultipartUtility.getMultipartTile(world(), pos); + + if (tileMultiPart != null && r != -1) + { + TMultiPart tp = tileMultiPart.partMap(this.side); + + if (this.canConnectTo(tp, ForgeDirection.getOrientation(absSide))) + { + // Check the wire we are connecting to and see if THAT block can accept this one. + int otherR = (r + 2) % 4; + + if (tp instanceof PartFlatWire && ((PartFlatWire) tp).canConnectTo(this, ForgeDirection.getOrientation(absSide).getOpposite()) && ((PartFlatWire) tp).maskOpen(otherR)) + { + // We found a wire! Merge connection. + connections[absSide] = tp; + getNetwork().merge(((PartFlatWire) tp).getNetwork()); + return true; + } + + /** Check for a micro-energy block */ + if (canConnectTo(tp)) + { + connections[absSide] = tp; + return true; + } + } + + this.disconnect(absSide); + } + + /** Look for an external energy handler. */ + TileEntity tileEntity = world().getBlockTileEntity(pos.x, pos.y, pos.z); + + if (this.canConnectTo(tileEntity, ForgeDirection.getOrientation(absSide))) + { + this.connections[absSide] = tileEntity; + return true; + } + + this.disconnect(absSide); + + return false; + } + + private synchronized void disconnect(int i) + { + if (!this.world().isRemote) + { + if (this.connections[i] != null) + { + if (this.connections[i] instanceof PartFlatWire) + { + PartFlatWire wire = (PartFlatWire) this.connections[i]; + this.connections[i] = null; + this.getNetwork().split(this, wire); + } + else + { + this.connections[i] = null; + } + } + } + } + + @Override + public Object[] getConnections() + { + return this.connections; + } + + public boolean canStay() + { + BlockCoord pos = new BlockCoord(tile()).offset(side); + return MultipartUtility.canPlaceWireOnSide(world(), pos.x, pos.y, pos.z, ForgeDirection.getOrientation(side ^ 1), false); + } + + public boolean dropIfCantStay() + { + if (!canStay()) + { + drop(); + return true; + } + return false; + } + + public void drop() + { + TileMultipart.dropItem(getItem(), world(), Vector3.fromTileEntityCenter(tile())); + tile().remPart(this); + } + + /** Recalculates connections to blocks outside this space + * + * @return true if a new connection was added or one was removed */ + protected boolean updateExternalConnections() + { + int newConn = 0; + + for (int r = 0; r < 4; r++) + { + if (!maskOpen(r)) + { + continue; + } + + if (connectStraight(r)) + { + newConn |= 0x10 << r; + } + else + { + int cnrMode = connectCorner(r); + + if (cnrMode != 0) + { + newConn |= 1 << r; + + if (cnrMode == 2) + { + newConn |= 0x100000 << r;// render flag + } + } + } + } + + if (newConn != (connMap & 0xF000FF)) + { + int diff = connMap ^ newConn; + connMap = connMap & ~0xF000FF | newConn; + + // Notify corner disconnections + for (int r = 0; r < 4; r++) + { + if ((diff & 1 << r) != 0) + { + notifyCornerChange(r); + } + } + + return true; + } + + return false; + } + + /** Recalculates connections to other parts within this space + * + * @return true if a new connection was added or one was removed */ + protected boolean updateInternalConnections() + { + int newConn = 0; + for (int r = 0; r < 4; r++) + { + if (connectInternal(r)) + { + newConn |= 0x100 << r; + } + } + + if (connectCenter()) + { + newConn |= 0x10000; + } + + if (newConn != (connMap & 0x10F00)) + { + connMap = connMap & ~0x10F00 | newConn; + return true; + } + return false; + } + + /** Recalculates connections that can be made to other parts outside of this space + * + * @return true if external connections should be recalculated */ + protected boolean updateOpenConnections() + { + int newConn = 0; + for (int r = 0; r < 4; r++) + if (connectionOpen(r)) + newConn |= 0x1000 << r; + + if (newConn != (connMap & 0xF000)) + { + connMap = connMap & ~0xF000 | newConn; + return true; + } + return false; + } + + public boolean connectionOpen(int r) + { + int absDir = Rotation.rotateSide(side, r); + TMultiPart facePart = tile().partMap(absDir); + if (facePart != null && (!(facePart instanceof PartFlatWire) || !canConnectTo(facePart, ForgeDirection.getOrientation(absDir)))) + return false; + + if (tile().partMap(PartMap.edgeBetween(side, absDir)) != null) + return false; + + return true; + } + + /** Return a corner connection state. 0 = No connection 1 = Physical connection 2 = Render + * connection */ + public int connectCorner(int r) + { + int absDir = Rotation.rotateSide(side, r); + + BlockCoord pos = new BlockCoord(tile()); + pos.offset(absDir); + + if (!canConnectThroughCorner(pos, absDir ^ 1, side)) + return 0; + + pos.offset(side); + TileMultipart t = MultipartUtility.getMultipartTile(world(), pos); + if (t != null) + { + TMultiPart tp = t.partMap(absDir ^ 1); + + if (canConnectTo(tp, ForgeDirection.getOrientation(absDir))) + { + if (tp instanceof PartFlatWire) + { + boolean b = ((PartFlatWire) tp).connectCorner(this, Rotation.rotationTo(absDir ^ 1, side ^ 1)); + + if (b) + { + // let them connect to us + if (!renderThisCorner((PartFlatWire) tp)) + { + return 1; + } + + return 2; + } + } + + return 2; + } + } + return 0; + } + + public boolean canConnectThroughCorner(BlockCoord pos, int side1, int side2) + { + if (world().isAirBlock(pos.x, pos.y, pos.z)) + { + return true; + } + + TileMultipart t = MultipartUtility.getMultipartTile(world(), pos); + if (t != null) + { + return t.partMap(side1) == null && t.partMap(side2) == null && t.partMap(PartMap.edgeBetween(side1, side2)) == null; + } + + return false; + } + + public boolean connectStraight(int r) + { + int absDir = Rotation.rotateSide(side, r); + + BlockCoord pos = new BlockCoord(tile()).offset(absDir); + + TileMultipart t = MultipartUtility.getMultipartTile(world(), pos); + if (t != null) + { + TMultiPart tp = t.partMap(side); + + if (this.canConnectTo(tp, ForgeDirection.getOrientation(absDir))) + { + if (tp instanceof PartFlatWire) + { + return ((PartFlatWire) tp).connectStraight(this, (r + 2) % 4); + } + + return true; + } + } + else + { + TileEntity tileEntity = world().getBlockTileEntity(pos.x, pos.y, pos.z); + return this.canConnectTo(tileEntity, ForgeDirection.getOrientation(absDir)); + } + + return false; + } + + public boolean connectInternal(int r) + { + int absDir = Rotation.rotateSide(side, r); + + if (tile().partMap(PartMap.edgeBetween(absDir, side)) != null) + return false; + + TMultiPart tp = tile().partMap(absDir); + + if (this.canConnectTo(tp, ForgeDirection.getOrientation(absDir))) + { + return ((PartFlatWire) tp).connectInternal(this, Rotation.rotationTo(absDir, side)); + } + + return connectInternalOverride(tp, r); + } + + public boolean connectInternalOverride(TMultiPart p, int r) + { + return false; + } + + public boolean connectCenter() + { + TMultiPart tp = tile().partMap(6); + + if (this.canConnectTo(tp)) + { + if (tp instanceof PartFlatWire) + { + return ((PartFlatWire) tp).connectInternal(this, side); + } + + return true; + } + + return false; + } + + public boolean renderThisCorner(PartFlatWire part) + { + if (!(part instanceof PartFlatWire)) + return false; + + PartFlatWire wire = part; + if (wire.getThickness() == getThickness()) + return side < wire.side; + + return wire.getThickness() > getThickness(); + } + + public boolean connectCorner(PartFlatWire wire, int r) + { + int absDir = Rotation.rotateSide(side, r); + + if (this.canConnectTo(wire, ForgeDirection.getOrientation(absDir)) && maskOpen(r)) + { + int oldConn = connMap; + connMap |= 0x1 << r; + if (renderThisCorner(wire))// render connection + connMap |= 0x100000 << r; + + if (oldConn != connMap) + sendConnUpdate(); + return true; + } + return false; + } + + public boolean connectStraight(PartFlatWire wire, int r) + { + int absDir = Rotation.rotateSide(side, r); + + if (this.canConnectTo(wire, ForgeDirection.getOrientation(absDir)) && maskOpen(r)) + { + int oldConn = connMap; + connMap |= 0x10 << r; + if (oldConn != connMap) + sendConnUpdate(); + return true; + } + return false; + } + + public boolean connectInternal(PartFlatWire wire, int r) + { + int absDir = Rotation.rotateSide(side, r); + + if (this.canConnectTo(wire, ForgeDirection.getOrientation(absDir))) + { + int oldConn = connMap; + connMap |= 0x100 << r; + if (oldConn != connMap) + sendConnUpdate(); + return true; + } + return false; + } + + public boolean canConnectCorner(int r) + { + return true; + } + + public void notifyCornerChange(int r) + { + int absDir = Rotation.rotateSide(side, r); + + BlockCoord pos = new BlockCoord(tile()).offset(absDir).offset(side); + world().notifyBlockOfNeighborChange(pos.x, pos.y, pos.z, tile().getBlockType().blockID); + } + + public void notifyStraightChange(int r) + { + int absDir = Rotation.rotateSide(side, r); + + BlockCoord pos = new BlockCoord(tile()).offset(absDir); + world().notifyBlockOfNeighborChange(pos.x, pos.y, pos.z, tile().getBlockType().blockID); + } + + public boolean maskConnects(int r) + { + return (connMap & 0x111 << r) != 0; + } + + public boolean maskOpen(int r) + { + return (connMap & 0x1000 << r) != 0; + } + + /** START TILEMULTIPART INTERACTIONS **/ + @Override + public float getStrength(MovingObjectPosition hit, EntityPlayer player) + { + return 4; + } + + @Override + public int getSlotMask() + { + return 1 << this.side; + } + + @Override + public Iterable getSubParts() + { + return Arrays.asList(new IndexedCuboid6(0, selectionBounds[getThickness()][side])); + } + + @Override + public boolean occlusionTest(TMultiPart npart) + { + return NormalOcclusionTest.apply(this, npart); + } + + @Override + public Iterable getOcclusionBoxes() + { + return Arrays.asList(occlusionBounds[getThickness()][side]); + } + + public int getThickness() + { + return this.isInsulated ? 2 : 1; + } + + @Override + public int redstoneConductionMap() + { + return 0; + } + + @Override + public boolean solid(int arg0) + { + return false; + } + + @Override + public String getType() + { + return "resonant_induction_flat_wire"; + } + + /** RENDERING */ + @SideOnly(Side.CLIENT) + public Icon getIcon() + { + return RenderFlatWire.flatWireTexture; + } + + public Colour getColour() + { + if (isInsulated) + { + Colour color = new ColourARGB(ItemDye.dyeColors[this.color]); + color.a = (byte) 255; + return color; + } + + return getMaterial().color; + } + + public boolean useStaticRenderer() + { + return true; + } + + @Override + @SideOnly(Side.CLIENT) + public void renderStatic(Vector3 pos, LazyLightMatrix olm, int pass) + { + if (pass == 0 && useStaticRenderer()) + { + CCRenderState.setBrightness(world(), x(), y(), z()); + RenderFlatWire.render(this, pos); + CCRenderState.setColour(-1); + } + } + + @Override + @SideOnly(Side.CLIENT) + public void renderDynamic(Vector3 pos, float frame, int pass) + { + if (pass == 0 && !useStaticRenderer()) + { + GL11.glDisable(GL11.GL_LIGHTING); + TextureUtils.bindAtlas(0); + CCRenderState.useModelColours(true); + CCRenderState.startDrawing(7); + RenderFlatWire.render(this, pos); + CCRenderState.draw(); + CCRenderState.setColour(-1); + GL11.glEnable(GL11.GL_LIGHTING); + } + } + + @Override + @SideOnly(Side.CLIENT) + public void drawBreaking(RenderBlocks renderBlocks) + { + CCRenderState.reset(); + RenderFlatWire.renderBreakingOverlay(renderBlocks.overrideBlockTexture, this); + } + + /** Utility method to aid in initializing this or subclasses, usually when you need to change the + * wire to another type + * + * @param otherCable the wire to copy from */ + public void copyFrom(PartFlatWire otherCable) + { + this.isInsulated = otherCable.isInsulated; + this.color = otherCable.color; + this.connections = otherCable.connections; + this.material = otherCable.material; + this.side = otherCable.side; + this.connMap = otherCable.connMap; + this.setNetwork(otherCable.getNetwork()); + this.getNetwork().setBufferFor(this, otherCable.getNetwork().getBufferOf(otherCable)); + } + + @Override + public String toString() + { + return "[PartFlatWire]" + x() + "x " + y() + "y " + z() + "z " + getSlotMask() + "s "; + } } \ No newline at end of file diff --git a/electrical/src/main/scala/resonantinduction/electrical/wire/framed/PartFramedWire.java b/electrical/src/main/scala/resonantinduction/electrical/wire/framed/PartFramedWire.java index 026bf57a8..a443faf22 100644 --- a/electrical/src/main/scala/resonantinduction/electrical/wire/framed/PartFramedWire.java +++ b/electrical/src/main/scala/resonantinduction/electrical/wire/framed/PartFramedWire.java @@ -8,12 +8,10 @@ import java.util.Collection; import java.util.HashSet; import java.util.Set; -import calclavia.lib.prefab.damage.ElectricalDamage; import net.minecraft.block.Block; import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.MovingObjectPosition; @@ -29,6 +27,7 @@ import universalelectricity.api.electricity.IElectricalNetwork; import universalelectricity.api.energy.EnergyNetworkLoader; import universalelectricity.api.energy.IConductor; import universalelectricity.api.energy.IEnergyNetwork; +import calclavia.lib.prefab.damage.ElectricalDamage; import codechicken.lib.lighting.LazyLightMatrix; import codechicken.lib.render.CCRenderState; import codechicken.lib.render.IconTransformation; @@ -349,7 +348,7 @@ public class PartFramedWire extends PartFramedConnection, N extends INodeNetwork> extends PartColorableMaterial implements IConnector, TSlottedPart, JNormalOcclusion, IHollowConnect { - public static IndexedCuboid6[] sides = new IndexedCuboid6[7]; - public static IndexedCuboid6[] insulatedSides = new IndexedCuboid6[7]; + public static IndexedCuboid6[] sides = new IndexedCuboid6[7]; + public static IndexedCuboid6[] insulatedSides = new IndexedCuboid6[7]; - static - { - sides[0] = new IndexedCuboid6(0, new Cuboid6(0.36, 0.000, 0.36, 0.64, 0.36, 0.64)); - sides[1] = new IndexedCuboid6(1, new Cuboid6(0.36, 0.64, 0.36, 0.64, 1.000, 0.64)); - sides[2] = new IndexedCuboid6(2, new Cuboid6(0.36, 0.36, 0.000, 0.64, 0.64, 0.36)); - sides[3] = new IndexedCuboid6(3, new Cuboid6(0.36, 0.36, 0.64, 0.64, 0.64, 1.000)); - sides[4] = new IndexedCuboid6(4, new Cuboid6(0.000, 0.36, 0.36, 0.36, 0.64, 0.64)); - sides[5] = new IndexedCuboid6(5, new Cuboid6(0.64, 0.36, 0.36, 1.000, 0.64, 0.64)); - sides[6] = new IndexedCuboid6(6, new Cuboid6(0.36, 0.36, 0.36, 0.64, 0.64, 0.64)); - insulatedSides[0] = new IndexedCuboid6(0, new Cuboid6(0.3, 0.0, 0.3, 0.7, 0.3, 0.7)); - insulatedSides[1] = new IndexedCuboid6(1, new Cuboid6(0.3, 0.7, 0.3, 0.7, 1.0, 0.7)); - insulatedSides[2] = new IndexedCuboid6(2, new Cuboid6(0.3, 0.3, 0.0, 0.7, 0.7, 0.3)); - insulatedSides[3] = new IndexedCuboid6(3, new Cuboid6(0.3, 0.3, 0.7, 0.7, 0.7, 1.0)); - insulatedSides[4] = new IndexedCuboid6(4, new Cuboid6(0.0, 0.3, 0.3, 0.3, 0.7, 0.7)); - insulatedSides[5] = new IndexedCuboid6(5, new Cuboid6(0.7, 0.3, 0.3, 1.0, 0.7, 0.7)); - insulatedSides[6] = new IndexedCuboid6(6, new Cuboid6(0.3, 0.3, 0.3, 0.7, 0.7, 0.7)); - } + static + { + sides[0] = new IndexedCuboid6(0, new Cuboid6(0.36, 0.000, 0.36, 0.64, 0.36, 0.64)); + sides[1] = new IndexedCuboid6(1, new Cuboid6(0.36, 0.64, 0.36, 0.64, 1.000, 0.64)); + sides[2] = new IndexedCuboid6(2, new Cuboid6(0.36, 0.36, 0.000, 0.64, 0.64, 0.36)); + sides[3] = new IndexedCuboid6(3, new Cuboid6(0.36, 0.36, 0.64, 0.64, 0.64, 1.000)); + sides[4] = new IndexedCuboid6(4, new Cuboid6(0.000, 0.36, 0.36, 0.36, 0.64, 0.64)); + sides[5] = new IndexedCuboid6(5, new Cuboid6(0.64, 0.36, 0.36, 1.000, 0.64, 0.64)); + sides[6] = new IndexedCuboid6(6, new Cuboid6(0.36, 0.36, 0.36, 0.64, 0.64, 0.64)); + insulatedSides[0] = new IndexedCuboid6(0, new Cuboid6(0.3, 0.0, 0.3, 0.7, 0.3, 0.7)); + insulatedSides[1] = new IndexedCuboid6(1, new Cuboid6(0.3, 0.7, 0.3, 0.7, 1.0, 0.7)); + insulatedSides[2] = new IndexedCuboid6(2, new Cuboid6(0.3, 0.3, 0.0, 0.7, 0.7, 0.3)); + insulatedSides[3] = new IndexedCuboid6(3, new Cuboid6(0.3, 0.3, 0.7, 0.7, 0.7, 1.0)); + insulatedSides[4] = new IndexedCuboid6(4, new Cuboid6(0.0, 0.3, 0.3, 0.3, 0.7, 0.7)); + insulatedSides[5] = new IndexedCuboid6(5, new Cuboid6(0.7, 0.3, 0.3, 1.0, 0.7, 0.7)); + insulatedSides[6] = new IndexedCuboid6(6, new Cuboid6(0.3, 0.3, 0.3, 0.7, 0.7, 0.7)); + } - protected Object[] connections = new Object[6]; + protected Object[] connections = new Object[6]; - protected N network; + protected N network; - /** - * Bitmask connections - */ - public byte currentWireConnections = 0x00; - public byte currentAcceptorConnections = 0x00; + /** Bitmask connections */ + public byte currentWireConnections = 0x00; + public byte currentAcceptorConnections = 0x00; - /** Client Side */ - private ForgeDirection testingSide; + /** Client Side */ + private ForgeDirection testingSide; - @SideOnly(Side.CLIENT) - protected Icon breakIcon; + @SideOnly(Side.CLIENT) + protected Icon breakIcon; - public PartFramedConnection(Item insulationType) - { - super(insulationType); - } + public PartFramedConnection(Item insulationType) + { + super(insulationType); + } - public void preparePlacement(int meta) - { - this.setMaterial(meta); - } + public void preparePlacement(int meta) + { + this.setMaterial(meta); + } - @Override - public boolean occlusionTest(TMultiPart other) - { - return NormalOcclusionTest.apply(this, other); - } + @Override + public boolean occlusionTest(TMultiPart other) + { + return NormalOcclusionTest.apply(this, other); + } - @Override - public Iterable getSubParts() - { - Set subParts = new HashSet(); - IndexedCuboid6[] currentSides = isInsulated() ? insulatedSides : sides; + @Override + public Iterable getSubParts() + { + Set subParts = new HashSet(); + IndexedCuboid6[] currentSides = isInsulated() ? insulatedSides : sides; - if (tile() != null) - { - for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) - { - int ord = side.ordinal(); - if (connectionMapContainsSide(getAllCurrentConnections(), side) || side == testingSide) - subParts.add(currentSides[ord]); - } - } + if (tile() != null) + { + for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) + { + int ord = side.ordinal(); + if (connectionMapContainsSide(getAllCurrentConnections(), side) || side == testingSide) + subParts.add(currentSides[ord]); + } + } - subParts.add(currentSides[6]); - return subParts; - } + subParts.add(currentSides[6]); + return subParts; + } - /** - * Rendering and block bounds. - */ - @Override - public Iterable getCollisionBoxes() - { - Set collisionBoxes = new HashSet(); - collisionBoxes.addAll((Collection) getSubParts()); + /** Rendering and block bounds. */ + @Override + public Iterable getCollisionBoxes() + { + Set collisionBoxes = new HashSet(); + collisionBoxes.addAll((Collection) getSubParts()); - return collisionBoxes; - } + return collisionBoxes; + } - @Override - public float getStrength(MovingObjectPosition hit, EntityPlayer player) - { - return 10F; - } + @Override + public float getStrength(MovingObjectPosition hit, EntityPlayer player) + { + return 10F; + } - @Override - public void drawBreaking(RenderBlocks renderBlocks) - { - if (breakIcon != null) - { - CCRenderState.reset(); - RenderUtils.renderBlock(sides[6], 0, new Translation(x(), y(), z()), new IconTransformation(breakIcon), null); - } - } + @Override + public void drawBreaking(RenderBlocks renderBlocks) + { + if (breakIcon != null) + { + CCRenderState.reset(); + RenderUtils.renderBlock(sides[6], 0, new Translation(x(), y(), z()), new IconTransformation(breakIcon), null); + } + } - @Override - public Iterable getOcclusionBoxes() - { - return getCollisionBoxes(); - } + @Override + public Iterable getOcclusionBoxes() + { + return getCollisionBoxes(); + } - @Override - public int getSlotMask() - { - return PartMap.CENTER.mask; - } + @Override + public int getSlotMask() + { + return PartMap.CENTER.mask; + } - @Override - public int getHollowSize() - { - return isInsulated ? 8 : 6; - } + @Override + public int getHollowSize() + { + return isInsulated ? 8 : 6; + } - public boolean isBlockedOnSide(ForgeDirection side) - { - TMultiPart blocker = tile().partMap(side.ordinal()); - testingSide = side; - boolean expandable = NormalOcclusionTest.apply(this, blocker); - testingSide = null; - return !expandable; - } + public boolean isBlockedOnSide(ForgeDirection side) + { + TMultiPart blocker = tile().partMap(side.ordinal()); + testingSide = side; + boolean expandable = NormalOcclusionTest.apply(this, blocker); + testingSide = null; + return !expandable; + } - public byte getAllCurrentConnections() - { - return (byte) (currentWireConnections | currentAcceptorConnections); - } + public byte getAllCurrentConnections() + { + return (byte) (currentWireConnections | currentAcceptorConnections); + } - public static boolean connectionMapContainsSide(byte connections, ForgeDirection side) - { - byte tester = (byte) (1 << side.ordinal()); - return ((connections & tester) > 0); - } + public static boolean connectionMapContainsSide(byte connections, ForgeDirection side) + { + byte tester = (byte) (1 << side.ordinal()); + return ((connections & tester) > 0); + } - @Override - public void bind(TileMultipart t) - { - if (this.getNetwork() != null) - { - getNetwork().getConnectors().remove(this); - super.bind(t); - getNetwork().getConnectors().add(this); - } - else - { - super.bind(t); - } - } + @Override + public void bind(TileMultipart t) + { + if (this.getNetwork() != null) + { + getNetwork().getConnectors().remove(this); + super.bind(t); + getNetwork().getConnectors().add(this); + } + else + { + super.bind(t); + } + } - /** - * CONNECTION LOGIC CODE - */ - protected abstract boolean canConnectTo(TileEntity tile, ForgeDirection to); + /** CONNECTION LOGIC CODE */ + protected abstract boolean canConnectTo(TileEntity tile, ForgeDirection to); - protected abstract C getConnector(TileEntity tile); + protected abstract C getConnector(TileEntity tile); - public boolean canConnectBothSides(TileEntity tile, ForgeDirection side) - { - boolean notPrevented = !isConnectionPrevented(tile, side); + public boolean canConnectBothSides(TileEntity tile, ForgeDirection side) + { + boolean notPrevented = !isConnectionPrevented(tile, side); - if (getConnector(tile) != null) - { - notPrevented &= getConnector(tile).canConnect(side.getOpposite(), this); - } + if (getConnector(tile) != null) + { + notPrevented &= getConnector(tile).canConnect(side.getOpposite(), this); + } - return notPrevented; - } + return notPrevented; + } - /** - * Override if there are ways of preventing a connection - * - * @param tile The TileEntity on the given side - * @param side The side we're checking - * @return Whether we're preventing connections on given side or to given tileEntity - */ - public boolean isConnectionPrevented(TileEntity tile, ForgeDirection side) - { - return (!this.canConnectTo(tile, side)) || (isBlockedOnSide(side)); - } + /** Override if there are ways of preventing a connection + * + * @param tile The TileEntity on the given side + * @param side The side we're checking + * @return Whether we're preventing connections on given side or to given tileEntity */ + public boolean isConnectionPrevented(TileEntity tile, ForgeDirection side) + { + return (!this.canConnectTo(tile, side)) || (isBlockedOnSide(side)); + } - public byte getPossibleWireConnections() - { - byte connections = 0x00; + public byte getPossibleWireConnections() + { + byte connections = 0x00; - for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) - { - TileEntity tileEntity = VectorHelper.getTileEntityFromSide(world(), new Vector3(tile()), side); + for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) + { + TileEntity tileEntity = VectorHelper.getTileEntityFromSide(world(), new Vector3(tile()), side); - if (getConnector(tileEntity) != null && canConnectBothSides(tileEntity, side)) - { - connections |= 1 << side.ordinal(); - } - } + if (getConnector(tileEntity) != null && canConnectBothSides(tileEntity, side)) + { + connections |= 1 << side.ordinal(); + } + } - return connections; - } + return connections; + } - public byte getPossibleAcceptorConnections() - { - byte connections = 0x00; + public byte getPossibleAcceptorConnections() + { + byte connections = 0x00; - for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) - { - TileEntity tileEntity = VectorHelper.getTileEntityFromSide(world(), new Vector3(tile()), side); + for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) + { + TileEntity tileEntity = VectorHelper.getTileEntityFromSide(world(), new Vector3(tile()), side); - if (canConnectTo(tileEntity, side) && canConnectBothSides(tileEntity, side)) - { - connections |= 1 << side.ordinal(); - } - } + if (canConnectTo(tileEntity, side) && canConnectBothSides(tileEntity, side)) + { + connections |= 1 << side.ordinal(); + } + } - return connections; - } + return connections; + } - public void refresh() - { - if (!world().isRemote) - { - byte possibleWireConnections = getPossibleWireConnections(); - byte possibleAcceptorConnections = getPossibleAcceptorConnections(); + public void refresh() + { + if (!world().isRemote) + { + byte possibleWireConnections = getPossibleWireConnections(); + byte possibleAcceptorConnections = getPossibleAcceptorConnections(); - if (possibleWireConnections != this.currentWireConnections) - { - byte or = (byte) (possibleWireConnections | this.currentWireConnections); + if (possibleWireConnections != this.currentWireConnections) + { + byte or = (byte) (possibleWireConnections | this.currentWireConnections); - // Connections have been removed - if (or != possibleWireConnections) - { - this.getNetwork().removeConnector(this); - this.getNetwork().split(this); - setNetwork(null); - } + // Connections have been removed + if (or != possibleWireConnections) + { + this.getNetwork().removeConnector(this); + this.getNetwork().split(this); + setNetwork(null); + } - for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) - { - if (connectionMapContainsSide(possibleWireConnections, side)) - { - TileEntity tileEntity = VectorHelper.getConnectorFromSide(world(), new Vector3(tile()), side, this); + for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) + { + if (connectionMapContainsSide(possibleWireConnections, side)) + { + TileEntity tileEntity = VectorHelper.getConnectorFromSide(world(), new Vector3(tile()), side, this); - if (getConnector(tileEntity) != null) - { - getNetwork().merge(getConnector(tileEntity).getNetwork()); - } - } - } + if (getConnector(tileEntity) != null) + { + getNetwork().merge(getConnector(tileEntity).getNetwork()); + } + } + } - this.currentWireConnections = possibleWireConnections; - } + this.currentWireConnections = possibleWireConnections; + } - this.currentAcceptorConnections = possibleAcceptorConnections; - this.getNetwork().reconstruct(); - this.sendConnectionUpdate(); - } + this.currentAcceptorConnections = possibleAcceptorConnections; + this.getNetwork().reconstruct(); + this.sendConnectionUpdate(); + } - tile().markRender(); - } + tile().markRender(); + } - /** - * Should include connections that are in the current connection maps even if those connections - * aren't allowed any more. This is so that networks split correctly. - */ - @Override - public TileEntity[] getConnections() - { - TileEntity[] connections = new TileEntity[6]; + /** Should include connections that are in the current connection maps even if those connections + * aren't allowed any more. This is so that networks split correctly. */ + @Override + public TileEntity[] getConnections() + { + TileEntity[] connections = new TileEntity[6]; - if (world() != null) - { - for (byte i = 0; i < 6; i++) - { - ForgeDirection side = ForgeDirection.getOrientation(i); - TileEntity tileEntity = VectorHelper.getTileEntityFromSide(world(), new Vector3(tile()), side); + if (world() != null) + { + for (byte i = 0; i < 6; i++) + { + ForgeDirection side = ForgeDirection.getOrientation(i); + TileEntity tileEntity = VectorHelper.getTileEntityFromSide(world(), new Vector3(tile()), side); - if (isCurrentlyConnected(side)) - { - connections[i] = tileEntity; - } - } + if (isCurrentlyConnected(side)) + { + connections[i] = tileEntity; + } + } - } - return connections; - } + } + return connections; + } - public boolean isCurrentlyConnected(ForgeDirection side) - { - return connectionMapContainsSide(getAllCurrentConnections(), side); - } + public boolean isCurrentlyConnected(ForgeDirection side) + { + return connectionMapContainsSide(getAllCurrentConnections(), side); + } - /** Shouldn't need to be overridden. Override connectionPrevented instead */ - @Override - public boolean canConnect(ForgeDirection direction, Object source) - { - Vector3 connectPos = new Vector3(tile()).translate(direction); - TileEntity connectTile = connectPos.getTileEntity(world()); - return !isConnectionPrevented(connectTile, direction); - } + /** Shouldn't need to be overridden. Override connectionPrevented instead */ + @Override + public boolean canConnect(ForgeDirection direction, Object source) + { + Vector3 connectPos = new Vector3(tile()).translate(direction); + TileEntity connectTile = connectPos.getTileEntity(world()); + return !isConnectionPrevented(connectTile, direction); + } - @Override - public void onAdded() - { - super.onAdded(); - refresh(); - } + @Override + public void onAdded() + { + super.onAdded(); + refresh(); + } - @Override - public void onWorldJoin() - { - refresh(); - } + @Override + public void onWorldJoin() + { + refresh(); + } - @Override - public void onNeighborChanged() - { - super.onNeighborChanged(); - refresh(); - } + @Override + public void onNeighborChanged() + { + super.onNeighborChanged(); + refresh(); + } - @Override - public void onPartChanged(TMultiPart part) - { - refresh(); - } + @Override + public void onPartChanged(TMultiPart part) + { + refresh(); + } - public void copyFrom(PartFramedConnection other) - { - this.isInsulated = other.isInsulated; - this.color = other.color; - this.connections = other.connections; - this.material = other.material; - this.currentWireConnections = other.currentWireConnections; - this.currentAcceptorConnections = other.currentAcceptorConnections; - this.setNetwork(other.getNetwork()); - } + public void copyFrom(PartFramedConnection other) + { + this.isInsulated = other.isInsulated; + this.color = other.color; + this.connections = other.connections; + this.material = other.material; + this.currentWireConnections = other.currentWireConnections; + this.currentAcceptorConnections = other.currentAcceptorConnections; + this.setNetwork(other.getNetwork()); + } - /** Packet Methods */ - public void sendConnectionUpdate() - { - tile().getWriteStream(this).writeByte(0).writeByte(this.currentWireConnections).writeByte(this.currentAcceptorConnections); - } + /** Packet Methods */ + public void sendConnectionUpdate() + { + tile().getWriteStream(this).writeByte(0).writeByte(this.currentWireConnections).writeByte(this.currentAcceptorConnections); + } - @Override - public void readDesc(MCDataInput packet) - { - super.readDesc(packet); - this.currentWireConnections = packet.readByte(); - this.currentAcceptorConnections = packet.readByte(); - } + @Override + public void readDesc(MCDataInput packet) + { + super.readDesc(packet); + this.currentWireConnections = packet.readByte(); + this.currentAcceptorConnections = packet.readByte(); + } - @Override - public void writeDesc(MCDataOutput packet) - { - super.writeDesc(packet); - packet.writeByte(this.currentWireConnections); - packet.writeByte(this.currentAcceptorConnections); - } + @Override + public void writeDesc(MCDataOutput packet) + { + super.writeDesc(packet); + packet.writeByte(this.currentWireConnections); + packet.writeByte(this.currentAcceptorConnections); + } - @Override - public void read(MCDataInput packet) - { - read(packet, packet.readUByte()); - } + @Override + public void read(MCDataInput packet) + { + read(packet, packet.readUByte()); + } - @Override - public void read(MCDataInput packet, int packetID) - { - if (packetID == 0) - { - this.currentWireConnections = packet.readByte(); - this.currentAcceptorConnections = packet.readByte(); - tile().markRender(); - } - else - { - super.read(packet, packetID); - } - } + @Override + public void read(MCDataInput packet, int packetID) + { + if (packetID == 0) + { + this.currentWireConnections = packet.readByte(); + this.currentAcceptorConnections = packet.readByte(); + tile().markRender(); + } + else + { + super.read(packet, packetID); + } + } - /** Network Methods */ - @Override - public void setNetwork(N network) - { - this.network = network; - } + /** Network Methods */ + @Override + public void setNetwork(N network) + { + this.network = network; + } - @Override - public IConnector getInstance(ForgeDirection dir) - { - return this; - } + @Override + public IConnector getInstance(ForgeDirection dir) + { + return this; + } + + @Override + public String toString() + { + return "[PartFramedConnection]" + x() + "x " + y() + "y " + z() + "z " + getSlotMask() + "s "; + } } \ No newline at end of file