From 1127fca76dea1cb929715d692ce81a76cefb91d1 Mon Sep 17 00:00:00 2001 From: astoria Date: Mon, 3 Apr 2023 10:03:55 -0500 Subject: [PATCH] Only update when needed --- .../afloydwiremod/api/AbstractWireTileEntity.java | 8 ++++++-- .../brokenmoon/afloydwiremod/tile/RedstoneLinkTile.java | 2 ++ .../afloydwiremod/tileentity/ChipTileEntity.java | 4 ++-- .../afloydwiremod/tileentity/RedstoneLinkTileEntity.java | 3 +-- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/brokenmoon/afloydwiremod/api/AbstractWireTileEntity.java b/src/main/java/net/brokenmoon/afloydwiremod/api/AbstractWireTileEntity.java index 49eb20a..47fdf32 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/api/AbstractWireTileEntity.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/api/AbstractWireTileEntity.java @@ -11,8 +11,7 @@ public abstract class AbstractWireTileEntity extends TileEntity { public boolean initialized = false; public boolean hasSettings = false; - @Override - public void updateEntity() { + public void update() { updateIO(); } @@ -79,6 +78,7 @@ public abstract class AbstractWireTileEntity extends TileEntity { for (int i = 0; i < outputs.length; ++i) { if (outputs[i].wire != null && outputs[i].wire.thisslot > -1) { WireConnection wire = outputs[i].wire; + Boolean doUpdate = false; AbstractWireTileEntity otherChip = (AbstractWireTileEntity)this.worldObj.getBlockTileEntity(wire.x, wire.y, wire.z); if(otherChip == null){ this.outputs[i].wire = new WireConnection(); @@ -90,10 +90,14 @@ public abstract class AbstractWireTileEntity extends TileEntity { } if(outputs[i].floatvalue != otherChip.inputs[wire.thatslot].floatvalue) { otherChip.inputs[wire.thatslot].floatvalue = outputs[i].floatvalue; + doUpdate = true; } if(!outputs[i].stringvalue.equals(otherChip.inputs[wire.thatslot].stringvalue)) { otherChip.inputs[wire.thatslot].stringvalue = outputs[i].stringvalue; + doUpdate = true; } + if(doUpdate) + otherChip.update(); } } } diff --git a/src/main/java/net/brokenmoon/afloydwiremod/tile/RedstoneLinkTile.java b/src/main/java/net/brokenmoon/afloydwiremod/tile/RedstoneLinkTile.java index 9bb4fbc..21d6621 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/tile/RedstoneLinkTile.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/tile/RedstoneLinkTile.java @@ -66,8 +66,10 @@ public class RedstoneLinkTile extends AbstractWireTile { RedstoneLinkTileEntity link = (RedstoneLinkTileEntity) world.getBlockTileEntity(i, j, k); if (world.isBlockGettingPowered(i, j, k)) { link.outputs[0].floatvalue = 1.0f; + link.updateIO(); } else { link.outputs[0].floatvalue = 0.0f; + link.updateIO(); } } diff --git a/src/main/java/net/brokenmoon/afloydwiremod/tileentity/ChipTileEntity.java b/src/main/java/net/brokenmoon/afloydwiremod/tileentity/ChipTileEntity.java index a9b95df..3a34758 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/tileentity/ChipTileEntity.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/tileentity/ChipTileEntity.java @@ -9,13 +9,13 @@ public class ChipTileEntity extends AbstractWireTileEntity { private boolean shouldIncrement = true; @Override - public void updateEntity() { + public void update() { switch (mode) { case "count": doIncrement(); + updateIO(); break; } - updateIO(); } public void doIncrement() { diff --git a/src/main/java/net/brokenmoon/afloydwiremod/tileentity/RedstoneLinkTileEntity.java b/src/main/java/net/brokenmoon/afloydwiremod/tileentity/RedstoneLinkTileEntity.java index 33a1cf9..87cb766 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/tileentity/RedstoneLinkTileEntity.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/tileentity/RedstoneLinkTileEntity.java @@ -31,7 +31,7 @@ public class RedstoneLinkTileEntity extends AbstractWireTileEntity { nbttagcompound.setBoolean("activity", this.isActive); } @Override - public void updateEntity() { + public void update() { if(inputs[0].floatvalue > 0 && !this.isActive && worldObj.blockExists(xCoord, yCoord, zCoord) && worldObj.getBlockId(xCoord, yCoord, zCoord) == WireMod.LinkTileInactive.blockID){ this.shouldnotremove = true; RedstoneLinkTile.updateLinkBlockState(true, this.worldObj, this.xCoord, this.yCoord, this.zCoord); @@ -43,6 +43,5 @@ public class RedstoneLinkTileEntity extends AbstractWireTileEntity { this.shouldnotremove = false; this.isActive = false; } - updateIO(); } }