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

You can fill composters in adventure mode

    XMLWordPrintable

Details

    • Bug
    • Status: Open
    • Resolution: Unresolved
    • 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
    • None
    • None
    • 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.18.1 using MCP-Reborn.

      net.minecraft.world.level.block.ComposterBlock.java
      public class ComposterBlock extends Block implements WorldlyContainerHolder {
         ...
         public InteractionResult use(BlockState $bs, Level $l, BlockPos $bp, Player $p, InteractionHand $ih, BlockHitResult $bhr) {
            int i = $bs.getValue(LEVEL);
            ItemStack itemstack = $p.getItemInHand($ih);
            if (i < 8 && COMPOSTABLES.containsKey(itemstack.getItem())) {
               if (i < 7 && !$l.isClientSide) {
                  BlockState blockstate = addItem($bs, $l, $bp, itemstack);
                  $l.levelEvent(1500, $bp, $bs != blockstate ? 1 : 0);
                  $p.awardStat(Stats.ITEM_USED.get(itemstack.getItem()));
                  if (!$p.getAbilities().instabuild) {
                     itemstack.shrink(1);
                  }
               }
               ...

      If we look at the above class, we can see that no checks are carried out to see what abilities the player possesses when filling a composter. The only checks that are in place are to see whether the level of the composter is less than 8, and if the item held by the player is compostable. This is evident through the following line of code:

      if (i < 8 && COMPOSTABLES.containsKey(itemstack.getItem()))

      Potential Fix:

      Simply adding a line of code that checks what abilities the player possesses before filling a composter, should resolve this problem. The following line of code could be used in order to fix this:

      !$p.getAbilities().mayBuild

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              Avoma Avoma
              Votes:
              1 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                CHK: