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

You can place candles on top of cakes in adventure mode

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • None
    • 21w13a, 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 Pre-release 3, 1.17.1 Release Candidate 1, 1.17.1, 21w37a, 21w39a, 21w40a, 21w43a, 1.18, 1.18.1, 22w03a, 22w05a, 22w06a, 1.18.2, 1.19 Pre-release 1, 1.19, 1.19.2, 22w43a, 1.19.3 Release Candidate 1, 1.19.3, 1.19.4, 1.20.1, 1.20.4, 23w51b, 24w20a, 1.21, 1.21.3, 1.21.4
    • Confirmed
    • Adventure
    • Items, Player
    • Low
    • Gameplay

      The Bug:

      You can place candles on top of cakes in adventure mode.

      Steps to Reproduce:

      1. Place down a cake and obtain a candle.
      2. Switch into adventure mode and attempt to place the candle on top of the cake.
      3. Take note as to whether or not you can place candles on top of cakes in adventure mode.

      Observed Behavior:

      You can place candles on top of cakes.

      Expected Behavior:

      You would not be able to place candles on top of cakes.

      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.CakeBlock.java
      public class CakeBlock extends Block {
         ...
         public InteractionResult use(BlockState blockState, Level level, BlockPos blockPos, Player player, InteractionHand interactionHand, BlockHitResult blockHitResult) {
            ItemStack itemstack = player.getItemInHand(interactionHand);
            Item item = itemstack.getItem();
            if (itemstack.is(ItemTags.CANDLES) && blockState.getValue(BITES) == 0) {
               Block block = Block.byItem(item);
               if (block instanceof CandleBlock) {
                  if (!player.isCreative()) {
                     itemstack.shrink(1);
                  }
                  level.playSound((Player)null, blockPos, SoundEvents.CAKE_ADD_CANDLE, SoundSource.BLOCKS, 1.0F, 1.0F);
                  level.setBlockAndUpdate(blockPos, CandleCakeBlock.byCandle(block));
                  level.gameEvent(player, GameEvent.BLOCK_CHANGE, blockPos);
                  player.awardStat(Stats.ITEM_USED.get(item));
                  return InteractionResult.SUCCESS;
               }
            }
            ...

      If we look at the above class, we can see that there are two checks that are carried out before allowing players to place candles on top of cakes. One of these checks is to see if the player is holding an item included within the CANDLES item tag and that the given cake block has not yet been eaten, and the other is to check to see if the item in its block form is a candle block. If these two requirements are met, candles can be placed on top of cakes. The game doesn't check to see what abilities the player possesses (what game mode they are in) before allowing them to place candles on top of cakes, 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 place candles on top of cakes will resolve this problem.

      Current "if" statement:
      if (itemstack.is(ItemTags.CANDLES) && blockState.getValue(BITES) == 0)
      Fixed "if" statement:
      if (itemstack.is(ItemTags.CANDLES) && blockState.getValue(BITES) == 0 && player.getAbilities().mayBuild)

        1. 2021-04-12_09.29.15.png
          2021-04-12_09.29.15.png
          516 kB
        2. MC-222404.mp4
          1.96 MB
        3. MC-222404 - Current Code.png
          MC-222404 - Current Code.png
          77 kB
        4. MC-222404 - Fixed Code.png
          MC-222404 - Fixed Code.png
          78 kB

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

              Created:
              Updated:
              CHK: