use of buildcraft.api.transport.pluggable.PipePluggable in project BuildCraft by BuildCraft.
the class TileGenericPipe method update.
@Override
public void update() {
try {
if (!worldObj.isRemote) {
if (deletePipe) {
worldObj.setBlockToAir(getPos());
}
if (pipe == null || coreState.pipeId == null) {
return;
}
if (!initialized) {
initialize(pipe);
}
}
if (attachPluggables) {
attachPluggables = false;
// Attach callback
for (int i = 0; i < EnumFacing.VALUES.length; i++) {
if (sideProperties.pluggables[i] != null) {
pipe.eventBus.registerHandler(sideProperties.pluggables[i]);
sideProperties.pluggables[i].onAttachedPipe(this, EnumFacing.getFront(i));
}
}
notifyBlockChanged();
}
if (!BlockGenericPipe.isValid(pipe)) {
return;
}
pipe.updateEntity();
for (EnumFacing direction : EnumFacing.VALUES) {
PipePluggable p = getPipePluggable(direction);
if (p != null) {
p.update(this, direction);
}
}
if (worldObj.isRemote) {
if (resyncGateExpansions) {
syncGateExpansions();
}
return;
}
if (blockNeighborChange) {
for (int i = 0; i < 6; i++) {
if ((blockNeighborChangedSides & (1 << i)) != 0) {
blockNeighborChangedSides ^= 1 << i;
computeConnection(EnumFacing.getFront(i));
}
}
pipe.onNeighborBlockChange(0);
blockNeighborChange = false;
refreshRenderState = true;
}
if (refreshRenderState) {
refreshRenderState();
refreshRenderState = false;
}
if (sendClientUpdate) {
sendClientUpdate = false;
if (!worldObj.isRemote) {
Packet updatePacket = getBCDescriptionPacket();
BuildCraftCore.instance.sendToPlayersNear(updatePacket, this);
}
}
} catch (Throwable t) {
BCLog.logger.warn("CRASH! OH NO!", t);
Throwables.propagate(t);
}
}
use of buildcraft.api.transport.pluggable.PipePluggable in project BuildCraft by BuildCraft.
the class ItemRobot method onItemUse.
@Override
public boolean onItemUse(ItemStack currentItem, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) {
if (!world.isRemote) {
Block b = world.getBlockState(pos).getBlock();
if (!(b instanceof BlockGenericPipe)) {
return false;
}
Pipe<?> pipe = BlockGenericPipe.getPipe(world, pos);
if (pipe == null) {
return false;
}
// BlockGenericPipe pipeBlock = (BlockGenericPipe) b;
// BlockGenericPipe.RaytraceResult rayTraceResult = pipeBlock.doRayTrace(world, pos, player);
PipePluggable pluggable = pipe.container.getPipePluggable(side);
if (pluggable instanceof RobotStationPluggable) {
RobotStationPluggable robotPluggable = (RobotStationPluggable) pluggable;
DockingStation station = robotPluggable.getStation();
if (!station.isTaken()) {
RedstoneBoardRobotNBT robotNBT = ItemRobot.getRobotNBT(currentItem);
if (robotNBT == RedstoneBoardRegistry.instance.getEmptyRobotBoard()) {
return true;
}
EntityRobot robot = ((ItemRobot) currentItem.getItem()).createRobot(currentItem, world);
RobotEvent.Place robotEvent = new RobotEvent.Place(robot, player);
MinecraftForge.EVENT_BUS.post(robotEvent);
if (robotEvent.isCanceled()) {
return true;
}
if (robot != null && robot.getRegistry() != null) {
robot.setUniqueRobotId(robot.getRegistry().getNextRobotId());
float px = pos.getX() + 0.5F + side.getFrontOffsetX() * 0.5F;
float py = pos.getY() + 0.5F + side.getFrontOffsetY() * 0.5F;
float pz = pos.getZ() + 0.5F + side.getFrontOffsetZ() * 0.5F;
robot.setPosition(px, py, pz);
station.takeAsMain(robot);
robot.dock(robot.getLinkedStation());
world.spawnEntityInWorld(robot);
if (!player.capabilities.isCreativeMode) {
player.getCurrentEquippedItem().stackSize--;
}
}
}
return true;
}
}
return false;
}
use of buildcraft.api.transport.pluggable.PipePluggable in project BuildCraft by BuildCraft.
the class LensFilterHandler method eventHandler.
@PipeEventPriority(priority = -100)
public void eventHandler(PipeEventItem.FindDest event) {
IPipeTile container = event.pipe.getTile();
List<EnumSet<EnumFacing>> newDestinations = new ArrayList<>(event.destinations.size() * 2);
for (EnumSet<EnumFacing> dirs : event.destinations) {
EnumSet<EnumFacing> correctColored = EnumSet.noneOf(EnumFacing.class);
EnumSet<EnumFacing> notColored = EnumSet.noneOf(EnumFacing.class);
EnumDyeColor myColor = event.item.color;
for (EnumFacing dir : dirs) {
boolean hasFilter = false;
boolean hasLens = false;
EnumDyeColor sideColor = null;
EnumDyeColor sideLensColor = null;
// Get the side's color
// (1/2) From this pipe's outpost
PipePluggable pluggable = container.getPipePluggable(dir);
if (pluggable != null && pluggable instanceof LensPluggable) {
if (((LensPluggable) pluggable).isFilter) {
hasFilter = true;
sideColor = ((LensPluggable) pluggable).dyeColor;
} else {
hasLens = true;
sideLensColor = ((LensPluggable) pluggable).dyeColor;
}
}
// (2/2) From the other pipe's outpost
IPipe otherPipe = container.getNeighborPipe(dir);
if (otherPipe != null && otherPipe.getTile() != null) {
IPipeTile otherContainer = otherPipe.getTile();
pluggable = otherContainer.getPipePluggable(dir.getOpposite());
if (pluggable != null && pluggable instanceof LensPluggable && ((LensPluggable) pluggable).isFilter) {
EnumDyeColor otherColor = ((LensPluggable) pluggable).dyeColor;
if (hasFilter && otherColor != sideColor) {
// Filter colors conflict - the side is unpassable
continue;
} else if (hasLens) {
// treated as colorless
if (sideLensColor == otherColor) {
hasFilter = false;
sideColor = null;
} else {
continue;
}
} else {
hasFilter = true;
sideColor = otherColor;
}
}
}
if (hasFilter) {
if (myColor == sideColor) {
correctColored.add(dir);
}
} else {
notColored.add(dir);
}
}
if (!correctColored.isEmpty()) {
newDestinations.add(correctColored);
}
if (!notColored.isEmpty()) {
newDestinations.add(notColored);
}
}
event.destinations.clear();
event.destinations.addAll(newDestinations);
}
use of buildcraft.api.transport.pluggable.PipePluggable in project BuildCraft by BuildCraft.
the class BCTransportProxy method getServerGuiElement.
@Override
public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) {
BCTransportGuis gui = BCTransportGuis.get(id);
if (gui == null)
return null;
TileEntity tile = world.getTileEntity(new BlockPos(x, y, z));
switch(gui) {
case FILTERED_BUFFER:
{
if (tile instanceof TileFilteredBuffer) {
TileFilteredBuffer filteredBuffer = (TileFilteredBuffer) tile;
return new ContainerFilteredBuffer_BC8(player, filteredBuffer);
}
break;
}
case PIPE_DIAMOND:
{
if (tile instanceof IPipeHolder) {
IPipeHolder holder = (IPipeHolder) tile;
IPipe pipe = holder.getPipe();
if (pipe == null)
return null;
PipeBehaviour behaviour = pipe.getBehaviour();
if (behaviour instanceof PipeBehaviourDiamond) {
PipeBehaviourDiamond diaPipe = (PipeBehaviourDiamond) behaviour;
return new ContainerDiamondPipe(player, diaPipe);
}
}
break;
}
case PIPE_DIAMOND_WOOD:
{
if (tile instanceof IPipeHolder) {
IPipeHolder holder = (IPipeHolder) tile;
IPipe pipe = holder.getPipe();
if (pipe == null)
return null;
PipeBehaviour behaviour = pipe.getBehaviour();
if (behaviour instanceof PipeBehaviourWoodDiamond) {
PipeBehaviourWoodDiamond diaPipe = (PipeBehaviourWoodDiamond) behaviour;
return new ContainerDiamondWoodPipe(player, diaPipe);
}
}
break;
}
case PIPE_EMZULI:
{
if (tile instanceof IPipeHolder) {
IPipeHolder holder = (IPipeHolder) tile;
IPipe pipe = holder.getPipe();
if (pipe == null)
return null;
PipeBehaviour behaviour = pipe.getBehaviour();
if (behaviour instanceof PipeBehaviourEmzuli) {
PipeBehaviourEmzuli emPipe = (PipeBehaviourEmzuli) behaviour;
return new ContainerEmzuliPipe_BC8(player, emPipe);
}
}
break;
}
case GATE:
{
int ry = y >> 3;
EnumFacing gateSide = EnumFacing.getFront(y & 0x7);
tile = world.getTileEntity(new BlockPos(x, ry, z));
if (tile instanceof IPipeHolder) {
IPipeHolder holder = (IPipeHolder) tile;
PipePluggable plug = holder.getPluggable(gateSide);
if (plug instanceof PluggableGate) {
return new ContainerGate(player, ((PluggableGate) plug).logic);
}
}
break;
}
}
return null;
}
use of buildcraft.api.transport.pluggable.PipePluggable in project LogisticsPipes by RS485.
the class LPRobotConnectionControl method checkAll.
public void checkAll(World world) {
if (!globalAvailableRobots.containsKey(world)) {
return;
}
for (Pair<DoubleCoordinates, ForgeDirection> canidatePos : globalAvailableRobots.get(world)) {
TileEntity connectedPipeTile = canidatePos.getValue1().getTileEntity(world);
if (!(connectedPipeTile instanceof LogisticsTileGenericPipe)) {
continue;
}
LogisticsTileGenericPipe connectedPipe = (LogisticsTileGenericPipe) connectedPipeTile;
if (!connectedPipe.isRoutingPipe()) {
continue;
}
PipePluggable connectedPluggable = ((TileGenericPipe) connectedPipe.tilePart.getOriginal()).getPipePluggable(canidatePos.getValue2());
if (!(connectedPluggable instanceof RobotStationPluggable)) {
continue;
}
DockingStation connectedStation = ((RobotStationPluggable) connectedPluggable).getStation();
if (!connectedStation.isTaken()) {
continue;
}
EntityRobotBase connectedRobot = connectedStation.robotTaking();
if (connectedRobot == null) {
continue;
}
if (!(connectedRobot.getBoard() instanceof LogisticsRoutingBoardRobot)) {
continue;
}
LogisticsRoutingBoardRobot lpBoard = ((LogisticsRoutingBoardRobot) connectedRobot.getBoard());
if (isModified(lpBoard)) {
connectedPipe.getRoutingPipe().triggerConnectionCheck();
}
}
}
Aggregations