net.minecraft.block.IGrowable Java Examples
The following examples show how to use
net.minecraft.block.IGrowable.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CompostRegistry.java From GardenCollection with MIT License | 6 votes |
private void init () { registerCompostMaterial(new ItemStack(Blocks.melon_block), defaultMaterial); registerCompostMaterial(new ItemStack(Blocks.pumpkin), defaultMaterial); registerCompostMaterial(new ItemStack(Blocks.hay_block), defaultMaterial); registerCompostMaterial(new ItemStack(Items.string), new StandardCompostMaterial(100, 0.0625f)); registerCompostMaterial(new ItemStack(Items.wheat), new StandardCompostMaterial(100, 0.125f)); registerCompostMaterial(new ItemStack(Items.reeds), new StandardCompostMaterial(150, 0.125f)); registerCompostMaterial(new ItemStack(Items.feather), new StandardCompostMaterial(50, 0.0625f)); registerCompostMaterial(new ItemStack(Items.rotten_flesh), new StandardCompostMaterial(150, 0.125f)); registerCompostMaterial(new ItemStack(Items.leather), new StandardCompostMaterial(150, 0.125f)); registerCompostMaterial("treeWood", new StandardCompostMaterial(300, 0.25f)); registerCompostMaterial("logWood", new StandardCompostMaterial(300, 0.25f)); registerCompostMaterial("treeLeaves", defaultMaterial); registerCompostMaterial("treeSapling", defaultMaterial); registerCompostMaterial("stickWood", defaultMaterial); registerCompostMaterial(IPlantable.class, defaultMaterial); registerCompostMaterial(IGrowable.class, defaultMaterial); registerCompostMaterial(BlockLeavesBase.class, defaultMaterial); registerCompostMaterial(BlockVine.class, defaultMaterial); registerCompostMaterial(ItemFood.class, defaultMaterial); }
Example #2
Source File: TileEntitySprinkler.java From AgriCraft with MIT License | 5 votes |
/** * This method will search through a vertical column of positions, starting from the top. It * will stop searching any lower once it hits anything other than air or plants. Any plant found * has an independant chance for a growth tick. That percentage is controlled by * AgriCraftConfig. Farmland also ends the search, but it first has its moisture set to max (7) * if it isn't already. The lowest position is special: a plant this far away is not helped. * Only farmland is currently. */ private void irrigateColumn(final int targetX, final int targetZ, final int highestY, final int lowestY) { for (int targetY = highestY; targetY >= lowestY; targetY -= 1) { BlockPos target = new BlockPos(targetX, targetY, targetZ); IBlockState state = this.getWorld().getBlockState(target); Block block = state.getBlock(); // Option A: Skip empty/air blocks. // TODO: Is there a way to use isSideSolid to ignore minor obstructions? (Farmland isn't solid.) if (block.isAir(state, this.getWorld(), target)) { continue; } // Option B: Give plants a chance to grow, and then continue onward to irrigate the farmland too. if ((block instanceof IPlantable || block instanceof IGrowable) && targetY != lowestY) { if (this.getRandom().nextInt(100) < AgriCraftConfig.sprinklerGrowthChance) { block.updateTick(this.getWorld(), target, state, this.getRandom()); } continue; } // Option C: Dry farmland gets set as moist. if (block instanceof BlockFarmland) { if (state.getValue(BlockFarmland.MOISTURE) < 7) { this.getWorld().setBlockState(target, state.withProperty(BlockFarmland.MOISTURE, 7), 2); } break; // Explicitly expresses the intent to stop. } // Option D: If it's none of the above, it blocks the sprinkler's irrigation. Stop. break; } }
Example #3
Source File: CropHandler.java From BetterChests with GNU Lesser General Public License v3.0 | 5 votes |
@Override public boolean handleHarvest(IBetterChest chest, IBlockState state, World world, BlockPos pos) { IGrowable growable = (IGrowable) state.getBlock(); if (!growable.canGrow(world, pos, state, chest.getWorldObj().isRemote)) { PlantHarvestHelper.breakBlockHandleDrop(world, pos, state, chest); return true; } return false; }
Example #4
Source File: PlantHelper.java From EmergingTechnology with MIT License | 4 votes |
public static boolean isPlantItem(Item item) { return item instanceof IPlantable || item instanceof IGrowable || isItemInOverride(item); }
Example #5
Source File: PlantHelper.java From EmergingTechnology with MIT License | 4 votes |
public static boolean isPlantBlock(Block block) { return block instanceof IPlantable || block instanceof IGrowable; }
Example #6
Source File: ModuleEffectThrive.java From Wizardry with GNU Lesser General Public License v3.0 | 4 votes |
@Override public boolean run(@NotNull World world, ModuleInstanceEffect instance, @Nonnull SpellData spell, @Nonnull SpellRing spellRing) { BlockPos targetPos = spell.getTargetPos(); Entity targetEntity = spell.getVictim(world); Entity caster = spell.getCaster(world); Vec3d pos = spell.getTarget(world); if (pos == null) return true; if (targetEntity instanceof EntityLivingBase) { double potency = spellRing.getAttributeValue(world, AttributeRegistry.POTENCY, spell) / 2; if (!spellRing.taxCaster(world, spell, true)) return false; ((EntityLivingBase) targetEntity).heal((float) potency); world.playSound(null, new BlockPos(pos), ModSounds.HEAL, SoundCategory.NEUTRAL, 1, 1); } if (targetPos != null) { BlockPos otherTargetPos = spell.getTargetPos().add(0, 1, 0); // beam missed crops and targets farmland if (world.getBlockState(targetPos).getBlock() instanceof IGrowable || world.getBlockState(otherTargetPos).getBlock() instanceof IGrowable) { if (!spellRing.taxCaster(world, spell, true)) return false; if (!(caster instanceof EntityPlayerMP) || BlockUtils.hasEditPermission(targetPos, (EntityPlayerMP) caster)) { ItemDye.applyBonemeal(new ItemStack(Items.DYE), world, targetPos); ItemDye.applyBonemeal(new ItemStack(Items.DYE), world, otherTargetPos); PacketThriveBlock ptb = new PacketThriveBlock(targetPos); PacketHandler.NETWORK.sendToAllAround(ptb, new NetworkRegistry.TargetPoint(world.provider.getDimension(), targetPos.getX(), targetPos.getY(), targetPos.getZ(), 100)); if (!world.isRemote) { world.playEvent(2005, targetPos, 0); world.playEvent(2005, otherTargetPos, 0); } } } else if (world.getBlockState(targetPos).getBlock() instanceof IPlantable || world.getBlockState(otherTargetPos).getBlock() instanceof IPlantable) { IBlockState state = world.getBlockState(targetPos); Block block = state.getBlock(); if (!spellRing.taxCaster(world, spell, true)) return false; if (caster == null || (caster instanceof EntityPlayer && BlockUtils.hasEditPermission(targetPos, (EntityPlayerMP) caster))) { while (world.getBlockState(targetPos.up()).getBlock() == block) { targetPos = targetPos.up(); state = world.getBlockState(targetPos); block = state.getBlock(); } world.immediateBlockTick(targetPos, state, RandUtil.random); world.playSound(null, new BlockPos(pos), ModSounds.HEAL, SoundCategory.NEUTRAL, 1, 1); } state = world.getBlockState(otherTargetPos); block = state.getBlock(); if (caster == null || (caster instanceof EntityPlayer && BlockUtils.hasEditPermission(otherTargetPos, (EntityPlayerMP) caster))) { while (world.getBlockState(otherTargetPos.up()).getBlock() == block) { otherTargetPos = otherTargetPos.up(); state = world.getBlockState(otherTargetPos); block = state.getBlock(); } world.immediateBlockTick(otherTargetPos, state, RandUtil.random); world.playSound(null, new BlockPos(pos), ModSounds.HEAL, SoundCategory.NEUTRAL, 1, 1); } } } return true; }
Example #7
Source File: DebugModeIGrowable.java From AgriCraft with MIT License | 4 votes |
@Override public void debugActionBlockClicked(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) { if (world.isRemote) { return; } // Start with the position of the block that was clicked on. '7' is gray. Btw, the chat font is not fixed width. :( StringBuilder outputRaw = new StringBuilder(String.format("`7%1$4d,%2$4d,%3$4d`r ", pos.getX(), pos.getY(), pos.getZ())); // Check if the clicked on block has the IGrowable interface. final IGrowable crop = WorldHelper.getBlock(world, pos, IGrowable.class).orElse(null); if (crop == null) { // If it does not, add a nicely formatted report, then skip onward. outputRaw.append(chatNotIG); } else { // Otherwise run the tests and record the results. IBlockState state = world.getBlockState(pos); outputRaw.append(crop.canGrow(world, pos, state, false) ? chatTrue : chatFalse); // canGrow outputRaw.append(crop.canUseBonemeal(world, world.rand, pos, state) ? chatTrue : chatFalse); // canUseBonemeal crop.grow(world, world.rand, pos, state); // grow // It's also helpful to also make clear what block was being tested. outputRaw.append("`3"); // '3' is dark aqua. outputRaw.append(crop.toString().replaceFirst("Block", "")); outputRaw.append("`r"); } // Ellipsis are added as a clue that there's more text. outputRaw.append(" `8[...]`r"); // '8' is dark gray. // Create a hover box with explanatory information. TextComponentString hoverComponent = new TextComponentString(MessageUtil.colorize(chatInfo)); HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverComponent); // Turn the output String into a chat message. TextComponentString outputComponent = new TextComponentString(MessageUtil.colorize(outputRaw.toString())); // Add the hover box to the chat message. outputComponent.getStyle().setHoverEvent(hoverEvent); // Now send the completed chat message. player.sendMessage(outputComponent); }
Example #8
Source File: BlockGardenFarmland.java From GardenCollection with MIT License | 4 votes |
@Override public void updateTick (World world, int x, int y, int z, Random random) { Block block = world.getBlock(x, y + 1, z); if (block instanceof IPlantable || block instanceof IGrowable) block.updateTick(world, x, y + 1, z, random); }
Example #9
Source File: CropHandler.java From BetterChests with GNU Lesser General Public License v3.0 | 4 votes |
@Override public boolean canHandleHarvest(IBlockState state, World world, BlockPos pos) { return state.getBlock() instanceof IGrowable; }
Example #10
Source File: PlasticFertilizer.java From PneumaticCraft with GNU General Public License v3.0 | 4 votes |
public PlasticFertilizer(Block block, FertilizerType type){ this.block = block; fertilizable = (IGrowable)block; validFertilizer = type; }