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

You can ignite TNT 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, 24w20a, 1.21, 1.21.3, 1.21.4
    • Confirmed
    • Adventure
    • Items, Player

      The Bug:

      You can ignite TNT in adventure mode.

      This behavior is inconsistent as the player cannot ignite candles or campfires in adventure mode, so one would expect the same behavior for TNT.

      Steps to Reproduce:

      1. Obtain some flint and steel, place down some TNT, and switch into adventure mode.
      2. Attempt to ignite the TNT using the flint and steel.
      3. Take note as to whether or not you can ignite TNT in adventure mode.

      Observed Behavior:

      TNT can be ignited.

      Expected Behavior:

      TNT would not be able to be ignited.

      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.TntBlock.java
      public class TntBlock extends Block {
         ...
         public InteractionResult use(BlockState blockState, Level level, BlockPos blockPos, Player player, InteractionHand interactionHand, BlockHitResult blockHitResult) {
            ItemStack itemstack = player.getItemInHand(interactionHand);
            if (!itemstack.is(Items.FLINT_AND_STEEL) && !itemstack.is(Items.FIRE_CHARGE)) {
               return super.use(blockState, level, blockPos, player, interactionHand, blockHitResult);
            } else {
               explode(level, blockPos, player);
               level.setBlock(blockPos, Blocks.AIR.defaultBlockState(), 11);
               Item item = itemstack.getItem();
               if (!player.isCreative()) {
                  if (itemstack.is(Items.FLINT_AND_STEEL)) {
                     itemstack.hurtAndBreak(1, player, (player1) -> {
                        player1.broadcastBreakEvent(interactionHand);
                     });
                  } else {
                     itemstack.shrink(1);
                  }
               }
               player.awardStat(Stats.ITEM_USED.get(item));
               return InteractionResult.sidedSuccess(level.isClientSide);
            }
         }
         ...

      If we look at the above class, we can see that there is only one necessary check that's carried out before allowing TNT to be ignited. This check is to quite simply see if the player is holding either flint and steel or a fire charge at the time of the interaction. If they are, the TNT will be ignited. The game doesn't check to see what abilities the player possesses (what game mode they are in) before allowing them to ignite TNT, therefore resulting in this problem occurring.

      Fix:

      Simply altering the appropriate existing "if" statement by adding an "if else" statement to it to check what abilities the player possesses before allowing them to ignite TNT will resolve this problem.

      Current "if" statement:
      if (!itemstack.is(Items.FLINT_AND_STEEL) && !itemstack.is(Items.FIRE_CHARGE)) {
         ...
      } else {
         ...
      Fixed "if" statement:
      if (!itemstack.is(Items.FLINT_AND_STEEL) && !itemstack.is(Items.FIRE_CHARGE)) {
         ...
      } else if (player.getAbilities().mayBuild) {
         ...
      }
      return InteractionResult.PASS;
      ...

        1. MC-222818 - Fixed Code.png
          MC-222818 - Fixed Code.png
          68 kB
        2. MC-222818 - Current Code.png
          MC-222818 - Current Code.png
          62 kB
        3. MC-222818.mp4
          2.46 MB
        4. 2021-04-12_09.12.13.png
          2021-04-12_09.12.13.png
          875 kB

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

              Created:
              Updated:
              CHK: