Merge pull request #2137 from kacpherek/fix/chicken-eggs

🤖 Agent: Gate check by Ludovic's AI agent (Claude). Checked against 26.3: `Chicken.aiStep` lays through `dropFromGiftLootTable(gameplay/chicken_lay)` with the chicken as `this`, which the table's conditions need, and snow and chorus flowers drop their loot when a player breaks them. One difference is left for later: an explosion's drops don't pass the exploding entity as `this` yet (snow broken by TNT). Gate: this wave's 55 PRs merged on main in one tree: clippy `-D warnings` clean, 1186 horizon-client and 163 horizon-world tests pass, and of the 101 harnesses `parity.py --changed-files` picked, 100 pass (`block_removal` failed on one spawner case from #2199's orb merging, fixed there). `lan_e2e.py` passes 24 checks with the host on its server thread and in-frame (chest, xp, pvp, doors, villagers, beds, frames, projectiles, arrows, fishing, damage, mobs, blast, drops, elytra, breath, predict, cracks, barter, kills, hurt, contacts, underwater, plates), plus forced-levels on the server thread. Thanks @kacpherek!
This commit is contained in:
Ludovic Marie
2026-10-26 20:12:45 +01:00
committed by GitHub
9 changed files with 103 additions and 17 deletions
+5 -4
View File
@@ -2238,8 +2238,9 @@ impl Game<'_> {
ticks: 0,
});
}
/// `Block.getDrops`: the block's loot table, drawing from its server random
/// sequence (`LootContext.Builder.create`), else the level random.
/// `Block.getDrops` for a block a player breaks: the block's loot table
/// with the player as `this`, drawing from its server random sequence
/// (`LootContext.Builder.create`), else the level random.
fn block_loot_at(
&mut self,
pos: [i32; 3],
@@ -2253,9 +2254,9 @@ impl Game<'_> {
let random = self.rand_sequences.get(&sequence, self.level.seed);
self.res
.items()
.block_drops_with(registry, state, held, &dynamic, random)
.block_drops_by_player(registry, state, held, &dynamic, random)
}
None => self.res.items().block_drops_with(
None => self.res.items().block_drops_by_player(
registry,
state,
held,
+42 -9
View File
@@ -850,6 +850,47 @@ impl Game<'_> {
}
}
}
/// `LivingEntity.dropFromGiftLootTable`: the gift table from its random
/// sequence with the mob as `this` (a chicken's egg depends on its
/// variant); the loot data of the game's resources decides, and without it
/// the items' table engine (no entity) rolls it.
fn drop_gift_loot(&mut self, mob: u32, table: &'static str, at: [f64; 3]) {
use horizon_client::mobs::drops;
use horizon_world::loot::EntityLootParams;
let loot = horizon_client::structure_blocks::loot_data(&self.options.resources);
let this = self
.mobs
.iter()
.find(|m| m.id == mob)
.map(|m| drops::loot_entity(m, None));
let stacks = match (loot, this) {
(Some(loot), Some(this)) if loot.has_table(table) => {
let params = EntityLootParams {
this,
..EntityLootParams::default()
};
let seed = self.level.seed;
match loot.random_sequence(table) {
Some(id) => {
let random = self.rand_sequences.get(id, seed);
loot.roll_entity(table, random, &params)
.iter()
.filter(|s| !s.is_empty())
.map(from_loot)
.collect()
}
None => Vec::new(),
}
}
_ => self
.res
.items()
.loot_table(table, false, None, &mut self.world.random),
};
for d in stacks {
self.spawn_item(d, at, [0.0, 0.2, 0.0], 10);
}
}
pub(super) fn handle_mob_events(&mut self, events: Vec<MobEvent>) -> Result<()> {
for e in events {
match e {
@@ -1251,15 +1292,7 @@ impl Game<'_> {
m.ai.aggressive |= aggressive;
}
}
MobEvent::GiftLoot { table, at } => {
let drops =
self.res
.items()
.loot_table(table, false, None, &mut self.world.random);
for d in drops {
self.spawn_item(d, at, [0.0, 0.2, 0.0], 10);
}
}
MobEvent::GiftLoot { mob, table, at } => self.drop_gift_loot(mob, table, at),
}
}
Ok(())
@@ -624,6 +624,7 @@ impl Game<'_> {
&mut self.world.random,
Some((&mut self.rand_sequences, self.level.seed)),
decay,
false,
);
for mut stack in drops {
if &*stack.item == "minecraft:air" || stack.count == 0 {
+42 -3
View File
@@ -834,6 +834,7 @@ impl Items {
held: None,
killed_by_player: false,
explosion_radius: None,
this_entity: false,
};
ctx.evaluate(table, random)
}
@@ -898,10 +899,26 @@ impl Items {
random: &mut impl RandomSource,
sequences: Option<(&mut crate::random_sequences::RandomSequences, i64)>,
) -> Vec<ItemStack> {
self.block_drops_exploded(registry, state, held, dynamic, random, sequences, None)
self.block_drops_exploded(
registry, state, held, dynamic, random, sequences, None, false,
)
}
/// `block_drops_with` for a block a player breaks (`Block.playerDestroy`):
/// the player is the loot context's `this` entity, so snow and chorus
/// flower tables see an entity.
pub fn block_drops_by_player(
&self,
registry: &BlockRegistry,
state: BlockStateId,
held: Option<&ItemStack>,
dynamic: &[ItemStack],
random: &mut impl RandomSource,
) -> Vec<ItemStack> {
self.block_drops_exploded(registry, state, held, dynamic, random, None, None, true)
}
/// `block_drops_full` for a block an explosion destroys: `explosion`
/// is its radius when the explosion decays drops (`DESTROY_WITH_DECAY`).
/// is its radius when the explosion decays drops (`DESTROY_WITH_DECAY`);
/// `breaker` is whether an entity (the player) broke the block.
#[allow(clippy::too_many_arguments)]
pub fn block_drops_exploded(
&self,
@@ -912,8 +929,10 @@ impl Items {
random: &mut impl RandomSource,
sequences: Option<(&mut crate::random_sequences::RandomSequences, i64)>,
explosion: Option<f32>,
breaker: bool,
) -> Vec<ItemStack> {
let drops = self.block_drops_raw(registry, state, held, random, sequences, explosion);
let drops =
self.block_drops_raw(registry, state, held, random, sequences, explosion, breaker);
if !drops.iter().any(|d| d.item.starts_with(DYNAMIC)) {
return drops;
}
@@ -928,6 +947,7 @@ impl Items {
})
.collect()
}
#[allow(clippy::too_many_arguments)]
fn block_drops_raw(
&self,
registry: &BlockRegistry,
@@ -936,6 +956,7 @@ impl Items {
random: &mut impl RandomSource,
sequences: Option<(&mut crate::random_sequences::RandomSequences, i64)>,
explosion_radius: Option<f32>,
breaker: bool,
) -> Vec<ItemStack> {
let Some(block) = registry.state(state) else {
return vec![];
@@ -969,6 +990,7 @@ impl Items {
held,
killed_by_player: false,
explosion_radius,
this_entity: breaker,
};
return ctx.evaluate(table, random);
}
@@ -979,6 +1001,7 @@ impl Items {
held,
killed_by_player: false,
explosion_radius,
this_entity: breaker,
};
ctx.evaluate(table, random)
}
@@ -1002,6 +1025,7 @@ impl Items {
held,
killed_by_player,
explosion_radius: None,
this_entity: false,
};
ctx.evaluate(table, random)
}
@@ -1034,6 +1058,7 @@ impl Items {
held: None,
killed_by_player: false,
explosion_radius: None,
this_entity: false,
};
match table.get("random_sequence").and_then(Value::as_str) {
Some(sequence) => ctx.evaluate(table, sequences.get(sequence, seed)),
@@ -1059,6 +1084,7 @@ impl Items {
held,
killed_by_player,
explosion_radius: None,
this_entity: false,
};
ctx.evaluate(table, random)
}
@@ -1081,6 +1107,7 @@ impl Items {
held,
killed_by_player,
explosion_radius: None,
this_entity: false,
};
ctx.evaluate(table, random)
}
@@ -1122,6 +1149,8 @@ struct LootContext<'a> {
killed_by_player: bool,
/// `LootContextParams.EXPLOSION_RADIUS`: an explosion that decays drops.
explosion_radius: Option<f32>,
/// `LootContextParams.THIS_ENTITY` is set (a player broke the block).
this_entity: bool,
}
impl LootContext<'_> {
/// Level of an enchantment on the tool / killer's weapon.
@@ -1282,6 +1311,15 @@ impl LootContext<'_> {
};
random.next_float() < chance
}
// `this` with no checks (snow, chorus flower) holds when an entity
// broke the block (LootItemEntityPropertyCondition needs the entity).
"minecraft:entity_properties"
if self.this_entity
&& c["entity"].as_str() == Some("this")
&& c["predicate"].as_object().is_none_or(|p| p.is_empty()) =>
{
true
}
// Entity flags, equipment and damage-source predicates: none hold
// for an unenchanted player kill without fire or lightning.
"minecraft:entity_properties" | "minecraft:damage_source_properties" => false,
@@ -1667,6 +1705,7 @@ mod tests {
held,
killed_by_player: block.is_empty(),
explosion_radius: None,
this_entity: false,
}
}
+3 -1
View File
@@ -1149,8 +1149,10 @@ pub enum MobEvent {
target: Who,
aggressive: bool,
},
/// Drop the loot of a gift table (chicken eggs, armadillo scutes).
/// Drop the loot of a gift table (chicken eggs, sniffer seeds) with the
/// mob as `this` (`LivingEntity.dropFromGiftLootTable`).
GiftLoot {
mob: u32,
table: &'static str,
at: [f64; 3],
},
+3
View File
@@ -351,6 +351,9 @@ pub fn loot_entity(m: &Mob, vehicle: Option<LootEntity>) -> LootEntity {
.to_owned(),
);
}
if s == S::Chicken {
e.chicken_variant = super::finalize::variant_component(m).map(|(_, id)| id);
}
e.powered = s == S::Creeper && m.extra.charged;
e.equipment = SLOTS
.iter()
+1
View File
@@ -80,6 +80,7 @@ pub fn chicken_ai_step(m: &mut Mob, _w: &MobWorld, events: &mut Vec<MobEvent>) {
let at = [m.position.x, m.position.y, m.position.z];
events.push(MobEvent::Sound("entity.chicken.egg", at, 1.0, pitch));
events.push(MobEvent::GiftLoot {
mob: m.id,
table: "minecraft:gameplay/chicken_lay",
at,
});
@@ -94,6 +94,7 @@ pub fn ai_step(m: &mut Mob, events: &mut Vec<MobEvent>) {
if current == DIGGING && now(m) == m.extra.ints[3] {
let h = head_block(m);
events.push(MobEvent::GiftLoot {
mob: m.id,
table: "minecraft:gameplay/sniffer_digging",
at: [f64::from(h[0]), f64::from(h[1]), f64::from(h[2])],
});
+5
View File
@@ -154,6 +154,8 @@ pub struct LootEntity {
pub captain: Option<bool>,
/// A frog's variant id (`minecraft:warm`).
pub frog_variant: Option<String>,
/// A chicken's variant id (`minecraft:warm`).
pub chicken_variant: Option<String>,
/// A charged creeper (`Creeper.isPowered`).
pub powered: bool,
/// Worn and held items by `EquipmentSlot` name (mainhand, offhand,
@@ -862,6 +864,9 @@ impl<R: RandomSource> Context<'_, R> {
"minecraft:frog/variant" => {
e.frog_variant.is_some() && want.as_str() == e.frog_variant.as_deref()
}
"minecraft:chicken/variant" => {
e.chicken_variant.is_some() && want.as_str() == e.chicken_variant.as_deref()
}
_ => false,
}),
"minecraft:type_specific/sheep" => e