protected void findLeaves(BlockPos pos, World world) { int offs = 4; for (int x = -offs; x <= offs; x++) { for (int y = -offs; y <= offs; y++) { for (int z = -offs; z <= offs; z++) { BlockPos p = pos.add(x, y, z); IBlockState st = world.getBlockState(p); if (st.getBlock().isLeaves(st, world, p)) { if (st.getValue(BlockLeaves.DECAYABLE)) { leavesToTick.put(p, 500); } } } } } }
public boolean isSmartLeaves() { if (this.smartLeaves == -1) { if (Config.isTreesSmart() && this.blockState.getBlock() instanceof BlockLeaves) { this.smartLeaves = 1; } else { this.smartLeaves = 0; } } return this.smartLeaves == 1; }
boolean nearSurface(World world, int posX, int posY, int posZ) { if (!world.isAirBlock(new BlockPos(posX, posY, posZ))) return false; int tries = 5; while (tries-- > 0) { Block block = world.getBlockState(new BlockPos(posX, --posY, posZ)).getBlock(); if (block == Blocks.snow || block == Blocks.ice || block instanceof BlockTopSoil || block instanceof BlockSubSoil || block instanceof BlockLeaves || block instanceof BlockTallGrassVC || BlocksVC.rock.containsBlock(block) || BlocksVC.gravel.containsBlock(block) || BlocksVC.sand.containsBlock(block) ) { return true; } } return false; }
@Override public void onUpdate(){ oldMotionX = motionX; oldMotionY = motionY; oldMotionZ = motionZ; super.onUpdate(); //blowOtherEntities(); motionX *= 0.95D;// equal to the potion effect friction. 0.95F motionY *= 0.95D; motionZ *= 0.95D; if(motionX * motionX + motionY * motionY + motionZ * motionZ < 0.1D) { setDead(); } if(!worldObj.isRemote) { int blockX = (int)Math.floor(posX); int blockY = (int)Math.floor(posY); int blockZ = (int)Math.floor(posZ); for(int i = 0; i < 7; i++) { // to 7 so the middle block will also trigger (with UNKNOWN direction) Block block = worldObj.getBlock(blockX + ForgeDirection.getOrientation(i).offsetX, blockY + ForgeDirection.getOrientation(i).offsetY, blockZ + ForgeDirection.getOrientation(i).offsetZ); if(block instanceof IPlantable || block instanceof BlockLeaves) { worldObj.func_147480_a(blockX + ForgeDirection.getOrientation(i).offsetX, blockY + ForgeDirection.getOrientation(i).offsetY, blockZ + ForgeDirection.getOrientation(i).offsetZ, true); } } } }
private boolean tryCutPlants(BlockPos pos) { Block block = world.getBlockState(pos).getBlock(); if (block instanceof IPlantable || block instanceof BlockLeaves) { world.destroyBlock(pos, true); return true; } return false; }
@Override protected void onImpact(RayTraceResult objectPosition) { if (objectPosition.entityHit != null) { Entity entity = objectPosition.entityHit; entity.motionX += motionX; entity.motionY += motionY; entity.motionZ += motionZ; if (!entity.world.isRemote && entity instanceof IShearable) { IShearable shearable = (IShearable) entity; BlockPos pos = new BlockPos(posX, posY, posZ); if (shearable.isShearable(ItemStack.EMPTY, world, pos)) { List<ItemStack> drops = shearable.onSheared(ItemStack.EMPTY, world, pos, 0); for (ItemStack stack : drops) { PneumaticCraftUtils.dropItemOnGround(stack, world, entity.posX, entity.posY, entity.posZ); } } } } else { Block block = world.getBlockState(objectPosition.getBlockPos()).getBlock(); if (block instanceof IPlantable || block instanceof BlockLeaves) { motionX = oldMotionX; motionY = oldMotionY; motionZ = oldMotionZ; } else { setDead(); } } hitCounter++; if (hitCounter > 20) setDead(); }
/** * Generates the leaves surrounding an individual entry in the leafNodes list. */ void generateLeafNode(BlockPos pos) { for (int i = 0; i < this.leafDistanceLimit; ++i) { this.func_181631_a(pos.up(i), this.leafSize(i), Blocks.leaves.getDefaultState().withProperty(BlockLeaves.CHECK_DECAY, Boolean.valueOf(false))); } }
public ItemLeaves(BlockLeaves block) { super(block); this.leaves = block; this.setMaxDamage(0); this.setHasSubtypes(true); }
@Nullable @Override public EntityItem entityDropItem(ItemStack stack, float offsetY) { IBlockState state = getBlock(); if (state != null && state.getBlock() instanceof BlockLeaves) { BlockLeaves leaves = (BlockLeaves) state.getBlock(); for (ItemStack item : leaves.getDrops(worldObj, getPosition(), state, 0)) { super.entityDropItem(item, offsetY); } return null; } return super.entityDropItem(stack, offsetY); }
@Nullable @Override public EntityItem entityDropItem(ItemStack stack, float offsetY) { IBlockState state = getBlock(); if (state != null && state.getBlock() instanceof BlockLeaves) { BlockLeaves leaves = (BlockLeaves) state.getBlock(); for (ItemStack item : leaves.getDrops(world, getPosition(), state, 0)) { super.entityDropItem(item, offsetY); } return null; } return super.entityDropItem(stack, offsetY); }
@SubscribeEvent @SideOnly(Side.CLIENT) public static void registerModels(final ModelRegistryEvent event) { for (final Item item : ITEMS) { ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(item.getRegistryName(), "inventory")); } for (final Block block : BLOCKS) { if (block instanceof BlockLeaves) { ModelLoader.setCustomStateMapper(block, new StateMap.Builder().ignore(BlockLeaves.CHECK_DECAY, BlockLeaves.DECAYABLE).build()); } } }
/** * Generates the leaves surrounding an individual entry in the leafNodes list. */ void generateLeafNode(BlockPos pos) { for (int i = 0; i < this.leafDistanceLimit; ++i) { this.crosSection(pos.up(i), this.leafSize(i), Blocks.LEAVES.getDefaultState().withProperty(BlockLeaves.CHECK_DECAY, Boolean.valueOf(false))); } }
/** * Generates the leaves surrounding an individual entry in the leafNodes list. */ void generateLeafNode(BlockPos pos) { for (int i = 0; i < this.leafDistanceLimit; ++i) { this.crosSection(pos.up(i), this.leafSize(i), leaves.withProperty(BlockLeaves.CHECK_DECAY, Boolean.valueOf(false))); } }
public EnderTreeNormalGen(boolean notify) { super(notify); this.minTreeHeight = 4; this.metaWood = Blocks.LOG.getDefaultState().withProperty(BlockOldLog.VARIANT, BlockPlanks.EnumType.OAK); this.oakLeaves = Blocks.LEAVES.getDefaultState().withProperty(BlockOldLeaf.VARIANT, BlockPlanks.EnumType.OAK).withProperty(BlockLeaves.CHECK_DECAY, false); this.enderLeaves = IWTechBlocks.BLOCK_ENDER_LEAVES.getDefaultState(); }
private void seedMap() { // Iterate through the blockmap looking for known pattern types. // Though they probably should all be registered with Forge // dictionary it's not a requirement. final Iterator<Block> itr = Block.REGISTRY.iterator(); while (itr.hasNext()) { final Block block = itr.next(); final String blockName = MCHelper.nameOf(block); if (block instanceof BlockCrops) { final BlockCrops crop = (BlockCrops) block; if (crop.getMaxAge() == 3) { this.registerBlocks("#beets", blockName); } else if (blockName.equals("minecraft:wheat")) { this.registerBlocks("#wheat", blockName); } else if (crop.getMaxAge() == 7) { this.registerBlocks("#crop", blockName); } } else if (block instanceof BlockSapling) { this.registerBlocks("#sapling", blockName); } else if (block instanceof BlockReed) { this.registerBlocks("#reed", blockName); } else if (block instanceof BlockFence) { this.registerBlocks("#fence", blockName); } else if (block instanceof BlockFlower || block instanceof BlockMushroom) { this.registerBlocks("NOT_EMITTER", blockName); } else if (block instanceof BlockLog || block instanceof BlockPlanks) { this.registerBlocks("wood", blockName); } else if (block instanceof BlockDoor) { this.registerBlocks("bluntwood", blockName); } else if (block instanceof BlockLeaves) { this.registerBlocks("leaves", blockName); } else if (block instanceof BlockOre) { this.registerBlocks("ore", blockName); } else if (block instanceof BlockIce) { this.registerBlocks("ice", blockName); } } }
@Override protected boolean canFallThrough(BlockPos pos) { IBlockState state = this.world.getBlockState(pos); Block block = state.getBlock(); return block.isReplaceable(this.world, pos) || block instanceof BlockLeaves; }
@SubscribeEvent public void blockDestroyed(HarvestDropsEvent event) { int rand = event.world.rand.nextInt(4); if(event.harvester != null) { if(event.block instanceof BlockLeaves && rand == 0) { ArrayList<ItemStack> drops = event.drops; drops.add(new ItemStack(ModItems.twig)); } } }
boolean canPlace(IBlockState blockstate, IBlockState blockatpos) { // Logs override any leaves // branchy leaves override leaves return blockatpos.getBlock() == Blocks.air || blockatpos.getBlock() == Blocks.vine || blockatpos.getBlock() == Blocks.tallgrass || (blockstate == log && (blockatpos.getBlock() instanceof BlockLeaves)) ; }
@Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) { boolean hasLeaves = state.getValue(HAS_LEAVES); ItemStack stack = playerIn.getHeldItem(hand); if (stack != null && stack.stackSize > 0 && stack.getItem().getToolClasses(stack).contains("sword")) { if (hasLeaves) { worldIn.setBlockState(pos, state.withProperty(HAS_LEAVES, false)); // TODO: pretend break leaf block // BlockLeaves.dropBlockAsItem } } if (canHaveLeaves(worldIn, pos, state)) { if (stack != null && stack.stackSize > 0 && stack.getItem() instanceof ItemBlock) { ItemBlock ib = (ItemBlock) stack.getItem(); if (ib.getBlock() instanceof BlockLeaves && !stack.hasTagCompound()) { stack.stackSize--; worldIn.setBlockState(pos, state.withProperty(HAS_LEAVES, true)); return true; } } } return false; }
/** * Recursively adds neighboring log blocks from the current position, up to the maximum * girth, height, and block count provided in the configuration. * @param block * @param world * @param startPos * @param currentPos * @param player * @param currentTree * @return Whether or not any leaf blocks were found next to the tree. */ public static boolean addNeighbors(Block block, World world, BlockPos startPos, BlockPos currentPos, EntityPlayer player, HashSet<BlockPos> currentTree) { boolean hasLeaves = false; for (int z = currentPos.getZ() - 1; z <= currentPos.getZ() + 1; z++) { for (int x = currentPos.getX() - 1; x <= currentPos.getX() + 1; x++) { for (int y = 0; y <= 1; y++) { BlockPos newPos = new BlockPos(x, currentPos.getY() + y, z); if (currentTree.contains(newPos)) continue; IBlockState upState = world.getBlockState(newPos); if (upState == null) continue; if (upState.getBlock() instanceof BlockLeaves) { hasLeaves = true; } if (upState.getBlock() == block) { if (Math.abs(x - startPos.getX()) <= maxGirth && Math.abs(z - startPos.getZ()) <= maxGirth && y - startPos.getY() <= maxHeight && currentTree.size() <= maxBlocks) { currentTree.add(newPos); if (addNeighbors(block, world, startPos, newPos, player, currentTree)) hasLeaves = true; } } } } } return hasLeaves; }
public ItemLeaves(BlockLeaves p_i45344_1_) { super(p_i45344_1_); this.field_150940_b = p_i45344_1_; this.setMaxDamage(0); this.setHasSubtypes(true); }
public int getLeavesAndWood(IBlockAccess world, BlockPos pos, ArrayList<BlockPos> poses, ArrayList<BlockPos> tried, int triesLeft) { tried.add(pos); for(int i = -5; i <= 5; i++) { for(int k = -5; k <= 5; k++) { BlockPos newPos = pos.add(i, 0, k); if(BlockLog.class.isInstance(world.getBlockState(newPos).getBlock())) { if(!poses.contains(newPos)) { poses.add(newPos); } if(!tried.contains(newPos)) { triesLeft = getLeavesAndWood(world, newPos, poses, tried, triesLeft); } } else if(BlockLeaves.class.isInstance(world.getBlockState(newPos).getBlock())) { if(!poses.contains(newPos)) { poses.add(newPos); } } } } return triesLeft - 1; }
/** * Returns the unlocalized name of this item. This version accepts an ItemStack so different stacks can have * different names based on their damage or NBT. */ public String getUnlocalizedName(ItemStack par1ItemStack) { int i = par1ItemStack.getItemDamage(); if (i < 0 || i >= BlockLeaves.LEAF_TYPES.length) { i = 0; } return super.getUnlocalizedName() + "." + BlockLeaves.LEAF_TYPES[i]; }
private void placeHelperBlock(EntityPlayer player) { BlockPos pos = PositionUtils.getPositionInfrontOfEntity(player); //player.worldObj.setBlockState(pos, Blocks.RED_MUSHROOM_BLOCK.getDefaultState(), 3); player.getEntityWorld().setBlockState(pos, Blocks.LEAVES.getDefaultState() .withProperty(BlockOldLeaf.VARIANT, BlockPlanks.EnumType.SPRUCE) .withProperty(BlockLeaves.CHECK_DECAY, false) .withProperty(BlockLeaves.DECAYABLE, true), 3); }
@SuppressWarnings("ObjectAllocationInLoop") @Method(modid = MOD_ID) private static void registerLeaves() { reportProgress("leaves"); for (final BlockLeaves leavesBlock : ModBlocks.leavesBlocks()) registerHarvestable(new MFRLeaves(leavesBlock)); }
/** Creates the list of which blocks correspond to different parts of trees */ public static void initTreePartClassification() { for (int i = 0; i < 4096; i++) { treeCategory[i] = TreeCategory.NOT_TREE; Block b = Block.blocksList[i]; if (i == 0 || b == null) continue; if (b instanceof BlockLog) treeCategory[i] = TreeCategory.TRUNK_PART; if (b instanceof BlockLeaves || b instanceof BlockFFLeaves) treeCategory[i] = TreeCategory.LEAF_PART; } int rubWood = Util.findBlockIdFromName("blockRubWood"); if (rubWood != 0) treeCategory[rubWood] = TreeCategory.TRUNK_PART; }
public BlockFFLeaves(int id, BlockLeaves leaves) { super(id); superSpecial = leaves; FysiksFun.logger.log(Level.INFO, "Replacing leaves with block id " + id); setHardness(leaves.blockHardness); setStepSound(leaves.stepSound); String unlocalizedName = leaves.getUnlocalizedName(); String[] parts = unlocalizedName.split("\\."); setUnlocalizedName(parts[1]); }