Merge pull request #1081 from ludovic111/fix/shears-carve-pumpkin

🤖 Agent: merged. Shears carve pumpkins (fixes #1067, reported by Tydragon). Integration proof (main + #1079 #1081 #1082 #1083 #1085 #1086 #1087), 2026-10-21: desktop parity 103/105; the 2 others (world_reopen, save_roundtrip) need a display and pass on the Mac mini. Verify passed.
This commit is contained in:
Ludovic Marie
2026-10-21 18:05:02 +02:00
committed by GitHub
7 changed files with 176 additions and 34 deletions
+5
View File
@@ -110,6 +110,7 @@ mod player_equip;
mod postprocess;
mod potions;
mod powder_snow;
mod pumpkin;
mod raids;
mod recipe_book;
mod remote;
@@ -2986,6 +2987,10 @@ impl Game<'_> {
self.swing_arm();
return Ok(true);
}
if self.use_pumpkin(hit.pos, hit.face, held.as_ref())? {
self.swing_arm();
return Ok(true);
}
match self.use_respawn_anchor(hit.pos, held.as_ref())? {
respawn_anchor::AnchorUse::Charged => {
self.swing_arm();
@@ -484,7 +484,8 @@ impl Game<'_> {
Ok(out)
}
/// A player three blocks south of `pos` right-clicks its top face holding
/// A player three blocks south of `pos`, turned to the case's `yaw`,
/// right-clicks its top face (or the case's `face`) holding
/// the case's item (`use_item_as_player` on that hit): the statistics,
/// the held stack and the item it started using, as
/// `VanillaDispenserOracle.useItem` prints them.
@@ -516,7 +517,7 @@ impl Game<'_> {
}
player.health.food.food = op["food"].as_i64().unwrap_or(20) as i32;
self.player = Some(player);
self.yaw = 0.0;
self.yaw = op["yaw"].as_f64().unwrap_or(0.0) as f32;
self.pitch = 90.0;
self.keys.clear();
if op["sneaking"].as_bool().unwrap_or(false) {
@@ -533,13 +534,23 @@ impl Game<'_> {
.collect();
items.dedup();
let used_before: Vec<_> = items.iter().map(|i| self.stats.get("used", i)).collect();
// The top face, or the case's `face`, clicked at its centre.
let face = match op["face"].as_str() {
Some("down") => [0, -1, 0],
Some("north") => [0, 0, -1],
Some("south") => [0, 0, 1],
Some("west") => [-1, 0, 0],
Some("east") => [1, 0, 0],
_ => [0, 1, 0],
};
let centre = |c: i32, f: i32| f64::from(c) + 0.5 + f64::from(f) * 0.5;
self.forced_hit = Some(super::Hit {
pos: [pos.x, pos.y, pos.z],
face: [0, 1, 0],
face,
point: [
f64::from(pos.x) + 0.5,
f64::from(pos.y) + 1.0,
f64::from(pos.z) + 0.5,
centre(pos.x, face[0]),
centre(pos.y, face[1]),
centre(pos.z, face[2]),
],
});
self.chat_capture = Some(Vec::new());
+1 -14
View File
@@ -1494,20 +1494,7 @@ impl Game<'_> {
.default_state("minecraft:carved_pumpkin")
{
let head = [target.0, target.1, target.2];
if self.completes_golem(head) {
// CarvedPumpkinBlock.onPlace builds the golem inside
// setBlock; the spot is air again by the time setBlock
// would update neighbours, so it skips them.
let at = Self::pos_of(target);
self.with_level(|b, level, ticks| {
b.set_block(level, ticks, at, pumpkin, 2 | 16)
});
self.process_level_events()?;
self.check_golem_spawn(head)?;
} else {
self.level_set(head, pumpkin)?;
self.check_golem_spawn(head)?;
}
self.set_golem_head(head, pumpkin)?;
self.post_block_game_event("minecraft:block_place", head, None, None);
}
return Ok((shrink(stack), CLICK));
+18
View File
@@ -85,6 +85,24 @@ impl Game<'_> {
pub(super) fn completes_golem(&self, head: [i32; 3]) -> bool {
self.find_golem(head).is_some() || self.copper_golem_base(head)
}
/// `Level.setBlock` of the golem head `state` at `head`, then
/// `CarvedPumpkinBlock.onPlace`. When the head completes a golem, onPlace
/// builds it inside setBlock and the spot is air again by the time
/// setBlock would update neighbours, so it skips them.
pub(super) fn set_golem_head(
&mut self,
head: [i32; 3],
state: horizon_world::registry::BlockStateId,
) -> Result<()> {
if self.completes_golem(head) {
let at = horizon_core::position::BlockPos::new(head[0], head[1], head[2]);
self.with_level(|b, level, ticks| b.set_block(level, ticks, at, state, 2 | 16));
self.process_level_events()?;
} else {
self.level_set(head, state)?;
}
self.check_golem_spawn(head)
}
/// `EntityType.create(level, TRIGGERED)` and `snapTo`: a built golem or
/// wither has no spawn finalization and draws nothing from the level.
pub(super) fn create_triggered(&mut self, kind: &str, at: [f64; 3], yaw: f32) -> Option<u32> {
+88
View File
@@ -0,0 +1,88 @@
//! `PumpkinBlock.useItemOn`: shears carve a pumpkin into a carved pumpkin
//! facing the clicked side (the side facing the player on the top and
//! bottom), and the `carve/pumpkin` seeds pop out of that side.
use super::Game;
use horizon_client::{Result, items::ItemStack};
use horizon_core::random::RandomSource;
impl Game<'_> {
/// `PumpkinBlock.useItemOn` with `held` in the hand that acts, the block
/// at `pos` clicked on `face`: true when shears carved it (SUCCESS).
pub(super) fn use_pumpkin(
&mut self,
pos: [i32; 3],
face: [i32; 3],
held: Option<&ItemStack>,
) -> Result<bool> {
let Some(shears) = held.filter(|s| &*s.item == "minecraft:shears") else {
return Ok(false);
};
let state = self.world.block(pos[0], pos[1], pos[2]);
if &*self.res.facts().get(state).name != "minecraft:pumpkin" {
return Ok(false);
}
// Up or down: player.getDirection().getOpposite().
let (dx, dz) = if face[1] != 0 {
match ((self.yaw / 90.0 + 0.5).floor() as i32).rem_euclid(4) {
0 => (0, -1),
1 => (1, 0),
2 => (0, 1),
_ => (-1, 0),
}
} else {
(face[0], face[2])
};
let facing = match (dx, dz) {
(0, -1) => "north",
(0, 1) => "south",
(-1, 0) => "west",
_ => "east",
};
// dropFromBlockInteractLootTable(CARVE_PUMPKIN): each stack as an
// ItemEntity in front of the carved side, moved by the level random
// (no pickup delay).
let (dx, dz) = (f64::from(dx), f64::from(dz));
for seeds in self.sequence_loot(
"minecraft:carve/pumpkin",
"minecraft:carve/pumpkin",
Some(shears),
) {
let at = [
f64::from(pos[0]) + 0.5 + dx * 0.65,
f64::from(pos[1]) + 0.1,
f64::from(pos[2]) + 0.5 + dz * 0.65,
];
let r = &mut self.world.random;
let vx = 0.05 * dx + r.next_double() * 0.02;
let vz = 0.05 * dz + r.next_double() * 0.02;
self.spawn_item(seeds, at, [vx, 0.05, vz], 0);
}
self.audio.play(
"minecraft:block.pumpkin.carve",
Some([
f64::from(pos[0]) + 0.5,
f64::from(pos[1]) + 0.5,
f64::from(pos[2]) + 0.5,
]),
1.0,
1.0,
);
let registry = self.pack.assets.registry;
let carved = registry
.default_state("minecraft:carved_pumpkin")
.and_then(|d| {
let mut s = registry.state(d)?.clone();
s.properties.insert("facing".into(), facing.into());
registry.resolve(&s).ok()
});
if let Some(carved) = carved {
self.set_golem_head(pos, carved)?;
}
self.damage_held(1);
self.post_block_game_event("minecraft:shear", pos, self.sculk_actor(), None);
self.stats.add("used", "minecraft:shears", 1);
// ServerPlayerGameMode.useItemOn: the action was consumed.
self.trigger_block("minecraft:item_used_on_block", pos, shears);
Ok(true)
}
}
@@ -582,7 +582,8 @@ public final class VanillaDispenserOracle {
}
/**
* A right click on the top of the block at `pos` (`ServerPlayerGameMode.useItemOn`
* A right click on the top of the block at `pos`, or on its `face`, by a
* player turned to `yaw` (`ServerPlayerGameMode.useItemOn`
* of the real game mode, survival or creative): the block's `useItemOn` and
* `useWithoutItem`, then the item's `useOn` (`BlockItem.place`, falling back
* to eating a consumable), and `useItem` when that passes, for the main
@@ -622,11 +623,14 @@ public final class VanillaDispenserOracle {
VanillaBlockUpdateOracle.set(Entity.class, player, "position", at);
VanillaBlockUpdateOracle.set(Entity.class, player, "blockPosition", BlockPos.containing(at));
VanillaBlockUpdateOracle.set(Entity.class, player, "xRot", 90f);
if (use.has("yaw")) VanillaBlockUpdateOracle.set(Entity.class, player, "yRot", use.get("yaw").getAsFloat());
var gameMode = new net.minecraft.server.level.ServerPlayerGameMode(player);
VanillaBlockUpdateOracle.set(net.minecraft.server.level.ServerPlayerGameMode.class, gameMode, "gameModeForPlayer",
player.creative ? net.minecraft.world.level.GameType.CREATIVE : net.minecraft.world.level.GameType.SURVIVAL);
var hit = new net.minecraft.world.phys.BlockHitResult(net.minecraft.world.phys.Vec3.atCenterOf(pos).add(0, 0.5, 0),
net.minecraft.core.Direction.UP, pos, false);
// The top face, or the case's `face`, clicked at its centre.
var face = use.has("face") ? net.minecraft.core.Direction.byName(use.get("face").getAsString()) : net.minecraft.core.Direction.UP;
var hit = new net.minecraft.world.phys.BlockHitResult(net.minecraft.world.phys.Vec3.atCenterOf(pos)
.add(face.getStepX() * 0.5, face.getStepY() * 0.5, face.getStepZ() * 0.5), face, pos, false);
// Minecraft.startUseItem: each hand in turn clicks the block, then uses
// its item unless the click succeeded or failed; a success ends it.
for (var hand : net.minecraft.world.InteractionHand.values()) {
+40 -11
View File
@@ -1,20 +1,22 @@
#!/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, for respawn anchors and
for beds in the Nether and the End.
berry bushes, for spawn eggs used on a monster spawner, for shears carving
pumpkins, 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
right-clicks the top face of the origin holding an item, sometimes with
another (or nothing) in the main hand and the item in the off hand, the
main hand trying first. Vanilla runs the real
`ServerPlayerGameMode.useItemOn` over the headless level of the dispenser
harness (`VanillaDispenserOracle.useItem`): the block's `useItemOn` and
`useWithoutItem` (picking a bush's berries, `SweetBerryBushBlock.useItemOn`
passing bone meal on), then `ItemStack.useOn` (`BlockItem.place` with its
`mayPlaceOn` rules, `BoneMealItem.useOn`, eating a consumable that could
not be placed, and `SpawnEggItem.useOn` setting a spawner's mob). Respawn
right-clicks the top face of the origin (for pumpkins, any face, turned any
way) holding an item, sometimes with another (or nothing) in the main hand
and the item in the off hand, the main hand trying first. Vanilla runs the
real `ServerPlayerGameMode.useItemOn` over the headless level of the
dispenser harness (`VanillaDispenserOracle.useItem`): the block's `useItemOn`
and `useWithoutItem` (picking a bush's berries, `SweetBerryBushBlock.useItemOn`
passing bone meal on, `PumpkinBlock.useItemOn` carving with shears and
dropping the seeds from the carved side), then `ItemStack.useOn`
(`BlockItem.place` with its `mayPlaceOn` rules, `BoneMealItem.useOn`, eating
a consumable that could not be placed, and `SpawnEggItem.useOn` setting a
spawner's mob). Respawn
anchors are charged with glowstone, set the respawn point in the Nether and
explode elsewhere (`RespawnAnchorBlock`, through the stand-in level's real
`ServerExplosion`, with water at the anchor). Respawn cases call
@@ -156,6 +158,27 @@ def anchor_case(rng, states, case):
case['cells'] = cells
def pumpkin_case(rng, states, case):
"""Shears (or something else) used on a pumpkin (`PumpkinBlock.useItemOn`):
any face, the player turned any way, worn shears (the stand-in player
has no entity id for the break event, so they keep one use)."""
cells = [[0, 0, 0, states.get(rng.choice(['pumpkin'] * 6 + ['carved_pumpkin', 'melon']))]]
if rng.random() < 0.3:
cells.append([0, 1, 0, states.get(rng.choice(['stone', 'snow', 'short_grass']))])
damage = rng.choice([0, 0, 0, 100, 236])
shears = d_plain('shears', 1) if damage == 0 else \
'{id:"minecraft:shears",count:1,components:{"minecraft:damage":%d}}' % damage
item = rng.choice([shears] * 6 + [d_plain('stick', 1), d_plain('pumpkin', 3), '-'])
use = {'item': item, 'creative': rng.random() < 0.2, 'sneaking': rng.random() < 0.15, 'food': 20,
'yaw': rng.choice([0, 30, 90, 135, 180, 200, 270, 315, -45, -100]),
'face': rng.choice(['up', 'up', 'down', 'north', 'south', 'west', 'east'])}
if rng.random() < 0.3:
# Shears in the off hand, something else or nothing in the main hand.
use.update(offhand=item, item=rng.choice(['-', '-', d_plain('stick', 1), d_plain('stone', 16)]))
case['use_item'] = use
case['cells'] = cells
def cases(facts, count, seed):
rng = random.Random(seed)
states = d.States(facts)
@@ -181,6 +204,12 @@ def cases(facts, count, seed):
case['mode'] = 'dispense'
yield case
continue
if rng.random() < 0.12:
pumpkin_case(rng, states, case)
case['items'] = []
case['mode'] = 'dispense'
yield case
continue
cells = []
item = rng.choice(ITEMS)
if rng.random() < 0.15: