@Override public void updateEntity() { if (pipe == null) return; if (!initialized) initialize(pipe); if (!BlockGenericPipe.isValid(pipe)) return; if (blockNeighborChange) { computeConnections(); pipe.onNeighborBlockChange(0); blockNeighborChange = false; refreshRenderState = true; } if (refreshRenderState) { refreshRenderState(); refreshRenderState = false; } IPowerProvider provider = getPowerProvider(); if (provider != null) provider.update(this); if (pipe != null) pipe.updateEntity(); }
@Override public int isProvidingWeakPower(IBlockAccess world, int i, int j, int k, int l) { Pipe pipe = getPipe(world, i, j, k); if (isValid(pipe)) return pipe.isIndirectlyPoweringTo(l); else return 0; }
@Override public boolean canConnectRedstone(IBlockAccess world, int x, int y, int z, int side) { Pipe pipe = getPipe(world, x, y, z); if (isValid(pipe)) return pipe.canConnectRedstone(); else return false; }
@Override public void dropBlockAsItemWithChance(World world, int i, int j, int k, int l, float f, int dmg) { if (CoreProxy.proxy.isRenderWorld(world)) return; int i1 = quantityDropped(world.rand); for (int j1 = 0; j1 < i1; j1++) { if (world.rand.nextFloat() > f) { continue; } Pipe pipe = getPipe(world, i, j, k); if (pipe == null) { pipe = pipeRemoved.get(new BlockIndex(i, j, k)); } if (pipe != null) { int k1 = pipe.itemID; if (k1 > 0) { pipe.dropContents(); dropBlockAsItem_do(world, i, j, k, new ItemStack(k1, 1, damageDropped(l))); } } } }
private boolean stripEquipment(Pipe pipe) { // Try to strip wires first, starting with yellow. for (IPipe.WireColor color : IPipe.WireColor.values()) { if (pipe.wireSet[color.reverse().ordinal()]) { if (!CoreProxy.proxy.isRenderWorld(pipe.container.worldObj)) { dropWire(color.reverse(), pipe); } pipe.wireSet[color.reverse().ordinal()] = false; // pipe.worldObj.markBlockNeedsUpdate(pipe.xCoord, pipe.yCoord, pipe.zCoord); pipe.container.scheduleRenderUpdate(); return true; } } // Try to strip gate next if (pipe.hasGate()) { if (!CoreProxy.proxy.isRenderWorld(pipe.container.worldObj)) { pipe.gate.dropGate(); } pipe.resetGate(); return true; } return false; }
@Override public ArrayList<ItemStack> getBlockDropped( World world, int x, int y, int z, int metadata, int fortune) { if (CoreProxy.proxy.isRenderWorld(world)) return null; ArrayList<ItemStack> list = new ArrayList<ItemStack>(); int count = quantityDropped(metadata, fortune, world.rand); for (int i = 0; i < count; i++) { Pipe pipe = getPipe(world, x, y, z); if (pipe == null) { pipe = pipeRemoved.get(new BlockIndex(x, y, z)); } if (pipe != null) { if (pipe.itemID > 0) { pipe.dropContents(); list.add(new ItemStack(pipe.itemID, 1, damageDropped(metadata))); } } } return list; }
@Override public int isProvidingStrongPower(IBlockAccess iblockaccess, int x, int y, int z, int l) { Pipe pipe = getPipe(iblockaccess, x, y, z); if (isValid(pipe)) return pipe.isPoweringTo(l); else return 0; }
@SuppressWarnings({"all"}) @Override public void randomDisplayTick(World world, int i, int j, int k, Random random) { Pipe pipe = getPipe(world, i, j, k); if (isValid(pipe)) { pipe.randomDisplayTick(random); } }
@Override public void onEntityCollidedWithBlock(World world, int i, int j, int k, Entity entity) { super.onEntityCollidedWithBlock(world, i, j, k, entity); Pipe pipe = getPipe(world, i, j, k); if (isValid(pipe)) { pipe.onEntityCollidedWithBlock(entity); } }
@Override public void onBlockPlacedBy( World world, int x, int y, int z, EntityLivingBase placer, ItemStack stack) { super.onBlockPlacedBy(world, x, y, z, placer, stack); Pipe pipe = getPipe(world, x, y, z); if (isValid(pipe)) { pipe.onBlockPlacedBy(placer); } }
@Override public int onBlockPlaced( World world, int x, int y, int z, int side, float par6, float par7, float par8, int meta) { super.onBlockPlaced(world, x, y, z, side, par6, par7, par8, meta); Pipe pipe = getPipe(world, x, y, z); if (isValid(pipe)) { pipe.onBlockPlaced(); } return meta; }
public static ItemPipe registerPipe(int key, Class<? extends Pipe> clas) { ItemPipe item = new ItemPipe(key); item.setUnlocalizedName("buildcraftPipe." + clas.getSimpleName().toLowerCase(Locale.ENGLISH)); GameRegistry.registerItem(item, item.getUnlocalizedName()); pipes.put(item.itemID, clas); Pipe dummyPipe = createPipe(item.itemID); if (dummyPipe != null) { item.setPipeIconIndex(dummyPipe.getIconIndexForItem()); TransportProxy.proxy.setIconProviderFromPipe(item, dummyPipe); } return item; }
@Override @SideOnly(Side.CLIENT) public void registerIcons(IconRegister iconRegister) { if (!skippedFirstIconRegister) { skippedFirstIconRegister = true; return; } BuildCraftTransport.instance.gateIconProvider.registerIcons(iconRegister); BuildCraftTransport.instance.wireIconProvider.registerIcons(iconRegister); for (int i : pipes.keySet()) { Pipe dummyPipe = createPipe(i); if (dummyPipe != null) { dummyPipe.getIconProvider().registerIcons(iconRegister); } } }
public boolean isPipeConnected(TileEntity with) { Pipe pipe1 = pipe; Pipe pipe2 = null; if (with instanceof TileGenericPipe) pipe2 = ((TileGenericPipe) with).pipe; if (!BlockGenericPipe.isValid(pipe1)) return false; if (BlockGenericPipe.isValid(pipe2) && !pipe1.transport.getClass().isAssignableFrom(pipe2.transport.getClass()) && !pipe1.transport.allowsConnect(pipe2.transport)) return false; if (pipe2 != null && !(pipe2.isPipeConnected(this))) return false; return pipe1 != null ? pipe1.isPipeConnected(with) : false; }
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 validate() { super.validate(); bindPipe(); if (pipe != null) { pipe.validate(); } }
@Override public void invalidate() { initialized = false; if (pipe != null) { pipe.invalidate(); } super.invalidate(); }
private void bindPipe() { if (!pipeBound && pipe != null) { pipe.setTile(this); coreState.pipeId = pipe.itemID; pipeBound = true; } }
@Override public void invalidate() { initialized = false; if (pipe != null) { pipe.invalidate(); } super.invalidate(); // if (BlockGenericPipe.isValid(pipe)) // BlockGenericPipe.removePipe(pipe); }
@Override public LinkedList<ITrigger> getTriggers() { LinkedList<ITrigger> result = new LinkedList<ITrigger>(); if (BlockGenericPipe.isFullyDefined(pipe) && pipe.hasGate()) { result.add(BuildCraftCore.triggerRedstoneActive); result.add(BuildCraftCore.triggerRedstoneInactive); } return result; }
@Override public void writeToNBT(NBTTagCompound nbttagcompound) { super.writeToNBT(nbttagcompound); if (pipe != null) { nbttagcompound.setInteger("pipeId", pipe.itemID); pipe.writeToNBT(nbttagcompound); } else nbttagcompound.setInteger("pipeId", key); for (int i = 0; i < Orientations.dirs().length; i++) { nbttagcompound.setInteger("facadeBlocks[" + i + "]", facadeBlocks[i]); nbttagcompound.setInteger("facadeMeta[" + i + "]", facadeMeta[i]); } }
@Override public void writeToNBT(NBTTagCompound nbttagcompound) { super.writeToNBT(nbttagcompound); if (pipe != null) { nbttagcompound.setInteger("pipeId", pipe.itemID); pipe.writeToNBT(nbttagcompound); } else nbttagcompound.setInteger("pipeId", coreState.pipeId); for (int i = 0; i < ForgeDirection.VALID_DIRECTIONS.length; i++) { nbttagcompound.setInteger("facadeBlocks[" + i + "]", facadeBlocks[i]); nbttagcompound.setInteger("facadeMeta[" + i + "]", facadeMeta[i]); } }
/** * Spawn particles for when the block is destroyed. Due to the nature of how this is invoked, the * x/y/z locations are not always guaranteed to host your block. So be sure to do proper sanity * checks before assuming that the location is this block. * * @param world The current world * @param x X position to spawn the particle * @param y Y position to spawn the particle * @param z Z position to spawn the particle * @param meta The metadata for the block before it was destroyed. * @param effectRenderer A reference to the current effect renderer. * @return True to prevent vanilla break particles from spawning. */ @SideOnly(Side.CLIENT) @Override public boolean addBlockDestroyEffects( World worldObj, int x, int y, int z, int meta, EffectRenderer effectRenderer) { Pipe pipe = getPipe(worldObj, x, y, z); if (pipe == null) return false; Icon icon = pipe.getIconProvider().getIcon(pipe.getIconIndexForItem()); byte its = 4; for (int i = 0; i < its; ++i) { for (int j = 0; j < its; ++j) { for (int k = 0; k < its; ++k) { double px = x + (i + 0.5D) / (double) its; double py = y + (j + 0.5D) / (double) its; double pz = z + (k + 0.5D) / (double) its; int random = rand.nextInt(6); EntityDiggingFX fx = new EntityDiggingFX( worldObj, px, py, pz, px - x - 0.5D, py - y - 0.5D, pz - z - 0.5D, BuildCraftTransport.genericPipeBlock, random, meta); fx.func_110125_a(icon); effectRenderer.addEffect(fx.applyColourMultiplier(x, y, z)); } } } return true; }
@Override public void readFromNBT(NBTTagCompound nbttagcompound) { super.readFromNBT(nbttagcompound); key = nbttagcompound.getInteger("pipeId"); pipe = BlockGenericPipe.createPipe(key); if (pipe != null) { pipe.readFromNBT(nbttagcompound); } for (int i = 0; i < Orientations.dirs().length; i++) { facadeBlocks[i] = nbttagcompound.getInteger("facadeBlocks[" + i + "]"); facadeMeta[i] = nbttagcompound.getInteger("facadeMeta[" + i + "]"); } }
@Override public void readFromNBT(NBTTagCompound nbttagcompound) { super.readFromNBT(nbttagcompound); coreState.pipeId = nbttagcompound.getInteger("pipeId"); pipe = BlockGenericPipe.createPipe(coreState.pipeId); if (pipe != null) { pipe.readFromNBT(nbttagcompound); } for (int i = 0; i < ForgeDirection.VALID_DIRECTIONS.length; i++) { facadeBlocks[i] = nbttagcompound.getInteger("facadeBlocks[" + i + "]"); facadeMeta[i] = nbttagcompound.getInteger("facadeMeta[" + i + "]"); } }
/** * Drops a pipe wire item of the passed color. * * @param color */ private void dropWire(IPipe.WireColor color, Pipe pipe) { Item wireItem; switch (color) { case Red: wireItem = BuildCraftTransport.redPipeWire; break; case Blue: wireItem = BuildCraftTransport.bluePipeWire; break; case Green: wireItem = BuildCraftTransport.greenPipeWire; break; default: wireItem = BuildCraftTransport.yellowPipeWire; } pipe.dropItem(new ItemStack(wireItem)); }
@Override public void afterStateUpdated(byte stateId) { if (!worldObj.isRemote) return; switch (stateId) { case 0: if (pipe == null && coreState.pipeId != 0) { initialize(BlockGenericPipe.createPipe(coreState.pipeId)); } if (pipe != null) { if (pipe.gate == null) { pipe.gate = new GateVanilla(pipe); } pipe.gate.kind = GateKind.values()[coreState.gateKind]; } break; } worldObj.markBlockNeedsUpdate(xCoord, yCoord, zCoord); }
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); } } }
public static void removePipe(Pipe pipe) { if (pipe == null) return; if (isValid(pipe)) { pipe.onBlockRemoval(); } World world = pipe.container.worldObj; if (world == null) return; int x = pipe.container.xCoord; int y = pipe.container.yCoord; int z = pipe.container.zCoord; if (lastRemovedDate != world.getWorldTime()) { lastRemovedDate = world.getWorldTime(); pipeRemoved.clear(); } pipeRemoved.put(new BlockIndex(x, y, z), pipe); world.removeBlockTileEntity(x, y, z); }
@Override public void onChunkUnload() { if (pipe != null) { pipe.onChunkUnload(); } }