mojira.dev
MC-257875

Fire charges aren't consumed when igniting creepers using them in survival or adventure mode

The Bug:

Fire charges won't be consumed when igniting creepers with them in survival or adventure mode.

Differently, while igniting a TNT, the fire charge is consumed.

Steps to Reproduce:

  1. Obtain a fire charge and switch into survival mode.

  2. Summon a creeper and use the fire charge on it.

  3. Take note as to whether or not fire charges are consumed when igniting creepers using them in survival or adventure mode.

Observed Behavior:

The fire charge is not consumed.

Expected Behavior:

The fire charge would be consumed.

Code Analysis:

Code analysis by @unknown can be found in this comment.

Linked issues

Attachments

Comments 2

Here's a code analysis of this issue along with a fix. 😉

Code Analysis:

The following is based on a decompiled version of Minecraft 1.19.3 Release Candidate 3 using Mojang mappings.

net.minecraft.world.entity.monster.Creeper.java

public class Creeper extends Monster implements PowerableMob {
   ...
   protected InteractionResult mobInteract(Player player, InteractionHand interactionHand) {
      ItemStack itemStack = player.getItemInHand(interactionHand);
      if (itemStack.is(ItemTags.CREEPER_IGNITERS)) {
         SoundEvent soundEvent = itemStack.is(Items.FIRE_CHARGE) ? SoundEvents.FIRECHARGE_USE : SoundEvents.FLINTANDSTEEL_USE;
         this.level.playSound(player, this.getX(), this.getY(), this.getZ(), soundEvent, this.getSoundSource(), 1.0f, this.random.nextFloat() * 0.4f + 0.8f);
         if (!this.level.isClientSide) {
            this.ignite();
            itemStack.hurtAndBreak(1, player, player2 -> player2.broadcastBreakEvent(interactionHand));
         }
         return InteractionResult.sidedSuccess(this.level.isClientSide);
      }
      return super.mobInteract(player, interactionHand);
   }
   ...

If we look at the above class, we can see that when an item that's included within the CREEPER_IGNITERS item tag is used on a creeper, the hurtAndBreak() method is called. This method is specifically and exclusively designed to decrease the durability of an item that can be damaged. Because fire charges don't have durability, this results in them not being consumed when using them on creepers, therefore resulting in this problem occurring.

Fix:

Simply adding some lines of code to call a certain method based on what item players use to interact with creepers, will resolve this problem. When players interact with creepers using flint and steel, the hurtAndBreak() method should be called, and on the other hand, when players interact with creepers using fire charges, the shrink() method should be called.

Wouldn't it make more sense to just modify hurtAndBreak to just consume the item/call shrink if it has no durability? I recon it won't create any other issues, but might prevent future ones.

KeqiaoNana

v-armanv

Confirmed

Expansion B

Important

Items

creeper, fire_charge

1.19.3 Pre-release 2, 1.19.3 Pre-release 3, 1.19.3 Release Candidate 1, 1.19.3 Release Candidate 3, 1.19.3

23w03a

Retrieved