use of buildcraft.api.transport.pipe.IPipe in project BuildCraft by BuildCraft.
the class PipeFlowItems method onItemReachEnd.
private void onItemReachEnd(TravellingItem item) {
IPipeHolder holder = pipe.getHolder();
PipeEventItem.ReachEnd reachEnd = new PipeEventItem.ReachEnd(holder, this, item.colour, item.stack, item.side);
holder.fireEvent(reachEnd);
item.colour = reachEnd.colour;
item.stack = reachEnd.getStack();
ItemStack excess = item.stack;
if (excess.isEmpty()) {
return;
}
if (pipe.isConnected(item.side)) {
ConnectedType type = pipe.getConnectedType(item.side);
EnumFacing oppositeSide = item.side.getOpposite();
switch(type) {
case PIPE:
{
IPipe oPipe = pipe.getConnectedPipe(item.side);
if (oPipe == null) {
break;
}
PipeFlow flow = oPipe.getFlow();
if (flow instanceof IFlowItems) {
IFlowItems oFlow = (IFlowItems) flow;
ItemStack before = excess;
excess = oFlow.injectItem(excess.copy(), true, oppositeSide, item.colour, item.speed);
if (!excess.isEmpty()) {
before.shrink(excess.getCount());
}
excess = fireEventEjectIntoPipe(oFlow, item.side, before, excess);
}
break;
}
case TILE:
{
TileEntity tile = pipe.getConnectedTile(item.side);
IInjectable injectable = ItemTransactorHelper.getInjectable(tile, oppositeSide);
ItemStack before = excess;
excess = injectable.injectItem(excess.copy(), true, oppositeSide, item.colour, item.speed);
if (!excess.isEmpty()) {
IItemTransactor transactor = ItemTransactorHelper.getTransactor(tile, oppositeSide);
excess = transactor.insert(excess, false, false);
}
excess = fireEventEjectIntoTile(tile, item.side, before, excess);
break;
}
}
}
if (excess.isEmpty()) {
return;
}
item.tried.add(item.side);
item.toCenter = true;
item.stack = excess;
item.genTimings(holder.getPipeWorld().getTotalWorldTime(), getPipeLength(item.side));
items.add(item.timeToDest, item);
sendItemDataToClient(item);
}
use of buildcraft.api.transport.pipe.IPipe in project BuildCraft by BuildCraft.
the class FilterEventHandler method sideCheck.
@PipeEventHandler
public static void sideCheck(PipeEventItem.SideCheck event) {
for (EnumFacing side : EnumFacing.VALUES) {
if (!event.isAllowed(side)) {
continue;
}
IPipe neighbour = event.holder.getNeighbourPipe(side);
if (neighbour == null) {
continue;
}
PipePluggable neighbourPlug = neighbour.getHolder().getPluggable(side.getOpposite());
PipePluggable atPlug = event.holder.getPluggable(side);
if (neighbourPlug instanceof PluggableLens) {
EnumDyeColor colourAt = event.colour;
if (atPlug instanceof PluggableLens) {
PluggableLens lens = (PluggableLens) atPlug;
if (!lens.isFilter) {
colourAt = lens.colour;
}
}
PluggableLens lens = (PluggableLens) neighbourPlug;
if (lens.isFilter) {
if (colourAt == lens.colour) {
event.increasePriority(side);
} else if (colourAt == null) {
event.decreasePriority(side);
}
}
}
}
}
use of buildcraft.api.transport.pipe.IPipe in project BuildCraft by BuildCraft.
the class Pipe method updateConnections.
private void updateConnections() {
if (holder.getPipeWorld().isRemote) {
return;
}
updateMarked = false;
EnumMap<EnumFacing, Float> old = connected.clone();
connected.clear();
types.clear();
textures.clear();
for (EnumFacing facing : EnumFacing.VALUES) {
PipePluggable plug = getHolder().getPluggable(facing);
if (plug != null && plug.isBlocking()) {
continue;
}
TileEntity oTile = getHolder().getNeighbourTile(facing);
if (oTile == null) {
continue;
}
IPipe oPipe = getHolder().getNeighbourPipe(facing);
if (oPipe != null) {
PipeBehaviour oBehaviour = oPipe.getBehaviour();
if (oBehaviour == null) {
continue;
}
PipePluggable oPlug = oTile.getCapability(PipeApi.CAP_PLUG, facing.getOpposite());
if (oPlug == null || !oPlug.isBlocking()) {
if (canPipesConnect(facing, this, oPipe)) {
connected.put(facing, DEFAULT_CONNECTION_DISTANCE);
types.put(facing, ConnectedType.PIPE);
textures.put(facing, behaviour.getTextureIndex(facing));
}
continue;
}
}
BlockPos nPos = holder.getPipePos().offset(facing);
IBlockState neighbour = holder.getPipeWorld().getBlockState(nPos);
ICustomPipeConnection cust = PipeConnectionAPI.getCustomConnection(neighbour.getBlock());
if (cust == null) {
cust = DefaultPipeConnection.INSTANCE;
}
float ext = DEFAULT_CONNECTION_DISTANCE + cust.getExtension(holder.getPipeWorld(), nPos, facing.getOpposite(), neighbour);
if (behaviour.canConnect(facing, oTile) & flow.canConnect(facing, oTile)) {
connected.put(facing, ext);
types.put(facing, ConnectedType.TILE);
textures.put(facing, behaviour.getTextureIndex(facing));
}
}
if (!old.equals(connected)) {
for (EnumFacing face : EnumFacing.VALUES) {
boolean o = old.containsKey(face);
boolean n = connected.containsKey(face);
if (o != n) {
IPipe oPipe = getHolder().getNeighbourPipe(face);
if (oPipe != null) {
oPipe.markForUpdate();
}
}
}
}
getHolder().scheduleNetworkUpdate(PipeMessageReceiver.BEHAVIOUR);
}
use of buildcraft.api.transport.pipe.IPipe in project BuildCraft by BuildCraft.
the class WireSystem method canWireConnect.
/**
* Checks to see if the given holder could connect a wire across the specified side even if a matching wire wasn't
* there.
*/
public static boolean canWireConnect(IPipeHolder holder, EnumFacing side) {
// TODO: Expand to pipeless wires (8.1.x)
IPipe pipe = holder.getPipe();
if (pipe == null) {
return false;
}
IPipe oPipe = holder.getNeighbourPipe(side);
if (oPipe == null) {
return false;
}
if (pipe.isConnected(side)) {
return true;
}
if (//
(holder.getPluggable(side) != null && holder.getPluggable(side).isBlocking()) || (oPipe.getHolder().getPluggable(side.getOpposite()) != null && oPipe.getHolder().getPluggable(side.getOpposite()).isBlocking())) {
return false;
}
if (pipe.getDefinition().flowType == PipeApi.flowStructure || oPipe.getDefinition().flowType == PipeApi.flowStructure) {
return pipe.getColour() == null || oPipe.getColour() == null || pipe.getColour() == oPipe.getColour();
}
return false;
}
Aggregations