Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-222682

You can fill composters in adventure mode

XMLWordPrintable

    • Icon: Bug 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
    • Community Consensus
    • Adventure
    • Items, Player

      The Bug:

      You can fill composters in adventure mode.

      Steps to Reproduce:

      1. Place down a composter and obtain some seeds.
      2. Switch into adventure mode and attempt to fill the composter.
      3. 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.

      net.minecraft.world.level.block.ComposterBlock.java
      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.

      Current "if" statement:
      if (i < 8 && COMPOSTABLES.containsKey(itemstack.getItem()))
      Fixed "if" statement:
      if (i < 8 && COMPOSTABLES.containsKey(itemstack.getItem()) && player.getAbilities().mayBuild)

        1. MC-222682 - Fixed Code.png
          MC-222682 - Fixed Code.png
          66 kB
        2. MC-222682 - Current Code.png
          MC-222682 - Current Code.png
          65 kB
        3. MC-222682.mp4
          2.75 MB
        4. 2021-04-12_09.20.10.png
          2021-04-12_09.20.10.png
          291 kB

            Unassigned Unassigned
            Avoma [Mod] Avoma
            Votes:
            3 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              CHK: