From 1338b83a02944c8bc522b4f8ae494c546310426a Mon Sep 17 00:00:00 2001 From: Calclavia Date: Fri, 3 Jan 2014 00:42:05 +0800 Subject: [PATCH] Fixed framed wire not connecting --- Calclavia-Core | 2 +- .../java/resonantinduction/MultipartRI.java | 4 +- .../java/resonantinduction/wire/ItemWire.java | 4 +- .../wire/flat/PartFlatWire.java | 21 ++++--- .../{PartWire.java => PartFramedWire.java} | 63 ++++++++++++++++--- .../wire/framed/RenderPartWire.java | 12 ++-- 6 files changed, 78 insertions(+), 28 deletions(-) rename src/main/java/resonantinduction/wire/framed/{PartWire.java => PartFramedWire.java} (88%) diff --git a/Calclavia-Core b/Calclavia-Core index 051bbef26..9fb37199c 160000 --- a/Calclavia-Core +++ b/Calclavia-Core @@ -1 +1 @@ -Subproject commit 051bbef264186f28303b43eb7f71e523e56d72cc +Subproject commit 9fb37199c4375ce8e07576cf843272355b66ad92 diff --git a/src/main/java/resonantinduction/MultipartRI.java b/src/main/java/resonantinduction/MultipartRI.java index 9f40a088a..87b08396a 100644 --- a/src/main/java/resonantinduction/MultipartRI.java +++ b/src/main/java/resonantinduction/MultipartRI.java @@ -4,7 +4,7 @@ import resonantinduction.multimeter.PartMultimeter; import resonantinduction.transformer.PartTransformer; import resonantinduction.wire.flat.PartFlatSwitchWire; import resonantinduction.wire.flat.PartFlatWire; -import resonantinduction.wire.framed.PartWire; +import resonantinduction.wire.framed.PartFramedWire; import codechicken.multipart.MultiPartRegistry; import codechicken.multipart.MultiPartRegistry.IPartFactory; import codechicken.multipart.MultipartGenerator; @@ -29,7 +29,7 @@ public class MultipartRI implements IPartFactory { if (name == "resonant_induction_wire") { - return new PartWire(); + return new PartFramedWire(); } else if (name == "resonant_induction_flat_wire") { diff --git a/src/main/java/resonantinduction/wire/ItemWire.java b/src/main/java/resonantinduction/wire/ItemWire.java index 951e62709..76560325a 100644 --- a/src/main/java/resonantinduction/wire/ItemWire.java +++ b/src/main/java/resonantinduction/wire/ItemWire.java @@ -19,7 +19,7 @@ import resonantinduction.TabRI; import resonantinduction.Utility; import resonantinduction.wire.flat.PartFlatWire; import resonantinduction.wire.flat.RenderFlatWire; -import resonantinduction.wire.framed.PartWire; +import resonantinduction.wire.framed.PartFramedWire; import resonantinduction.wire.framed.RenderPartWire; import universalelectricity.api.energy.UnitDisplay; import universalelectricity.api.energy.UnitDisplay.Unit; @@ -54,7 +54,7 @@ public class ItemWire extends JItemMultiPart if (ControlKeyModifer.isControlDown(player)) { - PartWire wire = (PartWire) MultiPartRegistry.createPart("resonant_induction_wire", false); + PartFramedWire wire = (PartFramedWire) MultiPartRegistry.createPart("resonant_induction_wire", false); if (wire != null) { diff --git a/src/main/java/resonantinduction/wire/flat/PartFlatWire.java b/src/main/java/resonantinduction/wire/flat/PartFlatWire.java index 3a0a50104..5e38a3384 100644 --- a/src/main/java/resonantinduction/wire/flat/PartFlatWire.java +++ b/src/main/java/resonantinduction/wire/flat/PartFlatWire.java @@ -440,17 +440,20 @@ public class PartFlatWire extends PartAdvancedWire implements TFacePart, JNormal private void disconnect(int i) { - if (this.connections[i] != null) + if (!this.world().isRemote) { - if (this.connections[i] instanceof PartFlatWire) + if (this.connections[i] != null) { - PartFlatWire wire = (PartFlatWire) this.connections[i]; - this.connections[i] = null; - this.getNetwork().split(this, wire); - } - else - { - 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; + } } } } diff --git a/src/main/java/resonantinduction/wire/framed/PartWire.java b/src/main/java/resonantinduction/wire/framed/PartFramedWire.java similarity index 88% rename from src/main/java/resonantinduction/wire/framed/PartWire.java rename to src/main/java/resonantinduction/wire/framed/PartFramedWire.java index 98d476707..f77047b77 100644 --- a/src/main/java/resonantinduction/wire/framed/PartWire.java +++ b/src/main/java/resonantinduction/wire/framed/PartFramedWire.java @@ -17,6 +17,8 @@ import universalelectricity.api.CompatibilityModule; import universalelectricity.api.energy.IConductor; import universalelectricity.api.vector.Vector3; import universalelectricity.api.vector.VectorHelper; +import codechicken.lib.data.MCDataInput; +import codechicken.lib.data.MCDataOutput; import codechicken.lib.lighting.LazyLightMatrix; import codechicken.lib.raytracer.IndexedCuboid6; import codechicken.lib.render.CCRenderState; @@ -36,7 +38,7 @@ import codechicken.multipart.TileMultipart; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -public class PartWire extends PartAdvancedWire implements TSlottedPart, JNormalOcclusion, IHollowConnect, JIconHitEffects +public class PartFramedWire extends PartAdvancedWire implements TSlottedPart, JNormalOcclusion, IHollowConnect, JIconHitEffects { /** Client Side Connection Check */ private ForgeDirection testingSide; @@ -50,17 +52,17 @@ public class PartWire extends PartAdvancedWire implements TSlottedPart, JNormalO public byte currentWireConnections = 0x00; public byte currentAcceptorConnections = 0x00; - public PartWire() + public PartFramedWire() { super(); } - public PartWire(int typeID) + public PartFramedWire(int typeID) { this(EnumWireMaterial.values()[typeID]); } - public PartWire(EnumWireMaterial type) + public PartFramedWire(EnumWireMaterial type) { super(); material = type; @@ -362,7 +364,7 @@ public class PartWire extends PartAdvancedWire implements TSlottedPart, JNormalO this.currentAcceptorConnections = possibleAcceptorConnections; this.getNetwork().reconstruct(); - // this.sendDescUpdate(); + this.sendConnectionUpdate(); } tile().markRender(); @@ -375,7 +377,7 @@ public class PartWire extends PartAdvancedWire implements TSlottedPart, JNormalO @Override public TileEntity[] getConnections() { - TileEntity[] cachedConnections = new TileEntity[6]; + TileEntity[] connections = new TileEntity[6]; for (byte i = 0; i < 6; i++) { @@ -384,11 +386,11 @@ public class PartWire extends PartAdvancedWire implements TSlottedPart, JNormalO if (isCurrentlyConnected(side)) { - cachedConnections[i] = tileEntity; + connections[i] = tileEntity; } } - return cachedConnections; + return connections; } public boolean isCurrentlyConnected(ForgeDirection side) @@ -438,4 +440,49 @@ public class PartWire extends PartAdvancedWire implements TSlottedPart, JNormalO super.onNeighborChanged(); refresh(); } + + /** + * Packets + */ + 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 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, int packetID) + { + if (packetID == 0) + { + this.currentWireConnections = packet.readByte(); + this.currentAcceptorConnections = packet.readByte(); + tile().markRender(); + } + else + { + super.read(packet, packetID); + } + } } \ No newline at end of file diff --git a/src/main/java/resonantinduction/wire/framed/RenderPartWire.java b/src/main/java/resonantinduction/wire/framed/RenderPartWire.java index b69176cd0..62fd6bb13 100644 --- a/src/main/java/resonantinduction/wire/framed/RenderPartWire.java +++ b/src/main/java/resonantinduction/wire/framed/RenderPartWire.java @@ -87,7 +87,7 @@ public class RenderPartWire buffer.flip(); } - public void renderShine(PartWire wire, double x, double y, double z, float f) + public void renderShine(PartFramedWire wire, double x, double y, double z, float f) { if (wire != null) { @@ -113,7 +113,7 @@ public class RenderPartWire for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { - if (PartWire.connectionMapContainsSide(renderSides, side)) + if (PartFramedWire.connectionMapContainsSide(renderSides, side)) renderSideShine(side, wire); } CCRenderState.draw(); @@ -137,7 +137,7 @@ public class RenderPartWire breakIcon = iconReg.registerIcon(ResonantInduction.PREFIX + "wire"); } - public void renderStatic(PartWire wire) + public void renderStatic(PartFramedWire wire) { TextureUtils.bindAtlas(0); CCRenderState.reset(); @@ -148,14 +148,14 @@ public class RenderPartWire for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { - if (PartWire.connectionMapContainsSide(renderSides, side)) + if (PartFramedWire.connectionMapContainsSide(renderSides, side)) { renderSide(side, wire); } } } - public void renderSide(ForgeDirection side, PartWire wire) + public void renderSide(ForgeDirection side, PartFramedWire wire) { String name = side.name().toLowerCase(); name = name.equals("unknown") ? "center" : name; @@ -169,7 +169,7 @@ public class RenderPartWire } } - public void renderSideShine(ForgeDirection side, PartWire wire) + public void renderSideShine(ForgeDirection side, PartFramedWire wire) { String name = side.name().toLowerCase(); name = name.equals("unknown") ? "center" : name;