Merge pull request #169 from ludovic111/fix/bed-explosions-101

Beds and straw beds blow up when used in the Nether and the End
This commit is contained in:
Ludovic Marie
2026-10-14 21:23:09 +02:00
committed by GitHub
5 changed files with 112 additions and 5 deletions
+3
View File
@@ -1711,6 +1711,9 @@ impl Game<'_> {
}
LevelEvent::Player { pos, effect, .. } => match effect {
PlayerEffect::OpenMenu => self.open_menu([pos.x, pos.y, pos.z]),
PlayerEffect::Sleep if self.beds_destroy_on_use() => {
self.destroy_bed_on_use([pos.x, pos.y, pos.z])?
}
PlayerEffect::Sleep => self.try_sleep([pos.x, pos.y, pos.z]),
PlayerEffect::GiveItem(item) => {
if let Some(rest) = self.give(ItemStack {
@@ -164,8 +164,10 @@ impl Game<'_> {
}
}
self.world.game_time = case["time"].as_i64().unwrap_or(0);
if case["dim"].as_str() == Some("nether") {
self.dim = super::Dim::Nether;
match case["dim"].as_str() {
Some("nether") => self.dim = super::Dim::Nether,
Some("end") => self.dim = super::Dim::End,
_ => {}
}
// The oracle level's clock stands at day time 6000.
self.world.day_time = 6000;
@@ -240,6 +240,59 @@ impl Game<'_> {
];
self.block_explosion(center, in_water.then_some(pos))
}
/// `BedRule.destroyOnUse` of the dimension's `bed_rule` and
/// `straw_bed_rule`: true in the Nether and the End.
pub(super) fn beds_destroy_on_use(&self) -> bool {
self.dim != Dim::Overworld
}
/// `AbstractBedBlock.useWithoutItem` where the bed rule destroys on use
/// (the bed's head at `head`): `BedBlock.destroyOnUse` removes both
/// halves and explodes; `StrawBedBlock` just falls apart.
pub(super) fn destroy_bed_on_use(&mut self, head: [i32; 3]) -> Result<()> {
let state = self.world.block(head[0], head[1], head[2]);
let name = self.res.facts.get(state).name.clone();
let center = [
f64::from(head[0]) + 0.5,
f64::from(head[1]) + 0.5,
f64::from(head[2]) + 0.5,
];
if &*name == "minecraft:straw_bed" {
// StrawBedBlock.destroyBed.
self.audio.play(
"minecraft:block.straw_bed.break_leave",
Some(center),
1.0,
1.0,
);
return self.level_set(head, self.world.air);
}
// removeBlock(head), then the foot behind it if it is still this bed.
let facing = self
.res
.assets
.registry
.state(state)
.and_then(|s| s.properties.get("facing").cloned())
.unwrap_or_default();
let back = match facing.as_str() {
"north" => [0, 0, 1],
"south" => [0, 0, -1],
"west" => [1, 0, 0],
_ => [-1, 0, 0],
};
self.level_set(head, self.world.air)?;
let foot = [head[0] + back[0], head[1], head[2] + back[2]];
if self
.res
.facts
.get(self.world.block(foot[0], foot[1], foot[2]))
.name
== name
{
self.level_set(foot, self.world.air)?;
}
self.block_explosion(center, None)
}
/// `Level.explode(null, badRespawnPointExplosion(center), calculator,
/// center, 5, true, ExplosionInteraction.BLOCK)` (beds and anchors):
/// `water_at` is the block that resists like water.
@@ -253,6 +253,12 @@ public final class VanillaDispenserOracle {
w.type = NETHER;
w.dimensionKey = Level.NETHER;
w.attributes = net.minecraft.world.attribute.EnvironmentAttributeSystem.builder().addConstantLayer(NETHER.attributes()).build();
} else if (f.has("dim") && f.get("dim").getAsString().equals("end")) {
// The End's (beds explode, anchors do too).
if (END == null) END = VanillaBlockUpdateOracle.loadDimensionType(net.minecraft.world.level.dimension.BuiltinDimensionTypes.END);
w.type = END;
w.dimensionKey = Level.END;
w.attributes = net.minecraft.world.attribute.EnvironmentAttributeSystem.builder().addConstantLayer(END.attributes()).build();
}
if (f.has("rules")) {
for (var rule : f.getAsJsonObject("rules").entrySet()) {
@@ -389,7 +395,7 @@ public final class VanillaDispenserOracle {
result.add("rng " + w.rng.nextLong());
}
static net.minecraft.world.level.dimension.DimensionType NETHER;
static net.minecraft.world.level.dimension.DimensionType NETHER, END;
/** The player of a "use" case: its main hand, game mode and the statistics it is awarded. */
static final class User extends net.minecraft.server.level.ServerPlayer {
+45 -2
View File
@@ -1,7 +1,8 @@
#!/usr/bin/env python3
"""Compare a player's right click on a block with vanilla's, for items that are
both food and blocks (sweet and glow berries, carrots, potatoes), for sweet
berry bushes, for spawn eggs used on a monster spawner and for respawn anchors.
berry bushes, for spawn eggs used on a monster spawner, for respawn anchors and
for beds in the Nether and the End.
Every case has a block at the origin, something above it, and a player three
blocks south, survival or creative, hungry or full, sneaking or not, who
@@ -17,7 +18,10 @@ explode elsewhere (`RespawnAnchorBlock`, through the stand-in level's real
`ServerExplosion`, with water at the anchor). Respawn cases call
`ServerPlayer.findRespawnAndUseSpawnBlock` on an anchor among blocks
(`RespawnAnchorBlock.findStandUpPosition` through `DismountHelper`): the
position, the yaw that faces the anchor and the charge it uses. Horizon runs
position, the yaw that faces the anchor and the charge it uses. Beds and straw
beds clicked (head or foot, whole or broken) in the Nether and the End blow up
or fall apart (`AbstractBedBlock.useWithoutItem` under the dimension's
`bed_rule`: `BedBlock.destroyOnUse`, `StrawBedBlock.destroyBed`). Horizon runs
`use_item_as_player` on that hit in a headless game
(`HORIZON_DISPENSE_FIXTURE`). Both print block changes, dropped items, level
events, sounds, game events, the used statistic, the held stack, the item the
@@ -76,6 +80,39 @@ def respawn_case(rng, states, case):
case['cells'] = cells
BED_COLORS = ['red', 'white', 'black', 'cyan', 'lime']
FACINGS = {'north': (0, -1), 'south': (0, 1), 'west': (-1, 0), 'east': (1, 0)}
def bed_case(rng, states, case):
"""A bed (or straw bed) clicked in the Nether or the End, among blocks."""
name = 'straw_bed' if rng.random() < 0.25 else rng.choice(BED_COLORS) + '_bed'
facing = rng.choice(list(FACINGS))
dx, dz = FACINGS[facing]
# The clicked block is the origin; the other half lies along the facing.
part = rng.choice(['head', 'foot'])
other = (-dx, 0, -dz) if part == 'head' else (dx, 0, dz)
cells = [[0, 0, 0, states.get(name, facing=facing, part=part, occupied='false')],
[0, -1, 0, states.get(rng.choice(['netherrack', 'end_stone', 'obsidian', 'stone']))],
[other[0], -1, other[2], states.get('stone')]]
if rng.random() < 0.9:
cells.append([*other, states.get(name, facing=facing, part='foot' if part == 'head' else 'head', occupied='false')])
taken = {tuple(c[:3]) for c in cells}
for _ in range(rng.choice([0, 3, 10, 30])):
p = (rng.randrange(-3, 4), rng.randrange(-2, 3), rng.randrange(-3, 4))
if p in taken:
continue
taken.add(p)
cells.append([*p, states.get(rng.choice(AROUND))])
case['dim'] = rng.choice(['nether', 'end'])
item = rng.choice(['-', '-', 'apple', 'stone', 'glowstone'])
case['use_item'] = {'item': '-' if item == '-' else d_plain(item, 1), 'creative': rng.random() < 0.2,
'sneaking': rng.random() < 0.1, 'food': 20, 'distance': 12}
if rng.random() < 0.2:
case['rules'] = {'block_explosion_drop_decay': False}
case['cells'] = cells
def anchor_case(rng, states, case):
"""A respawn anchor clicked in the Nether or the Overworld, with blocks
and water around it."""
@@ -120,6 +157,12 @@ def cases(facts, count, seed):
case = {**h.environment(rng), 'pos': [0, 0, 0]}
case.pop('raining', None)
case.pop('thundering', None)
if rng.random() < 0.1:
bed_case(rng, states, case)
case['items'] = []
case['mode'] = 'dispense'
yield case
continue
if rng.random() < 0.1:
respawn_case(rng, states, case)
case['items'] = []