private boolean shouldEat() { if(!Wrapper.getPlayer().canEat(false)) return false; if(Wrapper.getMinecraft().currentScreen != null) return false; if(Wrapper.getMinecraft().currentScreen == null && Wrapper.getMinecraft().objectMouseOver != null) { Entity entity = Wrapper.getMinecraft().objectMouseOver.entityHit; if(entity instanceof EntityVillager || entity instanceof EntityTameable) return false; if(Wrapper.getMinecraft().objectMouseOver.getBlockPos() != null && Wrapper.getWorld(). getBlockState(Wrapper.getMinecraft().objectMouseOver.getBlockPos()).getBlock() instanceof BlockContainer) return false; } return true; }
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int i, int j, int k, int side, float f, float f1, float f2) { if (player.isSneaking()) { return false; } if (!world.isRemote) { if (!world.canMineBlock(player, i, j, k)) { return false; } if (!player.canPlayerEdit(i, j, k, side, stack)) { return false; } Block block = world.getBlock(i, j, k); if (prohibitedBlocks.contains(block)) { return false; } if ((block instanceof BlockContainer)) { return false; } int data = world.getBlockMetadata(i, j, k); world.setBlock(i, j, k, Blocks.air, 0, 3); world.spawnEntityInWorld(new EnderBlock(world, player, block, data)); } return true; }
/** * Places the block in the world, at the location specified in the slot. */ public void buildBlock(BptSlotInfo slot, IBptContext context) { // Meta needs to be specified twice, depending on the block behavior context.world().setBlock(slot.x, slot.y, slot.z, slot.blockId, slot.meta,3); context.world().setBlockMetadataWithNotify(slot.x, slot.y, slot.z, slot.meta,3); if (Block.blocksList[slot.blockId] instanceof BlockContainer) { TileEntity tile = context.world().getBlockTileEntity(slot.x, slot.y, slot.z); slot.cpt.setInteger("x", slot.x); slot.cpt.setInteger("y", slot.y); slot.cpt.setInteger("z", slot.z); if (tile != null) { tile.readFromNBT(slot.cpt); } } }
/** * Initializes a slot from the blueprint according to an objet placed on {x, y, z} on the world. This typically means adding entries in slot.cpt. Note that * "id" and "meta" will be set automatically, corresponding to the block id and meta. * * By default, if the block is a BlockContainer, tile information will be to save / load the block. */ public void initializeFromWorld(BptSlotInfo slot, IBptContext context, int x, int y, int z) { if (Block.blocksList[slot.blockId] instanceof BlockContainer) { TileEntity tile = context.world().getBlockTileEntity(x, y, z); if (tile != null) { tile.writeToNBT(slot.cpt); } } if (Block.blocksList[slot.blockId] != null) { ArrayList<ItemStack> req = Block.blocksList[slot.blockId].getBlockDropped(context.world(), x, y, z, context.world().getBlockMetadata(x, y, z), 0); if (req != null) { slot.storedRequirements.addAll(req); } } }
/** * By default, block class name, block tile name and block name are used to define block signature. Overriding this subprogram may allow to replace some of * these with stars, specify the mod that this block kind is coming from or add custom data to the signature. */ public BlockSignature getSignature(Block block) { BlockSignature sig = new BlockSignature(); if (block.blockID > BuildCraftAPI.LAST_ORIGINAL_BLOCK) { sig.blockClassName = block.getClass().getSimpleName(); if (block instanceof BlockContainer) { // TODO: Try to see if we can get a world instance to call with instead of null TileEntity tile = ((BlockContainer) block).createNewTileEntity(null); if (tile != null) { sig.tileClassName = tile.getClass().getSimpleName(); } } } sig.blockName = block.getUnlocalizedName(); sig.replaceNullWithStar(); return sig; }
public boolean isPlantValidForSlot (World world, int x, int y, int z, int slot, PlantItem plant) { if (plant == null) return false; if (plant.getPlantBlock() instanceof BlockContainer) return false; if (!slotProfile.isPlantValidForSlot(world, x, y, z, slot, plant)) return false; if (!enoughSpaceAround(world, x, y, z, slot, plant)) return false; if (!isPlantValidForSubstrate(getGardenSubstrate(world, x, y, z, slot), plant)) return false; if (canSustainPlantIndependently(world, x, y, z, plant)) return false; return true; }
private boolean shouldEat() { // check hunger if(!WMinecraft.getPlayer().canEat(false)) return false; // check screen if(!ignoreScreen.isChecked() && mc.currentScreen != null) return false; // check for clickable objects if(mc.currentScreen == null && mc.objectMouseOver != null) { // clickable entities Entity entity = mc.objectMouseOver.entityHit; if(entity instanceof EntityVillager || entity instanceof EntityTameable) return false; // clickable blocks BlockPos pos = mc.objectMouseOver.getBlockPos(); if(pos != null) { Block block = WMinecraft.getWorld().getBlockState(pos).getBlock(); if(block instanceof BlockContainer || block instanceof BlockWorkbench) return false; } } return true; }
private boolean shouldEatSoup() { // check health if(WMinecraft.getPlayer().getHealth() > health.getValueF() * 2F) return false; // check screen if(!ignoreScreen.isChecked() && mc.currentScreen != null) return false; // check for clickable objects if(mc.currentScreen == null && mc.objectMouseOver != null) { // clickable entities Entity entity = mc.objectMouseOver.entityHit; if(entity instanceof EntityVillager || entity instanceof EntityTameable) return false; // clickable blocks if(mc.objectMouseOver.getBlockPos() != null && WBlock.getBlock( mc.objectMouseOver.getBlockPos()) instanceof BlockContainer) return false; } return true; }
@Mod.EventHandler @SideOnly(Side.CLIENT) public void initClient(FMLPreInitializationEvent event) { for (Block b : chest_blocks) { BlockContainer chest = (BlockContainer) b; TileEntity te = chest.createNewTileEntity(null, 0); if (te == null) continue; TileEntityRendererDispatcher.instance.mapSpecialRenderers.remove(te.getClass()); } // TODO: Needs a custom item renderer. Whatever. 1.8'll be here eventually. }
public void register3DItem(BlockContainer theBlock, TileEntitySpecialRenderer renderer) { try { MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(theBlock), new GenericBlockItemRenderer(renderer, theBlock.createNewTileEntity(null, 0))); } catch (Exception e) { e.printStackTrace(); } }
@Override public void updateWorldInfo(World worldIn, BlockPos pos) { adjAirCount = 0; List<HeatManager> adjacentManagers = new ArrayList<HeatManager>(); // For each adjacent block for (EnumFacing f : EnumFacing.VALUES) { BlockPos adjPos = pos.offset(f); Block block = worldIn.getBlockState(adjPos).getBlock(); if (block.isAir(worldIn, adjPos)) { // The block is an air block, will lose heat. if (ventSides.contains(f)) { adjAirCount += ventEfficiency; } else { adjAirCount ++; } } else if (block instanceof BlockContainer) { TileEntity te = worldIn.getTileEntity(adjPos); if (te instanceof ITileEntityHeated) { // This adjacent machine can exchange heat adjacentManagers.add(((ITileEntityHeated) te).getHeatManager()); } } } adjManagers = adjacentManagers.toArray(new HeatManager[adjacentManagers.size()]); }
private IInventory getOutputInventory() throws LuaException { ForgeDirection outDir = playerInterface.outputSide; if (outDir == null) { throw new LuaException("Output Side has not yet been set."); } Location blockLoc = new Location(playerInterface.xCoord + outDir.offsetX, playerInterface.yCoord + outDir.offsetY, playerInterface.zCoord + outDir.offsetZ, playerInterface.getWorldObj()); Block block = playerInterface.getWorldObj().getBlock(blockLoc.getRoundedX(), blockLoc.getRoundedY(), blockLoc.getRoundedZ()); if (block instanceof BlockContainer) { return (IInventory) playerInterface.getWorldObj().getTileEntity(blockLoc.getRoundedX(), blockLoc.getRoundedY(), blockLoc.getRoundedZ()); } else { throw new LuaException("Invalid Output Inventory."); } }
private IInventory getInputInventory() throws LuaException { ForgeDirection inDir = playerInterface.inputSide; if (inDir == null) { throw new LuaException("Input Side has not yet been set."); } Location blockLoc = new Location(playerInterface.xCoord + inDir.offsetX, playerInterface.yCoord + inDir.offsetY, playerInterface.zCoord + inDir.offsetZ, playerInterface.getWorldObj()); Block block = playerInterface.getWorldObj().getBlock(blockLoc.getRoundedX(), blockLoc.getRoundedY(), blockLoc.getRoundedZ()); if (block instanceof BlockContainer) { return (IInventory) playerInterface.getWorldObj().getTileEntity(blockLoc.getRoundedX(), blockLoc.getRoundedY(), blockLoc.getRoundedZ()); } else { throw new LuaException("Invalid Input Inventory."); } }
private boolean isInventoryOnSide(ForgeDirection dir) { if (!worldObj.isAirBlock(xCoord+dir.offsetX, yCoord+dir.offsetY, zCoord+dir.offsetZ)) { Block block = worldObj.getBlock(xCoord+dir.offsetX, yCoord+dir.offsetY, zCoord+dir.offsetZ); if (block instanceof BlockContainer || block instanceof IInventory) return true; if (block.hasTileEntity(worldObj.getBlockMetadata(xCoord+dir.offsetX, yCoord+dir.offsetY, zCoord+dir.offsetZ))) { return worldObj.getTileEntity(xCoord+dir.offsetX, yCoord+dir.offsetY, zCoord+dir.offsetZ) instanceof IInventory; } } return false; }
private IInventory getInventoryForSide(ForgeDirection dir) { if (!worldObj.isAirBlock(xCoord+dir.offsetX, yCoord+dir.offsetY, zCoord+dir.offsetZ)) { Block block = worldObj.getBlock(xCoord+dir.offsetX, yCoord+dir.offsetY, zCoord+dir.offsetZ); if (block instanceof IInventory) { return (IInventory) block; } if (block instanceof BlockContainer && block.hasTileEntity(worldObj.getBlockMetadata(xCoord+dir.offsetX, yCoord+dir.offsetY, zCoord+dir.offsetZ))) return (IInventory)worldObj.getTileEntity(xCoord+dir.offsetX, yCoord+dir.offsetY, zCoord+dir.offsetZ); } return null; }
@SubscribeEvent public void onPlayerInteract(PlayerInteractEvent e) { if (CorruptionDataHelper.hasCorruptionEffectsForPlayer(e.entityPlayer, "blockTeleport") && e.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK && e.entityPlayer.worldObj.getBlock(e.x, e.y, e.z) instanceof BlockContainer) { if (this.teleportBlockRandomly(e.x, e.y, e.z, e.entityPlayer.worldObj, e.entityPlayer)) { e.setResult(Event.Result.DENY); Corruption.blockTeleportCorruption.blocksBroken.add(e.entityPlayer.getCommandSenderName()); } } }
public TileEntity getTileEntity(IBlockAccess blockAccess, int x, int y, int z) { TileEntity tile = (TileEntity) blockAccess.getTileEntity(x, y, z); BlockContainer block = (BlockContainer) blockAccess.getBlock(x, y, z); if(tile == null || (block instanceof BlockExtendedContainer && !tile.getClass().isAssignableFrom(((BlockExtendedContainer) block).getTileEntityClass()))) { tile = block.createNewTileEntity(null, blockAccess.getBlockMetadata(x, y, z)); if(blockAccess instanceof World) { tile = block.createNewTileEntity(((World) blockAccess), blockAccess.getBlockMetadata(x, y, z)); ((World) blockAccess).setTileEntity(x, y, z, tile); } } return tile; }
public static void init() { GameRegistry.registerBlock(BlockCoffeePlant, Names.COFFEE_PLANT); GameRegistry.registerBlock(BlockLiquidCoffee, Names.LIQUID_COFFEE_BLOCK); GameRegistry.registerBlock(BlockCoffeeMaker, Names.COFFEE_MAKER); if (Loader.isModLoaded("ThermalFoundation")) { BlockContainer BlockCoffeeGenerator = new BlockCoffeeGenerator(); GameRegistry.registerBlock(BlockCoffeeGenerator, Names.COFFEE_GENERATOR); } }
public boolean testBlock(World world, BlockPos pos) { final IBlockState blockState = world.getBlockState(pos); final Block block = blockState.getBlock(); if (blockState.getBlock().isAir(blockState, world, pos)) return false; if (block instanceof BlockContainer) { TileEntity te = world.getTileEntity(pos); return (te != null)? tileEntityWhitelist.check(te) : false; } return blockWhitelist.check(new BlockCoords(blockState, world, pos)); }
/** * Returns object containing all information about how many input and output slots and their intended functions for this machine. */ public BlockContainer getBlockContainer() { return blockContainer; }
/**public String getTextureFile() { return CommonProxy.ITEMS_PNG; }**/ public ItemStack onItemRightClick(ItemStack myStack, World myWorld, EntityPlayer myPlayer) { if (!myWorld.isRemote) { if(!myPlayer.isSneaking()) { openGui(0, myPlayer, (int)myPlayer.posX, (int)myPlayer.posY, (int)myPlayer.posZ); //myPlayer.openGui(AdvancedBackpackMod.instance, 0, myPlayer.worldObj, (int)myPlayer.posX, (int)myPlayer.posY, (int)myPlayer.posZ); } else { //System.out.println("player is sneaking, use shared inventory mode for backpackbase"); MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(myWorld, myPlayer, true); if (movingobjectposition != null) { if (movingobjectposition.typeOfHit == EnumMovingObjectType.TILE) { int i = movingobjectposition.blockX; int j = movingobjectposition.blockY; int k = movingobjectposition.blockZ; if (myWorld.getBlockTileEntity(i, j, k) != null) { if (BlockContainer.class.isAssignableFrom(((Object)myWorld.getBlockTileEntity(i, j, k).getBlockType()).getClass())) { //System.out.println("this is a subclass of BlockContainer"); try { IInventory testInv = (IInventory) myWorld.getBlockTileEntity(i, j, k); //System.out.println(Block.blocksList[myWorld.getBlockId(i, j, k)].getUnlocalizedName()); //System.out.println(Block.blocksList[myWorld.getBlockId(i, j, k)].getLocalizedName()); //System.out.println("inventory size = " + testInv.getSizeInventory()); if (checkContainer(Block.blocksList[myWorld.getBlockId(i, j, k)].getUnlocalizedName())) { openGui(1, myPlayer, i, j, k); } } catch(ClassCastException e) { //System.out.println("has no IInventory"); //System.out.println(myWorld.getBlockTileEntity(i, j, k)); //System.out.println(myWorld.getBlockTileEntity(i, j, k).getBlockType()); //System.out.println(myWorld.getBlockTileEntity(i, j, k).getBlockType().getClass()); } if (BlockEnderChest.class.isAssignableFrom(((Object)myWorld.getBlockTileEntity(i, j, k).getBlockType()).getClass())) { //System.out.println("this is a vanilla enderchest"); openGui(2, myPlayer, i, j, k); } } } else { //System.out.println("has no tileentity"); } } } } } return myStack; }