Made redstone power be determined only when something changes

This commit is contained in:
Ellpeck 2015-12-03 18:40:43 +01:00
parent 5e0994fa29
commit 5993bb6e0f
16 changed files with 40 additions and 16 deletions

View file

@ -10,8 +10,10 @@
package ellpeck.actuallyadditions.blocks; package ellpeck.actuallyadditions.blocks;
import ellpeck.actuallyadditions.tile.TileEntityBase;
import ellpeck.actuallyadditions.tile.TileEntityInventoryBase; import ellpeck.actuallyadditions.tile.TileEntityInventoryBase;
import ellpeck.actuallyadditions.util.Util; import ellpeck.actuallyadditions.util.Util;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer; import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.item.EntityItem;
@ -74,4 +76,21 @@ public abstract class BlockContainerBase extends BlockContainer{
} }
return 0; return 0;
} }
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, Block block){
this.updateRedstoneState(world, x, y, z);
}
@Override
public void onBlockAdded(World world, int x, int y, int z){
this.updateRedstoneState(world, x, y, z);
}
private void updateRedstoneState(World world, int x, int y, int z){
TileEntity tile = world.getTileEntity(x, y, z);
if(tile instanceof TileEntityBase){
((TileEntityBase)tile).setRedstonePowered(world.isBlockIndirectlyGettingPowered(x, y, z));
}
}
} }

View file

@ -47,7 +47,7 @@ public class TileEntityAtomicReconstructor extends TileEntityInventoryBase imple
public void updateEntity(){ public void updateEntity(){
super.updateEntity(); super.updateEntity();
if(!this.worldObj.isRemote){ if(!this.worldObj.isRemote){
if(!worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord) && this.storage.getEnergyStored() >= ENERGY_USE){ if(!this.isRedstonePowered && this.storage.getEnergyStored() >= ENERGY_USE){
if(this.currentTime > 0){ if(this.currentTime > 0){
this.currentTime--; this.currentTime--;
if(this.currentTime <= 0){ if(this.currentTime <= 0){

View file

@ -24,7 +24,8 @@ import net.minecraft.world.World;
public abstract class TileEntityBase extends TileEntity{ public abstract class TileEntityBase extends TileEntity{
private int ticksElapsed; protected int ticksElapsed;
protected boolean isRedstonePowered;
public static void init(){ public static void init(){
ModUtil.LOGGER.info("Registering TileEntities..."); ModUtil.LOGGER.info("Registering TileEntities...");
@ -88,6 +89,10 @@ public abstract class TileEntityBase extends TileEntity{
this.ticksElapsed++; this.ticksElapsed++;
} }
public void setRedstonePowered(boolean powered){
this.isRedstonePowered = powered;
}
@Override @Override
public Packet getDescriptionPacket(){ public Packet getDescriptionPacket(){
NBTTagCompound tag = new NBTTagCompound(); NBTTagCompound tag = new NBTTagCompound();

View file

@ -51,7 +51,7 @@ public class TileEntityBreaker extends TileEntityInventoryBase{
public void updateEntity(){ public void updateEntity(){
super.updateEntity(); super.updateEntity();
if(!worldObj.isRemote){ if(!worldObj.isRemote){
if(!worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord)){ if(!this.isRedstonePowered){
if(this.currentTime > 0){ if(this.currentTime > 0){
this.currentTime--; this.currentTime--;
if(this.currentTime <= 0){ if(this.currentTime <= 0){

View file

@ -101,7 +101,7 @@ public class TileEntityCanolaPress extends TileEntityInventoryBase implements IE
if(this.tank.getFluidAmount() > 0){ if(this.tank.getFluidAmount() > 0){
WorldUtil.pushFluid(worldObj, xCoord, yCoord, zCoord, ForgeDirection.DOWN, this.tank); WorldUtil.pushFluid(worldObj, xCoord, yCoord, zCoord, ForgeDirection.DOWN, this.tank);
if(!worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord)){ if(!this.isRedstonePowered){
WorldUtil.pushFluid(worldObj, xCoord, yCoord, zCoord, ForgeDirection.NORTH, this.tank); WorldUtil.pushFluid(worldObj, xCoord, yCoord, zCoord, ForgeDirection.NORTH, this.tank);
WorldUtil.pushFluid(worldObj, xCoord, yCoord, zCoord, ForgeDirection.EAST, this.tank); WorldUtil.pushFluid(worldObj, xCoord, yCoord, zCoord, ForgeDirection.EAST, this.tank);
WorldUtil.pushFluid(worldObj, xCoord, yCoord, zCoord, ForgeDirection.SOUTH, this.tank); WorldUtil.pushFluid(worldObj, xCoord, yCoord, zCoord, ForgeDirection.SOUTH, this.tank);

View file

@ -94,7 +94,7 @@ public class TileEntityCoffeeMachine extends TileEntityInventoryBase implements
if(!worldObj.isRemote){ if(!worldObj.isRemote){
this.storeCoffee(); this.storeCoffee();
if(this.brewTime > 0 || this.worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord)){ if(this.brewTime > 0 || this.isRedstonePowered){
this.brew(); this.brew();
} }

View file

@ -41,7 +41,7 @@ public class TileEntityDirectionalBreaker extends TileEntityInventoryBase implem
public void updateEntity(){ public void updateEntity(){
super.updateEntity(); super.updateEntity();
if(!worldObj.isRemote){ if(!worldObj.isRemote){
if(!worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord)){ if(!this.isRedstonePowered){
if(this.storage.getEnergyStored() >= ENERGY_USE*RANGE){ if(this.storage.getEnergyStored() >= ENERGY_USE*RANGE){
if(this.currentTime > 0){ if(this.currentTime > 0){
this.currentTime--; this.currentTime--;

View file

@ -40,7 +40,7 @@ public class TileEntityDropper extends TileEntityInventoryBase{
public void updateEntity(){ public void updateEntity(){
super.updateEntity(); super.updateEntity();
if(!worldObj.isRemote){ if(!worldObj.isRemote){
if(!worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord)){ if(!this.isRedstonePowered){
if(this.currentTime > 0){ if(this.currentTime > 0){
this.currentTime--; this.currentTime--;
if(this.currentTime <= 0){ if(this.currentTime <= 0){

View file

@ -59,7 +59,7 @@ public class TileEntityFermentingBarrel extends TileEntityInventoryBase implemen
if(this.oilTank.getFluidAmount() > 0){ if(this.oilTank.getFluidAmount() > 0){
WorldUtil.pushFluid(worldObj, xCoord, yCoord, zCoord, ForgeDirection.DOWN, this.oilTank); WorldUtil.pushFluid(worldObj, xCoord, yCoord, zCoord, ForgeDirection.DOWN, this.oilTank);
if(!worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord)){ if(!this.isRedstonePowered){
WorldUtil.pushFluid(worldObj, xCoord, yCoord, zCoord, ForgeDirection.NORTH, this.oilTank); WorldUtil.pushFluid(worldObj, xCoord, yCoord, zCoord, ForgeDirection.NORTH, this.oilTank);
WorldUtil.pushFluid(worldObj, xCoord, yCoord, zCoord, ForgeDirection.EAST, this.oilTank); WorldUtil.pushFluid(worldObj, xCoord, yCoord, zCoord, ForgeDirection.EAST, this.oilTank);
WorldUtil.pushFluid(worldObj, xCoord, yCoord, zCoord, ForgeDirection.SOUTH, this.oilTank); WorldUtil.pushFluid(worldObj, xCoord, yCoord, zCoord, ForgeDirection.SOUTH, this.oilTank);

View file

@ -29,7 +29,7 @@ public class TileEntityFishingNet extends TileEntityBase{
public void updateEntity(){ public void updateEntity(){
super.updateEntity(); super.updateEntity();
if(!worldObj.isRemote){ if(!worldObj.isRemote){
if(!worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord)){ if(!this.isRedstonePowered){
if(worldObj.getBlock(xCoord, yCoord-1, zCoord).getMaterial() == Material.water){ if(worldObj.getBlock(xCoord, yCoord-1, zCoord).getMaterial() == Material.water){
if(this.timeUntilNextDrop > 0){ if(this.timeUntilNextDrop > 0){
this.timeUntilNextDrop--; this.timeUntilNextDrop--;

View file

@ -81,7 +81,7 @@ public class TileEntityFluidCollector extends TileEntityInventoryBase implements
public void updateEntity(){ public void updateEntity(){
super.updateEntity(); super.updateEntity();
if(!worldObj.isRemote){ if(!worldObj.isRemote){
if(!worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord)){ if(!this.isRedstonePowered){
if(this.currentTime > 0){ if(this.currentTime > 0){
this.currentTime--; this.currentTime--;
if(this.currentTime <= 0){ if(this.currentTime <= 0){
@ -138,7 +138,7 @@ public class TileEntityFluidCollector extends TileEntityInventoryBase implements
if(!this.isPlacer && this.tank.getFluidAmount() > 0){ if(!this.isPlacer && this.tank.getFluidAmount() > 0){
WorldUtil.pushFluid(worldObj, xCoord, yCoord, zCoord, ForgeDirection.DOWN, this.tank); WorldUtil.pushFluid(worldObj, xCoord, yCoord, zCoord, ForgeDirection.DOWN, this.tank);
if(!worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord)){ if(!this.isRedstonePowered){
WorldUtil.pushFluid(worldObj, xCoord, yCoord, zCoord, ForgeDirection.NORTH, this.tank); WorldUtil.pushFluid(worldObj, xCoord, yCoord, zCoord, ForgeDirection.NORTH, this.tank);
WorldUtil.pushFluid(worldObj, xCoord, yCoord, zCoord, ForgeDirection.EAST, this.tank); WorldUtil.pushFluid(worldObj, xCoord, yCoord, zCoord, ForgeDirection.EAST, this.tank);
WorldUtil.pushFluid(worldObj, xCoord, yCoord, zCoord, ForgeDirection.SOUTH, this.tank); WorldUtil.pushFluid(worldObj, xCoord, yCoord, zCoord, ForgeDirection.SOUTH, this.tank);

View file

@ -401,7 +401,7 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
this.initVars(); this.initVars();
//Is Block not powered by Redstone? //Is Block not powered by Redstone?
if(!worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord)){ if(!this.isRedstonePowered){
if(!(this.sideToPull == this.sideToPut && this.slotToPullStart == this.slotToPutStart && this.slotToPullEnd == this.slotToPutEnd)){ if(!(this.sideToPull == this.sideToPut && this.slotToPullStart == this.slotToPutStart && this.slotToPullEnd == this.slotToPutEnd)){
if(sideToPull != -1 && this.placeToPull instanceof IInventory){ if(sideToPull != -1 && this.placeToPull instanceof IInventory){
this.pull(); this.pull();

View file

@ -33,7 +33,7 @@ public class TileEntityLeafGenerator extends TileEntityBase implements IEnergyPr
public void updateEntity(){ public void updateEntity(){
super.updateEntity(); super.updateEntity();
if(!worldObj.isRemote){ if(!worldObj.isRemote){
if(!this.worldObj.isBlockIndirectlyGettingPowered(this.xCoord, this.yCoord, this.zCoord)){ if(!this.isRedstonePowered){
if(this.nextUseCounter >= 5){ if(this.nextUseCounter >= 5){
this.nextUseCounter = 0; this.nextUseCounter = 0;

View file

@ -31,7 +31,7 @@ public class TileEntityPhantomLiquiface extends TileEntityPhantomface implements
super.updateEntity(); super.updateEntity();
if(!worldObj.isRemote){ if(!worldObj.isRemote){
if(worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord) && this.isBoundThingInRange() && this.getHandler() != null){ if(this.isRedstonePowered && this.isBoundThingInRange() && this.getHandler() != null){
this.pushFluid(ForgeDirection.UP); this.pushFluid(ForgeDirection.UP);
this.pushFluid(ForgeDirection.DOWN); this.pushFluid(ForgeDirection.DOWN);
this.pushFluid(ForgeDirection.NORTH); this.pushFluid(ForgeDirection.NORTH);

View file

@ -51,7 +51,7 @@ public class TileEntityPhantomPlacer extends TileEntityInventoryBase implements
} }
if(this.isBoundThingInRange()){ if(this.isBoundThingInRange()){
if(!worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord)){ if(!this.isRedstonePowered){
if(this.currentTime > 0){ if(this.currentTime > 0){
this.currentTime--; this.currentTime--;
if(this.currentTime <= 0){ if(this.currentTime <= 0){

View file

@ -36,7 +36,7 @@ public class TileEntityRangedCollector extends TileEntityInventoryBase implement
public void updateEntity(){ public void updateEntity(){
super.updateEntity(); super.updateEntity();
if(!worldObj.isRemote){ if(!worldObj.isRemote){
if(!worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord)){ if(!this.isRedstonePowered){
ArrayList<EntityItem> items = (ArrayList<EntityItem>)this.worldObj.getEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.getBoundingBox(this.xCoord-RANGE, this.yCoord-RANGE, this.zCoord-RANGE, this.xCoord+RANGE, this.yCoord+RANGE, this.zCoord+RANGE)); ArrayList<EntityItem> items = (ArrayList<EntityItem>)this.worldObj.getEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.getBoundingBox(this.xCoord-RANGE, this.yCoord-RANGE, this.zCoord-RANGE, this.xCoord+RANGE, this.yCoord+RANGE, this.zCoord+RANGE));
if(!items.isEmpty()){ if(!items.isEmpty()){
for(EntityItem item : items){ for(EntityItem item : items){