Prelude for an advanced crafting table: lasers talk to anything implementing ILaserTarget now

This commit is contained in:
Christian 2012-10-13 16:20:22 -04:00
parent 06099ffcdd
commit 7d4b5d62c3
3 changed files with 75 additions and 45 deletions

View file

@ -13,6 +13,7 @@ import buildcraft.core.network.TileNetworkData;
import buildcraft.core.network.TilePacketWrapper;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.Utils;
import buildcraft.silicon.ILaserTarget;
import net.minecraft.src.Container;
import net.minecraft.src.EntityItem;
@ -24,7 +25,7 @@ import net.minecraft.src.NBTTagCompound;
import net.minecraft.src.NBTTagList;
import net.minecraft.src.TileEntity;
public class TileAssemblyTable extends TileEntity implements IMachine, IInventory, IPipeConnection {
public class TileAssemblyTable extends TileEntity implements IMachine, IInventory, IPipeConnection, ILaserTarget {
ItemStack[] items = new ItemStack[12];
@ -472,4 +473,23 @@ public class TileAssemblyTable extends TileEntity implements IMachine, IInventor
return currentRequiredEnergy;
}
@Override
public boolean hasCurrentWork() {
return currentRecipe != null;
}
@Override
public int getXCoord() {
return xCoord;
}
@Override
public int getYCoord() {
return yCoord;
}
@Override
public int getZCoord() {
return zCoord;
}
}

View file

@ -0,0 +1,10 @@
package buildcraft.silicon;
public interface ILaserTarget {
boolean hasCurrentWork();
void receiveLaserEnergy(float energy);
boolean isInvalid();
int getXCoord();
int getYCoord();
int getZCoord();
}

View file

@ -34,7 +34,7 @@ public class TileLaser extends TileBuildCraft implements IPowerReceptor {
private final SafeTimeTracker searchTracker = new SafeTimeTracker();
private final SafeTimeTracker networkTracker = new SafeTimeTracker();
private TileAssemblyTable assemblyTable;
private ILaserTarget laserTarget;
public IPowerProvider powerProvider;
@ -82,7 +82,7 @@ public class TileLaser extends TileBuildCraft implements IPowerReceptor {
// Consume power and transfer it to the table.
float power = powerProvider.useEnergy(0, 4, true);
assemblyTable.receiveLaserEnergy(power);
laserTarget.receiveLaserEnergy(power);
if (laser != null)
laser.pushPower(power);
@ -100,7 +100,7 @@ public class TileLaser extends TileBuildCraft implements IPowerReceptor {
protected boolean isValidTable() {
if (assemblyTable == null || assemblyTable.isInvalid() || assemblyTable.currentRecipe == null)
if (laserTarget == null || laserTarget.isInvalid() || !laserTarget.hasCurrentWork())
return false;
return true;
@ -163,7 +163,7 @@ public class TileLaser extends TileBuildCraft implements IPowerReceptor {
}
BlockIndex b = targets.get(worldObj.rand.nextInt(targets.size()));
assemblyTable = (TileAssemblyTable) worldObj.getBlockTileEntity(b.i, b.j, b.k);
laserTarget = (TileAssemblyTable) worldObj.getBlockTileEntity(b.i, b.j, b.k);
}
protected void createLaser() {
@ -202,9 +202,9 @@ public class TileLaser extends TileBuildCraft implements IPowerReceptor {
Position head = new Position(xCoord + 0.5 + px, yCoord + 0.5 + py, zCoord + 0.5 + pz);
Position tail = new Position(
assemblyTable.xCoord + 0.475 + (worldObj.rand.nextFloat() - 0.5) / 5F,
assemblyTable.yCoord + 9F / 16F,
assemblyTable.zCoord + 0.475 + (worldObj.rand.nextFloat() - 0.5) / 5F);
laserTarget.getXCoord() + 0.475 + (worldObj.rand.nextFloat() - 0.5) / 5F,
laserTarget.getYCoord() + 9F / 16F,
laserTarget.getZCoord() + 0.475 + (worldObj.rand.nextFloat() - 0.5) / 5F);
laser.setPositions(head, tail);