private void computeConnections() { if (tileBuffer != null) { boolean[] oldConnections = pipeConnectionsBuffer; pipeConnectionsBuffer = new boolean[6]; for (int i = 0; i < tileBuffer.length; ++i) { TileBuffer t = tileBuffer[i]; t.refresh(); if (t.getTile() != null) { pipeConnectionsBuffer[i] = isPipeConnected(t.getTile()); if (t.getTile() instanceof TileGenericPipe) { TileGenericPipe pipe = (TileGenericPipe) t.getTile(); pipe.pipeConnectionsBuffer[ForgeDirection.values()[i].getOpposite().ordinal()] = pipeConnectionsBuffer[i]; } } } for (int i = 0; i < tileBuffer.length; ++i) if (oldConnections[i] != pipeConnectionsBuffer[i]) { Position pos = new Position(xCoord, yCoord, zCoord, ForgeDirection.values()[i]); pos.moveForwards(1.0); scheduleRenderUpdate(); } } }
public void initialize(Pipe pipe) { this.pipe = pipe; tileBuffer = new TileBuffer[6]; for (ForgeDirection o : ForgeDirection.VALID_DIRECTIONS) { Position pos = new Position(xCoord, yCoord, zCoord, o); pos.moveForwards(1.0); tileBuffer[o.ordinal()] = new TileBuffer(); tileBuffer[o.ordinal()].initialize(worldObj, (int) pos.x, (int) pos.y, (int) pos.z); } for (ForgeDirection o : ForgeDirection.VALID_DIRECTIONS) { TileEntity tile = getTile(o); if (tile instanceof ITileBufferHolder) ((ITileBufferHolder) tile) .blockCreated(o, BuildCraftTransport.genericPipeBlock.blockID, this); } bindPipe(); computeConnections(); scheduleRenderUpdate(); if (pipe != null) pipe.initialize(); initialized = true; }
@Override public void doWork() { if (powerProvider.getEnergyStored() <= 0) return; World w = worldObj; int meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord); if (meta > 5) return; Position pos = new Position(xCoord, yCoord, zCoord, Orientations.values()[meta]); pos.moveForwards(1); TileEntity tile = w.getBlockTileEntity((int) pos.x, (int) pos.y, (int) pos.z); if (tile instanceof IInventory) { if (!PipeManager.canExtractItems(this, w, (int) pos.x, (int) pos.y, (int) pos.z)) return; IInventory inventory = (IInventory) tile; ItemStack[] extracted = checkExtract(inventory, true, pos.orientation.reverse()); if (extracted == null) return; for (ItemStack stack : extracted) { if (stack == null || stack.stackSize == 0) { powerProvider.useEnergy(1, 1, false); continue; } Position entityPos = new Position( pos.x + 0.5, pos.y + Utils.getPipeFloorOf(stack), pos.z + 0.5, pos.orientation.reverse()); entityPos.moveForwards(0.5); IPipedItem entity = new EntityPassiveItem(w, entityPos.x, entityPos.y, entityPos.z, stack); ((PipeTransportItems) transport).entityEntering(entity, entityPos.orientation); } } }
@Override public void doWork(PowerHandler workProvider) { if (powerProvider.getEnergyStored() <= 0) return; World w = getWorld(); int meta = w.getBlockMetadata(container.xCoord, container.yCoord, container.zCoord); if (meta > 5) return; Position pos = new Position( container.xCoord, container.yCoord, container.zCoord, ForgeDirection.VALID_DIRECTIONS[meta]); pos.moveForwards(1); int blockId = w.getBlockId((int) pos.x, (int) pos.y, (int) pos.z); TileEntity tile = w.getBlockTileEntity((int) pos.x, (int) pos.y, (int) pos.z); if (tile instanceof IInventory) { if (!PipeManager.canExtractItems(this, w, (int) pos.x, (int) pos.y, (int) pos.z)) return; IInventory inventory = (IInventory) tile; ItemStack extracted = checkExtract(inventory, true, pos.orientation.getOpposite()); if (extracted == null || extracted.stackSize == 0) { powerProvider.useEnergy(1, 1, false); return; } Position entityPos = new Position( pos.x + 0.5, pos.y + CoreConstants.PIPE_MIN_POS, pos.z + 0.5, pos.orientation.getOpposite()); entityPos.moveForwards(0.5); TravelingItem entity = new TravelingItem(entityPos.x, entityPos.y, entityPos.z, extracted); ((PipeTransportItems) transport).injectItem(entity, entityPos.orientation); } }
public ContainerGateInterface(IInventory playerInventory, Pipe pipe) { super(0); this.playerIInventory = playerInventory; for (int l = 0; l < 3; l++) for (int k1 = 0; k1 < 9; k1++) addSlotToContainer(new Slot(playerInventory, k1 + l * 9 + 9, 8 + k1 * 18, 123 + l * 18)); for (int i1 = 0; i1 < 9; i1++) addSlotToContainer(new Slot(playerInventory, i1, 8 + i1 * 18, 181)); this.pipe = pipe; // Do not attempt to create a list of potential actions and triggers on // the client. if (!CoreProxy.proxy.isRemote(pipe.worldObj)) { _potentialActions.addAll(pipe.getActions()); _potentialTriggers.addAll(ActionManager.getPipeTriggers(pipe)); for (Orientations o : Orientations.dirs()) { Position pos = new Position(pipe.xCoord, pipe.yCoord, pipe.zCoord, o); pos.moveForwards(1.0); TileEntity tile = pipe.worldObj.getBlockTileEntity((int) pos.x, (int) pos.y, (int) pos.z); int blockID = pipe.worldObj.getBlockId((int) pos.x, (int) pos.y, (int) pos.z); Block block = Block.blocksList[blockID]; LinkedList<ITrigger> nearbyTriggers = ActionManager.getNeighborTriggers(block, tile); for (ITrigger t : nearbyTriggers) if (!_potentialTriggers.contains(t)) _potentialTriggers.add(t); LinkedList<IAction> nearbyActions = ActionManager.getNeighborActions(block, tile); for (IAction a : nearbyActions) if (!_potentialActions.contains(a)) _potentialActions.add(a); } } }
protected void updateDataClient() { head.x = decodeDouble(dataWatcher.getWatchableObjectInt(8)); head.y = decodeDouble(dataWatcher.getWatchableObjectInt(9)); head.z = decodeDouble(dataWatcher.getWatchableObjectInt(10)); tail.x = decodeDouble(dataWatcher.getWatchableObjectInt(11)); tail.y = decodeDouble(dataWatcher.getWatchableObjectInt(12)); tail.z = decodeDouble(dataWatcher.getWatchableObjectInt(13)); isVisible = (dataWatcher.getWatchableObjectByte(14) == 1); }
@Override public void entityEntering(ItemStack payload, ForgeDirection orientation) { /* FIXME: This is untested guesswork */ Position itemPos = new Position(xCoord, yCoord, zCoord, orientation); itemPos.moveBackwards(1.0); itemPos.x += 0.5; itemPos.y += 0.25; itemPos.z += 0.5; itemPos.moveForwards(0.5); EntityPassiveItem pipedItem = new EntityPassiveItem(worldObj, itemPos.x, itemPos.y, itemPos.z, payload); entityEntering(pipedItem, orientation); }
private void moveSolids() { items.performLoad(); items.performRemoval(); for (TravelingItem item : items) { if (item.isCorrupted()) { items.scheduleRemoval(item); continue; } if (item.getContainer() != this.container) { items.scheduleRemoval(item); continue; } Position motion = new Position(0, 0, 0, item.toCenter ? item.input : item.output); motion.moveForwards(item.getSpeed()); item.movePosition(motion.x, motion.y, motion.z); if ((item.toCenter && middleReached(item)) || outOfBounds(item)) { item.toCenter = false; // Reajusting to the middle item.setPosition( container.xCoord + 0.5, container.yCoord + TransportUtils.getPipeFloorOf(item.getItemStack()), container.zCoord + 0.5); if (item.output == ForgeDirection.UNKNOWN) { if (travelHook != null) { travelHook.drop(this, item); } EntityItem dropped = null; if (items.scheduleRemoval(item)) { dropped = item.toEntityItem(item.input); } if (dropped != null) { onDropped(dropped); } } else { if (travelHook != null) { travelHook.centerReached(this, item); } } } else if (!item.toCenter && endReached(item)) { TileEntity tile = container.getTile(item.output); boolean handleItem = true; if (travelHook != null) { handleItem = !travelHook.endReached(this, item, tile); } // If the item has not been scheduled to removal by the hook if (handleItem && items.scheduleRemoval(item)) { handleTileReached(item, tile); } } } items.performRemoval(); }