The Trial Chamber assembly structure TNT trap automatically explodes when setting the gamerule doMobSpawning
off/false.
Steps to Reproduce
Find the trial chamber with the seed and coords here.
4226348645603381645
/execute in minecraft:overworld run tp @s -34.00 -22.14 -295.29
Set your doMobSpawning gamerule to false
See the TNT trap unfold
Expected Result
The TNT trap shouldn't be triggered
Observed Result
The TNT trap was triggered by absolutely no one but changing the gamerule itself, causing the chamber to be partially destroyed
Attachments
Comments 3
This issue should be renamed 'Trial Spawners cause observers to be ticked when updating their internal state'
The TNT itself is not the cause of the issue, it's the fact the observer is powered. You can test this by placing an observer next to a trial spawner and changing the gamerule, it will power.
Code analysis
The following code is an extract of decompiled 1.20.5-pre1 using official mappings
TrialSpawner.class
public void tickServer(ServerLevel serverLevel, BlockPos blockPos, boolean bl) {
// ...
if (!this.canSpawnInLevel(serverLevel)) {
if (trialSpawnerState.isCapableOfSpawning()) {
this.data.reset();
this.setState(serverLevel, TrialSpawnerState.INACTIVE); // triggers observer tick
}
} else {
// ...
TrialSpawnerState trialSpawnerState2 = trialSpawnerState.tickAndGetNext(blockPos, this, serverLevel);
if (trialSpawnerState2 != trialSpawnerState) {
this.setState(serverLevel, trialSpawnerState2); // triggers observer tick
}
}
}
public boolean canSpawnInLevel(Level level) {
if (this.overridePeacefulAndMobSpawnRule) {
return true;
} else {
// here you can see both the causes of this issue right here
return level.getDifficulty() == Difficulty.PEACEFUL ? false : level.getGameRules().getBoolean(GameRules.RULE_DOMOBSPAWNING);
}
}
The error exists within the above code.
Every server tick, the spawner checks if it is still able to spawn mobs as per the game rule and difficulty. If an update is required, it calls `setState`, which causes an observer to see the change and power the tnt.
Can confirm, also happens when the difficulty is set to peaceful.