Made the Phantom Redstoneface not update twice when binding to an already active redstone

This commit is contained in:
Ellpeck 2016-05-05 17:50:18 +02:00
parent 6a0d4ca611
commit 9d04c236c7
2 changed files with 33 additions and 18 deletions

View file

@ -21,8 +21,6 @@ public class TileEntityPhantomRedstoneface extends TileEntityPhantomface{
@Override @Override
public void updateEntity(){ public void updateEntity(){
super.updateEntity();
if(!this.worldObj.isRemote){ if(!this.worldObj.isRemote){
if(this.isBoundThingInRange()){ if(this.isBoundThingInRange()){
IBlockState boundState = this.worldObj.getBlockState(this.boundPosition); 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)){ 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.providesWeak, 0, this.lastProvidesWeak, 0, this.providesWeak.length);
System.arraycopy(this.providesStrong, 0, this.lastProvidesStrong, 0, this.providesStrong.length); System.arraycopy(this.providesStrong, 0, this.lastProvidesStrong, 0, this.providesStrong.length);
this.worldObj.notifyNeighborsOfStateChange(this.pos, PosUtil.getBlock(this.pos, this.worldObj)); super.onUpdateSent();
}
}
} }
} }

View file

@ -90,7 +90,23 @@ public class TileEntityPhantomface extends TileEntityInventoryBase implements IP
this.boundPosition = null; this.boundPosition = null;
} }
if(this.boundPosition != this.boundPosBefore || (this.boundPosition != null && PosUtil.getBlock(this.boundPosition, this.worldObj) != this.boundBlockBefore) || this.rangeBefore != this.range){ if(this.doesNeedUpdateSend()){
this.onUpdateSent();
System.out.println("UPDAT!");
}
}
else{
if(this.boundPosition != null){
this.renderParticles();
}
}
}
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.rangeBefore = this.range;
this.boundPosBefore = this.boundPosition; this.boundPosBefore = this.boundPosition;
this.boundBlockBefore = this.boundPosition == null ? null : PosUtil.getBlock(this.boundPosition, this.worldObj); this.boundBlockBefore = this.boundPosition == null ? null : PosUtil.getBlock(this.boundPosition, this.worldObj);
@ -100,13 +116,6 @@ public class TileEntityPhantomface extends TileEntityInventoryBase implements IP
this.sendUpdate(); this.sendUpdate();
this.markDirty(); this.markDirty();
} }
}
else{
if(this.boundPosition != null){
this.renderParticles();
}
}
}
@Override @Override
public boolean isItemValidForSlot(int slot, ItemStack stack){ public boolean isItemValidForSlot(int slot, ItemStack stack){