use of buildcraft.api.transport.IItemPluggable in project BuildCraft by BuildCraft.
the class BlockPipeHolder method onBlockActivated.
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
TilePipeHolder tile = getPipe(world, pos, false);
if (tile == null) {
return false;
}
RayTraceResult trace = rayTrace(world, pos, player);
if (trace == null) {
return false;
}
EnumFacing realSide = getPartSideHit(trace);
if (realSide == null) {
realSide = side;
}
if (trace.subHit > 6 && trace.subHit <= 12) {
PipePluggable existing = tile.getPluggable(realSide);
if (existing != null) {
return existing.onPluggableActivate(player, trace, hitX, hitY, hitZ);
}
}
EnumPipePart part = trace.subHit == 0 ? EnumPipePart.CENTER : EnumPipePart.fromFacing(realSide);
ItemStack held = player.getHeldItem(hand);
Item item = held.isEmpty() ? null : held.getItem();
PipePluggable existing = tile.getPluggable(realSide);
if (item instanceof IItemPluggable && existing == null) {
IItemPluggable itemPlug = (IItemPluggable) item;
PipePluggable plug = itemPlug.onPlace(held, tile, realSide, player, hand);
if (plug == null) {
return false;
} else {
tile.replacePluggable(realSide, plug);
if (!player.capabilities.isCreativeMode) {
held.shrink(1);
}
return true;
}
}
if (item instanceof ItemWire) {
EnumWirePart wirePartHit = getWirePartHit(trace);
EnumWirePart wirePart;
TilePipeHolder attachTile = tile;
if (wirePartHit != null) {
WireNode node = new WireNode(pos, wirePartHit);
node = node.offset(trace.sideHit);
wirePart = node.part;
if (!node.pos.equals(pos)) {
attachTile = getPipe(world, node.pos, false);
}
} else {
wirePart = EnumWirePart.get((trace.hitVec.x % 1 + 1) % 1 > 0.5, (trace.hitVec.y % 1 + 1) % 1 > 0.5, (trace.hitVec.z % 1 + 1) % 1 > 0.5);
}
if (wirePart != null && attachTile != null) {
boolean attached = attachTile.getWireManager().addPart(wirePart, EnumDyeColor.byMetadata(held.getMetadata()));
attachTile.scheduleNetworkUpdate(IPipeHolder.PipeMessageReceiver.WIRES);
if (attached && !player.capabilities.isCreativeMode) {
held.shrink(1);
}
if (attached) {
return true;
}
}
}
Pipe pipe = tile.getPipe();
if (pipe == null) {
return false;
}
if (pipe.behaviour.onPipeActivate(player, trace, hitX, hitY, hitZ, part)) {
return true;
}
if (pipe.flow.onFlowActivate(player, trace, hitX, hitY, hitZ, part)) {
return true;
}
return false;
}
Aggregations