Rework Pipe connection rules (again)

This commit is contained in:
CovertJaguar 2013-08-06 04:58:35 -07:00
parent 671caa458d
commit 447b914fb5
11 changed files with 80 additions and 81 deletions

View file

@ -1,17 +1,16 @@
/**
* Copyright (c) SpaceToad, 2011
* http://www.mod-buildcraft.com
* Copyright (c) SpaceToad, 2011 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
* 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.transport;
import buildcraft.api.transport.IPipeTile.PipeType;
import net.minecraftforge.common.ForgeDirection;
public interface IPipeConnection {
public boolean isPipeConnected(ForgeDirection with);
public boolean overridePipeConnection(PipeType type, ForgeDirection with);
}

View file

@ -11,7 +11,7 @@ import net.minecraft.item.ItemStack;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.IFluidHandler;
public interface IPipeTile extends ISolidSideTile, IPipeConnection, IFluidHandler {
public interface IPipeTile extends ISolidSideTile, IFluidHandler {
public enum PipeType {
@ -34,4 +34,6 @@ public interface IPipeTile extends ISolidSideTile, IPipeConnection, IFluidHandle
* @return Amount of items used from the passed stack.
*/
int injectItem(ItemStack stack, boolean doAdd, ForgeDirection from);
boolean isPipeConnected(ForgeDirection with);
}

View file

@ -374,47 +374,36 @@ public class Utils {
}
public static boolean checkPipesConnections(TileEntity tile1, TileEntity tile2) {
if (tile1 == null || tile2 == null) {
if (tile1 == null || tile2 == null)
return false;
}
if (!(tile1 instanceof IPipeConnection) && !(tile2 instanceof IPipeConnection)) {
if (!(tile1 instanceof IPipeTile) && !(tile2 instanceof IPipeTile))
return false;
}
ForgeDirection o = ForgeDirection.UNKNOWN;
if (tile1.xCoord - 1 == tile2.xCoord) {
if (tile1.xCoord - 1 == tile2.xCoord)
o = ForgeDirection.WEST;
} else if (tile1.xCoord + 1 == tile2.xCoord) {
else if (tile1.xCoord + 1 == tile2.xCoord)
o = ForgeDirection.EAST;
} else if (tile1.yCoord - 1 == tile2.yCoord) {
else if (tile1.yCoord - 1 == tile2.yCoord)
o = ForgeDirection.DOWN;
} else if (tile1.yCoord + 1 == tile2.yCoord) {
else if (tile1.yCoord + 1 == tile2.yCoord)
o = ForgeDirection.UP;
} else if (tile1.zCoord - 1 == tile2.zCoord) {
else if (tile1.zCoord - 1 == tile2.zCoord)
o = ForgeDirection.NORTH;
} else if (tile1.zCoord + 1 == tile2.zCoord) {
else if (tile1.zCoord + 1 == tile2.zCoord)
o = ForgeDirection.SOUTH;
}
if (tile1 instanceof IPipeConnection && !((IPipeConnection) tile1).isPipeConnected(o)) {
if (tile1 instanceof IPipeTile && !((IPipeTile) tile1).isPipeConnected(o))
return false;
}
if (tile2 instanceof IPipeConnection && !((IPipeConnection) tile2).isPipeConnected(o.getOpposite())) {
if (tile2 instanceof IPipeTile && !((IPipeTile) tile2).isPipeConnected(o.getOpposite()))
return false;
}
return true;
}
public static boolean checkPipesConnections(IBlockAccess blockAccess, TileEntity tile1, int x2, int y2, int z2) {
TileEntity tile2 = blockAccess.getBlockTileEntity(x2, y2, z2);
return checkPipesConnections(tile1, tile2);
}
public static boolean checkLegacyPipesConnections(IBlockAccess blockAccess, int x1, int y1, int z1, int x2, int y2, int z2) {
Block b1 = Block.blocksList[blockAccess.getBlockId(x1, y1, z1)];

View file

@ -17,6 +17,7 @@ import buildcraft.api.power.PowerHandler;
import buildcraft.api.power.PowerHandler.PowerReceiver;
import buildcraft.api.power.PowerHandler.Type;
import buildcraft.api.transport.IPipeConnection;
import buildcraft.api.transport.IPipeTile.PipeType;
import buildcraft.core.DefaultProps;
import buildcraft.core.TileBuffer;
import buildcraft.core.TileBuildCraft;
@ -498,7 +499,7 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
}
@Override
public boolean isPipeConnected(ForgeDirection with) {
public boolean overridePipeConnection(PipeType type, ForgeDirection with) {
return with != orientation;
}

View file

@ -7,6 +7,7 @@
*/
package buildcraft.energy;
import buildcraft.api.transport.IPipeTile.PipeType;
import buildcraft.core.proxy.CoreProxy;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.ForgeDirection;
@ -84,7 +85,7 @@ public class TileEngineWood extends TileEngine {
}
@Override
public boolean isPipeConnected(ForgeDirection with) {
public boolean overridePipeConnection(PipeType type, ForgeDirection with) {
return false;
}

View file

@ -118,32 +118,32 @@ public class BlockGenericPipe extends BlockContainer {
TileEntity tile1 = world.getBlockTileEntity(i, j, k);
TileGenericPipe tileG = (TileGenericPipe) tile1;
if (Utils.checkPipesConnections(world, tile1, i - 1, j, k)) {
if (tileG.isPipeConnected(ForgeDirection.WEST)) {
setBlockBounds(0.0F, Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMaxPos, Utils.pipeMaxPos, Utils.pipeMaxPos);
super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
}
if (Utils.checkPipesConnections(world, tile1, i + 1, j, k)) {
if (tileG.isPipeConnected(ForgeDirection.EAST)) {
setBlockBounds(Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMinPos, 1.0F, Utils.pipeMaxPos, Utils.pipeMaxPos);
super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
}
if (Utils.checkPipesConnections(world, tile1, i, j - 1, k)) {
if (tileG.isPipeConnected(ForgeDirection.DOWN)) {
setBlockBounds(Utils.pipeMinPos, 0.0F, Utils.pipeMinPos, Utils.pipeMaxPos, Utils.pipeMaxPos, Utils.pipeMaxPos);
super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
}
if (Utils.checkPipesConnections(world, tile1, i, j + 1, k)) {
if (tileG.isPipeConnected(ForgeDirection.UP)) {
setBlockBounds(Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMaxPos, 1.0F, Utils.pipeMaxPos);
super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
}
if (Utils.checkPipesConnections(world, tile1, i, j, k - 1)) {
if (tileG.isPipeConnected(ForgeDirection.NORTH)) {
setBlockBounds(Utils.pipeMinPos, Utils.pipeMinPos, 0.0F, Utils.pipeMaxPos, Utils.pipeMaxPos, Utils.pipeMaxPos);
super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
}
if (Utils.checkPipesConnections(world, tile1, i, j, k + 1)) {
if (tileG.isPipeConnected(ForgeDirection.SOUTH)) {
setBlockBounds(Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMaxPos, Utils.pipeMaxPos, 1.0F);
super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
}
@ -193,27 +193,27 @@ public class BlockGenericPipe extends BlockContainer {
if (tile1 instanceof TileGenericPipe) {
TileGenericPipe tileG = (TileGenericPipe) tile1;
if (Utils.checkPipesConnections(world, tile1, i - 1, j, k) || tileG.hasFacade(ForgeDirection.WEST)) {
if (tileG.isPipeConnected(ForgeDirection.WEST) || tileG.hasFacade(ForgeDirection.WEST)) {
xMin = 0.0F;
}
if (Utils.checkPipesConnections(world, tile1, i + 1, j, k) || tileG.hasFacade(ForgeDirection.EAST)) {
if (tileG.isPipeConnected(ForgeDirection.EAST) || tileG.hasFacade(ForgeDirection.EAST)) {
xMax = 1.0F;
}
if (Utils.checkPipesConnections(world, tile1, i, j - 1, k) || tileG.hasFacade(ForgeDirection.DOWN)) {
if (tileG.isPipeConnected(ForgeDirection.DOWN) || tileG.hasFacade(ForgeDirection.DOWN)) {
yMin = 0.0F;
}
if (Utils.checkPipesConnections(world, tile1, i, j + 1, k) || tileG.hasFacade(ForgeDirection.UP)) {
if (tileG.isPipeConnected(ForgeDirection.UP) || tileG.hasFacade(ForgeDirection.UP)) {
yMax = 1.0F;
}
if (Utils.checkPipesConnections(world, tile1, i, j, k - 1) || tileG.hasFacade(ForgeDirection.NORTH)) {
if (tileG.isPipeConnected(ForgeDirection.NORTH) || tileG.hasFacade(ForgeDirection.NORTH)) {
zMin = 0.0F;
}
if (Utils.checkPipesConnections(world, tile1, i, j, k + 1) || tileG.hasFacade(ForgeDirection.SOUTH)) {
if (tileG.isPipeConnected(ForgeDirection.SOUTH) || tileG.hasFacade(ForgeDirection.SOUTH)) {
zMax = 1.0F;
}
@ -277,11 +277,18 @@ public class BlockGenericPipe extends BlockContainer {
float xMin = Utils.pipeMinPos, xMax = Utils.pipeMaxPos, yMin = Utils.pipeMinPos, yMax = Utils.pipeMaxPos, zMin = Utils.pipeMinPos, zMax = Utils.pipeMaxPos;
TileEntity pipeTileEntity = world.getBlockTileEntity(x, y, z);
Pipe pipe = getPipe(world, x, y, z);
if (pipeTileEntity == null || !isValid(pipe)) {
TileGenericPipe tileG = null;
if(pipeTileEntity instanceof TileGenericPipe)
tileG = (TileGenericPipe)pipeTileEntity;
if(tileG == null)
return null;
Pipe pipe = tileG.pipe;
if (!isValid(pipe))
return null;
}
/**
* pipe hits along x, y, and z axis, gate (all 6 sides) [and
@ -294,12 +301,12 @@ public class BlockGenericPipe extends BlockContainer {
// check along the x axis
if (Utils.checkPipesConnections(world, pipeTileEntity, x - 1, y, z)) {
if (tileG.isPipeConnected(ForgeDirection.WEST)) {
xMin = 0.0F;
needAxisCheck = true;
}
if (Utils.checkPipesConnections(world, pipeTileEntity, x + 1, y, z)) {
if (tileG.isPipeConnected(ForgeDirection.WEST)) {
xMax = 1.0F;
needAxisCheck = true;
}
@ -316,12 +323,12 @@ public class BlockGenericPipe extends BlockContainer {
// check along the y axis
if (Utils.checkPipesConnections(world, pipeTileEntity, x, y - 1, z)) {
if (tileG.isPipeConnected(ForgeDirection.DOWN)) {
yMin = 0.0F;
needAxisCheck = true;
}
if (Utils.checkPipesConnections(world, pipeTileEntity, x, y + 1, z)) {
if (tileG.isPipeConnected(ForgeDirection.UP)) {
yMax = 1.0F;
needAxisCheck = true;
}
@ -338,12 +345,12 @@ public class BlockGenericPipe extends BlockContainer {
// check along the z axis
if (Utils.checkPipesConnections(world, pipeTileEntity, x, y, z - 1)) {
if (tileG.isPipeConnected(ForgeDirection.NORTH)) {
zMin = 0.0F;
needAxisCheck = true;
}
if (Utils.checkPipesConnections(world, pipeTileEntity, x, y, z + 1)) {
if (tileG.isPipeConnected(ForgeDirection.SOUTH)) {
zMax = 1.0F;
needAxisCheck = true;
}

View file

@ -325,7 +325,7 @@ public abstract class Pipe<T extends PipeTransport> implements IPipe, IDropContr
ForgeDirection o = ForgeDirection.getOrientation(side).getOpposite();
TileEntity tile = container.getTile(o);
if (tile instanceof TileGenericPipe && Utils.checkPipesConnections(this.container, tile))
if (tile instanceof TileGenericPipe && container.isPipeConnected(o))
return 0;
return 15;
@ -477,15 +477,14 @@ public abstract class Pipe<T extends PipeTransport> implements IPipe, IDropContr
ForgeDirection target_orientation = ForgeDirection.UNKNOWN;
for (ForgeDirection o : ForgeDirection.VALID_DIRECTIONS) {
if (Utils.checkPipesConnections(container.getTile(o), container)) {
if (container.isPipeConnected(o)) {
Connections_num++;
if (Connections_num == 1) {
if (Connections_num == 1)
target_orientation = o;
}
}
}
if (Connections_num > 1 || Connections_num == 0)
return ForgeDirection.UNKNOWN;

View file

@ -171,7 +171,7 @@ public class PipeTransportFluids extends PipeTransport implements IFluidHandler
public boolean canReceiveFluid(ForgeDirection o) {
TileEntity entity = container.getTile(o);
if (!Utils.checkPipesConnections(container, entity))
if (!container.isPipeConnected(o))
return false;
if (entity instanceof TileGenericPipe) {
@ -481,7 +481,7 @@ public class PipeTransportFluids extends PipeTransport implements IFluidHandler
super.onNeighborBlockChange(blockId);
for (ForgeDirection direction : directions) {
if (!Utils.checkPipesConnections(container.getTile(orientations[direction.ordinal()]), container)) {
if (!container.isPipeConnected(direction)) {
internalTanks[direction.ordinal()].reset();
transferState[direction.ordinal()] = TransferState.None;
renderCache[direction.ordinal()] = null;

View file

@ -295,7 +295,7 @@ public class PipeTransportItems extends PipeTransport {
public boolean canReceivePipeObjects(ForgeDirection o, TravelingItem item) {
TileEntity entity = container.getTile(o);
if (!Utils.checkPipesConnections(entity, container))
if (!container.isPipeConnected(o))
return false;
if (entity instanceof TileGenericPipe) {

View file

@ -108,15 +108,15 @@ public class PipeTransportPower extends PipeTransport {
}
private void updateTiles() {
for (int i = 0; i < 6; ++i) {
TileEntity tile = container.getTile(ForgeDirection.VALID_DIRECTIONS[i]);
if (Utils.checkPipesConnections(tile, container)) {
tiles[i] = tile;
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
TileEntity tile = container.getTile(side);
if (container.isPipeConnected(side)) {
tiles[side.ordinal()] = tile;
} else {
tiles[i] = null;
internalPower[i] = 0;
internalNextPower[i] = 0;
displayPower[i] = 0;
tiles[side.ordinal()] = null;
internalPower[side.ordinal()] = 0;
internalNextPower[side.ordinal()] = 0;
displayPower[side.ordinal()] = 0;
}
}
}

View file

@ -18,6 +18,7 @@ import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerHandler;
import buildcraft.api.power.PowerHandler.PowerReceiver;
import buildcraft.api.transport.IPipe;
import buildcraft.api.transport.IPipeConnection;
import buildcraft.api.transport.IPipeTile;
import buildcraft.api.transport.ISolidSideTile;
import buildcraft.core.DefaultProps;
@ -435,34 +436,35 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
}
/**
* Checks if this tile is connected to another tile
* Checks if this tile can connect to another tile
*
* @param with - The other Tile
* @param side - The orientation to get to the other tile ('with')
* @return true if pipes are considered connected
*/
protected boolean arePipesConnected(TileEntity with, ForgeDirection side) {
Pipe pipe1 = pipe;
protected boolean canPipeConnect(TileEntity with, ForgeDirection side) {
if (hasPlug(side))
return false;
if (!BlockGenericPipe.isValid(pipe1))
if (!BlockGenericPipe.isValid(pipe))
return false;
if(with instanceof IPipeConnection)
return ((IPipeConnection)with).overridePipeConnection(pipe.transport.getPipeType(), side.getOpposite());
if (with instanceof TileGenericPipe) {
if (((TileGenericPipe) with).hasPlug(side.getOpposite()))
return false;
Pipe pipe2 = ((TileGenericPipe) with).pipe;
Pipe otherPipe = ((TileGenericPipe) with).pipe;
if (!BlockGenericPipe.isValid(pipe2))
if (!BlockGenericPipe.isValid(otherPipe))
return false;
if (!pipe2.canPipeConnect(this, side.getOpposite()))
if (!otherPipe.canPipeConnect(this, side.getOpposite()))
return false;
}
return pipe1 != null ? pipe1.canPipeConnect(with, side) : false;
return pipe.canPipeConnect(with, side);
}
private void computeConnections() {
@ -474,9 +476,8 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
TileBuffer t = cache[side.ordinal()];
t.refresh();
if (t.getTile() != null) {
pipeConnectionsBuffer[side.ordinal()] = arePipesConnected(t.getTile(), side);
}
if (t.getTile() != null)
pipeConnectionsBuffer[side.ordinal()] = canPipeConnect(t.getTile(), side);
}
}
}