fixed pylons being garbage

This commit is contained in:
Boblet 2021-08-04 16:26:52 +02:00
parent f9da6e1d58
commit 358f8a1d43
5 changed files with 88 additions and 60 deletions

View File

@ -102,15 +102,9 @@ public class ItemAnalyzer extends Item {
if(te instanceof TileEntityPylonRedWire) { if(te instanceof TileEntityPylonRedWire) {
player.addChatMessage(new ChatComponentText( /**
"Connections:")); * this is a smoldering crater
*/
List<TileEntityPylonRedWire> 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));
}
} }
if(te instanceof TileEntityLockableBase) { if(te instanceof TileEntityLockableBase) {

View File

@ -42,8 +42,8 @@ public class ItemWiring extends Item {
TileEntityPylonRedWire first = (TileEntityPylonRedWire) world.getTileEntity(x1, y1, z1); TileEntityPylonRedWire first = (TileEntityPylonRedWire) world.getTileEntity(x1, y1, z1);
TileEntityPylonRedWire second = ((TileEntityPylonRedWire) te); TileEntityPylonRedWire second = ((TileEntityPylonRedWire) te);
first.connected.add(second); first.addTileEntityBasedOnCoords(x, y, z);
second.connected.add(first); second.addTileEntityBasedOnCoords(x1, y1, z1);
first.markDirty(); first.markDirty();
second.markDirty(); second.markDirty();

View File

@ -601,16 +601,16 @@ public class Library {
{ {
((TileEntityPylonRedWire)tileentity).uoteab.get(i).ticked = newTact; ((TileEntityPylonRedWire)tileentity).uoteab.get(i).ticked = newTact;
for(int j = 0; j < ((TileEntityPylonRedWire)tileentity).connected.size(); j++) { 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) { if(pylon != null) {
ffgeua(pylon.xCoord + 1, pylon.yCoord, pylon.zCoord, that.getTact(), that, worldObj); ffgeua(pylon[0] + 1, pylon[1], pylon[2], that.getTact(), that, worldObj);
ffgeua(pylon.xCoord - 1, pylon.yCoord, pylon.zCoord, that.getTact(), that, worldObj); ffgeua(pylon[0] - 1, pylon[1], pylon[2], that.getTact(), that, worldObj);
ffgeua(pylon.xCoord, pylon.yCoord + 1, pylon.zCoord, that.getTact(), that, worldObj); ffgeua(pylon[0], pylon[1] + 1, pylon[2], that.getTact(), that, worldObj);
ffgeua(pylon.xCoord, pylon.yCoord - 1, pylon.zCoord, that.getTact(), that, worldObj); ffgeua(pylon[0], pylon[1] - 1, pylon[2], that.getTact(), that, worldObj);
ffgeua(pylon.xCoord, pylon.yCoord, pylon.zCoord + 1, that.getTact(), that, worldObj); ffgeua(pylon[0], pylon[1], pylon[2] + 1, that.getTact(), that, worldObj);
ffgeua(pylon.xCoord, pylon.yCoord, pylon.zCoord - 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);
} }
} }
} }

View File

@ -34,11 +34,11 @@ public class RenderPylon extends TileEntitySpecialRenderer {
for(int i = 0; i < pyl.connected.size(); i++) { 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 wX = (wire[0] - pyl.xCoord) / 2F;
float wY = (wire.yCoord - pyl.yCoord) / 2F; float wY = (wire[1] - pyl.yCoord) / 2F;
float wZ = (wire.zCoord - pyl.zCoord) / 2F; float wZ = (wire[2] - pyl.zCoord) / 2F;
float count = 10; float count = 10;
for(float j = 0; j < count; j++) { for(float j = 0; j < count; j++) {

View File

@ -7,9 +7,12 @@ import com.hbm.blocks.ModBlocks;
import com.hbm.calc.UnionOfTileEntitiesAndBooleans; import com.hbm.calc.UnionOfTileEntitiesAndBooleans;
import com.hbm.interfaces.IConductor; import com.hbm.interfaces.IConductor;
import com.hbm.interfaces.Spaghetti; import com.hbm.interfaces.Spaghetti;
import com.hbm.interfaces.Untested;
import com.hbm.packet.NBTPacket;
import com.hbm.packet.PacketDispatcher; import com.hbm.packet.PacketDispatcher;
import com.hbm.packet.TEPylonDestructorPacket; import com.hbm.packet.TEPylonDestructorPacket;
import com.hbm.packet.TEPylonSenderPacket; import com.hbm.packet.TEPylonSenderPacket;
import com.hbm.tileentity.INBTPacketReceiver;
import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint; import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
@ -19,42 +22,75 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World; import net.minecraft.world.World;
@Spaghetti("Destroy this abomination in holy fire") @Untested
public class TileEntityPylonRedWire extends TileEntity implements IConductor { public class TileEntityPylonRedWire extends TileEntity implements IConductor, INBTPacketReceiver {
public List<UnionOfTileEntitiesAndBooleans> uoteab = new ArrayList<UnionOfTileEntitiesAndBooleans>(); public List<UnionOfTileEntitiesAndBooleans> uoteab = new ArrayList<UnionOfTileEntitiesAndBooleans>();
public List<TileEntityPylonRedWire> connected = new ArrayList<TileEntityPylonRedWire>(); public List<int[]> connected = new ArrayList<int[]>();
public boolean scheduleConnectionCheck = false; public boolean scheduleConnectionCheck = false;
public int[][] scheduleBuffer; public int[][] scheduleBuffer;
@Override @Override
public void updateEntity() { public void updateEntity() {
for(int i = connected.size() - 1; i >= 0; i--) { if(!worldObj.isRemote) {
if(connected.size() >= i + 1 && connected.get(i) == null)
connected.remove(i);
}
for(int i = connected.size() - 1; i >= 0; 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) { int[] con = connected.get(i);
scheduleConnectionCheck = false;
this.connected = TileEntityPylonRedWire.convertArrayToList(this.scheduleBuffer, worldObj);
}
//TODO: use serialized NBT packets for this trash if(con == null) {
if(!worldObj.isRemote) connected.remove(i);
if(!connected.isEmpty()) { continue;
PacketDispatcher.wrapper.sendToAllAround(new TEPylonDestructorPacket(xCoord, yCoord, zCoord), new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 150)); }
for(TileEntityPylonRedWire wire : connected) TileEntity pylon = worldObj.getTileEntity(con[0], con[1], con[2]);
PacketDispatcher.wrapper.sendToAllAround(new TEPylonSenderPacket(xCoord, yCoord, zCoord,
wire.xCoord, wire.yCoord, wire.zCoord), new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 150)); 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 @Override
@ -97,28 +133,26 @@ public class TileEntityPylonRedWire extends TileEntity implements IConductor {
nbt.setIntArray("conZ", conZ); nbt.setIntArray("conZ", conZ);
} }
public static List<TileEntityPylonRedWire> convertArrayToList(int[][] array, World worldObj) { public static List<int[]> convertArrayToList(int[][] array, World worldObj) {
List<TileEntityPylonRedWire> list = new ArrayList<TileEntityPylonRedWire>(); List<int[]> list = new ArrayList<int[]>();
for(int i = 0; i < array.length; i++) { for(int i = 0; i < array.length; i++) {
TileEntity te = worldObj.getTileEntity(array[i][0], array[i][1], array[i][2]); list.add(new int[] {array[i][0], array[i][1], array[i][2]});
if(te != null && te instanceof TileEntityPylonRedWire)
list.add((TileEntityPylonRedWire)te);
} }
return list; return list;
} }
public static int[][] convertListToArray(List<TileEntityPylonRedWire> list) { public static int[][] convertListToArray(List<int[]> list) {
int[][] array = new int[list.size()][3]; int[][] array = new int[list.size()][3];
for(int i = 0; i < list.size(); i++) { for(int i = 0; i < list.size(); i++) {
TileEntity te = list.get(i); int[] pos = list.get(i);
array[i][0] = te.xCoord; array[i][0] = pos[0];
array[i][1] = te.yCoord; array[i][1] = pos[1];
array[i][2] = te.zCoord; array[i][2] = pos[2];
} }
return array; return array;
@ -128,7 +162,7 @@ public class TileEntityPylonRedWire extends TileEntity implements IConductor {
TileEntity te = worldObj.getTileEntity(x, y, z); TileEntity te = worldObj.getTileEntity(x, y, z);
if(te != null && te instanceof TileEntityPylonRedWire) if(te != null && te instanceof TileEntityPylonRedWire)
this.connected.add((TileEntityPylonRedWire)te); this.connected.add(new int[]{x, y, z});
} }
@Override @Override