Merge pull request #1553 from ludovic111/cg3/pr1534-fixup

This commit is contained in:
Ludovic Marie
2026-10-24 14:31:42 +02:00
committed by GitHub
15 changed files with 48 additions and 50 deletions
+7 -7
View File
@@ -382,7 +382,7 @@ impl Providers {
);
Self { ints, floats }
}
fn eval(&self, v: &Value, fast: bool, table: &HashMap<String, Value>, depth: u32) -> f64 {
fn eval(v: &Value, fast: bool, table: &HashMap<String, Value>, depth: u32) -> f64 {
if depth > 16 {
return 0.0;
}
@@ -390,10 +390,10 @@ impl Providers {
Value::Number(n) => n.as_f64().unwrap_or(0.0),
Value::String(name) => table
.get(name)
.map_or(0.0, |v| self.eval(v, fast, table, depth + 1)),
.map_or(0.0, |v| Self::eval(v, fast, table, depth + 1)),
Value::Object(o) => {
let f =
|k: &str| self.eval(o.get(k).unwrap_or(&Value::Null), fast, table, depth + 1);
|k: &str| Self::eval(o.get(k).unwrap_or(&Value::Null), fast, table, depth + 1);
match o.get("type").and_then(Value::as_str).unwrap_or("") {
"minecraft:div" => {
let r = f("right");
@@ -425,14 +425,14 @@ impl Providers {
}
/// A plain `context_int_provider` value or reference (no context conditions).
pub fn int_value(&self, v: &Value) -> i32 {
self.eval(v, false, &self.ints, 0) as i32
Self::eval(v, false, &self.ints, 0) as i32
}
/// A plain `context_float_provider` value or reference; `default` when absent.
pub fn float_value(&self, v: &Value, default: f32) -> f32 {
if v.is_null() {
default
} else {
self.eval(v, false, &self.floats, 0) as f32
Self::eval(v, false, &self.floats, 0) as f32
}
}
#[cfg(test)]
@@ -446,14 +446,14 @@ impl Providers {
items
.get(&stack.item)
.and_then(|i| i.fuel.as_ref())
.map_or(0, |(time, _)| self.eval(time, fast, &self.ints, 0) as i32)
.map_or(0, |(time, _)| Self::eval(time, fast, &self.ints, 0) as i32)
}
pub fn speed(&self, items: &Items, stack: &ItemStack, fast: bool) -> f32 {
items
.get(&stack.item)
.and_then(|i| i.fuel.as_ref())
.map_or(1.0, |(_, speed)| {
self.eval(speed, fast, &self.floats, 0) as f32
Self::eval(speed, fast, &self.floats, 0) as f32
})
}
}
+5 -5
View File
@@ -1741,10 +1741,10 @@ impl Game<'_> {
let state = self.world.block(pos[0], pos[1], pos[2]);
let f = self.res.facts().get(state);
if !self.res.facts().is_air(state)
&& !(f.fluid != Fluid::None
&& !f.waterlogged
&& &*f.name != "minecraft:kelp"
&& f.render_shape != horizon_client::blocks::RenderShape::Model)
&& (f.fluid == Fluid::None
|| f.waterlogged
|| &*f.name == "minecraft:kelp"
|| f.render_shape == horizon_client::blocks::RenderShape::Model)
&& !matches!(
&*f.name,
"minecraft:water" | "minecraft:lava" | "minecraft:bubble_column"
@@ -3510,7 +3510,7 @@ impl Game<'_> {
return Ok(true);
}
// Block foods attempt placement before starting consumption.
if !on_block && !(info.block.is_some() && block_hit.is_some()) && self.start_eating(&info) {
if !on_block && (info.block.is_none() || block_hit.is_none()) && self.start_eating(&info) {
return Ok(true);
}
// BoatItem.use also performs its own fluid/block raycast.
+2 -5
View File
@@ -1,6 +1,6 @@
//! Chat, the command registries and the per-world state behind commands
//! (game rules, the world clock, difficulty), bound to the game.
use super::{Dim, Game, Screen};
use super::{Game, Screen};
use horizon_client::{
chat::{Chat, ChatAction, ChatScreen, Commands, SYSTEM_INDICATOR},
command::Registries,
@@ -695,10 +695,7 @@ impl Game<'_> {
/// Advance the overworld clock (ServerClockManager.tick) when
/// `advance_time` allows it.
pub(super) fn advance_clock(&mut self) {
if !self.ui.rules.bool("advance_time")
|| self.ui.clock.paused
|| self.dim == Dim::Nether && false
{
if !self.ui.rules.bool("advance_time") || self.ui.clock.paused {
return;
}
let c = &mut self.ui.clock;
+1 -1
View File
@@ -38,7 +38,7 @@ impl DebugHost for Host<'_, '_> {
// the menu as it always has (key_pressed).
let g = &mut *self.game;
if without_menu && g.screen == Screen::Playing {
g.pause_menu = !(g.has_singleplayer_server() && !g.is_published());
g.pause_menu = !g.has_singleplayer_server() || g.is_published();
g.screen = Screen::Paused;
g.capture(false);
g.mining = None;
@@ -205,7 +205,9 @@ impl Game<'_> {
return;
};
let [x, y, z] = p.position;
if !(x.is_finite() && y.is_finite() && z.is_finite())
if !x.is_finite()
|| !y.is_finite()
|| !z.is_finite()
|| !p.yaw.is_finite()
|| !p.pitch.is_finite()
{
+2 -3
View File
@@ -544,7 +544,7 @@ impl Game<'_> {
/// (`LivingEntity.forceAddEffect`): the effect replaces any of its kind.
/// Other entities' effects are not shown.
fn remote_effect(&mut self, p: &play::UpdateMobEffect) {
if !self.remote.as_ref().is_some_and(|r| r.entity_id == p.id) {
if self.remote.as_ref().is_none_or(|r| r.entity_id != p.id) {
return;
}
let Some(id) = self.remote_effect_id(p.effect) else {
@@ -4318,8 +4318,7 @@ impl Game<'_> {
/// Keys with a multiplayer meaning; returns true when consumed.
pub(super) fn remote_key(&mut self, key: KeyCode) -> Result<bool> {
if self.screen != Screen::Playing {
if key == KeyCode::KeyE && self.screen == Screen::Inventory
|| key == KeyCode::Escape && self.screen == Screen::Inventory
if (key == KeyCode::KeyE || key == KeyCode::Escape) && self.screen == Screen::Inventory
{
self.remote_close_container();
self.screen = Screen::Playing;
+13 -13
View File
@@ -1051,7 +1051,7 @@ impl LootContext<'_> {
continue;
}
// LootPool: rolls.getInt (Mth.randomBetweenInclusive for uniform rolls).
let rolls = ctx.int_number(&pool["rolls"], random).max(0) as u32;
let rolls = LootContext::int_number(&pool["rolls"], random).max(0) as u32;
for _ in 0..rolls {
let mut produced = Vec::new();
ctx.choose(
@@ -1085,7 +1085,7 @@ impl LootContext<'_> {
fn enchantment_level(&self, id: &str) -> u32 {
self.held.map_or(0, |h| h.enchantment_level(id))
}
fn number<R: RandomSource>(&self, v: &Value, random: &mut R) -> f32 {
fn number<R: RandomSource>(v: &Value, random: &mut R) -> f32 {
match v {
Value::Number(n) => n.as_f64().unwrap_or(0.0) as f32,
Value::Object(o) => match o
@@ -1097,8 +1097,8 @@ impl LootContext<'_> {
o.get("value").and_then(Value::as_f64).unwrap_or(0.0) as f32
}
"minecraft:uniform" => {
let min = self.number(o.get("min").unwrap_or(&Value::Null), random);
let max = self.number(o.get("max").unwrap_or(&Value::Null), random);
let min = Self::number(o.get("min").unwrap_or(&Value::Null), random);
let max = Self::number(o.get("max").unwrap_or(&Value::Null), random);
// UniformGenerator.getFloat / getInt (Mth.nextInt) differ; use int for counts.
if max <= min {
min
@@ -1107,8 +1107,8 @@ impl LootContext<'_> {
}
}
"minecraft:binomial" => {
let n = self.number(o.get("n").unwrap_or(&Value::Null), random) as u32;
let p = self.number(o.get("p").unwrap_or(&Value::Null), random);
let n = Self::number(o.get("n").unwrap_or(&Value::Null), random) as u32;
let p = Self::number(o.get("p").unwrap_or(&Value::Null), random);
(0..n).filter(|_| random.next_float() < p).count() as f32
}
_ => 1.0,
@@ -1116,22 +1116,22 @@ impl LootContext<'_> {
_ => 1.0,
}
}
fn int_number<R: RandomSource>(&self, v: &Value, random: &mut R) -> i32 {
fn int_number<R: RandomSource>(v: &Value, random: &mut R) -> i32 {
if let Value::Object(o) = v
&& o.get("type")
.and_then(Value::as_str)
.unwrap_or("minecraft:uniform")
== "minecraft:uniform"
{
let min = self.int_number(o.get("min").unwrap_or(&Value::Null), random);
let max = self.int_number(o.get("max").unwrap_or(&Value::Null), random);
let min = Self::int_number(o.get("min").unwrap_or(&Value::Null), random);
let max = Self::int_number(o.get("max").unwrap_or(&Value::Null), random);
return if max <= min {
min
} else {
min + random.next_int_bound(max - min + 1).unwrap_or(0)
};
}
self.number(v, random).round() as i32
Self::number(v, random).round() as i32
}
fn condition<R: RandomSource>(&self, c: &Value, random: &mut R) -> bool {
let (kind, c) = match c {
@@ -1157,7 +1157,7 @@ impl LootContext<'_> {
.into_iter()
.flatten()
.all(|t| self.condition(t, random)),
"minecraft:random_chance" => random.next_float() < self.number(&c["chance"], random),
"minecraft:random_chance" => random.next_float() < Self::number(&c["chance"], random),
"minecraft:table_bonus" => {
// BonusLevelTableCondition: chances[min(level, len - 1)].
let level =
@@ -1378,7 +1378,7 @@ impl LootContext<'_> {
}
match f["type"].as_str().or(f["function"].as_str()).unwrap_or("") {
"minecraft:set_count" => {
let n = self.int_number(&f["count"], random);
let n = Self::int_number(&f["count"], random);
let base = if f["add"].as_bool() == Some(true) {
stack.count as i32
} else {
@@ -1421,7 +1421,7 @@ impl LootContext<'_> {
// Attacker's level x count, rounded (looting).
let level = self.enchantment_level(f["enchantment"].as_str().unwrap_or(""));
if level > 0 && self.killed_by_player && self.block.is_empty() {
let add = level as f32 * self.number(&f["count"], random);
let add = level as f32 * Self::number(&f["count"], random);
stack.count = (stack.count as i32 + add.round() as i32).max(0) as u32;
if let Some(limit) = f["limit"].as_i64().filter(|l| *l > 0) {
stack.count = stack.count.min(limit as u32);
+4 -4
View File
@@ -405,7 +405,7 @@ pub fn tick(
}
// Mob.tickHeadTurn -> BodyRotationControl.clientTick (a frozen
// creaking's waits).
if m.alive() && !(super::creaking::is_creaking(m) && !super::creaking::can_move(m)) {
if m.alive() && (!super::creaking::is_creaking(m) || super::creaking::can_move(m)) {
m.body_rotation_tick();
}
events.append(&mut m.outbox);
@@ -752,8 +752,8 @@ impl Mob {
pub fn pushable(&self) -> bool {
self.alive()
&& !matches!(self.species(), Species::Bat | Species::Shulker)
&& !(self.kind.flags.climber && self.climbing)
&& !(self.species() == Species::Creaking && !super::creaking::can_move(self))
&& (!self.kind.flags.climber || !self.climbing)
&& (self.species() != Species::Creaking || super::creaking::can_move(self))
}
}
/// LivingEntity.onClimbable for the pusher (Spider.onClimbable: climbing a wall).
@@ -780,7 +780,7 @@ fn push_entities(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
let self_pushable = m.alive()
&& m.species() != Species::Shulker
&& !on_climbable(m, w)
&& !(m.species() == Species::Creaking && !super::creaking::can_move(m));
&& (m.species() != Species::Creaking || super::creaking::can_move(m));
let mut targets: Vec<(Who, Vec3)> = Vec::new();
if let Some(p) = &w.player
// Entity.push: passengers of the same vehicle never push each other.
+1 -1
View File
@@ -1046,7 +1046,7 @@ impl Goal for GrowCrop {
}
fn can_use(&mut self, m: &mut Mob, cx: &mut Cx) -> bool {
// The 0.3 roll comes only after the crop count: it draws randomness.
let usable = !get(m).is_some_and(|b| b.crops_grown >= 10)
let usable = get(m).is_none_or(|b| b.crops_grown < 10)
&& m.random.next_float() >= 0.3
&& has_nectar(m)
&& hive_valid(m, cx.w);
+3 -3
View File
@@ -167,9 +167,9 @@ impl MobWorld<'_> {
let Ok(block) = self.collision.collision_block(state) else {
continue;
};
if !block.large_collision_shape
&& !block.moving_piston
&& !(column && meets(Axis::Y, y))
if !(block.large_collision_shape
|| block.moving_piston
|| (column && meets(Axis::Y, y)))
{
continue;
}
@@ -677,7 +677,7 @@ impl B {
.is_some_and(|l| l.contains(&Who::Player));
!reachable
};
if !(can_attack(m, cx.w, target) && !tired && alive && !stop_when) {
if !can_attack(m, cx.w, target) || tired || !alive || stop_when {
set_attack_target(m, None);
}
*running = true;
+1 -1
View File
@@ -426,7 +426,7 @@ impl Goal for MoveThroughVillage {
self.visited.remove(0);
}
let Some(s) = state(m) else { return false };
if !(s.active_raid && !s.raid_over) || m.ai.target.is_some() {
if !s.active_raid || s.raid_over || m.ai.target.is_some() {
return false;
}
let Some(homes) = s.homes.clone() else {
@@ -2777,8 +2777,8 @@ impl B {
let on_or_over = jumpable(here) || jumpable([here[0], here[1] - 1, here[2]]);
let still = m.is_baby()
&& bed.is_some_and(jumpable)
&& !(!on_or_over && *time_left <= 0)
&& !(on_or_over && *jumps <= 0);
&& (on_or_over || *time_left > 0)
&& (!on_or_over || *jumps > 0);
if !still {
self.do_stop(m, cx);
return;
@@ -3171,7 +3171,7 @@ fn follow_trading_condition(m: &Mob, w: &MobWorld) -> bool {
m.extra.flag2
&& m.alive()
&& !m.fluids.in_water
&& !(m.hurt_time > 0)
&& m.hurt_time <= 0
&& w.player
.as_ref()
.is_some_and(|p| m.distance_sqr(p.position) <= 16.0)
+1 -1
View File
@@ -457,7 +457,7 @@ pub fn can_receive_vibration(m: &Mob, _now: i64, ctx: &Context) -> bool {
&& m.alive()
&& !st.brain.mem.vibration_cooldown.present()
&& !digging_or_emerging(m)
&& !(ctx.living && !ctx.targetable)
&& (!ctx.living || ctx.targetable)
}
/// `VibrationSystem.Listener.handleGameEvent` for the warden: a free
/// listener within 16 blocks of its eyes schedules what it can hear.
+1 -1
View File
@@ -3233,7 +3233,7 @@ impl ParticleEngine {
} => {
p.base_tick(level);
let (fluid, source) = level.fluid_source(ParticleLevel::block_at(p.position));
if !p.removed && !(fluid == Fluid::Water && source) {
if !(p.removed || (fluid == Fluid::Water && source)) {
p.removed = true;
}
if !p.removed && p.position[1] >= y_end {