From 3d9ef7a3a1234a8f996f4ebf2f5e4cd82f1c2074 Mon Sep 17 00:00:00 2001 From: LordMZTE Date: Sat, 14 Jan 2023 00:10:40 +0100 Subject: [PATCH] fix: accelerator - added powered state and pipe connections to datapacket - fixed nonsensical partial `writeToNBT` (WTF) closes #10 --- .../eloraam/redpower/machine/RenderAccel.java | 1 - .../eloraam/redpower/machine/TileAccel.java | 29 +++++++------------ .../redpower/machine/TileMachinePanel.java | 14 ++++----- .../eloraam/redpower/machine/TilePump.java | 10 +++---- 4 files changed, 22 insertions(+), 32 deletions(-) diff --git a/src/main/java/com/eloraam/redpower/machine/RenderAccel.java b/src/main/java/com/eloraam/redpower/machine/RenderAccel.java index bf434eb..832cad6 100644 --- a/src/main/java/com/eloraam/redpower/machine/RenderAccel.java +++ b/src/main/java/com/eloraam/redpower/machine/RenderAccel.java @@ -19,7 +19,6 @@ import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; -import net.minecraftforge.client.IItemRenderer.ItemRenderType; import org.lwjgl.opengl.GL11; @SideOnly(Side.CLIENT) diff --git a/src/main/java/com/eloraam/redpower/machine/TileAccel.java b/src/main/java/com/eloraam/redpower/machine/TileAccel.java index 288bb23..cceecb6 100644 --- a/src/main/java/com/eloraam/redpower/machine/TileAccel.java +++ b/src/main/java/com/eloraam/redpower/machine/TileAccel.java @@ -52,7 +52,6 @@ public class TileAccel return TileAccel.this; } }; - private boolean hasChanged = false; public int ConMask = -1; public int conCache = -1; @@ -80,7 +79,6 @@ public class TileAccel } else { item.side = (byte) side; this.flow.add(item); - this.hasChanged = true; this.markDirty(); return true; } @@ -100,7 +98,6 @@ public class TileAccel public void addTubeItem(TubeItem ti) { ti.side = (byte) (ti.side ^ 1); this.flow.add(ti); - this.hasChanged = true; this.markDirty(); } @@ -183,11 +180,8 @@ public class TileAccel @Override public void updateEntity() { super.updateEntity(); - if (this.flow.update()) { - this.hasChanged = true; - } - if (this.hasChanged) { + if (this.flow.update()) { if (!super.worldObj.isRemote) { this.markForUpdate(); } @@ -253,6 +247,10 @@ public class TileAccel @Override protected void writeToPacket(NBTTagCompound data) { + super.writeToPacket(data); + data.setInteger("cc", this.conCache); + data.setBoolean("po", this.powered); + int cs = this.flow.contents.size(); if (cs > 6) { cs = 6; @@ -267,26 +265,19 @@ public class TileAccel ti.writeToPacket(itag); data.setTag("cs" + i, itag); } - - if (this.hasChanged) { - this.hasChanged = false; - data.setBoolean("data", true); - super.writeToPacket(data); - } } @Override protected void readFromPacket(NBTTagCompound data) { + super.readFromPacket(data); + this.conCache = data.getInteger("cc"); + this.powered = data.getBoolean("p"); + this.flow.contents.clear(); int cs = data.getInteger("cs"); for (int i = 0; i < cs; ++i) { - this.flow.contents.add(TubeItem.newFromPacket((NBTTagCompound - ) data.getTag("cs" + i))); - } - - if (data.hasKey("data")) { - super.readFromPacket(data); + this.flow.contents.add(TubeItem.newFromPacket(data.getCompoundTag("cs" + i))); } } } diff --git a/src/main/java/com/eloraam/redpower/machine/TileMachinePanel.java b/src/main/java/com/eloraam/redpower/machine/TileMachinePanel.java index 3143bcc..e3c08c6 100644 --- a/src/main/java/com/eloraam/redpower/machine/TileMachinePanel.java +++ b/src/main/java/com/eloraam/redpower/machine/TileMachinePanel.java @@ -19,7 +19,7 @@ import net.minecraft.world.IBlockAccess; public class TileMachinePanel extends TileMultipart implements IRotatable, IFrameSupport { public int Rotation = 0; public boolean Active = false; - public boolean Powered = false; + public boolean powered = false; public boolean Delay = false; public boolean Charged = false; @@ -133,7 +133,7 @@ public class TileMachinePanel extends TileMultipart implements IRotatable, IFram @Override public void writeFramePacket(NBTTagCompound tag) { tag.setByte("rot", (byte) this.Rotation); - int ps = (this.Active ? 1 : 0) | (this.Powered ? 2 : 0) | (this.Delay ? 4 : 0) + int ps = (this.Active ? 1 : 0) | (this.powered ? 2 : 0) | (this.Delay ? 4 : 0) | (this.Charged ? 8 : 0); tag.setByte("ps", (byte) ps); } @@ -143,7 +143,7 @@ public class TileMachinePanel extends TileMultipart implements IRotatable, IFram this.Rotation = tag.getByte("rot"); int ps = tag.getByte("ps"); this.Active = (ps & 1) > 0; - this.Powered = (ps & 2) > 0; + this.powered = (ps & 2) > 0; this.Delay = (ps & 4) > 0; this.Charged = (ps & 8) > 0; } @@ -163,7 +163,7 @@ public class TileMachinePanel extends TileMultipart implements IRotatable, IFram byte k = data.getByte("ps"); this.Rotation = data.getByte("rot"); this.Active = (k & 1) > 0; - this.Powered = (k & 2) > 0; + this.powered = (k & 2) > 0; this.Delay = (k & 4) > 0; this.Charged = (k & 8) > 0; } @@ -171,7 +171,7 @@ public class TileMachinePanel extends TileMultipart implements IRotatable, IFram @Override public void writeToNBT(NBTTagCompound data) { super.writeToNBT(data); - int ps = (this.Active ? 1 : 0) | (this.Powered ? 2 : 0) | (this.Delay ? 4 : 0) + int ps = (this.Active ? 1 : 0) | (this.powered ? 2 : 0) | (this.Delay ? 4 : 0) | (this.Charged ? 8 : 0); data.setByte("ps", (byte) ps); data.setByte("rot", (byte) this.Rotation); @@ -182,7 +182,7 @@ public class TileMachinePanel extends TileMultipart implements IRotatable, IFram this.Rotation = data.getByte("rot"); int ps = data.getByte("ps"); this.Active = (ps & 1) > 0; - this.Powered = (ps & 2) > 0; + this.powered = (ps & 2) > 0; this.Delay = (ps & 4) > 0; this.Charged = (ps & 8) > 0; this.updateLight(); @@ -191,7 +191,7 @@ public class TileMachinePanel extends TileMultipart implements IRotatable, IFram @Override protected void writeToPacket(NBTTagCompound data) { data.setByte("rot", (byte) this.Rotation); - int ps = (this.Active ? 1 : 0) | (this.Powered ? 2 : 0) | (this.Delay ? 4 : 0) + int ps = (this.Active ? 1 : 0) | (this.powered ? 2 : 0) | (this.Delay ? 4 : 0) | (this.Charged ? 8 : 0); data.setByte("ps", (byte) ps); } diff --git a/src/main/java/com/eloraam/redpower/machine/TilePump.java b/src/main/java/com/eloraam/redpower/machine/TilePump.java index 970af18..4c26991 100644 --- a/src/main/java/com/eloraam/redpower/machine/TilePump.java +++ b/src/main/java/com/eloraam/redpower/machine/TilePump.java @@ -93,12 +93,12 @@ public class TilePump if (RedPowerLib.isPowered( super.worldObj, super.xCoord, super.yCoord, super.zCoord, 16777215, 63 )) { - if (!super.Powered) { - super.Powered = true; + if (!super.powered) { + super.powered = true; this.markDirty(); } } else { - super.Powered = false; + super.powered = false; this.markDirty(); } } @@ -168,7 +168,7 @@ public class TilePump this.updateBlock(); } - if (super.Charged && super.Powered) { + if (super.Charged && super.powered) { super.Active = true; } @@ -181,7 +181,7 @@ public class TilePump @Override public void onTileTick() { - if (!super.worldObj.isRemote && !super.Powered) { + if (!super.worldObj.isRemote && !super.powered) { super.Active = false; this.updateBlock(); }