Skip to content

Commit

Permalink
Fix minor issues with the berry puzzle:
Browse files Browse the repository at this point in the history
- Berries can now no longer be placed directly into a full 3x3
- Berries now may lower their efficiencies on a block update
  • Loading branch information
bruberu committed Oct 20, 2023
1 parent 1ee028b commit 933fafb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/main/java/gregtechfoodoption/GTFOEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/gregtechfoodoption/block/GTFOBerryBush.java
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public ActionResult<ItemStack> 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)) {
Expand Down

0 comments on commit 933fafb

Please sign in to comment.