fix: accelerator

- added powered state and pipe connections to datapacket
- fixed nonsensical partial `writeToNBT` (WTF)

closes #10
This commit is contained in:
LordMZTE 2023-01-14 00:10:40 +01:00
parent 9326d1ce37
commit 3d9ef7a3a1
Signed by: LordMZTE
GPG Key ID: B64802DC33A64FF6
4 changed files with 22 additions and 32 deletions

View File

@ -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)

View File

@ -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)));
}
}
}

View File

@ -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);
}

View File

@ -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();
}