From 9d4b1b9782fb66e989e8eb9f4a19489ea6689a6e Mon Sep 17 00:00:00 2001 From: CovertJaguar Date: Wed, 20 Nov 2013 17:27:01 -0800 Subject: [PATCH] Move ILaserTarget to the power API --- common/buildcraft/api/power/ILaserTarget.java | 46 +++++++++++++++++++ common/buildcraft/silicon/ILaserTarget.java | 15 ------ .../silicon/TileAdvancedCraftingTable.java | 7 +-- .../buildcraft/silicon/TileAssemblyTable.java | 17 +++---- common/buildcraft/silicon/TileLaser.java | 12 ++--- 5 files changed, 65 insertions(+), 32 deletions(-) create mode 100644 common/buildcraft/api/power/ILaserTarget.java delete mode 100644 common/buildcraft/silicon/ILaserTarget.java diff --git a/common/buildcraft/api/power/ILaserTarget.java b/common/buildcraft/api/power/ILaserTarget.java new file mode 100644 index 00000000..3d1eca59 --- /dev/null +++ b/common/buildcraft/api/power/ILaserTarget.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) SpaceToad, 2011-2012 + * http://www.mod-buildcraft.com + * + * BuildCraft is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * http://www.mod-buildcraft.com/MMPL-1.0.txt + */ +package buildcraft.api.power; + +/** + * Specifies a Tile Entity that can receive power via laser beam. + * + * @author cpw + */ +public interface ILaserTarget { + + /** + * Returns true if the target currently needs power. For example, if the Advanced + * Crafting Table has work to do. + * + * @return true if needs power + */ + boolean requiresLaserEnergy(); + + /** + * Transfers energy from the laser to the target. + * + * @param energy + */ + void receiveLaserEnergy(float energy); + + /** + * Return true if the Tile Entity object is no longer a valid target. For + * example, if its been invalidated. + * + * @return true if no longer a valid target object + */ + boolean isInvalidTarget(); + + int getXCoord(); + + int getYCoord(); + + int getZCoord(); +} diff --git a/common/buildcraft/silicon/ILaserTarget.java b/common/buildcraft/silicon/ILaserTarget.java deleted file mode 100644 index 46a39b60..00000000 --- a/common/buildcraft/silicon/ILaserTarget.java +++ /dev/null @@ -1,15 +0,0 @@ -package buildcraft.silicon; - -public interface ILaserTarget { - boolean hasCurrentWork(); - - void receiveLaserEnergy(float energy); - - boolean isInvalidTarget(); - - int getXCoord(); - - int getYCoord(); - - int getZCoord(); -} diff --git a/common/buildcraft/silicon/TileAdvancedCraftingTable.java b/common/buildcraft/silicon/TileAdvancedCraftingTable.java index 8fd35a15..89a1e9d5 100644 --- a/common/buildcraft/silicon/TileAdvancedCraftingTable.java +++ b/common/buildcraft/silicon/TileAdvancedCraftingTable.java @@ -1,5 +1,6 @@ package buildcraft.silicon; +import buildcraft.api.power.ILaserTarget; import buildcraft.BuildCraftCore; import buildcraft.api.gates.IAction; import buildcraft.api.gates.IActionReceptor; @@ -413,8 +414,8 @@ public class TileAdvancedCraftingTable extends TileEntity implements IInventory, } @Override - public boolean hasCurrentWork() { - return craftable && !justCrafted && lastMode != ActionMachineControl.Mode.Off; + public boolean requiresLaserEnergy() { + return craftable && !justCrafted && lastMode != ActionMachineControl.Mode.Off && storedEnergy < REQUIRED_POWER * 10; } @Override @@ -440,7 +441,7 @@ public class TileAdvancedCraftingTable extends TileEntity implements IInventory, @Override public boolean isActive() { - return hasCurrentWork(); + return requiresLaserEnergy(); } @Override diff --git a/common/buildcraft/silicon/TileAssemblyTable.java b/common/buildcraft/silicon/TileAssemblyTable.java index ffc6ae5e..f855de21 100644 --- a/common/buildcraft/silicon/TileAssemblyTable.java +++ b/common/buildcraft/silicon/TileAssemblyTable.java @@ -1,5 +1,6 @@ package buildcraft.silicon; +import buildcraft.api.power.ILaserTarget; import buildcraft.api.gates.IAction; import buildcraft.api.recipes.AssemblyRecipe; import buildcraft.core.DefaultProps; @@ -71,12 +72,6 @@ public class TileAssemblyTable extends TileEntity implements IMachine, IInventor return result; } - @Override - public void receiveLaserEnergy(float energy) { - energyStored += energy; - recentEnergy[tick] += energy; - } - @Override public boolean canUpdate() { return !FMLCommonHandler.instance().getEffectiveSide().isClient(); @@ -456,8 +451,14 @@ public class TileAssemblyTable extends TileEntity implements IMachine, IInventor } @Override - public boolean hasCurrentWork() { - return currentRecipe != null; + public boolean requiresLaserEnergy() { + return currentRecipe != null && energyStored < currentRequiredEnergy * 5F; + } + + @Override + public void receiveLaserEnergy(float energy) { + energyStored += energy; + recentEnergy[tick] += energy; } @Override diff --git a/common/buildcraft/silicon/TileLaser.java b/common/buildcraft/silicon/TileLaser.java index c85b983c..7dcace38 100644 --- a/common/buildcraft/silicon/TileLaser.java +++ b/common/buildcraft/silicon/TileLaser.java @@ -7,6 +7,7 @@ */ package buildcraft.silicon; +import buildcraft.api.power.ILaserTarget; import buildcraft.BuildCraftCore; import buildcraft.api.core.Position; import buildcraft.api.core.SafeTimeTracker; @@ -125,7 +126,7 @@ public class TileLaser extends TileBuildCraft implements IPowerReceptor, IAction protected boolean isValidTable() { - if (laserTarget == null || laserTarget.isInvalidTarget() || !laserTarget.hasCurrentWork()) + if (laserTarget == null || laserTarget.isInvalidTarget() || !laserTarget.requiresLaserEnergy()) return false; return true; @@ -163,7 +164,7 @@ public class TileLaser extends TileBuildCraft implements IPowerReceptor, IAction break; } - List targets = new LinkedList(); + List targets = new LinkedList(); for (int x = minX; x <= maxX; ++x) { for (int y = minY; y <= maxY; ++y) { @@ -173,8 +174,8 @@ public class TileLaser extends TileBuildCraft implements IPowerReceptor, IAction if (tile instanceof ILaserTarget) { ILaserTarget table = (ILaserTarget) tile; - if (table.hasCurrentWork()) { - targets.add(new BlockIndex(x, y, z)); + if (table.requiresLaserEnergy()) { + targets.add(table); } } @@ -185,8 +186,7 @@ public class TileLaser extends TileBuildCraft implements IPowerReceptor, IAction if (targets.isEmpty()) return; - BlockIndex b = targets.get(worldObj.rand.nextInt(targets.size())); - laserTarget = (ILaserTarget) worldObj.getBlockTileEntity(b.x, b.y, b.z); + laserTarget = targets.get(worldObj.rand.nextInt(targets.size())); } protected void createLaser() {