Clear a door's lower half when the tool would not drop it

DoorBlock.playerWillDestroy removes the bottom half for creative or !hasCorrectToolForDrops (iron door by hand); only creative was handled.
This commit is contained in:
Kacpherek
2026-10-27 22:27:59 +01:00
parent e08adcd31c
commit 2c2aa41619
4 changed files with 13 additions and 6 deletions
+6
View File
@@ -3983,12 +3983,18 @@ impl Game<'_> {
// library: the block entity's side effects (containers spill), neighbour
// and shape updates, and the destroy event (particles, sound).
let creative = self.creative;
let correct_tool = !facts.requires_tool
|| self
.res
.items()
.correct_for_drops(self.held(), &facts.name);
let removed = self.with_level(|b, level, ticks| {
b.player_destroy_block(
level,
ticks,
BlockPos::new(pos[0], pos[1], pos[2]),
creative,
correct_tool,
)
});
if removed {
+3 -3
View File
@@ -386,7 +386,7 @@ impl<L: LevelAccess + ?Sized> Sim<'_, L> {
/// `ServerPlayerGameMode.destroyBlock`: `playerWillDestroy` then
/// `removeBlock`. Drops are the caller's (tool-dependent loot).
pub(crate) fn player_destroy(&mut self, pos: BlockPos, creative: bool) -> bool {
pub(crate) fn player_destroy(&mut self, pos: BlockPos, creative: bool, correct_tool: bool) -> bool {
let b = self.b;
let p = b.props;
let state = self.state(pos);
@@ -394,8 +394,8 @@ impl<L: LevelAccess + ?Sized> Sim<'_, L> {
return false;
}
let data = b.data(state);
if creative
&& (data.is(Class::DoublePlant) || data.is(Class::Door))
// DoorBlock also clears the bottom half when the tool would not drop it.
if ((creative && data.is(Class::DoublePlant)) || (data.is(Class::Door) && (creative || !correct_tool)))
&& b.table.text(state, p.half) == "upper"
{
let bottom = below(pos);
+3 -2
View File
@@ -80,7 +80,7 @@
//! behaviours.place_block(&mut level, &mut ticks, &PlaceContext { clicked_pos, face, hit, inside: false,
//! yaw, pitch, sneaking, item: "minecraft:oak_stairs".into(), can_use_game_master_blocks: false });
//! behaviours.use_without_item(&mut level, &mut ticks, pos, face, hit, player_context);
//! behaviours.player_destroy_block(&mut level, &mut ticks, pos, creative);
//! behaviours.player_destroy_block(&mut level, &mut ticks, pos, creative, correct_tool);
//! // Falling-block entity landed:
//! behaviours.falling_block_landed(&mut level, &mut ticks, landing_pos, carried_state, false);
//! ```
@@ -657,8 +657,9 @@ impl Behaviours {
ticks: &mut Ticks,
pos: BlockPos,
creative: bool,
correct_tool: bool,
) -> bool {
self.sim(level, ticks).player_destroy(pos, creative)
self.sim(level, ticks).player_destroy(pos, creative, correct_tool)
}
/// `IceBlock.playerDestroy` after the drops: mined ice melts into water
/// unless the tool prevents ice melting (silk touch). `destroyed` is the
+1 -1
View File
@@ -1361,7 +1361,7 @@ fn player_breaks_fire_with_extinguish_not_generic_break_event() {
w.level.events.clear();
assert!(
w.f.behaviours
.player_destroy_block(&mut w.level, &mut w.ticks, pos, false)
.player_destroy_block(&mut w.level, &mut w.ticks, pos, false, true)
);
let is_fire = name != "white_wool";
assert_eq!(