Engines should prefer facing pipes on placement

This commit is contained in:
CovertJaguar 2013-09-12 10:57:20 -07:00
parent 47d504d781
commit 880fd64e27
2 changed files with 22 additions and 9 deletions

View file

@ -95,7 +95,7 @@ public class BlockEngine extends BlockContainer {
public boolean rotateBlock(World world, int x, int y, int z, ForgeDirection axis) { public boolean rotateBlock(World world, int x, int y, int z, ForgeDirection axis) {
TileEntity tile = world.getBlockTileEntity(x, y, z); TileEntity tile = world.getBlockTileEntity(x, y, z);
if (tile instanceof TileEngine) { if (tile instanceof TileEngine) {
return ((TileEngine) tile).switchOrientation(); return ((TileEngine) tile).switchOrientation(false);
} }
return false; return false;
} }
@ -127,7 +127,8 @@ public class BlockEngine extends BlockContainer {
public void onPostBlockPlaced(World world, int x, int y, int z, int par5) { public void onPostBlockPlaced(World world, int x, int y, int z, int par5) {
TileEngine tile = (TileEngine) world.getBlockTileEntity(x, y, z); TileEngine tile = (TileEngine) world.getBlockTileEntity(x, y, z);
tile.orientation = ForgeDirection.UP; tile.orientation = ForgeDirection.UP;
tile.switchOrientation(); if (!tile.isOrientationValid())
tile.switchOrientation(true);
} }
@Override @Override

View file

@ -27,6 +27,7 @@ import buildcraft.api.power.PowerHandler;
import buildcraft.api.power.PowerHandler.PowerReceiver; import buildcraft.api.power.PowerHandler.PowerReceiver;
import buildcraft.api.power.PowerHandler.Type; import buildcraft.api.power.PowerHandler.Type;
import buildcraft.api.transport.IPipeConnection; import buildcraft.api.transport.IPipeConnection;
import buildcraft.api.transport.IPipeTile;
import buildcraft.api.transport.IPipeTile.PipeType; import buildcraft.api.transport.IPipeTile.PipeType;
import buildcraft.core.DefaultProps; import buildcraft.core.DefaultProps;
import buildcraft.core.TileBuffer; import buildcraft.core.TileBuffer;
@ -57,7 +58,6 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
public float progress; public float progress;
public float energy; public float energy;
public float heat = MIN_HEAT; public float heat = MIN_HEAT;
// //
public @TileNetworkData public @TileNetworkData
EnergyStage energyStage = EnergyStage.BLUE; EnergyStage energyStage = EnergyStage.BLUE;
@ -66,11 +66,11 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
public @TileNetworkData public @TileNetworkData
boolean isPumping = false; // Used for SMP synch boolean isPumping = false; // Used for SMP synch
public TileEngine(){ public TileEngine() {
powerHandler = new PowerHandler(this, Type.ENGINE); powerHandler = new PowerHandler(this, Type.ENGINE);
powerHandler.configurePowerPerdition(1, 100); powerHandler.configurePowerPerdition(1, 100);
} }
@Override @Override
public void initialize() { public void initialize() {
if (!CoreProxy.proxy.isRenderWorld(worldObj)) { if (!CoreProxy.proxy.isRenderWorld(worldObj)) {
@ -254,7 +254,21 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
sendNetworkUpdate(); sendNetworkUpdate();
} }
public boolean switchOrientation() { public boolean isOrientationValid() {
Position pos = new Position(xCoord, yCoord, zCoord, orientation);
pos.moveForwards(1);
TileEntity tile = worldObj.getBlockTileEntity((int) pos.x, (int) pos.y, (int) pos.z);
return isPoweredTile(tile, orientation);
}
public boolean switchOrientation(boolean preferPipe) {
if (preferPipe && switchOrientation_do(true))
return true;
return switchOrientation_do(false);
}
private boolean switchOrientation_do(boolean pipesOnly) {
for (int i = orientation.ordinal() + 1; i <= orientation.ordinal() + 6; ++i) { for (int i = orientation.ordinal() + 1; i <= orientation.ordinal() + 6; ++i) {
ForgeDirection o = ForgeDirection.VALID_DIRECTIONS[i % 6]; ForgeDirection o = ForgeDirection.VALID_DIRECTIONS[i % 6];
@ -262,7 +276,7 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
pos.moveForwards(1); pos.moveForwards(1);
TileEntity tile = worldObj.getBlockTileEntity((int) pos.x, (int) pos.y, (int) pos.z); TileEntity tile = worldObj.getBlockTileEntity((int) pos.x, (int) pos.y, (int) pos.z);
if (isPoweredTile(tile, o)) { if ((!pipesOnly || tile instanceof IPipeTile) && isPoweredTile(tile, o)) {
orientation = o; orientation = o;
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, worldObj.getBlockId(xCoord, yCoord, zCoord)); worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, worldObj.getBlockId(xCoord, yCoord, zCoord));
@ -320,10 +334,8 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
iCrafting.sendProgressBarUpdate(containerEngine, 2, Math.round(currentOutput * 10)); iCrafting.sendProgressBarUpdate(containerEngine, 2, Math.round(currentOutput * 10));
iCrafting.sendProgressBarUpdate(containerEngine, 3, Math.round(heat * 100)); iCrafting.sendProgressBarUpdate(containerEngine, 3, Math.round(heat * 100));
} }
public void delete() { public void delete() {
} }
/* STATE INFORMATION */ /* STATE INFORMATION */