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

You can fill composters in adventure mode

    XMLWordPrintable

Details

    • 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
    • Community Consensus
    • Adventure
    • (Unassigned)

    Description

      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 in adventure mode.

      Expected Behavior:

      You would not be able to fill composters in adventure mode.

      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)

      Attachments

        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

        Issue Links

          Activity

            People

              Unassigned Unassigned
              Avoma [Helper] Avoma
              Votes:
              2 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                CHK: