Changed IPipeConnection to return three states

And fix engines connecting to pipes. This is why I shouldn't code at 5
AM.
This commit is contained in:
CovertJaguar 2013-08-06 14:47:45 -07:00
parent 447b914fb5
commit 91a84f2062
5 changed files with 81 additions and 102 deletions

View file

@ -12,5 +12,18 @@ import net.minecraftforge.common.ForgeDirection;
public interface IPipeConnection {
public boolean overridePipeConnection(PipeType type, ForgeDirection with);
enum ConnectOverride {
CONNECT, DISCONNECT, DEFAULT
};
/**
* Allows you to override pipe connection logic.
*
* @param type
* @param with
* @return CONNECT to force a connection, DISCONNECT to force no connection,
* and DEFAULT to let the pipe decide.
*/
public ConnectOverride overridePipeConnection(PipeType type, ForgeDirection with);
}

View file

@ -97,24 +97,22 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
protected EnergyStage computeEnergyStage() {
float energyLevel = getHeatLevel();
if (energyLevel < 0.25f) {
if (energyLevel < 0.25f)
return EnergyStage.BLUE;
} else if (energyLevel < 0.5f) {
else if (energyLevel < 0.5f)
return EnergyStage.GREEN;
} else if (energyLevel < 0.75f) {
else if (energyLevel < 0.75f)
return EnergyStage.YELLOW;
} else if (energyLevel < 1f) {
else if (energyLevel < 1f)
return EnergyStage.RED;
} else {
else
return EnergyStage.OVERHEAT;
}
}
public final EnergyStage getEnergyStage() {
if (CoreProxy.proxy.isSimulating(worldObj)) {
if (energyStage == EnergyStage.OVERHEAT) {
if (energyStage == EnergyStage.OVERHEAT)
return energyStage;
}
EnergyStage newStage = computeEnergyStage();
if (energyStage != newStage) {
@ -143,9 +141,8 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
}
public float getPistonSpeed() {
if (CoreProxy.proxy.isSimulating(worldObj)) {
if (CoreProxy.proxy.isSimulating(worldObj))
return Math.max(0.16f * getHeatLevel(), 0.01f);
}
switch (getEnergyStage()) {
case BLUE:
return 0.02F;
@ -172,9 +169,8 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
progressPart = 0;
progress = 0;
}
} else if (this.isPumping) {
} else if (this.isPumping)
progressPart = 1;
}
return;
}
@ -194,21 +190,17 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
progress = 0;
progressPart = 0;
}
} else if (isRedstonePowered && isActive()) {
if (isPoweredTile(tile, orientation)) {
} else if (isRedstonePowered && isActive())
if (isPoweredTile(tile, orientation))
if (getPowerToExtract() > 0) {
progressPart = 1;
setPumping(true);
} else {
} else
setPumping(false);
}
} else {
else
setPumping(false);
}
} else {
else
setPumping(false);
}
// Uncomment for constant power
// if (isRedstonePowered && isActive()) {
@ -248,13 +240,11 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
}
protected void engineUpdate() {
if (!isRedstonePowered) {
if (energy >= 1) {
if (!isRedstonePowered)
if (energy >= 1)
energy -= 1;
} else if (energy < 1) {
else if (energy < 1)
energy = 0;
}
}
}
public boolean isActive() {
@ -295,9 +285,8 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
progress = data.getFloat("progress");
energy = data.getFloat("energyF");
NBTBase tag = data.getTag("heat");
if (tag instanceof NBTTagFloat) {
if (tag instanceof NBTTagFloat)
heat = data.getFloat("heat");
}
inv.readFromNBT(data);
}
@ -415,9 +404,8 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
worldObj.setBlockToAir(xCoord, yCoord, zCoord);
}
if (energy > getMaxEnergy()) {
if (energy > getMaxEnergy())
energy = getMaxEnergy();
}
}
public float extractEnergy(float min, float max, boolean doExtract) {
@ -426,11 +414,10 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
float actualMax;
if (max > maxEnergyExtracted()) {
if (max > maxEnergyExtracted())
actualMax = maxEnergyExtracted();
} else {
else
actualMax = max;
}
if (actualMax < min)
return 0;
@ -439,23 +426,20 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
if (energy >= actualMax) {
extracted = actualMax;
if (doExtract) {
if (doExtract)
energy -= actualMax;
}
} else {
extracted = energy;
if (doExtract) {
if (doExtract)
energy = 0;
}
}
return extracted;
}
public boolean isPoweredTile(TileEntity tile, ForgeDirection side) {
if (tile instanceof IPowerReceptor) {
if (tile instanceof IPowerReceptor)
return ((IPowerReceptor) tile).getPowerReceiver(side.getOpposite()) != null;
}
return false;
}
@ -499,8 +483,12 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
}
@Override
public boolean overridePipeConnection(PipeType type, ForgeDirection with) {
return with != orientation;
public ConnectOverride overridePipeConnection(PipeType type, ForgeDirection with) {
if (type == PipeType.POWER)
return ConnectOverride.DEFAULT;
if (with == orientation)
return ConnectOverride.DISCONNECT;
return ConnectOverride.DEFAULT;
}
@Override

View file

@ -10,7 +10,6 @@ package buildcraft.energy;
import buildcraft.BuildCraftCore;
import buildcraft.BuildCraftEnergy;
import buildcraft.api.gates.ITrigger;
import buildcraft.core.DefaultProps;
import buildcraft.core.GuiIds;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.Utils;

View file

@ -43,22 +43,20 @@ public class TileEngineWood extends TileEngine {
@Override
protected EnergyStage computeEnergyStage() {
float energyLevel = getEnergyLevel();
if (energyLevel < 0.25f) {
if (energyLevel < 0.25f)
return EnergyStage.BLUE;
} else if (energyLevel < 0.5f) {
else if (energyLevel < 0.5f)
return EnergyStage.GREEN;
} else if (energyLevel < 0.75f) {
else if (energyLevel < 0.75f)
return EnergyStage.YELLOW;
} else {
else
return EnergyStage.RED;
}
}
@Override
public float getPistonSpeed() {
if (CoreProxy.proxy.isSimulating(worldObj)) {
if (CoreProxy.proxy.isSimulating(worldObj))
return Math.max(0.8f * getHeatLevel(), 0.01f);
}
switch (getEnergyStage()) {
case BLUE:
return 0.01F;
@ -77,16 +75,14 @@ public class TileEngineWood extends TileEngine {
public void engineUpdate() {
super.engineUpdate();
if (isRedstonePowered) {
if (worldObj.getWorldTime() % 20 == 0) {
if (isRedstonePowered)
if (worldObj.getWorldTime() % 20 == 0)
addEnergy(1);
}
}
}
@Override
public boolean overridePipeConnection(PipeType type, ForgeDirection with) {
return false;
public ConnectOverride overridePipeConnection(PipeType type, ForgeDirection with) {
return ConnectOverride.DISCONNECT;
}
@Override

View file

@ -95,9 +95,8 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
if (pipe != null) {
nbt.setInteger("pipeId", pipe.itemID);
pipe.writeToNBT(nbt);
} else {
} else
nbt.setInteger("pipeId", coreState.pipeId);
}
for (int i = 0; i < ForgeDirection.VALID_DIRECTIONS.length; i++) {
nbt.setInteger("facadeBlocks[" + i + "]", facadeBlocks[i]);
@ -114,9 +113,9 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
coreState.pipeId = nbt.getInteger("pipeId");
pipe = BlockGenericPipe.createPipe(coreState.pipeId);
if (pipe != null) {
if (pipe != null)
pipe.readFromNBT(nbt);
} else {
else {
BuildCraftCore.bcLog.log(Level.WARNING, "Pipe failed to load from NBT at {0},{1},{2}", new Object[]{xCoord, yCoord, zCoord});
deletePipe = true;
}
@ -133,9 +132,8 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
public void invalidate() {
initialized = false;
tileBuffer = null;
if (pipe != null) {
if (pipe != null)
pipe.invalidate();
}
super.invalidate();
}
@ -144,25 +142,22 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
super.validate();
tileBuffer = null;
bindPipe();
if (pipe != null) {
if (pipe != null)
pipe.validate();
}
}
public boolean initialized = false;
@Override
public void updateEntity() {
if (deletePipe) {
if (deletePipe)
worldObj.setBlockToAir(xCoord, yCoord, zCoord);
}
if (pipe == null)
return;
if (!initialized) {
if (!initialized)
initialize(pipe);
}
if (!BlockGenericPipe.isValid(pipe))
return;
@ -182,13 +177,11 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
PowerReceiver provider = getPowerReceiver(null);
if (provider != null) {
if (provider != null)
provider.update();
}
if (pipe != null) {
if (pipe != null)
pipe.updateEntity();
}
}
// PRECONDITION: worldObj must not be null
@ -272,12 +265,10 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
for (ForgeDirection o : ForgeDirection.VALID_DIRECTIONS) {
TileEntity tile = getTile(o);
if (tile instanceof ITileBufferHolder) {
if (tile instanceof ITileBufferHolder)
((ITileBufferHolder) tile).blockCreated(o, BuildCraftTransport.genericPipeBlock.blockID, this);
}
if (tile instanceof TileGenericPipe) {
if (tile instanceof TileGenericPipe)
((TileGenericPipe) tile).scheduleNeighborChange();
}
}
bindPipe();
@ -321,9 +312,8 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
@Override
public void doWork(PowerHandler workProvider) {
if (BlockGenericPipe.isValid(pipe) && pipe instanceof IPowerReceptor) {
if (BlockGenericPipe.isValid(pipe) && pipe instanceof IPowerReceptor)
((IPowerReceptor) pipe).doWork(workProvider);
}
}
public void scheduleNeighborChange() {
@ -356,9 +346,8 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
/* SMP */
public void handleDescriptionPacket(PipeRenderStatePacket packet) {
if (worldObj.isRemote) {
if (pipe == null && packet.getPipeId() != 0) {
if (pipe == null && packet.getPipeId() != 0)
initialize(BlockGenericPipe.createPipe(packet.getPipeId()));
}
renderState = packet.getRenderState();
worldObj.markBlockForRenderUpdate(xCoord, yCoord, zCoord);
}
@ -369,21 +358,18 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
bindPipe();
PacketTileState packet = new PacketTileState(this.xCoord, this.yCoord, this.zCoord);
if (pipe != null && pipe.gate != null) {
if (pipe != null && pipe.gate != null)
coreState.gateKind = pipe.gate.kind.ordinal();
} else {
else
coreState.gateKind = 0;
}
if (pipe != null && pipe.transport != null) {
if (pipe != null && pipe.transport != null)
pipe.transport.sendDescriptionPacket();
}
packet.addStateForSerialization((byte) 0, coreState);
packet.addStateForSerialization((byte) 1, renderState);
if (pipe instanceof IClientState) {
if (pipe instanceof IClientState)
packet.addStateForSerialization((byte) 2, (IClientState) pipe);
}
return packet.getPacket();
}
@ -448,9 +434,12 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
if (!BlockGenericPipe.isValid(pipe))
return false;
if(with instanceof IPipeConnection)
return ((IPipeConnection)with).overridePipeConnection(pipe.transport.getPipeType(), side.getOpposite());
if (with instanceof IPipeConnection) {
IPipeConnection.ConnectOverride override = ((IPipeConnection) with).overridePipeConnection(pipe.transport.getPipeType(), side.getOpposite());
if (override != IPipeConnection.ConnectOverride.DEFAULT)
return override == IPipeConnection.ConnectOverride.CONNECT ? true : false;
}
if (with instanceof TileGenericPipe) {
if (((TileGenericPipe) with).hasPlug(side.getOpposite()))
@ -497,9 +486,8 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
@Override
public void onChunkUnload() {
if (pipe != null) {
if (pipe != null)
pipe.onChunkUnload();
}
}
/**
@ -560,9 +548,8 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
if (this.facadeBlocks[direction.ordinal()] == blockid)
return false;
if (hasFacade(direction)) {
if (hasFacade(direction))
dropFacadeItem(direction);
}
this.facadeBlocks[direction.ordinal()] = blockid;
this.facadeMeta[direction.ordinal()] = meta;
@ -629,13 +616,11 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
switch (stateId) {
case 0:
if (pipe == null && coreState.pipeId != 0) {
if (pipe == null && coreState.pipeId != 0)
initialize(BlockGenericPipe.createPipe(coreState.pipeId));
}
if (pipe != null && coreState.gateKind != GateKind.None.ordinal()) {
if (pipe.gate == null) {
if (pipe.gate == null)
pipe.gate = new GateVanilla(pipe);
}
pipe.gate.kind = GateKind.values()[coreState.gateKind];
}
break;
@ -659,10 +644,9 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
if (hasFacade(side))
return true;
if (BlockGenericPipe.isValid(pipe) && pipe instanceof ISolidSideTile) {
if (BlockGenericPipe.isValid(pipe) && pipe instanceof ISolidSideTile)
if (((ISolidSideTile) pipe).isSolidOnSide(side))
return true;
}
return false;
}
@ -698,9 +682,8 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
public int getBlockId() {
Block block = getBlockType();
if (block != null) {
if (block != null)
return block.blockID;
}
return 0;
}