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

Details

    • Bug
    • Status: Open
    • Resolution: Unresolved
    • 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
    • None
    • None
    • Confirmed
    • Adventure
    • Items, Player
    • Low

    Description

      The Bug:

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

      Steps to Reproduce:

      • Place down a cake and obtain a candle.
      • Switch into adventure mode and attempt to place the candle on top of the cake.
      • 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 in adventure mode.

      Expected Behavior:

      You would not be able to place candles on top of cakes 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.CakeBlock.java
      public class CakeBlock extends Block {
         ...
         public InteractionResult use(BlockState $bs, Level $l, BlockPos $bp, Player $p, InteractionHand $ih, BlockHitResult $bhr) {
            ItemStack itemstack = $p.getItemInHand($ih);
            Item item = itemstack.getItem();
            if (itemstack.is(ItemTags.CANDLES) && $bs.getValue(BITES) == 0) {
               Block block = Block.byItem(item);
               if (block instanceof CandleBlock) {
                  if (!$p.isCreative()) {
                     itemstack.shrink(1);
                  }
      
                  $l.playSound((Player)null, $bp, SoundEvents.CAKE_ADD_CANDLE, SoundSource.BLOCKS, 1.0F, 1.0F);
                  $l.setBlockAndUpdate($bp, CandleCakeBlock.byCandle(block));
                  $l.gameEvent($p, GameEvent.BLOCK_CHANGE, $bp);
                  $p.awardStat(Stats.ITEM_USED.get(item));
                  return InteractionResult.SUCCESS;
               }
            }
            ...

      If we look at the above class, we can see that no checks are carried out to see what abilities the player possesses when placing a candle on top of a cake. The only checks that are in place are to see whether the player is holding a candle and if the cake has any bites taken out of it. This is evident through the following line of code:

      if (itemstack.is(ItemTags.CANDLES) && $bs.getValue(BITES) == 0)

      Potential Fix:

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

      !$p.getAbilities().mayBuild

      Attachments

        Activity

          People

            Unassigned Unassigned
            Avoma Avoma
            Votes:
            11 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              CHK: