-
Bug
-
Resolution: Unresolved
-
None
-
1.16.5, 21w14a, 21w15a, 21w16a, 21w17a, 21w18a, 21w19a, 21w20a, 1.17 Pre-release 1, 1.17 Pre-release 3, 1.17 Pre-release 4, 1.17 Pre-release 5, 1.17 Release Candidate 1, 1.17 Release Candidate 2, 1.17, 1.17.1 Pre-release 1, 1.17.1 Pre-release 2, 1.17.1 Release Candidate 1, 1.17.1, 21w37a, 21w43a, 1.18, 1.18.1, 22w05a, 22w06a, 1.18.2, 1.19, 1.19.2, 22w43a, 1.19.3, 1.19.4, 1.20.1, 1.20.4, 23w51b, 24w20a, 1.21, 1.21.3, 1.21.4
-
Community Consensus
-
Adventure
-
Items, Player
The Bug:
You can fill composters in adventure mode.
Steps to Reproduce:
- Place down a composter and obtain some seeds.
- Switch into adventure mode and attempt to fill the composter.
- Take note as to whether or not you can fill composters in adventure mode.
Observed Behavior:
You can fill composters.
Expected Behavior:
You would not be able to fill composters.
Code Analysis:
Code analysis by Avoma can be found below.
The following is based on a decompiled version of Minecraft 1.19.2 using MCP-Reborn.
public class ComposterBlock extends Block implements WorldlyContainerHolder { ... public InteractionResult use(BlockState blockState, Level level, BlockPos blockPos, Player player, InteractionHand interactionHand, BlockHitResult blockHitResult) { int i = blockState.getValue(LEVEL); ItemStack itemstack = player.getItemInHand(interactionHand); if (i < 8 && COMPOSTABLES.containsKey(itemstack.getItem())) { if (i < 7 && !level.isClientSide) { BlockState blockstate = addItem(blockState, level, blockPos, itemstack); level.levelEvent(1500, blockPos, blockState != blockstate ? 1 : 0); player.awardStat(Stats.ITEM_USED.get(itemstack.getItem())); ...
If we look at the above class, we can see that there is only one necessary check that's carried out before allowing players to fill composters. This check is to see if the "level" block state of the composter is below a value of "8", and if the player is holding an item that can be composted. If this requirement is met along with the other criteria within this method, composters can be filled. The game doesn't check to see what abilities the player possesses (what game mode they are in) before allowing them to fill composters, therefore resulting in this problem occurring.
Fix:
Simply altering the appropriate existing "if" statement within this piece of code to check what abilities the player possesses before allowing them to fill composters will resolve this problem.
if (i < 8 && COMPOSTABLES.containsKey(itemstack.getItem()))
if (i < 8 && COMPOSTABLES.containsKey(itemstack.getItem()) && player.getAbilities().mayBuild)