diff --git a/src/main/java/gregtechfoodoption/GTFOEventHandler.java b/src/main/java/gregtechfoodoption/GTFOEventHandler.java index 8b46e090..1b0e28ed 100644 --- a/src/main/java/gregtechfoodoption/GTFOEventHandler.java +++ b/src/main/java/gregtechfoodoption/GTFOEventHandler.java @@ -252,7 +252,7 @@ public static void onDrinkPotion(PotionEvent.PotionAddedEvent event) { public static void handleBerryGrowth(BlockEvent.CropGrowEvent.Post event) { if (event.getState().getBlock() instanceof GTFOBerryBush bush) { event.getWorld().setBlockState(event.getPos(), - bush.withEfficiency(event.getState(), bush.getEfficiency(event.getWorld(), event.getPos(), event.getState())), + bush.withEfficiency(event.getState(), bush.calcEfficiency(event.getWorld(), event.getPos())), 2); } } diff --git a/src/main/java/gregtechfoodoption/block/GTFOBerryBush.java b/src/main/java/gregtechfoodoption/block/GTFOBerryBush.java index 7f1db3f5..406583c2 100644 --- a/src/main/java/gregtechfoodoption/block/GTFOBerryBush.java +++ b/src/main/java/gregtechfoodoption/block/GTFOBerryBush.java @@ -81,10 +81,10 @@ public void grow(World worldIn, BlockPos pos, IBlockState state) { i = j; } - worldIn.setBlockState(pos, withEfficiency(this.withAge(i), getEfficiency(worldIn, pos, state)), 3); + worldIn.setBlockState(pos, withEfficiency(this.withAge(i), calcEfficiency(worldIn, pos)), 3); } - public int getEfficiency(World worldIn, BlockPos pos, IBlockState state) { + public int calcEfficiency(World worldIn, BlockPos pos) { int[] efficiencies = new int[EFFICIENCY_GTFO.getAllowedValues().stream().max(Integer::compare).get() + 1]; BlockPos.getAllInBox(pos.east().north(), pos.west().south()).forEach((blockpos) -> { if (!blockpos.equals(pos)) @@ -186,4 +186,14 @@ public IBlockState getStateFromMeta(int meta) { public int getMetaFromState(IBlockState state) { return this.getEfficiency(state) * 3 + this.getAge(state); } + + @Override + public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos) { + if (!(worldIn.getBlockState(fromPos).getBlock() instanceof GTFOBerryBush)) { + // We don't want crops transmuting to higher efficiencies. + int newEfficiency = Math.min(calcEfficiency(worldIn, pos), getEfficiency(state)); + worldIn.setBlockState(pos, state.withProperty(EFFICIENCY_GTFO, newEfficiency), 3); + } + super.neighborChanged(state, worldIn, pos, blockIn, fromPos); + } } diff --git a/src/main/java/gregtechfoodoption/item/GTFOBerrySeedBehaviour.java b/src/main/java/gregtechfoodoption/item/GTFOBerrySeedBehaviour.java index a6fb08b1..3ee2d9b2 100644 --- a/src/main/java/gregtechfoodoption/item/GTFOBerrySeedBehaviour.java +++ b/src/main/java/gregtechfoodoption/item/GTFOBerrySeedBehaviour.java @@ -43,7 +43,7 @@ public ActionResult onItemUse(EntityPlayer player, World world, Block private boolean isBlocked(World world, BlockPos pos, EntityPlayer player) { AtomicBoolean areAnyBlocked = new AtomicBoolean(false); BlockPos.getAllInBox(pos.up().east().north(), pos.up().west().south()).forEach((crop) -> { - if (world.getBlockState(crop).getBlock() instanceof GTFOBerryBush) { + if (crop.equals(pos.up()) || world.getBlockState(crop).getBlock() instanceof GTFOBerryBush) { AtomicBoolean isBlocked = new AtomicBoolean(true); BlockPos.getAllInBox(crop.east().north(), crop.west().south()).forEach((blockpos) -> { if (!blockpos.equals(pos.up()) && world.getBlockState(blockpos).getBlock().isAir(world.getBlockState(blockpos), world, blockpos)) {