The Bug
Affects both sweet berries and glow berries. This could potentially be intended, but it does change the sweet berry/glow berry block
Steps to Reproduce
Place down some cave vines and apply some bone meal to them.
Place down some sweet berry bushes and apply some bone meal to them.
Switch into adventure mode and attempt to harvest the berries from both of these blocks.
Take note as to whether or not sweet berries and glow berries can be harvested in adventure mode.
Observed Behavior
Sweet berries and glow berries can be harvested in adventure mode.
Expected Behavior
Sweet berries and glow berries would not be able to be harvested in adventure mode.
Code analysis
Code analysis by @unknown can be found in this comment.
Linked issues
is duplicated by 1
Attachments
Comments 16
I can confirm this behavior in 1.18.1.
Here's a code analysis along with a potential fix regarding this issue.
Code Analysis:
The following is based on a decompiled version of Minecraft 1.18.1 using MCP-Reborn.
net.minecraft.world.level.block.SweetBerryBushBlock.java
public class SweetBerryBushBlock extends BushBlock implements BonemealableBlock {
...
public InteractionResult use(BlockState $bs, Level $l, BlockPos $bp, Player $p, InteractionHand $ih, BlockHitResult $bhr) {
int i = $bs.getValue(AGE);
boolean flag = i == 3;
if (!flag && $p.getItemInHand($ih).is(Items.BONE_MEAL)) {
return InteractionResult.PASS;
} else if (i > 1) {
int j = 1 + $l.random.nextInt(2);
popResource($l, $bp, new ItemStack(Items.SWEET_BERRIES, j + (flag ? 1 : 0)));
$l.playSound((Player)null, $bp, SoundEvents.SWEET_BERRY_BUSH_PICK_BERRIES, SoundSource.BLOCKS, 1.0F, 0.8F + $l.random.nextFloat() * 0.4F);
$l.setBlock($bp, $bs.setValue(AGE, Integer.valueOf(1)), 2);
return InteractionResult.sidedSuccess($l.isClientSide);
} else {
return super.use($bs, $l, $bp, $p, $ih, $bhr);
}
}
...
If we look at the above class, we can see that no checks are carried out to see what abilities the player possesses when harvesting berries from sweet berry bushes. The only check that is in place is to see if the age of the sweet berry bush is greater than 1. This is evident through the following line of code:
else if (i > 1)
Potential Fix:
Simply adding a line of code that checks what abilities the player possesses before harvesting berries from sweet berry bushes, should resolve this problem. The following line of code could be used in order to fix this:
!$p.getAbilities().mayBuild
Can confirm