use of buildcraft.api.transport.pluggable.IPipePluggableItem in project BuildCraft by BuildCraft.
the class BlockGenericPipe method addOrStripPipePluggable.
private boolean addOrStripPipePluggable(World world, BlockPos pos, ItemStack stack, EntityPlayer player, EnumFacing side, Pipe<?> pipe) {
RaytraceResult rayTraceResult = doRayTrace(world, pos, player);
EnumFacing placementSide = rayTraceResult != null && rayTraceResult.sideHit != null ? rayTraceResult.sideHit : side;
IPipePluggableItem pluggableItem = (IPipePluggableItem) stack.getItem();
PipePluggable pluggable = pluggableItem.createPipePluggable(pipe, placementSide, stack);
if (pluggable == null) {
return false;
}
if (player.isSneaking()) {
if (pipe.container.hasPipePluggable(side) && rayTraceResult != null && rayTraceResult.hitPart == Part.Pluggable && pluggable.getClass().isInstance(pipe.container.getPipePluggable(side))) {
return pipe.container.setPluggable(side, null, player);
}
}
if (rayTraceResult != null && rayTraceResult.hitPart == Part.Pipe) {
if (!pipe.container.hasPipePluggable(placementSide)) {
if (pipe.container.setPluggable(placementSide, pluggable, player)) {
if (!player.capabilities.isCreativeMode) {
stack.stackSize--;
}
world.playSoundEffect(pos.getX() + 0.5F, pos.getY() + 0.5F, pos.getZ() + 0.5F, "dig.stone", 1.0f, 0.8f);
return true;
} else {
return false;
}
}
}
return false;
}
use of buildcraft.api.transport.pluggable.IPipePluggableItem in project BuildCraft by BuildCraft.
the class BlockGenericPipe method onBlockActivated.
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumFacing side, float xOffset, float yOffset, float zOffset) {
if (super.onBlockActivated(world, pos, state, player, side, xOffset, yOffset, zOffset)) {
return true;
}
world.notifyBlockOfStateChange(pos, BuildCraftTransport.genericPipeBlock);
Pipe<?> pipe = getPipe(world, pos);
RaytraceResult rayTrace = doRayTrace(world, pos, player);
if (rayTrace != null) {
side = rayTrace.sideHit;
}
if (isValid(pipe)) {
ItemStack currentItem = player.getCurrentEquippedItem();
// from the pipe.
if (player.isSneaking() && currentItem == null) {
if (stripEquipment(world, pos, player, pipe, side)) {
return true;
}
} else if (currentItem == null) {
// Fall through the end of the test
} else if (currentItem.getItem() == Items.sign) {
// Sign will be placed anyway, so lets show the sign gui
return false;
} else if (currentItem.getItem() instanceof ItemPipe) {
return false;
} else if (currentItem.getItem() instanceof ItemGateCopier) {
return false;
} else if (currentItem.getItem() instanceof IToolWrench) {
// Only check the instance at this point. Call the IToolWrench
// interface callbacks for the individual pipe/logic calls
RaytraceResult rayTraceResult = doRayTrace(world, pos, player);
if (rayTraceResult != null) {
EnumFacing hitSide = rayTraceResult.hitPart == Part.Pipe ? rayTraceResult.sideHit : null;
return pipe.blockActivated(player, hitSide);
} else {
return pipe.blockActivated(player, null);
}
} else if (currentItem.getItem() instanceof IMapLocation) {
// We want to be able to record pipe locations
return false;
} else if (PipeWire.RED.isPipeWire(currentItem)) {
if (addOrStripWire(player, pipe, PipeWire.RED)) {
return true;
}
} else if (PipeWire.BLUE.isPipeWire(currentItem)) {
if (addOrStripWire(player, pipe, PipeWire.BLUE)) {
return true;
}
} else if (PipeWire.GREEN.isPipeWire(currentItem)) {
if (addOrStripWire(player, pipe, PipeWire.GREEN)) {
return true;
}
} else if (PipeWire.YELLOW.isPipeWire(currentItem)) {
if (addOrStripWire(player, pipe, PipeWire.YELLOW)) {
return true;
}
} else if (currentItem.getItem() == Items.water_bucket) {
if (!world.isRemote) {
pipe.container.setPipeColor(-1);
}
return true;
} else if (currentItem.getItem() instanceof IPipePluggableItem) {
if (addOrStripPipePluggable(world, pos, currentItem, player, side, pipe)) {
return true;
}
}
Gate clickedGate = null;
if (rayTrace != null && rayTrace.hitPart == Part.Pluggable && pipe.container.getPipePluggable(rayTrace.sideHit) instanceof GatePluggable) {
clickedGate = pipe.gates[rayTrace.sideHit.ordinal()];
}
if (clickedGate != null) {
clickedGate.openGui(player);
return true;
} else {
if (pipe.blockActivated(player, side)) {
return true;
}
if (rayTrace != null) {
EnumFacing hitSide = rayTrace.hitPart == Part.Pipe ? rayTrace.sideHit : null;
return pipe.blockActivated(player, hitSide);
}
}
}
return false;
}
Aggregations