From 202a775a6d9fadcf6951b5959da2ba3ce42d88fe Mon Sep 17 00:00:00 2001 From: DarkGuardsman Date: Sat, 6 Jul 2013 00:46:56 -0400 Subject: [PATCH] Cleanup and fixed network split --- .../common/armbot/BlockArmbot.java | 4 +- .../common/imprinter/BlockImprinter.java | 4 +- .../imprinter/prefab/BlockImprintable.java | 4 +- ...BlockALMachine.java => BlockAssembly.java} | 14 +++++-- .../common/machine/BlockCrate.java | 2 +- .../common/machine/BlockTurntable.java | 2 +- .../common/machine/NetworkAssembly.java | 38 +++++++++---------- .../common/machine/TileEntityAssembly.java | 21 ++++++---- .../machine/belt/BlockConveyorBelt.java | 4 +- .../machine/crane/BlockCraneController.java | 4 +- .../common/machine/crane/BlockCraneFrame.java | 4 +- .../common/machine/encoder/BlockEncoder.java | 4 +- 12 files changed, 58 insertions(+), 47 deletions(-) rename src/minecraft/assemblyline/common/machine/{BlockALMachine.java => BlockAssembly.java} (80%) diff --git a/src/minecraft/assemblyline/common/armbot/BlockArmbot.java b/src/minecraft/assemblyline/common/armbot/BlockArmbot.java index 9c70da7ad..5fcf25a73 100644 --- a/src/minecraft/assemblyline/common/armbot/BlockArmbot.java +++ b/src/minecraft/assemblyline/common/armbot/BlockArmbot.java @@ -11,11 +11,11 @@ import universalelectricity.core.vector.Vector3; import universalelectricity.prefab.multiblock.IMultiBlock; import assemblyline.client.render.BlockRenderingHandler; import assemblyline.common.TabAssemblyLine; -import assemblyline.common.machine.BlockALMachine; +import assemblyline.common.machine.BlockAssembly; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -public class BlockArmbot extends BlockALMachine +public class BlockArmbot extends BlockAssembly { public BlockArmbot(int id) { diff --git a/src/minecraft/assemblyline/common/imprinter/BlockImprinter.java b/src/minecraft/assemblyline/common/imprinter/BlockImprinter.java index 6c6c06109..7bfef5764 100644 --- a/src/minecraft/assemblyline/common/imprinter/BlockImprinter.java +++ b/src/minecraft/assemblyline/common/imprinter/BlockImprinter.java @@ -15,11 +15,11 @@ import net.minecraft.world.World; import assemblyline.common.AssemblyLine; import assemblyline.common.CommonProxy; import assemblyline.common.TabAssemblyLine; -import assemblyline.common.machine.BlockALMachine; +import assemblyline.common.machine.BlockAssembly; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -public class BlockImprinter extends BlockALMachine +public class BlockImprinter extends BlockAssembly { Icon imprinter_side; Icon imprinter_top; diff --git a/src/minecraft/assemblyline/common/imprinter/prefab/BlockImprintable.java b/src/minecraft/assemblyline/common/imprinter/prefab/BlockImprintable.java index 683108716..cc44505ad 100644 --- a/src/minecraft/assemblyline/common/imprinter/prefab/BlockImprintable.java +++ b/src/minecraft/assemblyline/common/imprinter/prefab/BlockImprintable.java @@ -12,14 +12,14 @@ import net.minecraft.world.World; import universalelectricity.prefab.implement.IRedstoneReceptor; import assemblyline.api.IFilterable; import assemblyline.common.imprinter.ItemImprinter; -import assemblyline.common.machine.BlockALMachine; +import assemblyline.common.machine.BlockAssembly; /** * Extend this block class if a filter is allowed to be placed inside of this block. * * @author Calclavia */ -public abstract class BlockImprintable extends BlockALMachine +public abstract class BlockImprintable extends BlockAssembly { public BlockImprintable(String name, int id, Material material, CreativeTabs creativeTab) { diff --git a/src/minecraft/assemblyline/common/machine/BlockALMachine.java b/src/minecraft/assemblyline/common/machine/BlockAssembly.java similarity index 80% rename from src/minecraft/assemblyline/common/machine/BlockALMachine.java rename to src/minecraft/assemblyline/common/machine/BlockAssembly.java index bb7d80bd4..d11e2be75 100644 --- a/src/minecraft/assemblyline/common/machine/BlockALMachine.java +++ b/src/minecraft/assemblyline/common/machine/BlockAssembly.java @@ -9,6 +9,8 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Icon; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; +import universalelectricity.core.electricity.ElectricityDisplay; +import universalelectricity.core.electricity.ElectricityDisplay.ElectricUnit; import universalelectricity.prefab.block.BlockAdvanced; import assemblyline.common.AssemblyLine; import assemblyline.common.TabAssemblyLine; @@ -16,11 +18,11 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import dark.core.api.INetworkPart; -public class BlockALMachine extends BlockAdvanced +public class BlockAssembly extends BlockAdvanced { public Icon machine_icon; - public BlockALMachine(int id, Material material, String name) + public BlockAssembly(int id, Material material, String name) { super(AssemblyLine.CONFIGURATION.getBlock(name, id).getInt(), material); this.setUnlocalizedName(name); @@ -39,7 +41,13 @@ public class BlockALMachine extends BlockAdvanced output += "Channel:" + (asm.getTileNetwork() != null ? asm.getTileNetwork().toString() : "Error") + "|"; entityPlayer.sendChatToPlayer(output); output = "Debug>>>"; - output += "Powered:" + asm.running; + output += "Powered:" + asm.running + " "; + if (asm.getTileNetwork() instanceof NetworkAssembly) + { + output += ElectricityDisplay.getDisplaySimple(((NetworkAssembly) asm.getTileNetwork()).getCurrentBattery(), ElectricUnit.WATT, 2); + output += "/"; + output += ElectricityDisplay.getDisplaySimple(((NetworkAssembly) asm.getTileNetwork()).getMaxBattery(), ElectricUnit.WATT, 2); + } entityPlayer.sendChatToPlayer(output); } return super.onBlockActivated(world, x, y, z, entityPlayer, side, hitX, hitY, hitZ); diff --git a/src/minecraft/assemblyline/common/machine/BlockCrate.java b/src/minecraft/assemblyline/common/machine/BlockCrate.java index 9fe919b0a..e6f9ec2d8 100644 --- a/src/minecraft/assemblyline/common/machine/BlockCrate.java +++ b/src/minecraft/assemblyline/common/machine/BlockCrate.java @@ -25,7 +25,7 @@ import cpw.mods.fml.relauncher.SideOnly; * @author Calclavia * */ -public class BlockCrate extends BlockALMachine +public class BlockCrate extends BlockAssembly { Icon crate_icon; diff --git a/src/minecraft/assemblyline/common/machine/BlockTurntable.java b/src/minecraft/assemblyline/common/machine/BlockTurntable.java index 783d17200..b6d6553fe 100644 --- a/src/minecraft/assemblyline/common/machine/BlockTurntable.java +++ b/src/minecraft/assemblyline/common/machine/BlockTurntable.java @@ -21,7 +21,7 @@ import assemblyline.common.TabAssemblyLine; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -public class BlockTurntable extends BlockALMachine +public class BlockTurntable extends BlockAssembly { private Icon top; diff --git a/src/minecraft/assemblyline/common/machine/NetworkAssembly.java b/src/minecraft/assemblyline/common/machine/NetworkAssembly.java index 46f2a16a4..2ef43fe8e 100644 --- a/src/minecraft/assemblyline/common/machine/NetworkAssembly.java +++ b/src/minecraft/assemblyline/common/machine/NetworkAssembly.java @@ -1,26 +1,13 @@ package assemblyline.common.machine; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Set; - -import universalelectricity.core.block.IConductor; -import universalelectricity.core.block.IConnectionProvider; -import universalelectricity.core.electricity.ElectricityPack; -import universalelectricity.core.electricity.IElectricityNetwork; -import universalelectricity.core.vector.Vector3; - -import net.minecraft.tileentity.TileEntity; -import net.minecraftforge.common.ForgeDirection; import dark.core.api.INetworkPart; import dark.core.tile.network.NetworkPowerTiles; import dark.core.tile.network.NetworkTileEntities; public class NetworkAssembly extends NetworkPowerTiles { - /** List of network members that are providing power for the network */ - private List powerSources = new ArrayList(); + + /** Power stored to be used by network members */ private double wattStored = 0.0; public NetworkAssembly(INetworkPart... parts) @@ -28,12 +15,17 @@ public class NetworkAssembly extends NetworkPowerTiles super(parts); } - /** Checks if the tile can run as well sucks up energy for the tile to run */ - public boolean canRun(TileEntityAssembly tile) + public NetworkTileEntities newInstance() { - if (tile != null && this.wattStored >= tile.getRequest(ForgeDirection.UNKNOWN)) + return new NetworkAssembly(); + } + + /** Checks if the tile can run as well sucks up energy for the tile to run */ + public boolean doPowerRun(TileEntityAssembly tile) + { + if (tile != null && this.wattStored >= tile.getRequest()) { - this.wattStored -= tile.getRequest(ForgeDirection.UNKNOWN); + this.wattStored -= tile.getRequest(); return true; } return false; @@ -72,7 +64,7 @@ public class NetworkAssembly extends NetworkPowerTiles } @Override - public void postMergeProcessing(NetworkTileEntities network) + public void mergeDo(NetworkTileEntities network) { NetworkAssembly newNetwork = new NetworkAssembly(); newNetwork.getNetworkMemebers().addAll(this.getNetworkMemebers()); @@ -87,4 +79,10 @@ public class NetworkAssembly extends NetworkPowerTiles return super.isValidMember(part) && part instanceof TileEntityAssembly; } + @Override + public String toString() + { + return "AssemblyNetwork[" + this.hashCode() + "|parts:" + this.networkMember.size() + "]"; + } + } diff --git a/src/minecraft/assemblyline/common/machine/TileEntityAssembly.java b/src/minecraft/assemblyline/common/machine/TileEntityAssembly.java index 9db726a46..cd736518a 100644 --- a/src/minecraft/assemblyline/common/machine/TileEntityAssembly.java +++ b/src/minecraft/assemblyline/common/machine/TileEntityAssembly.java @@ -54,17 +54,22 @@ public abstract class TileEntityAssembly extends TileEntityRunnableMachine imple public void invalidate() { NetworkAssembly.invalidate(this); + if (this.getTileNetwork() != null) + { + this.getTileNetwork().splitNetwork(this.worldObj, this); + } super.invalidate(); } @Override public void updateEntity() { - boolean prevRun = this.running; - this.powered = false; - super.updateEntity(); + if (!this.worldObj.isRemote) { + boolean prevRun = this.running; + this.powered = false; + super.updateEntity(); if (ticks % updateTick == 0) { this.updateTick = ((int) random.nextInt(10) + 20); @@ -105,14 +110,14 @@ public abstract class TileEntityAssembly extends TileEntityRunnableMachine imple /** Checks to see if this assembly tile can run using several methods */ public boolean isRunning() { - if (!worldObj.isRemote) + if (!this.worldObj.isRemote) { - boolean running = AssemblyLine.REQUIRE_NO_POWER; - if (!running && this.getTileNetwork() instanceof NetworkAssembly) + boolean on = AssemblyLine.REQUIRE_NO_POWER; + if (!on && this.getTileNetwork() instanceof NetworkAssembly) { - running = ((NetworkAssembly) this.getTileNetwork()).canRun(this); + on = ((NetworkAssembly) this.getTileNetwork()).doPowerRun(this); } - return running; + return on; } else { diff --git a/src/minecraft/assemblyline/common/machine/belt/BlockConveyorBelt.java b/src/minecraft/assemblyline/common/machine/belt/BlockConveyorBelt.java index 45f17ca55..56b4af104 100644 --- a/src/minecraft/assemblyline/common/machine/belt/BlockConveyorBelt.java +++ b/src/minecraft/assemblyline/common/machine/belt/BlockConveyorBelt.java @@ -16,7 +16,7 @@ import net.minecraftforge.common.ForgeDirection; import universalelectricity.core.UniversalElectricity; import assemblyline.client.render.BlockRenderingHandler; import assemblyline.common.TabAssemblyLine; -import assemblyline.common.machine.BlockALMachine; +import assemblyline.common.machine.BlockAssembly; import assemblyline.common.machine.belt.TileEntityConveyorBelt.SlantType; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -26,7 +26,7 @@ import cpw.mods.fml.relauncher.SideOnly; * * @author Calclavia, DarkGuardsman */ -public class BlockConveyorBelt extends BlockALMachine +public class BlockConveyorBelt extends BlockAssembly { public BlockConveyorBelt(int id) { diff --git a/src/minecraft/assemblyline/common/machine/crane/BlockCraneController.java b/src/minecraft/assemblyline/common/machine/crane/BlockCraneController.java index 78bc36a39..dbc73ae20 100644 --- a/src/minecraft/assemblyline/common/machine/crane/BlockCraneController.java +++ b/src/minecraft/assemblyline/common/machine/crane/BlockCraneController.java @@ -8,11 +8,11 @@ import net.minecraftforge.common.ForgeDirection; import universalelectricity.core.UniversalElectricity; import assemblyline.client.render.BlockRenderingHandler; import assemblyline.common.TabAssemblyLine; -import assemblyline.common.machine.BlockALMachine; +import assemblyline.common.machine.BlockAssembly; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -public class BlockCraneController extends BlockALMachine +public class BlockCraneController extends BlockAssembly { public BlockCraneController(int id) { diff --git a/src/minecraft/assemblyline/common/machine/crane/BlockCraneFrame.java b/src/minecraft/assemblyline/common/machine/crane/BlockCraneFrame.java index e698a563a..c72c45c48 100644 --- a/src/minecraft/assemblyline/common/machine/crane/BlockCraneFrame.java +++ b/src/minecraft/assemblyline/common/machine/crane/BlockCraneFrame.java @@ -8,11 +8,11 @@ import net.minecraftforge.common.ForgeDirection; import universalelectricity.core.UniversalElectricity; import assemblyline.client.render.BlockRenderingHandler; import assemblyline.common.TabAssemblyLine; -import assemblyline.common.machine.BlockALMachine; +import assemblyline.common.machine.BlockAssembly; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -public class BlockCraneFrame extends BlockALMachine +public class BlockCraneFrame extends BlockAssembly { public BlockCraneFrame(int id) { diff --git a/src/minecraft/assemblyline/common/machine/encoder/BlockEncoder.java b/src/minecraft/assemblyline/common/machine/encoder/BlockEncoder.java index 0a1cb93af..059c9d047 100644 --- a/src/minecraft/assemblyline/common/machine/encoder/BlockEncoder.java +++ b/src/minecraft/assemblyline/common/machine/encoder/BlockEncoder.java @@ -10,11 +10,11 @@ import net.minecraft.world.World; import assemblyline.common.AssemblyLine; import assemblyline.common.CommonProxy; import assemblyline.common.TabAssemblyLine; -import assemblyline.common.machine.BlockALMachine; +import assemblyline.common.machine.BlockAssembly; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -public class BlockEncoder extends BlockALMachine +public class BlockEncoder extends BlockAssembly { Icon encoder_side; Icon encoder_top;