Move ILaserTarget to the power API
This commit is contained in:
parent
d1a1ad9d01
commit
9d4b1b9782
5 changed files with 65 additions and 32 deletions
46
common/buildcraft/api/power/ILaserTarget.java
Normal file
46
common/buildcraft/api/power/ILaserTarget.java
Normal file
|
@ -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();
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
package buildcraft.silicon;
|
||||
|
||||
public interface ILaserTarget {
|
||||
boolean hasCurrentWork();
|
||||
|
||||
void receiveLaserEnergy(float energy);
|
||||
|
||||
boolean isInvalidTarget();
|
||||
|
||||
int getXCoord();
|
||||
|
||||
int getYCoord();
|
||||
|
||||
int getZCoord();
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<BlockIndex> targets = new LinkedList<BlockIndex>();
|
||||
List<ILaserTarget> targets = new LinkedList<ILaserTarget>();
|
||||
|
||||
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() {
|
||||
|
|
Loading…
Reference in a new issue