From 9d04c236c771b3e8e462c6a8679af072758fcbec Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Thu, 5 May 2016 17:50:18 +0200 Subject: [PATCH] Made the Phantom Redstoneface not update twice when binding to an already active redstone --- .../tile/TileEntityPhantomRedstoneface.java | 24 ++++++++++------- .../mod/tile/TileEntityPhantomface.java | 27 ++++++++++++------- 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomRedstoneface.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomRedstoneface.java index 17004796d..2d3e9e0c8 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomRedstoneface.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomRedstoneface.java @@ -21,8 +21,6 @@ public class TileEntityPhantomRedstoneface extends TileEntityPhantomface{ @Override public void updateEntity(){ - super.updateEntity(); - if(!this.worldObj.isRemote){ if(this.isBoundThingInRange()){ IBlockState boundState = this.worldObj.getBlockState(this.boundPosition); @@ -37,13 +35,21 @@ public class TileEntityPhantomRedstoneface extends TileEntityPhantomface{ } } } - - if(!Arrays.equals(this.providesStrong, this.lastProvidesStrong) || !Arrays.equals(this.providesWeak, this.lastProvidesWeak)){ - System.arraycopy(this.providesWeak, 0, this.lastProvidesWeak, 0, this.providesWeak.length); - System.arraycopy(this.providesStrong, 0, this.lastProvidesStrong, 0, this.providesStrong.length); - - this.worldObj.notifyNeighborsOfStateChange(this.pos, PosUtil.getBlock(this.pos, this.worldObj)); - } } + + super.updateEntity(); + } + + @Override + protected boolean doesNeedUpdateSend(){ + return super.doesNeedUpdateSend() || !Arrays.equals(this.providesStrong, this.lastProvidesStrong) || !Arrays.equals(this.providesWeak, this.lastProvidesWeak); + } + + @Override + protected void onUpdateSent(){ + System.arraycopy(this.providesWeak, 0, this.lastProvidesWeak, 0, this.providesWeak.length); + System.arraycopy(this.providesStrong, 0, this.lastProvidesStrong, 0, this.providesStrong.length); + + super.onUpdateSent(); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomface.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomface.java index 0ac068edf..f4ff0f1e7 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomface.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomface.java @@ -90,15 +90,9 @@ public class TileEntityPhantomface extends TileEntityInventoryBase implements IP this.boundPosition = null; } - if(this.boundPosition != this.boundPosBefore || (this.boundPosition != null && PosUtil.getBlock(this.boundPosition, this.worldObj) != this.boundBlockBefore) || this.rangeBefore != this.range){ - this.rangeBefore = this.range; - this.boundPosBefore = this.boundPosition; - this.boundBlockBefore = this.boundPosition == null ? null : PosUtil.getBlock(this.boundPosition, this.worldObj); - - this.worldObj.notifyNeighborsOfStateChange(this.pos, PosUtil.getBlock(this.pos, this.worldObj)); - - this.sendUpdate(); - this.markDirty(); + if(this.doesNeedUpdateSend()){ + this.onUpdateSent(); + System.out.println("UPDAT!"); } } else{ @@ -108,6 +102,21 @@ public class TileEntityPhantomface extends TileEntityInventoryBase implements IP } } + protected boolean doesNeedUpdateSend(){ + return this.boundPosition != this.boundPosBefore || (this.boundPosition != null && PosUtil.getBlock(this.boundPosition, this.worldObj) != this.boundBlockBefore) || this.rangeBefore != this.range; + } + + protected void onUpdateSent(){ + this.rangeBefore = this.range; + this.boundPosBefore = this.boundPosition; + this.boundBlockBefore = this.boundPosition == null ? null : PosUtil.getBlock(this.boundPosition, this.worldObj); + + this.worldObj.notifyNeighborsOfStateChange(this.pos, PosUtil.getBlock(this.pos, this.worldObj)); + + this.sendUpdate(); + this.markDirty(); + } + @Override public boolean isItemValidForSlot(int slot, ItemStack stack){ return false;