From 358f8a1d43ef9e45351d9fde825d42ea81ed46ee Mon Sep 17 00:00:00 2001 From: Boblet Date: Wed, 4 Aug 2021 16:26:52 +0200 Subject: [PATCH] fixed pylons being garbage --- .../java/com/hbm/items/tool/ItemAnalyzer.java | 12 +- .../java/com/hbm/items/tool/ItemWiring.java | 4 +- src/main/java/com/hbm/lib/Library.java | 16 +-- .../hbm/render/tileentity/RenderPylon.java | 8 +- .../conductor/TileEntityPylonRedWire.java | 108 ++++++++++++------ 5 files changed, 88 insertions(+), 60 deletions(-) diff --git a/src/main/java/com/hbm/items/tool/ItemAnalyzer.java b/src/main/java/com/hbm/items/tool/ItemAnalyzer.java index 2afeadb7d..f55a59a26 100644 --- a/src/main/java/com/hbm/items/tool/ItemAnalyzer.java +++ b/src/main/java/com/hbm/items/tool/ItemAnalyzer.java @@ -102,15 +102,9 @@ public class ItemAnalyzer extends Item { if(te instanceof TileEntityPylonRedWire) { - player.addChatMessage(new ChatComponentText( - "Connections:")); - - List connections = ((TileEntityPylonRedWire)te).connected; - - for(int i = 0; i < connections.size(); i++) { - player.addChatMessage(new ChatComponentText( - " *" + connections.get(i).xCoord + " / " + connections.get(i).yCoord + " / " + connections.get(i).zCoord)); - } + /** + * this is a smoldering crater + */ } if(te instanceof TileEntityLockableBase) { diff --git a/src/main/java/com/hbm/items/tool/ItemWiring.java b/src/main/java/com/hbm/items/tool/ItemWiring.java index 13b689662..deb396fe9 100644 --- a/src/main/java/com/hbm/items/tool/ItemWiring.java +++ b/src/main/java/com/hbm/items/tool/ItemWiring.java @@ -42,8 +42,8 @@ public class ItemWiring extends Item { TileEntityPylonRedWire first = (TileEntityPylonRedWire) world.getTileEntity(x1, y1, z1); TileEntityPylonRedWire second = ((TileEntityPylonRedWire) te); - first.connected.add(second); - second.connected.add(first); + first.addTileEntityBasedOnCoords(x, y, z); + second.addTileEntityBasedOnCoords(x1, y1, z1); first.markDirty(); second.markDirty(); diff --git a/src/main/java/com/hbm/lib/Library.java b/src/main/java/com/hbm/lib/Library.java index f674e9ff8..1adc8fe33 100644 --- a/src/main/java/com/hbm/lib/Library.java +++ b/src/main/java/com/hbm/lib/Library.java @@ -601,16 +601,16 @@ public class Library { { ((TileEntityPylonRedWire)tileentity).uoteab.get(i).ticked = newTact; for(int j = 0; j < ((TileEntityPylonRedWire)tileentity).connected.size(); j++) { - TileEntityPylonRedWire pylon = ((TileEntityPylonRedWire)tileentity).connected.get(j); + int[] pylon = ((TileEntityPylonRedWire)tileentity).connected.get(j); if(pylon != null) { - ffgeua(pylon.xCoord + 1, pylon.yCoord, pylon.zCoord, that.getTact(), that, worldObj); - ffgeua(pylon.xCoord - 1, pylon.yCoord, pylon.zCoord, that.getTact(), that, worldObj); - ffgeua(pylon.xCoord, pylon.yCoord + 1, pylon.zCoord, that.getTact(), that, worldObj); - ffgeua(pylon.xCoord, pylon.yCoord - 1, pylon.zCoord, that.getTact(), that, worldObj); - ffgeua(pylon.xCoord, pylon.yCoord, pylon.zCoord + 1, that.getTact(), that, worldObj); - ffgeua(pylon.xCoord, pylon.yCoord, pylon.zCoord - 1, that.getTact(), that, worldObj); + ffgeua(pylon[0] + 1, pylon[1], pylon[2], that.getTact(), that, worldObj); + ffgeua(pylon[0] - 1, pylon[1], pylon[2], that.getTact(), that, worldObj); + ffgeua(pylon[0], pylon[1] + 1, pylon[2], that.getTact(), that, worldObj); + ffgeua(pylon[0], pylon[1] - 1, pylon[2], that.getTact(), that, worldObj); + ffgeua(pylon[0], pylon[1], pylon[2] + 1, that.getTact(), that, worldObj); + ffgeua(pylon[0], pylon[1], pylon[2] - 1, that.getTact(), that, worldObj); - ffgeua(pylon.xCoord, pylon.yCoord, pylon.zCoord, that.getTact(), that, worldObj); + ffgeua(pylon[0], pylon[1], pylon[2], that.getTact(), that, worldObj); } } } diff --git a/src/main/java/com/hbm/render/tileentity/RenderPylon.java b/src/main/java/com/hbm/render/tileentity/RenderPylon.java index d6fbc11f1..5907854b5 100644 --- a/src/main/java/com/hbm/render/tileentity/RenderPylon.java +++ b/src/main/java/com/hbm/render/tileentity/RenderPylon.java @@ -34,11 +34,11 @@ public class RenderPylon extends TileEntitySpecialRenderer { for(int i = 0; i < pyl.connected.size(); i++) { - TileEntityPylonRedWire wire = pyl.connected.get(i); + int[] wire = pyl.connected.get(i); - float wX = (wire.xCoord - pyl.xCoord) / 2F; - float wY = (wire.yCoord - pyl.yCoord) / 2F; - float wZ = (wire.zCoord - pyl.zCoord) / 2F; + float wX = (wire[0] - pyl.xCoord) / 2F; + float wY = (wire[1] - pyl.yCoord) / 2F; + float wZ = (wire[2] - pyl.zCoord) / 2F; float count = 10; for(float j = 0; j < count; j++) { diff --git a/src/main/java/com/hbm/tileentity/conductor/TileEntityPylonRedWire.java b/src/main/java/com/hbm/tileentity/conductor/TileEntityPylonRedWire.java index 465da22b1..2c0a0427b 100644 --- a/src/main/java/com/hbm/tileentity/conductor/TileEntityPylonRedWire.java +++ b/src/main/java/com/hbm/tileentity/conductor/TileEntityPylonRedWire.java @@ -7,9 +7,12 @@ import com.hbm.blocks.ModBlocks; import com.hbm.calc.UnionOfTileEntitiesAndBooleans; import com.hbm.interfaces.IConductor; import com.hbm.interfaces.Spaghetti; +import com.hbm.interfaces.Untested; +import com.hbm.packet.NBTPacket; import com.hbm.packet.PacketDispatcher; import com.hbm.packet.TEPylonDestructorPacket; import com.hbm.packet.TEPylonSenderPacket; +import com.hbm.tileentity.INBTPacketReceiver; import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint; import cpw.mods.fml.relauncher.Side; @@ -19,42 +22,75 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraft.world.World; -@Spaghetti("Destroy this abomination in holy fire") -public class TileEntityPylonRedWire extends TileEntity implements IConductor { +@Untested +public class TileEntityPylonRedWire extends TileEntity implements IConductor, INBTPacketReceiver { public List uoteab = new ArrayList(); - public List connected = new ArrayList(); + public List connected = new ArrayList(); public boolean scheduleConnectionCheck = false; public int[][] scheduleBuffer; @Override public void updateEntity() { - for(int i = connected.size() - 1; i >= 0; i--) { - if(connected.size() >= i + 1 && connected.get(i) == null) - connected.remove(i); - } - - for(int i = connected.size() - 1; i >= 0; i--) { - if(connected.size() >= i + 1 && connected.get(i) != null && - this.worldObj.getBlock(connected.get(i).xCoord, connected.get(i).yCoord, connected.get(i).zCoord) != ModBlocks.red_pylon) - connected.remove(i); - } - - if(scheduleConnectionCheck && this.scheduleBuffer != null) { - scheduleConnectionCheck = false; - this.connected = TileEntityPylonRedWire.convertArrayToList(this.scheduleBuffer, worldObj); - } - - //TODO: use serialized NBT packets for this trash - if(!worldObj.isRemote) - if(!connected.isEmpty()) { - PacketDispatcher.wrapper.sendToAllAround(new TEPylonDestructorPacket(xCoord, yCoord, zCoord), new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 150)); + if(!worldObj.isRemote) { + + for(int i = connected.size() - 1; i >= 0; i--) { - for(TileEntityPylonRedWire wire : connected) - PacketDispatcher.wrapper.sendToAllAround(new TEPylonSenderPacket(xCoord, yCoord, zCoord, - wire.xCoord, wire.yCoord, wire.zCoord), new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 150)); + int[] con = connected.get(i); + + if(con == null) { + connected.remove(i); + continue; + } + + TileEntity pylon = worldObj.getTileEntity(con[0], con[1], con[2]); + + if(pylon.isInvalid()) { + connected.remove(i); + continue; + } } + + if(scheduleConnectionCheck && this.scheduleBuffer != null) { + scheduleConnectionCheck = false; + this.connected = convertArrayToList(this.scheduleBuffer, worldObj); + } + + if(worldObj.getTotalWorldTime() % 10 == 0) { + NBTTagCompound data = new NBTTagCompound(); + data.setInteger("count", this.connected.size()); + + for(int i = 0; i < connected.size(); i++) { + + int[] pos = connected.get(i); + + TileEntity te = worldObj.getTileEntity(pos[0], pos[1], pos[2]); + + if(te instanceof TileEntityPylonRedWire) { + data.setIntArray("c" + i, new int[] { pos[0], pos[1], pos[2] }); + } + } + + PacketDispatcher.wrapper.sendToAllAround(new NBTPacket(data, xCoord, yCoord, zCoord), new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 100)); + } + } + } + + @Override + public void networkUnpack(NBTTagCompound nbt) { + + this.connected.clear(); + + int count = nbt.getInteger("count"); + + for(int i = 0; i < count; i++) { + + if(nbt.hasKey("c" + i)) { + int[] pos = nbt.getIntArray("c" + i); + this.connected.add(pos); + } + } } @Override @@ -97,28 +133,26 @@ public class TileEntityPylonRedWire extends TileEntity implements IConductor { nbt.setIntArray("conZ", conZ); } - public static List convertArrayToList(int[][] array, World worldObj) { + public static List convertArrayToList(int[][] array, World worldObj) { - List list = new ArrayList(); + List list = new ArrayList(); for(int i = 0; i < array.length; i++) { - TileEntity te = worldObj.getTileEntity(array[i][0], array[i][1], array[i][2]); - if(te != null && te instanceof TileEntityPylonRedWire) - list.add((TileEntityPylonRedWire)te); + list.add(new int[] {array[i][0], array[i][1], array[i][2]}); } return list; } - public static int[][] convertListToArray(List list) { + public static int[][] convertListToArray(List list) { int[][] array = new int[list.size()][3]; for(int i = 0; i < list.size(); i++) { - TileEntity te = list.get(i); - array[i][0] = te.xCoord; - array[i][1] = te.yCoord; - array[i][2] = te.zCoord; + int[] pos = list.get(i); + array[i][0] = pos[0]; + array[i][1] = pos[1]; + array[i][2] = pos[2]; } return array; @@ -128,7 +162,7 @@ public class TileEntityPylonRedWire extends TileEntity implements IConductor { TileEntity te = worldObj.getTileEntity(x, y, z); if(te != null && te instanceof TileEntityPylonRedWire) - this.connected.add((TileEntityPylonRedWire)te); + this.connected.add(new int[]{x, y, z}); } @Override