mojira.dev
MC-312654

Dispensers consume the durability of flint and steel and play their clicking sound despite there being nothing to ignite

The Bug:

Dispensers consume the durability of flint and steel and play their clicking sound despite there being nothing to ignite.

This was not an issue in 1.21.11. I have no idea when it first appeared.

Steps to Reproduce:

  1. Place down a dispenser and some flint and steel inside of it.

  2. Make sure there is no way that fire could form if you were to activate the dispenser.

  3. Now activate the dispenser and listen closely as you do this.

  4. Open the dispenser and observe if the flint and steel consumed durability.

Observed Behavior:

The flint and steel click sound is heard, and the flint and steel loses durability even though nothing was ignited.

Expected Behavior:

The dispenser would fail and no flint and steel click sound would be heard, and the flint and steel wouldn’t lose any durability.

Linked issues

Attachments

Comments 3

Can confirm, strange bug

This bug was introduced in 26.2-snapshot-6.

Code Ananysis

net.minecraft.core.dispenser.FlintAndSteelDispenseItemBehavior pre 26.2-snapshot-5:

    protected ItemStack execute(BlockSource source, ItemStack dispensed) {
        ServerLevel level = source.level();
        this.setSuccess(true);
        Direction facing = source.state().getValue(DispenserBlock.FACING);
        BlockPos targetPos = source.pos().relative(facing);
        BlockState target = level.getBlockState(targetPos);
        if (BaseFireBlock.canBePlacedAt(level, targetPos, facing)) {
            level.setBlockAndUpdate(targetPos, BaseFireBlock.getState(level, targetPos));
            level.gameEvent(null, GameEvent.BLOCK_PLACE, targetPos);
        } else if (CampfireBlock.canLight(target) || CandleBlock.canLight(target) || CandleCakeBlock.canLight(target)) {
            level.setBlockAndUpdate(targetPos, (BlockState)target.setValue(BlockStateProperties.LIT, true));
            level.gameEvent(null, GameEvent.BLOCK_CHANGE, targetPos);
        } else if (target.getBlock() instanceof TntBlock) {
            if (TntBlock.prime(level, targetPos)) {
                level.removeBlock(targetPos, false);
            } else {
                this.setSuccess(false);
            }
        } else if (!FlintAndSteelDispenseItemBehavior.tryIgniteExplosiveEntities(level, targetPos)) {
            // This is the failing case in question
            this.setSuccess(false);
        }
        if (this.isSuccess()) {
            dispensed.hurtAndBreak(1, level, null, item -> {});
        }
        return dispensed;
    }

Note the part marked in comments. When no blocks can be ignited, the code tries to ignite entities (namely TNT sulfur cubes), and when this fails as well, the code properly sets the attempt as failing in the marked path.

26.2-snapshot-6 moved the entity ignition test forward, resulting in the following shape:

    protected ItemStack execute(BlockSource source, ItemStack dispensed) {
        ServerLevel level = source.level();
        this.setSuccess(true);
        Direction facing = source.state().getValue(DispenserBlock.FACING);
        BlockPos targetPos = source.pos().relative(facing);
        BlockState target = level.getBlockState(targetPos);
        if (!FlintAndSteelDispenseItemBehavior.tryIgniteExplosiveEntities(level, targetPos)) {
            if (BaseFireBlock.canBePlacedAt(level, targetPos, facing)) {
                level.setBlockAndUpdate(targetPos, BaseFireBlock.getState(level, targetPos));
                level.gameEvent(null, GameEvent.BLOCK_PLACE, targetPos);
            } else if (CampfireBlock.canLight(target) || CandleBlock.canLight(target) || CandleCakeBlock.canLight(target)) {
                level.setBlockAndUpdate(targetPos, (BlockState)target.setValue(BlockStateProperties.LIT, true));
                level.gameEvent(null, GameEvent.BLOCK_CHANGE, targetPos);
            } else if (target.getBlock() instanceof TntBlock) {
                if (TntBlock.prime(level, targetPos, null, dispensed)) {
                    level.removeBlock(targetPos, false);
                } else {
                    this.setSuccess(false);
                }
            }
        }
        // No failing path!
        if (this.isSuccess()) {
            FlintAndSteelItem.playSound(level, targetPos);
            dispensed.hurtAndBreak(1, level, null, itemStack -> {});
        }
        return dispensed;
    }

The failing path is gone. Now failing to ignite an entity goes to the inner if-else, which, when there is nothing to ignite (the failing part for TNT does not trigger when there is no TNT in the first place), the state is not set to failing. Thus the flint and steel is used when nothing can be ignited.

By the way, it is curious how this bug has not been found until now.

Here is example clip of it. Doesn’t happen to brush, bonemeal, nor shears (mentioned since shear and sulfur cubes are a thing). Recorded on 26.3 release.

Avoma

bl4ckscor3

Community Consensus

Platform EC

Important

Items

26.3, 26.4 Snapshot 4

26.4 Snapshot 5

Retrieved