diff --git a/src/minecraft/assemblyline/common/block/BlockALMachine.java b/src/minecraft/assemblyline/common/block/BlockALMachine.java index 755690435..5968c5589 100644 --- a/src/minecraft/assemblyline/common/block/BlockALMachine.java +++ b/src/minecraft/assemblyline/common/block/BlockALMachine.java @@ -37,7 +37,10 @@ public class BlockALMachine extends BlockAdvanced { TileEntityAssembly asm = (TileEntityAssembly) ent; String output = "Debug>>>"; - output += "Channel:" + (asm.getTileNetwork() != null ? asm.getTileNetwork().toString() : "Error") + "|"; + output += "Channel:" + (asm.getTileNetwork() != null ? asm.getTileNetwork().toString() : "Error") + "|"; + entityPlayer.sendChatToPlayer(output); + output = "Debug>>>"; + output += "Powered:"+asm.powered + " By:"+(asm.powerSource != null ? asm.powerSource.toString() : "Error"); entityPlayer.sendChatToPlayer(output); } return super.onBlockActivated(world, x, y, z, entityPlayer, side, hitX, hitY, hitZ); diff --git a/src/minecraft/assemblyline/common/machine/NetworkAssembly.java b/src/minecraft/assemblyline/common/machine/NetworkAssembly.java index 3738d125a..a08793dd7 100644 --- a/src/minecraft/assemblyline/common/machine/NetworkAssembly.java +++ b/src/minecraft/assemblyline/common/machine/NetworkAssembly.java @@ -69,7 +69,7 @@ public class NetworkAssembly extends NetworkTileEntities { if (((TileEntityAssembly) part).powered) { - this.markAsPowerSource((TileEntity) part); + this.markAsPowerSource((TileEntity) part, true); } } return added; @@ -81,18 +81,21 @@ public class NetworkAssembly extends NetworkTileEntities return super.isValidMember(part) && part instanceof TileEntityAssembly; } - /** Marks a tile as the source of power for the network */ - public void markAsPowerSource(TileEntity entity) + /** Marks a tile as the source of power for the network + * + * @param powered true to add, false to remove */ + public void markAsPowerSource(TileEntity entity, boolean powered) { - if (!this.powerSources.contains(entity)) + if (powered) { - this.powerSources.add(entity); + if (!this.powerSources.contains(entity)) + { + this.powerSources.add(entity); + } + } + else + { + this.powerSources.remove(entity); } } - - /** unmarks or removes the tile as a source of power for the network */ - public void removeAsPowerSource(TileEntity entity) - { - this.powerSources.remove(entity); - } } diff --git a/src/minecraft/assemblyline/common/machine/TileEntityAssembly.java b/src/minecraft/assemblyline/common/machine/TileEntityAssembly.java index a3efb0102..1e30c1c63 100644 --- a/src/minecraft/assemblyline/common/machine/TileEntityAssembly.java +++ b/src/minecraft/assemblyline/common/machine/TileEntityAssembly.java @@ -1,8 +1,11 @@ package assemblyline.common.machine; +import java.util.Random; + import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.ForgeDirection; import universalelectricity.core.electricity.ElectricityPack; +import universalelectricity.core.vector.Vector3; import assemblyline.common.AssemblyLine; import dark.core.api.INetworkPart; import dark.core.tile.network.NetworkTileEntities; @@ -20,32 +23,45 @@ public abstract class TileEntityAssembly extends TileEntityRunnableMachine imple private NetworkAssembly assemblyNetwork; /** Tiles that are connected to this */ private TileEntity[] connectedTiles = new TileEntity[6]; - private TileEntityAssembly powerSource; + /** Cached power source to reduce the need to path find for a new one each tick */ + public TileEntityAssembly powerSource; + /** Random instance */ + public Random random = new Random(); + /** Number of ticks this can go without power */ + private int powerTicks = 0; + private int updateTick = 1; @Override public void updateEntity() { super.updateEntity(); + if (ticks % updateTick == 0) + { + this.updateTick = ((int) random.nextInt(10) + 20); + this.updateNetworkConnections(); + this.powerSource = null; + } if (this.wattsReceived >= this.getRequest().getWatts()) { this.wattsReceived -= getRequest().getWatts(); this.powered = true; - if (this.getTileNetwork() instanceof NetworkAssembly) - { - NetworkAssembly net = ((NetworkAssembly) this.getTileNetwork()); - net.markAsPowerSource(this); - } + this.powerTicks = 2; + + } + else if (this.powerTicks > 0) + { + this.powerTicks--; + this.powered = true; } else { this.powered = false; - if (this.getTileNetwork() instanceof NetworkAssembly) - { - NetworkAssembly net = ((NetworkAssembly) this.getTileNetwork()); - net.removeAsPowerSource(this); - } - + } + if (this.getTileNetwork() instanceof NetworkAssembly) + { + NetworkAssembly net = ((NetworkAssembly) this.getTileNetwork()); + net.markAsPowerSource(this, this.powered); } this.onUpdate(); @@ -137,4 +153,9 @@ public abstract class TileEntityAssembly extends TileEntityRunnableMachine imple } } + + public String toString() + { + return "AssemblyTile>>>At>>>" + (new Vector3(this).toString()); + } } diff --git a/src/minecraft/assemblyline/common/machine/belt/BlockConveyorBelt.java b/src/minecraft/assemblyline/common/machine/belt/BlockConveyorBelt.java index d75ec84d0..1f8111950 100644 --- a/src/minecraft/assemblyline/common/machine/belt/BlockConveyorBelt.java +++ b/src/minecraft/assemblyline/common/machine/belt/BlockConveyorBelt.java @@ -170,6 +170,7 @@ public class BlockConveyorBelt extends BlockALMachine @Override public void onBlockPlacedBy(World world, int x, int y, int z, EntityLiving par5EntityLiving, ItemStack stack) { + super.onBlockPlacedBy(world, x, y, z, par5EntityLiving, stack); int angle = MathHelper.floor_double((par5EntityLiving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; int change = 2;