@Override public void onArmorTick(World world, EntityPlayer player, @Nonnull ItemStack stack) { super.onArmorTick(world, player, stack); BlockPos pos = player.getPosition(); Block playerStandingOnBlock = player.world.getBlockState(pos.down()).getBlock(); if (player.onGround && player.isSneaking()) { if (playerStandingOnBlock instanceof BlockFarmland) { player.setPosition(pos.getX(), pos.getY() + 0.5D, pos.getZ()); playerStandingOnBlock.onFallenUpon(world, pos.down(), player, 1.0F); if (world.rand.nextInt(100) <= 50) { stack.damageItem(1, player); } } } }
@Override public Material getMaterial() { if (callerProvider.getCallerClass() == BlockFarmland.class) return Material.water; return super.getMaterial(); }
@Override public List<String> getWailaBody(ItemStack itemStack, List<String> currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config) { Block block = accessor.getBlock(); if (config.getConfig("general.showcrop")) { if (block instanceof BlockDoubleCrop) { World world = accessor.getWorld(); BlockPos pos = accessor.getPosition(); IBlockState stateUp = world.getBlockState(pos.up()); IBlockState stateDown = world.getBlockState(pos.down()); float growthValue = (accessor.getMetadata() / 14.0F) * 100.0F; if (growthValue < 100.0 && accessor.getMetadata() != 7 && accessor.getMetadata() != 6) { currenttip.add(String.format("%s : %.0f %%", LangUtil.translateG("hud.msg.growth"), growthValue)); } else if (growthValue < 100.0 && accessor.getMetadata() == 6 && stateUp.getBlock() instanceof BlockAir) { currenttip.add(String.format("%s : %.0f %%", LangUtil.translateG("hud.msg.growth"), growthValue)); } else if (accessor.getMetadata() == 7 || accessor.getMetadata() == 14) { currenttip.add(String.format("%s : %s", LangUtil.translateG("hud.msg.growth"), LangUtil.translateG("hud.msg.mature"))); } if (stateUp.getBlock() instanceof BlockDoubleCrop && stateDown.getBlock() instanceof BlockFarmland) { float growthValueTop = (block.getMetaFromState(stateUp) / 14.0F) * 100.0F; if (growthValueTop < 100.0 && accessor.getMetadata() == 6) { currenttip.add(String.format("%s : %.0f %%", LangUtil.translateG("hud.msg.growth"), growthValueTop)); } } } } if (block instanceof BlockModCauldron) { if (accessor.getMetadata() == 12) { currenttip.add("Cheese ripening in progress"); } } return currenttip; }
/** * 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; } }
@Override public boolean canAdvance(World world, BlockPos pos, IBlockState state) { return world.getBlockState(pos.down()).getBlock() == Blocks.FARMLAND && ((BlockFarmland)world.getBlockState(pos.down()).getBlock()).getMetaFromState(world.getBlockState(pos.down())) == 0; }
@SuppressWarnings("unused") public static boolean fireEvent(Entity entity, BlockFarmland block, int x, int y, int z) { return MinecraftForge.EVENT_BUS.post(new BlockTrampleEvent(entity, x, y, z, block, entity.worldObj.getBlockMetadata(x, y, z))); }