@Override public boolean canPlaceBlockAt(World world, BlockPos pos) { return this.greenhouseTier == 0 && super.canPlaceBlockAt(world, pos); }
@Override public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) { return super.getDrops(world, pos, state, fortune - 1); }
@Override public int quantityDropped(Random random) { return super.quantityDropped(random) + 1; }
private static void addPamCrops() { if (!Loader.isModLoaded("harvestcraft")) return; try { Class<?> pamRegistry = Class.forName("com.pam.harvestcraft.blocks.CropRegistry"); Field names = pamRegistry.getDeclaredField("cropNames"); Method getCrop = pamRegistry.getMethod("getCrop", String.class); for (String name : (String[]) names.get(null)) { BlockCrops crop = (BlockCrops) getCrop.invoke(null, name); HarvestRegistry.registerStandardCrop(crop, crop.getMaxAge()); } } catch (ClassNotFoundException e) { BMLog.DEFAULT.error("HarvestCraft integration cancelled; unable to find registry class"); } catch (NoSuchMethodException | NoSuchFieldException e) { BMLog.DEFAULT.error("HarvestCraft integration cancelled; unable to find crop name mapper"); } catch (IllegalAccessException | InvocationTargetException e) { BMLog.DEFAULT.error("HarvestCraft integration cancelled; crop name lookup broke"); } } }
@Override protected boolean canEatBlock(IBlockState state) { Block block = state.getBlock(); if (block == null) return false; else if (block == Blocks.TALLGRASS || state == ModBlocks.SMALL_PLANT.getDefaultState().withProperty(BlockSmallPlant.PLANT_TYPE, BlockSmallPlant.EnumSmallPlantType.FERN) || block instanceof BlockCrops && ((BlockCrops) block).isMaxAge(state)) return true; return false; }
@Override public void grow(World world, BlockPos pos, IBlockState state) { if (state.getValue(HALF) == HopsHalf.UP) { IBlockState stateDrown = world.getBlockState(pos.down()); Block block = stateDrown.getBlock(); if (block instanceof BlockHops) { ((BlockHops) block).grow(world, pos.down(), stateDrown); } return; } super.grow(world, pos, state); }
@Override public boolean canBlockStay(World worldIn, BlockPos pos, IBlockState state) { if (state.getValue(HALF) == HopsHalf.UP) { return worldIn.getBlockState(pos.down()).getBlock() == this; } else { IBlockState iblockstate = worldIn.getBlockState(pos.up()); return iblockstate.getBlock() == this && super.canBlockStay(worldIn, pos, iblockstate); } }
resetState = mcblock.getDefaultState().withProperty(BlockBeetroot.BEETROOT_AGE, 0); } else if (mcblock instanceof BlockCrops) { meta = ((BlockCrops) mcblock).getMaxAge(); resetMeta = 0; grownState = mcblock.getDefaultState().withProperty(BlockCrops.AGE, ((BlockCrops) mcblock).getMaxAge()); resetState = mcblock.getDefaultState().withProperty(BlockCrops.AGE, 0); } else if (mcblock instanceof BlockNetherWart) {
@Override public FarmerResult tryHarvestPlant(World world, BlockPos pos, IFarmer farmer) { int use = 250; if (farmer.getEnergy() >= use) { IBlockState state = world.getBlockState(pos); Block block = state.getBlock(); if (block instanceof BlockCrops) { if (((BlockCrops) block).isMaxAge(state)) { return doFarmerStuff(state, world, pos, farmer); } } else if ((BlockCrops.AGE).equals(block.getBlockState().getProperty("age"))) { if (state.getValue(BlockCrops.AGE) >= 7 && !(block instanceof BlockStem)) return doFarmerStuff(state, world, pos, farmer); } } return FarmerResult.FAIL; }
addMaturityTooltip(currenttip, accessor.getMetadata() / (float) ((BlockCrops) block).getMaxAge()); else if (block == melonStem || block == pumpkinStem) addMaturityTooltip(currenttip, accessor.getMetadata() / 7F);
@Override public int quantityDropped(IBlockState state, int fortune, Random random){ return this.getMetaFromState(state) >= 7 ? random.nextInt(this.addDropAmount)+this.minDropAmount : super.quantityDropped(state, fortune, random); }
public boolean canPlaceBlockAt(World worldIn, BlockPos pos) { return super.canPlaceBlockAt(worldIn, pos) && worldIn.isAirBlock(pos.up()); }
private static void harvestCrops(IBlockState blockState, EntityPlayer player, World world, BlockPos blockPos) { final BlockCrops crops = (BlockCrops) blockState.getBlock(); final ItemStack stack = player.getHeldItemMainhand(); final int fortune = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, stack); final List<ItemStack> drops = crops.getDrops(world, blockPos, blockState, fortune); // This removes exactly one seed from drops in order to make this more fair compared to vanilla // as one seed stays planted. final Item seedItem = crops.getItemDropped(blockState, world.rand, fortune); if(seedItem != null) for(Iterator<ItemStack> iterator = drops.iterator(); iterator.hasNext();) { final ItemStack drop = iterator.next(); // Remove a seed, then break. if(!(drop.getItem() == seedItem) || crops instanceof BlockCarrot || crops instanceof BlockPotato) { iterator.remove(); break; } } ForgeEventFactory.fireBlockHarvesting(drops, world, blockPos, blockState, fortune, 1f, false, player); // Reset growth level world.setBlockState(blockPos, crops.withAge(0)); for(ItemStack drop : drops) { dropItem(drop, world, blockPos); } }
int j = ((BlockCrops) this.cropTypeA).getMaxAge(); int k = j / 3; this.setBlockState(worldIn, this.cropTypeA.getStateFromMeta(MathHelper.getInt(randomIn, k, j)), 1, 1, i, structureBoundingBoxIn); this.setBlockState(worldIn, this.cropTypeA.getStateFromMeta(MathHelper.getInt(randomIn, k, j)), 2, 1, i, structureBoundingBoxIn); int l = ((BlockCrops) this.cropTypeB).getMaxAge(); int i1 = l / 3; this.setBlockState(worldIn, this.cropTypeB.getStateFromMeta(MathHelper.getInt(randomIn, i1, l)), 4, 1, i, structureBoundingBoxIn); this.setBlockState(worldIn, this.cropTypeB.getStateFromMeta(MathHelper.getInt(randomIn, i1, l)), 5, 1, i, structureBoundingBoxIn); int j1 = ((BlockCrops) this.cropTypeC).getMaxAge(); int k1 = j1 / 3; this.setBlockState(worldIn, this.cropTypeC.getStateFromMeta(MathHelper.getInt(randomIn, k1, j1)), 7, 1, i, structureBoundingBoxIn); this.setBlockState(worldIn, this.cropTypeC.getStateFromMeta(MathHelper.getInt(randomIn, k1, j1)), 8, 1, i, structureBoundingBoxIn); int l1 = ((BlockCrops) this.cropTypeD).getMaxAge(); int i2 = l1 / 3; this.setBlockState(worldIn, this.cropTypeD.getStateFromMeta(MathHelper.getInt(randomIn, i2, l1)), 10, 1, i, structureBoundingBoxIn);