mirror of
https://github.com/horizon-rust/horizon.git
synced 2026-11-07 11:06:11 -10:00
Compare commits
216
Commits
main
...
cg21/union
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c002989c82 | ||
|
|
65b0cb2521 | ||
|
|
add777206d | ||
|
|
91c84ca76d | ||
|
|
de23ad4338 | ||
|
|
56108d1b37 | ||
|
|
e6bd4cf76c | ||
|
|
cf7e635cb0 | ||
|
|
d6f9367ff1 | ||
|
|
fbbf0ac64c | ||
|
|
c07049a77f | ||
|
|
83fcd89847 | ||
|
|
6f67726a5b | ||
|
|
1318853025 | ||
|
|
3fef8426d4 | ||
|
|
bd374a9f30 | ||
|
|
f1cb0920ce | ||
|
|
b2604a3963 | ||
|
|
18d98c064a | ||
|
|
686697840d | ||
|
|
dcfab95680 | ||
|
|
d560f1534f | ||
|
|
8194ef9740 | ||
|
|
2cb20cda62 | ||
|
|
fa09f3486f | ||
|
|
b3e41ac6b5 | ||
|
|
6cead02e34 | ||
|
|
02f0970cd4 | ||
|
|
cfbbc077cc | ||
|
|
db87ac7956 | ||
|
|
5fc4723bab | ||
|
|
c3198c9c17 | ||
|
|
3c83854938 | ||
|
|
3e10fb465b | ||
|
|
06f666db57 | ||
|
|
789326bb92 | ||
|
|
c8d55feca3 | ||
|
|
3f8f346851 | ||
|
|
755a6acc76 | ||
|
|
21117506d2 | ||
|
|
ed6125756c | ||
|
|
8ae648d67d | ||
|
|
7c92e49971 | ||
|
|
6f29f197a0 | ||
|
|
e6605b2364 | ||
|
|
11d72958f4 | ||
|
|
e304294056 | ||
|
|
0904969572 | ||
|
|
a2950bce2f | ||
|
|
4f6b549e5d | ||
|
|
1397756847 | ||
|
|
71827f3b4d | ||
|
|
2cb278ab3c | ||
|
|
56f2552241 | ||
|
|
aae895a096 | ||
|
|
e414d77f68 | ||
|
|
c33e47a33b | ||
|
|
260b564fe1 | ||
|
|
9d008e809f | ||
|
|
98d98f4dde | ||
|
|
6def29e16f | ||
|
|
fab334a930 | ||
|
|
fe0d9733ad | ||
|
|
b9381720d4 | ||
|
|
e70f4650ab | ||
|
|
1c71afafab | ||
|
|
8ff13ea185 | ||
|
|
9f89c65d34 | ||
|
|
f2460134fe | ||
|
|
f0e1d992ef | ||
|
|
e60ce10870 | ||
|
|
292cecbda3 | ||
|
|
5211bdd224 | ||
|
|
e42a82e9b9 | ||
|
|
d77569c672 | ||
|
|
937dcba5b8 | ||
|
|
d8b49e8697 | ||
|
|
c1ebf5d1b0 | ||
|
|
71b8f39eb5 | ||
|
|
36f6ab9839 | ||
|
|
d3b28edfb6 | ||
|
|
9c49424b4d | ||
|
|
6a65ee1124 | ||
|
|
ad70f755d7 | ||
|
|
d2ca443d6f | ||
|
|
716cc7f102 | ||
|
|
64279fa1ce | ||
|
|
c35436a7da | ||
|
|
393b8ef7e6 | ||
|
|
15be176380 | ||
|
|
8905aaf0dd | ||
|
|
9ad735b9d7 | ||
|
|
b463f1c80a | ||
|
|
a8ccf43d2b | ||
|
|
6964ee8ece | ||
|
|
6f19f06634 | ||
|
|
bbc1ffb408 | ||
|
|
4c78d32e36 | ||
|
|
4516f54e2b | ||
|
|
9809bf38b6 | ||
|
|
c752c21246 | ||
|
|
82055fb57d | ||
|
|
739d4fe187 | ||
|
|
24744aae44 | ||
|
|
73aef0ce8e | ||
|
|
7115c708e1 | ||
|
|
82c8398c6b | ||
|
|
8f78fdeb7b | ||
|
|
ed9fdb5208 | ||
|
|
6120c8c0ad | ||
|
|
53ea3e7224 | ||
|
|
462787aee1 | ||
|
|
da736d56d6 | ||
|
|
e872d3ae54 | ||
|
|
484cc945aa | ||
|
|
0c127ec1d9 | ||
|
|
a14da6bb70 | ||
|
|
3114fc66e9 | ||
|
|
452fca8bdd | ||
|
|
ab40cd63e6 | ||
|
|
00f2663e7b | ||
|
|
91d6bdba85 | ||
|
|
4248048ab6 | ||
|
|
7f5e3384b3 | ||
|
|
0300ad8922 | ||
|
|
e8ae26c270 | ||
|
|
b62095dfcb | ||
|
|
ba3b567f54 | ||
|
|
5d3e9d218d | ||
|
|
36ef05b0b9 | ||
|
|
49ad61035b | ||
|
|
3842d851d8 | ||
|
|
c987778e97 | ||
|
|
b28108128d | ||
|
|
c50557ea0b | ||
|
|
f364c4f9c6 | ||
|
|
9841ce7824 | ||
|
|
83a6f5c7b9 | ||
|
|
18f4dd92ae | ||
|
|
47654b62a3 | ||
|
|
2f3dade42f | ||
|
|
af49fd7dc3 | ||
|
|
af6faa88e5 | ||
|
|
e71d4281ac | ||
|
|
26626e8c27 | ||
|
|
7102727197 | ||
|
|
70868f3208 | ||
|
|
aff673a08d | ||
|
|
2e642857fc | ||
|
|
147e5269c7 | ||
|
|
b3a499d85d | ||
|
|
3c013dac75 | ||
|
|
b913dab5e5 | ||
|
|
e87e839c97 | ||
|
|
8c8f857313 | ||
|
|
9c427dfae0 | ||
|
|
13144a82a1 | ||
|
|
ef711f8b1f | ||
|
|
601e7918a8 | ||
|
|
dd3697bb4d | ||
|
|
273729aac8 | ||
|
|
94592a35ac | ||
|
|
728bf14aa7 | ||
|
|
53501ab94e | ||
|
|
581dc08cf5 | ||
|
|
85a6ce0921 | ||
|
|
1b4fe0f067 | ||
|
|
fd0f09d6f6 | ||
|
|
06fb03567e | ||
|
|
c418034f10 | ||
|
|
c273a7271e | ||
|
|
5b9a66089e | ||
|
|
4c72a3a44f | ||
|
|
8691d9a8e8 | ||
|
|
d2105fe66c | ||
|
|
79bfb8fcb8 | ||
|
|
20630b1230 | ||
|
|
8d77913ea5 | ||
|
|
66637220ef | ||
|
|
5fa423169f | ||
|
|
183382cd2b | ||
|
|
84aba7b3d4 | ||
|
|
329ce1b724 | ||
|
|
e2a399aff0 | ||
|
|
2a0824cf5f | ||
|
|
a4d0f76edd | ||
|
|
00e2cfec29 | ||
|
|
a5fa40d2ee | ||
|
|
cc39d57e07 | ||
|
|
0a5e80de7b | ||
|
|
b7c47ccbf9 | ||
|
|
9c3450622b | ||
|
|
3615c65d18 | ||
|
|
7cc8def23f | ||
|
|
e553db9bb5 | ||
|
|
790b191ed1 | ||
|
|
d136dda092 | ||
|
|
a8205dd80d | ||
|
|
f252941ac1 | ||
|
|
30fa41ddbd | ||
|
|
e2781f7939 | ||
|
|
d338bcd070 | ||
|
|
8697f3fd3f | ||
|
|
6bc8a8b889 | ||
|
|
4825e537cc | ||
|
|
2e91bd84e9 | ||
|
|
5d72fdd8c2 | ||
|
|
3287a74d64 | ||
|
|
946f47b3ec | ||
|
|
09078949d7 | ||
|
|
265965445d | ||
|
|
f5f7448909 | ||
|
|
9e3956282a | ||
|
|
408a75aeb3 | ||
|
|
19a5098b14 | ||
|
|
a7ff22eea0 |
No files matched your search
@@ -11,7 +11,7 @@ Feature → files → harness for the most-changed areas: [docs/architecture.md]
|
||||
- **Keep your runs away from real player data.** Any game or launcher you start gets fresh `mktemp -d`
|
||||
folders in `HORIZON_HOME` (the game's data), `HORIZON_LAUNCHER_HOME`, `XDG_DATA_HOME` and
|
||||
`XDG_CONFIG_HOME`, plus `HORIZON_LAUNCHER_NO_SELF_UPDATE=1` and `HORIZON_NO_AUDIO=1`, and, for the
|
||||
launcher, `HORIZON_LAUNCHER_TRASH` and `HORIZON_LAUNCHER_CLIPBOARD` pointing into the scratch home. Never write to
|
||||
launcher, `HORIZON_LAUNCHER_TRASH`, `HORIZON_LAUNCHER_CLIPBOARD` and `HORIZON_LAUNCHER_DESKTOP` pointing into the scratch home. Never write to
|
||||
`~/.local/share/{applications,horizon,horizon-launcher}` or `~/.local/bin`.
|
||||
- **Mark what an agent posts.** A PR body starts with a line naming whose agent opened it and with what.
|
||||
Ludovic's agents write `> 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself.`, and a
|
||||
|
||||
@@ -54,7 +54,7 @@ pub fn main() -> Result<()> {
|
||||
match c["axis"].as_i64() {
|
||||
Some(axis @ 0..=2) => {
|
||||
let line = record("electric_spark");
|
||||
particles::along_axis(&mut random, axis as usize, p, |p, v| {
|
||||
particles::along_axis(&mut random, axis as usize, p, (10, 19), |p, v| {
|
||||
lines.push(line(p, v))
|
||||
});
|
||||
}
|
||||
|
||||
@@ -75,6 +75,10 @@ pub fn main() -> Result<()> {
|
||||
registry: assets.registry,
|
||||
raining_at: &|_| false,
|
||||
marker: target.map(|name| (name, &options as &dyn Fn(_) -> _)),
|
||||
model_offset: &|_, _, _| None,
|
||||
gateway_particles: &|_, _| 0,
|
||||
thundering: false,
|
||||
ultrawarm: false,
|
||||
};
|
||||
engine.seed_randoms(1057, 0, 0);
|
||||
engine.requested = Some(Vec::new());
|
||||
|
||||
@@ -580,7 +580,7 @@ fn player_hurt(player: Option<&PlayerView>, e: &MobEvent) -> bool {
|
||||
match e {
|
||||
MobEvent::AttackPlayer(amount, _) | MobEvent::DamagePlayer { amount, .. } => *amount > 0.0,
|
||||
// ServerExplosion.hurtEntities: within twice the radius every hit does damage.
|
||||
MobEvent::Explode(at, radius) => {
|
||||
MobEvent::Explode(at, radius, _) => {
|
||||
let d = Vec3::new(at[0], at[1], at[2])
|
||||
.distance_squared(p.position)
|
||||
.sqrt();
|
||||
@@ -1050,6 +1050,7 @@ pub fn main() -> horizon_client::Result<()> {
|
||||
off_hand: None,
|
||||
head: None,
|
||||
armor_cover: 0.0,
|
||||
invisible: false,
|
||||
spectator: false,
|
||||
gold_armor: false,
|
||||
hurt_by: None,
|
||||
@@ -1061,6 +1062,7 @@ pub fn main() -> horizon_client::Result<()> {
|
||||
uuid: PLAYER_UUID,
|
||||
allies: Default::default(),
|
||||
remote: false,
|
||||
passenger: false,
|
||||
}
|
||||
});
|
||||
let mut scratch = LegacyRandom::new(0);
|
||||
@@ -1098,6 +1100,7 @@ pub fn main() -> horizon_client::Result<()> {
|
||||
block_tags: &items.block_tags,
|
||||
biomes: &biomes,
|
||||
mob_griefing: true,
|
||||
mob_drops: true,
|
||||
difficulty: LocalDifficulty::new(s.difficulty, world.day_time, 0, 0.0),
|
||||
end: false,
|
||||
world_seed: 0,
|
||||
|
||||
@@ -208,7 +208,7 @@ fn snapshot(out: &mut impl Write, player: &PlayerMotion) -> Result<()> {
|
||||
)),
|
||||
MotionEvent::Emission {
|
||||
state,
|
||||
in_water: true,
|
||||
muffled: true,
|
||||
..
|
||||
} => Some(format!("muffled-step {}", state.0)),
|
||||
MotionEvent::BubbleColumnParticle { bubble, position } => Some(format!(
|
||||
@@ -353,6 +353,7 @@ pub fn main() -> Result<()> {
|
||||
horizon_world::food::Difficulty::Hard,
|
||||
][op["difficulty"].as_u64().unwrap() as usize],
|
||||
natural_regeneration: op["regenerate"].as_bool().unwrap(),
|
||||
..Default::default()
|
||||
};
|
||||
}
|
||||
"food" => {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
//! conditions advancements use).
|
||||
use serde_json::Value;
|
||||
use std::{
|
||||
collections::{BTreeMap, HashMap},
|
||||
collections::{BTreeMap, BTreeSet, HashMap},
|
||||
path::Path,
|
||||
};
|
||||
|
||||
@@ -437,6 +437,8 @@ pub struct EntityView {
|
||||
/// mainhand, offhand, head, chest, legs, feet, body.
|
||||
pub equipment: [Option<ItemView>; 7],
|
||||
pub vehicle: Option<Box<EntityView>>,
|
||||
/// Player: what it looks at within 100 blocks (`PlayerPredicate.lookingAt`).
|
||||
pub looking_at: Option<Box<EntityView>>,
|
||||
pub effects: Vec<(String, i32, i32)>,
|
||||
/// Player: game mode name.
|
||||
pub gamemode: Option<String>,
|
||||
@@ -458,7 +460,7 @@ fn range_f(v: &Value, x: f64) -> bool {
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
fn range_i(v: &Value, x: i64) -> bool {
|
||||
pub fn range_i(v: &Value, x: i64) -> bool {
|
||||
range_f(v, x as f64)
|
||||
}
|
||||
/// A registry id, `#tag`, or list matched against one id.
|
||||
@@ -473,6 +475,51 @@ pub fn id_matches(v: &Value, registry: &str, id: &str, w: &dyn World) -> bool {
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
/// `PotionsPredicate`: the potion in a `HolderSet`, plus a `CollectionPredicate`
|
||||
/// over the potion's effects (`contains`, `count`, `size`).
|
||||
pub fn potions(v: &Value, potion: Option<&str>, w: &dyn World) -> bool {
|
||||
if v.is_null() {
|
||||
return true;
|
||||
}
|
||||
if !v["potions"].is_null() && !potion.is_some_and(|p| id_matches(&v["potions"], "potion", p, w))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
let c = &v["effects"];
|
||||
if c.is_null() {
|
||||
return true;
|
||||
}
|
||||
let effects: Vec<(String, i32, i32)> = potion
|
||||
.and_then(crate::brewing::potion)
|
||||
.map(|d| {
|
||||
d.effects
|
||||
.iter()
|
||||
.map(|(id, dur, amp)| (format!("minecraft:{id}"), *amp, *dur))
|
||||
.collect()
|
||||
})
|
||||
.unwrap_or_default();
|
||||
// `MobEffectsPredicate.test`: the one listed effect, amplifier and duration.
|
||||
let test = |pred: &Value, e: &(String, i32, i32)| {
|
||||
pred.as_object().is_some_and(|m| {
|
||||
m.get(&e.0).is_some_and(|want| {
|
||||
range_i(&want["amplifier"], i64::from(e.1))
|
||||
&& range_i(&want["duration"], i64::from(e.2))
|
||||
&& want["ambient"].as_bool().is_none_or(|b| !b)
|
||||
&& want["visible"].as_bool().is_none_or(|b| b)
|
||||
})
|
||||
})
|
||||
};
|
||||
c["contains"]
|
||||
.as_array()
|
||||
.is_none_or(|l| l.iter().all(|p| effects.iter().any(|e| test(p, e))))
|
||||
&& c["count"].as_array().is_none_or(|l| {
|
||||
l.iter().all(|entry| {
|
||||
let n = effects.iter().filter(|e| test(&entry["test"], e)).count();
|
||||
range_i(&entry["count"], n as i64)
|
||||
})
|
||||
})
|
||||
&& range_i(&c["size"], effects.len() as i64)
|
||||
}
|
||||
/// `ItemPredicate`.
|
||||
pub fn item(v: &Value, it: &ItemView, w: &dyn World) -> bool {
|
||||
if v.is_null() {
|
||||
@@ -614,6 +661,18 @@ fn components(expected: &Value, have: &[(String, String)]) -> bool {
|
||||
})
|
||||
})
|
||||
}
|
||||
/// `DistancePredicate.matches` between two points.
|
||||
pub fn distance(v: &Value, a: [f64; 3], b: [f64; 3]) -> bool {
|
||||
let d = [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
|
||||
range_f(&v["x"], d[0].abs())
|
||||
&& range_f(&v["y"], d[1].abs())
|
||||
&& range_f(&v["z"], d[2].abs())
|
||||
&& range_f(&v["horizontal"], (d[0] * d[0] + d[2] * d[2]).sqrt())
|
||||
&& range_f(
|
||||
&v["absolute"],
|
||||
(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]).sqrt(),
|
||||
)
|
||||
}
|
||||
/// `EntityPredicate` (26.x keyed sub-predicates).
|
||||
pub fn entity(v: &Value, e: &EntityView, w: &dyn World, origin: [f64; 3]) -> bool {
|
||||
if v.is_null() {
|
||||
@@ -629,21 +688,7 @@ pub fn entity(v: &Value, e: &EntityView, w: &dyn World, origin: [f64; 3]) -> boo
|
||||
"minecraft:stepping_on" => {
|
||||
location(p, [e.position[0], e.position[1] - 0.5, e.position[2]], w)
|
||||
}
|
||||
"minecraft:distance" | "distance" => {
|
||||
let d = [
|
||||
e.position[0] - origin[0],
|
||||
e.position[1] - origin[1],
|
||||
e.position[2] - origin[2],
|
||||
];
|
||||
range_f(&p["x"], d[0].abs())
|
||||
&& range_f(&p["y"], d[1].abs())
|
||||
&& range_f(&p["z"], d[2].abs())
|
||||
&& range_f(&p["horizontal"], (d[0] * d[0] + d[2] * d[2]).sqrt())
|
||||
&& range_f(
|
||||
&p["absolute"],
|
||||
(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]).sqrt(),
|
||||
)
|
||||
}
|
||||
"minecraft:distance" | "distance" => distance(p, e.position, origin),
|
||||
"minecraft:flags" | "flags" => {
|
||||
let f = |k: &str, have: bool| p[k].as_bool().is_none_or(|want| want == have);
|
||||
f("is_on_fire", e.on_fire)
|
||||
@@ -678,11 +723,16 @@ pub fn entity(v: &Value, e: &EntityView, w: &dyn World, origin: [f64; 3]) -> boo
|
||||
})
|
||||
})
|
||||
}),
|
||||
"minecraft:type_specific/player" => p["gamemode"].as_array().is_none_or(|modes| {
|
||||
e.gamemode
|
||||
.as_deref()
|
||||
.is_some_and(|g| modes.iter().any(|m| m.as_str() == Some(g)))
|
||||
}),
|
||||
"minecraft:type_specific/player" => {
|
||||
p["gamemode"].as_array().is_none_or(|modes| {
|
||||
e.gamemode
|
||||
.as_deref()
|
||||
.is_some_and(|g| modes.iter().any(|m| m.as_str() == Some(g)))
|
||||
}) && (p["looking_at"].is_null()
|
||||
|| e.looking_at
|
||||
.as_ref()
|
||||
.is_some_and(|t| entity(&p["looking_at"], t, w, origin)))
|
||||
}
|
||||
"minecraft:type_specific/lightning" => {
|
||||
range_i(&p["blocks_set_on_fire"], 0)
|
||||
&& (p["entity_struck"].is_null()
|
||||
@@ -703,6 +753,87 @@ pub fn entity(v: &Value, e: &EntityView, w: &dyn World, origin: [f64; 3]) -> boo
|
||||
}
|
||||
true
|
||||
}
|
||||
/// `KilledByArrowTrigger.TriggerInstance.matches`: the weapon, each listed
|
||||
/// victim condition matched by a distinct victim, and the count of entity types.
|
||||
pub fn killed_by_arrow(
|
||||
c: &Value,
|
||||
me: &EntityView,
|
||||
victims: &[EntityView],
|
||||
weapon: Option<&ItemView>,
|
||||
w: &dyn World,
|
||||
) -> bool {
|
||||
fn ctx<'a>(e: &'a EntityView, me: &EntityView) -> Entities<'a> {
|
||||
Entities {
|
||||
this: Some(e),
|
||||
origin: me.position,
|
||||
tool: None,
|
||||
block_pos: None,
|
||||
}
|
||||
}
|
||||
if !conditions(&c["player"], &ctx(me, me), w) {
|
||||
return false;
|
||||
}
|
||||
if !c["fired_from_weapon"].is_null()
|
||||
&& !weapon.is_some_and(|it| item(&c["fired_from_weapon"], it, w))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
let mut left: Vec<&EntityView> = victims.iter().collect();
|
||||
for want in c["victims"].as_array().into_iter().flatten() {
|
||||
let Some(i) = left.iter().position(|e| conditions(want, &ctx(e, me), w)) else {
|
||||
return false;
|
||||
};
|
||||
left.remove(i);
|
||||
}
|
||||
let kinds: BTreeSet<&str> = victims.iter().map(|e| e.kind.as_str()).collect();
|
||||
range_i(&c["unique_entity_types"], kinds.len() as i64)
|
||||
}
|
||||
/// A damage event as `DamagePredicate` sees it.
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct DamageView {
|
||||
/// The damage type id (`minecraft:arrow`).
|
||||
pub kind: String,
|
||||
/// `DamageSource.getDirectEntity` and `getEntity`.
|
||||
pub direct: Option<EntityView>,
|
||||
pub source: Option<EntityView>,
|
||||
/// `DamageSource.isDirect`: the direct entity is the causing one.
|
||||
pub is_direct: bool,
|
||||
/// The damage before and after the shield took its share.
|
||||
pub original: f32,
|
||||
pub actual: f32,
|
||||
pub blocked: bool,
|
||||
}
|
||||
/// `DamagePredicate`, with its `DamageSourcePredicate` as `type`.
|
||||
pub fn damage(v: &Value, d: &DamageView, w: &dyn World, origin: [f64; 3]) -> bool {
|
||||
if v.is_null() {
|
||||
return true;
|
||||
}
|
||||
let by = |key: &str, e: &Option<EntityView>| {
|
||||
v[key].is_null() || e.as_ref().is_some_and(|e| entity(&v[key], e, w, origin))
|
||||
};
|
||||
if !range_f(&v["dealt"], f64::from(d.original))
|
||||
|| !range_f(&v["taken"], f64::from(d.actual))
|
||||
|| !by("source_entity", &d.source)
|
||||
|| v["blocked"].as_bool().is_some_and(|b| b != d.blocked)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
let ty = &v["type"];
|
||||
let tags_ok = ty["tags"].as_array().into_iter().flatten().all(|t| {
|
||||
let tag = t["id"].as_str().unwrap_or("");
|
||||
let tag = tag.strip_prefix('#').unwrap_or(tag);
|
||||
w.in_tag("damage_type", tag, &d.kind) == t["expected"].as_bool().unwrap_or(true)
|
||||
});
|
||||
let direct_ok = ty["direct_entity"].is_null()
|
||||
|| d.direct
|
||||
.as_ref()
|
||||
.is_some_and(|e| entity(&ty["direct_entity"], e, w, origin));
|
||||
let source_ok = ty["source_entity"].is_null()
|
||||
|| d.source
|
||||
.as_ref()
|
||||
.is_some_and(|e| entity(&ty["source_entity"], e, w, origin));
|
||||
tags_ok && direct_ok && source_ok && ty["is_direct"].as_bool().is_none_or(|b| b == d.is_direct)
|
||||
}
|
||||
/// The entities a loot-style condition list may refer to.
|
||||
pub struct Entities<'a> {
|
||||
pub this: Option<&'a EntityView>,
|
||||
|
||||
@@ -8,7 +8,7 @@ use crate::{
|
||||
blocks::{BlockFacts, Fluid},
|
||||
command::args::GameMode,
|
||||
items::ItemStack,
|
||||
particles::{ParticleEngine, ParticleOptions, ParticleType as T},
|
||||
particles::{ParticleEngine, ParticleOptions, ParticleType as T, along_axis},
|
||||
world::World,
|
||||
};
|
||||
use horizon_core::{
|
||||
@@ -73,6 +73,22 @@ enum Animate {
|
||||
waterlogged: bool,
|
||||
},
|
||||
EndPortal,
|
||||
/// A powered lever: its facing and the direction it is attached toward.
|
||||
Lever {
|
||||
facing: [i32; 3],
|
||||
connected: [i32; 3],
|
||||
},
|
||||
/// A powered repeater.
|
||||
Repeater {
|
||||
facing: [i32; 3],
|
||||
delay: i32,
|
||||
},
|
||||
/// A free-hanging stalactite tip that is not waterlogged.
|
||||
PointedDripstone,
|
||||
WitherRose,
|
||||
EndGateway,
|
||||
/// A lightning rod, by the axis it points along (0, 1, 2 for X, Y, Z).
|
||||
LightningRod(usize),
|
||||
}
|
||||
fn step(facing: &str) -> [i32; 3] {
|
||||
match facing {
|
||||
@@ -87,6 +103,7 @@ fn step(facing: &str) -> [i32; 3] {
|
||||
fn classify(name: &str, prop: &dyn Fn(&str) -> Option<String>) -> Animate {
|
||||
let name = name.strip_prefix("minecraft:").unwrap_or(name);
|
||||
let lit = prop("lit").as_deref() == Some("true");
|
||||
let powered = prop("powered").as_deref() == Some("true");
|
||||
let facing = || step(&prop("facing").unwrap_or_default());
|
||||
match name {
|
||||
"torch" => Animate::Torch(T::Flame),
|
||||
@@ -167,6 +184,38 @@ fn classify(name: &str, prop: &dyn Fn(&str) -> Option<String>) -> Animate {
|
||||
waterlogged: prop("waterlogged").as_deref() == Some("true"),
|
||||
},
|
||||
"end_portal" => Animate::EndPortal,
|
||||
"lever" if powered => Animate::Lever {
|
||||
facing: facing(),
|
||||
// FaceAttachedHorizontalDirectionalBlock.getConnectedDirection.
|
||||
connected: match prop("face").as_deref() {
|
||||
Some("ceiling") => [0, -1, 0],
|
||||
Some("floor") => [0, 1, 0],
|
||||
_ => facing(),
|
||||
},
|
||||
},
|
||||
"repeater" if powered => Animate::Repeater {
|
||||
facing: facing(),
|
||||
delay: prop("delay").and_then(|d| d.parse().ok()).unwrap_or(1),
|
||||
},
|
||||
"pointed_dripstone"
|
||||
if prop("vertical_direction").as_deref() == Some("down")
|
||||
&& prop("thickness").as_deref() == Some("tip")
|
||||
&& prop("waterlogged").as_deref() != Some("true") =>
|
||||
{
|
||||
Animate::PointedDripstone
|
||||
}
|
||||
"wither_rose" => Animate::WitherRose,
|
||||
"end_gateway" => Animate::EndGateway,
|
||||
_ if name == "lightning_rod" || name.ends_with("_lightning_rod") => {
|
||||
let [dx, dy, _] = facing();
|
||||
Animate::LightningRod(if dx != 0 {
|
||||
0
|
||||
} else if dy != 0 {
|
||||
1
|
||||
} else {
|
||||
2
|
||||
})
|
||||
}
|
||||
"sculk_sensor" | "calibrated_sculk_sensor"
|
||||
if prop("sculk_sensor_phase").as_deref() == Some("active") =>
|
||||
{
|
||||
@@ -237,6 +286,8 @@ pub struct AnimateTables {
|
||||
burnable: Vec<bool>,
|
||||
/// Biome id -> ambient particles and probabilities (`minecraft:visual/ambient_particles`).
|
||||
ambient: Vec<Vec<(T, f32)>>,
|
||||
/// Per state: 1 for a pointed dripstone, 2 for one whose tip points down.
|
||||
dripstone: Vec<u8>,
|
||||
}
|
||||
impl AnimateTables {
|
||||
pub fn load(root: &Path, registry: &BlockRegistry, biomes: &Biomes) -> crate::Result<Self> {
|
||||
@@ -302,8 +353,25 @@ impl AnimateTables {
|
||||
}
|
||||
}
|
||||
}
|
||||
let dripstone = (0..registry.len() as u32)
|
||||
.map(|id| {
|
||||
registry.state(BlockStateId(id)).map_or(0, |s| {
|
||||
let name = s.name.strip_prefix("minecraft:").unwrap_or(&s.name);
|
||||
if name != "pointed_dripstone" {
|
||||
0
|
||||
} else if s.properties.get("vertical_direction").map(String::as_str)
|
||||
== Some("down")
|
||||
{
|
||||
2
|
||||
} else {
|
||||
1
|
||||
}
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
Ok(Self {
|
||||
kinds,
|
||||
dripstone,
|
||||
impermeable: by_state("minecraft:impermeable"),
|
||||
power_provider: by_state("minecraft:enchantment_power_provider"),
|
||||
power_transmitter: by_state("minecraft:enchantment_power_transmitter"),
|
||||
@@ -335,6 +403,14 @@ pub struct AnimateContext<'a> {
|
||||
pub raining_at: &'a dyn Fn([i32; 3]) -> bool,
|
||||
/// Creative main-hand marker block and a resolver for each placed state's sprite.
|
||||
pub marker: Option<(&'a str, &'a dyn Fn(BlockStateId) -> Option<ParticleOptions>)>,
|
||||
/// `BlockState.getOffset` of a state at (x, z), for blocks with a random model offset.
|
||||
pub model_offset: &'a dyn Fn(BlockStateId, i32, i32) -> Option<[f64; 3]>,
|
||||
/// `TheEndGatewayBlockEntity.getParticleAmount` of the gateway state at a position.
|
||||
pub gateway_particles: &'a dyn Fn(BlockStateId, [i32; 3]) -> usize,
|
||||
/// `Level.isThundering`.
|
||||
pub thundering: bool,
|
||||
/// The dimension has `water_evaporates` and drips lava from dripstone (the Nether).
|
||||
pub ultrawarm: bool,
|
||||
}
|
||||
|
||||
/// `ClientLevel.getMarkerParticleTarget`: only the selected main-hand item counts.
|
||||
@@ -383,6 +459,9 @@ impl AnimateContext<'_> {
|
||||
],
|
||||
))
|
||||
}
|
||||
fn offset_of(&self, state: BlockStateId, p: [i32; 3]) -> [f64; 3] {
|
||||
(self.model_offset)(state, p[0], p[2]).unwrap_or([0.0; 3])
|
||||
}
|
||||
fn foliage(&self, p: [i32; 3]) -> u32 {
|
||||
let biome = self
|
||||
.world
|
||||
@@ -1027,6 +1106,99 @@ fn block_animate_tick(
|
||||
let p = [fx + r.next_double(), fy + 0.8, fz + r.next_double()];
|
||||
add(engine, T::Smoke, p, [0.0; 3]);
|
||||
}
|
||||
Animate::Lever { facing, connected } => {
|
||||
// LeverBlock.animateTick: a powered lever puffs red dust a quarter of the time.
|
||||
if engine.random().next_float() < 0.25 {
|
||||
// LeverBlock.makeParticle with scale 0.5.
|
||||
let at = |base: f64, i: usize| {
|
||||
base + 0.5 + 0.1 * f64::from(-facing[i]) + 0.2 * f64::from(-connected[i])
|
||||
};
|
||||
let p = [at(fx, 0), at(fy, 1), at(fz, 2)];
|
||||
engine.add(&ParticleOptions::dust([1.0, 0.0, 0.0], 0.5), p, [0.0; 3]);
|
||||
}
|
||||
}
|
||||
Animate::Repeater { facing, delay } => {
|
||||
// RepeaterBlock.animateTick: dust at one of the torches.
|
||||
let r = engine.random();
|
||||
let x = fx + 0.5 + (r.next_double() - 0.5) * 0.2;
|
||||
let y = fy + 0.4 + (r.next_double() - 0.5) * 0.2;
|
||||
let z = fz + 0.5 + (r.next_double() - 0.5) * 0.2;
|
||||
let mut offset = -5.0f32;
|
||||
if r.next_boolean() {
|
||||
offset = (delay * 2 - 1) as f32;
|
||||
}
|
||||
offset /= 16.0;
|
||||
let xo = f64::from(offset * facing[0] as f32);
|
||||
let zo = f64::from(offset * facing[2] as f32);
|
||||
redstone(engine, [x + xo, y, z + zo]);
|
||||
}
|
||||
Animate::PointedDripstone => dripstone_drip(tables, engine, ctx, state, pos),
|
||||
Animate::WitherRose => {
|
||||
// WitherRoseBlock.animateTick: smoke puffs at the centre of the shape.
|
||||
let center = ctx.shape_y(pos).map_or([0.5; 2], |s| {
|
||||
[(s.2[0] + s.2[1]) / 2.0, (s.2[2] + s.2[3]) / 2.0]
|
||||
});
|
||||
let offset = ctx.offset_of(state, pos);
|
||||
let x = fx + center[0] + offset[0];
|
||||
let z = fz + center[1] + offset[2];
|
||||
for _ in 0..3 {
|
||||
let r = engine.random();
|
||||
if r.next_boolean() {
|
||||
let p = [
|
||||
x + r.next_double() / 5.0,
|
||||
fy + (0.5 - r.next_double()),
|
||||
z + r.next_double() / 5.0,
|
||||
];
|
||||
add(engine, T::Smoke, p, [0.0; 3]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Animate::EndGateway => {
|
||||
// EndGatewayBlock.animateTick: portal particles, one for each visible face.
|
||||
for _ in 0..(ctx.gateway_particles)(state, pos) {
|
||||
let r = engine.random();
|
||||
let mut p = [
|
||||
fx + r.next_double(),
|
||||
fy + r.next_double(),
|
||||
fz + r.next_double(),
|
||||
];
|
||||
let mut v = [
|
||||
(r.next_double() - 0.5) * 0.5,
|
||||
(r.next_double() - 0.5) * 0.5,
|
||||
(r.next_double() - 0.5) * 0.5,
|
||||
];
|
||||
let flip = next_int(r, 2) * 2 - 1;
|
||||
if r.next_boolean() {
|
||||
p[2] = fz + 0.5 + 0.25 * f64::from(flip);
|
||||
v[2] = f64::from(r.next_float() * 2.0 * flip as f32);
|
||||
} else {
|
||||
p[0] = fx + 0.5 + 0.25 * f64::from(flip);
|
||||
v[0] = f64::from(r.next_float() * 2.0 * flip as f32);
|
||||
}
|
||||
add(engine, T::Portal, p, v);
|
||||
}
|
||||
}
|
||||
Animate::LightningRod(axis) => {
|
||||
// LightningRodBlock.animateTick: in a thunderstorm, sparks along the
|
||||
// topmost rod, more often as the game time within 200 ticks grows.
|
||||
if ctx.thundering
|
||||
&& i64::from(next_int(engine.level_random(), 200)) <= ctx.world.game_time % 200
|
||||
&& pos[1]
|
||||
== ctx
|
||||
.world
|
||||
.world_surface(pos[0], pos[2], |id| ctx.facts.is_air(id))
|
||||
- 1
|
||||
{
|
||||
let mut sparks = Vec::new();
|
||||
along_axis(engine.level_random(), axis, pos, (1, 2), |p, v| {
|
||||
sparks.push((p, v));
|
||||
});
|
||||
let options = ParticleOptions::simple(T::ElectricSpark);
|
||||
for (p, v) in sparks {
|
||||
engine.add(&options, p, v);
|
||||
}
|
||||
}
|
||||
}
|
||||
Animate::EnderChest => {
|
||||
for _ in 0..3 {
|
||||
let r = engine.random();
|
||||
@@ -1282,6 +1454,68 @@ fn block_animate_tick(
|
||||
}
|
||||
}
|
||||
}
|
||||
/// `PointedDripstoneBlock.animateTick`: a free-hanging stalactite tip drips the
|
||||
/// fluid above the root of its stalactite.
|
||||
fn dripstone_drip(
|
||||
tables: &AnimateTables,
|
||||
engine: &mut ParticleEngine,
|
||||
ctx: &AnimateContext,
|
||||
state: BlockStateId,
|
||||
pos: [i32; 3],
|
||||
) {
|
||||
let roll = engine.random().next_float();
|
||||
if roll > 0.12 {
|
||||
return;
|
||||
}
|
||||
// getFluidAboveStalactite: findRootBlock climbs at most ten blocks of
|
||||
// stalactite and stops at the first block that is not pointed dripstone.
|
||||
let mut root = None;
|
||||
for step in 1..11 {
|
||||
let p = [pos[0], pos[1] + step, pos[2]];
|
||||
match tables
|
||||
.dripstone
|
||||
.get(ctx.state(p).0 as usize)
|
||||
.copied()
|
||||
.unwrap_or(0)
|
||||
{
|
||||
0 => {
|
||||
root = Some(p);
|
||||
break;
|
||||
}
|
||||
2 => {}
|
||||
_ => return,
|
||||
}
|
||||
}
|
||||
let Some(root) = root else {
|
||||
return;
|
||||
};
|
||||
let above = ctx.facts.get(ctx.state([root[0], root[1] + 1, root[2]]));
|
||||
// Mud above the root counts as a water source unless water evaporates here.
|
||||
let (fluid, source) = if &*above.name == "minecraft:mud" && !ctx.ultrawarm {
|
||||
(Fluid::Water, true)
|
||||
} else {
|
||||
(above.fluid, above.fluid_level >= 8 && !above.fluid_falling)
|
||||
};
|
||||
// canFillCauldron: only a water or lava source passes below a 2% roll.
|
||||
if roll >= 0.02 && !(fluid != Fluid::None && source) {
|
||||
return;
|
||||
}
|
||||
// getDripParticle: no fluid drips what the dimension's default says.
|
||||
let lava = fluid == Fluid::Lava || (fluid == Fluid::None && ctx.ultrawarm);
|
||||
let ty = if lava {
|
||||
T::DrippingDripstoneLava
|
||||
} else {
|
||||
T::DrippingDripstoneWater
|
||||
};
|
||||
let offset = ctx.offset_of(state, pos);
|
||||
// STALACTITE_DRIP_START_PIXEL is the tip's lowest point, 5/16.
|
||||
let p = [
|
||||
f64::from(pos[0]) + 0.5 + offset[0],
|
||||
f64::from(pos[1]) + 0.3125 - 0.0625,
|
||||
f64::from(pos[2]) + 0.5 + offset[2],
|
||||
];
|
||||
add(engine, ty, p, [0.0; 3]);
|
||||
}
|
||||
/// `AbstractCandleBlock.addParticlesAndSound`.
|
||||
fn candle(engine: &mut ParticleEngine, p: [f64; 3]) {
|
||||
let r = engine.random();
|
||||
|
||||
@@ -159,6 +159,8 @@ pub struct ArrowState {
|
||||
pub pickup: Pickup,
|
||||
/// `pickupItemStack`: what picking the arrow up gives.
|
||||
pub pickup_item: crate::items::ItemStack,
|
||||
/// `AbstractArrow.firedFromWeapon`: the crossbow or bow it was shot from.
|
||||
pub fired_from_weapon: Option<crate::items::ItemStack>,
|
||||
pub no_physics: bool,
|
||||
/// `AbstractArrow.getPierceLevel`.
|
||||
pub pierce: u8,
|
||||
@@ -208,6 +210,7 @@ impl ArrowState {
|
||||
last_state: None,
|
||||
pickup: Pickup::Disallowed,
|
||||
pickup_item: crate::items::ItemStack::new("minecraft:arrow", 1),
|
||||
fired_from_weapon: None,
|
||||
no_physics: false,
|
||||
pierce: 0,
|
||||
pierced: Vec::new(),
|
||||
|
||||
@@ -5,7 +5,11 @@
|
||||
//! (`entity-models.json`); transforms, animation and textures follow each
|
||||
//! vanilla renderer. Faces are lit like the `entity` shader: the lightmap at
|
||||
//! the block plus `minecraft_mix_light` with the level's two diffuse lights.
|
||||
use crate::{hud::Rect, mesher::Vertex, world::World};
|
||||
use crate::{
|
||||
hud::Rect,
|
||||
mesher::{CULL_BACK, Vertex},
|
||||
world::World,
|
||||
};
|
||||
use glam::{DVec3, Mat4, Quat, Vec3};
|
||||
use horizon_core::geometry::{
|
||||
Direction,
|
||||
@@ -932,6 +936,30 @@ impl BlockEntityRenderer {
|
||||
let lights = diffuse_lights(scene.nether);
|
||||
self.render_one(scene, pos, kind, base, packed, lights, false, false, out);
|
||||
}
|
||||
/// `TheEndGatewayBlockEntity.shouldRenderFace` for each face of the gateway
|
||||
/// at `pos`: the faces its portal is drawn on.
|
||||
pub fn gateway_faces(
|
||||
&self,
|
||||
world: &World,
|
||||
state: BlockStateId,
|
||||
pos: [i32; 3],
|
||||
) -> Vec<Direction> {
|
||||
Direction::ALL
|
||||
.into_iter()
|
||||
.filter(|&d| {
|
||||
let [dx, dy, dz] = d.normal();
|
||||
let neighbor = world.block(pos[0] + dx, pos[1] + dy, pos[2] + dz);
|
||||
self.visibility.as_ref().is_none_or(|v| {
|
||||
v.lock()
|
||||
.map(|mut v| {
|
||||
v.should_render_face(state, neighbor, d, true)
|
||||
.unwrap_or(true)
|
||||
})
|
||||
.unwrap_or(true)
|
||||
})
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
/// Whether this block state has a block-entity renderer here.
|
||||
pub fn renders(&self, state: u32) -> bool {
|
||||
!matches!(self.kind(state), Kind::None)
|
||||
@@ -1385,6 +1413,7 @@ impl BlockEntityRenderer {
|
||||
m *= around(Mat4::from_rotation_y(turn * decay), pivot);
|
||||
}
|
||||
}
|
||||
let first = out.len();
|
||||
if let Some(paint) =
|
||||
paint("entity/decorated_pot/decorated_pot_base", 0xFFFFFF, packed)
|
||||
{
|
||||
@@ -1402,6 +1431,11 @@ impl BlockEntityRenderer {
|
||||
draw_part(part, side, m, &none, paint, out);
|
||||
}
|
||||
}
|
||||
// `DecoratedPotRenderer` submits every part with `entitySolid`, which culls
|
||||
// back faces: the flat `top` and `bottom` planes show one side each.
|
||||
for vertex in &mut out[first..] {
|
||||
vertex.normal = CULL_BACK;
|
||||
}
|
||||
}
|
||||
Kind::EndPortal => {
|
||||
// TheEndPortalRenderer.TRANSFORMATION: y from 6/16 to 12/16; only the
|
||||
@@ -1432,22 +1466,8 @@ impl BlockEntityRenderer {
|
||||
out,
|
||||
);
|
||||
}
|
||||
// AbstractEndPortalRenderer.extractRenderState: TheEndGatewayBlockEntity.shouldRenderFace.
|
||||
let faces: Vec<Direction> = Direction::ALL
|
||||
.into_iter()
|
||||
.filter(|&d| {
|
||||
let [dx, dy, dz] = d.normal();
|
||||
let neighbor = scene.world.block(pos[0] + dx, pos[1] + dy, pos[2] + dz);
|
||||
self.visibility.as_ref().is_none_or(|v| {
|
||||
v.lock()
|
||||
.map(|mut v| {
|
||||
v.should_render_face(BlockStateId(*state), neighbor, d, true)
|
||||
.unwrap_or(true)
|
||||
})
|
||||
.unwrap_or(true)
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
// AbstractEndPortalRenderer.extractRenderState.
|
||||
let faces = self.gateway_faces(scene.world, BlockStateId(*state), pos);
|
||||
portal_cube(base, &faces, END_GATEWAY_LAYER, out);
|
||||
}
|
||||
Kind::Conduit => {
|
||||
|
||||
@@ -40,6 +40,8 @@ pub struct Interaction {
|
||||
/// The cauldron's new state.
|
||||
pub block: Option<BlockState>,
|
||||
pub sound: Option<&'static str>,
|
||||
/// The custom statistic the player earns (`use_cauldron`, ...).
|
||||
pub stat: Option<&'static str>,
|
||||
}
|
||||
|
||||
fn state(name: &str, level: Option<u8>) -> BlockState {
|
||||
@@ -57,6 +59,7 @@ fn pass() -> Interaction {
|
||||
outcome: Outcome::Pass,
|
||||
block: None,
|
||||
sound: None,
|
||||
stat: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,11 +120,12 @@ fn lowered(cauldron: &BlockState) -> BlockState {
|
||||
}
|
||||
}
|
||||
|
||||
fn changed(block: BlockState, sound: Option<&'static str>) -> Interaction {
|
||||
fn changed(block: BlockState, sound: Option<&'static str>, stat: &'static str) -> Interaction {
|
||||
Interaction {
|
||||
outcome: Outcome::Success,
|
||||
block: Some(block),
|
||||
sound,
|
||||
stat: Some(stat),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,18 +183,22 @@ pub fn interact(
|
||||
stack.data_mut().dyed_color = None;
|
||||
stack.tidy();
|
||||
}
|
||||
return changed(lowered(cauldron), None);
|
||||
return changed(lowered(cauldron), None, "clean_armor");
|
||||
}
|
||||
let fill_bucket = |player: &mut dyn Player, new: &str, can_fill: bool, sound| {
|
||||
if !can_fill {
|
||||
return pass();
|
||||
}
|
||||
filled(player, ItemStack::new(new, 1), true);
|
||||
changed(state("minecraft:cauldron", None), Some(sound))
|
||||
changed(
|
||||
state("minecraft:cauldron", None),
|
||||
Some(sound),
|
||||
"use_cauldron",
|
||||
)
|
||||
};
|
||||
let empty_bucket = |player: &mut dyn Player, block: BlockState, sound| {
|
||||
filled(player, ItemStack::new("minecraft:bucket", 1), true);
|
||||
changed(block, Some(sound))
|
||||
changed(block, Some(sound), "fill_cauldron")
|
||||
};
|
||||
match item {
|
||||
"minecraft:lava_bucket" => {
|
||||
@@ -199,6 +207,7 @@ pub fn interact(
|
||||
outcome: Outcome::Consume,
|
||||
block: None,
|
||||
sound: None,
|
||||
stat: None,
|
||||
}
|
||||
} else {
|
||||
empty_bucket(
|
||||
@@ -221,6 +230,7 @@ pub fn interact(
|
||||
outcome: Outcome::Consume,
|
||||
block: None,
|
||||
sound: None,
|
||||
stat: None,
|
||||
}
|
||||
} else {
|
||||
empty_bucket(
|
||||
@@ -241,6 +251,7 @@ pub fn interact(
|
||||
changed(
|
||||
state("minecraft:water_cauldron", Some(1)),
|
||||
Some("minecraft:item.bottle.empty"),
|
||||
"use_cauldron",
|
||||
)
|
||||
}
|
||||
("water", "minecraft:bucket") => fill_bucket(
|
||||
@@ -255,7 +266,11 @@ pub fn interact(
|
||||
ItemStack::new("minecraft:potion", 1).with_potion("minecraft:water"),
|
||||
true,
|
||||
);
|
||||
changed(lowered(cauldron), Some("minecraft:item.bottle.fill"))
|
||||
changed(
|
||||
lowered(cauldron),
|
||||
Some("minecraft:item.bottle.fill"),
|
||||
"use_cauldron",
|
||||
)
|
||||
}
|
||||
("water", "minecraft:potion") => {
|
||||
if level == 3 || !water_potion {
|
||||
@@ -266,7 +281,7 @@ pub fn interact(
|
||||
// BlockState.cycle on a 1..=3 property
|
||||
next.properties
|
||||
.insert("level".into(), (level % 3 + 1).to_string());
|
||||
changed(next, Some("minecraft:item.bottle.empty"))
|
||||
changed(next, Some("minecraft:item.bottle.empty"), "use_cauldron")
|
||||
}
|
||||
("water", name)
|
||||
if name
|
||||
@@ -283,7 +298,7 @@ pub fn interact(
|
||||
cleaned.data_mut().banner_patterns.pop();
|
||||
cleaned.tidy();
|
||||
filled(player, cleaned, false);
|
||||
changed(lowered(cauldron), None)
|
||||
changed(lowered(cauldron), None, "clean_banner")
|
||||
}
|
||||
("water", name)
|
||||
if name
|
||||
@@ -292,7 +307,7 @@ pub fn interact(
|
||||
.is_some_and(|c| COLORS.contains(&c)) =>
|
||||
{
|
||||
filled(player, held.transmute("minecraft:shulker_box", 1), false);
|
||||
changed(lowered(cauldron), None)
|
||||
changed(lowered(cauldron), None, "clean_shulker_box")
|
||||
}
|
||||
("lava", "minecraft:bucket") => fill_bucket(
|
||||
player,
|
||||
|
||||
@@ -728,6 +728,18 @@ impl Furnace {
|
||||
.recipes_used
|
||||
.entry(recipe_used_key(&recipe.id))
|
||||
.or_insert(0) += 1;
|
||||
// AbstractFurnaceBlockEntity.burn: drying a wet sponge fills
|
||||
// the bucket in the fuel slot.
|
||||
if self.items[0]
|
||||
.as_ref()
|
||||
.is_some_and(|i| &*i.item == "minecraft:wet_sponge")
|
||||
&& self.items[1]
|
||||
.as_ref()
|
||||
.is_some_and(|f| &*f.item == "minecraft:bucket")
|
||||
{
|
||||
self.items[1] =
|
||||
Some(ItemStack::new("minecraft:water_bucket", 1));
|
||||
}
|
||||
if let Some(i) = self.items[0].as_mut() {
|
||||
i.count -= 1;
|
||||
if i.count == 0 {
|
||||
|
||||
@@ -129,15 +129,16 @@ fn periodic(id: &str, tick: i32, amp: i32) -> Option<EffectAction> {
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
/// `InstantenousMobEffect.applyInstantenousEffect` (potions apply these directly).
|
||||
/// `HealOrHarmMobEffect.applyInstantaneousEffect` (potions apply these directly;
|
||||
/// the amount rounds to the nearest whole point).
|
||||
pub fn instant(id: &str, amp: i32, scale: f64) -> Option<EffectAction> {
|
||||
match id {
|
||||
"instant_health" => Some(EffectAction::Heal(
|
||||
(scale * f64::from(4 << amp.min(30))) as i32 as f32,
|
||||
(scale * f64::from(4 << amp.min(30)) + 0.5) as i32 as f32,
|
||||
)),
|
||||
"instant_damage" => Some(EffectAction::Hurt(
|
||||
"minecraft:magic",
|
||||
(scale * f64::from(6 << amp.min(30))) as i32 as f32,
|
||||
(scale * f64::from(6 << amp.min(30)) + 0.5) as i32 as f32,
|
||||
)),
|
||||
"saturation" => Some(EffectAction::Eat(amp + 1, 1.0)),
|
||||
_ => None,
|
||||
@@ -213,8 +214,9 @@ impl PlayerEffects {
|
||||
}
|
||||
/// `LivingEntity.tickEffects` (server part) with the omens' effect ticks:
|
||||
/// `omen` answers `BadOmenMobEffect` (every tick) and `RaidOmenMobEffect`
|
||||
/// (on its last tick). Returns the actions to apply, in order, and
|
||||
/// whether Raid Omen was newly added.
|
||||
/// (on its last tick); `absorption_empty` is `AbsorptionMobEffect`'s
|
||||
/// answer: the effect ends once the absorption is used up. Returns the
|
||||
/// actions to apply, in order, and whether Raid Omen was newly added.
|
||||
///
|
||||
/// Bad Omen turning into a new Raid Omen adds an entry to the map being
|
||||
/// iterated: vanilla's iterator then throws a
|
||||
@@ -224,6 +226,7 @@ impl PlayerEffects {
|
||||
pub fn tick_with(
|
||||
&mut self,
|
||||
omen: &mut dyn FnMut(&EffectInstance) -> OmenTick,
|
||||
absorption_empty: bool,
|
||||
) -> (Vec<EffectAction>, bool) {
|
||||
self.tick_count = self.tick_count.wrapping_add(1);
|
||||
let mut actions = Vec::new();
|
||||
@@ -246,6 +249,7 @@ impl PlayerEffects {
|
||||
let answer = match e.id {
|
||||
"bad_omen" => omen(e),
|
||||
"raid_omen" if t == 1 => omen(e),
|
||||
"absorption" if absorption_empty => OmenTick::Remove,
|
||||
_ => OmenTick::Continue,
|
||||
};
|
||||
match answer {
|
||||
@@ -465,13 +469,13 @@ mod tests {
|
||||
};
|
||||
// The first tick adds Raid Omen and stops there (the iterator's
|
||||
// ConcurrentModificationException): Bad Omen and Speed stay as they were.
|
||||
let (_, added) = fx.tick_with(&mut convert);
|
||||
let (_, added) = fx.tick_with(&mut convert, false);
|
||||
assert!(added);
|
||||
assert_eq!(fx.get("bad_omen").unwrap().duration, 100);
|
||||
assert_eq!(fx.get("speed").unwrap().duration, 50);
|
||||
assert_eq!(fx.get("raid_omen").unwrap().duration, 600);
|
||||
// The second refreshes Raid Omen and drops Bad Omen.
|
||||
let (_, added) = fx.tick_with(&mut convert);
|
||||
let (_, added) = fx.tick_with(&mut convert, false);
|
||||
assert!(!added);
|
||||
assert!(fx.get("bad_omen").is_none());
|
||||
assert_eq!(fx.get("speed").unwrap().duration, 49);
|
||||
@@ -486,9 +490,9 @@ mod tests {
|
||||
seen.push(e.duration);
|
||||
OmenTick::Remove
|
||||
};
|
||||
fx.tick_with(&mut watch);
|
||||
fx.tick_with(&mut watch, false);
|
||||
assert!(fx.get("raid_omen").is_some());
|
||||
fx.tick_with(&mut watch);
|
||||
fx.tick_with(&mut watch, false);
|
||||
assert!(fx.get("raid_omen").is_none());
|
||||
assert_eq!(seen, vec![1]);
|
||||
}
|
||||
|
||||
@@ -44,6 +44,8 @@ struct Out {
|
||||
// entity.vsh's lightMapColor, multiplied in after the overlay.
|
||||
@location(9) light_color: vec4<f32>,
|
||||
@location(10) @interpolate(flat) weather_rect: vec4<f32>,
|
||||
// 1 drops the quad's back-facing pixels (Vertex::normal w = 1), like a culling render type.
|
||||
@location(11) @interpolate(flat) cull: u32,
|
||||
}
|
||||
// Shipped light.glsl; normals are already transformed and RGBA8_SNORM packed.
|
||||
fn entity_light(normal: vec3<f32>, nether: bool) -> f32 {
|
||||
@@ -92,7 +94,10 @@ fn entity_vertex(position: vec3<f32>, uv: vec2<f32>,
|
||||
// minecraft_mix_light: the vertex colour times the cardinal light only.
|
||||
var c = color;
|
||||
var back = c;
|
||||
if normal.w != 0.0 {
|
||||
// Normal w: 0 keeps the baked colour, +-127 shades by the normal, and a small positive 1
|
||||
// keeps the baked colour but culls back faces (entitySolid models such as the decorated pot).
|
||||
out.cull = select(0u, 1u, normal.w > 0.0 && normal.w < 0.5);
|
||||
if abs(normal.w) >= 0.5 {
|
||||
c = vec4(c.rgb * entity_light(normal.xyz, globals.time.y != 0.0), c.a);
|
||||
back = select(c, vec4(back.rgb * entity_light(-normal.xyz, globals.time.y != 0.0), back.a), normal.w < 0.0);
|
||||
}
|
||||
@@ -198,7 +203,7 @@ fn crumbling_uv(uv: vec2<f32>, packed_origin: vec2<f32>, sprite_size: vec2<f32>,
|
||||
// clouds.fsh: alpha fades out towards the cloud fog end.
|
||||
return vec4(color.rgb, color.a * (1.0 - linear_fog(in.spherical, 0.0, globals.fog_ends.y)));
|
||||
}
|
||||
if color.a < 0.1 { discard; }
|
||||
if color.a < 0.1 || (in.cull != 0u && !front) { discard; }
|
||||
// entity.fsh calculateFinalColor: the overlay (hurt red, TNT white) over the
|
||||
// lit texture, then the lightmap, then the glint and fog.
|
||||
color = vec4(mix(in.overlay_color.rgb, color.rgb, in.overlay_color.a), color.a);
|
||||
|
||||
@@ -487,6 +487,10 @@ pub fn mob_to_nbt(m: &Mob, uuid: [i32; 4], raw: Option<&Tag>) -> Tag {
|
||||
map.insert("anger".into(), Tag::compound(Vec::<(&str, Tag)>::new()));
|
||||
}
|
||||
}
|
||||
// Armadillo.addAdditionalSaveData: the time left to the next scute.
|
||||
"minecraft:armadillo" => {
|
||||
map.insert("scute_time".into(), Tag::Int(m.extra.egg_time));
|
||||
}
|
||||
"minecraft:ravager" => {
|
||||
map.insert("AttackTick".into(), Tag::Int(m.extra.counter));
|
||||
map.insert("StunTick".into(), Tag::Int(m.extra.counter2));
|
||||
@@ -1065,6 +1069,12 @@ pub fn mob_from_nbt(tag: &Tag, types: &HashMap<String, Arc<MobType>>, id: u32) -
|
||||
st.vibration = crate::sculk::Data::from_nbt(listener);
|
||||
}
|
||||
}
|
||||
// Armadillo.readAdditionalSaveData: keeps the constructor's time when absent.
|
||||
if m.species() == crate::mobs::Species::Armadillo
|
||||
&& let Some(t) = number(tag.get("scute_time"))
|
||||
{
|
||||
m.extra.egg_time = t as i32;
|
||||
}
|
||||
if m.species() == crate::mobs::Species::Ravager {
|
||||
m.extra.counter = number(tag.get("AttackTick")).unwrap_or(0) as i32;
|
||||
m.extra.counter2 = number(tag.get("StunTick")).unwrap_or(0) as i32;
|
||||
|
||||
+249
-129
@@ -564,6 +564,8 @@ struct GameLevel<'w> {
|
||||
player_collision: Option<PlayerCollision>,
|
||||
/// Minecart boxes (detector rails).
|
||||
cart_boxes: Vec<([f64; 3], [f64; 3])>,
|
||||
/// Each minecart's kind and comparator signal, in `cart_boxes` order.
|
||||
cart_signals: Vec<(minecarts::CartKind, i32)>,
|
||||
/// Arrow and thrown trident boxes (wooden buttons).
|
||||
arrow_boxes: Vec<([f64; 3], [f64; 3])>,
|
||||
/// The other entities that keep blocks from being placed into them.
|
||||
@@ -642,6 +644,37 @@ impl EntityObstructionWorld for BuildingObstruction {
|
||||
}
|
||||
}
|
||||
impl GameLevel<'_> {
|
||||
/// `DetectorRailBlock.getAnalogOutputSignal`: a powered rail reads the
|
||||
/// minecart on it, a command block cart first (its success count, which
|
||||
/// is 0 here), else the first container cart's fullness.
|
||||
fn detector_rail_signal(&self, pos: BlockPos, powered: bool) -> i32 {
|
||||
if !powered {
|
||||
return 0;
|
||||
}
|
||||
let (x, y, z) = (f64::from(pos.x), f64::from(pos.y), f64::from(pos.z));
|
||||
let area = Aabb::new(
|
||||
Vec3::new(x + 0.2, y, z + 0.2),
|
||||
Vec3::new(x + 0.8, y + 0.8, z + 0.8),
|
||||
);
|
||||
let mut container = None;
|
||||
for ((lo, hi), &(kind, signal)) in self.cart_boxes.iter().zip(&self.cart_signals) {
|
||||
let cart = Aabb::new(
|
||||
Vec3::new(lo[0], lo[1], lo[2]),
|
||||
Vec3::new(hi[0], hi[1], hi[2]),
|
||||
);
|
||||
if !area.intersects(cart) {
|
||||
continue;
|
||||
}
|
||||
match kind {
|
||||
minecarts::CartKind::CommandBlock => return 0,
|
||||
minecarts::CartKind::Chest | minecarts::CartKind::Hopper => {
|
||||
container = container.or(Some(signal));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
container.unwrap_or(0)
|
||||
}
|
||||
/// Every entity box that blocks building: the players who aren't
|
||||
/// spectators, the minecarts and the `Blockers` (a removed mob or a marker
|
||||
/// armor stand, whose box is empty, doesn't).
|
||||
@@ -702,6 +735,14 @@ impl LevelAccess for GameLevel<'_> {
|
||||
state: BlockStateId,
|
||||
_direction: Direction,
|
||||
) -> i32 {
|
||||
if let Some(s) = self.registry.state(state)
|
||||
&& s.name == "minecraft:detector_rail"
|
||||
{
|
||||
return self.detector_rail_signal(
|
||||
pos,
|
||||
s.properties.get("powered").is_some_and(|v| v == "true"),
|
||||
);
|
||||
}
|
||||
if let Some(signal) = command_blocks::analog_signal(self.world, (pos.x, pos.y, pos.z)) {
|
||||
return signal;
|
||||
}
|
||||
@@ -1476,6 +1517,8 @@ struct Game<'a> {
|
||||
/// `ClientAvatarState`: walked distance and view bob.
|
||||
avatar: horizon_client::camera::AvatarBob,
|
||||
flash: u32,
|
||||
/// `ClientLevel.rainSoundTime`: ticks of rain since the last rain sound.
|
||||
rain_sound_time: i32,
|
||||
/// Bolts that struck here and sky flashes they made, in total (`status`).
|
||||
lightning_seen: [u32; 2],
|
||||
/// The head of the bed while sleeping; the visual timer also survives waking.
|
||||
@@ -1483,6 +1526,8 @@ struct Game<'a> {
|
||||
sleep_timer: u32,
|
||||
dim: Dim,
|
||||
world_root: PathBuf,
|
||||
/// The world is superflat (`ServerLevel.isFlat`, for every dimension).
|
||||
world_flat: bool,
|
||||
/// A player carried through a portal, re-placed once the destination loads.
|
||||
travelling: Option<(PlayerMotion, Vec3)>,
|
||||
/// A server's players on their way to another level, each waiting for
|
||||
@@ -1558,6 +1603,12 @@ struct Game<'a> {
|
||||
/// Map textures waiting for the next HUD batch to upload them.
|
||||
map_patches: Vec<horizon_client::font::Patch>,
|
||||
text_displays: std::collections::HashMap<i32, text_displays::RemoteTextDisplay>,
|
||||
/// The fence knots a server tracks to this client, by entity id, at their
|
||||
/// block (`LeashFenceKnotEntity`).
|
||||
remote_knots: HashMap<u32, [i32; 3]>,
|
||||
/// The entity ids a hosted server gives the knots its mobs hang on, by
|
||||
/// block, while a lead is tied there.
|
||||
knot_ids: HashMap<[i32; 3], u32>,
|
||||
text_display_vertices: usize,
|
||||
/// Player skin downloads, and which skin each atlas skin slot holds
|
||||
/// (least recently shown first).
|
||||
@@ -2562,8 +2613,14 @@ impl Game<'_> {
|
||||
pickups::Taken::Item(Box::new(item.clone())),
|
||||
pickups::Collector::Player,
|
||||
);
|
||||
// handleTakeItemEntity: the random pitch of a full pickup.
|
||||
let pitch = ((self.world.random.next_float()
|
||||
- self.world.random.next_float())
|
||||
* 0.7
|
||||
+ 1.0)
|
||||
* 2.0;
|
||||
self.audio
|
||||
.play("minecraft:entity.item.pickup", Some(feet), 0.2, 1.0);
|
||||
.play("minecraft:entity.item.pickup", Some(feet), 0.2, pitch);
|
||||
}
|
||||
item.stack = rest;
|
||||
}
|
||||
@@ -2620,6 +2677,7 @@ impl Game<'_> {
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
let cart_signals = self.cart_signals();
|
||||
let arrow_boxes = self
|
||||
.creatures
|
||||
.projectiles
|
||||
@@ -2662,6 +2720,7 @@ impl Game<'_> {
|
||||
};
|
||||
let mut level = GameLevel {
|
||||
cart_boxes,
|
||||
cart_signals,
|
||||
arrow_boxes,
|
||||
blockers,
|
||||
world: &mut self.world,
|
||||
@@ -2716,9 +2775,13 @@ impl Game<'_> {
|
||||
self.process_level_events()
|
||||
}
|
||||
fn attack_block(&mut self, pos: [i32; 3]) -> Result<()> {
|
||||
self.with_level(|b, level, ticks| {
|
||||
b.attack_block(level, ticks, BlockPos::new(pos[0], pos[1], pos[2]));
|
||||
let note = self.with_level(|b, level, ticks| {
|
||||
b.attack_block(level, ticks, BlockPos::new(pos[0], pos[1], pos[2]))
|
||||
});
|
||||
// NoteBlock.attack awards the statistic.
|
||||
if note {
|
||||
self.stats.custom("play_noteblock", 1);
|
||||
}
|
||||
self.process_level_events()
|
||||
}
|
||||
/// Track which chunks are ticking (Ticks needs chunk load/unload).
|
||||
@@ -2990,6 +3053,16 @@ impl Game<'_> {
|
||||
data,
|
||||
} => self.sculk_charge_event(pos, data),
|
||||
LevelEvent::LevelEvent { id: 3007, pos, .. } => self.shriek_event(pos),
|
||||
// LevelEventHandler 2019 and 2020: the crack on a face of the
|
||||
// block being mined, with its hit sound for 2020.
|
||||
LevelEvent::LevelEvent {
|
||||
id: id @ (2019 | 2020),
|
||||
pos,
|
||||
data,
|
||||
} => {
|
||||
let face = horizon_core::geometry::Direction::ALL[data.clamp(0, 5) as usize];
|
||||
self.breaking_block_effects([pos.x, pos.y, pos.z], face.normal(), id == 2020);
|
||||
}
|
||||
LevelEvent::LevelEvent { id: 2004, pos, .. } => {
|
||||
self.spawner_burst([pos.x, pos.y, pos.z])
|
||||
}
|
||||
@@ -3217,6 +3290,8 @@ impl Game<'_> {
|
||||
// Popped as the behaviour emits it (GameLevel::emit).
|
||||
PlayerEffect::DropItem(_) => {}
|
||||
PlayerEffect::EatCake => {
|
||||
// CakeBlock.eat
|
||||
self.stats.custom("eat_cake_slice", 1);
|
||||
if let Some(p) = self.player.as_mut() {
|
||||
let food = &mut p.health.food;
|
||||
food.food = (food.food + 2).min(20);
|
||||
@@ -3350,20 +3425,21 @@ impl Game<'_> {
|
||||
self.open_command_block(key);
|
||||
return;
|
||||
}
|
||||
// SignBlock.useWithoutItem: the text editor, not a container.
|
||||
if horizon_client::signs::sign_kind(&name).is_some() {
|
||||
self.use_sign_empty_hand(pos);
|
||||
return;
|
||||
}
|
||||
if &*name == "minecraft:crafting_table" {
|
||||
self.craft_size = 3;
|
||||
self.craft_table = Some(pos);
|
||||
} else if &*name == "minecraft:ender_chest" {
|
||||
self.open_ender_chest(key);
|
||||
self.container_opener_event(key, true);
|
||||
let at = [
|
||||
f64::from(key.0) + 0.5,
|
||||
f64::from(key.1) + 0.5,
|
||||
f64::from(key.2) + 0.5,
|
||||
];
|
||||
let pitch = self.world.random.next_float() * 0.1 + 0.9;
|
||||
self.audio
|
||||
.play("minecraft:block.ender_chest.open", Some(at), 0.5, pitch);
|
||||
// EnderChestBlock.useWithoutItem
|
||||
self.stats.custom("open_enderchest", 1);
|
||||
if self.container_opener_event(key, true) {
|
||||
self.container_edge_sound(key, true);
|
||||
}
|
||||
} else if &*name == "minecraft:beacon" && self.open_station(pos, &name) {
|
||||
self.world.block_entities.get_or_insert_with(key, || {
|
||||
BlockEntity::for_block(&name).unwrap_or(BlockEntity::Chest(Vec::new()))
|
||||
@@ -3379,7 +3455,7 @@ impl Game<'_> {
|
||||
];
|
||||
self.resolve_container_maps(key, centre);
|
||||
self.container = Some(key);
|
||||
self.container_opener_event(key, true);
|
||||
let first = self.container_opener_event(key, true);
|
||||
self.post_block_game_event(
|
||||
"minecraft:container_open",
|
||||
[key.0, key.1, key.2],
|
||||
@@ -3403,26 +3479,8 @@ impl Game<'_> {
|
||||
if self.guarded_by_piglins(&name) {
|
||||
self.anger_piglins(true);
|
||||
}
|
||||
let sound = if storage::is_shulker_box(&name) {
|
||||
Some("minecraft:block.shulker_box.open")
|
||||
} else if name.contains("chest") {
|
||||
Some("minecraft:block.chest.open")
|
||||
} else if &*name == "minecraft:barrel" {
|
||||
Some("minecraft:block.barrel.open")
|
||||
} else {
|
||||
None
|
||||
};
|
||||
if let Some(sound) = sound {
|
||||
self.audio.play(
|
||||
sound,
|
||||
Some([
|
||||
f64::from(key.0) + 0.5,
|
||||
f64::from(key.1) + 0.5,
|
||||
f64::from(key.2) + 0.5,
|
||||
]),
|
||||
0.5,
|
||||
1.0,
|
||||
);
|
||||
if first {
|
||||
self.container_edge_sound(key, true);
|
||||
}
|
||||
} else if self.open_station(pos, &name) {
|
||||
// Workstation menus: game/stations.rs.
|
||||
@@ -3746,6 +3804,21 @@ impl Game<'_> {
|
||||
{
|
||||
self.hive_broken_by_player(pos, hive, honey, facing);
|
||||
}
|
||||
// InfestedBlock.spawnAfterBreak: its silverfish comes out unless the
|
||||
// tool has silk touch (#prevents_infested_spawns) or blocks don't drop.
|
||||
if facts.name.starts_with("minecraft:infested_")
|
||||
&& !silk
|
||||
&& self.ui.rules.bool("block_drops")
|
||||
{
|
||||
let at = [
|
||||
f64::from(pos[0]) + 0.5,
|
||||
f64::from(pos[1]),
|
||||
f64::from(pos[2]) + 0.5,
|
||||
];
|
||||
if let Some(id) = self.spawn_mob("minecraft:silverfish", at, false) {
|
||||
self.mob_poof(id);
|
||||
}
|
||||
}
|
||||
// SpawnerBlock.spawnAfterBreak pops its experience whatever the tool.
|
||||
let xp = if silk && &*facts.name != "minecraft:spawner" {
|
||||
0
|
||||
@@ -3867,6 +3940,14 @@ impl Game<'_> {
|
||||
self.swing_arm();
|
||||
return Ok(true);
|
||||
}
|
||||
if self.use_sign_applicator(hit.pos, held.as_ref()) {
|
||||
self.swing_arm();
|
||||
return Ok(true);
|
||||
}
|
||||
if self.use_golem_statue(hit.pos, held.as_ref()) {
|
||||
self.swing_arm();
|
||||
return Ok(true);
|
||||
}
|
||||
if self.use_jukebox(hit.pos, held.as_ref()) {
|
||||
self.swing_arm();
|
||||
return Ok(true);
|
||||
@@ -3887,6 +3968,10 @@ impl Game<'_> {
|
||||
self.swing_arm();
|
||||
return Ok(true);
|
||||
}
|
||||
if self.use_beehive(hit.pos, held.as_ref())? {
|
||||
self.swing_arm();
|
||||
return Ok(true);
|
||||
}
|
||||
if self.use_campfire_douse(hit.pos, held.as_ref())? {
|
||||
self.swing_arm();
|
||||
return Ok(true);
|
||||
@@ -3926,6 +4011,20 @@ impl Game<'_> {
|
||||
)
|
||||
});
|
||||
self.process_level_events()?;
|
||||
// NoteBlock.useWithoutItem (tuned) and BellBlock.onHit (rung).
|
||||
if result == horizon_world::level::InteractionResult::Success {
|
||||
let name = self
|
||||
.res
|
||||
.facts()
|
||||
.get(self.world.block(hit.pos[0], hit.pos[1], hit.pos[2]))
|
||||
.name
|
||||
.clone();
|
||||
match &*name {
|
||||
"minecraft:note_block" => self.stats.custom("tune_noteblock", 1),
|
||||
"minecraft:bell" => self.stats.custom("bell_ring", 1),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
if result.consumes_action() {
|
||||
self.swing_arm();
|
||||
return Ok(true);
|
||||
@@ -4229,6 +4328,8 @@ impl Game<'_> {
|
||||
self.release_used_item(&stack, ticks, hand_changed);
|
||||
return;
|
||||
}
|
||||
// ServerPlayer.updateUsingItem: USING_ITEM every tick of the use.
|
||||
self.trigger_using_item(&stack);
|
||||
let Some(info) = self.res.items().get(&stack.item).cloned() else {
|
||||
self.using = None;
|
||||
return;
|
||||
@@ -4295,6 +4396,17 @@ impl Game<'_> {
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
/// `ServerPlayerGameMode.tick` while a player digs: level event 2020 every
|
||||
/// fourth tick since the START (the hit sound), else 2019 (the crack only),
|
||||
/// for everyone around, the digger included (`levelEvent(null, ...)`).
|
||||
fn destroy_progress_event(&mut self, pos: [i32; 3], face: [i32; 3], ticks: u32) {
|
||||
let id = if ticks.is_multiple_of(4) { 2020 } else { 2019 };
|
||||
let direction = horizon_core::geometry::Direction::ALL
|
||||
.iter()
|
||||
.position(|d| d.normal() == face)
|
||||
.unwrap_or(1);
|
||||
self.level_event_at(id, pos, direction as i32);
|
||||
}
|
||||
fn tick_mining(&mut self) -> Result<()> {
|
||||
if self.destroy_delay > 0 {
|
||||
self.destroy_delay -= 1;
|
||||
@@ -4338,6 +4450,11 @@ impl Game<'_> {
|
||||
let state = self.world.block(hit.pos[0], hit.pos[1], hit.pos[2]);
|
||||
let facts = self.res.facts().get(state);
|
||||
if facts.hardness < 0.0 {
|
||||
// The server still counts its destroy ticks on an unbreakable block.
|
||||
let m = self.mining.as_mut().ok_or("mining")?;
|
||||
m.ticks += 1;
|
||||
let (pos, ticks) = (m.pos, m.ticks);
|
||||
self.destroy_progress_event(pos, hit.face, ticks);
|
||||
return Ok(());
|
||||
}
|
||||
// Player.getDestroySpeed / BlockBehaviour.getDestroyProgress.
|
||||
@@ -4368,26 +4485,15 @@ impl Game<'_> {
|
||||
} else {
|
||||
speed / facts.hardness / if harvest { 30.0 } else { 100.0 }
|
||||
};
|
||||
let hit_sound = facts.sounds.clone();
|
||||
self.swing_arm();
|
||||
let m = self.mining.as_mut().ok_or("mining")?;
|
||||
m.progress += progress;
|
||||
m.ticks += 1;
|
||||
let crack = (m.pos, hit.face);
|
||||
if m.ticks % 4 == 1 {
|
||||
let c = [
|
||||
f64::from(m.pos[0]) + 0.5,
|
||||
f64::from(m.pos[1]) + 0.5,
|
||||
f64::from(m.pos[2]) + 0.5,
|
||||
];
|
||||
self.audio.play(
|
||||
&hit_sound.hit,
|
||||
Some(c),
|
||||
(hit_sound.volume + 1.0) / 8.0,
|
||||
hit_sound.pitch * 0.5,
|
||||
);
|
||||
// An instant break at START sends no destroy events.
|
||||
if m.progress < 1.0 || m.ticks > 1 {
|
||||
let (pos, ticks) = (m.pos, m.ticks);
|
||||
self.destroy_progress_event(pos, hit.face, ticks);
|
||||
}
|
||||
self.crack_particle(crack.0, crack.1, state);
|
||||
let m = self.mining.as_mut().ok_or("mining")?;
|
||||
// ServerPlayerGameMode breaks a player's block at once only when it is instant (START's
|
||||
// insta-mine); otherwise it waits for the client's STOP_DESTROY_BLOCK
|
||||
@@ -4741,13 +4847,11 @@ impl Game<'_> {
|
||||
for event in events {
|
||||
match event {
|
||||
MotionEvent::HurtSound(sound) => self.player_hurt_sound(sound, feet),
|
||||
MotionEvent::Emission {
|
||||
state, in_water, ..
|
||||
} if !crouching => {
|
||||
MotionEvent::Emission { state, muffled, .. } if !crouching => {
|
||||
let sounds = self.res.facts().get(state).sounds.clone();
|
||||
// Entity.playStepSound: the block's step sound at 0.15 volume,
|
||||
// muffled under the swim sound in water.
|
||||
let (volume, pitch) = if in_water {
|
||||
let (volume, pitch) = if muffled {
|
||||
(sounds.volume * 0.05, sounds.pitch * 0.8)
|
||||
} else {
|
||||
(sounds.volume * 0.15, sounds.pitch)
|
||||
@@ -4813,6 +4917,10 @@ impl Game<'_> {
|
||||
};
|
||||
self.audio.play(name, Some(feet), volume, pitch);
|
||||
}
|
||||
// Player.causeFallDamage: a fall of 2 blocks or more counts.
|
||||
MotionEvent::Fall(horizon_client::landing::FallEvent::Statistic(cm)) => {
|
||||
self.stats.custom("fall_one_cm", cm)
|
||||
}
|
||||
// LivingEntity.checkFallDamage: the block's crumbs where the fall landed.
|
||||
MotionEvent::Fall(horizon_client::landing::FallEvent::Particles {
|
||||
state,
|
||||
@@ -6055,41 +6163,15 @@ impl Game<'_> {
|
||||
if let Some(key) = self.container.take() {
|
||||
// A cart's or chest boat's items go back to it.
|
||||
self.close_cart_container(key);
|
||||
self.container_opener_event(key, false);
|
||||
let last = self.container_opener_event(key, false);
|
||||
self.post_block_game_event(
|
||||
"minecraft:container_close",
|
||||
[key.0, key.1, key.2],
|
||||
Some(horizon_client::mobs::Who::Player),
|
||||
None,
|
||||
);
|
||||
let name = self
|
||||
.res
|
||||
.facts()
|
||||
.get(self.world.block(key.0, key.1, key.2))
|
||||
.name
|
||||
.clone();
|
||||
let sound = if storage::is_shulker_box(&name) {
|
||||
Some("minecraft:block.shulker_box.close")
|
||||
} else if &*name == "minecraft:ender_chest" {
|
||||
Some("minecraft:block.ender_chest.close")
|
||||
} else if name.contains("chest") {
|
||||
Some("minecraft:block.chest.close")
|
||||
} else if &*name == "minecraft:barrel" {
|
||||
Some("minecraft:block.barrel.close")
|
||||
} else {
|
||||
None
|
||||
};
|
||||
if let Some(sound) = sound {
|
||||
self.audio.play(
|
||||
sound,
|
||||
Some([
|
||||
f64::from(key.0) + 0.5,
|
||||
f64::from(key.1) + 0.5,
|
||||
f64::from(key.2) + 0.5,
|
||||
]),
|
||||
0.5,
|
||||
1.0,
|
||||
);
|
||||
if last {
|
||||
self.container_edge_sound(key, false);
|
||||
}
|
||||
self.world.modified.insert((key.0 >> 4, key.2 >> 4));
|
||||
}
|
||||
@@ -6609,6 +6691,7 @@ impl Game<'_> {
|
||||
self.player_menu_sound(sound);
|
||||
}
|
||||
let crafted = std::mem::take(&mut menu.crafted);
|
||||
let brewed = std::mem::take(&mut menu.brewed);
|
||||
let equipped = std::mem::take(&mut menu.equipped);
|
||||
for (i, stack) in after.into_iter().enumerate() {
|
||||
if let Some(g) = game_of[i] {
|
||||
@@ -6624,6 +6707,9 @@ impl Game<'_> {
|
||||
self.player_drop(stack);
|
||||
}
|
||||
self.award_crafted(&crafted);
|
||||
for stack in &brewed {
|
||||
self.trigger_brewed_potion(stack);
|
||||
}
|
||||
if furnace_before > furnace_after
|
||||
&& self.remote.is_none()
|
||||
&& let (Some(pos), Some(p)) = (self.container, self.player.as_ref())
|
||||
@@ -7943,13 +8029,15 @@ impl Game<'_> {
|
||||
}
|
||||
/// The visual and sound part of `Player.doSweepAttack` after a successful hit.
|
||||
pub(super) fn sweep_attack(&mut self, at: [f64; 3], from: Option<[f64; 3]>) {
|
||||
self.particles.add(
|
||||
&horizon_client::particles::ParticleOptions::simple(
|
||||
horizon_client::particles::ParticleType::SweepAttack,
|
||||
),
|
||||
at,
|
||||
[0.0; 3],
|
||||
let sweep = horizon_client::particles::ParticleOptions::simple(
|
||||
horizon_client::particles::ParticleType::SweepAttack,
|
||||
);
|
||||
self.particles.add(&sweep, at, [0.0; 3]);
|
||||
// Player.sweepAttack's `sendParticles(SWEEP_ATTACK, ..., 0, dx, 0, dz, 0)`:
|
||||
// the offset is the one from the player to the particle.
|
||||
let origin = from.unwrap_or(at);
|
||||
let spread = [at[0] - origin[0], 0.0, at[2] - origin[2]];
|
||||
self.lan_send_particles(&sweep, at, spread, 0.0, 0);
|
||||
self.audio
|
||||
.play("minecraft:entity.player.attack.sweep", from, 1.0, 1.0);
|
||||
}
|
||||
@@ -8104,11 +8192,6 @@ impl Game<'_> {
|
||||
let sweep = self.sweep_attack_position(scale, crit);
|
||||
let (knockback, knockback_attack) = self.extra_knockback(&target_kind, scale);
|
||||
self.attack_ticks = 0;
|
||||
if let Some(p) = self.player.as_mut()
|
||||
&& !self.creative
|
||||
{
|
||||
p.cause_food_exhaustion(0.1);
|
||||
}
|
||||
let player = self.player.as_ref();
|
||||
let from = player.map(|p| [p.position.x, p.position.y, p.position.z]);
|
||||
if knockback_attack {
|
||||
@@ -8123,6 +8206,15 @@ impl Game<'_> {
|
||||
None => horizon_client::mobs::Damage::of(horizon_client::mobs::DamageKind::Generic),
|
||||
};
|
||||
let landed = self.hurt_by_player(index, amount, source);
|
||||
if landed {
|
||||
let victim = self.mob_entity(&self.mobs[index]);
|
||||
self.player_hit(
|
||||
&victim,
|
||||
creatures::damage_type(source.kind, true),
|
||||
None,
|
||||
amount,
|
||||
);
|
||||
}
|
||||
if let Some(p) = self.player.as_mut() {
|
||||
if p.attack_log.len() >= 64 {
|
||||
p.attack_log.remove(0);
|
||||
@@ -8188,6 +8280,14 @@ impl Game<'_> {
|
||||
0.2,
|
||||
(actual * 0.5) as u32,
|
||||
);
|
||||
// The players a server serves are sent them too.
|
||||
self.lan_send_particles(
|
||||
&indicator,
|
||||
[feet[0], feet[1] + height * 0.5, feet[2]],
|
||||
[0.1, 0.0, 0.1],
|
||||
0.2,
|
||||
(actual * 0.5) as u32,
|
||||
);
|
||||
}
|
||||
self.last_hurt_by_player
|
||||
.insert(self.mobs[index].id, self.lan_acting);
|
||||
@@ -8208,16 +8308,32 @@ impl Game<'_> {
|
||||
// The hurt or death sound the mob raised (getHurtSound / getDeathSound,
|
||||
// its voice pitch from its own random).
|
||||
let queued = std::mem::take(&mut self.mobs[index].outbox);
|
||||
let mut infested = false;
|
||||
for event in queued {
|
||||
if let horizon_client::mobs::MobEvent::Sound(s, at, volume, pitch) = event {
|
||||
self.audio
|
||||
.play(&format!("minecraft:{s}"), Some(at), volume, pitch);
|
||||
} else {
|
||||
// Left for the end of the tick.
|
||||
self.mobs[index].outbox.push(event);
|
||||
match event {
|
||||
horizon_client::mobs::MobEvent::Sound(s, at, volume, pitch) => {
|
||||
self.audio
|
||||
.play(&format!("minecraft:{s}"), Some(at), volume, pitch);
|
||||
}
|
||||
horizon_client::mobs::MobEvent::Infested { .. } => infested = true,
|
||||
other => {
|
||||
// Left for the end of the tick.
|
||||
self.mobs[index].outbox.push(other);
|
||||
}
|
||||
}
|
||||
}
|
||||
if infested {
|
||||
let id = self.mobs[index].id;
|
||||
self.mob_infested(id);
|
||||
}
|
||||
self.weapon_hit(index);
|
||||
// Player.attack: causeFoodExhaustion(0.1F) only when the hit hurt
|
||||
// (inside `if (wasHurt)`), after damageStatsAndHearts.
|
||||
if let Some(p) = self.player.as_mut()
|
||||
&& !self.creative
|
||||
{
|
||||
p.cause_food_exhaustion(0.1);
|
||||
}
|
||||
} else {
|
||||
self.audio
|
||||
.play("minecraft:entity.player.attack.nodamage", from, 1.0, 1.0);
|
||||
@@ -8478,6 +8594,7 @@ impl Game<'_> {
|
||||
book.to_be_displayed.retain(|r| index.contains(r));
|
||||
self.dim = dim;
|
||||
self.world_root = save_root.clone();
|
||||
self.world_flat = horizon_client::save::WorldGen::read(&save_root).is_some_and(|w| w.flat);
|
||||
self.block_ticks = Ticks::new(self.level.seed as i32);
|
||||
self.tick_chunks.clear();
|
||||
self.clear_entities();
|
||||
@@ -8781,6 +8898,10 @@ impl Game<'_> {
|
||||
}
|
||||
self.lan_close(false);
|
||||
self.save_game()?;
|
||||
if let Some(mut remote) = self.remote.take() {
|
||||
// Minecraft.disconnect closes the connection, so the host sees a clean leave.
|
||||
remote.session.disconnect();
|
||||
}
|
||||
self.saved_for_exit = true;
|
||||
Ok(())
|
||||
}
|
||||
@@ -9062,6 +9183,9 @@ impl Game<'_> {
|
||||
if result.outcome == Outcome::Pass {
|
||||
return Ok(false);
|
||||
}
|
||||
if let Some(stat) = result.stat {
|
||||
self.stats.custom(stat, 1);
|
||||
}
|
||||
if let Some(block) = result.block
|
||||
&& let Ok(new) = registry.resolve(&block)
|
||||
{
|
||||
@@ -9171,6 +9295,8 @@ impl Game<'_> {
|
||||
else {
|
||||
return Ok(false);
|
||||
};
|
||||
// BlockTransformer.transformBlock: ITEM_USED_ON_BLOCK before the swap.
|
||||
self.trigger_block("minecraft:item_used_on_block", pos, stack);
|
||||
self.level_set(pos, new)?;
|
||||
// BlockTransformer.TransformParticle.send.
|
||||
self.transform_particle(&particle, pos);
|
||||
@@ -9443,6 +9569,8 @@ impl Game<'_> {
|
||||
if let Some(waxed) = old.and_then(|old| self.res.transformers().waxed(registry, &old))
|
||||
&& let Ok(state) = registry.resolve(&waxed)
|
||||
{
|
||||
// HoneycombItem.useOn: ITEM_USED_ON_BLOCK before the swap.
|
||||
self.trigger_block("minecraft:item_used_on_block", hit.pos, stack);
|
||||
self.level_set(hit.pos, state)?;
|
||||
self.level_event_at(3003, hit.pos, 0);
|
||||
self.audio.play(
|
||||
@@ -10156,37 +10284,7 @@ impl Game<'_> {
|
||||
if self.flash > 0 {
|
||||
self.flash -= 1;
|
||||
}
|
||||
let (rain, _) = self.world.weather.levels(1.0);
|
||||
let Some(eye) = self.eye_position() else {
|
||||
return;
|
||||
};
|
||||
// WeatherEffectRenderer.tickRainParticles: occasional rain sounds.
|
||||
if rain > 0.0 && self.world.random.next_int_bound(3).unwrap_or(1) < (rain * 3.0) as i32 {
|
||||
let r = &mut self.world.random;
|
||||
let (dx, dz) = (
|
||||
r.next_int_bound(21).unwrap_or(10) - 10,
|
||||
r.next_int_bound(21).unwrap_or(10) - 10,
|
||||
);
|
||||
let (x, z) = (eye[0].floor() as i32 + dx, eye[2].floor() as i32 + dz);
|
||||
let top = self.rain_height(x, z);
|
||||
if self.precipitation(x, top, z) == Some(false)
|
||||
&& (top - eye[1] as i32).abs() < 10
|
||||
&& self.world.random.next_int_bound(5).unwrap_or(1) == 0
|
||||
{
|
||||
let above = f64::from(top) > eye[1] + 1.0;
|
||||
let (name, volume, pitch) = if above {
|
||||
("minecraft:weather.rain.above", 0.1, 0.5)
|
||||
} else {
|
||||
("minecraft:weather.rain", 0.2, 1.0)
|
||||
};
|
||||
self.audio.play(
|
||||
name,
|
||||
Some([f64::from(x) + 0.5, f64::from(top), f64::from(z) + 0.5]),
|
||||
volume,
|
||||
pitch,
|
||||
);
|
||||
}
|
||||
}
|
||||
// The rain sounds come with the rain splashes (`tick_particles`).
|
||||
}
|
||||
/// WeatherEffectRenderer: rain and snow columns within the weather radius.
|
||||
fn weather_geometry(
|
||||
@@ -12731,6 +12829,16 @@ impl ApplicationHandler for Game<'_> {
|
||||
}
|
||||
}
|
||||
fn about_to_wait(&mut self, event_loop: &ActiveEventLoop) {
|
||||
if horizon_threads::stop_requests() > 0
|
||||
&& self.pending_save.as_ref().is_none_or(|save| !save.quit)
|
||||
{
|
||||
// SIGTERM, SIGINT or SIGHUP: the shutdown hook's server halt, as a window close.
|
||||
if let Err(error) = self.begin_closing_save(true) {
|
||||
self.error = Some(error);
|
||||
event_loop.exit();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if self.pending_save.is_some() {
|
||||
match self.poll_closing_save() {
|
||||
Ok(true) => event_loop.exit(),
|
||||
@@ -13021,11 +13129,13 @@ impl<'a> Game<'a> {
|
||||
dragging: false,
|
||||
avatar: Default::default(),
|
||||
flash: 0,
|
||||
rain_sound_time: 0,
|
||||
lightning_seen: [0; 2],
|
||||
sleeping: None,
|
||||
sleep_timer: 0,
|
||||
dim: Dim::Overworld,
|
||||
world_root: PathBuf::new(),
|
||||
world_flat: false,
|
||||
travelling: None,
|
||||
server_trips: Vec::new(),
|
||||
level_teleports: Vec::new(),
|
||||
@@ -13075,6 +13185,8 @@ impl<'a> Game<'a> {
|
||||
dragon_model: prepared.dragon_model,
|
||||
map_patches: Vec::new(),
|
||||
text_displays: Default::default(),
|
||||
remote_knots: Default::default(),
|
||||
knot_ids: Default::default(),
|
||||
text_display_vertices: 0,
|
||||
skin_downloads: RefCell::new(horizon_client::skins::Downloader::new(
|
||||
std::env::current_dir()
|
||||
@@ -14217,6 +14329,11 @@ impl Loading {
|
||||
}
|
||||
}
|
||||
fn about_to_wait(&mut self, event_loop: &ActiveEventLoop) {
|
||||
if horizon_threads::stop_requests() > 0 {
|
||||
// No world is open yet: nothing to save.
|
||||
event_loop.exit();
|
||||
return;
|
||||
}
|
||||
if let Err(error) = self.poll_menu_resources() {
|
||||
self.error = Some(error);
|
||||
event_loop.exit();
|
||||
@@ -14494,6 +14611,9 @@ pub fn run() -> Result<()> {
|
||||
{
|
||||
horizon_client::heartbeat::start();
|
||||
}
|
||||
if options.execution_role.is_client() {
|
||||
horizon_threads::catch_stop_signals();
|
||||
}
|
||||
let started = Instant::now();
|
||||
horizon_client::spans::enable(options.spikes.is_some());
|
||||
let vanilla_root = options.resources.clone();
|
||||
|
||||
@@ -9,6 +9,7 @@ use horizon_client::{
|
||||
text::{self, Style, Text},
|
||||
toasts::Slide,
|
||||
};
|
||||
use horizon_core::geometry::Vec3;
|
||||
use serde_json::Value;
|
||||
use std::{
|
||||
collections::{BTreeMap, BTreeSet, VecDeque},
|
||||
@@ -82,6 +83,8 @@ pub(super) struct AdvState {
|
||||
pub(super) quiet: bool,
|
||||
/// The inventory last seen by `inventory_changed`.
|
||||
pub(super) last_inventory: u64,
|
||||
/// `ServerPlayer.levitationStartPos` and `levitationStartTime`.
|
||||
pub(super) levitation: Option<([f64; 3], u64)>,
|
||||
/// While the game acts for a network player (`as_guest`): the
|
||||
/// advancements whose progress changed (`progressChanged`), the recipes
|
||||
/// unlocked and the announcements, for their client and everyone's.
|
||||
@@ -180,6 +183,14 @@ impl adv::World for View<'_, '_> {
|
||||
"block" => items.block_tags.get(tag).is_some_and(|t| t.contains(id)),
|
||||
"entity_type" => self.0.res.mob_data().entity_has(tag, id),
|
||||
"worldgen/biome" => self.0.res.mob_data().biome_has(tag, id),
|
||||
"damage_type" => self
|
||||
.0
|
||||
.res
|
||||
.stations()
|
||||
.enchantments
|
||||
.damage_tags
|
||||
.get(tag)
|
||||
.is_some_and(|t| t.contains(id)),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
@@ -647,6 +658,28 @@ impl Game<'_> {
|
||||
};
|
||||
adv::conditions(&c["player"], &ctx, w)
|
||||
});
|
||||
// ServerPlayer.onEffectAdded and onEffectsRemoved keep the start of a
|
||||
// levitation; tick fires LEVITATION while there is one.
|
||||
let levitating = self
|
||||
.potions
|
||||
.effects
|
||||
.list
|
||||
.iter()
|
||||
.any(|e| e.id == "levitation");
|
||||
match (levitating, self.adv.levitation) {
|
||||
(true, None) => {
|
||||
let at = self
|
||||
.player
|
||||
.as_ref()
|
||||
.map(|p| [p.position.x, p.position.y, p.position.z]);
|
||||
self.adv.levitation = at.map(|at| (at, self.ticks));
|
||||
}
|
||||
(false, Some(_)) => self.adv.levitation = None,
|
||||
_ => {}
|
||||
}
|
||||
if let Some((start, since)) = self.adv.levitation {
|
||||
self.trigger_levitation(start, (self.ticks - since) as i64);
|
||||
}
|
||||
if self.ticks.is_multiple_of(20) {
|
||||
let me = self.player_entity();
|
||||
self.trigger("minecraft:location", |c, w| {
|
||||
@@ -681,6 +714,136 @@ impl Game<'_> {
|
||||
adv::conditions(&c["player"], &pctx, w) && adv::conditions(&c[&key], &ectx, w)
|
||||
});
|
||||
}
|
||||
/// `LevitationTrigger`: how far the player rose from where it started
|
||||
/// levitating, and for how long.
|
||||
fn trigger_levitation(&mut self, start: [f64; 3], duration: i64) {
|
||||
let me = self.player_entity();
|
||||
self.trigger("minecraft:levitation", move |c, w| {
|
||||
let pctx = adv::Entities {
|
||||
this: Some(&me),
|
||||
origin: me.position,
|
||||
tool: None,
|
||||
block_pos: None,
|
||||
};
|
||||
adv::conditions(&c["player"], &pctx, w)
|
||||
&& (c["distance"].is_null() || adv::distance(&c["distance"], start, me.position))
|
||||
&& adv::range_i(&c["duration"], duration)
|
||||
});
|
||||
}
|
||||
/// `ServerPlayer.updateUsingItem`: USING_ITEM for the item in use, with
|
||||
/// what the player looks at (`PlayerPredicate.lookingAt`).
|
||||
pub(super) fn trigger_using_item(&mut self, stack: &ItemStack) {
|
||||
if self.remote.is_some() || self.no_player_here() {
|
||||
return;
|
||||
}
|
||||
let mut me = self.player_entity();
|
||||
me.looking_at = self.looking_at_entity().map(Box::new);
|
||||
let it = item_view(stack);
|
||||
self.trigger("minecraft:using_item", move |c, w| {
|
||||
let pctx = adv::Entities {
|
||||
this: Some(&me),
|
||||
origin: me.position,
|
||||
tool: None,
|
||||
block_pos: None,
|
||||
};
|
||||
adv::conditions(&c["player"], &pctx, w) && adv::item(&c["item"], &it, w)
|
||||
});
|
||||
}
|
||||
/// The mob a 100 block ray from the eyes meets first, if no block is in
|
||||
/// the way (`ProjectileUtil.getEntityHitResult` and `hasLineOfSight`).
|
||||
fn looking_at_entity(&self) -> Option<EntityView> {
|
||||
let eye = self.eye_position()?;
|
||||
let dir = super::view_vector(self.yaw, self.pitch);
|
||||
let (m, _) = self
|
||||
.mobs
|
||||
.iter()
|
||||
.filter(|m| m.alive())
|
||||
.filter_map(|m| Some((m, super::ray_box(eye, dir, 100.0, m.bounds())?)))
|
||||
.min_by(|a, b| a.1.total_cmp(&b.1))?;
|
||||
// `LivingEntity.hasLineOfSight`: eye to the target's eye height,
|
||||
// `ClipContext.Block.COLLIDER`, no fluids, within 128 blocks.
|
||||
let from = Vec3::new(eye[0], eye[1], eye[2]);
|
||||
let to = Vec3::new(m.position.x, m.eye_y(), m.position.z);
|
||||
let world = self.mob_world_base(&[]);
|
||||
let clear = to.distance(from) <= 128.0 && world.clear_between(from, to, false);
|
||||
clear.then(|| self.mob_entity(m))
|
||||
}
|
||||
/// `KilledByArrowTrigger`: what the arrow killed and the weapon it came from.
|
||||
pub(super) fn trigger_killed_by_arrow(
|
||||
&mut self,
|
||||
victims: &[EntityView],
|
||||
weapon: Option<&ItemStack>,
|
||||
) {
|
||||
let me = self.player_entity();
|
||||
let victims = victims.to_vec();
|
||||
let weapon = weapon.map(item_view);
|
||||
self.trigger("minecraft:killed_by_arrow", move |c, w| {
|
||||
adv::killed_by_arrow(c, &me, &victims, weapon.as_ref(), w)
|
||||
});
|
||||
}
|
||||
/// `PlayerHurtEntityTrigger`: the player, the damage and the victim.
|
||||
pub(super) fn trigger_player_hurt_entity(
|
||||
&mut self,
|
||||
victim: &EntityView,
|
||||
damage: &adv::DamageView,
|
||||
) {
|
||||
let me = self.player_entity();
|
||||
let (victim, damage) = (victim.clone(), damage.clone());
|
||||
self.trigger("minecraft:player_hurt_entity", move |c, w| {
|
||||
let pctx = adv::Entities {
|
||||
this: Some(&me),
|
||||
origin: me.position,
|
||||
tool: None,
|
||||
block_pos: None,
|
||||
};
|
||||
let vctx = adv::Entities {
|
||||
this: Some(&victim),
|
||||
..pctx
|
||||
};
|
||||
adv::conditions(&c["player"], &pctx, w)
|
||||
&& adv::damage(&c["damage"], &damage, w, me.position)
|
||||
&& adv::conditions(&c["entity"], &vctx, w)
|
||||
});
|
||||
}
|
||||
/// The player's hit on `victim` as `LivingEntity.hurtServer` reports it:
|
||||
/// `kind` damage of `amount` from `direct` (the player's own hand when
|
||||
/// `None`), nothing blocked.
|
||||
pub(super) fn player_hit(
|
||||
&mut self,
|
||||
victim: &EntityView,
|
||||
kind: &str,
|
||||
direct: Option<EntityView>,
|
||||
amount: f32,
|
||||
) {
|
||||
let me = self.player_entity();
|
||||
self.trigger_player_hurt_entity(
|
||||
victim,
|
||||
&adv::DamageView {
|
||||
kind: kind.to_owned(),
|
||||
is_direct: direct.is_none(),
|
||||
direct: direct.or_else(|| Some(me.clone())),
|
||||
source: Some(me),
|
||||
original: amount,
|
||||
actual: amount,
|
||||
blocked: false,
|
||||
},
|
||||
);
|
||||
}
|
||||
/// `EntityHurtPlayerTrigger`: the player and the damage it took.
|
||||
pub(super) fn trigger_entity_hurt_player(&mut self, damage: &adv::DamageView) {
|
||||
let me = self.player_entity();
|
||||
let damage = damage.clone();
|
||||
self.trigger("minecraft:entity_hurt_player", move |c, w| {
|
||||
let pctx = adv::Entities {
|
||||
this: Some(&me),
|
||||
origin: me.position,
|
||||
tool: None,
|
||||
block_pos: None,
|
||||
};
|
||||
adv::conditions(&c["player"], &pctx, w)
|
||||
&& adv::damage(&c["damage"], &damage, w, me.position)
|
||||
});
|
||||
}
|
||||
/// A player condition plus one item (`item` key).
|
||||
pub(super) fn trigger_item(&mut self, name: &str, stack: &ItemStack) {
|
||||
let me = self.player_entity();
|
||||
@@ -708,6 +871,101 @@ impl Game<'_> {
|
||||
let it = item_view(stack);
|
||||
self.trigger(name, |c, w| adv::item_entity(c, &me, target, &it, w));
|
||||
}
|
||||
/// `ConstructBeaconTrigger`: the pyramid levels of the new beacon.
|
||||
pub(super) fn trigger_construct_beacon(&mut self, levels: i32) {
|
||||
let me = self.player_entity();
|
||||
self.trigger("minecraft:construct_beacon", move |c, w| {
|
||||
let pctx = adv::Entities {
|
||||
this: Some(&me),
|
||||
origin: me.position,
|
||||
tool: None,
|
||||
block_pos: None,
|
||||
};
|
||||
adv::conditions(&c["player"], &pctx, w) && adv::range_i(&c["level"], i64::from(levels))
|
||||
});
|
||||
}
|
||||
/// `BrewedPotionTrigger`: the potion contents of a stack taken from a
|
||||
/// brewing stand.
|
||||
pub(super) fn trigger_brewed_potion(&mut self, stack: &ItemStack) {
|
||||
let me = self.player_entity();
|
||||
let potion = stack.potion().map(str::to_owned);
|
||||
self.trigger("minecraft:brewed_potion", move |c, w| {
|
||||
let pctx = adv::Entities {
|
||||
this: Some(&me),
|
||||
origin: me.position,
|
||||
tool: None,
|
||||
block_pos: None,
|
||||
};
|
||||
adv::conditions(&c["player"], &pctx, w)
|
||||
&& adv::potions(&c["potion"], potion.as_deref(), w)
|
||||
});
|
||||
}
|
||||
/// `EnchantedItemTrigger`: the enchanted item and the levels it cost.
|
||||
pub(super) fn trigger_enchanted_item(&mut self, stack: &ItemStack, levels: i32) {
|
||||
let me = self.player_entity();
|
||||
let it = item_view(stack);
|
||||
self.trigger("minecraft:enchanted_item", move |c, w| {
|
||||
let pctx = adv::Entities {
|
||||
this: Some(&me),
|
||||
origin: me.position,
|
||||
tool: None,
|
||||
block_pos: None,
|
||||
};
|
||||
adv::conditions(&c["player"], &pctx, w)
|
||||
&& adv::item(&c["item"], &it, w)
|
||||
&& adv::range_i(&c["levels"], i64::from(levels))
|
||||
});
|
||||
}
|
||||
/// `TradeTrigger`: the villager and the item the trade gave.
|
||||
pub(super) fn trigger_trade(&mut self, villager: &EntityView, stack: &ItemStack) {
|
||||
let me = self.player_entity();
|
||||
let villager = villager.clone();
|
||||
let it = item_view(stack);
|
||||
self.trigger("minecraft:villager_trade", move |c, w| {
|
||||
let pctx = adv::Entities {
|
||||
this: Some(&me),
|
||||
origin: me.position,
|
||||
tool: None,
|
||||
block_pos: None,
|
||||
};
|
||||
let vctx = adv::Entities {
|
||||
this: Some(&villager),
|
||||
..pctx
|
||||
};
|
||||
adv::conditions(&c["player"], &pctx, w)
|
||||
&& adv::conditions(&c["villager"], &vctx, w)
|
||||
&& adv::item(&c["item"], &it, w)
|
||||
});
|
||||
}
|
||||
/// `FishingRodHookedTrigger`: the rod, what the hook is in (or the hook)
|
||||
/// and the items it caught.
|
||||
pub(super) fn trigger_fishing_rod_hooked(
|
||||
&mut self,
|
||||
rod: &ItemStack,
|
||||
hooked: &EntityView,
|
||||
items: &[ItemStack],
|
||||
) {
|
||||
let me = self.player_entity();
|
||||
let rod = item_view(rod);
|
||||
let hooked = hooked.clone();
|
||||
let items: Vec<ItemView> = items.iter().map(item_view).collect();
|
||||
self.trigger("minecraft:fishing_rod_hooked", move |c, w| {
|
||||
let pctx = adv::Entities {
|
||||
this: Some(&me),
|
||||
origin: me.position,
|
||||
tool: None,
|
||||
block_pos: None,
|
||||
};
|
||||
let ectx = adv::Entities {
|
||||
this: Some(&hooked),
|
||||
..pctx
|
||||
};
|
||||
adv::conditions(&c["player"], &pctx, w)
|
||||
&& adv::item(&c["rod"], &rod, w)
|
||||
&& adv::conditions(&c["entity"], &ectx, w)
|
||||
&& (c["item"].is_null() || items.iter().any(|i| adv::item(&c["item"], i, w)))
|
||||
});
|
||||
}
|
||||
/// `EnterBlockTrigger`: the block, its state properties and the player.
|
||||
pub(super) fn trigger_enter_block(&mut self, state: horizon_world::registry::BlockStateId) {
|
||||
let Some(definition) = self.pack.assets.registry.state(state).cloned() else {
|
||||
|
||||
@@ -131,7 +131,8 @@ impl Game<'_> {
|
||||
let m = &mut self.mobs[i];
|
||||
m.extra.ints[1] -= 1;
|
||||
m.extra.ints[3] = 60;
|
||||
self.spawn_item(ItemStack::new(&item, 1), from, v, 40);
|
||||
// ItemEntity.setDefaultPickUpDelay.
|
||||
self.spawn_item(ItemStack::new(&item, 1), from, v, 10);
|
||||
if self.world.game_time % 7 == 0 && self.world.random.next_double() < 0.9 {
|
||||
const PITCHES: [f32; 16] = [
|
||||
0.5625, 0.625, 0.75, 0.9375, 1.0, 1.0, 1.125, 1.25, 1.5, 1.875, 2.0, 2.25, 2.5,
|
||||
@@ -160,7 +161,7 @@ impl Game<'_> {
|
||||
}
|
||||
// Allay.duplicateAllay: entity event 18, three spawnHeartParticle.
|
||||
let id = self.mobs[index].id;
|
||||
self.particles_around_mob(id, "heart", horizon_client::particles::Burst::ALLAY);
|
||||
self.mob_event_particles(id, 18);
|
||||
self.audio
|
||||
.play("minecraft:block.amethyst_block.chime", Some(at), 2.0, 1.0);
|
||||
self.consume_held();
|
||||
|
||||
@@ -164,11 +164,35 @@ impl Game<'_> {
|
||||
let (was, is) = (previous > 0, b.levels > 0);
|
||||
if !was && is {
|
||||
self.beacon_sound([x, y, z], "minecraft:block.beacon.activate");
|
||||
let levels = b.levels;
|
||||
self.for_each_player(|g| g.beacon_constructed([x, y, z], levels));
|
||||
} else if was && !is {
|
||||
self.beacon_sound([x, y, z], "minecraft:block.beacon.deactivate");
|
||||
}
|
||||
}
|
||||
}
|
||||
/// `BeaconBlockEntity.tick` after activating: `CONSTRUCT_BEACON` for a
|
||||
/// player in the box `AABB(x, y, z, x, y - 4, z).inflate(10, 5, 10)`.
|
||||
fn beacon_constructed(&mut self, p: [i32; 3], levels: i32) {
|
||||
let Some(bb) = self
|
||||
.player
|
||||
.as_ref()
|
||||
.map(|pl| pl.dimensions.bounds(pl.position))
|
||||
else {
|
||||
return;
|
||||
};
|
||||
let (lo, hi) = (bb.min_position(), bb.max_position());
|
||||
let [x, y, z] = p.map(f64::from);
|
||||
if lo.x < x + 10.0
|
||||
&& hi.x > x - 10.0
|
||||
&& lo.y < y + 5.0
|
||||
&& hi.y > y - 9.0
|
||||
&& lo.z < z + 10.0
|
||||
&& hi.z > z - 10.0
|
||||
{
|
||||
self.trigger_construct_beacon(levels);
|
||||
}
|
||||
}
|
||||
pub(super) fn beacon_sound(&mut self, p: [i32; 3], sound: &str) {
|
||||
let at = [
|
||||
f64::from(p[0]) + 0.5,
|
||||
|
||||
@@ -3,8 +3,10 @@
|
||||
//! player breaks the hive or fire reaches it.
|
||||
use super::Game;
|
||||
use horizon_client::{
|
||||
Result,
|
||||
beehive::{self, Beehive, HiveHost, Release},
|
||||
containers::BlockEntity,
|
||||
items::ItemStack,
|
||||
mobs::{Mob, Who, bee},
|
||||
};
|
||||
use horizon_core::{
|
||||
@@ -194,19 +196,139 @@ impl Game<'_> {
|
||||
}
|
||||
self.anger_nearby_bees(at);
|
||||
}
|
||||
/// `BeehiveBlock.useItemOn` with `held` in the acting hand: shears take
|
||||
/// the honeycombs and a glass bottle a honey bottle from a full hive
|
||||
/// (honey level 5), then the honey level resets and, unless a campfire
|
||||
/// smokes the hive, the bees come out angry. True when it took the click.
|
||||
pub(super) fn use_beehive(&mut self, pos: [i32; 3], held: Option<&ItemStack>) -> Result<bool> {
|
||||
let Some(held) = held else { return Ok(false) };
|
||||
let shears = &*held.item == "minecraft:shears";
|
||||
if !shears && &*held.item != "minecraft:glass_bottle" {
|
||||
return Ok(false);
|
||||
}
|
||||
let state = self.world.block(pos[0], pos[1], pos[2]);
|
||||
if !matches!(
|
||||
&*self.res.facts().get(state).name,
|
||||
"minecraft:beehive" | "minecraft:bee_nest"
|
||||
) {
|
||||
return Ok(false);
|
||||
}
|
||||
let prop = |key: &str| {
|
||||
self.pack
|
||||
.assets
|
||||
.registry
|
||||
.state(state)
|
||||
.and_then(|s| s.properties.get(key).cloned())
|
||||
};
|
||||
if prop("honey_level").and_then(|v| v.parse::<i32>().ok()) != Some(5) {
|
||||
return Ok(false);
|
||||
}
|
||||
let facing = beehive::facing_step(prop("facing").as_deref());
|
||||
let at = self
|
||||
.player
|
||||
.as_ref()
|
||||
.map(|p| [p.position.x, p.position.y, p.position.z]);
|
||||
if shears {
|
||||
// dropHoneycomb (harvest/beehive), the shear sound, hurtAndBreak.
|
||||
for stack in self.sequence_loot(
|
||||
"minecraft:harvest/beehive",
|
||||
"minecraft:harvest/beehive",
|
||||
Some(held),
|
||||
) {
|
||||
self.pop_resource(pos, stack);
|
||||
}
|
||||
self.audio
|
||||
.play("minecraft:block.beehive.shear", at, 1.0, 1.0);
|
||||
self.damage_held(1);
|
||||
self.post_block_game_event("minecraft:shear", pos, self.sculk_actor(), None);
|
||||
} else {
|
||||
// shrink(1), then the honey bottle in the hand, the inventory or
|
||||
// on the ground.
|
||||
self.audio.play("minecraft:item.bottle.fill", at, 1.0, 1.0);
|
||||
let cell = self.held_mut();
|
||||
if let Some(s) = cell.as_mut() {
|
||||
s.count -= 1;
|
||||
if s.count == 0 {
|
||||
*cell = None;
|
||||
}
|
||||
}
|
||||
let bottle = ItemStack::new("minecraft:honey_bottle", 1);
|
||||
if self.held().is_none() {
|
||||
*self.held_mut() = Some(bottle);
|
||||
} else if let Some(rest) = self.give(bottle)
|
||||
&& let Some(eye) = self.eye_position()
|
||||
{
|
||||
self.spawn_item(rest, eye, [0.0, 0.1, 0.0], 40);
|
||||
}
|
||||
self.post_block_game_event("minecraft:fluid_pickup", pos, self.sculk_actor(), None);
|
||||
}
|
||||
self.stats.add("used", &held.item, 1);
|
||||
let smokey = beehive::smokey(&self.mob_world_base(&[]), pos);
|
||||
let key = (pos[0], pos[1], pos[2]);
|
||||
if !smokey
|
||||
&& matches!(self.world.block_entities.get(&key), Some(BlockEntity::Beehive(h)) if !h.bees.is_empty())
|
||||
{
|
||||
self.anger_nearby_bees(pos);
|
||||
}
|
||||
// resetHoneyLevel.
|
||||
if let Some(reset) = self.with_props(state, &[("honey_level", "0")]) {
|
||||
self.level_set(pos, reset)?;
|
||||
}
|
||||
if !smokey
|
||||
&& let Some(BlockEntity::Beehive(mut hive)) = self.world.block_entities.take(&key)
|
||||
{
|
||||
// emptyAllLivingFromHive: the bees within 4 blocks of the player
|
||||
// go for them.
|
||||
let released = hive.release_all(
|
||||
pos,
|
||||
facing,
|
||||
None,
|
||||
Release::Emergency,
|
||||
&mut GameHive { game: self },
|
||||
);
|
||||
self.world
|
||||
.block_entities
|
||||
.put(key, BlockEntity::Beehive(hive));
|
||||
if let Some(p) = self.player_view().map(|p| p.position) {
|
||||
for m in self.mobs.iter_mut().filter(|m| released.contains(&m.id)) {
|
||||
if m.distance_sqr(p) <= 16.0 {
|
||||
m.ai.target = Some(Who::Player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// ServerPlayerGameMode.useItemOn: the action was consumed.
|
||||
self.trigger_block("minecraft:item_used_on_block", pos, held);
|
||||
Ok(true)
|
||||
}
|
||||
/// `BeehiveBlock.angerNearbyBees`: bees within 8 blocks (6 up and down)
|
||||
/// without a target go for a player in the same box.
|
||||
fn anger_nearby_bees(&mut self, at: [i32; 3]) {
|
||||
/// without a target go for a random player in the same box, the window's
|
||||
/// own or a guest (`None` is the window's player).
|
||||
pub(super) fn anger_nearby_bees(&mut self, at: [i32; 3]) {
|
||||
let min = Vec3::new(
|
||||
f64::from(at[0]) - 8.0,
|
||||
f64::from(at[1]) - 6.0,
|
||||
f64::from(at[2]) - 8.0,
|
||||
);
|
||||
let area = Aabb::new(min, Vec3::new(min.x + 17.0, min.y + 13.0, min.z + 17.0));
|
||||
if !self
|
||||
let mut players: Vec<Option<u32>> = Vec::new();
|
||||
if self
|
||||
.player_view()
|
||||
.is_some_and(|p| p.bounds.intersects(area))
|
||||
{
|
||||
players.push(None);
|
||||
}
|
||||
if let Some(host) = self.lan.as_ref() {
|
||||
players.extend(
|
||||
host.hub
|
||||
.guests
|
||||
.iter()
|
||||
.filter(|g| host.hub.here(g) && g.loaded && !g.dead)
|
||||
.filter(|g| super::lan_mobs::guest_bounds(g).intersects(area))
|
||||
.map(|g| Some(g.conn)),
|
||||
);
|
||||
}
|
||||
if players.is_empty() {
|
||||
return;
|
||||
}
|
||||
let mut bees: Vec<usize> = (0..self.mobs.len())
|
||||
@@ -219,9 +341,20 @@ impl Game<'_> {
|
||||
.collect();
|
||||
bees.retain(|&i| self.mobs[i].ai.target.is_none());
|
||||
for i in bees {
|
||||
// Util.getRandom over the one player.
|
||||
let _ = self.world.random.next_int_bound(1);
|
||||
// Util.getRandom over the players.
|
||||
let pick = self
|
||||
.world
|
||||
.random
|
||||
.next_int_bound(players.len() as i32)
|
||||
.unwrap_or(0) as usize;
|
||||
self.mobs[i].ai.target = Some(Who::Player);
|
||||
// The player a mob sees is its guest binding, else the window's.
|
||||
if let Some(host) = self.lan.as_mut() {
|
||||
match players[pick] {
|
||||
Some(conn) => host.mob_players.insert(self.mobs[i].id, conn),
|
||||
None => host.mob_players.remove(&self.mobs[i].id),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -76,23 +76,24 @@ impl Game<'_> {
|
||||
/// A player opened (`open`) or closed the container at `key`: the opener
|
||||
/// count block event (`ContainerOpenersCounter` / `ShulkerBoxBlockEntity`
|
||||
/// `startOpen`/`stopOpen`) for chests, ender chests and shulker boxes,
|
||||
/// on both halves of a double chest (`CompoundContainer`).
|
||||
pub(super) fn container_opener_event(&mut self, key: (i32, i32, i32), open: bool) {
|
||||
/// on both halves of a double chest (`CompoundContainer`). True when the
|
||||
/// count went from 0 to 1 or back to 0: the only moments the container
|
||||
/// plays its open or close sound.
|
||||
pub(super) fn container_opener_event(&mut self, key: (i32, i32, i32), open: bool) -> bool {
|
||||
// Spectators never count as openers.
|
||||
if !self.spectator() {
|
||||
self.container_openers_changed(key, open);
|
||||
}
|
||||
!self.spectator() && self.container_openers_changed(key, open)
|
||||
}
|
||||
/// `container_opener_event` for a player who is not a spectator (a guest).
|
||||
pub(super) fn container_openers_changed(&mut self, key: (i32, i32, i32), open: bool) {
|
||||
pub(super) fn container_openers_changed(&mut self, key: (i32, i32, i32), open: bool) -> bool {
|
||||
let pos = [key.0, key.1, key.2];
|
||||
let state = self.world.block(pos[0], pos[1], pos[2]).0;
|
||||
match self.be_anims.ticker(state) {
|
||||
Some(Ticker::Lid) => {
|
||||
self.lid_openers_changed(key, open);
|
||||
let edge = self.lid_openers_changed(key, open);
|
||||
if let Some(other) = self.chest_other_half(key) {
|
||||
self.lid_openers_changed(other, open);
|
||||
}
|
||||
edge
|
||||
}
|
||||
_ if self
|
||||
.res
|
||||
@@ -102,26 +103,27 @@ impl Game<'_> {
|
||||
.as_ref()
|
||||
== "minecraft:barrel" =>
|
||||
{
|
||||
self.barrel_openers_changed(key, open);
|
||||
self.barrel_openers_changed(key, open)
|
||||
}
|
||||
Some(Ticker::Shulker { .. }) => {
|
||||
let shulker = self.be_anims.shulkers.entry(pos).or_default();
|
||||
let (count, _) = if open {
|
||||
let (count, edge) = if open {
|
||||
shulker.start_open()
|
||||
} else {
|
||||
shulker.stop_open()
|
||||
};
|
||||
self.block_entity_event(pos, 1, count);
|
||||
self.lan_block_event(pos, 1, count);
|
||||
edge
|
||||
}
|
||||
_ => {}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
/// `ContainerOpenersCounter.incrementOpeners` / `decrementOpeners` of the
|
||||
/// chest at `key` (the host and the guests are counted), then
|
||||
/// `ChestBlockEntity.signalOpenCount`: block event 1 with the count, here
|
||||
/// and for the guests.
|
||||
fn lid_openers_changed(&mut self, key: (i32, i32, i32), open: bool) {
|
||||
/// and for the guests. True when the count crossed zero.
|
||||
fn lid_openers_changed(&mut self, key: (i32, i32, i32), open: bool) -> bool {
|
||||
let (before, count) = self.count_opener(key, open);
|
||||
let pos = [key.0, key.1, key.2];
|
||||
self.block_entity_event(pos, 1, count);
|
||||
@@ -139,12 +141,15 @@ impl Game<'_> {
|
||||
b.update_neighbors_at(level, ticks, p.offset(0, -1, 0), block);
|
||||
});
|
||||
}
|
||||
(before == 0) != (count == 0)
|
||||
}
|
||||
/// `BarrelBlockEntity.openersCounter`: the first opener opens the barrel
|
||||
/// (`open=true`), the last one to leave closes it (`updateBlockState`).
|
||||
fn barrel_openers_changed(&mut self, key: (i32, i32, i32), open: bool) {
|
||||
/// True when the count crossed zero.
|
||||
fn barrel_openers_changed(&mut self, key: (i32, i32, i32), open: bool) -> bool {
|
||||
let (before, count) = self.count_opener(key, open);
|
||||
if (before == 0) != (count == 0) {
|
||||
let edge = (before == 0) != (count == 0);
|
||||
if edge {
|
||||
self.set_bool_prop(
|
||||
key,
|
||||
"open",
|
||||
@@ -152,6 +157,7 @@ impl Game<'_> {
|
||||
horizon_world::level::flags::UPDATE_ALL,
|
||||
);
|
||||
}
|
||||
edge
|
||||
}
|
||||
/// One opener more (`open`) or less at `key`: the count before and after
|
||||
/// (`ContainerOpenersCounter.incrementOpeners` / `decrementOpeners`).
|
||||
|
||||
@@ -789,6 +789,11 @@ impl Game<'_> {
|
||||
pub(super) fn sync_rules(&mut self) {
|
||||
self.world.health_rules.natural_regeneration =
|
||||
self.ui.rules.bool("natural_health_regeneration");
|
||||
// Player.isInvulnerableTo: the damage-type rules.
|
||||
self.world.health_rules.drowning_damage = self.ui.rules.bool("drowning_damage");
|
||||
self.world.health_rules.fall_damage = self.ui.rules.bool("fall_damage");
|
||||
self.world.health_rules.fire_damage = self.ui.rules.bool("fire_damage");
|
||||
self.world.health_rules.freeze_damage = self.ui.rules.bool("freeze_damage");
|
||||
use horizon_world::food::Difficulty;
|
||||
self.world.health_rules.difficulty = match self.ui.difficulty {
|
||||
0 => Difficulty::Peaceful,
|
||||
|
||||
@@ -36,6 +36,13 @@ pub(super) struct CombatTracker {
|
||||
/// The mob exploding now (`ServerExplosion.source`): its team's friendly
|
||||
/// fire decides whom the blast may hurt.
|
||||
pub(super) explosion_source: Option<u32>,
|
||||
/// The blast now going off comes from a primed TNT, creeper, wither
|
||||
/// skull, wither or TNT minecart, the sources that empty a hive they
|
||||
/// destroy (`BeehiveBlock.getDrops`).
|
||||
pub(super) hive_emptying_blast: bool,
|
||||
/// The mob that owns the projectile exploding now (`getIndirectSourceEntity`):
|
||||
/// the mobs the blast hurts record it as their attacker.
|
||||
pub(super) explosion_owner: Option<u32>,
|
||||
/// Charged creepers whose blast just went off and that have not dropped
|
||||
/// a head yet (`Creeper.droppedSkulls`): they are gone from the mob list,
|
||||
/// but the mobs they killed still ask for their loot.
|
||||
@@ -90,6 +97,19 @@ impl Game<'_> {
|
||||
self.recheck_combat();
|
||||
for e in events {
|
||||
let (name, amount) = match e {
|
||||
// LivingEntity.getDamageAfterMagicAbsorb (Resistance) and
|
||||
// Player.actuallyHurt (absorption hearts) and
|
||||
// LivingEntity.hurtServer (the shield, only for an accepted
|
||||
// hit), in tenths.
|
||||
MotionEvent::Health(HealthEvent::Statistic { name, amount }) => {
|
||||
match *name {
|
||||
"resisted" => self.stats.custom("damage_resisted", *amount),
|
||||
"absorbed" => self.stats.custom("damage_absorbed", *amount),
|
||||
"blocked" => self.stats.custom("damage_blocked_by_shield", *amount),
|
||||
_ => {}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
MotionEvent::Health(HealthEvent::RecordedDamage { source, amount }) => {
|
||||
let Some(d) = self.motion.health.damage.definition(*source) else {
|
||||
continue;
|
||||
@@ -136,6 +156,10 @@ impl Game<'_> {
|
||||
direct,
|
||||
});
|
||||
self.combat.last_damage = now;
|
||||
// InfestedMobEffect.onMobHurt.
|
||||
if self.potions.effects.get("infested").is_some() {
|
||||
self.player_infested();
|
||||
}
|
||||
}
|
||||
self.combat.pending.clear();
|
||||
self.combat.pending_direct.clear();
|
||||
|
||||
@@ -57,6 +57,17 @@ impl Game<'_> {
|
||||
self.audio
|
||||
.play("minecraft:entity.player.burp", self.feet(), 0.5, pitch);
|
||||
}
|
||||
// SuspiciousStewEffects.onConsume, a ConsumableListener: each entry is
|
||||
// added as a `MobEffectInstance(effect, duration)` (amplifier 0).
|
||||
if let Some(data) = stack.extra.as_deref() {
|
||||
for (id, duration) in &data.stew_effects {
|
||||
if let Some(def) = horizon_client::brewing::effect(id) {
|
||||
self.add_player_effect(horizon_client::effects::EffectInstance::new(
|
||||
def.id, *duration, 0,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
for effect in &consumable.effects {
|
||||
self.apply_consume_effect(effect);
|
||||
}
|
||||
|
||||
@@ -44,13 +44,13 @@ impl Game<'_> {
|
||||
slot: usize,
|
||||
stack: Option<ItemStack>,
|
||||
) {
|
||||
if let Some(e) = self
|
||||
.world
|
||||
.block_entities
|
||||
.get_mut(&(chest[0], chest[1], chest[2]))
|
||||
let key = (chest[0], chest[1], chest[2]);
|
||||
if let Some(e) = self.world.block_entities.get_mut(&key)
|
||||
&& let Some(s) = e.slots_mut().get_mut(slot)
|
||||
{
|
||||
*s = stack;
|
||||
// TransportItemsBetweenContainers calls Container.setChanged.
|
||||
self.container_changed(key);
|
||||
}
|
||||
}
|
||||
/// `ContainerOpenersCounter.recheckOpeners` every five ticks: the golems
|
||||
@@ -204,6 +204,64 @@ impl Game<'_> {
|
||||
}
|
||||
}
|
||||
// ---- interactions -----------------------------------------------------
|
||||
/// `WeatheringCopperGolemStatueBlock.useItemOn`: an axe on an unoxidized
|
||||
/// statue turns it back into a golem (`CopperGolemStatueBlockEntity.removeStatue`),
|
||||
/// wearing the axe. Weathered statues are scraped by the axe's own
|
||||
/// transform instead.
|
||||
pub(super) fn use_golem_statue(&mut self, pos: [i32; 3], held: Option<&ItemStack>) -> bool {
|
||||
if !held.is_some_and(|s| s.item.ends_with("_axe")) {
|
||||
return false;
|
||||
}
|
||||
let registry = self.pack.assets.registry;
|
||||
let Some(state) = registry.state(self.world.block(pos[0], pos[1], pos[2])) else {
|
||||
return false;
|
||||
};
|
||||
if state.name != "minecraft:copper_golem_statue" {
|
||||
return false;
|
||||
}
|
||||
// `Direction.toYRot` of the statue's facing.
|
||||
let yaw = match state.properties.get("facing").map(String::as_str) {
|
||||
Some("west") => 90.0,
|
||||
Some("north") => 180.0,
|
||||
Some("east") => 270.0,
|
||||
_ => 0.0,
|
||||
};
|
||||
let waterlogged = state
|
||||
.properties
|
||||
.get("waterlogged")
|
||||
.is_some_and(|w| w == "true");
|
||||
// initCopperGolem: at the block's feet, facing as the statue does.
|
||||
let at = [
|
||||
f64::from(pos[0]) + 0.5,
|
||||
f64::from(pos[1]),
|
||||
f64::from(pos[2]) + 0.5,
|
||||
];
|
||||
let Some(id) = self.spawn_mob("minecraft:copper_golem", at, true) else {
|
||||
return false;
|
||||
};
|
||||
if let Some(m) = self.mobs.iter_mut().find(|m| m.id == id) {
|
||||
m.yaw = yaw;
|
||||
m.previous_yaw = yaw;
|
||||
m.body_yaw = yaw;
|
||||
m.previous_body_yaw = yaw;
|
||||
m.head_yaw = yaw;
|
||||
m.previous_head_yaw = yaw;
|
||||
}
|
||||
self.damage_held(1);
|
||||
self.audio
|
||||
.play("minecraft:entity.copper_golem.spawn", Some(at), 1.0, 1.0);
|
||||
// Level.removeBlock(pos, false): air, or the water the statue stood in.
|
||||
let replacement = registry.default_state(if waterlogged {
|
||||
"minecraft:water"
|
||||
} else {
|
||||
"minecraft:air"
|
||||
});
|
||||
if let Some(replacement) = replacement {
|
||||
let _ = self.level_set(pos, replacement);
|
||||
}
|
||||
self.world.block_entities.remove(&(pos[0], pos[1], pos[2]));
|
||||
true
|
||||
}
|
||||
/// `CopperGolem.mobInteract`; true when handled.
|
||||
pub(super) fn interact_copper_golem(&mut self, index: usize, item: &str) -> bool {
|
||||
if self.mobs[index].species() != Species::CopperGolem || !self.mobs[index].alive() {
|
||||
|
||||
@@ -46,10 +46,22 @@ pub(super) struct Creatures {
|
||||
pub projectiles: Vec<Projectile>,
|
||||
/// Wind bursts from a guest's turn, waiting for it to end (game/wind.rs).
|
||||
pub wind_bursts: Vec<super::wind::Burst>,
|
||||
/// Explosion packets from a guest's turn, waiting for it to end
|
||||
/// (centre, small, radius, blocks hit; game/lan_particles.rs).
|
||||
pub lan_explosions: Vec<([f64; 3], bool, f32, usize)>,
|
||||
/// Ticks left of the elder guardian's apparition (MobAppearanceParticle).
|
||||
pub elder_apparition: i32,
|
||||
/// The wandering trader spawner's clock.
|
||||
pub trader: super::wandering_trader::Spawner,
|
||||
/// Particles from a guest's turn, waiting for it to end
|
||||
/// (`lan_send_particles`: options, centre, spread, speed, count).
|
||||
pub lan_particles: Vec<(
|
||||
horizon_client::particles::ParticleOptions,
|
||||
[f64; 3],
|
||||
[f64; 3],
|
||||
f64,
|
||||
u32,
|
||||
)>,
|
||||
}
|
||||
pub(super) struct ProjWorld<'a, 'w> {
|
||||
pub w: &'a MobWorld<'w>,
|
||||
@@ -187,6 +199,7 @@ impl Game<'_> {
|
||||
off_hand: None,
|
||||
head: self.armor[0].as_ref().map(|s| s.item.clone()),
|
||||
armor_cover: self.armor.iter().filter(|a| a.is_some()).count() as f32 / 4.0,
|
||||
invisible: self.potions.effects.get("invisibility").is_some(),
|
||||
spectator: self.spectator(),
|
||||
gold_armor: self.wearing_gold(),
|
||||
hurt_by: self.player_hurt_by(),
|
||||
@@ -198,6 +211,7 @@ impl Game<'_> {
|
||||
uuid: self.level.player_uuid.unwrap_or_default(),
|
||||
allies: std::sync::Arc::new(self.player_allies()),
|
||||
remote: false,
|
||||
passenger: self.riding.is_some(),
|
||||
})
|
||||
}
|
||||
/// Biome facts at a position for finalizeSpawn and variant rules.
|
||||
@@ -419,6 +433,7 @@ impl Game<'_> {
|
||||
block_tags: &self.res.items().block_tags,
|
||||
biomes: self.res.biomes(),
|
||||
mob_griefing: self.ui.rules.bool("mob_griefing"),
|
||||
mob_drops: self.ui.rules.bool("mob_drops"),
|
||||
end: self.dim == Dim::End,
|
||||
world_seed: self.level.seed,
|
||||
sea_level: if self.dim == Dim::Nether { 32 } else { 63 },
|
||||
@@ -512,6 +527,7 @@ impl Game<'_> {
|
||||
let mut events = Vec::new();
|
||||
let mut mobs = std::mem::take(&mut self.mobs);
|
||||
let mut dead = Vec::new();
|
||||
let mut corpses = Vec::new();
|
||||
let mut died = std::mem::take(&mut self.died);
|
||||
let ticking = self.entity_ticking_area();
|
||||
// With guests on, each mob sees its nearest player (game/lan_mobs.rs).
|
||||
@@ -606,6 +622,11 @@ impl Game<'_> {
|
||||
horizon_client::mobs::apply_mob_pushes(m, &mut pushes);
|
||||
let from = events.len();
|
||||
let kept = m.tick(&w, &mut scratch, &mut events);
|
||||
// A killed mob's body is removed: its effects that act on
|
||||
// death run (`LivingEntity.remove` with KILLED).
|
||||
if !kept && !m.alive() && !m.removed && !m.extra.effects.is_empty() {
|
||||
corpses.push(m.clone());
|
||||
}
|
||||
horizon_client::mobs::take_mob_pushes(&mut events, from, &mut pushes);
|
||||
// LivingEntity.tickDeath: after twenty ticks the body is removed.
|
||||
if !kept && !m.removed && !m.alive() && m.death_time >= 20 {
|
||||
@@ -685,6 +706,16 @@ impl Game<'_> {
|
||||
for m in dead {
|
||||
self.mob_died(&m);
|
||||
}
|
||||
for mut m in corpses {
|
||||
let names: Vec<&'static str> = m
|
||||
.extra
|
||||
.effects
|
||||
.iter()
|
||||
.map(|e| e.0.trim_start_matches("minecraft:"))
|
||||
.collect();
|
||||
let bounds = m.bounds();
|
||||
self.effects_on_death(&names, bounds, false, Some(m.id), Some(&mut m.random));
|
||||
}
|
||||
self.handle_mob_events(events)?;
|
||||
self.lan_guest_mob_events(guest_events);
|
||||
self.tick_projectiles()?;
|
||||
@@ -757,6 +788,7 @@ impl Game<'_> {
|
||||
self.villager_murdered(m, by_player);
|
||||
let pos = [m.position.x, m.position.y + 0.5, m.position.z];
|
||||
self.drop_death_loot(&mut dying, by_player, consumed, pos);
|
||||
self.create_wither_rose(m);
|
||||
if m.species() == Species::CopperGolem {
|
||||
// CopperGolem.dropEquipment: the preserved equipment too.
|
||||
self.golem_drop_equipment(&mut dying);
|
||||
@@ -887,6 +919,18 @@ impl Game<'_> {
|
||||
}
|
||||
}
|
||||
}
|
||||
/// `InfestedMobEffect.onMobHurt` for a mob: silverfish from half its height up.
|
||||
pub(super) fn mob_infested(&mut self, mob: u32) {
|
||||
if let Some(m) = self.mobs.iter().find(|m| m.id == mob) {
|
||||
let at = [
|
||||
m.position.x,
|
||||
m.position.y + f64::from(m.height()) / 2.0,
|
||||
m.position.z,
|
||||
];
|
||||
let look = m.view_vector();
|
||||
self.infested_hurt(at, look, Some(mob));
|
||||
}
|
||||
}
|
||||
/// `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
|
||||
@@ -999,7 +1043,7 @@ impl Game<'_> {
|
||||
self.combat.charged_exploders.push(mob);
|
||||
}
|
||||
}
|
||||
MobEvent::Explode(at, radius) => {
|
||||
MobEvent::Explode(at, radius, species) => {
|
||||
// The exploding mob causes the damage (Creeper.explodeCreeper).
|
||||
let source_mob = self.combat.explosion_source.or_else(|| {
|
||||
self.mobs
|
||||
@@ -1015,7 +1059,14 @@ impl Game<'_> {
|
||||
self.note_attacker("minecraft:explosion", id);
|
||||
}
|
||||
self.combat.explosion_source = source_mob;
|
||||
let result = self.explode(at, radius);
|
||||
// Only a creeper or a wither empties the hives it blows up.
|
||||
// The creeper is already gone from the list, so the event
|
||||
// carries its kind.
|
||||
let result = if matches!(species, Species::Creeper | Species::Wither) {
|
||||
self.with_hive_emptying_blast(|g| g.explode(at, radius))
|
||||
} else {
|
||||
self.explode(at, radius)
|
||||
};
|
||||
self.combat.explosion_source = None;
|
||||
result?
|
||||
}
|
||||
@@ -1026,6 +1077,7 @@ impl Game<'_> {
|
||||
} => {
|
||||
let mut killed = false;
|
||||
let mut hurt = false;
|
||||
let mut infested = false;
|
||||
if let Some(t) = self.mobs.iter_mut().find(|m| m.id == target) {
|
||||
let hit = t.damage(amount, source);
|
||||
hurt = hit;
|
||||
@@ -1034,20 +1086,27 @@ impl Game<'_> {
|
||||
// The hurt or death sound the mob raised.
|
||||
let center = t.center();
|
||||
for event in std::mem::take(&mut t.outbox) {
|
||||
if let MobEvent::Sound(s, _, volume, pitch) = event {
|
||||
self.audio.play(
|
||||
&format!("minecraft:{s}"),
|
||||
Some(center),
|
||||
volume,
|
||||
pitch,
|
||||
);
|
||||
} else {
|
||||
// Left for the end of the tick.
|
||||
t.outbox.push(event);
|
||||
match event {
|
||||
MobEvent::Sound(s, _, volume, pitch) => {
|
||||
self.audio.play(
|
||||
&format!("minecraft:{s}"),
|
||||
Some(center),
|
||||
volume,
|
||||
pitch,
|
||||
);
|
||||
}
|
||||
MobEvent::Infested { .. } => infested = true,
|
||||
other => {
|
||||
// Left for the end of the tick.
|
||||
t.outbox.push(other);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if infested {
|
||||
self.mob_infested(target);
|
||||
}
|
||||
if hurt
|
||||
&& let Some(Who::Mob(attacker)) = source.attacker
|
||||
&& let Some(m) = self
|
||||
@@ -1093,6 +1152,7 @@ impl Game<'_> {
|
||||
}
|
||||
MobEvent::BecomeStatue { mob } => self.golem_become_statue(mob),
|
||||
MobEvent::EnterHive { mob, hive } => self.bee_enter_hive(mob, hive),
|
||||
MobEvent::Infested { mob } => self.mob_infested(mob),
|
||||
MobEvent::Gift { target, item } => {
|
||||
if let Some(m) = self.mobs.iter_mut().find(|m| m.id == target)
|
||||
&& m.saddle_item().is_none()
|
||||
@@ -1256,12 +1316,17 @@ impl Game<'_> {
|
||||
}
|
||||
}
|
||||
MobEvent::AroundSelf {
|
||||
mob,
|
||||
event,
|
||||
kind,
|
||||
feet,
|
||||
width,
|
||||
height,
|
||||
burst,
|
||||
} => self.particles_around(kind, feet, [width, height], burst),
|
||||
} => {
|
||||
self.lan_entity_event(mob as i32, event, feet);
|
||||
self.particles_around(kind, feet, [width, height], burst)
|
||||
}
|
||||
MobEvent::ParticleAt { kind, at, velocity } => {
|
||||
if let Some(ty) = horizon_client::particles::ParticleType::from_name(kind) {
|
||||
let options = horizon_client::particles::ParticleOptions::simple(ty);
|
||||
@@ -1372,6 +1437,22 @@ impl Game<'_> {
|
||||
m.ai.aggressive |= aggressive;
|
||||
}
|
||||
}
|
||||
MobEvent::ShedScute { mob, at, pitch } => {
|
||||
// The mob already checked `shouldDropLoot` (a baby, `mob_drops`).
|
||||
let table = "minecraft:gameplay/armadillo_shed";
|
||||
let drops = self.sequence_loot(table, table, None);
|
||||
for d in drops {
|
||||
self.spawn_at_location(Vec3::new(at[0], at[1], at[2]), 0.0, d);
|
||||
}
|
||||
self.audio.play(
|
||||
"minecraft:entity.armadillo.scute_drop",
|
||||
Some(at),
|
||||
1.0,
|
||||
pitch,
|
||||
);
|
||||
let ctx = self.who_context(Some(Who::Mob(mob)), None);
|
||||
self.post_game_event("minecraft:entity_place", at, ctx);
|
||||
}
|
||||
MobEvent::GiftLoot { mob, table, at } => {
|
||||
// Turtle.ageBoundaryReached: only with mob loot on.
|
||||
if table == "minecraft:gameplay/turtle_grow" && !self.ui.rules.bool("mob_drops")
|
||||
@@ -1500,6 +1581,8 @@ impl Game<'_> {
|
||||
q.extra.in_love = 0;
|
||||
}
|
||||
let q = self.mobs.iter().find(|m| m.id == partner).cloned();
|
||||
// Animal.finalizeSpawnChildFromBreeding: entity event 18 for the parent.
|
||||
self.mob_event_particles(parent, 18);
|
||||
// Sniffer.spawnChildFromBreeding: an egg instead of a baby.
|
||||
if p.species() == Species::Sniffer {
|
||||
self.lay_sniffer_egg(&p);
|
||||
@@ -1772,6 +1855,10 @@ impl Game<'_> {
|
||||
let (xd, zd) = from.map_or((0.0, 0.0), |from| {
|
||||
(from[0] - player.position.x, from[2] - player.position.z)
|
||||
});
|
||||
// dealDefaultKnockback's `indicateDamage`, unless blocked.
|
||||
if o.blocked <= 0.0 {
|
||||
player.health.indicate_damage(xd, zd, player.yaw);
|
||||
}
|
||||
self.knock_back_player(f64::from(0.4_f32), xd, zd);
|
||||
if let Some(p) = self.player.as_mut()
|
||||
&& let Some(r) = p.hurt_log.last_mut()
|
||||
@@ -1784,6 +1871,23 @@ impl Game<'_> {
|
||||
self.thorns(a);
|
||||
}
|
||||
}
|
||||
// LivingEntity.hurtServer: ENTITY_HURT_PLAYER, unless it returned
|
||||
// early (invulnerable, or inside the hurt cooldown).
|
||||
if outcome.hurt || outcome.sound {
|
||||
let source = attacker
|
||||
.or(owner)
|
||||
.and_then(|id| self.mobs.iter().find(|m| m.id == id))
|
||||
.map(|m| self.mob_entity(m));
|
||||
self.trigger_entity_hurt_player(&horizon_client::advancements::DamageView {
|
||||
kind: damage_type.to_owned(),
|
||||
direct: source.clone().filter(|_| !projectile),
|
||||
is_direct: !projectile,
|
||||
source,
|
||||
original: amount,
|
||||
actual: amount - outcome.blocked,
|
||||
blocked: outcome.blocked > 0.0,
|
||||
});
|
||||
}
|
||||
if raised {
|
||||
self.after_block(outcome, amount, attacker, projectile);
|
||||
}
|
||||
@@ -2085,6 +2189,7 @@ impl Game<'_> {
|
||||
_ => self.projectile_hit(&p, hit)?,
|
||||
}
|
||||
}
|
||||
self.flush_lan_explosions();
|
||||
self.flush_wind_bursts()
|
||||
}
|
||||
/// `projectile_hit` for a projectile the guest `conn` shot, run as them;
|
||||
@@ -2436,6 +2541,35 @@ impl Game<'_> {
|
||||
.is_some_and(|m| m.damage(amount, source));
|
||||
if p.owner == Some(Who::Player) {
|
||||
self.last_hurt_by_player.insert(id, self.lan_acting);
|
||||
if hurt && let Some(m) = self.mobs.iter().find(|m| m.id == id) {
|
||||
// LivingEntity.hurtServer: PLAYER_HURT_ENTITY.
|
||||
let victim = self.mob_entity(m);
|
||||
let spectral = p.arrow.as_ref().is_some_and(|a| {
|
||||
&*a.pickup_item.item == "minecraft:spectral_arrow"
|
||||
});
|
||||
let direct = horizon_client::advancements::EntityView {
|
||||
kind: if spectral {
|
||||
"minecraft:spectral_arrow"
|
||||
} else {
|
||||
"minecraft:arrow"
|
||||
}
|
||||
.into(),
|
||||
position: [p.position.x, p.position.y, p.position.z],
|
||||
..Default::default()
|
||||
};
|
||||
self.player_hit(&victim, "minecraft:arrow", Some(direct), amount);
|
||||
}
|
||||
// AbstractArrow.onHitEntity: KILLED_BY_ARROW for a kill
|
||||
// (piercing arrows are not modelled).
|
||||
if hurt
|
||||
&& let Some(m) = self.mobs.iter().find(|m| m.id == id)
|
||||
&& !m.alive()
|
||||
{
|
||||
let victim = self.mob_entity(m);
|
||||
let weapon =
|
||||
p.arrow.as_ref().and_then(|a| a.fired_from_weapon.as_ref());
|
||||
self.trigger_killed_by_arrow(&[victim], weapon);
|
||||
}
|
||||
}
|
||||
hurt
|
||||
}
|
||||
@@ -2479,6 +2613,7 @@ impl Game<'_> {
|
||||
};
|
||||
m.damage(amount, source);
|
||||
}
|
||||
self.thrown_break_event(p.id, atp);
|
||||
self.item_burst(atp, "minecraft:snowball");
|
||||
}
|
||||
(ProjectileKind::Egg, hit) => {
|
||||
@@ -2504,6 +2639,7 @@ impl Game<'_> {
|
||||
}
|
||||
}
|
||||
}
|
||||
self.thrown_break_event(p.id, atp);
|
||||
self.item_burst(atp, "minecraft:egg");
|
||||
}
|
||||
(ProjectileKind::EnderPearl, hit) => {
|
||||
@@ -2607,7 +2743,10 @@ impl Game<'_> {
|
||||
if let Some(owner) = self.combat.projectile_owner {
|
||||
self.note_attacker("minecraft:explosion", owner);
|
||||
}
|
||||
self.explode(atp, *power as f32)?;
|
||||
self.combat.explosion_owner = self.combat.projectile_owner;
|
||||
let result = self.explode(atp, *power as f32);
|
||||
self.combat.explosion_owner = None;
|
||||
result?;
|
||||
}
|
||||
(
|
||||
ProjectileKind::Potion {
|
||||
@@ -2753,10 +2892,17 @@ impl Game<'_> {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
/// `Snowball`/`ThrownEgg.onHit`: entity event 3 for the guests, before the
|
||||
/// projectile is discarded (the clients lose it when the tracker next runs).
|
||||
fn thrown_break_event(&mut self, id: u32, at: [f64; 3]) {
|
||||
if id != 0 {
|
||||
self.lan_entity_event(id as i32, 3, at);
|
||||
}
|
||||
}
|
||||
/// `Snowball`/`ThrownEgg.handleEntityEvent(3)`: eight crumbs of the
|
||||
/// thrown item where it broke, at rest for a snowball, scattered by the
|
||||
/// client entity's random (the particle engine's here) for an egg.
|
||||
fn item_burst(&mut self, at: [f64; 3], item: &str) {
|
||||
pub(super) fn item_burst(&mut self, at: [f64; 3], item: &str) {
|
||||
let options = self.item_particle(&horizon_client::items::ItemStack::new(item, 1));
|
||||
let egg = item != "minecraft:snowball";
|
||||
for _ in 0..8 {
|
||||
@@ -2792,6 +2938,10 @@ impl Game<'_> {
|
||||
if self.name_mob(index) {
|
||||
return Ok(true);
|
||||
}
|
||||
if self.spawn_egg_offspring(index) {
|
||||
self.swing_arm();
|
||||
return Ok(true);
|
||||
}
|
||||
{
|
||||
let item = self.held().map(|h| h.item.to_string()).unwrap_or_default();
|
||||
if self.interact_leash(index, &item) {
|
||||
@@ -2853,6 +3003,14 @@ impl Game<'_> {
|
||||
self.swing_arm();
|
||||
return Ok(true);
|
||||
}
|
||||
if self.interact_armadillo(index, &item) {
|
||||
if let Some(stack) = &held {
|
||||
let target = self.mob_entity(&self.mobs[index]);
|
||||
self.trigger_item_entity("minecraft:player_interacted_with_entity", stack, &target);
|
||||
}
|
||||
self.swing_arm();
|
||||
return Ok(true);
|
||||
}
|
||||
if self.interact_copper_golem(index, &item) {
|
||||
self.swing_arm();
|
||||
return Ok(true);
|
||||
@@ -2908,6 +3066,16 @@ impl Game<'_> {
|
||||
consume = true;
|
||||
sound = Some("entity.cow.milk");
|
||||
}
|
||||
// Goat.mobInteract: a bucket on an adult gives milk.
|
||||
Species::Goat if item == "minecraft:bucket" && !m.is_baby() => {
|
||||
give = Some("minecraft:milk_bucket");
|
||||
consume = true;
|
||||
sound = Some(if m.extra.screaming {
|
||||
"entity.goat.screaming.milk"
|
||||
} else {
|
||||
"entity.goat.milk"
|
||||
});
|
||||
}
|
||||
Species::Mooshroom if item == "minecraft:bowl" && !m.is_baby() => {
|
||||
give = Some("minecraft:mushroom_stew");
|
||||
consume = true;
|
||||
@@ -3028,14 +3196,8 @@ impl Game<'_> {
|
||||
m.ai.target = None;
|
||||
m.extra.sitting = true;
|
||||
}
|
||||
// TamableAnimal.spawnTamingParticles.
|
||||
let kind = if tamed { "heart" } else { "smoke" };
|
||||
// TamableAnimal.spawnTamingParticles (entity event 7 or 6).
|
||||
self.particles_around_mob(
|
||||
self.mobs[index].id,
|
||||
kind,
|
||||
horizon_client::particles::Burst::TAMING,
|
||||
);
|
||||
self.mob_event_particles(self.mobs[index].id, if tamed { 7 } else { 6 });
|
||||
if tamed {
|
||||
let view = self.mob_entity(&self.mobs[index]);
|
||||
self.trigger_entity("minecraft:tame_animal", "entity", &view);
|
||||
@@ -3102,13 +3264,8 @@ impl Game<'_> {
|
||||
m.extra.sitting = true;
|
||||
}
|
||||
eat = eating_sound(m, &mut self.world.random);
|
||||
let kind = if tamed { "heart" } else { "smoke" };
|
||||
// TamableAnimal.spawnTamingParticles (entity event 7 or 6).
|
||||
self.particles_around_mob(
|
||||
self.mobs[index].id,
|
||||
kind,
|
||||
horizon_client::particles::Burst::TAMING,
|
||||
);
|
||||
self.mob_event_particles(self.mobs[index].id, if tamed { 7 } else { 6 });
|
||||
if tamed {
|
||||
let view = self.mob_entity(&self.mobs[index]);
|
||||
self.trigger_entity("minecraft:tame_animal", "entity", &view);
|
||||
@@ -3156,18 +3313,42 @@ impl Game<'_> {
|
||||
m.extra.tame = true;
|
||||
m.extra.owner = self.level.player_uuid.or(Some([0, 0, 0, 1]));
|
||||
}
|
||||
let kind = if tamed { "heart" } else { "smoke" };
|
||||
// TamableAnimal.spawnTamingParticles (entity event 7 or 6).
|
||||
self.particles_around_mob(
|
||||
self.mobs[index].id,
|
||||
kind,
|
||||
horizon_client::particles::Burst::TAMING,
|
||||
);
|
||||
self.mob_event_particles(self.mobs[index].id, if tamed { 7 } else { 6 });
|
||||
if tamed {
|
||||
let view = self.mob_entity(&self.mobs[index]);
|
||||
self.trigger_entity("minecraft:tame_animal", "entity", &view);
|
||||
}
|
||||
}
|
||||
// Tadpole.feed: frog food ages it by a tenth of the time left to
|
||||
// grow into a frog (it grows on its next tick once past 24000).
|
||||
Species::Tadpole if is_food && !m.extra.age_locked => {
|
||||
consume = true;
|
||||
let left = 24_000 - m.extra.age;
|
||||
m.extra.age += ((left / 20) as f32 * 0.1) as i32 * 20;
|
||||
// One happy villager particle at rest about the body.
|
||||
self.particles_around_mob(
|
||||
self.mobs[index].id,
|
||||
"happy_villager",
|
||||
horizon_client::particles::Burst::HORSE_EATING,
|
||||
);
|
||||
}
|
||||
// Bee.mobInteract: a wither rose or an open eyeblossom is eaten for
|
||||
// its `getBeeInteractionEffect` instead of breeding the bee.
|
||||
Species::Bee
|
||||
if is_food
|
||||
&& matches!(
|
||||
&*item,
|
||||
"minecraft:wither_rose" | "minecraft:open_eyeblossom"
|
||||
) =>
|
||||
{
|
||||
if &*item == "minecraft:wither_rose" {
|
||||
m.add_effect("minecraft:wither", 40, 0);
|
||||
} else {
|
||||
m.add_effect("minecraft:poison", 25, 0);
|
||||
}
|
||||
consume = true;
|
||||
}
|
||||
// HappyGhast.canFallInLove: never, so only a ghastling takes food.
|
||||
_ if is_food
|
||||
&& m.kind.flags.animal
|
||||
@@ -3180,6 +3361,11 @@ impl Game<'_> {
|
||||
Some(sound) => {
|
||||
consume = true;
|
||||
eat = sound;
|
||||
// Animal.setInLove: entity event 18 (a baby that
|
||||
// only grew is not in love).
|
||||
if self.mobs[index].extra.in_love > 0 {
|
||||
self.mob_event_particles(self.mobs[index].id, 18);
|
||||
}
|
||||
}
|
||||
// Animal.mobInteract still consumes the client click when
|
||||
// an adult cannot breed, without swinging or taking food.
|
||||
@@ -3255,6 +3441,50 @@ impl Game<'_> {
|
||||
}
|
||||
Ok(true)
|
||||
}
|
||||
/// `Armadillo.mobInteract`: a brush brushes a scute off an adult
|
||||
/// (`brushOffScute`) and loses 16 durability.
|
||||
fn interact_armadillo(&mut self, index: usize, item: &str) -> bool {
|
||||
let m = &self.mobs[index];
|
||||
if item != "minecraft:brush"
|
||||
|| m.species() != Species::Armadillo
|
||||
|| !m.alive()
|
||||
|| m.is_baby()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
let (id, at) = (m.id, m.position);
|
||||
let feet = [at.x, at.y, at.z];
|
||||
let tool = self.held().cloned();
|
||||
let table = "minecraft:brush/armadillo";
|
||||
for d in self.sequence_loot(table, table, tool.as_ref()) {
|
||||
self.spawn_at_location(at, 0.0, d);
|
||||
}
|
||||
self.audio
|
||||
.play("minecraft:entity.armadillo.brush", Some(feet), 1.0, 1.0);
|
||||
let ctx = self.who_context(Some(Who::Mob(id)), None);
|
||||
self.post_game_event("minecraft:entity_interact", feet, ctx);
|
||||
// ItemStack.hurtAndBreak(16).
|
||||
if !self.creative
|
||||
&& let Some(stack) = tool
|
||||
{
|
||||
let max = self
|
||||
.res
|
||||
.items()
|
||||
.get(&stack.item)
|
||||
.map_or(0, |i| i.max_damage);
|
||||
if max > 0 {
|
||||
let loss = self.durability_loss(&stack, 16);
|
||||
let slot = self.held_slot();
|
||||
if let Some(held) = self.stack_in_mut(slot).as_mut() {
|
||||
held.damage += loss;
|
||||
if held.damage >= max {
|
||||
*self.stack_in_mut(slot) = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
pub(super) fn damage_held_tool(&mut self) {
|
||||
if self.creative {
|
||||
return;
|
||||
@@ -3332,6 +3562,45 @@ impl Game<'_> {
|
||||
}
|
||||
Ok(true)
|
||||
}
|
||||
/// `Mob.checkAndHandleImportantInteractions` with a spawn egg of mob
|
||||
/// `index`'s own kind (`SpawnEggItem.spawnOffspringFromSpawnEgg`): a baby
|
||||
/// at the mob's feet, taking the parent's variant as `getBreedOffspring`
|
||||
/// does, and one egg used. False (PASS) when the mob has no baby form.
|
||||
fn spawn_egg_offspring(&mut self, index: usize) -> bool {
|
||||
let Some(stack) = self.held().cloned() else {
|
||||
return false;
|
||||
};
|
||||
let parent = &self.mobs[index];
|
||||
if !parent.alive()
|
||||
|| stack.item.strip_suffix("_spawn_egg") != Some(parent.kind.id.as_str())
|
||||
|| !horizon_client::mobs::drops::can_be_baby(parent.species())
|
||||
// WanderingTrader.getBreedOffspring returns null: no offspring, the
|
||||
// click carries on to trading.
|
||||
|| parent.species() == Species::WanderingTrader
|
||||
{
|
||||
return false;
|
||||
}
|
||||
let (kind, at) = (
|
||||
parent.kind.id.clone(),
|
||||
[parent.position.x, parent.position.y, parent.position.z],
|
||||
);
|
||||
let (species, variant, color) =
|
||||
(parent.species(), parent.extra.variant, parent.extra.color);
|
||||
let target = self.mob_entity(&self.mobs[index]);
|
||||
let Some(id) = self.spawn_mob(&kind, at, true) else {
|
||||
return false;
|
||||
};
|
||||
if let Some(child) = self.mobs.iter_mut().find(|m| m.id == id) {
|
||||
horizon_client::mobs::finalize::set_baby(child, true);
|
||||
child.extra.variant = variant;
|
||||
if species == Species::Sheep {
|
||||
child.extra.color = color;
|
||||
}
|
||||
}
|
||||
self.trigger_item_entity("minecraft:player_interacted_with_entity", &stack, &target);
|
||||
self.consume_held();
|
||||
true
|
||||
}
|
||||
fn use_spawn_egg(&mut self, stack: &ItemStack) -> Result<bool> {
|
||||
let Some(hit) = self.pick() else {
|
||||
return Ok(false);
|
||||
|
||||
@@ -219,6 +219,7 @@ impl Game<'_> {
|
||||
if let Some(a) = arrow.arrow.as_mut() {
|
||||
a.set_item(ammo);
|
||||
a.set_owner(Some(Who::Player));
|
||||
a.fired_from_weapon = Some(weapon.clone());
|
||||
a.pierce = pierce;
|
||||
}
|
||||
arrow.shoot(&mut self.world.random, dir.to_array(), power, 1.0);
|
||||
@@ -235,6 +236,11 @@ impl Game<'_> {
|
||||
.play("minecraft:item.crossbow.shoot", Some(eye), 1.0, pitch);
|
||||
self.damage_held(if rocket { 3 } else { 1 });
|
||||
}
|
||||
// CrossbowItem.performShooting: SHOT_CROSSBOW with the crossbow, which
|
||||
// is an empty stack (no match) when the shots broke it.
|
||||
if let Some(stack) = self.held().cloned() {
|
||||
self.trigger_item("minecraft:shot_crossbow", &stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -120,6 +120,11 @@ impl Game<'_> {
|
||||
p.guest = guest;
|
||||
// Not into the one who turned it on its way out.
|
||||
p.left_owner = false;
|
||||
// `AbstractHurtingProjectile.onDeflection` by an attack, and the
|
||||
// `needsSync` that `AIM_DEFLECT` sets: a server's players see it turn
|
||||
// at once, not at the fireball's next update ten ticks later.
|
||||
p.acceleration = 0.1;
|
||||
p.needs_sync = true;
|
||||
self.reset_attack_strength();
|
||||
self.swing_arm();
|
||||
let from = self
|
||||
|
||||
@@ -27,6 +27,8 @@ pub(super) const SPECIAL: u32 = u32::MAX - 4096;
|
||||
const CRYSTAL_IDS: u32 = SPECIAL + 16;
|
||||
const FIGHT_FILE: &str = "data/minecraft/ender_dragon_fight.dat";
|
||||
const MAX_HEALTH: f32 = 200.0;
|
||||
/// `Mob.getAmbientSoundInterval`.
|
||||
const AMBIENT_INTERVAL: i32 = 80;
|
||||
|
||||
#[derive(Default)]
|
||||
pub(super) struct Fight {
|
||||
@@ -270,6 +272,8 @@ pub(super) struct Dragon {
|
||||
flame_count: i32,
|
||||
sitting_damage: f32,
|
||||
growl: i32,
|
||||
/// `Mob.ambientSoundTime`.
|
||||
ambient_time: i32,
|
||||
ticks: i32,
|
||||
/// DragonFlightHistory: (y, yRot) samples, newest at `head`.
|
||||
history: [(f64, f32); 64],
|
||||
@@ -291,11 +295,11 @@ pub(super) enum FightWho {
|
||||
}
|
||||
/// A player in the End as the dragon sees it.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
struct FightPlayer {
|
||||
who: FightWho,
|
||||
position: Vec3,
|
||||
bounds: Aabb,
|
||||
alive: bool,
|
||||
pub(super) struct FightPlayer {
|
||||
pub(super) who: FightWho,
|
||||
pub(super) position: Vec3,
|
||||
pub(super) bounds: Aabb,
|
||||
pub(super) alive: bool,
|
||||
creative: bool,
|
||||
spectator: bool,
|
||||
}
|
||||
@@ -397,6 +401,7 @@ impl Dragon {
|
||||
flame_count: 0,
|
||||
sitting_damage: 0.0,
|
||||
growl: 100,
|
||||
ambient_time: 0,
|
||||
ticks: 0,
|
||||
history: [(position.y, yaw); 64],
|
||||
head: 0,
|
||||
@@ -693,7 +698,7 @@ impl Game<'_> {
|
||||
}
|
||||
/// The players in the level the dragon sees (`level.players()`): the
|
||||
/// window's own, then every guest in the level.
|
||||
fn fight_players(&self) -> Vec<FightPlayer> {
|
||||
pub(super) fn fight_players(&self) -> Vec<FightPlayer> {
|
||||
let mut out = Vec::new();
|
||||
if let Some(p) = self.player.as_ref() {
|
||||
out.push(FightPlayer {
|
||||
@@ -722,7 +727,7 @@ impl Game<'_> {
|
||||
}
|
||||
/// Run `f` as the fight's player `who` (a guest's turn, its knockback
|
||||
/// sent to its client).
|
||||
fn as_fight_player(&mut self, who: FightWho, f: impl FnOnce(&mut Self)) {
|
||||
pub(super) fn as_fight_player(&mut self, who: FightWho, f: impl FnOnce(&mut Self)) {
|
||||
match who {
|
||||
FightWho::Host => f(self),
|
||||
FightWho::Guest(conn) => {
|
||||
@@ -987,6 +992,8 @@ impl Game<'_> {
|
||||
};
|
||||
let hurt = d.hurt(part, damage, counts, arrow);
|
||||
if hurt == (Hurt::Landed { full: true }) {
|
||||
// Mob.playHurtSound: the ambient sound clock starts again.
|
||||
d.ambient_time = -AMBIENT_INTERVAL;
|
||||
let at = [d.position.x, d.position.y, d.position.z];
|
||||
let pitch = 0.8 + self.world.random.next_float() * 0.3;
|
||||
self.audio
|
||||
@@ -1566,6 +1573,7 @@ impl Game<'_> {
|
||||
age: 0,
|
||||
duration: 200,
|
||||
from_dragon: true,
|
||||
potion: None,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1658,6 +1666,24 @@ impl Game<'_> {
|
||||
self.tick_dragon_death();
|
||||
return;
|
||||
}
|
||||
// Mob.baseTick: the ambient sound, rarer right after one.
|
||||
let roll = d.random.next_int_bound(1000).unwrap_or(999);
|
||||
let waited = d.ambient_time;
|
||||
d.ambient_time += 1;
|
||||
if roll < waited {
|
||||
d.ambient_time = -AMBIENT_INTERVAL;
|
||||
let at = [d.position.x, d.position.y, d.position.z];
|
||||
// LivingEntity.getVoicePitch, from the dragon's own random.
|
||||
let r = &mut d.random;
|
||||
let pitch = (r.next_float() - r.next_float()) * 0.2 + 1.0;
|
||||
self.audio.play(
|
||||
"minecraft:entity.ender_dragon.ambient",
|
||||
Some(at),
|
||||
5.0,
|
||||
pitch,
|
||||
);
|
||||
}
|
||||
let d = self.dragon.as_mut().expect("dragon");
|
||||
// Flapping, growls and the flap sound.
|
||||
let flap_was = (d.old_flap * std::f32::consts::TAU).cos();
|
||||
let v = d.velocity;
|
||||
@@ -2078,6 +2104,7 @@ impl Game<'_> {
|
||||
age: 0,
|
||||
duration: 600,
|
||||
from_dragon: false,
|
||||
potion: None,
|
||||
});
|
||||
// DragonFireball.onHit: level event 2006 (the burst of dragon
|
||||
// breath and the explosion sound) at its block position.
|
||||
@@ -2115,6 +2142,10 @@ impl Game<'_> {
|
||||
let mut harmed: Vec<(FightWho, f32)> = Vec::new();
|
||||
let mut clouds = std::mem::take(&mut self.breath_clouds);
|
||||
clouds.retain_mut(|c| {
|
||||
// Lingering potions' clouds tick with the potions.
|
||||
if c.potion.is_some() {
|
||||
return true;
|
||||
}
|
||||
c.age += 1;
|
||||
if c.age >= c.duration {
|
||||
return false;
|
||||
@@ -2262,8 +2293,22 @@ pub(super) struct Breath {
|
||||
pub(super) at: [f64; 3],
|
||||
pub(super) radius: f32,
|
||||
pub(super) age: i32,
|
||||
duration: i32,
|
||||
from_dragon: bool,
|
||||
pub(super) duration: i32,
|
||||
pub(super) from_dragon: bool,
|
||||
/// A lingering potion's cloud (`ThrownLingeringPotion`): what it applies.
|
||||
pub(super) potion: Option<super::potions::PotionCloud>,
|
||||
}
|
||||
impl Breath {
|
||||
/// `AreaEffectCloud.isWaiting`: before its wait time (20 ticks, 10 for a
|
||||
/// lingering potion's).
|
||||
pub(super) fn waiting(&self) -> bool {
|
||||
self.age
|
||||
< if self.potion.is_some() {
|
||||
super::potions::LINGERING_WAIT
|
||||
} else {
|
||||
20
|
||||
}
|
||||
}
|
||||
}
|
||||
impl Game<'_> {
|
||||
/// `EnderDragonRenderer` and `EnderDragonModel.setupAnim`.
|
||||
|
||||
@@ -307,6 +307,12 @@ impl Game<'_> {
|
||||
)
|
||||
{
|
||||
outcome = o;
|
||||
// dealDefaultKnockback's `indicateDamage` points at the blast
|
||||
// (the source position), not the no-direction fallback.
|
||||
if o.knockback && o.blocked <= 0.0 {
|
||||
p.health
|
||||
.indicate_damage(center[0] - feet[0], center[2] - feet[2], p.yaw);
|
||||
}
|
||||
}
|
||||
if !spectator && !(creative && flying) {
|
||||
p.velocity = Vec3::new(
|
||||
@@ -394,7 +400,14 @@ impl Game<'_> {
|
||||
// it kills drop its charged-creeper loot (`Creeper.killedEntity`).
|
||||
let source = horizon_client::mobs::Damage {
|
||||
kind: horizon_client::mobs::DamageKind::Explosion,
|
||||
attacker: exploding.map(horizon_client::mobs::Who::Mob),
|
||||
// A projectile's owner (`getIndirectSourceEntity`), else
|
||||
// the exploding mob itself.
|
||||
attacker: self
|
||||
.combat
|
||||
.explosion_owner
|
||||
.or(exploding)
|
||||
.filter(|&o| o != m.id)
|
||||
.map(horizon_client::mobs::Who::Mob),
|
||||
from: Some(center),
|
||||
};
|
||||
if hurtable && !m.damage(damage(dist, exposure), source) {
|
||||
@@ -490,6 +503,15 @@ impl Game<'_> {
|
||||
);
|
||||
}
|
||||
}
|
||||
/// Runs an explosion whose source empties the hives it destroys
|
||||
/// (`BeehiveBlock.getDrops`: primed TNT, creeper, wither skull, wither,
|
||||
/// TNT minecart).
|
||||
pub(super) fn with_hive_emptying_blast<R>(&mut self, blast: impl FnOnce(&mut Self) -> R) -> R {
|
||||
self.combat.hive_emptying_blast = true;
|
||||
let result = blast(self);
|
||||
self.combat.hive_emptying_blast = false;
|
||||
result
|
||||
}
|
||||
/// `Level.explode` on the server: positions, entities, blocks, fire; then
|
||||
/// the client's explosion sound.
|
||||
pub(super) fn server_explode(
|
||||
@@ -606,6 +628,22 @@ impl Game<'_> {
|
||||
// Block.onExplosionHit: the drops copy from the block entity, which
|
||||
// then spills its contents as the block turns to air.
|
||||
let key = (pos[0], pos[1], pos[2]);
|
||||
let is_hive = matches!(&*name, "minecraft:beehive" | "minecraft:bee_nest");
|
||||
// BeehiveBlock.getDrops: the bees of a hive blown up by TNT, a
|
||||
// creeper, a wither skull, a wither or a TNT minecart come out.
|
||||
if is_hive && self.combat.hive_emptying_blast {
|
||||
let facing = self
|
||||
.pack
|
||||
.assets
|
||||
.registry
|
||||
.state(state)
|
||||
.and_then(|s| s.properties.get("facing").cloned());
|
||||
self.empty_hive(
|
||||
pos,
|
||||
horizon_client::beehive::facing_step(facing.as_deref()),
|
||||
horizon_client::beehive::Release::Emergency,
|
||||
);
|
||||
}
|
||||
if let Some(entity) = self.world.block_entities.get(&key).cloned() {
|
||||
let custom = self.world.block_names.get(&key).cloned();
|
||||
self.pending.record(pos, &entity, &name, custom);
|
||||
@@ -638,6 +676,10 @@ impl Game<'_> {
|
||||
}
|
||||
self.pending.clear(pos);
|
||||
self.level_set(pos, self.world.air)?;
|
||||
// BeehiveBlock.onExplosionHit: the bees about turn on the player.
|
||||
if is_hive {
|
||||
self.anger_nearby_bees(pos);
|
||||
}
|
||||
// TntBlock.wasExploded: new PrimedTnt (its push drawn first), then
|
||||
// getRandomShortFuse(80); no game event.
|
||||
if is_tnt && self.ui.rules.bool("tnt_explodes") {
|
||||
|
||||
@@ -23,7 +23,7 @@ pub(super) struct Rocket {
|
||||
/// The entity id a server tracks it by (0 until it is tracked).
|
||||
pub id: u32,
|
||||
pub(super) position: Vec3,
|
||||
previous: Vec3,
|
||||
pub(super) previous: Vec3,
|
||||
pub(super) velocity: Vec3,
|
||||
life: i32,
|
||||
lifetime: i32,
|
||||
@@ -62,11 +62,56 @@ impl Rocket {
|
||||
item,
|
||||
}
|
||||
}
|
||||
/// One tick of a server's client: the previous position, then `step`.
|
||||
pub(super) fn remote_step(&mut self, step: impl FnOnce(Vec3) -> Vec3) {
|
||||
/// One tick of a server's client: the rocket flies on by itself between
|
||||
/// the server's updates (a rocket that follows an entity is placed by the
|
||||
/// caller).
|
||||
pub(super) fn remote_step(&mut self, scene: &mut SceneCollisions) {
|
||||
self.previous = self.position;
|
||||
if self.attached_to.is_none() {
|
||||
self.free_flight(scene);
|
||||
}
|
||||
self.life += 1;
|
||||
self.position = step(self.position);
|
||||
}
|
||||
/// `FireworkRocketEntity.tick` for a rocket attached to no entity: speed
|
||||
/// up (an angled one keeps its motion) and rise, then move. True when a
|
||||
/// block stopped it.
|
||||
fn free_flight(&mut self, scene: &mut SceneCollisions) -> bool {
|
||||
let h = 0.125;
|
||||
let bounds = Aabb::new(
|
||||
Vec3::new(self.position.x - h, self.position.y, self.position.z - h),
|
||||
Vec3::new(
|
||||
self.position.x + h,
|
||||
self.position.y + 2.0 * h,
|
||||
self.position.z + h,
|
||||
),
|
||||
);
|
||||
let wanted = if self.angled {
|
||||
self.velocity
|
||||
} else {
|
||||
Vec3::new(
|
||||
self.velocity.x * 1.15,
|
||||
self.velocity.y + 0.04,
|
||||
self.velocity.z * 1.15,
|
||||
)
|
||||
};
|
||||
let Ok(moved) = scene.resolve(bounds, wanted, 0.0, false) else {
|
||||
return false;
|
||||
};
|
||||
let blocked = (moved.x - wanted.x).abs() > 1e-7
|
||||
|| (moved.y - wanted.y).abs() > 1e-7
|
||||
|| (moved.z - wanted.z).abs() > 1e-7;
|
||||
let horizontal = (moved.x - wanted.x).abs() > 1e-7 || (moved.z - wanted.z).abs() > 1e-7;
|
||||
self.position = Vec3::new(
|
||||
self.position.x + moved.x,
|
||||
self.position.y + moved.y,
|
||||
self.position.z + moved.z,
|
||||
);
|
||||
self.velocity = if horizontal {
|
||||
Vec3::new(self.velocity.x, wanted.y, self.velocity.z)
|
||||
} else {
|
||||
wanted
|
||||
};
|
||||
blocked
|
||||
}
|
||||
/// Position and motion (the dispenser parity fixture).
|
||||
pub(super) fn motion(&self) -> (Vec3, Vec3) {
|
||||
@@ -191,46 +236,14 @@ impl Game<'_> {
|
||||
r.velocity = p.velocity;
|
||||
}
|
||||
} else {
|
||||
// Not shot at an angle: accelerate (unless blocked sideways) and rise.
|
||||
let mut scene = SceneCollisions {
|
||||
world: &self.world,
|
||||
binding: self.collision,
|
||||
subject: None,
|
||||
};
|
||||
let h = 0.125;
|
||||
let bounds = Aabb::new(
|
||||
Vec3::new(r.position.x - h, r.position.y, r.position.z - h),
|
||||
Vec3::new(r.position.x + h, r.position.y + 2.0 * h, r.position.z + h),
|
||||
);
|
||||
let wanted = if r.angled {
|
||||
r.velocity
|
||||
} else {
|
||||
Vec3::new(
|
||||
r.velocity.x * 1.15,
|
||||
r.velocity.y + 0.04,
|
||||
r.velocity.z * 1.15,
|
||||
)
|
||||
};
|
||||
if let Ok(moved) = scene.resolve(bounds, wanted, 0.0, false) {
|
||||
let blocked = (moved.x - wanted.x).abs() > 1e-7
|
||||
|| (moved.y - wanted.y).abs() > 1e-7
|
||||
|| (moved.z - wanted.z).abs() > 1e-7;
|
||||
if r.angled && blocked {
|
||||
// hitTargetOrDeflectSelf: explode on the block.
|
||||
r.life = r.lifetime;
|
||||
}
|
||||
let horizontal =
|
||||
(moved.x - wanted.x).abs() > 1e-7 || (moved.z - wanted.z).abs() > 1e-7;
|
||||
r.position = Vec3::new(
|
||||
r.position.x + moved.x,
|
||||
r.position.y + moved.y,
|
||||
r.position.z + moved.z,
|
||||
);
|
||||
r.velocity = if horizontal {
|
||||
Vec3::new(r.velocity.x, wanted.y, r.velocity.z)
|
||||
} else {
|
||||
wanted
|
||||
};
|
||||
if r.free_flight(&mut scene) && r.angled {
|
||||
// hitTargetOrDeflectSelf: explode on the block.
|
||||
r.life = r.lifetime;
|
||||
}
|
||||
}
|
||||
let at = [r.position.x, r.position.y, r.position.z];
|
||||
@@ -383,7 +396,12 @@ impl Game<'_> {
|
||||
/// lit at the rocket's light probe.
|
||||
pub(super) fn rocket_geometry(&self, camera: glam::DVec3, alpha: f64, out: &mut Vec<Vertex>) {
|
||||
let orientation = glam::Mat4::from_quat(self.camera_orientation());
|
||||
for r in self.rockets.iter().filter(|r| !r.attached) {
|
||||
// shouldRender: not while attached to an entity (`isAttachedToEntity`).
|
||||
for r in self
|
||||
.rockets
|
||||
.iter()
|
||||
.filter(|r| !r.attached && r.attached_to.is_none())
|
||||
{
|
||||
// FireworkRocketEntity.shouldRenderAtSqrDistance: within 64 blocks;
|
||||
// EntityRenderer.shouldRender: its 0.25 box in the view.
|
||||
if !self.standing_entity_in_view(
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
//! bobbing, lure and bite timers, open water, hooking mobs, retrieving the
|
||||
//! `gameplay/fishing` loot) and `FishingHookRenderer` (bobber and line).
|
||||
use super::{Game, view_vector};
|
||||
use horizon_client::advancements::EntityView;
|
||||
use horizon_client::lan::{entity::States, hub::Hub};
|
||||
use horizon_client::{
|
||||
blocks::Fluid,
|
||||
@@ -77,7 +78,7 @@ impl Game<'_> {
|
||||
let at = [p.position.x, p.position.y, p.position.z];
|
||||
let pitch = 0.4 / (self.world.random.next_float() * 0.4 + 0.8);
|
||||
if self.hook.is_some() {
|
||||
let damage = self.retrieve_hook();
|
||||
let damage = self.retrieve_hook(stack);
|
||||
self.damage_held(damage);
|
||||
self.audio.play(
|
||||
"minecraft:entity.fishing_bobber.retrieve",
|
||||
@@ -143,7 +144,7 @@ impl Game<'_> {
|
||||
true
|
||||
}
|
||||
/// `FishingHook.retrieve`: the rod damage it costs.
|
||||
fn retrieve_hook(&mut self) -> u32 {
|
||||
fn retrieve_hook(&mut self, rod: &ItemStack) -> u32 {
|
||||
let Some(hook) = self.hook.take() else {
|
||||
return 0;
|
||||
};
|
||||
@@ -167,6 +168,15 @@ impl Game<'_> {
|
||||
item.velocity = pulled(item.velocity);
|
||||
hooked_item = true;
|
||||
}
|
||||
// CriteriaTriggers.FISHING_ROD_HOOKED with no items.
|
||||
let hooked = self
|
||||
.mobs
|
||||
.iter()
|
||||
.find(|m| m.id == id)
|
||||
.map(|m| self.mob_entity(m));
|
||||
if let Some(hooked) = hooked {
|
||||
self.trigger_fishing_rod_hooked(rod, &hooked, &[]);
|
||||
}
|
||||
// `hookedIn instanceof ItemEntity ? 3 : 5`.
|
||||
damage = if hooked_item { 3 } else { 5 };
|
||||
} else if hook.nibble > 0 {
|
||||
@@ -191,6 +201,7 @@ impl Game<'_> {
|
||||
Some(hook.open_water),
|
||||
);
|
||||
self.world.random = random;
|
||||
let mut caught = Vec::new();
|
||||
for stack in items {
|
||||
// FishingHook.retrieve: fish_caught for each catch in #minecraft:fishes.
|
||||
if self
|
||||
@@ -222,6 +233,7 @@ impl Game<'_> {
|
||||
if let Some(potion) = &stack.potion {
|
||||
item = item.with_potion(potion);
|
||||
}
|
||||
caught.push(item.clone());
|
||||
let (dx, dy, dz) = (
|
||||
owner.x - hook.position.x,
|
||||
owner.y - hook.position.y,
|
||||
@@ -241,6 +253,15 @@ impl Game<'_> {
|
||||
let xp = self.world.random.next_int_bound(6).unwrap_or(0) as u32 + 1;
|
||||
self.spawn_orbs([owner.x, owner.y + 0.5, owner.z + 0.5], xp);
|
||||
}
|
||||
// CriteriaTriggers.FISHING_ROD_HOOKED: the hook itself is the entity.
|
||||
let bobber = EntityView {
|
||||
kind: "minecraft:fishing_bobber".into(),
|
||||
position: [hook.position.x, hook.position.y, hook.position.z],
|
||||
on_ground: hook.on_ground,
|
||||
fishing_open_water: Some(hook.open_water),
|
||||
..Default::default()
|
||||
};
|
||||
self.trigger_fishing_rod_hooked(rod, &bobber, &caught);
|
||||
damage = 1;
|
||||
}
|
||||
if hook.on_ground {
|
||||
@@ -433,6 +454,8 @@ impl Game<'_> {
|
||||
let options = ParticleOptions::simple(kind);
|
||||
self.particles
|
||||
.send_particles(&options, at, spread, speed, count);
|
||||
// The players a server serves are sent them too.
|
||||
self.lan_send_particles(&options, at, spread, speed, count);
|
||||
}
|
||||
/// `FishingHook.tick`.
|
||||
pub(super) fn tick_fishing(&mut self) {
|
||||
|
||||
@@ -114,7 +114,7 @@ impl Game<'_> {
|
||||
living: Some(HurtBob {
|
||||
hurt_time: p.health.hurt_animation_time as f32 - partial,
|
||||
hurt_duration: hurt.hurt_duration,
|
||||
hurt_dir: 0.0,
|
||||
hurt_dir: p.health.hurt_dir,
|
||||
death_time: self.death_time().map(|t| t as f32 + partial),
|
||||
}),
|
||||
player: Some((
|
||||
|
||||
@@ -79,6 +79,7 @@ impl Game<'_> {
|
||||
if !self.creative {
|
||||
self.consume_held();
|
||||
}
|
||||
self.stats.custom("play_record", 1);
|
||||
self.world.block_entities.insert(
|
||||
(pos[0], pos[1], pos[2]),
|
||||
BlockEntity::Jukebox(Jukebox {
|
||||
@@ -90,6 +91,8 @@ impl Game<'_> {
|
||||
self.set_has_record(pos, true);
|
||||
self.start_song(pos, &song);
|
||||
self.jukebox_changed(pos);
|
||||
// ServerPlayerGameMode.useItemOn: the action was consumed.
|
||||
self.trigger_block("minecraft:item_used_on_block", pos, stack);
|
||||
true
|
||||
}
|
||||
/// Level event 1010: the song from the jukebox, and the "Now Playing" overlay.
|
||||
|
||||
@@ -338,6 +338,14 @@ fn mob_meta(
|
||||
meta.push((19, serializer::BOOLEAN, Value::Bool(true)));
|
||||
}
|
||||
}
|
||||
// HappyGhast.STAYS_STILL (after AgeableMob's two and IS_LEASH_HOLDER),
|
||||
// set while `serverStillTimeout > 0` (`syncStayStillFlag`).
|
||||
"minecraft:happy_ghast" => {
|
||||
if horizon_client::mobs::happy_ghast::on_still_timeout(m) {
|
||||
meta.push((19, serializer::BOOLEAN, Value::Bool(true)));
|
||||
}
|
||||
defaults.push((19, serializer::BOOLEAN, Value::Bool(false)));
|
||||
}
|
||||
// Villager.DATA_VILLAGER_DATA and ZombieVillager's (after Zombie's three).
|
||||
"minecraft:villager" | "minecraft:zombie_villager" => {
|
||||
use horizon_client::mobs::render::{PROFESSIONS, VILLAGER_TYPES};
|
||||
@@ -652,7 +660,8 @@ impl Game<'_> {
|
||||
let host_uuid = host.unwrap_or(0);
|
||||
self.next_entity += 1;
|
||||
let host_entity = self.next_entity as i32;
|
||||
let hub = Hub::new(lan, sync, encoder, config);
|
||||
let mut hub = Hub::new(lan, sync, encoder, config);
|
||||
hub.flat_world = self.world_flat;
|
||||
let port = hub.lan.port;
|
||||
self.world.block_log = Some(Vec::new());
|
||||
self.world.light_log = Some(Default::default());
|
||||
@@ -910,7 +919,7 @@ impl Game<'_> {
|
||||
out.clear();
|
||||
for m in self.mobs.iter().filter(|m| !m.removed) {
|
||||
// The lead's holder: the player the mob sees (a guest, else the
|
||||
// host) or another mob. A fence knot isn't an entity here.
|
||||
// host), another mob or a fence knot (game/lan_entities.rs).
|
||||
let player_entity = mob_players
|
||||
.get(&m.id)
|
||||
.and_then(|conn| hub.guest(*conn))
|
||||
@@ -919,7 +928,7 @@ impl Game<'_> {
|
||||
let leash = m.extra.leash.and_then(|h| match h {
|
||||
Holder::Player => player_entity,
|
||||
Holder::Mob(id) => Some(id as i32),
|
||||
Holder::Knot(_) => None,
|
||||
Holder::Knot(p) => self.knot_ids.get(&p).map(|&id| id as i32),
|
||||
});
|
||||
let e = out.add(m.id as i32, entity_uuid(m.id), m.kind.id.as_str());
|
||||
e.position = [m.position.x, m.position.y, m.position.z];
|
||||
@@ -928,6 +937,9 @@ impl Game<'_> {
|
||||
e.velocity = [m.velocity.x, m.velocity.y, m.velocity.z];
|
||||
e.needs_sync = m.needs_sync;
|
||||
mob_meta(m, hub, player_entity, &mut e.meta, &mut e.defaults);
|
||||
// HappyGhast.aiStep: requiresPrecisePosition while on a still timeout.
|
||||
e.precise = m.species() == horizon_client::mobs::Species::HappyGhast
|
||||
&& horizon_client::mobs::happy_ghast::on_still_timeout(m);
|
||||
mob_equipment(m, hub, &mut e.equipment);
|
||||
self.mob_attributes(m, &mut e.attributes);
|
||||
e.leash = leash;
|
||||
@@ -1004,6 +1016,9 @@ impl Game<'_> {
|
||||
for m in &mut self.mobs {
|
||||
m.needs_sync = false;
|
||||
}
|
||||
for p in &mut self.creatures.projectiles {
|
||||
p.needs_sync = false;
|
||||
}
|
||||
// `runBlockEvents`' broadcast precedes the tick's block changes
|
||||
// (`ChunkHolder.broadcastChanges` in `tick_level` below): the
|
||||
// guest re-runs a piston's `triggerEvent` while its level still
|
||||
@@ -1164,8 +1179,11 @@ impl Game<'_> {
|
||||
drop(holding);
|
||||
lan::flush_all(host.hub.guests.iter().map(|g| &g.sender));
|
||||
self.lan = Some(host);
|
||||
// A mace's wind burst from a guest's attack.
|
||||
// A blast from a guest's attack, and a mace's wind burst.
|
||||
self.flush_lan_explosions();
|
||||
let _ = self.flush_wind_bursts();
|
||||
// Particles a guest's turn sent (sweep attack, damage indicator, a hook's splashes).
|
||||
self.flush_lan_particles();
|
||||
}
|
||||
|
||||
fn lan_guest_joined(
|
||||
@@ -1267,8 +1285,9 @@ impl Game<'_> {
|
||||
horizon_world::level::LevelEvent::LevelEvent { id, pos, data } => {
|
||||
// The acting guest does not predict the egg's teleport
|
||||
// particles, bone meal's growth, or anvil result sounds
|
||||
// (these levelEvent calls name no excluded player).
|
||||
let except = if matches!(*id, 2015 | 1505 | 1029 | 1030) {
|
||||
// (these levelEvent calls name no excluded player), nor
|
||||
// the digger's own crack and hit sound (2019, 2020).
|
||||
let except = if matches!(*id, 2015 | 1505 | 1029 | 1030 | 2019 | 2020) {
|
||||
None
|
||||
} else {
|
||||
self.lan_acting
|
||||
|
||||
@@ -75,6 +75,8 @@ pub(super) struct GuestPlay {
|
||||
/// `ServerPlayer.getStats` and the inventory `inventory_changed` last saw.
|
||||
pub(super) stats: super::stats::Stats,
|
||||
last_inventory: u64,
|
||||
/// `ServerPlayer.levitationStartPos` and `levitationStartTime`.
|
||||
levitation: Option<([f64; 3], u64)>,
|
||||
/// `Entity.portalProcess` and `portalCooldown` (game/server_travel.rs).
|
||||
pub(super) portal: horizon_client::nether_portal::PortalState,
|
||||
/// `ServerPlayer.wonGame`: the End poem is showing, the player waits for
|
||||
@@ -158,6 +160,7 @@ pub(super) struct GuestSwap {
|
||||
host_ender: Option<(i32, i32, i32)>,
|
||||
adv_loaded: bool,
|
||||
last_inventory: u64,
|
||||
levitation: Option<([f64; 3], u64)>,
|
||||
death_cause: Option<String>,
|
||||
/// The guest's own damage record, in place while they act.
|
||||
combat: super::combat::CombatTracker,
|
||||
@@ -265,8 +268,10 @@ impl Game<'_> {
|
||||
}
|
||||
let mut play = host.play.remove(&conn).unwrap_or_default();
|
||||
if fresh {
|
||||
// A new body (joined, respawned, changed level): nothing on it yet.
|
||||
// A new body (joined, respawned, changed level): nothing on it yet,
|
||||
// its effects' modifiers and armor protection included.
|
||||
play.equipped = None;
|
||||
play.potions = Default::default();
|
||||
play.sculk = Default::default();
|
||||
}
|
||||
let g = &mut host.hub.guests[i];
|
||||
@@ -382,6 +387,7 @@ impl Game<'_> {
|
||||
std::mem::swap(&mut self.hook, &mut play.hook);
|
||||
let adv_loaded = std::mem::replace(&mut self.adv.loaded, true);
|
||||
let last_inventory = std::mem::replace(&mut self.adv.last_inventory, play.last_inventory);
|
||||
let levitation = std::mem::replace(&mut self.adv.levitation, play.levitation);
|
||||
let death_cause = std::mem::replace(&mut self.ui.death_cause, play.death_cause.take());
|
||||
let acting = (
|
||||
self.lan_acting.replace(conn),
|
||||
@@ -402,6 +408,12 @@ impl Game<'_> {
|
||||
self.apply_equipment();
|
||||
play.equipped = Some(equipped);
|
||||
}
|
||||
// The player's effects are on the new body before anything it does
|
||||
// (the movement that brought it, a landing): vanilla keeps the same
|
||||
// entity through a level change, with its attributes and effects.
|
||||
if fresh {
|
||||
self.apply_effect_status();
|
||||
}
|
||||
self.update_totem_ready();
|
||||
Some(GuestSwap {
|
||||
conn,
|
||||
@@ -446,6 +458,7 @@ impl Game<'_> {
|
||||
host_ender,
|
||||
adv_loaded,
|
||||
last_inventory,
|
||||
levitation,
|
||||
death_cause,
|
||||
acting,
|
||||
packets,
|
||||
@@ -504,6 +517,7 @@ impl Game<'_> {
|
||||
host_ender,
|
||||
adv_loaded,
|
||||
last_inventory,
|
||||
levitation,
|
||||
death_cause,
|
||||
combat,
|
||||
acting,
|
||||
@@ -614,6 +628,7 @@ impl Game<'_> {
|
||||
std::mem::swap(&mut self.hook, &mut play.hook);
|
||||
self.adv.loaded = adv_loaded;
|
||||
play.last_inventory = std::mem::replace(&mut self.adv.last_inventory, last_inventory);
|
||||
play.levitation = std::mem::replace(&mut self.adv.levitation, levitation);
|
||||
let stat_events = std::mem::take(&mut play.stats.events);
|
||||
let name = g.name.clone();
|
||||
self.potions.swap_player(&mut g.effects, &mut play.potions);
|
||||
@@ -657,6 +672,13 @@ impl Game<'_> {
|
||||
g.sprinting = false;
|
||||
}
|
||||
m.sprinting = false;
|
||||
// ServerPlayer.indicateDamage: the hit's direction to the player.
|
||||
if let Some(yaw) = m.health.indicated_dir.take() {
|
||||
g.send(&C::HurtAnimation(play::HurtAnimation {
|
||||
id: g.entity_id,
|
||||
yaw,
|
||||
}));
|
||||
}
|
||||
let teleported = std::mem::take(&mut m.teleported);
|
||||
let moved: f64 = (0..3).map(|k| (at[k] - g.position[k]).powi(2)).sum();
|
||||
g.motion = Some(Box::new(m));
|
||||
@@ -858,13 +880,17 @@ impl Game<'_> {
|
||||
}
|
||||
|
||||
/// The guest's open container is closing (`AbstractContainerMenu.removed`):
|
||||
/// it no longer counts among the openers of the lid.
|
||||
/// it no longer counts among the openers of the lid, and the lid's close
|
||||
/// sound is played for everyone around (`ChestBlockEntity.onClose`, a
|
||||
/// `playSound` with no player), the guest included, once the last opener
|
||||
/// has left.
|
||||
pub(super) fn guest_container_closed(&mut self, host: &mut LanHost, conn: u32) {
|
||||
if let Some(g) = host.hub.guest(conn)
|
||||
&& let Some(pos) = g.menu.as_ref().and_then(|m| m.pos)
|
||||
&& !g.spectator()
|
||||
&& self.container_openers_changed(pos, false)
|
||||
{
|
||||
self.container_openers_changed(pos, false);
|
||||
self.container_edge_sound(pos, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -958,6 +984,20 @@ impl Game<'_> {
|
||||
// The pause between two blocks is the client's (MultiPlayerGameMode's
|
||||
// destroyDelay); the server digs from the START it receives.
|
||||
play.destroy_delay = 0;
|
||||
// ServerPlayerGameMode.handleBlockBreakAction: a survival START
|
||||
// attacks the block at once, so a tap released in the same tick
|
||||
// still plays a note. The dig is marked begun for tick_mining.
|
||||
let pos = a.pos;
|
||||
self.as_guest(host, conn, |g| {
|
||||
if g.may_build() && !g.creative {
|
||||
let _ = g.attack_block(pos);
|
||||
g.mining = Some(Mining {
|
||||
pos,
|
||||
progress: 0.0,
|
||||
ticks: 0,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
1 => {}
|
||||
3 => {
|
||||
@@ -1524,9 +1564,13 @@ impl Game<'_> {
|
||||
if let Some(victim) = Self::pvp_victim(host, conn, id) {
|
||||
if let Some(Some(strike)) = self.as_guest(host, conn, |g| g.pvp_strike())
|
||||
&& self.pvp_land(host, victim, &strike)
|
||||
&& strike.stops_sprint()
|
||||
{
|
||||
self.as_guest(host, conn, |g| g.stop_sprint_after_extra_knockback());
|
||||
self.as_guest(host, conn, |g| {
|
||||
g.pvp_exhaustion();
|
||||
if strike.stops_sprint() {
|
||||
g.stop_sprint_after_extra_knockback();
|
||||
}
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -1831,10 +1875,6 @@ impl Game<'_> {
|
||||
};
|
||||
xp.respawn(self.ui.rules.bool("keep_inventory") || g.game_mode == SPECTATOR);
|
||||
(g.xp_level, g.xp_progress, g.xp_total) = (xp.level, xp.progress, xp.total);
|
||||
// A new body: nothing given to the old one carries over.
|
||||
if let Some(play) = host.play.get_mut(&conn) {
|
||||
play.potions = Default::default();
|
||||
}
|
||||
let clock_rate = self.network_clock_rate();
|
||||
let ctx = TickCtx {
|
||||
world: &mut self.world,
|
||||
@@ -2311,6 +2351,13 @@ impl Game<'_> {
|
||||
// ServerEntity.sendChanges sends it as it is after this travel.
|
||||
let marked = std::mem::take(&mut player.health.sync_velocity);
|
||||
let velocity = marked.then_some(player.velocity);
|
||||
// Player.causeFallDamage: a fall of 2 blocks or more counts.
|
||||
for event in &events {
|
||||
if let MotionEvent::Fall(horizon_client::landing::FallEvent::Statistic(cm)) = event
|
||||
{
|
||||
game.stats.custom("fall_one_cm", *cm);
|
||||
}
|
||||
}
|
||||
game.record_combat(&events);
|
||||
game.wear_armor(&events);
|
||||
(events, velocity)
|
||||
|
||||
@@ -127,9 +127,18 @@ impl Game<'_> {
|
||||
}
|
||||
let dropped = std::mem::take(&mut menu.dropped);
|
||||
let equipped = std::mem::take(&mut menu.equipped);
|
||||
let brewed = std::mem::take(&mut menu.brewed);
|
||||
menu.drops.clear();
|
||||
menu.crafted.clear();
|
||||
store_player(menu, &mut host.hub.guests[gi]);
|
||||
if !brewed.is_empty() {
|
||||
let conn = host.hub.guests[gi].conn;
|
||||
self.as_guest(host, conn, |g| {
|
||||
for stack in &brewed {
|
||||
g.trigger_brewed_potion(stack);
|
||||
}
|
||||
});
|
||||
}
|
||||
if !equipped.is_empty() {
|
||||
let conn = host.hub.guests[gi].conn;
|
||||
self.as_guest(host, conn, |g| {
|
||||
|
||||
@@ -225,6 +225,16 @@ impl Game<'_> {
|
||||
}
|
||||
out.push(e);
|
||||
}
|
||||
for (p, &id) in &self.knot_ids {
|
||||
// LeashFenceKnotEntity.getAddEntityPacket: the fence's block.
|
||||
out.push(state(
|
||||
id,
|
||||
"minecraft:leash_knot",
|
||||
p.map(f64::from),
|
||||
0.0,
|
||||
false,
|
||||
));
|
||||
}
|
||||
for p in &self.paintings {
|
||||
let mut e = state(p.id, "minecraft:painting", p.pos.map(f64::from), 0.0, false);
|
||||
// Direction.get2DDataValue (south 0, west 1, north 2, east 3) to its
|
||||
@@ -270,6 +280,24 @@ impl Game<'_> {
|
||||
/// Gives the entities Horizon keeps without an id one (`Entity.id`, from
|
||||
/// the same counter as the rest) before they are first tracked.
|
||||
pub(super) fn lan_assign_ids(&mut self) {
|
||||
// LeashFenceKnotEntity: one per fence post with a lead on it
|
||||
// (`notifyLeasheeRemoved` discards it once the last lead is gone).
|
||||
let knots: Vec<[i32; 3]> = self
|
||||
.mobs
|
||||
.iter()
|
||||
.filter(|m| !m.removed)
|
||||
.filter_map(|m| match m.extra.leash {
|
||||
Some(horizon_client::mobs::leash::Holder::Knot(p)) => Some(p),
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
self.knot_ids.retain(|p, _| knots.contains(p));
|
||||
for p in knots {
|
||||
self.knot_ids.entry(p).or_insert_with(|| {
|
||||
self.next_entity += 1;
|
||||
self.next_entity
|
||||
});
|
||||
}
|
||||
let next = &mut self.next_entity;
|
||||
let mut give = |id: &mut u32| {
|
||||
if *id == 0 {
|
||||
@@ -342,6 +370,7 @@ impl Game<'_> {
|
||||
let mut e = state(p.id, kind, at(p.position), p.yaw, false);
|
||||
e.pitch = p.pitch;
|
||||
e.velocity = at(p.velocity);
|
||||
e.needs_sync = p.needs_sync;
|
||||
// Projectile.getAddEntityPacket: the owner's id.
|
||||
e.data = match p.guest.and_then(|conn| hub.guest(conn)) {
|
||||
Some(g) => g.entity_id,
|
||||
@@ -466,7 +495,7 @@ impl Game<'_> {
|
||||
}
|
||||
out.push(e);
|
||||
}
|
||||
// The dragon's breath clouds (AreaEffectCloud's DATA_RADIUS,
|
||||
// The dragon's breath and lingering potion clouds (AreaEffectCloud's DATA_RADIUS,
|
||||
// DATA_WAITING for its 20-tick wait, and DATA_PARTICLE): the
|
||||
// client draws them from these (`tick_remote_clouds`).
|
||||
let breath = self.network_particle(
|
||||
@@ -484,10 +513,14 @@ impl Game<'_> {
|
||||
for b in self.breath_clouds.iter().filter(|b| b.id != 0) {
|
||||
let mut e = state(b.id, "minecraft:area_effect_cloud", b.at, 0.0, false);
|
||||
e.meta.push((8, serializer::FLOAT, Value::Float(b.radius)));
|
||||
if b.age < 20 {
|
||||
if b.waiting() {
|
||||
e.meta.push((9, serializer::BOOLEAN, Value::Bool(true)));
|
||||
}
|
||||
if let Some(p) = &breath {
|
||||
let particle = match &b.potion {
|
||||
Some(p) => self.network_particle(&p.particle(), None),
|
||||
None => breath.clone(),
|
||||
};
|
||||
if let Some(p) = &particle {
|
||||
e.meta
|
||||
.push((10, serializer::PARTICLE, Value::Particle(p.clone())));
|
||||
}
|
||||
|
||||
@@ -363,6 +363,7 @@ mod tests {
|
||||
off_hand: None,
|
||||
head: None,
|
||||
armor_cover: 0.0,
|
||||
invisible: false,
|
||||
spectator: false,
|
||||
gold_armor: false,
|
||||
hurt_by: None,
|
||||
@@ -374,6 +375,7 @@ mod tests {
|
||||
uuid: [0; 4],
|
||||
allies: Default::default(),
|
||||
remote: false,
|
||||
passenger: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -318,16 +318,86 @@ impl Game<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
/// `ServerLevel.sendParticles` for the players a server serves: one
|
||||
/// `ClientboundLevelParticlesPacket` to each player in the level whose
|
||||
/// block is within 32 blocks of `at`. The window's own player is not
|
||||
/// sent it (the caller draws it in this window). While the host holds
|
||||
/// the players (a guest's turn through `as_guest`, a host's hit on a
|
||||
/// guest) the packet waits for the turn to end so that it reaches every
|
||||
/// player, the guest too.
|
||||
pub(super) fn lan_send_particles(
|
||||
&mut self,
|
||||
options: &ParticleOptions,
|
||||
at: [f64; 3],
|
||||
spread: [f64; 3],
|
||||
speed: f64,
|
||||
count: u32,
|
||||
) {
|
||||
if self.lan.is_none() {
|
||||
// The server is running (its sounds are captured for the guests).
|
||||
if self.audio.capture.is_some() {
|
||||
self.creatures
|
||||
.lan_particles
|
||||
.push((options.clone(), at, spread, speed, count));
|
||||
}
|
||||
return;
|
||||
}
|
||||
let Some(particle) = self.network_particle(options, None) else {
|
||||
return;
|
||||
};
|
||||
let Some(host) = self.lan.as_ref() else {
|
||||
return;
|
||||
};
|
||||
let body = C::LevelParticles(play::LevelParticles {
|
||||
particle,
|
||||
override_limiter: false,
|
||||
always_show: false,
|
||||
pos: at,
|
||||
dist: spread.map(|d| d as f32),
|
||||
max_speed: [speed as f32; 3],
|
||||
count: count as i32,
|
||||
randomization: 0,
|
||||
})
|
||||
.encode();
|
||||
for g in host.hub.guests.iter().filter(|g| host.hub.here(g)) {
|
||||
// BlockPos.closerToCenterThan(at, 32): from the centre of the
|
||||
// player's block.
|
||||
let d: f64 = (0..3)
|
||||
.map(|k| (g.position[k].floor() + 0.5 - at[k]).powi(2))
|
||||
.sum();
|
||||
if d < 32.0 * 32.0 {
|
||||
g.sender.send(body.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The particles guests' turns put off.
|
||||
pub(super) fn flush_lan_particles(&mut self) {
|
||||
for (options, at, spread, speed, count) in std::mem::take(&mut self.creatures.lan_particles)
|
||||
{
|
||||
self.lan_send_particles(&options, at, spread, speed, count);
|
||||
}
|
||||
}
|
||||
|
||||
/// `ServerLevel.explode`'s packet to each player within 64 blocks. The
|
||||
/// sound and the push reach them on their own (the level's sounds, the
|
||||
/// motion a hurt player is sent), so the packet carries neither.
|
||||
pub(super) fn lan_explode(
|
||||
&self,
|
||||
&mut self,
|
||||
center: [f64; 3],
|
||||
small: bool,
|
||||
radius: f32,
|
||||
block_count: usize,
|
||||
) {
|
||||
// In a guest's turn (their hit on an end crystal or a minecart) the
|
||||
// host holds the players (`as_guest`): the packet waits for the turn
|
||||
// to end so that it reaches every player, the guest too.
|
||||
if self.lan_acting.is_some() && self.lan.is_none() {
|
||||
self.creatures
|
||||
.lan_explosions
|
||||
.push((center, small, radius, block_count));
|
||||
return;
|
||||
}
|
||||
let emitter = if small {
|
||||
"minecraft:explosion"
|
||||
} else {
|
||||
@@ -341,6 +411,15 @@ impl Game<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
/// The explosions guests' turns put off.
|
||||
pub(super) fn flush_lan_explosions(&mut self) {
|
||||
for (center, small, radius, block_count) in
|
||||
std::mem::take(&mut self.creatures.lan_explosions)
|
||||
{
|
||||
self.lan_explode(center, small, radius, block_count);
|
||||
}
|
||||
}
|
||||
|
||||
/// A wind charge's burst (`AbstractWindCharge.explode`): gust emitters,
|
||||
/// no block particles, and for each player it pushed the push
|
||||
/// (`ServerExplosion.hitPlayers`), which only that client applies, as
|
||||
|
||||
@@ -86,9 +86,11 @@ impl Game<'_> {
|
||||
};
|
||||
if let Some(strike) = self.pvp_strike()
|
||||
&& self.pvp_land(&mut host, Victim::Guest(conn), &strike)
|
||||
&& strike.stops_sprint()
|
||||
{
|
||||
self.stop_sprint_after_extra_knockback();
|
||||
self.pvp_exhaustion();
|
||||
if strike.stops_sprint() {
|
||||
self.stop_sprint_after_extra_knockback();
|
||||
}
|
||||
}
|
||||
self.lan = Some(host);
|
||||
true
|
||||
@@ -106,8 +108,18 @@ impl Game<'_> {
|
||||
.map(|g| Victim::Guest(g.conn))
|
||||
}
|
||||
|
||||
/// `Player.attack`'s `causeFoodExhaustion(0.1F)`, charged to the attacker
|
||||
/// (the host, or a guest swapped in) only once the hit hurt the victim.
|
||||
pub(super) fn pvp_exhaustion(&mut self) {
|
||||
if let Some(p) = self.player.as_mut()
|
||||
&& !self.creative
|
||||
{
|
||||
p.cause_food_exhaustion(0.1);
|
||||
}
|
||||
}
|
||||
|
||||
/// The attacker's side of `Player.attack` (the host, or a guest swapped
|
||||
/// in): the damage, the charge reset, the exhaustion and the swing.
|
||||
/// in): the damage, the charge reset and the swing.
|
||||
pub(super) fn pvp_strike(&mut self) -> Option<Strike> {
|
||||
let p = self.player.as_ref()?;
|
||||
let from = [p.position.x, p.position.y, p.position.z];
|
||||
@@ -116,11 +128,6 @@ impl Game<'_> {
|
||||
let (strength, knockback_attack) = self.extra_knockback("minecraft:player", scale);
|
||||
let (xd, zd) = self.extra_knockback_direction();
|
||||
self.attack_ticks = 0;
|
||||
if let Some(p) = self.player.as_mut()
|
||||
&& !self.creative
|
||||
{
|
||||
p.cause_food_exhaustion(0.1);
|
||||
}
|
||||
self.swing_arm();
|
||||
Some(Strike {
|
||||
attacker: self.lan_acting,
|
||||
@@ -260,6 +267,30 @@ impl Game<'_> {
|
||||
} else {
|
||||
Default::default()
|
||||
};
|
||||
// ServerPlayer.awardKillScore: the blow that kills a player.
|
||||
if hurt {
|
||||
let died = match victim {
|
||||
// A totem that fired is applied on the next tick_totem, so the
|
||||
// victim is still at zero health but is not dying.
|
||||
Victim::Host => self
|
||||
.player
|
||||
.as_ref()
|
||||
.is_some_and(|p| p.health.dead_or_dying() && !p.health.totem_used),
|
||||
Victim::Guest(conn) => host
|
||||
.hub
|
||||
.guest(conn)
|
||||
.and_then(|g| g.motion.as_deref())
|
||||
.is_some_and(|p| p.health.dead_or_dying() && !p.health.totem_used),
|
||||
};
|
||||
if died {
|
||||
match s.attacker {
|
||||
Some(conn) => {
|
||||
self.as_guest(host, conn, |g| g.stats.custom("player_kills", 1));
|
||||
}
|
||||
None => self.stats.custom("player_kills", 1),
|
||||
}
|
||||
}
|
||||
}
|
||||
if hurt && (s.crit || s.magic) {
|
||||
let target = match victim {
|
||||
Victim::Host => self.player.as_ref().map(|p| (host.host_entity, p)),
|
||||
|
||||
@@ -317,6 +317,8 @@ impl Game<'_> {
|
||||
self.as_guest(host, conn, |game| {
|
||||
game.give_levels(-need);
|
||||
game.stats.custom("enchant_item", 1);
|
||||
// CriteriaTriggers.ENCHANTED_ITEM, with the levels it cost.
|
||||
game.trigger_enchanted_item(&enchanted, need);
|
||||
});
|
||||
host.hub.guests[gi].xp_seed = self.world.random.next_int();
|
||||
let env = self.menu_env();
|
||||
|
||||
@@ -277,7 +277,12 @@ impl Game<'_> {
|
||||
g.carried = menu.carried.take();
|
||||
}
|
||||
self.register_exploration_maps(made);
|
||||
gm.merchant.session = self.merchant_apply(session, gm.merchant.mob);
|
||||
let (session, traded) = self.merchant_apply(session, gm.merchant.mob);
|
||||
gm.merchant.session = session;
|
||||
if !traded.is_empty() {
|
||||
// The guest's own statistic and advancements.
|
||||
self.as_guest(host, conn, |g| g.merchant_traded(gm.merchant.mob, &traded));
|
||||
}
|
||||
self.drop_guest_items(host, gi, dropped);
|
||||
self.lan_send_offers(host, conn, &mut gm, false);
|
||||
self.lan_send_merchant_content(host, conn, &mut gm);
|
||||
|
||||
@@ -36,7 +36,7 @@ impl Game<'_> {
|
||||
// 3002 with an axis: a lightning rod; otherwise copper cleaned by lightning.
|
||||
match usize::try_from(data) {
|
||||
Ok(axis) if id == 3002 && axis < 3 => {
|
||||
particles::along_axis(random, axis, p, |p, v| spawned.push((p, v)));
|
||||
particles::along_axis(random, axis, p, (10, 19), |p, v| spawned.push((p, v)));
|
||||
}
|
||||
_ => particles::on_block_faces(random, p, |p, v| spawned.push((p, v))),
|
||||
}
|
||||
@@ -310,6 +310,30 @@ impl Game<'_> {
|
||||
// Each guest plays it from the global packet.
|
||||
self.audio.play_unshared(sound, at, volume, 1.0);
|
||||
}
|
||||
/// `ClientLevel.addBreakingBlockEffects`: the block's hit sound (only for
|
||||
/// `play_sound`) and one crumb on the face being mined; nothing for air.
|
||||
pub(super) fn breaking_block_effects(
|
||||
&mut self,
|
||||
pos: [i32; 3],
|
||||
face: [i32; 3],
|
||||
play_sound: bool,
|
||||
) {
|
||||
let state = self.world.block(pos[0], pos[1], pos[2]);
|
||||
if self.res.facts().is_air(state) {
|
||||
return;
|
||||
}
|
||||
if play_sound {
|
||||
let sounds = self.res.facts().get(state).sounds.clone();
|
||||
// Each guest plays it from the level event itself.
|
||||
self.audio.play_unshared(
|
||||
&sounds.hit,
|
||||
Some(pos.map(|v| f64::from(v) + 0.5)),
|
||||
(sounds.volume + 1.0) / 8.0,
|
||||
sounds.pitch * 0.5,
|
||||
);
|
||||
}
|
||||
self.crack_particle(pos, face, state);
|
||||
}
|
||||
/// `LevelEventHandler.potionSplashParticles` (2002 with `Effect`, 2007
|
||||
/// with `InstantEffect`): eight splash potion crumbs, and a hundred
|
||||
/// spell particles in the potion's colour `data`, flung out in a disc.
|
||||
|
||||
@@ -66,6 +66,8 @@ pub(super) struct Parked {
|
||||
tnts: Vec<tnt::PrimedTnt>,
|
||||
hoppers: HashMap<(i32, i32, i32), machines::HopperState>,
|
||||
mobs: Vec<Mob>,
|
||||
/// The entity ids of the level's fence knots (`knot_ids`).
|
||||
knot_ids: HashMap<[i32; 3], u32>,
|
||||
projectiles: Vec<horizon_client::projectiles::Projectile>,
|
||||
dropped: Vec<ItemEntity>,
|
||||
orbs: Vec<ExperienceOrb>,
|
||||
@@ -166,6 +168,7 @@ impl Game<'_> {
|
||||
tnts: Vec::new(),
|
||||
hoppers: HashMap::new(),
|
||||
mobs: Vec::new(),
|
||||
knot_ids: HashMap::new(),
|
||||
projectiles: Vec::new(),
|
||||
dropped: Vec::new(),
|
||||
orbs: Vec::new(),
|
||||
@@ -219,6 +222,7 @@ impl Game<'_> {
|
||||
swap(&mut self.tnts, &mut p.tnts);
|
||||
swap(&mut self.hoppers, &mut p.hoppers);
|
||||
swap(&mut self.mobs, &mut p.mobs);
|
||||
swap(&mut self.knot_ids, &mut p.knot_ids);
|
||||
swap(&mut self.creatures.projectiles, &mut p.projectiles);
|
||||
swap(&mut self.dropped, &mut p.dropped);
|
||||
swap(&mut self.orbs, &mut p.orbs);
|
||||
|
||||
@@ -16,7 +16,7 @@ pub(super) struct Bolt {
|
||||
flashes: i32,
|
||||
seed: i64,
|
||||
visual_only: bool,
|
||||
/// Mooshrooms switch colour once per bolt.
|
||||
/// Mooshrooms and copper golems change once per bolt.
|
||||
converted: Vec<u32>,
|
||||
}
|
||||
impl Game<'_> {
|
||||
@@ -278,6 +278,13 @@ impl Game<'_> {
|
||||
}
|
||||
self.strike_rod(b.at);
|
||||
}
|
||||
// LightningBolt.tick runs clearCopperOnLightningStrike for
|
||||
// every server bolt, a skeleton trap's visual one included;
|
||||
// a client's copy of a server bolt (spawn_remote_bolt) only
|
||||
// flashes.
|
||||
if self.remote.is_none() {
|
||||
self.bolt_clear_copper(b.at);
|
||||
}
|
||||
}
|
||||
b.life -= 1;
|
||||
if b.life < 0 {
|
||||
@@ -334,6 +341,16 @@ impl Game<'_> {
|
||||
self.level_event_at(3002, p, axis);
|
||||
}
|
||||
}
|
||||
/// `LightningBolt.clearCopperOnLightningStrike` at the block the bolt struck.
|
||||
fn bolt_clear_copper(&mut self, at: [f64; 3]) {
|
||||
let p = BlockPos::new(
|
||||
at[0].floor() as i32,
|
||||
(at[1] - 1.0e-6).floor() as i32,
|
||||
at[2].floor() as i32,
|
||||
);
|
||||
self.with_level(|b, level, ticks| b.lightning_clear_copper(level, ticks, p));
|
||||
let _ = self.process_level_events();
|
||||
}
|
||||
/// `thunderHit` for entities within 3 blocks (up to 9 above).
|
||||
fn thunder_hit(&mut self, b: &mut Bolt) {
|
||||
let at = b.at;
|
||||
@@ -393,6 +410,17 @@ impl Game<'_> {
|
||||
continue;
|
||||
}
|
||||
Species::Creeper => m.extra.charged = true,
|
||||
// CopperGolem.thunderHit (after Entity.thunderHit's fire and
|
||||
// damage): once per bolt, an oxidized golem goes back one step
|
||||
// and its weathering timer (or wax, -2) is reset to -1.
|
||||
Species::CopperGolem if !b.converted.contains(&m.id) => {
|
||||
b.converted.push(m.id);
|
||||
if m.extra.variant > 0 {
|
||||
m.extra.vector[0] = -1.0;
|
||||
m.extra.variant =
|
||||
horizon_client::mobs::copper_golem::weather_previous(m.extra.variant);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
// Entity.thunderHit: burning (8 seconds) and 5 lightning damage.
|
||||
|
||||
@@ -25,11 +25,13 @@ impl Game<'_> {
|
||||
};
|
||||
let m = &mut self.mobs[index];
|
||||
let mut used = false;
|
||||
let mut loved = false;
|
||||
if item == "minecraft:hay_block" && m.extra.tame && m.extra.age == 0 && m.extra.in_love <= 0
|
||||
{
|
||||
m.extra.in_love = 600;
|
||||
m.extra.love_player = true;
|
||||
used = true;
|
||||
loved = true;
|
||||
}
|
||||
if m.health < m.attrs.max_health {
|
||||
m.health = (m.health + heal).min(m.attrs.max_health);
|
||||
@@ -57,6 +59,10 @@ impl Game<'_> {
|
||||
if !used {
|
||||
return false;
|
||||
}
|
||||
// Animal.setInLove: entity event 18.
|
||||
if loved {
|
||||
self.mob_event_particles(self.mobs[index].id, 18);
|
||||
}
|
||||
self.llama_sound(index, "entity.llama.eat", 1.0);
|
||||
self.consume_held();
|
||||
true
|
||||
|
||||
@@ -626,46 +626,8 @@ impl Game<'_> {
|
||||
/// `HopperBlockEntity.suckInItems`: from the container above, or item entities.
|
||||
fn hopper_suck(&mut self, pos: Pos, hopper: &View) -> bool {
|
||||
let above = (pos.0, pos.1 + 1, pos.2);
|
||||
let c = self.containers();
|
||||
if let Some(source) = c.view(above, false) {
|
||||
if let Kind::Composter(level) = source.kind {
|
||||
if level != 8 {
|
||||
return false;
|
||||
}
|
||||
// tryTakeInItemFromSlot on the OutputContainer: removeItem calls
|
||||
// its setChanged, which empties the composter, and so does the
|
||||
// second setChanged after the move or, when the hopper has no
|
||||
// room, the setItem putting the bone meal back into the detached
|
||||
// container (whose bone meal is lost with it).
|
||||
let bone_meal = c.bone_meal.clone();
|
||||
let at = BlockPos::new(above.0, above.1, above.2);
|
||||
self.with_level(|b, level, ticks| b.composter_empty(level, ticks, at));
|
||||
let moved = self.add_item(None, hopper, bone_meal, None).is_none();
|
||||
self.with_level(|b, level, ticks| b.composter_empty(level, ticks, at));
|
||||
self.world.modified.insert((above.0 >> 4, above.2 >> 4));
|
||||
return moved;
|
||||
}
|
||||
let source_hopper = (source.kind == Kind::Hopper).then_some(above);
|
||||
for slot in source.slots_for_face(Some(Direction::Down)) {
|
||||
let c = self.containers();
|
||||
let Some(stack) = c.get(&source, slot) else {
|
||||
continue;
|
||||
};
|
||||
if !c.can_take(&source, slot, stack, Direction::Down) {
|
||||
continue;
|
||||
}
|
||||
let Some(one) = self.take_one(&source, slot) else {
|
||||
continue;
|
||||
};
|
||||
match self.add_item(source_hopper, hopper, one, None) {
|
||||
None => {
|
||||
self.view_changed(&source);
|
||||
return true;
|
||||
}
|
||||
Some(rest) => self.put_back(&source, slot, rest),
|
||||
}
|
||||
}
|
||||
return false;
|
||||
if let Some(took) = self.suck_from_container(above, hopper) {
|
||||
return took;
|
||||
}
|
||||
let above_state = self.world.block(above.0, above.1, above.2);
|
||||
let blocked = self.res.facts().get(above_state).full_collision
|
||||
@@ -695,6 +657,56 @@ impl Game<'_> {
|
||||
{
|
||||
return false;
|
||||
}
|
||||
self.suck_item_entities(hopper, min, max)
|
||||
}
|
||||
/// The container half of `HopperBlockEntity.suckInItems`: one item from the
|
||||
/// container at `above`, through its bottom face. `None` when there is no
|
||||
/// container there.
|
||||
fn suck_from_container(&mut self, above: Pos, hopper: &View) -> Option<bool> {
|
||||
let c = self.containers();
|
||||
let source = c.view(above, false)?;
|
||||
if let Kind::Composter(level) = source.kind {
|
||||
if level != 8 {
|
||||
return Some(false);
|
||||
}
|
||||
// tryTakeInItemFromSlot on the OutputContainer: removeItem calls
|
||||
// its setChanged, which empties the composter, and so does the
|
||||
// second setChanged after the move or, when the hopper has no
|
||||
// room, the setItem putting the bone meal back into the detached
|
||||
// container (whose bone meal is lost with it).
|
||||
let bone_meal = c.bone_meal.clone();
|
||||
let at = BlockPos::new(above.0, above.1, above.2);
|
||||
self.with_level(|b, level, ticks| b.composter_empty(level, ticks, at));
|
||||
let moved = self.add_item(None, hopper, bone_meal, None).is_none();
|
||||
self.with_level(|b, level, ticks| b.composter_empty(level, ticks, at));
|
||||
self.world.modified.insert((above.0 >> 4, above.2 >> 4));
|
||||
return Some(moved);
|
||||
}
|
||||
let source_hopper = (source.kind == Kind::Hopper).then_some(above);
|
||||
for slot in source.slots_for_face(Some(Direction::Down)) {
|
||||
let c = self.containers();
|
||||
let Some(stack) = c.get(&source, slot) else {
|
||||
continue;
|
||||
};
|
||||
if !c.can_take(&source, slot, stack, Direction::Down) {
|
||||
continue;
|
||||
}
|
||||
let Some(one) = self.take_one(&source, slot) else {
|
||||
continue;
|
||||
};
|
||||
match self.add_item(source_hopper, hopper, one, None) {
|
||||
None => {
|
||||
self.view_changed(&source);
|
||||
return Some(true);
|
||||
}
|
||||
Some(rest) => self.put_back(&source, slot, rest),
|
||||
}
|
||||
}
|
||||
Some(false)
|
||||
}
|
||||
/// The item half of `HopperBlockEntity.suckInItems` (`getItemsAtAndAbove`):
|
||||
/// adds the item entities that meet the box, until one is taken whole.
|
||||
fn suck_item_entities(&mut self, hopper: &View, min: [f64; 3], max: [f64; 3]) -> bool {
|
||||
let mut i = 0;
|
||||
while i < self.dropped.len() {
|
||||
let b = self.dropped[i].bounds();
|
||||
@@ -719,6 +731,66 @@ impl Game<'_> {
|
||||
}
|
||||
false
|
||||
}
|
||||
/// `MinecartHopper.tick`'s `tryConsumeItems` (`suckInItems`) for an enabled
|
||||
/// hopper minecart: one item from the container above, else the item
|
||||
/// entities over it or touching it, each tick without a cooldown.
|
||||
pub(super) fn hopper_cart_suck(&mut self, cart: &mut super::minecarts::Minecart) {
|
||||
// The cart's slots are edited as a container under the placeholder key
|
||||
// its menu uses; when that menu is open the placeholder is the live copy.
|
||||
let key = (i32::MAX - 15, super::minecarts::CART_KEY_Y, cart.id as i32);
|
||||
let open = self.world.block_entities.contains_key(&key);
|
||||
if !open {
|
||||
let items = BlockEntity::Chest(std::mem::take(&mut cart.items));
|
||||
self.world.block_entities.insert(key, items);
|
||||
}
|
||||
let size = self
|
||||
.world
|
||||
.block_entities
|
||||
.get(&key)
|
||||
.map_or(0, |e| e.slots().len());
|
||||
let view = View {
|
||||
parts: vec![(key, size)],
|
||||
kind: Kind::Generic,
|
||||
};
|
||||
let p = cart.position;
|
||||
// getLevelY is the cart's y + 0.5, so the container is the block at
|
||||
// y + 1.5, and Hopper.SUCK_AABB (moved by getLevel - 0.5) starts 11/16
|
||||
// above the cart.
|
||||
let above = (
|
||||
p.x.floor() as i32,
|
||||
(p.y + 1.5).floor() as i32,
|
||||
p.z.floor() as i32,
|
||||
);
|
||||
let took = match self.suck_from_container(above, &view) {
|
||||
Some(took) => took,
|
||||
None => self.suck_item_entities(
|
||||
&view,
|
||||
[p.x - 0.5, p.y + 11.0 / 16.0, p.z - 0.5],
|
||||
[p.x + 0.5, p.y + 2.0, p.z + 0.5],
|
||||
),
|
||||
};
|
||||
if !took {
|
||||
// The cart's own box, inflated by 0.25 sideways.
|
||||
let b = cart.bounds();
|
||||
let (lo, hi) = (b.min_position(), b.max_position());
|
||||
self.suck_item_entities(
|
||||
&view,
|
||||
[lo.x - 0.25, lo.y, lo.z - 0.25],
|
||||
[hi.x + 0.25, hi.y, hi.z + 0.25],
|
||||
);
|
||||
}
|
||||
// The cart's own items stay the one source of truth: a menu copy that
|
||||
// is still around (open, or left by a guest's close) gets the pulled
|
||||
// items back into `cart.items`, so reopening never restores a stale copy.
|
||||
let slots = if open {
|
||||
self.world.block_entities.get(&key).cloned()
|
||||
} else {
|
||||
self.world.block_entities.remove(&key)
|
||||
};
|
||||
if let Some(BlockEntity::Chest(items)) = slots {
|
||||
cart.items = items;
|
||||
}
|
||||
}
|
||||
|
||||
// ---- dispensers and droppers ----
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ use horizon_client::{
|
||||
blocks::Fluid,
|
||||
collisions::SceneCollisions,
|
||||
containers::BlockEntity,
|
||||
items::ItemStack,
|
||||
items::{ItemStack, Items},
|
||||
mesher::Vertex,
|
||||
mobs::{Part, anim::Poses},
|
||||
particles::{ParticleOptions, ParticleType},
|
||||
@@ -198,6 +198,17 @@ impl Minecart {
|
||||
fn horizontal(&self) -> f64 {
|
||||
self.velocity.x.hypot(self.velocity.z)
|
||||
}
|
||||
/// `AbstractContainerMenu.getRedstoneSignalFromContainer` of `slots`.
|
||||
fn container_signal(slots: &[Option<ItemStack>], items: &Items) -> i32 {
|
||||
let mut total = 0.0f32;
|
||||
for s in slots.iter().flatten() {
|
||||
let max = items.get(&s.item).map_or(64, |i| i.max_stack).min(64);
|
||||
total += s.count as f32 / max as f32;
|
||||
}
|
||||
total /= slots.len().max(1) as f32;
|
||||
// Mth.lerpDiscrete(total, 0, 15)
|
||||
(total * 14.0).floor() as i32 + i32::from(total > 0.0)
|
||||
}
|
||||
}
|
||||
pub(super) struct CartModels {
|
||||
pub models: HashMap<CartKind, Part>,
|
||||
@@ -543,7 +554,6 @@ impl Game<'_> {
|
||||
// applyGravity
|
||||
c.velocity.y -= if self.cart_in_water(c) { 0.005 } else { 0.04 };
|
||||
let pos = self.rail_block(c.position);
|
||||
let fall_speed = c.velocity;
|
||||
if let Some(rail) = self.rail(pos[0], pos[1], pos[2]) {
|
||||
self.move_along_track(c, pos, &rail, intent);
|
||||
if &*rail.name == "minecraft:activator_rail" {
|
||||
@@ -585,22 +595,26 @@ impl Game<'_> {
|
||||
}
|
||||
}
|
||||
CartKind::Tnt => {
|
||||
let speed = fall_speed.x * fall_speed.x + fall_speed.z * fall_speed.z;
|
||||
// MinecartTNT.tick: the fuse and the collision check are separate.
|
||||
if c.fuse > 0 {
|
||||
c.fuse -= 1;
|
||||
let at = [c.position.x, c.position.y + 0.5, c.position.z];
|
||||
self.particles
|
||||
.add(&ParticleOptions::simple(ParticleType::Smoke), at, [0.0; 3]);
|
||||
} else if c.fuse == 0 || (c.horizontal_collision && speed >= 0.01) {
|
||||
} else if c.fuse == 0 {
|
||||
// explode(horizontalDistanceSqr()): a rising cart's
|
||||
// vertical speed adds nothing.
|
||||
let speed = c.velocity.x * c.velocity.x + c.velocity.z * c.velocity.z;
|
||||
let speed = if c.fuse == 0 && c.velocity.y > 0.0 {
|
||||
c.velocity.y * c.velocity.y
|
||||
} else {
|
||||
speed
|
||||
};
|
||||
self.explode_cart(c, speed);
|
||||
return false;
|
||||
}
|
||||
if c.horizontal_collision {
|
||||
let speed = c.velocity.x * c.velocity.x + c.velocity.z * c.velocity.z;
|
||||
if speed >= f64::from(0.01_f32) {
|
||||
self.explode_cart(c, speed);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
@@ -644,51 +658,9 @@ impl Game<'_> {
|
||||
// The cart is the explosion's source: it is gone before the blast
|
||||
// looks for entities, so it can't hit itself.
|
||||
self.carts.retain(|x| x.id != c.id);
|
||||
let _ = self.server_explode(at, power, BlockInteraction::Destroy, false);
|
||||
}
|
||||
/// `MinecartHopper.suckInItems`: items above, into the five slots.
|
||||
fn hopper_cart_pickup(&mut self, c: &mut Minecart) {
|
||||
if !c.enabled {
|
||||
return;
|
||||
}
|
||||
let p = c.position;
|
||||
let zone = Aabb::new(
|
||||
Vec3::new(p.x - 0.5, p.y - 0.5 + 0.0, p.z - 0.5),
|
||||
Vec3::new(p.x + 0.5, p.y + 1.5, p.z + 0.5),
|
||||
);
|
||||
let mut i = 0;
|
||||
while i < self.dropped.len() {
|
||||
let e = &self.dropped[i];
|
||||
if e.pickup_delay > 0 || !zone.contains(e.position) {
|
||||
i += 1;
|
||||
continue;
|
||||
}
|
||||
let mut stack = e.stack.clone();
|
||||
for slot in c.items.iter_mut() {
|
||||
match slot {
|
||||
None => {
|
||||
*slot = Some(stack.clone());
|
||||
stack.count = 0;
|
||||
}
|
||||
Some(s) if s.same_item_same_components(&stack) => {
|
||||
let max = self.res.items().get(&s.item).map_or(64, |i| i.max_stack);
|
||||
let moved = stack.count.min(max.saturating_sub(s.count));
|
||||
s.count += moved;
|
||||
stack.count -= moved;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
if stack.count == 0 {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if stack.count == 0 {
|
||||
self.dropped.remove(i);
|
||||
} else {
|
||||
self.dropped[i].stack = stack;
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
let _ = self.with_hive_emptying_blast(|g| {
|
||||
g.server_explode(at, power, BlockInteraction::Destroy, false)
|
||||
});
|
||||
}
|
||||
/// `AbstractMinecart.push` from each player walking into a cart
|
||||
/// (`LivingEntity.pushEntities`): the window's player and every server
|
||||
@@ -827,8 +799,8 @@ impl Game<'_> {
|
||||
}
|
||||
let mut c = self.carts[i].clone();
|
||||
let alive = self.tick_cart(&mut c, [0.0; 2]);
|
||||
if c.kind == CartKind::Hopper {
|
||||
self.hopper_cart_pickup(&mut c);
|
||||
if c.kind == CartKind::Hopper && c.enabled {
|
||||
self.hopper_cart_suck(&mut c);
|
||||
}
|
||||
let Some(i) = self.carts.iter().position(|c| c.id == id) else {
|
||||
continue;
|
||||
@@ -946,7 +918,7 @@ impl Game<'_> {
|
||||
}
|
||||
true
|
||||
}
|
||||
/// `getDismountLocationForPassenger`: beside the cart (across its motion), else on top.
|
||||
/// `getDismountLocationForPassenger`: beside the cart (across its facing), else on top.
|
||||
pub(super) fn dismount_cart(&mut self, i: usize) {
|
||||
self.riding = None;
|
||||
let c = &self.carts[i];
|
||||
@@ -956,17 +928,25 @@ impl Game<'_> {
|
||||
c.position.z.floor() as i32,
|
||||
);
|
||||
let mut target = None;
|
||||
// DismountHelper.offsetsForDirection of the cart's facing
|
||||
// (Direction.fromYRot of its yaw): right, left, back right, back left,
|
||||
// forward right, forward left, back, forward.
|
||||
let step = |q: i32| [(0, 1), (-1, 0), (0, -1), (1, 0)][(q & 3) as usize];
|
||||
let facing = (f64::from(c.yaw) / 90.0 + 0.5).floor() as i32;
|
||||
let (fx, fz) = step(facing);
|
||||
let (rx, rz) = (-fz, fx);
|
||||
let offsets = [
|
||||
(rx, rz),
|
||||
(-rx, -rz),
|
||||
(rx - fx, rz - fz),
|
||||
(-rx - fx, -rz - fz),
|
||||
(fx + rx, fz + rz),
|
||||
(fx - rx, fz - rz),
|
||||
(-fx, -fz),
|
||||
(fx, fz),
|
||||
];
|
||||
'search: for dy in [0, 1, -1] {
|
||||
for (dx, dz) in [
|
||||
(1, 0),
|
||||
(-1, 0),
|
||||
(0, 1),
|
||||
(0, -1),
|
||||
(1, 1),
|
||||
(-1, -1),
|
||||
(1, -1),
|
||||
(-1, 1),
|
||||
] {
|
||||
for (dx, dz) in offsets {
|
||||
let (x, y, z) = (bx + dx, by + dy, bz + dz);
|
||||
let below = self.res.facts().get(self.world.block(x, y - 1, z));
|
||||
let here = self.res.facts().get(self.world.block(x, y, z));
|
||||
@@ -1050,6 +1030,22 @@ impl Game<'_> {
|
||||
}
|
||||
best
|
||||
}
|
||||
/// Each cart's kind and comparator signal, for the detector rail
|
||||
/// (`DetectorRailBlock.getAnalogOutputSignal`). A cart whose menu is open
|
||||
/// counts the items in that menu.
|
||||
pub(super) fn cart_signals(&self) -> Vec<(CartKind, i32)> {
|
||||
self.carts
|
||||
.iter()
|
||||
.map(|c| {
|
||||
let key = (i32::MAX - 15, CART_KEY_Y, c.id as i32);
|
||||
let slots = match self.world.block_entities.get(&key) {
|
||||
Some(BlockEntity::Chest(open)) => open,
|
||||
_ => &c.items,
|
||||
};
|
||||
(c.kind, Minecart::container_signal(slots, self.res.items()))
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
/// `interact`: ride, open, fuel or ignite the cart under the crosshair.
|
||||
pub(super) fn interact_cart(&mut self) -> bool {
|
||||
let Some((i, d)) = self.cart_hit() else {
|
||||
@@ -1067,10 +1063,8 @@ impl Game<'_> {
|
||||
}
|
||||
self.riding = Some(self.carts[i].id);
|
||||
}
|
||||
// AbstractMinecartContainer.interact: no sneak check.
|
||||
CartKind::Chest | CartKind::Hopper => {
|
||||
if sneaking {
|
||||
return false;
|
||||
}
|
||||
let c = self.carts[i].clone();
|
||||
let key = (i32::MAX - 15, CART_KEY_Y, c.id as i32);
|
||||
self.world
|
||||
|
||||
@@ -215,10 +215,12 @@ impl Game<'_> {
|
||||
return false;
|
||||
}
|
||||
let mut used = false;
|
||||
let mut loved = false;
|
||||
if love && m.extra.tame && m.extra.age == 0 && m.extra.in_love <= 0 {
|
||||
m.extra.in_love = 600;
|
||||
m.extra.love_player = true;
|
||||
used = true;
|
||||
loved = true;
|
||||
}
|
||||
if m.health < m.attrs.max_health && heal > 0.0 {
|
||||
m.health = (m.health + heal).min(m.attrs.max_health);
|
||||
@@ -238,6 +240,7 @@ impl Game<'_> {
|
||||
// eating(): the mouth opens and the horse eats.
|
||||
m.anim.v[2] = 1.0;
|
||||
let at = m.center();
|
||||
let id = m.id;
|
||||
let sound = match m.species() {
|
||||
Species::Camel => "minecraft:entity.camel.eat",
|
||||
Species::CamelHusk => "minecraft:entity.camel_husk.eat",
|
||||
@@ -247,6 +250,10 @@ impl Game<'_> {
|
||||
};
|
||||
let pitch = (self.world.random.next_float() - self.world.random.next_float()) * 0.2 + 1.0;
|
||||
self.audio.play(sound, Some(at), 1.0, pitch);
|
||||
// Animal.setInLove: entity event 18.
|
||||
if loved {
|
||||
self.mob_event_particles(id, 18);
|
||||
}
|
||||
self.consume_held();
|
||||
true
|
||||
}
|
||||
@@ -452,14 +459,16 @@ impl Game<'_> {
|
||||
m.extra.owner = owner;
|
||||
m.persistent = true;
|
||||
// AbstractHorse.tameWithName: entity event 7, spawnTamingParticles(true).
|
||||
self.particles_around_mob(
|
||||
mob,
|
||||
"heart",
|
||||
horizon_client::particles::Burst::TAMING,
|
||||
);
|
||||
self.mob_event_particles(mob, 7);
|
||||
}
|
||||
}
|
||||
MobEvent::Buck { mob } if self.riding == Some(mob) => self.dismount_mount(),
|
||||
MobEvent::Buck { mob } => {
|
||||
if self.riding == Some(mob) {
|
||||
self.dismount_mount();
|
||||
}
|
||||
// RunAroundLikeCrazyGoal.tick: entity event 6, smoke.
|
||||
self.mob_event_particles(mob, 6);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,13 +85,8 @@ impl Game<'_> {
|
||||
m.ai.target = None;
|
||||
}
|
||||
let sound = nautilus::eat_sound(m);
|
||||
let kind = if tamed { "heart" } else { "smoke" };
|
||||
// TamableAnimal.spawnTamingParticles (entity event 7 or 6).
|
||||
self.particles_around_mob(
|
||||
self.mobs[index].id,
|
||||
kind,
|
||||
horizon_client::particles::Burst::TAMING,
|
||||
);
|
||||
self.mob_event_particles(self.mobs[index].id, if tamed { 7 } else { 6 });
|
||||
self.nautilus_sound(index, sound);
|
||||
if tamed {
|
||||
let view = self.mob_entity(&self.mobs[index]);
|
||||
@@ -145,6 +140,8 @@ impl Game<'_> {
|
||||
let sound = nautilus::eat_sound(m);
|
||||
self.use_nautilus_food(item);
|
||||
self.nautilus_sound(index, sound);
|
||||
// Animal.setInLove: entity event 18.
|
||||
self.mob_event_particles(self.mobs[index].id, 18);
|
||||
return true;
|
||||
}
|
||||
false
|
||||
|
||||
@@ -218,11 +218,20 @@ impl Game<'_> {
|
||||
_ => None,
|
||||
})
|
||||
});
|
||||
// A living mount at the default scale and camera distance.
|
||||
// Camera.setup: the living mount's scale and camera distance
|
||||
// attributes (the happy ghast's is 8, the default 4).
|
||||
let mount = self
|
||||
.riding
|
||||
.and_then(|id| self.mobs.iter().find(|m| m.id == id))
|
||||
.map(|_| (1.0, 4.0));
|
||||
.map(|m| {
|
||||
let attribute = |name: &str, default: f64| {
|
||||
m.kind.attributes.get(name).copied().unwrap_or(default)
|
||||
};
|
||||
(
|
||||
attribute("minecraft:scale", 1.0) as f32,
|
||||
attribute("minecraft:camera_distance", 4.0),
|
||||
)
|
||||
});
|
||||
// AbstractBoat.positionRider turns a passenger by the boat's
|
||||
// deltaRotation after its yRotO was saved, and LocalPlayer.getViewYRot
|
||||
// interpolates a passenger's yaw: the boat's turn is spread over the
|
||||
|
||||
@@ -2,7 +2,12 @@
|
||||
//! `Consumable`), throwing splash/lingering potions (`ThrownSplashPotion`),
|
||||
//! filling glass bottles (`BottleItem`), the per-tick effect application,
|
||||
//! effect attribute modifiers and the HUD effect icons (`Hud.extractEffects`).
|
||||
use super::{Game, Screen, item_draw::owner_at};
|
||||
use super::{
|
||||
Game, Screen,
|
||||
dragon::{Breath, FightPlayer, FightWho},
|
||||
item_draw::owner_at,
|
||||
remote_projectiles::cloud_client_tick,
|
||||
};
|
||||
use horizon_assets::item_model::DisplayContext;
|
||||
use horizon_client::{
|
||||
block_entity_render::vertex_light,
|
||||
@@ -12,9 +17,13 @@ use horizon_client::{
|
||||
hud_layout, hud_overlays, inventory_effects,
|
||||
items::ItemStack,
|
||||
mesher::Vertex,
|
||||
particles::{ParticleOptions, ParticleType},
|
||||
text::Text,
|
||||
};
|
||||
use horizon_core::{geometry::Vec3, random::RandomSource};
|
||||
use horizon_core::{
|
||||
geometry::{Aabb, Direction, Vec3},
|
||||
random::{LegacyRandom, RandomSource},
|
||||
};
|
||||
|
||||
/// A thrown splash or lingering potion in flight.
|
||||
#[derive(Clone, Debug)]
|
||||
@@ -31,6 +40,35 @@ pub(super) struct ThrownPotion {
|
||||
/// for a dispenser's).
|
||||
owner: Option<Text>,
|
||||
}
|
||||
/// `AreaEffectCloud` wait time set by `ThrownLingeringPotion.onHitAsPotion`.
|
||||
pub(super) const LINGERING_WAIT: i32 = 10;
|
||||
/// `AreaEffectCloud.DEFAULT_REAPPLICATION_DELAY`.
|
||||
const REAPPLICATION_DELAY: i32 = 20;
|
||||
/// An entity a cloud has affected (`AreaEffectCloud.victims`).
|
||||
#[derive(Clone, Copy, PartialEq)]
|
||||
enum Victim {
|
||||
Mob(u32),
|
||||
Player(FightWho),
|
||||
}
|
||||
/// What a lingering potion's `AreaEffectCloud` applies: the potion's effects
|
||||
/// (at the lingering item's 0.25 duration scale) and who it has affected.
|
||||
pub(super) struct PotionCloud {
|
||||
effects: &'static [(&'static str, i32, i32)],
|
||||
/// The potion's colour (`PotionContents.getColor`).
|
||||
color: u32,
|
||||
/// Each victim and the tick it can be affected again.
|
||||
victims: Vec<(Victim, i32)>,
|
||||
/// Who its instant damage names (`indirectMagic(cloud, owner)`): the
|
||||
/// thrower, else the cloud.
|
||||
source: Text,
|
||||
}
|
||||
impl PotionCloud {
|
||||
/// `AreaEffectCloud.updateParticle`: an entity effect in the potion's colour.
|
||||
pub(super) fn particle(&self) -> ParticleOptions {
|
||||
let c = |shift: u32| (self.color >> shift & 255) as f32 / 255.0;
|
||||
ParticleOptions::colored(ParticleType::EntityEffect, [c(16), c(8), c(0), 1.0])
|
||||
}
|
||||
}
|
||||
/// A mob's effect ids carry the `minecraft:` namespace.
|
||||
fn mob_effect_id(id: &str) -> Option<&'static str> {
|
||||
use std::{collections::HashMap, sync::OnceLock};
|
||||
@@ -48,7 +86,203 @@ fn mob_effect_id(id: &str) -> Option<&'static str> {
|
||||
.get(id)
|
||||
.copied()
|
||||
}
|
||||
/// `LivingEntity.canBeAffected` with the mob overrides (`WitherBoss` and
|
||||
/// `WitherSkeleton` shrug off wither, `Spider` and `AbstractNautilus` poison,
|
||||
/// `Parched` weakness): the immune-to-infested and immune-to-oozing tags
|
||||
/// decide first, then the tag of mobs that ignore poison and regeneration.
|
||||
fn mob_can_be_affected(
|
||||
tags: &std::collections::HashMap<String, std::collections::HashSet<String>>,
|
||||
kind: &str,
|
||||
effect: &str,
|
||||
) -> bool {
|
||||
let effect = effect.trim_start_matches("minecraft:");
|
||||
let kind = kind.trim_start_matches("minecraft:");
|
||||
let overridden = match kind {
|
||||
"wither" | "wither_skeleton" => effect == "wither",
|
||||
"spider" | "cave_spider" | "nautilus" | "zombie_nautilus" => effect == "poison",
|
||||
"parched" => effect == "weakness",
|
||||
_ => false,
|
||||
};
|
||||
if overridden {
|
||||
return false;
|
||||
}
|
||||
let in_tag = |tag: &str| {
|
||||
tags.get(tag)
|
||||
.is_some_and(|t| t.contains(&format!("minecraft:{kind}")))
|
||||
};
|
||||
if in_tag("minecraft:immune_to_infested") {
|
||||
effect != "infested"
|
||||
} else if in_tag("minecraft:immune_to_oozing") {
|
||||
effect != "oozing"
|
||||
} else {
|
||||
!in_tag("minecraft:ignores_poison_and_regen")
|
||||
|| (effect != "regeneration" && effect != "poison")
|
||||
}
|
||||
}
|
||||
/// `ThrownSplashPotion.onHitAsPotion`: the squared distance from the potion's
|
||||
/// box at the hit point to an entity's box grown by the hit margin
|
||||
/// (`ProjectileUtil.computeMargin`), for entities that meet the potion's box
|
||||
/// grown by (4, 2, 4); none when it is 16 or more.
|
||||
fn splash_distance_sqr(at: Vec3, age: u32, bounds: Aabb) -> Option<f64> {
|
||||
let potion = Aabb::new(
|
||||
Vec3::new(at.x - 0.125, at.y, at.z - 0.125),
|
||||
Vec3::new(at.x + 0.125, at.y + 0.25, at.z + 0.125),
|
||||
);
|
||||
if !potion.inflate(Vec3::new(4.0, 2.0, 4.0)).intersects(bounds) {
|
||||
return None;
|
||||
}
|
||||
let margin = ((f64::from(age) - 2.0) / 20.0).clamp(0.0, 0.3);
|
||||
let d2 = potion.distance_squared_to_box(bounds.inflate(Vec3::new(margin, margin, margin)));
|
||||
(d2 < 16.0).then_some(d2)
|
||||
}
|
||||
impl Game<'_> {
|
||||
/// `LivingEntity.triggerOnDeathMobEffects` (`onMobRemoved` with the reason
|
||||
/// KILLED) for what Oozing, Weaving and Wind Charged do when their bearer
|
||||
/// dies. `bearer` is the dying mob's id, `player` whether it is a player,
|
||||
/// `random` the dying mob's own (`mob.getRandom()`; the world's for the
|
||||
/// player).
|
||||
pub(super) fn effects_on_death(
|
||||
&mut self,
|
||||
effects: &[&str],
|
||||
bounds: Aabb,
|
||||
player: bool,
|
||||
bearer: Option<u32>,
|
||||
mut random: Option<&mut LegacyRandom>,
|
||||
) {
|
||||
let feet = bounds.bottom_center();
|
||||
if effects.contains(&"oozing") {
|
||||
// OozingMobEffect.numberOfSlimesToSpawn: two, fewer when the
|
||||
// slimes close by already fill the cramming limit.
|
||||
let limit = self.ui.rules.int("max_entity_cramming");
|
||||
let mut count = 2;
|
||||
if limit >= 1 {
|
||||
let near = bounds.inflate(Vec3::new(2.0, 2.0, 2.0));
|
||||
let nearby = self
|
||||
.mobs
|
||||
.iter()
|
||||
.filter(|m| {
|
||||
m.species() == horizon_client::mobs::Species::Slime
|
||||
&& Some(m.id) != bearer
|
||||
&& m.bounds().intersects(near)
|
||||
})
|
||||
.count()
|
||||
.min(limit as usize) as i32;
|
||||
count = (limit - nearby).clamp(0, count);
|
||||
}
|
||||
for _ in 0..count {
|
||||
// spawnSlimeOffspring: a size 2 slime half a block up.
|
||||
if let Some(id) = self.spawn_mob_for(
|
||||
"minecraft:slime",
|
||||
[feet.x, feet.y + 0.5, feet.z],
|
||||
false,
|
||||
true,
|
||||
) && let Some(m) = self.mobs.iter_mut().find(|m| m.id == id)
|
||||
{
|
||||
horizon_client::mobs::cube::set_size(m, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
if effects.contains(&"weaving") && (player || self.ui.rules.bool("mob_griefing")) {
|
||||
self.spawn_cobwebs_around(
|
||||
[
|
||||
feet.x.floor() as i32,
|
||||
feet.y.floor() as i32,
|
||||
feet.z.floor() as i32,
|
||||
],
|
||||
random.as_deref_mut(),
|
||||
);
|
||||
}
|
||||
if effects.contains(&"wind_charged") {
|
||||
// A burst centred at half the height, radius 3 to 5.
|
||||
let center = [feet.x, feet.y + bounds.size().y / 2.0, feet.z];
|
||||
let r = random.unwrap_or(&mut self.world.random);
|
||||
let radius = 3.0 + r.next_float() * 2.0;
|
||||
let _ = self.wind_burst(center, radius, 1.0, false, false);
|
||||
}
|
||||
}
|
||||
/// `WeavingMobEffect.spawnCobwebsRandomlyAround`: two or three cobwebs in
|
||||
/// free spaces with a solid floor, picked among 15 random blocks within one
|
||||
/// block of `pos`.
|
||||
fn spawn_cobwebs_around(&mut self, pos: [i32; 3], mut random: Option<&mut LegacyRandom>) {
|
||||
let r = random.as_deref_mut().unwrap_or(&mut self.world.random);
|
||||
let wanted = 2 + r.next_int_bound(2).unwrap_or(0) as usize;
|
||||
let mut chosen: Vec<[i32; 3]> = Vec::new();
|
||||
for _ in 0..15 {
|
||||
let r = random.as_deref_mut().unwrap_or(&mut self.world.random);
|
||||
let at = [
|
||||
pos[0] - 1 + r.next_int_bound(3).unwrap_or(0),
|
||||
pos[1] - 1 + r.next_int_bound(3).unwrap_or(0),
|
||||
pos[2] - 1 + r.next_int_bound(3).unwrap_or(0),
|
||||
];
|
||||
let facts = self.res.facts();
|
||||
let here = facts.get(self.world.block(at[0], at[1], at[2]));
|
||||
let below = facts.get(self.world.block(at[0], at[1] - 1, at[2]));
|
||||
if !chosen.contains(&at)
|
||||
&& here.replaceable
|
||||
&& below.sturdy_full & (1 << Direction::Up as u8) != 0
|
||||
{
|
||||
chosen.push(at);
|
||||
if chosen.len() >= wanted {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
for at in chosen {
|
||||
if self.set_state_named(at, "minecraft:cobweb", &[]).is_ok() {
|
||||
self.level_event_at(3018, at, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
/// `InfestedMobEffect.onMobHurt` for the player: from half its height up,
|
||||
/// along where it looks.
|
||||
pub(super) fn player_infested(&mut self) {
|
||||
if let Some(p) = self.player.as_ref() {
|
||||
let at = [
|
||||
p.position.x,
|
||||
p.position.y + f64::from(p.dimensions.height) / 2.0,
|
||||
p.position.z,
|
||||
];
|
||||
let look = super::view_vector(self.yaw, self.pitch);
|
||||
self.infested_hurt(at, look, None);
|
||||
}
|
||||
}
|
||||
/// A living mob's own random (`Entity.random`), else the world's.
|
||||
fn bearer_random(&mut self, bearer: Option<u32>) -> &mut LegacyRandom {
|
||||
match bearer.and_then(|id| self.mobs.iter().position(|m| m.id == id)) {
|
||||
Some(i) => &mut self.mobs[i].random,
|
||||
None => &mut self.world.random,
|
||||
}
|
||||
}
|
||||
/// `InfestedMobEffect.onMobHurt`: a 10% chance of one or two silverfish at
|
||||
/// `at` (half the bearer's height up), thrown along its look direction.
|
||||
/// The draws are the bearer's (`mob.getRandom()`): `bearer` is the mob,
|
||||
/// none for the player (the world's random).
|
||||
pub(super) fn infested_hurt(&mut self, at: [f64; 3], look: [f64; 3], bearer: Option<u32>) {
|
||||
if self.bearer_random(bearer).next_float() > 0.1 {
|
||||
return;
|
||||
}
|
||||
let count = 1 + self.bearer_random(bearer).next_int_bound(2).unwrap_or(0);
|
||||
for _ in 0..count {
|
||||
// Mth.randomBetween(-PI / 2, PI / 2), then the look direction
|
||||
// scaled by (0.3, 0.45, 0.3) and turned about the y axis.
|
||||
let half = std::f32::consts::FRAC_PI_2;
|
||||
let angle = self.bearer_random(bearer).next_float() * (2.0 * half) - half;
|
||||
let (sin, cos) = angle.sin_cos();
|
||||
let (x, z) = (look[0] * 0.3, look[2] * 0.3);
|
||||
let velocity = Vec3::new(
|
||||
f64::from(x as f32 * cos + z as f32 * sin),
|
||||
look[1] * 0.3 * 1.5,
|
||||
f64::from(-x as f32 * sin + z as f32 * cos),
|
||||
);
|
||||
if let Some(id) = self.spawn_mob_for("minecraft:silverfish", at, false, true)
|
||||
&& let Some(m) = self.mobs.iter_mut().find(|m| m.id == id)
|
||||
{
|
||||
m.velocity = velocity;
|
||||
}
|
||||
self.audio
|
||||
.play("minecraft:entity.silverfish.hurt", Some(at), 1.0, 1.0);
|
||||
}
|
||||
}
|
||||
/// A splash potion, lingering potion or experience bottle in flight (the
|
||||
/// player's throws and dispensers both end up here).
|
||||
pub(super) fn launch_thrown(
|
||||
@@ -390,6 +624,7 @@ impl Game<'_> {
|
||||
self.tick_mob_effects();
|
||||
if running {
|
||||
self.tick_thrown_potions();
|
||||
self.tick_potion_clouds();
|
||||
}
|
||||
}
|
||||
/// `LivingEntity.tickEffects` (server side) for `self.player`, the local
|
||||
@@ -400,13 +635,37 @@ impl Game<'_> {
|
||||
return;
|
||||
};
|
||||
if player.health.dead_or_dying() {
|
||||
// LivingEntity.die → removeAllEffects.
|
||||
// LivingEntity.die → removeAllEffects. Vanilla runs the effects
|
||||
// that act on death (`onMobRemoved`) when the dead player is
|
||||
// removed, up to 20 ticks later; here it is as the effects go.
|
||||
let w = f64::from(player.dimensions.width) / 2.0;
|
||||
let bounds = Aabb::new(
|
||||
Vec3::new(
|
||||
player.position.x - w,
|
||||
player.position.y,
|
||||
player.position.z - w,
|
||||
),
|
||||
Vec3::new(
|
||||
player.position.x + w,
|
||||
player.position.y + f64::from(player.dimensions.height),
|
||||
player.position.z + w,
|
||||
),
|
||||
);
|
||||
let ids: Vec<&'static str> = self.potions.effects.list.iter().map(|e| e.id).collect();
|
||||
self.potions.effects.clear();
|
||||
if !ids.is_empty() {
|
||||
self.effects_on_death(&ids, bounds, true, None, None);
|
||||
}
|
||||
}
|
||||
// The omens act from inside the effect tick (BadOmenMobEffect,
|
||||
// RaidOmenMobEffect).
|
||||
let absorption_empty = self
|
||||
.player
|
||||
.as_ref()
|
||||
.is_some_and(|p| p.health.absorption() <= 0.0);
|
||||
let mut effects = std::mem::take(&mut self.potions.effects);
|
||||
let (actions, raid_omen_added) = effects.tick_with(&mut |e| self.omen_tick(e));
|
||||
let (actions, raid_omen_added) =
|
||||
effects.tick_with(&mut |e| self.omen_tick(e), absorption_empty);
|
||||
self.potions.effects = effects;
|
||||
if raid_omen_added {
|
||||
self.raid_omen_added();
|
||||
@@ -547,29 +806,176 @@ impl Game<'_> {
|
||||
let state =
|
||||
self.world
|
||||
.block(p.x.floor() as i32, p.y.floor() as i32, p.z.floor() as i32);
|
||||
if self.res.facts().get(state).full_collision
|
||||
|| self.mobs.iter().any(|m| {
|
||||
m.alive()
|
||||
&& (m.position.x - p.x).abs() < m.kind.width / 2.0 + 0.125
|
||||
&& (m.position.z - p.z).abs() < m.kind.width / 2.0 + 0.125
|
||||
&& p.y >= m.position.y
|
||||
&& p.y <= m.position.y + m.kind.height
|
||||
})
|
||||
{
|
||||
hit = Some(p);
|
||||
let mob = self.mobs.iter().find(|m| {
|
||||
m.alive()
|
||||
&& (m.position.x - p.x).abs() < m.kind.width / 2.0 + 0.125
|
||||
&& (m.position.z - p.z).abs() < m.kind.width / 2.0 + 0.125
|
||||
&& p.y >= m.position.y
|
||||
&& p.y <= m.position.y + m.kind.height
|
||||
});
|
||||
if self.res.facts().get(state).full_collision || mob.is_some() {
|
||||
hit = Some((p, mob.map(|m| m.position)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
if let Some(p) = hit {
|
||||
landed.push((t.stack.clone(), p, t.owner.clone()));
|
||||
if let Some((p, mob)) = hit {
|
||||
landed.push((t.stack.clone(), p, mob, t.age, t.owner.clone()));
|
||||
return false;
|
||||
}
|
||||
t.position = next;
|
||||
t.age < 1200 && t.position.y > -128.0
|
||||
});
|
||||
self.potions.thrown = thrown;
|
||||
for (stack, at, owner) in landed {
|
||||
self.splash(&stack, at, owner);
|
||||
for (stack, at, mob, age, owner) in landed {
|
||||
self.splash(&stack, at, mob, age, owner);
|
||||
}
|
||||
}
|
||||
/// `AreaEffectCloud.tick` for the lingering potions' clouds: the client
|
||||
/// tick's particles, then the server tick.
|
||||
fn tick_potion_clouds(&mut self) {
|
||||
if self.breath_clouds.iter().all(|c| c.potion.is_none()) {
|
||||
return;
|
||||
}
|
||||
let players: Vec<FightPlayer> = self
|
||||
.fight_players()
|
||||
.into_iter()
|
||||
.filter(|p| p.alive)
|
||||
.collect();
|
||||
let mut clouds = std::mem::take(&mut self.breath_clouds);
|
||||
clouds.retain_mut(|c| c.potion.is_none() || self.tick_potion_cloud(c, &players));
|
||||
self.breath_clouds.append(&mut clouds);
|
||||
}
|
||||
/// `AreaEffectCloud.serverTick` for a lingering potion's cloud: after its
|
||||
/// wait it shrinks, and every 5 ticks it affects the living entities in
|
||||
/// its box and radius that were not affected in the last 20 ticks, each
|
||||
/// taking some of its radius. False once it is gone.
|
||||
fn tick_potion_cloud(&mut self, c: &mut Breath, players: &[FightPlayer]) -> bool {
|
||||
c.age += 1;
|
||||
let Some(potion) = c.potion.as_mut() else {
|
||||
return true;
|
||||
};
|
||||
if c.age - LINGERING_WAIT >= c.duration {
|
||||
return false;
|
||||
}
|
||||
let waiting = c.age < LINGERING_WAIT;
|
||||
cloud_client_tick(
|
||||
&mut self.particles,
|
||||
c.at,
|
||||
c.radius,
|
||||
waiting,
|
||||
&potion.particle(),
|
||||
);
|
||||
if waiting {
|
||||
return true;
|
||||
}
|
||||
// setRadiusPerTick(-radius / duration).
|
||||
c.radius += -3.0 / 600.0;
|
||||
if c.radius < 0.5 {
|
||||
return false;
|
||||
}
|
||||
if c.age % 5 != 0 {
|
||||
return true;
|
||||
}
|
||||
potion.victims.retain(|(_, until)| c.age < *until);
|
||||
let r = f64::from(c.radius);
|
||||
let area = Aabb::new(
|
||||
Vec3::new(c.at[0] - r, c.at[1], c.at[2] - r),
|
||||
Vec3::new(c.at[0] + r, c.at[1] + 0.5, c.at[2] + r),
|
||||
);
|
||||
let mut inside = Vec::new();
|
||||
for p in players.iter().filter(|p| p.bounds.intersects(area)) {
|
||||
inside.push((Victim::Player(p.who), p.position.x, p.position.z));
|
||||
}
|
||||
let effects = potion.effects;
|
||||
let tags = &self.res.stations().enchantments.entity_tags;
|
||||
// Only mobs that at least one of the cloud's effects can affect are
|
||||
// taken (`allEffects.stream().anyMatch(entity::canBeAffected)`), so
|
||||
// the others neither become victims nor use up its radius.
|
||||
for m in self.mobs.iter().filter(|m| {
|
||||
m.alive()
|
||||
&& m.bounds().intersects(area)
|
||||
&& effects
|
||||
.iter()
|
||||
.any(|(id, ..)| mob_can_be_affected(tags, &m.kind.id, id))
|
||||
}) {
|
||||
inside.push((Victim::Mob(m.id), m.position.x, m.position.z));
|
||||
}
|
||||
for (victim, x, z) in inside {
|
||||
let (dx, dz) = (x - c.at[0], z - c.at[2]);
|
||||
if potion.victims.iter().any(|(v, _)| *v == victim)
|
||||
|| dx * dx + dz * dz > f64::from(c.radius * c.radius)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
potion.victims.push((victim, c.age + REAPPLICATION_DELAY));
|
||||
self.cloud_affect(victim, effects, c.at, &potion.source);
|
||||
// setRadiusOnUse(-0.5).
|
||||
c.radius -= 0.5;
|
||||
if c.radius < 0.5 {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
/// What a cloud puts on one entity: instant effects at half strength
|
||||
/// (`applyInstantaneousEffect` with 0.5), the others for their duration
|
||||
/// at the lingering item's 0.25 scale (`PotionContents.forEachEffect`).
|
||||
fn cloud_affect(
|
||||
&mut self,
|
||||
victim: Victim,
|
||||
effects: &'static [(&'static str, i32, i32)],
|
||||
at: [f64; 3],
|
||||
source: &Text,
|
||||
) {
|
||||
let scaled = |duration: i32| ((f64::from(duration) * 0.25) as i32).max(1);
|
||||
match victim {
|
||||
Victim::Player(who) => self.as_fight_player(who, |g| {
|
||||
for (id, duration, amp) in effects {
|
||||
let Some(e) = brewing::effect(id) else {
|
||||
continue;
|
||||
};
|
||||
if e.instant {
|
||||
if let Some(a) = horizon_client::effects::instant(id, *amp, 0.5) {
|
||||
g.apply_indirect_effect_action(a, source);
|
||||
}
|
||||
} else {
|
||||
g.add_player_effect(EffectInstance::new(e.id, scaled(*duration), *amp));
|
||||
}
|
||||
}
|
||||
}),
|
||||
Victim::Mob(mob) => {
|
||||
let Some(i) = self.mobs.iter().position(|m| m.id == mob) else {
|
||||
return;
|
||||
};
|
||||
// Undead invert healing and harming.
|
||||
let tags = &self.res.stations().enchantments.entity_tags;
|
||||
let inverted = tags
|
||||
.get("minecraft:inverted_healing_and_harm")
|
||||
.is_some_and(|t| t.contains(&self.mobs[i].kind.id));
|
||||
for (id, duration, amp) in effects {
|
||||
let m = &mut self.mobs[i];
|
||||
match *id {
|
||||
"instant_damage" | "instant_health" => {
|
||||
let amount =
|
||||
|base: i32| (0.5 * f64::from(base << amp) + 0.5) as i32 as f32;
|
||||
if (*id == "instant_damage") != inverted {
|
||||
m.hurt(amount(6), Some(at), &mut self.world.random);
|
||||
} else {
|
||||
m.health = (m.health + amount(4)).min(m.kind.max_health);
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
// `LivingEntity.addEffect` refuses what the mob
|
||||
// cannot be affected by.
|
||||
if mob_can_be_affected(tags, &m.kind.id, id)
|
||||
&& let Some(name) = mob_effect_id(id)
|
||||
{
|
||||
m.add_effect(name, scaled(*duration), *amp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/// `ThrowableProjectile.tick`'s `applyGravity` and `applyInertia`, which
|
||||
@@ -671,44 +1077,46 @@ impl Game<'_> {
|
||||
self.submit_item_world(&state, pose, vertex_light(light), out);
|
||||
}
|
||||
}
|
||||
/// `HealOrHarmMobEffect.applyInstantaneousEffect` with a source (a
|
||||
/// potion or a cloud): indirectMagic, not plain magic.
|
||||
fn apply_indirect_effect_action(&mut self, a: EffectAction, source: &Text) {
|
||||
let a = match a {
|
||||
EffectAction::Hurt("minecraft:magic", amount) => {
|
||||
self.note_direct_entity("minecraft:indirect_magic", source.clone());
|
||||
EffectAction::Hurt("minecraft:indirect_magic", amount)
|
||||
}
|
||||
a => a,
|
||||
};
|
||||
self.apply_effect_action(a);
|
||||
}
|
||||
/// A splash potion's effects on the player in place, by their distance.
|
||||
fn splash_on_player(
|
||||
&mut self,
|
||||
effects: &'static [(&'static str, i32, i32)],
|
||||
at: Vec3,
|
||||
scale: f64,
|
||||
age: u32,
|
||||
source: &Text,
|
||||
) {
|
||||
if let Some(p) = self.player.as_ref() {
|
||||
let center = Vec3::new(
|
||||
p.position.x,
|
||||
p.position.y + f64::from(p.dimensions.height) / 2.0,
|
||||
p.position.z,
|
||||
let w = f64::from(p.dimensions.width) / 2.0;
|
||||
let bounds = Aabb::new(
|
||||
Vec3::new(p.position.x - w, p.position.y, p.position.z - w),
|
||||
Vec3::new(
|
||||
p.position.x + w,
|
||||
p.position.y + f64::from(p.dimensions.height),
|
||||
p.position.z + w,
|
||||
),
|
||||
);
|
||||
let d2 =
|
||||
(center.x - at.x).powi(2) + (center.y - at.y).powi(2) + (center.z - at.z).powi(2);
|
||||
if d2 < 16.0 && (center.y - at.y).abs() <= 2.0 + f64::from(p.dimensions.height) {
|
||||
if let Some(d2) = splash_distance_sqr(at, age, bounds) {
|
||||
let intensity = 1.0 - d2.sqrt() / 4.0;
|
||||
for (id, duration, amp) in effects {
|
||||
let instant = brewing::effect(id).is_some_and(|e| e.instant);
|
||||
if instant {
|
||||
if let Some(a) = horizon_client::effects::instant(id, *amp, intensity) {
|
||||
// HealOrHarmMobEffect.applyInstantaneousEffect with
|
||||
// a source: indirectMagic, not plain magic.
|
||||
let a = match a {
|
||||
EffectAction::Hurt("minecraft:magic", amount) => {
|
||||
self.note_direct_entity(
|
||||
"minecraft:indirect_magic",
|
||||
source.clone(),
|
||||
);
|
||||
EffectAction::Hurt("minecraft:indirect_magic", amount)
|
||||
}
|
||||
a => a,
|
||||
};
|
||||
self.apply_effect_action(a);
|
||||
self.apply_indirect_effect_action(a, source);
|
||||
}
|
||||
} else {
|
||||
let d = (intensity * f64::from(*duration) * scale + 0.5) as i32;
|
||||
let d = (intensity * f64::from(*duration) + 0.5) as i32;
|
||||
if d > 20
|
||||
&& let Some(e) = brewing::effect(id)
|
||||
{
|
||||
@@ -719,8 +1127,16 @@ impl Game<'_> {
|
||||
}
|
||||
}
|
||||
}
|
||||
/// `ThrownSplashPotion.onHitAsPotion` (lingering clouds apply as a weaker splash).
|
||||
fn splash(&mut self, stack: &ItemStack, at: Vec3, owner: Option<Text>) {
|
||||
/// `ThrownSplashPotion.onHitAsPotion`, or `ThrownLingeringPotion.onHitAsPotion`
|
||||
/// for a lingering potion; `mob` is where it hit a mob, `age` its age.
|
||||
fn splash(
|
||||
&mut self,
|
||||
stack: &ItemStack,
|
||||
at: Vec3,
|
||||
mob: Option<Vec3>,
|
||||
age: u32,
|
||||
owner: Option<Text>,
|
||||
) {
|
||||
let block = [at.x, at.y, at.z].map(|v| v.floor() as i32);
|
||||
if &*stack.item == "minecraft:experience_bottle" {
|
||||
// ThrownExperienceBottle.onHit: the water-coloured splash (level
|
||||
@@ -744,31 +1160,48 @@ impl Game<'_> {
|
||||
let color = brewing::potion_color(stack.potion());
|
||||
self.level_event_at(if instant { 2007 } else { 2002 }, block, color as i32);
|
||||
self.level_event_at(if instant { 1054 } else { 1053 }, block, 0);
|
||||
let scale = if lingering { 0.25 } else { 1.0 };
|
||||
let Some(def) = potion else {
|
||||
return;
|
||||
};
|
||||
if lingering {
|
||||
// The cloud sits at the mob it hit (its feet), else the impact;
|
||||
// radius 3, wait 10, 600 ticks, shrinking to nothing, and a
|
||||
// potion with no effects leaves none.
|
||||
if !def.effects.is_empty() {
|
||||
let at = mob.unwrap_or(at);
|
||||
self.breath_clouds.push(Breath {
|
||||
id: 0,
|
||||
at: [at.x, at.y, at.z],
|
||||
radius: 3.0,
|
||||
age: 0,
|
||||
duration: 600,
|
||||
from_dragon: false,
|
||||
potion: Some(PotionCloud {
|
||||
effects: def.effects,
|
||||
color,
|
||||
victims: Vec::new(),
|
||||
source: owner.unwrap_or_else(|| {
|
||||
Text::translate("entity.minecraft.area_effect_cloud", &[])
|
||||
}),
|
||||
}),
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
// Every player in range (`ThrownSplashPotion.applySplash` over
|
||||
// `LivingEntity`s, the players among them).
|
||||
// Instant damage is indirectMagic(potion or cloud, owner), which the
|
||||
// death message names by the owner, else by the potion or cloud.
|
||||
let source = owner.unwrap_or_else(|| {
|
||||
let entity = if lingering {
|
||||
"entity.minecraft.area_effect_cloud"
|
||||
} else {
|
||||
"entity.minecraft.splash_potion"
|
||||
};
|
||||
Text::translate(entity, &[])
|
||||
});
|
||||
self.for_each_player(|g| g.splash_on_player(def.effects, at, scale, &source));
|
||||
// Instant damage is indirectMagic(potion, owner), which the death
|
||||
// message names by the owner, else by the potion.
|
||||
let source =
|
||||
owner.unwrap_or_else(|| Text::translate("entity.minecraft.splash_potion", &[]));
|
||||
self.for_each_player(|g| g.splash_on_player(def.effects, at, age, &source));
|
||||
// Mobs take the instant effects (undead invert healing and harming).
|
||||
let undead = &self.res.stations().enchantments.entity_tags;
|
||||
let mut hits = Vec::new();
|
||||
for (i, m) in self.mobs.iter().enumerate() {
|
||||
let d2 = (m.position.x - at.x).powi(2)
|
||||
+ (m.position.y + m.kind.height / 2.0 - at.y).powi(2)
|
||||
+ (m.position.z - at.z).powi(2);
|
||||
if m.alive() && d2 < 16.0 {
|
||||
if m.alive()
|
||||
&& let Some(d2) = splash_distance_sqr(at, age, m.bounds())
|
||||
{
|
||||
let inverted = undead
|
||||
.get("minecraft:inverted_healing_and_harm")
|
||||
.is_some_and(|t| t.contains(&m.kind.id));
|
||||
@@ -783,7 +1216,7 @@ impl Game<'_> {
|
||||
_ => {
|
||||
// `Potion.applySplash`: timed effects last in
|
||||
// proportion to how close the mob was.
|
||||
let d = (intensity * f64::from(*duration) * scale + 0.5) as i32;
|
||||
let d = (intensity * f64::from(*duration) + 0.5) as i32;
|
||||
if d > 20
|
||||
&& let Some(name) = mob_effect_id(id)
|
||||
{
|
||||
@@ -795,12 +1228,12 @@ impl Game<'_> {
|
||||
let m = &mut self.mobs[i];
|
||||
if harm {
|
||||
m.hurt(
|
||||
(intensity * f64::from(6 << amp)) as i32 as f32,
|
||||
(intensity * f64::from(6 << amp) + 0.5) as i32 as f32,
|
||||
Some([at.x, at.y, at.z]),
|
||||
&mut self.world.random,
|
||||
);
|
||||
} else {
|
||||
m.health = (m.health + (intensity * f64::from(4 << amp)) as i32 as f32)
|
||||
m.health = (m.health + (intensity * f64::from(4 << amp) + 0.5) as i32 as f32)
|
||||
.min(m.kind.max_health);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ pub(super) struct Remote {
|
||||
joined: bool,
|
||||
status: String,
|
||||
pub(super) entity_id: i32,
|
||||
dimension: DimensionType,
|
||||
pub(super) dimension: DimensionType,
|
||||
/// What chunk packets decode with (the dimension's height and sky, the
|
||||
/// biome registry); replaced whenever one of them changes.
|
||||
pub(super) chunk_format: Arc<ChunkFormat>,
|
||||
@@ -156,6 +156,9 @@ pub(super) struct Remote {
|
||||
stepped: HashMap<i32, SteppedInterpolation>,
|
||||
/// `LivingEntity.lerpHeadTo`: the head yaw and the ticks left to reach it.
|
||||
head_lerps: HashMap<i32, (f32, u32)>,
|
||||
/// The happy ghast the player just got off, until the server's teleport
|
||||
/// puts the player on top of it (`place_ghast_under`).
|
||||
pub(super) ghast_dismount: Option<u32>,
|
||||
/// Item entities waiting for their item data: where they are and their
|
||||
/// motion.
|
||||
pending_items: HashMap<i32, ([f64; 3], Vec3)>,
|
||||
@@ -191,6 +194,8 @@ pub(super) struct Remote {
|
||||
input: horizon_client::interaction_input::InteractionInput,
|
||||
stop_mining: bool,
|
||||
placing: Option<([i32; 3], u64)>,
|
||||
/// `CommonPlayerSpawnInfo.isFlat`: the level is a superflat one.
|
||||
pub(super) flat: bool,
|
||||
death_message: Option<String>,
|
||||
player_type: Option<Arc<MobType>>,
|
||||
/// Inventory as last synchronised, for creative-mode slot updates.
|
||||
@@ -454,6 +459,7 @@ impl Game<'_> {
|
||||
lerps: HashMap::new(),
|
||||
stepped: HashMap::new(),
|
||||
head_lerps: HashMap::new(),
|
||||
ghast_dismount: None,
|
||||
pending_items: HashMap::new(),
|
||||
health: (20.0, 20, 5.0),
|
||||
flash_on_set_health: false,
|
||||
@@ -475,6 +481,7 @@ impl Game<'_> {
|
||||
input: Default::default(),
|
||||
stop_mining: false,
|
||||
placing: None,
|
||||
flat: false,
|
||||
death_message: None,
|
||||
player_type,
|
||||
synced: vec![None; 36],
|
||||
@@ -989,6 +996,7 @@ impl Game<'_> {
|
||||
r.chunk_format = Arc::new(r.chunk_format.with_dimension(&dimension));
|
||||
r.dimension = dimension;
|
||||
r.game_mode = spawn.game_type;
|
||||
r.flat = spawn.flat;
|
||||
r.loaded_sent = false;
|
||||
// A replacement LocalPlayer has a fresh sendPosition baseline.
|
||||
r.position_sender = Default::default();
|
||||
@@ -1408,6 +1416,13 @@ impl Game<'_> {
|
||||
{
|
||||
return;
|
||||
}
|
||||
// So does a firework rocket: its own tick flies it on.
|
||||
if path.is_some()
|
||||
&& let Some(f) = self.rockets.iter_mut().find(|f| f.id == id as u32)
|
||||
{
|
||||
f.position = Vec3::new(position[0], position[1], position[2]);
|
||||
return;
|
||||
}
|
||||
// A dragon fireball keeps Entity's NO_OP InterpolationHandler too:
|
||||
// the server's position replaces its own at once.
|
||||
if let Some(b) = self.dragon_fireballs.iter_mut().find(|b| b.id == id as u32) {
|
||||
@@ -1868,7 +1883,8 @@ impl Game<'_> {
|
||||
}
|
||||
C::SetPassengers(p) => self.remote_set_passengers(p.vehicle, &p.passengers),
|
||||
// ClientPacketListener.handleEntityLinkPacket: who holds a mob's
|
||||
// lead (this player, another player or a mob), for the rope.
|
||||
// lead (this player, another player, a mob or a fence knot), for
|
||||
// the rope.
|
||||
C::SetEntityLink(p) => {
|
||||
let me = self.remote.as_ref().map(|r| r.entity_id);
|
||||
if let Some(m) = self.mobs.iter_mut().find(|m| m.id == p.source as u32) {
|
||||
@@ -1876,7 +1892,12 @@ impl Game<'_> {
|
||||
m.extra.leash = match p.dest {
|
||||
0 => None,
|
||||
d if Some(d) == me => Some(Holder::Player),
|
||||
d => Some(Holder::Mob(d as u32)),
|
||||
d => match self.remote_knots.get(&(d as u32)) {
|
||||
Some(&block) => Some(Holder::Knot(block)),
|
||||
// Not a known knot yet: kept by id until the knot
|
||||
// arrives (game/remote_objects.rs).
|
||||
None => Some(Holder::Mob(d as u32)),
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -2109,8 +2130,9 @@ impl Game<'_> {
|
||||
}
|
||||
C::HurtAnimation(p) => {
|
||||
if self.remote.as_ref().is_some_and(|r| r.entity_id == p.id) {
|
||||
// Player.animateHurt: the tilt turns around the yaw.
|
||||
if let Some(pl) = self.player.as_mut() {
|
||||
pl.health.animate_hurt();
|
||||
pl.health.animate_hurt_dir(p.yaw);
|
||||
}
|
||||
} else if let Some(m) = self.mobs.iter_mut().find(|m| m.id == p.id as u32) {
|
||||
m.hurt_time = 10;
|
||||
@@ -2157,6 +2179,37 @@ impl Game<'_> {
|
||||
if p.event == super::totem::TOTEM_EVENT {
|
||||
self.remote_totem(p.id);
|
||||
}
|
||||
// Mob.handleEntityEvent 20: the spawn poof.
|
||||
if p.event == 20 && self.mobs.iter().any(|m| m.id == p.id as u32) {
|
||||
self.poof_particles(p.id as u32);
|
||||
}
|
||||
// Villager 12, 13 and 14, TamableAnimal and AbstractHorse 6 and
|
||||
// 7, Animal and Allay 18: the particles about the mob.
|
||||
if matches!(p.event, 6 | 7 | 12 | 13 | 14 | 18) {
|
||||
self.entity_event_particles(p.id as u32, p.event);
|
||||
}
|
||||
// Snowball and ThrownEgg.handleEntityEvent 3: the crumbs where
|
||||
// the projectile is (the server removes it right after).
|
||||
if p.event == 3 {
|
||||
let crumbs = self
|
||||
.creatures
|
||||
.projectiles
|
||||
.iter()
|
||||
.find(|pr| pr.id == p.id as u32)
|
||||
.and_then(|pr| {
|
||||
let item = match pr.kind {
|
||||
horizon_client::projectiles::ProjectileKind::Snowball => {
|
||||
"minecraft:snowball"
|
||||
}
|
||||
horizon_client::projectiles::ProjectileKind::Egg => "minecraft:egg",
|
||||
_ => return None,
|
||||
};
|
||||
Some(([pr.position.x, pr.position.y, pr.position.z], item))
|
||||
});
|
||||
if let Some((at, item)) = crumbs {
|
||||
self.item_burst(at, item);
|
||||
}
|
||||
}
|
||||
// Entity event 53: the honey slide particles of a player
|
||||
// sliding down a honey block (HoneyBlock.showSlideParticles).
|
||||
if p.event == 53 {
|
||||
@@ -3057,6 +3110,8 @@ impl Game<'_> {
|
||||
p.velocity = v;
|
||||
} else if let Some(b) = self.dragon_fireballs.iter_mut().find(|b| b.id == id as u32) {
|
||||
b.velocity = v;
|
||||
} else if let Some(r) = self.rockets.iter_mut().find(|r| r.id == id as u32) {
|
||||
r.velocity = v;
|
||||
} else if let Some(p) = self
|
||||
.remote
|
||||
.as_mut()
|
||||
@@ -3079,6 +3134,37 @@ impl Game<'_> {
|
||||
p.health.food.saturation = saturation;
|
||||
}
|
||||
}
|
||||
/// `ServerPlayer.dismountTo` lands a rider at the ghast's own (x, maxY, z)
|
||||
/// (`HappyGhast.getDismountLocationForPassenger`). A vanilla client
|
||||
/// simulates the ghast it rides, so its copy is where the server has it;
|
||||
/// this window's copy trails the server's by the stepped interpolation and
|
||||
/// would rise into the rider's feet, which lets the rider fall through.
|
||||
/// Put the copy under the landing spot.
|
||||
fn place_ghast_under(&mut self, id: u32, spot: Vec3) {
|
||||
let Some(m) = self
|
||||
.mobs
|
||||
.iter_mut()
|
||||
.find(|m| m.id == id && m.species() == horizon_client::mobs::Species::HappyGhast)
|
||||
else {
|
||||
return;
|
||||
};
|
||||
let at = Vec3::new(spot.x, spot.y - f64::from(m.height()), spot.z);
|
||||
// Only a teleport that is that dismount: right above the ghast.
|
||||
if (at.x - m.position.x).powi(2) + (at.z - m.position.z).powi(2) > 25.0
|
||||
|| (at.y - m.position.y).abs() > 5.0
|
||||
{
|
||||
return;
|
||||
}
|
||||
m.position = at;
|
||||
m.previous = at;
|
||||
if let Some(handler) = self
|
||||
.remote
|
||||
.as_mut()
|
||||
.and_then(|r| r.stepped.get_mut(&(id as i32)))
|
||||
{
|
||||
handler.cancel();
|
||||
}
|
||||
}
|
||||
/// ClientPacketListener.handleMovePlayer.
|
||||
fn remote_teleport(&mut self, p: &play::PlayerPosition) -> Result<()> {
|
||||
use play::relative as rel;
|
||||
@@ -3138,6 +3224,9 @@ impl Game<'_> {
|
||||
self.previous_position = position;
|
||||
self.yaw = yaw;
|
||||
self.pitch = pitch;
|
||||
if let Some(id) = self.remote.as_mut().and_then(|r| r.ghast_dismount.take()) {
|
||||
self.place_ghast_under(id, position);
|
||||
}
|
||||
if let Some(r) = self.remote.as_mut() {
|
||||
// handleMovePlayer does not change LocalPlayer.sendPosition's
|
||||
// baseline: the next tick must still report the corrected state.
|
||||
@@ -3352,12 +3441,12 @@ impl Game<'_> {
|
||||
let feet = [player.position.x, player.position.y, player.position.z];
|
||||
for event in events {
|
||||
match event {
|
||||
horizon_client::motion::MotionEvent::Emission {
|
||||
state, in_water, ..
|
||||
} if !crouching => {
|
||||
horizon_client::motion::MotionEvent::Emission { state, muffled, .. }
|
||||
if !crouching =>
|
||||
{
|
||||
let sounds = self.res.facts().get(state).sounds.clone();
|
||||
// Player.playStepSound: muffled under the swim sound in water.
|
||||
let (volume, pitch) = if in_water {
|
||||
let (volume, pitch) = if muffled {
|
||||
(sounds.volume * 0.05, sounds.pitch * 0.8)
|
||||
} else {
|
||||
(sounds.volume * 0.15, sounds.pitch)
|
||||
@@ -3935,6 +4024,9 @@ impl Game<'_> {
|
||||
if let Some(r) = self.remote.as_mut() {
|
||||
r.destroying = Some((hit.pos, face, 0.0));
|
||||
}
|
||||
// startDestroyBlock plays the first hit and crack itself; the
|
||||
// server's level events 2019 and 2020 do the rest.
|
||||
self.breaking_block_effects(hit.pos, hit.face, true);
|
||||
self.mining = Some(Mining {
|
||||
pos: hit.pos,
|
||||
progress: 0.0,
|
||||
@@ -3947,20 +4039,6 @@ impl Game<'_> {
|
||||
};
|
||||
let done = done + progress;
|
||||
let ticks = self.mining.as_ref().map_or(0, |m| m.ticks) + 1;
|
||||
if ticks % 4 == 1 {
|
||||
let c = [
|
||||
f64::from(pos[0]) + 0.5,
|
||||
f64::from(pos[1]) + 0.5,
|
||||
f64::from(pos[2]) + 0.5,
|
||||
];
|
||||
self.audio.play(
|
||||
&facts.sounds.hit,
|
||||
Some(c),
|
||||
(facts.sounds.volume + 1.0) / 8.0,
|
||||
facts.sounds.pitch * 0.5,
|
||||
);
|
||||
}
|
||||
self.crack_particle(pos, hit.face, state);
|
||||
if done >= 1.0 {
|
||||
let seq = self.next_sequence();
|
||||
self.predict_break(pos, state, seq);
|
||||
@@ -4250,6 +4328,16 @@ impl Game<'_> {
|
||||
if self.keys.contains(&KeyCode::ShiftLeft) && hands_full {
|
||||
return (false, DryUse::default());
|
||||
}
|
||||
// BeehiveBlock.useItemOn: shears or a glass bottle on a full hive
|
||||
// (honey level 5) is SUCCESS, so the click ends after UseItemOn and
|
||||
// no UseItem follows (the server does the harvest, see `use_beehive`).
|
||||
if held.is_some_and(|s| matches!(&*s.item, "minecraft:shears" | "minecraft:glass_bottle"))
|
||||
&& self
|
||||
.hive_state(hit.pos)
|
||||
.is_some_and(|(honey, _)| honey == Some(5))
|
||||
{
|
||||
return (true, DryUse::default());
|
||||
}
|
||||
use horizon_core::geometry::Direction;
|
||||
let face = match hit.face {
|
||||
[0, 1, 0] => Direction::Up,
|
||||
|
||||
@@ -97,6 +97,10 @@ fn apply(m: &mut Mob, values: &[(u8, i32, Value)], builtin: &Builtin, local_enti
|
||||
// Pillager.IS_CHARGING_CROSSBOW: the charge pose (Raider's
|
||||
// IS_CELEBRATING takes 16).
|
||||
(Species::Pillager, 17, Value::Bool(charging)) => m.extra.flag = *charging,
|
||||
// HappyGhast.STAYS_STILL (after AgeableMob's two and IS_LEASH_HOLDER):
|
||||
// `isOnStillTimeout` on a client, which keeps the ghast solid to
|
||||
// the player (`canBeCollidedWith`).
|
||||
(Species::HappyGhast, 19, Value::Bool(still)) => m.extra.counter = i32::from(*still),
|
||||
// SpellcasterIllager.DATA_SPELL_CASTING_ID: the casting pose.
|
||||
(Species::Evoker | Species::Illusioner, 17, Value::Byte(spell)) => {
|
||||
m.extra.variant2 = (*spell).max(0) as u8;
|
||||
|
||||
@@ -66,8 +66,11 @@ impl Game<'_> {
|
||||
| Species::Salmon
|
||||
| Species::TropicalFish
|
||||
| Species::Pufferfish
|
||||
| Species::Axolotl
|
||||
| Species::Tadpole => item == "minecraft:water_bucket",
|
||||
| Species::Axolotl => item == "minecraft:water_bucket",
|
||||
// Tadpole.mobInteract: frog food, else the bucket.
|
||||
Species::Tadpole => {
|
||||
item == "minecraft:water_bucket" || m.kind.food.iter().any(|f| f.as_str() == item)
|
||||
}
|
||||
Species::Armadillo => item == "minecraft:brush",
|
||||
// ZombieVillager.mobInteract: CONSUME for a golden apple.
|
||||
Species::ZombieVillager => item == "minecraft:golden_apple",
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
//! Boats, minecarts, armor stands, item frames and paintings on a server's
|
||||
//! Boats, minecarts, armor stands, item frames, paintings and fence knots on a server's
|
||||
//! client (`ClientPacketListener.handleAddEntity`, `handleSetEntityData`,
|
||||
//! `handleSetEquipment`): the server simulates them, the client places them
|
||||
//! where it says and interpolates their moves like a mob's.
|
||||
use super::Game;
|
||||
use horizon_client::entities::{ArmorStand, Cushion, ItemFrame, Painting};
|
||||
use horizon_client::mobs::leash::Holder;
|
||||
use horizon_core::geometry::Vec3;
|
||||
use horizon_protocol::entity_data::Value;
|
||||
use std::sync::Arc;
|
||||
@@ -24,7 +25,17 @@ impl Game<'_> {
|
||||
let at = Vec3::new(position[0], position[1], position[2]);
|
||||
let block = position.map(|v| v.floor() as i32);
|
||||
self.remove_remote_object(id);
|
||||
if kind == "minecraft:text_display" {
|
||||
if kind == "minecraft:leash_knot" {
|
||||
// A lead that came before its knot waits as a mob holder with the
|
||||
// knot's id (handleEntityLinkPacket's delayed holder); now it can
|
||||
// be tied to the fence.
|
||||
self.remote_knots.insert(id, block);
|
||||
for m in &mut self.mobs {
|
||||
if m.extra.leash == Some(Holder::Mob(id)) {
|
||||
m.extra.leash = Some(Holder::Knot(block));
|
||||
}
|
||||
}
|
||||
} else if kind == "minecraft:text_display" {
|
||||
self.text_displays.insert(
|
||||
id as i32,
|
||||
super::text_displays::RemoteTextDisplay::new(position, yaw),
|
||||
@@ -304,6 +315,7 @@ impl Game<'_> {
|
||||
/// Every object a server sent (a new connection, level or dimension).
|
||||
pub(super) fn clear_remote_objects(&mut self) {
|
||||
self.text_displays.clear();
|
||||
self.remote_knots.clear();
|
||||
self.carts.clear();
|
||||
self.boats.clear();
|
||||
self.armor_stands.clear();
|
||||
@@ -314,6 +326,7 @@ impl Game<'_> {
|
||||
|
||||
pub(super) fn remove_remote_object(&mut self, id: u32) {
|
||||
self.text_displays.remove(&(id as i32));
|
||||
self.remote_knots.remove(&id);
|
||||
self.carts.retain(|c| c.id != id);
|
||||
self.boats.retain(|b| b.id != id);
|
||||
self.armor_stands.retain(|a| a.id != id);
|
||||
|
||||
@@ -3,8 +3,11 @@
|
||||
//! and `handleSetEntityData`): the server simulates them, the client draws
|
||||
//! them where it says and interpolates their moves.
|
||||
use super::{FallStep, FallingBlock, Game, fireworks::fireworks_of, view_vector};
|
||||
use horizon_client::particles::{ParticleOptions, ParticleType};
|
||||
use horizon_client::projectiles::{Hit, Projectile, ProjectileKind, ProjectileWorld};
|
||||
use horizon_client::{
|
||||
collisions::SceneCollisions,
|
||||
particles::{ParticleOptions, ParticleType},
|
||||
};
|
||||
use horizon_core::{geometry::Vec3, position::BlockPos, random::RandomSource};
|
||||
use horizon_protocol::entity_data::Value;
|
||||
use horizon_world::registry::BlockStateId;
|
||||
@@ -23,6 +26,58 @@ fn default_cloud_particle() -> ParticleOptions {
|
||||
ParticleOptions::colored(ParticleType::EntityEffect, [1.0; 4])
|
||||
}
|
||||
|
||||
/// `AreaEffectCloud.clientTick`: while waiting, now and then two particles
|
||||
/// near the middle; then about one per square block of the disc, drifting
|
||||
/// (an entity effect stays still).
|
||||
pub(super) fn cloud_client_tick(
|
||||
particles: &mut horizon_client::particles::ParticleEngine,
|
||||
at: [f64; 3],
|
||||
radius: f32,
|
||||
waiting: bool,
|
||||
particle: &ParticleOptions,
|
||||
) {
|
||||
if waiting && particles.random().next_boolean() {
|
||||
return;
|
||||
}
|
||||
let (count, spread) = if waiting {
|
||||
(2, 0.2)
|
||||
} else {
|
||||
(
|
||||
(std::f32::consts::PI * radius * radius).ceil() as i32,
|
||||
radius,
|
||||
)
|
||||
};
|
||||
for _ in 0..count {
|
||||
let r = particles.random();
|
||||
let angle = r.next_float() * std::f32::consts::TAU;
|
||||
let distance = r.next_float().sqrt() * spread;
|
||||
let at = [
|
||||
at[0] + f64::from(angle.cos() * distance),
|
||||
at[1],
|
||||
at[2] + f64::from(angle.sin() * distance),
|
||||
];
|
||||
let (options, velocity) = if particle.ty == ParticleType::EntityEffect {
|
||||
let default = waiting && r.next_boolean();
|
||||
let options = if default {
|
||||
default_cloud_particle()
|
||||
} else {
|
||||
particle.clone()
|
||||
};
|
||||
(options, [0.0; 3])
|
||||
} else if waiting {
|
||||
(particle.clone(), [0.0; 3])
|
||||
} else {
|
||||
let v = [
|
||||
(0.5 - r.next_double()) * 0.15,
|
||||
f64::from(0.01f32),
|
||||
(0.5 - r.next_double()) * 0.15,
|
||||
];
|
||||
(particle.clone(), v)
|
||||
};
|
||||
particles.add(&options, at, velocity);
|
||||
}
|
||||
}
|
||||
|
||||
/// The projectile a type id names, as Horizon models it.
|
||||
fn projectile_kind(kind: &str) -> Option<ProjectileKind> {
|
||||
Some(match kind {
|
||||
@@ -360,31 +415,58 @@ impl Game<'_> {
|
||||
let id = t.id;
|
||||
t.remote_step(|at| step(id, at));
|
||||
}
|
||||
// FireworkRocketEntity.tick: a rocket attached to the gliding local
|
||||
// player boosts it client-side too (attachedToEntity.isFallFlying).
|
||||
// FireworkRocketEntity.tick: a rocket attached to an entity follows it
|
||||
// and boosts it client-side too (attachedToEntity.isFallFlying), and
|
||||
// every rocket leaves its spark trail on a client.
|
||||
let me = self
|
||||
.remote
|
||||
.as_ref()
|
||||
.and_then(|r| u32::try_from(r.entity_id).ok());
|
||||
for r in &mut self.rockets {
|
||||
let id = r.id;
|
||||
r.remote_step(|at| step(id, at));
|
||||
if me.is_some()
|
||||
&& r.attached_to == me
|
||||
&& let Some(p) = self.player.as_mut()
|
||||
&& p.fall_flying
|
||||
{
|
||||
let look = view_vector(self.yaw, self.pitch);
|
||||
let m = p.velocity;
|
||||
p.velocity = Vec3::new(
|
||||
m.x + look[0] * 0.1 + (look[0] * 1.5 - m.x) * 0.5,
|
||||
m.y + look[1] * 0.1 + (look[1] * 1.5 - m.y) * 0.5,
|
||||
m.z + look[2] * 0.1 + (look[2] * 1.5 - m.z) * 0.5,
|
||||
);
|
||||
r.position = p.position;
|
||||
r.velocity = p.velocity;
|
||||
let mut rockets = std::mem::take(&mut self.rockets);
|
||||
for r in &mut rockets {
|
||||
r.remote_step(&mut SceneCollisions {
|
||||
world: &self.world,
|
||||
binding: self.collision,
|
||||
subject: None,
|
||||
});
|
||||
if let Some(target) = r.attached_to {
|
||||
if me == Some(target) {
|
||||
if let Some(p) = self.player.as_mut() {
|
||||
if p.fall_flying {
|
||||
let look = view_vector(self.yaw, self.pitch);
|
||||
let m = p.velocity;
|
||||
p.velocity = Vec3::new(
|
||||
m.x + look[0] * 0.1 + (look[0] * 1.5 - m.x) * 0.5,
|
||||
m.y + look[1] * 0.1 + (look[1] * 1.5 - m.y) * 0.5,
|
||||
m.z + look[2] * 0.1 + (look[2] * 1.5 - m.z) * 0.5,
|
||||
);
|
||||
}
|
||||
r.position = p.position;
|
||||
r.velocity = p.velocity;
|
||||
}
|
||||
} else if let Some(m) = self.mobs.iter().find(|m| m.id == target) {
|
||||
// Another player's motion is not known here: its step.
|
||||
r.velocity = Vec3::new(
|
||||
m.position.x - r.previous.x,
|
||||
m.position.y - r.previous.y,
|
||||
m.position.z - r.previous.z,
|
||||
);
|
||||
r.position = m.position;
|
||||
}
|
||||
}
|
||||
let g = |g: &mut horizon_core::random::LegacyRandom| g.next_gaussian() * 0.05;
|
||||
let v = [
|
||||
g(&mut self.world.random),
|
||||
-r.velocity.y * 0.5,
|
||||
g(&mut self.world.random),
|
||||
];
|
||||
self.particles.add(
|
||||
&ParticleOptions::simple(ParticleType::Firework),
|
||||
[r.position.x, r.position.y, r.position.z],
|
||||
v,
|
||||
);
|
||||
}
|
||||
self.rockets = rockets;
|
||||
for c in &mut self.crystals {
|
||||
c.time += 1;
|
||||
c.position = step(c.id, c.position);
|
||||
@@ -414,52 +496,10 @@ impl Game<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
/// `AreaEffectCloud.clientTick`: while waiting, now and then two
|
||||
/// particles near the middle; then about one per square block of the
|
||||
/// disc, drifting (an entity effect stays still).
|
||||
/// `AreaEffectCloud.clientTick` for each cloud a server tracks.
|
||||
fn tick_remote_clouds(&mut self) {
|
||||
for c in &self.potions.clouds {
|
||||
let r = self.particles.random();
|
||||
if c.waiting && r.next_boolean() {
|
||||
continue;
|
||||
}
|
||||
let (count, spread) = if c.waiting {
|
||||
(2, 0.2)
|
||||
} else {
|
||||
(
|
||||
(std::f32::consts::PI * c.radius * c.radius).ceil() as i32,
|
||||
c.radius,
|
||||
)
|
||||
};
|
||||
for _ in 0..count {
|
||||
let r = self.particles.random();
|
||||
let angle = r.next_float() * std::f32::consts::TAU;
|
||||
let distance = r.next_float().sqrt() * spread;
|
||||
let at = [
|
||||
c.at[0] + f64::from(angle.cos() * distance),
|
||||
c.at[1],
|
||||
c.at[2] + f64::from(angle.sin() * distance),
|
||||
];
|
||||
let (options, velocity) = if c.particle.ty == ParticleType::EntityEffect {
|
||||
let default = c.waiting && r.next_boolean();
|
||||
let options = if default {
|
||||
default_cloud_particle()
|
||||
} else {
|
||||
c.particle.clone()
|
||||
};
|
||||
(options, [0.0; 3])
|
||||
} else if c.waiting {
|
||||
(c.particle.clone(), [0.0; 3])
|
||||
} else {
|
||||
let v = [
|
||||
(0.5 - r.next_double()) * 0.15,
|
||||
f64::from(0.01f32),
|
||||
(0.5 - r.next_double()) * 0.15,
|
||||
];
|
||||
(c.particle.clone(), v)
|
||||
};
|
||||
self.particles.add(&options, at, velocity);
|
||||
}
|
||||
cloud_client_tick(&mut self.particles, c.at, c.radius, c.waiting, &c.particle);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -128,6 +128,17 @@ impl Game<'_> {
|
||||
} else if self.riding == Some(vehicle_id) {
|
||||
// The server takes the player out, then teleports it.
|
||||
self.riding = None;
|
||||
// HappyGhast.removePassenger: a still timeout of 10 (the server's
|
||||
// STAYS_STILL confirms it), and the rider lands on top of the ghast
|
||||
// (`place_ghast_under`).
|
||||
if let Some(m) = self.mobs.iter_mut().find(|m| {
|
||||
m.id == vehicle_id && m.species() == horizon_client::mobs::Species::HappyGhast
|
||||
}) {
|
||||
m.extra.counter = 10;
|
||||
if let Some(r) = self.remote.as_mut() {
|
||||
r.ghast_dismount = Some(vehicle_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -92,9 +92,8 @@ impl Game<'_> {
|
||||
distant_terrain: self.lod.is_some(),
|
||||
cloud_range_chunks: self.settings.cloud_range,
|
||||
camera_y: camera.y,
|
||||
// level.getMinY(): the Nether and the End start at y 0.
|
||||
min_y: if self.dim == Dim::Overworld { MIN_Y } else { 0 },
|
||||
flat: false,
|
||||
min_y: self.level_min_y(),
|
||||
flat: self.level_flat(),
|
||||
forward: forward.map(|c| c as f32),
|
||||
rain,
|
||||
thunder,
|
||||
@@ -108,9 +107,30 @@ impl Game<'_> {
|
||||
},
|
||||
)
|
||||
}
|
||||
/// `SkyRenderer.shouldRenderDarkDisc`: eye below the horizon (y 63) and not under water.
|
||||
/// `ClientLevelData.isFlat`: on the server thread, the world-wide flag.
|
||||
fn level_flat(&self) -> bool {
|
||||
match self.remote.as_ref() {
|
||||
Some(r) => r.flat,
|
||||
None => self.world_flat,
|
||||
}
|
||||
}
|
||||
/// `Level.getMinY`: the current dimension type's minimum y.
|
||||
fn level_min_y(&self) -> i32 {
|
||||
match self.remote.as_ref() {
|
||||
Some(r) => r.dimension.min_y,
|
||||
None => self.dim.min_y(),
|
||||
}
|
||||
}
|
||||
/// `SkyRenderer.shouldRenderDarkDisc`: eye below the horizon and not under
|
||||
/// water. `ClientLevelData.getHorizonHeight`: the bottom of a flat world,
|
||||
/// otherwise y 63.
|
||||
pub(super) fn dark_disc(&self, camera: glam::DVec3) -> bool {
|
||||
camera.y < 63.0
|
||||
let horizon = if self.level_flat() {
|
||||
f64::from(self.level_min_y())
|
||||
} else {
|
||||
63.0
|
||||
};
|
||||
camera.y < horizon
|
||||
&& fog_type(
|
||||
&self.world,
|
||||
self.res.facts(),
|
||||
@@ -272,6 +292,16 @@ impl Game<'_> {
|
||||
&& motion_blocking(world, facts, p[0], p[2], p[1] + 64) <= p[1]
|
||||
&& rains_at(world, biomes, p[0], p[1], p[2])
|
||||
};
|
||||
let tables = &self.pack.context.tables;
|
||||
let model_offset = |state, x, z| tables.offset(state, x, z);
|
||||
let gateway_particles = |state, p| {
|
||||
self.res
|
||||
.block_entity_render()
|
||||
.gateway_faces(world, state, p)
|
||||
.len()
|
||||
};
|
||||
// Level.isThundering: a thunder level above 0.9 where the sky is open.
|
||||
let thundering = self.dim == Dim::Overworld && world.weather.levels(1.0).1 > 0.9;
|
||||
let ctx = AnimateContext {
|
||||
world,
|
||||
facts,
|
||||
@@ -280,6 +310,10 @@ impl Game<'_> {
|
||||
registry: self.pack.assets.registry,
|
||||
raining_at: &raining_at,
|
||||
marker: marker.map(|name| (name, &marker_options as &dyn Fn(_) -> _)),
|
||||
model_offset: &model_offset,
|
||||
gateway_particles: &gateway_particles,
|
||||
thundering,
|
||||
ultrawarm: self.dim == Dim::Nether,
|
||||
};
|
||||
if let Some(e) = eye {
|
||||
let block = [
|
||||
@@ -289,11 +323,13 @@ impl Game<'_> {
|
||||
];
|
||||
animate_tick(self.res.animate(), &mut self.particles, &ctx, block);
|
||||
if rain > 0.0 {
|
||||
// ClientLevel.tickWeatherEffects: rain splashes (weather radius 10).
|
||||
// ClientLevel.tickWeatherEffects: rain splashes (weather radius 10)
|
||||
// and the rain sound.
|
||||
let mut random = LegacyRandom::new(self.world.game_time.wrapping_mul(312_987_231));
|
||||
let radius = 10;
|
||||
let diameter = 2 * radius + 1;
|
||||
let count = (0.225 * (diameter * diameter) as f32 * rain * rain) as i32;
|
||||
let mut rain_position = None;
|
||||
for _ in 0..count {
|
||||
let x = block[0] + random.next_int_bound(diameter).unwrap_or(0) - radius;
|
||||
let z = block[2] + random.next_int_bound(diameter).unwrap_or(0) - radius;
|
||||
@@ -306,6 +342,7 @@ impl Game<'_> {
|
||||
continue;
|
||||
}
|
||||
let below = top - 1;
|
||||
rain_position = Some([x, below, z]);
|
||||
let (bx, bz) = (random.next_double(), random.next_double());
|
||||
let state = world.block(x, below, z);
|
||||
let f = facts.get(state);
|
||||
@@ -337,6 +374,26 @@ impl Game<'_> {
|
||||
self.particles
|
||||
.add(&ParticleOptions::simple(ty), p, [0.0; 3]);
|
||||
}
|
||||
// The last rain column of the tick makes the sound, more often the
|
||||
// longer it has been quiet; indoors it is the quieter one.
|
||||
if let Some(at) = rain_position {
|
||||
let waited = self.rain_sound_time;
|
||||
self.rain_sound_time += 1;
|
||||
if random.next_int_bound(3).unwrap_or(0) < waited {
|
||||
self.rain_sound_time = 0;
|
||||
let roof =
|
||||
motion_blocking(world, facts, block[0], block[2], MIN_Y + HEIGHT);
|
||||
let (name, volume, pitch) = if at[1] > block[1] + 1 && roof > block[1] {
|
||||
("minecraft:weather.rain.above", 0.1, 0.5)
|
||||
} else {
|
||||
("minecraft:weather.rain", 0.2, 1.0)
|
||||
};
|
||||
let p = at.map(|c| f64::from(c) + 0.5);
|
||||
// playLocalSound: guests make their own rain, so a host
|
||||
// must not capture it for them.
|
||||
self.audio.play_unshared(name, Some(p), volume, pitch);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(r) = &self.renderer {
|
||||
|
||||
@@ -5,7 +5,8 @@ use super::{Game, lan::LanHost};
|
||||
use horizon_client::{
|
||||
containers::BlockEntity,
|
||||
hud::{HudBatch, rgba},
|
||||
signs::wood_type,
|
||||
items::ItemStack,
|
||||
signs::{DYE_TEXT, wood_type},
|
||||
ui::EditBox,
|
||||
};
|
||||
use horizon_protocol::packets::play::{self, Clientbound as C, Serverbound as S};
|
||||
@@ -31,6 +32,157 @@ fn sign_box() -> EditBox {
|
||||
}
|
||||
|
||||
impl Game<'_> {
|
||||
/// `SignBlockEntity.getSlotPlayerIsFacing`: whether the player stands in
|
||||
/// front of the sign's text (within 90 degrees of its facing).
|
||||
fn facing_sign_front(&self, pos: (i32, i32, i32)) -> bool {
|
||||
let Some(player) = self.player.as_ref() else {
|
||||
return true;
|
||||
};
|
||||
let state = self.world.block(pos.0, pos.1, pos.2);
|
||||
let Some(state) = self.pack.assets.registry.state(state) else {
|
||||
return true;
|
||||
};
|
||||
let prop = |key: &str| state.properties.get(key).map(String::as_str);
|
||||
// getYRotationDegrees: a wall sign's `Direction.toYRot`, a standing or
|
||||
// ceiling sign's rotation segment.
|
||||
let y_rot = if state.name.contains("_wall_") {
|
||||
match prop("facing") {
|
||||
Some("west") => 90.0,
|
||||
Some("north") => 180.0,
|
||||
Some("east") => 270.0,
|
||||
_ => 0.0,
|
||||
}
|
||||
} else {
|
||||
prop("rotation")
|
||||
.and_then(|r| r.parse::<f32>().ok())
|
||||
.unwrap_or(0.0)
|
||||
* 22.5
|
||||
};
|
||||
// getSignHitboxCenterPosition: only a wall sign's board is off-centre,
|
||||
// against the wall it hangs on.
|
||||
let centre = if state.name.ends_with("_wall_sign") {
|
||||
match y_rot as i32 {
|
||||
90 => (0.9375, 0.5),
|
||||
180 => (0.5, 0.9375),
|
||||
270 => (0.0625, 0.5),
|
||||
_ => (0.5, 0.0625),
|
||||
}
|
||||
} else {
|
||||
(0.5, 0.5)
|
||||
};
|
||||
let xd = player.position.x - (f64::from(pos.0) + centre.0);
|
||||
let zd = player.position.z - (f64::from(pos.2) + centre.1);
|
||||
let player_y_rot = (zd.atan2(xd).to_degrees() - 90.0) as f32;
|
||||
// Mth.degreesDifferenceAbs.
|
||||
let diff = (player_y_rot - y_rot).rem_euclid(360.0);
|
||||
let diff = if diff >= 180.0 { 360.0 - diff } else { diff };
|
||||
diff <= 90.0
|
||||
}
|
||||
/// `SignBlock.useWithoutItem` (the block's `OpenMenu` effect): a waxed
|
||||
/// sign plays the failed-interaction sound; otherwise a player who may
|
||||
/// build edits the side they face.
|
||||
pub(super) fn use_sign_empty_hand(&mut self, pos: [i32; 3]) {
|
||||
let key = (pos[0], pos[1], pos[2]);
|
||||
let Some(BlockEntity::Sign(sign)) = self.world.block_entities.get(&key) else {
|
||||
return;
|
||||
};
|
||||
if sign.waxed {
|
||||
// `getSignInteractionFailedSoundEvent`: a hanging sign has its own.
|
||||
let sound = if sign.hanging {
|
||||
"minecraft:block.hanging_sign.waxed_interact_fail"
|
||||
} else {
|
||||
"minecraft:block.sign.waxed_interact_fail"
|
||||
};
|
||||
self.audio
|
||||
.play(sound, Some(pos.map(|v| f64::from(v) + 0.5)), 1.0, 1.0);
|
||||
} else if self.may_build() {
|
||||
let front = self.facing_sign_front(key);
|
||||
self.open_sign_editor(key, front);
|
||||
}
|
||||
}
|
||||
/// `SignBlock.useItemOn` with a `SignApplicator` in hand (dyes, ink sacs,
|
||||
/// honeycomb): the item changes the side the player faces and is used up.
|
||||
/// Whether it did; a sign it does not apply to goes on to the empty hand.
|
||||
pub(super) fn use_sign_applicator(&mut self, pos: [i32; 3], held: Option<&ItemStack>) -> bool {
|
||||
let Some(stack) = held else {
|
||||
return false;
|
||||
};
|
||||
let key = (pos[0], pos[1], pos[2]);
|
||||
let Some(BlockEntity::Sign(sign)) = self.world.block_entities.get(&key) else {
|
||||
return false;
|
||||
};
|
||||
if sign.waxed || !self.may_build() {
|
||||
return false;
|
||||
}
|
||||
let item = &*stack.item;
|
||||
let dye = if item.ends_with("_dye") {
|
||||
self.res
|
||||
.items()
|
||||
.get(&stack.item)
|
||||
.and_then(|i| i.dye.clone())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let colour = dye.and_then(|d| DYE_TEXT.iter().position(|(n, _)| *n == d));
|
||||
if !matches!(
|
||||
item,
|
||||
"minecraft:honeycomb" | "minecraft:glow_ink_sac" | "minecraft:ink_sac"
|
||||
) && colour.is_none()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
let front = self.facing_sign_front(key);
|
||||
let Some(BlockEntity::Sign(sign)) = self.world.block_entities.get_mut(&key) else {
|
||||
return false;
|
||||
};
|
||||
let centre = pos.map(|v| f64::from(v) + 0.5);
|
||||
let sound = if item == "minecraft:honeycomb" {
|
||||
// HoneycombItem.tryApplyToSign: waxes any sign, empty or not.
|
||||
sign.waxed = true;
|
||||
"minecraft:item.honeycomb.wax_on"
|
||||
} else {
|
||||
let side = if front {
|
||||
&mut sign.front
|
||||
} else {
|
||||
&mut sign.back
|
||||
};
|
||||
// SignApplicator.canApplyToSign: the side must have text.
|
||||
if side.is_empty() {
|
||||
return false;
|
||||
}
|
||||
match colour {
|
||||
Some(c) if side.color != c as u8 => {
|
||||
side.color = c as u8;
|
||||
"minecraft:item.dye.use"
|
||||
}
|
||||
None if item == "minecraft:glow_ink_sac" && !side.glowing => {
|
||||
side.glowing = true;
|
||||
"minecraft:item.glow_ink_sac.use"
|
||||
}
|
||||
None if item == "minecraft:ink_sac" && side.glowing => {
|
||||
side.glowing = false;
|
||||
"minecraft:item.ink_sac.use"
|
||||
}
|
||||
_ => return false,
|
||||
}
|
||||
};
|
||||
if item == "minecraft:honeycomb" {
|
||||
self.level_event_at(3003, pos, 0);
|
||||
}
|
||||
self.audio.play(sound, Some(centre), 1.0, 1.0);
|
||||
self.mark_block_entity_updated(key);
|
||||
let state = self.world.block(pos[0], pos[1], pos[2]);
|
||||
self.post_block_game_event(
|
||||
"minecraft:block_change",
|
||||
pos,
|
||||
self.sculk_actor(),
|
||||
Some(state),
|
||||
);
|
||||
self.stats.add("used", &stack.item, 1);
|
||||
self.consume_held();
|
||||
self.trigger_block("minecraft:item_used_on_block", pos, stack);
|
||||
true
|
||||
}
|
||||
/// `SignBlock.openTextEdit` for the front side after placement.
|
||||
pub(super) fn open_sign_editor(&mut self, pos: (i32, i32, i32), front: bool) {
|
||||
self.sign_edit = Some(SignEditor {
|
||||
|
||||
@@ -253,12 +253,21 @@ impl Game<'_> {
|
||||
self.world.modified.insert((key.0 >> 4, key.2 >> 4));
|
||||
}
|
||||
/// `LivingEntity.makePoofParticles` (entity event 20) for a mob.
|
||||
fn mob_poof(&mut self, id: u32) {
|
||||
pub(super) fn mob_poof(&mut self, id: u32) {
|
||||
let Some(m) = self.mobs.iter().find(|m| m.id == id) else {
|
||||
return;
|
||||
};
|
||||
let at = m.position;
|
||||
self.lan_entity_event(id as i32, 20, [at.x, at.y, at.z]);
|
||||
self.poof_particles(id);
|
||||
}
|
||||
/// `Mob.handleEntityEvent` 20 (`spawnAnim` on a client): the poof about
|
||||
/// mob `id`.
|
||||
pub(super) fn poof_particles(&mut self, id: u32) {
|
||||
let Some(m) = self.mobs.iter().find(|m| m.id == id) else {
|
||||
return;
|
||||
};
|
||||
let (at, w, h) = (m.position, f64::from(m.width()), f64::from(m.height()));
|
||||
self.lan_entity_event(id as i32, 20, [at.x, at.y, at.z]);
|
||||
let options = ParticleOptions::simple(ParticleType::Poof);
|
||||
for _ in 0..20 {
|
||||
let r = self.particles.level_random();
|
||||
|
||||
@@ -779,6 +779,7 @@ impl Game<'_> {
|
||||
return;
|
||||
};
|
||||
let pos = s.pos;
|
||||
let enchanted_item = enchanted.clone();
|
||||
// Player.onEnchantmentPerformed
|
||||
self.give_levels(-(lapis_needed as i32));
|
||||
self.level.xp_seed = self.world.random.next_int();
|
||||
@@ -795,6 +796,7 @@ impl Game<'_> {
|
||||
}
|
||||
let pitch = self.world.random.next_float() * 0.1 + 0.9;
|
||||
self.stats.custom("enchant_item", 1);
|
||||
self.trigger_enchanted_item(&enchanted_item, lapis_needed as i32);
|
||||
self.play_at("minecraft:block.enchantment_table.use", pos, 1.0, pitch);
|
||||
self.station_changed();
|
||||
}
|
||||
|
||||
@@ -256,9 +256,8 @@ impl Game<'_> {
|
||||
.fluid
|
||||
== horizon_client::blocks::Fluid::Water;
|
||||
let on_ground = p.ground.on_ground;
|
||||
let (sprinting, flying, gliding, swimming) = (
|
||||
let (sprinting, gliding, swimming) = (
|
||||
p.sprinting,
|
||||
p.flying,
|
||||
p.fall_flying,
|
||||
p.pose == horizon_client::pose::Pose::Swimming,
|
||||
);
|
||||
@@ -272,15 +271,27 @@ impl Game<'_> {
|
||||
});
|
||||
let s = &mut self.stats;
|
||||
match riding {
|
||||
Some(Ok(horizon_client::mobs::Species::Pig)) => s.custom("pig_one_cm", total),
|
||||
Some(Ok(horizon_client::mobs::Species::Strider)) => s.custom("strider_one_cm", total),
|
||||
Some(Ok(sp)) if horizon_client::mobs::equine::is_equine(sp) => {
|
||||
s.custom("horse_one_cm", horizontal)
|
||||
Some(Ok(sp)) => {
|
||||
use horizon_client::mobs::Species;
|
||||
// `checkRidingStatistics`: only these mounts count, the horse
|
||||
// family by the full 3D distance; any other mount nothing.
|
||||
match sp {
|
||||
Species::Pig => s.custom("pig_one_cm", total),
|
||||
Species::Strider => s.custom("strider_one_cm", total),
|
||||
Species::HappyGhast => s.custom("happy_ghast_one_cm", total),
|
||||
Species::Nautilus | Species::ZombieNautilus => {
|
||||
s.custom("nautilus_one_cm", total)
|
||||
}
|
||||
sp if horizon_client::mobs::equine::is_equine(sp) => {
|
||||
s.custom("horse_one_cm", total)
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
Some(_) => {
|
||||
Some(Err(())) => {
|
||||
if self.boats.iter().any(|b| Some(b.id) == self.riding) {
|
||||
s.custom("boat_one_cm", total)
|
||||
} else {
|
||||
} else if self.carts.iter().any(|c| Some(c.id) == self.riding) {
|
||||
s.custom("minecart_one_cm", total)
|
||||
}
|
||||
}
|
||||
@@ -300,8 +311,9 @@ impl Game<'_> {
|
||||
}
|
||||
}
|
||||
None if gliding => s.custom("aviate_one_cm", total),
|
||||
None if flying => s.custom("fly_one_cm", horizontal),
|
||||
None if d.y < 0.0 => s.custom("fall_one_cm", (-d.y * 100.0).round() as i32),
|
||||
// Airborne and not gliding: more than 25 cm sideways per move
|
||||
// (creative flight, or a long jump), not only flying.
|
||||
None if horizontal > 25 => s.custom("fly_one_cm", horizontal),
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
//! player's `PlayerEnderChestContainer`, saved as `EnderItems`).
|
||||
use super::Game;
|
||||
use horizon_client::{containers::BlockEntity, items::ItemStack, text::Text};
|
||||
use horizon_core::random::RandomSource;
|
||||
|
||||
pub(super) fn is_shulker_box(name: &str) -> bool {
|
||||
name.ends_with("shulker_box")
|
||||
@@ -156,6 +157,79 @@ impl Game<'_> {
|
||||
);
|
||||
paired.then_some((other, kind == "right"))
|
||||
}
|
||||
/// The open or close sound of a container block (`ChestBlockEntity.playSound`,
|
||||
/// `BarrelBlockEntity.playSound`, `ShulkerBoxBlockEntity.startOpen`): volume
|
||||
/// 0.5 and pitch 0.9 to 1.0. A double chest sounds once from the middle of
|
||||
/// both halves, a barrel from the face it opens on.
|
||||
pub(super) fn container_sound(&mut self, sound: &str, key: (i32, i32, i32), name: &str) {
|
||||
let mut at = [
|
||||
f64::from(key.0) + 0.5,
|
||||
f64::from(key.1) + 0.5,
|
||||
f64::from(key.2) + 0.5,
|
||||
];
|
||||
if let Some((other, _)) = self.chest_partner(key) {
|
||||
at[0] = f64::from(key.0 + other.0) / 2.0 + 0.5;
|
||||
at[2] = f64::from(key.2 + other.2) / 2.0 + 0.5;
|
||||
} else if name == "minecraft:barrel"
|
||||
&& let Some(state) = self
|
||||
.pack
|
||||
.assets
|
||||
.registry
|
||||
.state(self.world.block(key.0, key.1, key.2))
|
||||
&& let Some(facing) = state.properties.get("facing")
|
||||
{
|
||||
let (dx, dy, dz) = match facing.as_str() {
|
||||
"up" => (0.0, 0.5, 0.0),
|
||||
"down" => (0.0, -0.5, 0.0),
|
||||
f => {
|
||||
let (x, z) = facing_step(f);
|
||||
(f64::from(x) / 2.0, 0.0, f64::from(z) / 2.0)
|
||||
}
|
||||
};
|
||||
at = [at[0] + dx, at[1] + dy, at[2] + dz];
|
||||
}
|
||||
let pitch = self.world.random.next_float() * 0.1 + 0.9;
|
||||
self.audio.play(sound, Some(at), 0.5, pitch);
|
||||
}
|
||||
/// The open or close sound of the container block at `key`, if it has one.
|
||||
/// Callers play it only when the opener count crosses zero
|
||||
/// (`ContainerOpenersCounter.onOpen` / `onClose`).
|
||||
pub(super) fn container_edge_sound(&mut self, key: (i32, i32, i32), open: bool) {
|
||||
let name = self
|
||||
.res
|
||||
.facts()
|
||||
.get(self.world.block(key.0, key.1, key.2))
|
||||
.name
|
||||
.clone();
|
||||
let sound = if is_shulker_box(&name) {
|
||||
if open {
|
||||
"minecraft:block.shulker_box.open"
|
||||
} else {
|
||||
"minecraft:block.shulker_box.close"
|
||||
}
|
||||
} else if &*name == "minecraft:ender_chest" {
|
||||
if open {
|
||||
"minecraft:block.ender_chest.open"
|
||||
} else {
|
||||
"minecraft:block.ender_chest.close"
|
||||
}
|
||||
} else if name.contains("chest") {
|
||||
if open {
|
||||
"minecraft:block.chest.open"
|
||||
} else {
|
||||
"minecraft:block.chest.close"
|
||||
}
|
||||
} else if &*name == "minecraft:barrel" {
|
||||
if open {
|
||||
"minecraft:block.barrel.open"
|
||||
} else {
|
||||
"minecraft:block.barrel.close"
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
};
|
||||
self.container_sound(sound, key, &name);
|
||||
}
|
||||
/// The other half of a double chest at `key`, for neighbour updates.
|
||||
pub(super) fn chest_other_half(&self, key: (i32, i32, i32)) -> Option<(i32, i32, i32)> {
|
||||
self.chest_partner(key).map(|p| p.0)
|
||||
|
||||
@@ -178,7 +178,9 @@ impl Game<'_> {
|
||||
];
|
||||
self.tnts.remove(i);
|
||||
count -= 1;
|
||||
self.server_explode(center, 4.0, BlockInteraction::Destroy, false)?;
|
||||
self.with_hive_emptying_blast(|g| {
|
||||
g.server_explode(center, 4.0, BlockInteraction::Destroy, false)
|
||||
})?;
|
||||
} else {
|
||||
i += 1;
|
||||
}
|
||||
|
||||
@@ -245,7 +245,7 @@ impl Game<'_> {
|
||||
self.handle_mob_events(events)?;
|
||||
return Ok(true);
|
||||
}
|
||||
self.stats.custom("talk_to_villager", 1);
|
||||
self.stats.custom("talked_to_villager", 1);
|
||||
self.ensure_offers(index);
|
||||
let m = &self.mobs[index];
|
||||
let trade = m.extra.trade.as_deref().cloned().unwrap_or_default();
|
||||
@@ -398,18 +398,21 @@ impl Game<'_> {
|
||||
.as_ref()
|
||||
.and_then(|s| s.merchant.as_ref())
|
||||
.and_then(|m| m.mob);
|
||||
let session = self.merchant_apply(session, mob);
|
||||
let (session, traded) = self.merchant_apply(session, mob);
|
||||
self.merchant_traded(mob, &traded);
|
||||
if let Some(m) = self.station.as_mut().and_then(|s| s.merchant.as_mut()) {
|
||||
m.session = session;
|
||||
}
|
||||
}
|
||||
/// What a menu click's session did, applied to the world and its mob.
|
||||
/// What a menu click's session did, applied to the world and its mob;
|
||||
/// with the result of each trade made, for `merchant_traded`.
|
||||
pub(super) fn merchant_apply(
|
||||
&mut self,
|
||||
session: Box<merchant::Session>,
|
||||
mob: Option<u32>,
|
||||
) -> Box<merchant::Session> {
|
||||
) -> (Box<merchant::Session>, Vec<ItemStack>) {
|
||||
let mut session = session;
|
||||
let mut traded = Vec::new();
|
||||
let events = std::mem::take(&mut session.events);
|
||||
let (villager, origin) = (session.villager, session.origin);
|
||||
if let Some(m) = mob.and_then(|id| self.mobs.iter_mut().find(|m| m.id == id)) {
|
||||
@@ -438,11 +441,26 @@ impl Game<'_> {
|
||||
};
|
||||
self.audio.play(sound, Some(origin), 1.0, pitch);
|
||||
}
|
||||
merchant::Event::Traded(_) => self.stats.custom("traded_with_villager", 1),
|
||||
merchant::Event::Traded(index) => {
|
||||
traded.extend(session.offers.get(index).map(|o| o.result.clone()));
|
||||
}
|
||||
merchant::Event::TradeSound => {}
|
||||
}
|
||||
}
|
||||
session
|
||||
(session, traded)
|
||||
}
|
||||
/// `MerchantResultSlot.checkTakeAchievements` and `AbstractVillager.notifyTrade`
|
||||
/// for each trade made: the statistic and the `villager_trade` trigger.
|
||||
pub(super) fn merchant_traded(&mut self, mob: Option<u32>, results: &[ItemStack]) {
|
||||
for result in results {
|
||||
self.stats.custom("traded_with_villager", 1);
|
||||
let villager = mob
|
||||
.and_then(|id| self.mobs.iter().find(|m| m.id == id))
|
||||
.map(|m| self.mob_entity(m));
|
||||
if let Some(villager) = villager {
|
||||
self.trigger_trade(&villager, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
/// `Villager.customServerAiStep`: the TRADE reputation event of the last
|
||||
/// trade, a tick later; the prices follow the new reputation.
|
||||
|
||||
@@ -32,6 +32,8 @@ pub(super) struct ThrownTrident {
|
||||
pub(super) no_physics: bool,
|
||||
returning: u32,
|
||||
creative_only: bool,
|
||||
/// The guest that threw it (`Projectile.getOwner`); `None` for the host.
|
||||
guest: Option<u32>,
|
||||
}
|
||||
impl ThrownTrident {
|
||||
/// A trident a server sent (`handleAddEntity`): placed and moved by it.
|
||||
@@ -51,6 +53,7 @@ impl ThrownTrident {
|
||||
no_physics: false,
|
||||
returning: 0,
|
||||
creative_only: false,
|
||||
guest: None,
|
||||
}
|
||||
}
|
||||
/// One tick of a server's client: the previous position, then `step`.
|
||||
@@ -302,11 +305,33 @@ impl Game<'_> {
|
||||
no_physics: false,
|
||||
returning: 0,
|
||||
creative_only: self.creative,
|
||||
guest: self.lan_acting,
|
||||
});
|
||||
self.player_projectile_shot();
|
||||
self.audio
|
||||
.play("minecraft:item.trident.throw", at, 1.0, 1.0);
|
||||
}
|
||||
/// The thrower's `PLAYER_HURT_ENTITY` for a trident hit: run as the
|
||||
/// guest that threw it, and not at all once they have left.
|
||||
fn thrower_hit(
|
||||
&mut self,
|
||||
guest: Option<u32>,
|
||||
victim: &horizon_client::advancements::EntityView,
|
||||
direct: horizon_client::advancements::EntityView,
|
||||
damage: f32,
|
||||
) {
|
||||
let Some(conn) = guest.filter(|c| self.lan_acting != Some(*c)) else {
|
||||
self.player_hit(victim, "minecraft:trident", Some(direct), damage);
|
||||
return;
|
||||
};
|
||||
let Some(mut host) = self.lan.take() else {
|
||||
return;
|
||||
};
|
||||
self.as_guest(&mut host, conn, |g| {
|
||||
g.player_hit(victim, "minecraft:trident", Some(direct), damage)
|
||||
});
|
||||
self.lan = Some(host);
|
||||
}
|
||||
pub(super) fn tick_tridents(&mut self) {
|
||||
let Some(eye) = self.eye_position() else {
|
||||
return;
|
||||
@@ -394,6 +419,18 @@ impl Game<'_> {
|
||||
{
|
||||
self.channel_lightning(at);
|
||||
}
|
||||
if hurt_at.is_some()
|
||||
&& let Some(m) = self.mobs.iter().find(|m| m.id == id)
|
||||
{
|
||||
// LivingEntity.hurtServer: PLAYER_HURT_ENTITY.
|
||||
let victim = self.mob_entity(m);
|
||||
let direct = horizon_client::advancements::EntityView {
|
||||
kind: "minecraft:trident".into(),
|
||||
position: [t.position.x, t.position.y, t.position.z],
|
||||
..Default::default()
|
||||
};
|
||||
self.thrower_hit(t.guest, &victim, direct, damage);
|
||||
}
|
||||
self.audio.play(
|
||||
"minecraft:item.trident.hit",
|
||||
Some([t.position.x, t.position.y, t.position.z]),
|
||||
|
||||
@@ -169,6 +169,8 @@ impl Game<'_> {
|
||||
self.consume_held();
|
||||
}
|
||||
}
|
||||
// ServerPlayerGameMode.useItemOn: the action was consumed.
|
||||
self.trigger_block("minecraft:item_used_on_block", pos, &stack);
|
||||
Ok(true)
|
||||
}
|
||||
fn vault_events(&mut self, key: Pos, events: Vec<VaultEvent>) -> Result<()> {
|
||||
|
||||
@@ -148,7 +148,7 @@ impl Game<'_> {
|
||||
// VillagerMakeLove: entity event 13 for the partner, then the parent.
|
||||
for i in [ib, ia] {
|
||||
let id = self.mobs[i].id;
|
||||
self.villager_particles(id, "angry_villager");
|
||||
self.mob_event_particles(id, 13);
|
||||
}
|
||||
return;
|
||||
};
|
||||
@@ -173,12 +173,31 @@ impl Game<'_> {
|
||||
child.extra.bed = Some(bed);
|
||||
}
|
||||
// VillagerMakeLove.giveBirth: entity event 12 for the child.
|
||||
self.villager_particles(id, "heart");
|
||||
self.mob_event_particles(id, 12);
|
||||
}
|
||||
/// `Villager.handleEntityEvent` 12, 13, 14 and 42:
|
||||
/// `AbstractVillager.addParticlesAroundSelf`.
|
||||
pub(super) fn villager_particles(&mut self, id: u32, kind: &'static str) {
|
||||
self.particles_around_mob(id, kind, horizon_client::particles::Burst::VILLAGER);
|
||||
/// `Level.broadcastEntityEvent` of an event whose `handleEntityEvent`
|
||||
/// draws particles about the mob (villager 12, 13 and 14, taming 6 and 7,
|
||||
/// love 18): the guests get the byte, and this game draws it as its own
|
||||
/// client would.
|
||||
pub(super) fn mob_event_particles(&mut self, id: u32, event: i8) {
|
||||
let Some(m) = self.mobs.iter().find(|m| m.id == id) else {
|
||||
return;
|
||||
};
|
||||
let at = [m.position.x, m.position.y, m.position.z];
|
||||
self.lan_entity_event(id as i32, event, at);
|
||||
self.entity_event_particles(id, event);
|
||||
}
|
||||
/// `handleEntityEvent(event)`'s particles about mob `id`
|
||||
/// (`Villager`, `TamableAnimal`, `AbstractHorse`, `Animal`, `Allay`).
|
||||
pub(super) fn entity_event_particles(&mut self, id: u32, event: i8) {
|
||||
let Some(m) = self.mobs.iter().find(|m| m.id == id) else {
|
||||
return;
|
||||
};
|
||||
if let Some((kind, burst)) =
|
||||
horizon_client::particles::entity_event_burst(&m.kind.id, event as u8)
|
||||
{
|
||||
self.particles_around_mob(id, kind, burst);
|
||||
}
|
||||
}
|
||||
/// `particles::around_self` about mob `id`.
|
||||
pub(super) fn particles_around_mob(
|
||||
@@ -315,7 +334,7 @@ impl Game<'_> {
|
||||
}
|
||||
// Villager.setLastHurtByMob: entity event 13.
|
||||
for id in angry {
|
||||
self.villager_particles(id, "angry_villager");
|
||||
self.mob_event_particles(id, 13);
|
||||
}
|
||||
}
|
||||
/// `Villager.tellWitnessesThatIWasMurdered`: the villagers that saw a
|
||||
@@ -370,7 +389,7 @@ impl Game<'_> {
|
||||
gossip::REPUTATION_CHANGE_PER_TRADE,
|
||||
);
|
||||
// Villager.customServerAiStep after a trade: entity event 14.
|
||||
self.villager_particles(id, "happy_villager");
|
||||
self.mob_event_particles(id, 14);
|
||||
}
|
||||
/// `Villager.getPlayerReputation` of the local player.
|
||||
pub(super) fn villager_reputation(&self, id: u32) -> i32 {
|
||||
|
||||
@@ -2,11 +2,53 @@
|
||||
//! its boss bar, and its skulls hitting and exploding.
|
||||
use super::Game;
|
||||
use horizon_client::{
|
||||
items::ItemStack,
|
||||
mobs::{Damage, DamageKind, Species, Who},
|
||||
projectiles::{Projectile, ProjectileKind},
|
||||
};
|
||||
use horizon_core::position::BlockPos;
|
||||
|
||||
impl Game<'_> {
|
||||
/// `LivingEntity.createWitherRose`: a mob a wither killed leaves a wither
|
||||
/// rose where it stood (with mobGriefing, on air that can hold it), else
|
||||
/// drops one.
|
||||
pub(super) fn create_wither_rose(&mut self, m: &horizon_client::mobs::Mob) {
|
||||
// getKillCredit: the player who last hurt it, else the last mob (kept
|
||||
// for 100 ticks).
|
||||
let by_wither = m.ai.last_hurt_by_player <= 0
|
||||
&& m.age as i32 - m.ai.last_hurt_by_time <= 100
|
||||
&& matches!(m.ai.last_hurt_by, Some(Who::Mob(id))
|
||||
if self.mobs.iter().any(|o| o.id == id && o.alive() && o.species() == Species::Wither));
|
||||
if !by_wither {
|
||||
return;
|
||||
}
|
||||
let pos = [
|
||||
m.position.x.floor() as i32,
|
||||
m.position.y.floor() as i32,
|
||||
m.position.z.floor() as i32,
|
||||
];
|
||||
let registry = self.pack.assets.registry;
|
||||
let rose = registry.default_state("minecraft:wither_rose");
|
||||
if self.ui.rules.bool("mob_griefing")
|
||||
&& let Some(rose) = rose
|
||||
&& self
|
||||
.res
|
||||
.facts()
|
||||
.is_air(self.world.block(pos[0], pos[1], pos[2]))
|
||||
&& self.with_level(|b, level, ticks| {
|
||||
b.can_survive(level, ticks, BlockPos::new(pos[0], pos[1], pos[2]), rose)
|
||||
})
|
||||
{
|
||||
let _ = self.level_set(pos, rose);
|
||||
return;
|
||||
}
|
||||
self.spawn_item(
|
||||
ItemStack::new("minecraft:wither_rose", 1),
|
||||
[m.position.x, m.position.y, m.position.z],
|
||||
super::dispenser::new_item_motion(),
|
||||
0,
|
||||
);
|
||||
}
|
||||
fn is_wither_skull(&self, p: [i32; 3]) -> bool {
|
||||
let name = &*self
|
||||
.res
|
||||
@@ -130,7 +172,10 @@ impl Game<'_> {
|
||||
if let Some(id) = owner {
|
||||
self.note_attacker("minecraft:explosion", id);
|
||||
}
|
||||
self.explode(at, 1.0)
|
||||
self.combat.explosion_owner = owner;
|
||||
let result = self.with_hive_emptying_blast(|g| g.explode(at, 1.0));
|
||||
self.combat.explosion_owner = None;
|
||||
result
|
||||
}
|
||||
}
|
||||
/// Wither skulls drawn as the skull model, blue when dangerous.
|
||||
|
||||
@@ -29,12 +29,22 @@ pub(crate) type State = HurtState<DamageTypeId>;
|
||||
pub struct HealthRules {
|
||||
pub difficulty: Difficulty,
|
||||
pub natural_regeneration: bool,
|
||||
/// The `drowning_damage`, `fall_damage`, `fire_damage` and
|
||||
/// `freeze_damage` rules `Player.isInvulnerableTo` reads.
|
||||
pub drowning_damage: bool,
|
||||
pub fall_damage: bool,
|
||||
pub fire_damage: bool,
|
||||
pub freeze_damage: bool,
|
||||
}
|
||||
impl Default for HealthRules {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
difficulty: Difficulty::Normal,
|
||||
natural_regeneration: true,
|
||||
drowning_damage: true,
|
||||
fall_damage: true,
|
||||
fire_damage: true,
|
||||
freeze_damage: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -170,6 +180,12 @@ pub struct PlayerHealth {
|
||||
pub hurt: State,
|
||||
/// Client hurt animation; fully blocked hits only refresh the server's hurt state.
|
||||
pub hurt_animation_time: i32,
|
||||
/// `Player.hurtDir` on a client: the yaw `ClientboundHurtAnimationPacket`
|
||||
/// gave, which `GameRenderer.bobHurt` tilts the camera around.
|
||||
pub hurt_dir: f32,
|
||||
/// `ServerPlayer.hurtDir` of a hit the player's client hasn't been told
|
||||
/// of yet (`indicateDamage`).
|
||||
pub indicated_dir: Option<f32>,
|
||||
pub dead: bool,
|
||||
pub sync_velocity: bool,
|
||||
pub game_time: i64,
|
||||
@@ -220,6 +236,8 @@ impl PlayerHealth {
|
||||
last_stamp: 0,
|
||||
},
|
||||
hurt_animation_time: 0,
|
||||
hurt_dir: 0.0,
|
||||
indicated_dir: None,
|
||||
dead: false,
|
||||
sync_velocity: false,
|
||||
game_time: 0,
|
||||
@@ -267,6 +285,18 @@ impl PlayerHealth {
|
||||
self.hurt.hurt_time = 10;
|
||||
self.hurt_animation_time = 10;
|
||||
}
|
||||
/// `LivingEntity.animateHurt(yaw)` on a player: the tilt restarts around
|
||||
/// `yaw` (`Player.animateHurt` keeps it as `hurtDir`).
|
||||
pub fn animate_hurt_dir(&mut self, yaw: f32) {
|
||||
self.animate_hurt();
|
||||
self.hurt_dir = yaw;
|
||||
}
|
||||
/// `ServerPlayer.indicateDamage`: the hit's direction relative to where
|
||||
/// the player looks, kept for the packet to its client.
|
||||
pub fn indicate_damage(&mut self, xd: f64, zd: f64, yaw: f32) {
|
||||
use horizon_core::geometry::trig::{RAD_TO_DEG, atan2};
|
||||
self.indicated_dir = Some((atan2(zd, xd) * f64::from(RAD_TO_DEG) - f64::from(yaw)) as f32);
|
||||
}
|
||||
/// `LocalPlayer.hurtTo` with `flashOnSetHealth`: a drop below the current
|
||||
/// health starts the hurt animation; `damageCooldownTime` (20 on a drop,
|
||||
/// 10 on a gain) is what lets `Hud.extractPlayerHealth` blink the hearts.
|
||||
@@ -370,6 +400,13 @@ impl PlayerMotion {
|
||||
if outcome.hurt {
|
||||
h.hurt_animation_time = h.hurt.hurt_time;
|
||||
}
|
||||
// `dealDefaultKnockback` ends in `indicateDamage` unless blocked: a
|
||||
// hit with no direction of its own (`xd` and `zd` zero) is sent as
|
||||
// the opposite of the player's yaw. A hit that has a direction
|
||||
// replaces this (`mob_hits_player`).
|
||||
if outcome.knockback && outcome.blocked <= 0.0 {
|
||||
h.indicate_damage(0.0, 0.0, self.yaw);
|
||||
}
|
||||
let after = h.health() + h.absorption();
|
||||
if self.hurt_log.len() >= HURT_LOG {
|
||||
self.hurt_log.remove(0);
|
||||
@@ -633,8 +670,13 @@ impl ImmunityWorld for Environment<'_> {
|
||||
fn enchantment_immunity(&mut self) -> io::Result<bool> {
|
||||
Ok(false)
|
||||
}
|
||||
fn damage_rule(&mut self, _: DamageRule) -> io::Result<bool> {
|
||||
Ok(true)
|
||||
fn damage_rule(&mut self, rule: DamageRule) -> io::Result<bool> {
|
||||
Ok(match rule {
|
||||
DamageRule::Drowning => self.rules.drowning_damage,
|
||||
DamageRule::Fall => self.rules.fall_damage,
|
||||
DamageRule::Fire => self.rules.fire_damage,
|
||||
DamageRule::Freeze => self.rules.freeze_damage,
|
||||
})
|
||||
}
|
||||
fn changing_dimension(&mut self) -> io::Result<bool> {
|
||||
Ok(false)
|
||||
|
||||
@@ -12,7 +12,7 @@ mod special;
|
||||
use crate::{
|
||||
block_entity_render::{ModelPart, diffuse},
|
||||
hud::Rect,
|
||||
mesher::Vertex,
|
||||
mesher::{CULL_BACK, Vertex},
|
||||
};
|
||||
use glam::{Mat3, Mat4, Vec3};
|
||||
use horizon_assets::{
|
||||
@@ -46,6 +46,8 @@ pub struct ItemQuad {
|
||||
pub foil: Foil,
|
||||
/// `MaterialInfo.lightEmission` (block light floor).
|
||||
pub light_emission: u8,
|
||||
/// The render type culls back faces (`entitySolid`): world drawing discards them.
|
||||
pub cull_back: bool,
|
||||
}
|
||||
/// Which glint render type a quad uses.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
@@ -246,6 +248,7 @@ fn submit_quads(
|
||||
color: argb(color),
|
||||
foil,
|
||||
light_emission: q.light_emission,
|
||||
cull_back: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -697,7 +700,7 @@ impl ItemSink for WorldSink<'_> {
|
||||
let overlay = if q.foil == Foil::None { 0 } else { 7 };
|
||||
for (p, uv) in q.pos.iter().zip(q.uv) {
|
||||
self.out.push(Vertex {
|
||||
normal: [0; 4],
|
||||
normal: if q.cull_back { CULL_BACK } else { [0; 4] },
|
||||
pos: p.to_array(),
|
||||
uv,
|
||||
layer: overlay,
|
||||
|
||||
@@ -358,6 +358,7 @@ mod tests {
|
||||
color,
|
||||
foil: Foil::None,
|
||||
light_emission: 0,
|
||||
cull_back: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -65,6 +65,17 @@ pub(super) fn load_parts(root: &Path) -> HashMap<String, ModelPart> {
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Marks every quad passed on as drawn with a back-face-culling render type (`entitySolid`).
|
||||
struct CullBack<'a>(&'a mut dyn ItemSink);
|
||||
impl ItemSink for CullBack<'_> {
|
||||
fn quad(&mut self, quad: ItemQuad) {
|
||||
self.0.quad(ItemQuad {
|
||||
cull_back: true,
|
||||
..quad
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// A pose override for a named part (`setupAnim`).
|
||||
type Adjust<'a> = &'a dyn Fn(&str, &mut [f32; 9]);
|
||||
fn none(_: &str, _: &mut [f32; 9]) {}
|
||||
@@ -119,6 +130,7 @@ fn draw(
|
||||
color,
|
||||
foil,
|
||||
light_emission: 0,
|
||||
cull_back: false,
|
||||
});
|
||||
}
|
||||
for (child_name, child) in &part.children {
|
||||
@@ -569,6 +581,8 @@ pub(super) fn submit(
|
||||
}
|
||||
SpecialKind::DecoratedPot => {
|
||||
let sides = pot_sides(argument);
|
||||
// `DecoratedPotRenderer` draws every part with `entitySolid`.
|
||||
let sink = &mut CullBack(sink);
|
||||
if let Some(base) = renderer.part("decorated_pot_base")
|
||||
&& let Some(r) = sprites
|
||||
.get("entity/decorated_pot/decorated_pot_base")
|
||||
|
||||
@@ -175,6 +175,9 @@ pub struct Hub {
|
||||
/// An integrated server's owner (`MinecraftServer.isSingleplayerOwner`),
|
||||
/// whose moves are never checked.
|
||||
pub singleplayer_owner: Option<u128>,
|
||||
/// The world is superflat (`ServerLevel.isFlat`, a world-wide flag, sent as
|
||||
/// `CommonPlayerSpawnInfo.isFlat` in every dimension).
|
||||
pub flat_world: bool,
|
||||
/// Who rides what, set by the game before each tick.
|
||||
pub riding: super::entity::Riding,
|
||||
/// The scoreboard's teams, set by the game each tick, for players'
|
||||
@@ -354,6 +357,7 @@ impl Hub {
|
||||
ticks: 0,
|
||||
movement_checks: (true, true),
|
||||
singleplayer_owner: None,
|
||||
flat_world: false,
|
||||
riding: Default::default(),
|
||||
last_clock: i64::MIN,
|
||||
last_rate: 0.0,
|
||||
@@ -595,7 +599,7 @@ impl Hub {
|
||||
game_type: game_mode,
|
||||
previous_game_type: None,
|
||||
debug: false,
|
||||
flat: false,
|
||||
flat: self.flat_world,
|
||||
last_death: None,
|
||||
portal_cooldown: 0,
|
||||
sea_level: 63,
|
||||
|
||||
@@ -288,6 +288,9 @@ pub struct Menu {
|
||||
pub player_sounds: Vec<&'static str>,
|
||||
/// Recipes whose result was taken (`awardUsedRecipes`), for the caller.
|
||||
pub crafted: Vec<String>,
|
||||
/// Potions taken from a brewing stand's bottle slots
|
||||
/// (`PotionSlot.onTake`), for the caller.
|
||||
pub brewed: Vec<ItemStack>,
|
||||
/// `LivingEntity.onEquipItem` calls that change the item: the
|
||||
/// `EquipmentSlot` name and the new stack, in order, for the caller.
|
||||
pub equipped: Vec<(&'static str, Option<ItemStack>)>,
|
||||
@@ -683,6 +686,7 @@ impl Menu {
|
||||
sounds: Vec::new(),
|
||||
player_sounds: Vec::new(),
|
||||
crafted: Vec::new(),
|
||||
brewed: Vec::new(),
|
||||
equipped: Vec::new(),
|
||||
merchant: None,
|
||||
stone: Stonecutter::default(),
|
||||
@@ -1504,7 +1508,17 @@ impl Menu {
|
||||
}
|
||||
|
||||
/// `ResultSlot.onTake` and the other `Slot.onTake` overrides.
|
||||
fn on_take(&mut self, env: &Env, s: usize) {
|
||||
fn on_take(&mut self, env: &Env, s: usize, taken: &ItemStack) {
|
||||
if self.slots[s].role == Role::Potion {
|
||||
// BrewingStandMenu.PotionSlot.onTake: a stack with potion contents.
|
||||
if matches!(
|
||||
&*taken.item,
|
||||
"minecraft:potion" | "minecraft:splash_potion" | "minecraft:lingering_potion"
|
||||
) {
|
||||
self.brewed.push(taken.clone());
|
||||
}
|
||||
return;
|
||||
}
|
||||
if self.slots[s].role == Role::MerchantResult {
|
||||
self.merchant_take(env);
|
||||
return;
|
||||
@@ -1671,7 +1685,7 @@ impl Menu {
|
||||
max_amount: u32,
|
||||
) -> Option<ItemStack> {
|
||||
let mut result = self.try_remove(env, s, amount, max_amount)?;
|
||||
self.on_take(env, s);
|
||||
self.on_take(env, s, &result);
|
||||
if self.slots[s].role == Role::CartoResult {
|
||||
Self::map_crafted(env, &mut result);
|
||||
}
|
||||
@@ -2346,7 +2360,7 @@ impl Menu {
|
||||
return None;
|
||||
}
|
||||
if after_take || matches!(self.kind, Kind::Inventory | Kind::Crafting) {
|
||||
self.on_take(env, index);
|
||||
self.on_take(env, index, &clicked);
|
||||
}
|
||||
// What the result slot's move left over is dropped.
|
||||
if (index == 0 && matches!(self.kind, Kind::Inventory | Kind::Crafting))
|
||||
@@ -2594,7 +2608,7 @@ impl Menu {
|
||||
};
|
||||
if let Some(mut taken) = self.try_remove(env, s, amount, u32::MAX) {
|
||||
self.carried = Some(taken.clone());
|
||||
self.on_take(env, s);
|
||||
self.on_take(env, s, &taken);
|
||||
if self.slots[s].role == Role::CartoResult {
|
||||
// onTake's onCraftedBy edits the carried stack.
|
||||
Self::map_crafted(env, &mut taken);
|
||||
@@ -2628,7 +2642,7 @@ impl Menu {
|
||||
if let Some(c) = self.carried.as_mut() {
|
||||
c.count += taken.count;
|
||||
}
|
||||
self.on_take(env, s);
|
||||
self.on_take(env, s, &taken);
|
||||
if self.slots[s].role == Role::CartoResult {
|
||||
// onCraftedBy edits the taken stack, not the carried one.
|
||||
Self::map_crafted(env, &mut taken);
|
||||
@@ -2656,7 +2670,7 @@ impl Menu {
|
||||
if self.may_pickup(env, target) {
|
||||
self.containers[PLAYER][inv_slot] = Some(taken.clone());
|
||||
self.set_by_player(env, target, None);
|
||||
self.on_take(env, target);
|
||||
self.on_take(env, target, &taken);
|
||||
if self.slots[target].role == Role::CartoResult
|
||||
&& let Some(stack) = self.containers[PLAYER][inv_slot].as_mut()
|
||||
{
|
||||
@@ -2684,14 +2698,14 @@ impl Menu {
|
||||
let part = split(&mut source, max);
|
||||
self.containers[PLAYER][inv_slot] = Some(source);
|
||||
self.set_by_player(env, target, Some(part));
|
||||
self.on_take(env, target);
|
||||
self.on_take(env, target, &taken);
|
||||
if !self.inventory_add(env, &mut taken) {
|
||||
self.drop_stack(&taken);
|
||||
}
|
||||
} else {
|
||||
self.containers[PLAYER][inv_slot] = Some(taken);
|
||||
self.containers[PLAYER][inv_slot] = Some(taken.clone());
|
||||
self.set_by_player(env, target, Some(source));
|
||||
self.on_take(env, target);
|
||||
self.on_take(env, target, &taken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,9 +36,13 @@ pub struct Vertex {
|
||||
pub color: u32,
|
||||
/// Smooth light, 16x fixed point: sky in bits 0..8, block in bits 8..16.
|
||||
pub light: u32,
|
||||
/// RGBA8_SNORM face normal; w = -127 for two-sided lighting, 0 to keep baked/unlit colour.
|
||||
/// RGBA8_SNORM face normal; w = -127 for two-sided lighting, 0 to keep baked/unlit colour,
|
||||
/// [`CULL_BACK`] to keep it and also drop back-facing pixels.
|
||||
pub normal: [i8; 4],
|
||||
}
|
||||
/// `Vertex::normal` of a baked-colour quad of an `entitySolid` model: the render type culls
|
||||
/// back faces, which the entity pipelines here do not, so `entity.wgsl` discards them.
|
||||
pub const CULL_BACK: [i8; 4] = [0, 0, 0, 1];
|
||||
/// A section vertex: vanilla's `DefaultVertexFormat.BLOCK` (position, colour,
|
||||
/// UV0, UV2) with the sprite's array layer beside the light, in 24 bytes
|
||||
/// rather than vanilla's 28: the UV is fixed point, which holds model UVs
|
||||
|
||||
@@ -926,6 +926,10 @@ pub enum MobEvent {
|
||||
slot: usize,
|
||||
stack: Option<crate::items::ItemStack>,
|
||||
},
|
||||
/// `InfestedMobEffect.onMobHurt`: the mob was hurt while infested.
|
||||
Infested {
|
||||
mob: u32,
|
||||
},
|
||||
/// `OfferFlowerGoal.stop`: the item goes to the target's antenna (saddle)
|
||||
/// slot if it is empty, as a guaranteed drop.
|
||||
Gift {
|
||||
@@ -1003,7 +1007,9 @@ pub enum MobEvent {
|
||||
mob: u32,
|
||||
charged: bool,
|
||||
},
|
||||
Explode([f64; 3], f32),
|
||||
/// The centre, the radius and the kind of the mob blowing up (it may be
|
||||
/// gone from the list by the time the blast is handled).
|
||||
Explode([f64; 3], f32, Species),
|
||||
/// Melee or ranged damage to another mob.
|
||||
AttackMob {
|
||||
target: u32,
|
||||
@@ -1067,8 +1073,11 @@ pub enum MobEvent {
|
||||
at: [f64; 3],
|
||||
count: u32,
|
||||
},
|
||||
/// Client particles about a mob's box (`particles::around_self`).
|
||||
/// Client particles about a mob's box (`particles::around_self`) and the
|
||||
/// entity event `event` that shows them, sent for mob `mob`.
|
||||
AroundSelf {
|
||||
mob: u32,
|
||||
event: i8,
|
||||
kind: &'static str,
|
||||
feet: [f64; 3],
|
||||
width: f64,
|
||||
@@ -1196,6 +1205,12 @@ pub enum MobEvent {
|
||||
table: &'static str,
|
||||
at: [f64; 3],
|
||||
},
|
||||
/// `Armadillo.customServerAiStep`: the armadillo sheds a scute.
|
||||
ShedScute {
|
||||
mob: u32,
|
||||
at: [f64; 3],
|
||||
pitch: f32,
|
||||
},
|
||||
/// A lead snaps or loses its holder: the lead item drops when asked.
|
||||
LeashBreak {
|
||||
mob: u32,
|
||||
@@ -1300,6 +1315,8 @@ pub struct Seen {
|
||||
pub active_raid: bool,
|
||||
/// A copper golem's `openedChestPos` (`ContainerUser.hasContainerOpen`).
|
||||
pub opened_chest: Option<[i32; 3]>,
|
||||
/// `isPassenger`.
|
||||
pub passenger: bool,
|
||||
/// A villager's reputation of the player (`getPlayerReputation`).
|
||||
pub player_rep: i32,
|
||||
/// `isPushable` and pushed by others (`Entity.push(Entity)` moves it).
|
||||
@@ -1387,6 +1404,7 @@ impl Mob {
|
||||
hurt_by: m.ai.last_hurt_by.map(|w| (w, m.ai.last_hurt_by_time)),
|
||||
active_raid: raider::has_active_raid(m),
|
||||
opened_chest: m.extra.opened_chest,
|
||||
passenger: m.extra.mount.is_some(),
|
||||
player_rep: match (villager, player) {
|
||||
(true, Some(uuid)) => villager::ext(m).map_or(0, |e| e.gossips.reputation(uuid)),
|
||||
_ => 0,
|
||||
@@ -1545,6 +1563,8 @@ pub struct PlayerView {
|
||||
pub off_hand: Option<Arc<str>>,
|
||||
pub head: Option<Arc<str>>,
|
||||
pub armor_cover: f32,
|
||||
/// The Invisibility effect (`isInvisible`).
|
||||
pub invisible: bool,
|
||||
pub spectator: bool,
|
||||
/// `PiglinAi.isWearingSafeArmor`: some golden armour.
|
||||
pub gold_armor: bool,
|
||||
@@ -1566,8 +1586,21 @@ pub struct PlayerView {
|
||||
/// A LAN guest: its own client moves it, and touching mobs push it there
|
||||
/// (`EntitySelector.pushableBy` on the client).
|
||||
pub remote: bool,
|
||||
/// `isPassenger`.
|
||||
pub passenger: bool,
|
||||
}
|
||||
impl PlayerView {
|
||||
/// `LivingEntity.getVisibilityPercent` without the worn-skull scaling.
|
||||
pub fn visibility_percent(&self) -> f64 {
|
||||
let mut visibility = 1.0;
|
||||
if self.sneaking {
|
||||
visibility *= 0.8;
|
||||
}
|
||||
if self.invisible {
|
||||
visibility *= 0.7 * f64::from(self.armor_cover).max(0.1);
|
||||
}
|
||||
visibility
|
||||
}
|
||||
/// `LivingEntity.hasEffect`, by id without namespace.
|
||||
pub fn has_effect(&self, effect: &str) -> bool {
|
||||
self.effects.contains(&effect)
|
||||
@@ -1600,6 +1633,8 @@ pub struct MobWorld<'a> {
|
||||
pub biomes: &'a crate::biome::Biomes,
|
||||
/// The `mob_griefing` game rule.
|
||||
pub mob_griefing: bool,
|
||||
/// The `mob_drops` game rule (`shouldDropLoot`).
|
||||
pub mob_drops: bool,
|
||||
/// `getCurrentDifficultyAt` near the player.
|
||||
pub difficulty: spawning::LocalDifficulty,
|
||||
/// The End (its dimension type's monster spawn light rules).
|
||||
@@ -1887,7 +1922,7 @@ impl Mob {
|
||||
let dead = !self.alive();
|
||||
let sound = ai::voice_sounds(self)[if dead { 2 } else { 1 }];
|
||||
if !dead {
|
||||
self.ambient_timer = -self.kind.ambient_interval;
|
||||
self.ambient_timer = -self.ambient_interval();
|
||||
}
|
||||
if !sound.is_empty() {
|
||||
let pitch = self.voice_pitch();
|
||||
@@ -1898,6 +1933,9 @@ impl Mob {
|
||||
}
|
||||
}
|
||||
}
|
||||
if self.has_effect("minecraft:infested") {
|
||||
self.outbox.push(MobEvent::Infested { mob: self.id });
|
||||
}
|
||||
// Squid.hurtServer: a squid hurt after a living entity hit it squirts ink.
|
||||
if matches!(self.species(), Species::Squid | Species::GlowSquid)
|
||||
&& self.ai.last_hurt_by.is_some()
|
||||
@@ -1970,14 +2008,14 @@ impl Mob {
|
||||
}
|
||||
pub fn add_effect(&mut self, effect: &'static str, ticks: i32, amplifier: i32) {
|
||||
if let Some(e) = self.extra.effects.iter_mut().find(|e| e.0 == effect) {
|
||||
// MobEffectInstance.update: a stronger effect replaces the old one
|
||||
// with its own duration, an equal one keeps the longer duration,
|
||||
// and a weaker one never changes the active effect.
|
||||
// MobEffectInstance.update: a stronger effect replaces with its
|
||||
// own duration, an equal one only extends it; a weaker one is
|
||||
// ignored (vanilla keeps it hidden behind the active one).
|
||||
if amplifier > e.2 {
|
||||
e.1 = ticks;
|
||||
e.2 = amplifier;
|
||||
} else if amplifier == e.2 {
|
||||
e.1 = e.1.max(ticks);
|
||||
} else if amplifier == e.2 && e.1 != -1 && (ticks == -1 || e.1 < ticks) {
|
||||
e.1 = ticks;
|
||||
}
|
||||
} else {
|
||||
self.extra.effects.push((effect, ticks, amplifier));
|
||||
@@ -1997,6 +2035,16 @@ impl Mob {
|
||||
let at = [self.position.x, self.eye_y(), self.position.z];
|
||||
events.push(MobEvent::Sound(event, at, 1.0, 1.0));
|
||||
}
|
||||
/// `Mob.getAmbientSoundInterval`; `HappyGhast` waits six times as long
|
||||
/// while it carries a passenger.
|
||||
pub fn ambient_interval(&self) -> i32 {
|
||||
let ridden = self.rider.is_some() || self.extra.rider.is_some();
|
||||
if self.species() == Species::HappyGhast && ridden {
|
||||
self.kind.ambient_interval * 6
|
||||
} else {
|
||||
self.kind.ambient_interval
|
||||
}
|
||||
}
|
||||
/// LivingEntity.getVoicePitch.
|
||||
pub fn voice_pitch(&mut self) -> f32 {
|
||||
let pitch = (self.random.next_float() - self.random.next_float()) * 0.2
|
||||
|
||||
@@ -185,6 +185,18 @@ pub fn register(m: &mut Mob) {
|
||||
if m.species() == Species::Rabbit {
|
||||
super::rabbit::register(m);
|
||||
}
|
||||
if m.species() == Species::Frog {
|
||||
// `Frog()`: SmoothSwimmingMoveControl(85, 10, 0.02, 0.1, true).
|
||||
// The speed attribute is 1.0, so the controller's scaling is
|
||||
// what keeps a frog at a walking pace on land.
|
||||
m.ai.mov.kind = super::control::MoveKind::SmoothSwimming {
|
||||
max_turn_x: 85.0,
|
||||
max_turn_y: 10.0,
|
||||
in_water: 0.02,
|
||||
outside: 0.1,
|
||||
gravity: true,
|
||||
};
|
||||
}
|
||||
if m.species() == Species::Turtle {
|
||||
super::turtle::register(m);
|
||||
}
|
||||
@@ -307,12 +319,30 @@ fn generic(m: &mut Mob) {
|
||||
m.ai.targets.add(1, HurtByTarget::new());
|
||||
m.ai.targets.add(2, NearestTarget::player(true));
|
||||
} else {
|
||||
if m.kind.species == Species::Goat {
|
||||
// GoatAi's idle and core behaviours (the ram and long jump
|
||||
// activities are not here): panic 2.0, AnimalMakeLove, tempting
|
||||
// with goat_food and baby follow at 1.25, then stroll.
|
||||
g.add(0, Float);
|
||||
g.add(1, Panic::new(2.0));
|
||||
g.add(2, Breed::new(1.0));
|
||||
g.add(3, Tempt::new(1.25, m.kind.food.clone(), false));
|
||||
g.add(4, FollowParent::new(1.25));
|
||||
g.add(5, Stroll::avoiding_water(1.0));
|
||||
g.add(6, LookAtPlayer::new(6.0));
|
||||
g.add(7, RandomLookAround::default());
|
||||
return;
|
||||
}
|
||||
g.add(0, Float);
|
||||
let rabbit = m.kind.species == Species::Rabbit;
|
||||
g.add(1, Panic::new(if rabbit { 2.2 } else { 1.25 }));
|
||||
g.add(5, Stroll::avoiding_water(if rabbit { 0.6 } else { 1.0 }));
|
||||
g.add(6, LookAtPlayer::new(6.0));
|
||||
g.add(7, RandomLookAround::default());
|
||||
if m.kind.species == Species::Armadillo {
|
||||
// Armadillo's constructor: pickNextScuteDropTime.
|
||||
m.extra.egg_time = next_scute_time(m);
|
||||
}
|
||||
}
|
||||
}
|
||||
/// Subclasses of `net.minecraft.world.entity.monster.Monster`.
|
||||
@@ -584,7 +614,7 @@ fn base_tick(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
|
||||
let t = m.ambient_timer;
|
||||
m.ambient_timer += 1;
|
||||
if roll < t {
|
||||
m.ambient_timer = -m.kind.ambient_interval;
|
||||
m.ambient_timer = -m.ambient_interval();
|
||||
play_ambient(m, w, events);
|
||||
}
|
||||
}
|
||||
@@ -978,9 +1008,31 @@ fn server_ai_step(
|
||||
}
|
||||
m.jump_control_tick();
|
||||
}
|
||||
/// `Armadillo.pickNextScuteDropTime`: 5 to 10 minutes.
|
||||
fn next_scute_time(m: &mut Mob) -> i32 {
|
||||
m.random.next_int_bound(20 * 60 * 5).unwrap_or(0) + 20 * 60 * 5
|
||||
}
|
||||
/// `Armadillo.customServerAiStep`: the scute timer keeps counting down and is
|
||||
/// only reset once `shouldDropLoot` (not a baby, `mob_drops` on) lets it shed.
|
||||
fn armadillo_server_ai_step(m: &mut Mob, mob_drops: bool, events: &mut Vec<MobEvent>) {
|
||||
if !m.alive() {
|
||||
return;
|
||||
}
|
||||
m.extra.egg_time -= 1;
|
||||
if m.extra.egg_time <= 0 && !m.is_baby() && mob_drops {
|
||||
let pitch = (m.random.next_float() - m.random.next_float()) * 0.2 + 1.0;
|
||||
events.push(MobEvent::ShedScute {
|
||||
mob: m.id,
|
||||
at: [m.position.x, m.position.y, m.position.z],
|
||||
pitch,
|
||||
});
|
||||
m.extra.egg_time = next_scute_time(m);
|
||||
}
|
||||
}
|
||||
fn custom_server_ai_step(m: &mut Mob, cx: &mut Cx) {
|
||||
match m.species() {
|
||||
Species::Rabbit => super::rabbit::server_ai_step(m),
|
||||
Species::Armadillo => armadillo_server_ai_step(m, cx.w.mob_drops, cx.events),
|
||||
Species::Sheep => {}
|
||||
Species::Zombie
|
||||
| Species::Husk
|
||||
@@ -1580,25 +1632,31 @@ fn tick_effects(m: &mut Mob) {
|
||||
let mut effects = std::mem::take(&mut m.extra.effects);
|
||||
for (effect, ticks, amp) in &mut effects {
|
||||
let interval = |base: i32| (base >> (*amp).max(0)).max(1);
|
||||
// MobEffectInstance.tickServer: an infinite (-1) effect times its
|
||||
// ticks by the mob's tickCount and never counts down.
|
||||
let infinite = *ticks == -1;
|
||||
let count = if infinite { m.age as i32 } else { *ticks };
|
||||
match *effect {
|
||||
"minecraft:poison"
|
||||
if *ticks % interval(25) == 0 && !m.kind.flags.undead && m.health > 1.0 =>
|
||||
if count % interval(25) == 0 && !m.kind.flags.undead && m.health > 1.0 =>
|
||||
{
|
||||
m.damage(1.0, Damage::of(DamageKind::Magic));
|
||||
}
|
||||
"minecraft:wither" if *ticks % interval(40) == 0 => {
|
||||
"minecraft:wither" if count % interval(40) == 0 => {
|
||||
m.damage(1.0, Damage::of(DamageKind::Magic));
|
||||
}
|
||||
"minecraft:regeneration"
|
||||
if *ticks % interval(50) == 0 && !m.kind.flags.undead && m.alive() =>
|
||||
if count % interval(50) == 0 && !m.kind.flags.undead && m.alive() =>
|
||||
{
|
||||
m.health = (m.health + 1.0).min(m.attrs.max_health);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
*ticks -= 1;
|
||||
if !infinite {
|
||||
*ticks -= 1;
|
||||
}
|
||||
}
|
||||
effects.retain(|e| e.1 > 0);
|
||||
effects.retain(|e| e.1 > 0 || e.1 == -1);
|
||||
m.extra
|
||||
.hidden_effects
|
||||
.retain(|h| effects.iter().any(|e| e.0 == *h));
|
||||
|
||||
@@ -625,8 +625,7 @@ fn targetable(m: &mut Mob, w: &MobWorld, who: Who) -> bool {
|
||||
// TargetingConditions.forNonCombat(): in range (scaled by the
|
||||
// player's visibility, at least 2) and in sight.
|
||||
let Some(p) = &w.player else { return false };
|
||||
let visibility = if p.sneaking { 0.8 } else { 1.0 };
|
||||
let r = (range * visibility).max(2.0);
|
||||
let r = (range * p.visibility_percent()).max(2.0);
|
||||
p.alive && !p.spectator && m.distance_sqr(p.position) <= r * r && m.sees(w, who)
|
||||
}
|
||||
Who::Mob(id) => {
|
||||
|
||||
@@ -323,12 +323,19 @@ pub fn sting(m: &mut Mob, who: Who, cx: &mut Cx) {
|
||||
match who {
|
||||
Who::Player => {
|
||||
cx.events.push(MobEvent::AttackPlayer(amount, from));
|
||||
let seconds = if cx.w.difficulty.hard { 18 } else { 10 };
|
||||
cx.events.push(MobEvent::EffectPlayer {
|
||||
effect: "minecraft:poison",
|
||||
ticks: seconds * 20,
|
||||
amplifier: 0,
|
||||
});
|
||||
// Poison only on normal (10 s) and hard (18 s).
|
||||
let seconds = match cx.w.difficulty.id {
|
||||
2 => 10,
|
||||
3 => 18,
|
||||
_ => 0,
|
||||
};
|
||||
if seconds > 0 {
|
||||
cx.events.push(MobEvent::EffectPlayer {
|
||||
effect: "minecraft:poison",
|
||||
ticks: seconds * 20,
|
||||
amplifier: 0,
|
||||
});
|
||||
}
|
||||
}
|
||||
Who::Mob(id) => cx.events.push(MobEvent::AttackMob {
|
||||
target: id,
|
||||
@@ -421,10 +428,10 @@ pub fn drop_off_nectar(m: &mut Mob) {
|
||||
set_has_nectar(m, false);
|
||||
st(m).crops_grown = 0;
|
||||
}
|
||||
/// `Bee.setStayOutOfHiveCountdown`, which in 26.3 only resets the time
|
||||
/// without nectar.
|
||||
/// `Bee.setStayOutOfHiveCountdown`: the bee will not enter a hive for 400
|
||||
/// ticks (the hive passes that when a sedated hive lets its bees out).
|
||||
pub fn set_stay_out_of_hive_countdown(m: &mut Mob) {
|
||||
st(m).ticks_without_nectar = 0;
|
||||
st(m).stay_out_of_hive = 400;
|
||||
}
|
||||
fn drop_hive(m: &mut Mob) {
|
||||
let b = st(m);
|
||||
|
||||
@@ -24,12 +24,13 @@ pub fn register(m: &mut Mob) {
|
||||
m.extra.tame = true;
|
||||
let tempt = m.kind.tempt.clone();
|
||||
let g = &mut m.ai.goals;
|
||||
// CamelAi speed modifiers (times the 0.09 movement speed attribute).
|
||||
g.add(0, Float);
|
||||
g.add(1, CamelPanic(Panic::new(4.0 * 0.25)));
|
||||
g.add(1, CamelPanic(Panic::new(4.0)));
|
||||
g.add(2, Breed::new(1.0));
|
||||
g.add(3, Tempt::new(2.5 * 0.25, tempt, false));
|
||||
g.add(4, FollowParent::new(2.5 * 0.25));
|
||||
g.add(5, Stroll::new(2.0 * 0.25));
|
||||
g.add(3, Tempt::new(2.5, tempt, false));
|
||||
g.add(4, FollowParent::new(2.5));
|
||||
g.add(5, Stroll::new(2.0));
|
||||
g.add(5, RandomSitting);
|
||||
g.add(6, LookAtPlayer::new(6.0));
|
||||
g.add(7, RandomLookAround::default());
|
||||
|
||||
@@ -403,6 +403,15 @@ pub fn die(m: &mut Mob, d: &Death, sequences: &mut RandomSequences) -> (Vec<Drop
|
||||
out.push(Drop::Item(stack));
|
||||
clear_slot(m, "mainhand");
|
||||
}
|
||||
// Allay: what it carries (`ints[1]` of the held item) is its inventory.
|
||||
let allay_load = (s == Species::Allay)
|
||||
.then(|| {
|
||||
m.extra
|
||||
.main_hand
|
||||
.clone()
|
||||
.map(|item| (item, m.extra.ints[1]))
|
||||
})
|
||||
.flatten();
|
||||
let drops_loot = d.mob_drops && (is_monster(s) || !m.is_baby());
|
||||
if drops_loot {
|
||||
let table = format!(
|
||||
@@ -459,6 +468,19 @@ pub fn die(m: &mut Mob, d: &Death, sequences: &mut RandomSequences) -> (Vec<Drop
|
||||
out.push(Drop::Item(loot_stack("minecraft:nether_star", 1)));
|
||||
}
|
||||
}
|
||||
// Allay.dropEquipment: its inventory, then the main-hand item unless it
|
||||
// prevents equipment drops.
|
||||
if let Some((item, carried)) = allay_load {
|
||||
if carried > 0 {
|
||||
out.push(Drop::Item(loot_stack(&item, carried)));
|
||||
}
|
||||
if let Some(stack) = slot_item(m, "mainhand")
|
||||
&& !d.loot.prevents_equipment_drop(&stack)
|
||||
{
|
||||
out.push(Drop::Item(stack));
|
||||
clear_slot(m, "mainhand");
|
||||
}
|
||||
}
|
||||
// Piglin.dropCustomDeathLoot: everything in its inventory.
|
||||
if s == Species::Piglin {
|
||||
for stack in m.extra.inventory.drain(..) {
|
||||
|
||||
@@ -588,24 +588,38 @@ impl Mob {
|
||||
if p.creative || p.allies.contains(&self.id) {
|
||||
return false;
|
||||
}
|
||||
self.player_in_range(w, range, check_sight)
|
||||
self.player_in_range(w, range, check_sight, true)
|
||||
}
|
||||
/// forCombat().ignoreInvisibilityTesting() for the player: the check for
|
||||
/// a target the mob already has, which ignores the visibility scaling.
|
||||
pub fn can_keep_target_player(&mut self, w: &MobWorld, range: f64) -> bool {
|
||||
let Some(p) = &w.player else { return false };
|
||||
if p.creative || p.allies.contains(&self.id) {
|
||||
return false;
|
||||
}
|
||||
self.player_in_range(w, range, true, false)
|
||||
}
|
||||
/// TargetingConditions.forNonCombat().range(range).test for the player
|
||||
/// (seen by anyone, within range scaled by visibility, in sight).
|
||||
pub fn can_see_player(&mut self, w: &MobWorld, range: f64) -> bool {
|
||||
self.player_in_range(w, range, true)
|
||||
self.player_in_range(w, range, true, true)
|
||||
}
|
||||
fn player_in_range(&mut self, w: &MobWorld, range: f64, check_sight: bool) -> bool {
|
||||
/// `scale` is `TargetingConditions.testInvisible`: scale the range by
|
||||
/// the player's visibility.
|
||||
fn player_in_range(
|
||||
&mut self,
|
||||
w: &MobWorld,
|
||||
range: f64,
|
||||
check_sight: bool,
|
||||
scale: bool,
|
||||
) -> bool {
|
||||
let Some(p) = &w.player else { return false };
|
||||
if !p.alive || p.spectator {
|
||||
return false;
|
||||
}
|
||||
// LivingEntity.getVisibilityPercent
|
||||
let mut visibility = 1.0;
|
||||
if p.sneaking {
|
||||
visibility *= 0.8;
|
||||
}
|
||||
if let Some(head) = &p.head {
|
||||
let mut visibility = if scale { p.visibility_percent() } else { 1.0 };
|
||||
if let Some(head) = p.head.as_ref().filter(|_| scale) {
|
||||
let skull = match self.species() {
|
||||
Species::Zombie | Species::Husk | Species::Drowned | Species::ZombieVillager => {
|
||||
"minecraft:zombie_head"
|
||||
|
||||
@@ -364,8 +364,7 @@ impl Goal for GhastTempt {
|
||||
let Some(p) = &cx.w.player else { return false };
|
||||
// getNearestPlayer(TargetingConditions.forNonCombat()
|
||||
// .ignoreLineOfSight().range(TEMPT_RANGE 16)): creative players too.
|
||||
let visibility = if p.sneaking { 0.8 } else { 1.0 };
|
||||
let range = (16.0_f64 * visibility).max(2.0);
|
||||
let range = (16.0_f64 * p.visibility_percent()).max(2.0);
|
||||
p.alive
|
||||
&& !p.spectator
|
||||
&& (Self::wants(m, &p.main_hand) || Self::wants(m, &p.off_hand))
|
||||
|
||||
@@ -184,6 +184,7 @@ pub fn creeper_tick(m: &mut Mob, events: &mut Vec<MobEvent>) {
|
||||
events.push(MobEvent::Explode(
|
||||
[m.position.x, m.position.y, m.position.z],
|
||||
radius,
|
||||
m.species(),
|
||||
));
|
||||
m.removed = true;
|
||||
}
|
||||
|
||||
@@ -629,7 +629,11 @@ impl Mob {
|
||||
return;
|
||||
}
|
||||
let power = self.fall_distance + 1.0e-6 - self.kind.safe_fall_distance;
|
||||
let damage = (power * self.kind.fall_damage_multiplier).floor();
|
||||
let mut damage = (power * self.kind.fall_damage_multiplier).floor();
|
||||
// Frog.calculateFallDamage: five points less than the base damage.
|
||||
if self.species() == super::Species::Frog {
|
||||
damage -= 5.0;
|
||||
}
|
||||
if damage > 0.0 {
|
||||
let at = [self.position.x, self.position.y, self.position.z];
|
||||
let sound = if damage > 4.0 {
|
||||
|
||||
@@ -359,11 +359,14 @@ fn can_attack(m: &Mob, w: &MobWorld, who: Who) -> bool {
|
||||
/// `Sensor.isEntityAttackable`: `TargetingConditions.forCombat()` within the
|
||||
/// follow range, in sight.
|
||||
fn attackable(m: &mut Mob, w: &MobWorld, who: Who) -> bool {
|
||||
// The current ATTACK_TARGET is tested with ignoreInvisibilityTesting.
|
||||
let current = mem_ref(m).attack_target.value() == Some(who);
|
||||
let range = m.attrs.follow_range;
|
||||
if !can_attack(m, w, who) {
|
||||
return false;
|
||||
}
|
||||
match who {
|
||||
Who::Player if current => m.can_keep_target_player(w, range),
|
||||
Who::Player => m.can_target_player(w, range, true),
|
||||
Who::Mob(id) => {
|
||||
let Some(s) = w.seen(id) else { return false };
|
||||
@@ -1137,6 +1140,7 @@ struct Quarry {
|
||||
position: Vec3,
|
||||
head_yaw: f32,
|
||||
height: f64,
|
||||
passenger: bool,
|
||||
}
|
||||
fn quarry(w: &MobWorld, who: Who) -> Option<Quarry> {
|
||||
let t = w.target_info(who)?;
|
||||
@@ -1148,6 +1152,7 @@ fn quarry(w: &MobWorld, who: Who) -> Option<Quarry> {
|
||||
position: t.position,
|
||||
head_yaw,
|
||||
height: t.bounds.max_position().y - t.bounds.min_position().y,
|
||||
passenger: t.passenger,
|
||||
})
|
||||
}
|
||||
/// `BreezeUtil.randomPointBehindTarget`.
|
||||
@@ -1233,7 +1238,8 @@ fn shoot_tick(m: &mut Mob, cx: &mut Bx) {
|
||||
let firing = super::breeze::firing_y(m);
|
||||
let (xd, yd, zd) = (
|
||||
q.position.x - m.position.x,
|
||||
q.position.y + q.height * 0.3 - firing,
|
||||
// target.getY(target.isPassenger() ? 0.8 : 0.3).
|
||||
q.position.y + q.height * if q.passenger { 0.8 } else { 0.3 } - firing,
|
||||
q.position.z - m.position.z,
|
||||
);
|
||||
let start = Vec3::new(m.position.x, firing, m.position.z);
|
||||
@@ -1242,14 +1248,19 @@ fn shoot_tick(m: &mut Mob, cx: &mut Bx) {
|
||||
start,
|
||||
Some(Who::Mob(m.id)),
|
||||
);
|
||||
// The new entity's own random spreads the shot (5 - difficulty * 4 at
|
||||
// normal): not the breeze's.
|
||||
// The new entity's own random spreads the shot (5 - difficulty id * 4):
|
||||
// not the breeze's.
|
||||
let mut own = LegacyRandom::new(
|
||||
cx.now
|
||||
.wrapping_mul(0x5DEE_CE66)
|
||||
.wrapping_add(i64::from(m.id)),
|
||||
);
|
||||
p.shoot(&mut own, [xd, yd, zd], 0.7, -3.0);
|
||||
p.shoot(
|
||||
&mut own,
|
||||
[xd, yd, zd],
|
||||
0.7,
|
||||
5.0 - f32::from(cx.w.difficulty.id) * 4.0,
|
||||
);
|
||||
cx.events.push(MobEvent::Projectile(p));
|
||||
breeze_sound(m, cx, "entity.breeze.shoot", 1.5);
|
||||
}
|
||||
|
||||
@@ -39,6 +39,8 @@ pub struct LocalDifficulty {
|
||||
pub normal: bool,
|
||||
/// The world difficulty is hard.
|
||||
pub hard: bool,
|
||||
/// `Difficulty.getId`: 0 peaceful to 3 hard.
|
||||
pub id: u8,
|
||||
}
|
||||
/// `DimensionType.MOON_BRIGHTNESS_PER_PHASE`.
|
||||
pub const MOON_BRIGHTNESS: [f32; 8] = [1.0, 0.75, 0.5, 0.25, 0.0, 0.25, 0.5, 0.75];
|
||||
@@ -53,6 +55,7 @@ impl LocalDifficulty {
|
||||
effective: 0.0,
|
||||
normal,
|
||||
hard,
|
||||
id: base,
|
||||
};
|
||||
}
|
||||
let global = ((total as f32 - 72000.0) / 1_440_000.0).clamp(0.0, 1.0) * 0.25;
|
||||
@@ -66,6 +69,7 @@ impl LocalDifficulty {
|
||||
effective: f32::from(base) * (0.75 + global + local),
|
||||
normal,
|
||||
hard,
|
||||
id: base,
|
||||
}
|
||||
}
|
||||
/// `getSpecialMultiplier`.
|
||||
|
||||
@@ -1447,7 +1447,6 @@ impl Def {
|
||||
| S::IronGolem
|
||||
| S::Cat
|
||||
| S::Ocelot
|
||||
| S::Frog
|
||||
| S::Slime
|
||||
| S::MagmaCube
|
||||
| S::Wither
|
||||
@@ -1581,7 +1580,7 @@ impl Def {
|
||||
S::Bee => "bee_food",
|
||||
S::Turtle => "turtle_food",
|
||||
S::Armadillo => "armadillo_food",
|
||||
S::Frog => "frog_food",
|
||||
S::Frog | S::Tadpole => "frog_food",
|
||||
S::Axolotl => "axolotl_food",
|
||||
S::Hoglin => "hoglin_food",
|
||||
S::Strider => "strider_food",
|
||||
@@ -1658,6 +1657,12 @@ impl Def {
|
||||
| S::Camel
|
||||
| S::CamelHusk => 400,
|
||||
S::Ocelot => 900,
|
||||
// Guardian.getAmbientSoundInterval (the elder too).
|
||||
S::Guardian | S::ElderGuardian => 160,
|
||||
// Hoglin extends Animal; Shulker extends AbstractGolem.
|
||||
S::Hoglin | S::Shulker => 120,
|
||||
// Allay is a PathfinderMob: the Mob default.
|
||||
S::Allay => 80,
|
||||
S::Squid
|
||||
| S::GlowSquid
|
||||
| S::Cod
|
||||
|
||||
@@ -370,6 +370,7 @@ pub fn ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
|
||||
events.push(MobEvent::Explode(
|
||||
[m.position.x, m.position.y + 0.0625, m.position.z],
|
||||
power,
|
||||
m.species(),
|
||||
));
|
||||
m.removed = true;
|
||||
return;
|
||||
|
||||
@@ -2918,11 +2918,18 @@ impl B {
|
||||
let mut bodies = Vec::new();
|
||||
if let Some(t) = cx.w.target_info(target) {
|
||||
let (min, max) = (t.bounds.min_position(), t.bounds.max_position());
|
||||
bodies.push((t.position, max.x - min.x, max.y - min.y));
|
||||
bodies.push((partner, t.position, max.x - min.x, max.y - min.y));
|
||||
}
|
||||
bodies.push((m.position, f64::from(m.width()), f64::from(m.height())));
|
||||
for (feet, width, height) in bodies {
|
||||
bodies.push((
|
||||
m.id,
|
||||
m.position,
|
||||
f64::from(m.width()),
|
||||
f64::from(m.height()),
|
||||
));
|
||||
for (mob, feet, width, height) in bodies {
|
||||
cx.events.push(MobEvent::AroundSelf {
|
||||
mob,
|
||||
event: 12,
|
||||
kind: "heart",
|
||||
feet: [feet.x, feet.y, feet.z],
|
||||
width,
|
||||
@@ -3605,6 +3612,8 @@ fn pois_scan_order(_m: &Mob, found: &[(Poi, [i32; 3])]) -> Vec<usize> {
|
||||
/// `AbstractVillager.addParticlesAroundSelf(HAPPY_VILLAGER)` on the client.
|
||||
fn happy_particles(m: &Mob, cx: &mut Bx) {
|
||||
cx.events.push(MobEvent::AroundSelf {
|
||||
mob: m.id,
|
||||
event: 14,
|
||||
kind: "happy_villager",
|
||||
feet: [m.position.x, m.position.y, m.position.z],
|
||||
width: f64::from(m.width()),
|
||||
|
||||
@@ -221,6 +221,7 @@ pub fn custom_server_ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEven
|
||||
events.push(MobEvent::Explode(
|
||||
[m.position.x, m.eye_y(), m.position.z],
|
||||
7.0,
|
||||
m.species(),
|
||||
));
|
||||
// Global level event 1023.
|
||||
if !m.silent {
|
||||
|
||||
@@ -25,6 +25,8 @@ pub struct TargetInfo {
|
||||
pub can_be_seen_as_enemy: bool,
|
||||
pub is_player: bool,
|
||||
pub creative: bool,
|
||||
/// `isPassenger`.
|
||||
pub passenger: bool,
|
||||
}
|
||||
impl MobWorld<'_> {
|
||||
/// The biome's base temperature at a position.
|
||||
@@ -243,6 +245,7 @@ impl MobWorld<'_> {
|
||||
can_be_seen_as_enemy: true,
|
||||
is_player: true,
|
||||
creative: p.creative,
|
||||
passenger: p.passenger,
|
||||
}),
|
||||
Who::Mob(id) => self.seen(id).map(|s| TargetInfo {
|
||||
position: s.position,
|
||||
@@ -252,6 +255,7 @@ impl MobWorld<'_> {
|
||||
can_be_seen_as_enemy: !s.playing_dead,
|
||||
is_player: false,
|
||||
creative: false,
|
||||
passenger: s.passenger,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,6 +55,10 @@ pub struct MotionResources {
|
||||
/// `BlockTags.SOUL_SPEED_BLOCKS`: what Soul Speed's effects look for.
|
||||
pub soul_speed_blocks: BTreeSet<String>,
|
||||
pub fall_reset: BTreeSet<String>,
|
||||
/// `BlockTags.INSIDE_STEP_SOUND_BLOCKS`.
|
||||
pub inside_step_sound: BTreeSet<String>,
|
||||
/// `BlockTags.COMBINATION_STEP_SOUND_BLOCKS`.
|
||||
pub combination_step_sound: BTreeSet<String>,
|
||||
pub landing: BlockLandingRegistry,
|
||||
pub health: crate::health::HealthResources,
|
||||
pub fluids: FluidResources,
|
||||
@@ -115,6 +119,8 @@ impl MotionResources {
|
||||
glide_through: tag("minecraft:can_glide_through")?,
|
||||
soul_speed_blocks: tag("minecraft:soul_speed_blocks")?,
|
||||
fall_reset: tag("minecraft:fall_damage_resetting")?,
|
||||
inside_step_sound: tag("minecraft:inside_step_sound_blocks")?,
|
||||
combination_step_sound: tag("minecraft:combination_step_sound_blocks")?,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -159,11 +165,12 @@ pub enum MotionEvent {
|
||||
position: BlockPos,
|
||||
},
|
||||
/// `Entity.walkingStepSound` on this block: `Player.playStepSound`
|
||||
/// muffles it under a swim sound when `in_water`.
|
||||
/// mutes it (`playMuffledStepSound`) under a swim sound in water or
|
||||
/// under a combination block's own step.
|
||||
Emission {
|
||||
position: BlockPos,
|
||||
state: BlockStateId,
|
||||
in_water: bool,
|
||||
muffled: bool,
|
||||
},
|
||||
/// `Entity.waterSwimSound`: `entity.player.swim`.
|
||||
Swim {
|
||||
@@ -2153,16 +2160,48 @@ impl MovementEmissionWorld for MotionWorld<'_, '_, '_> {
|
||||
fn in_water(&mut self) -> Result<bool> {
|
||||
Ok(self.player.fluids.was_touching_water)
|
||||
}
|
||||
/// `Player.playStepSound`: in water a swim sound, then the step muffled.
|
||||
/// `Player.playStepSound`: in water a swim sound, then the step muffled;
|
||||
/// on land the step of an inside-sound block above the floor, or of a
|
||||
/// combination block above it with the floor's step muffled.
|
||||
fn walking_step_sound(&mut self, position: BlockPos, state: BlockStateId) -> Result<()> {
|
||||
let in_water = self.player.fluids.was_touching_water;
|
||||
if in_water {
|
||||
let muffled = self.player.fluids.was_touching_water;
|
||||
if muffled {
|
||||
self.water_swim_sound()?;
|
||||
} else {
|
||||
// Entity.getPrimaryStepSoundBlockPos.
|
||||
let above = BlockPos {
|
||||
y: position.y + 1,
|
||||
..position
|
||||
};
|
||||
let above_state = self.block(above);
|
||||
let name = &self
|
||||
.assets
|
||||
.registry
|
||||
.state(above_state)
|
||||
.ok_or("missing scene state")?
|
||||
.name;
|
||||
let combination = self.resources.combination_step_sound.contains(name);
|
||||
if combination || self.resources.inside_step_sound.contains(name) {
|
||||
self.player.events.push(MotionEvent::Emission {
|
||||
position: above,
|
||||
state: above_state,
|
||||
muffled: false,
|
||||
});
|
||||
if combination {
|
||||
// Entity.playCombinationStepSounds.
|
||||
self.player.events.push(MotionEvent::Emission {
|
||||
position,
|
||||
state,
|
||||
muffled: true,
|
||||
});
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
self.player.events.push(MotionEvent::Emission {
|
||||
position,
|
||||
state,
|
||||
in_water,
|
||||
muffled,
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -588,15 +588,17 @@ pub fn on_block_faces_between(
|
||||
}
|
||||
}
|
||||
/// `ParticleUtils.spawnParticlesAlongAxis(axis, level, pos, 0.125, particle,
|
||||
/// UniformInt.of(10, 19))` (level event 3002 on a lightning rod): sparks along
|
||||
/// the rod, moving along it. `axis` is 0, 1, 2 for X, Y, Z.
|
||||
/// UniformInt.of(min, max))` (`count` is the range; level event 3002 on a
|
||||
/// lightning rod uses 10 to 19): sparks along the rod, moving along it.
|
||||
/// `axis` is 0, 1, 2 for X, Y, Z.
|
||||
pub fn along_axis(
|
||||
random: &mut impl RandomSource,
|
||||
axis: usize,
|
||||
pos: [i32; 3],
|
||||
(min, max): (i32, i32),
|
||||
mut emit: impl FnMut([f64; 3], [f64; 3]),
|
||||
) {
|
||||
let count = random.next_int_bound(19 - 10 + 1).unwrap_or(0) + 10;
|
||||
let count = random.next_int_bound(max - min + 1).unwrap_or(0) + min;
|
||||
for _ in 0..count {
|
||||
let p: [f64; 3] = std::array::from_fn(|i| {
|
||||
f64::from(pos[i])
|
||||
|
||||
@@ -109,6 +109,9 @@ pub struct Projectile {
|
||||
pub arrow: Option<Box<crate::arrows::ArrowState>>,
|
||||
/// `AbstractHurtingProjectile.accelerationPower`.
|
||||
pub acceleration: f64,
|
||||
/// `Entity.needsSync`: a server tells its clients about the change this
|
||||
/// tick instead of at the next update interval.
|
||||
pub needs_sync: bool,
|
||||
}
|
||||
/// What a projectile struck this tick.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
@@ -173,6 +176,7 @@ impl Projectile {
|
||||
left_owner: false,
|
||||
bonus: Default::default(),
|
||||
acceleration: 0.1,
|
||||
needs_sync: false,
|
||||
arrow: kind_is_arrow.then(|| {
|
||||
// Entity.random: seeded unpredictably, the position stands in.
|
||||
Box::new(crate::arrows::ArrowState::new(
|
||||
|
||||
@@ -126,6 +126,38 @@ fn idle() -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
/// How many stop requests (Ctrl-C, SIGTERM, SIGHUP) arrived since `catch_stop_signals`.
|
||||
pub fn stop_requests() -> u32 {
|
||||
STOP_REQUESTS.load(std::sync::atomic::Ordering::SeqCst)
|
||||
}
|
||||
|
||||
static STOP_REQUESTS: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0);
|
||||
|
||||
/// Count stop requests from outside instead of dying on them: vanilla's "Client Shutdown Thread"
|
||||
/// (`Main.java`) halts the integrated server when the JVM shuts down, and the JVM does that on
|
||||
/// these signals, so a killed game still saves. The caller's event loop turns the first request
|
||||
/// into a normal quit; a second one (the save is stuck) ends the process at once.
|
||||
#[cfg(any(target_vendor = "apple", target_os = "linux", target_os = "android"))]
|
||||
pub fn catch_stop_signals() {
|
||||
extern "C" fn handle(_: libc::c_int) {
|
||||
if STOP_REQUESTS.fetch_add(1, Ordering::SeqCst) >= 1 {
|
||||
// SAFETY: _exit is async-signal-safe; 130 is the shell's code for a Ctrl-C death.
|
||||
unsafe { libc::_exit(130) }
|
||||
}
|
||||
}
|
||||
let handler = handle as extern "C" fn(libc::c_int);
|
||||
for signal in [libc::SIGINT, libc::SIGTERM, libc::SIGHUP] {
|
||||
// SAFETY: the handler only touches an atomic and calls _exit, both async-signal-safe.
|
||||
unsafe {
|
||||
libc::signal(signal, handler as libc::sighandler_t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Windows and the other systems keep their default: a closed window is a `CloseRequested`.
|
||||
#[cfg(not(any(target_vendor = "apple", target_os = "linux", target_os = "android")))]
|
||||
pub fn catch_stop_signals() {}
|
||||
|
||||
/// Give back to the OS the memory the allocator holds free, after something
|
||||
/// large was dropped: glibc keeps freed pages in the arena of the thread that
|
||||
/// allocated them, and macOS in its zones until memory runs short. Nothing
|
||||
|
||||
@@ -559,20 +559,26 @@ impl Behaviours {
|
||||
sim.game_event_state(pos, "minecraft:block_change", next);
|
||||
}
|
||||
|
||||
/// The state change of `RedStoneOreBlock.attack` when mining begins.
|
||||
/// `BlockBehaviour.attack` when mining begins: `RedStoneOreBlock.attack`
|
||||
/// lights the ore, `NoteBlock.attack` plays the note. True for a note
|
||||
/// block, whose player also earns the `play_noteblock` statistic.
|
||||
pub fn attack_block<L: LevelAccess + ?Sized>(
|
||||
&self,
|
||||
level: &mut L,
|
||||
ticks: &mut Ticks,
|
||||
pos: BlockPos,
|
||||
) {
|
||||
) -> bool {
|
||||
let mut sim = self.sim(level, ticks);
|
||||
let state = sim.state(pos);
|
||||
if self.data(state).chain.contains(&Class::RedStoneOre)
|
||||
&& !self.table.bool(state, self.props.lit)
|
||||
{
|
||||
let chain = &self.data(state).chain;
|
||||
if chain.contains(&Class::Note) {
|
||||
sim.note_play(pos, state);
|
||||
return true;
|
||||
}
|
||||
if chain.contains(&Class::RedStoneOre) && !self.table.bool(state, self.props.lit) {
|
||||
sim.set_block_and_update(pos, self.table.set_bool(state, self.props.lit, true));
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
/// `BlockState.useWithoutItem` for a right-click on `pos` (hit face and
|
||||
@@ -641,6 +647,25 @@ impl Behaviours {
|
||||
if self.data(state).chain.contains(&Class::CopperGolemStatue) {
|
||||
return self.turn_statue(level, ticks, pos, state, item);
|
||||
}
|
||||
// NoteBlock.useItemOn: a mob head on the top face is placed, not tuned
|
||||
// (`#minecraft:noteblock_top_instruments`).
|
||||
if face == Direction::Up
|
||||
&& self.data(state).chain.contains(&Class::Note)
|
||||
&& item.is_some_and(|i| {
|
||||
matches!(
|
||||
i,
|
||||
"minecraft:zombie_head"
|
||||
| "minecraft:skeleton_skull"
|
||||
| "minecraft:creeper_head"
|
||||
| "minecraft:dragon_head"
|
||||
| "minecraft:wither_skeleton_skull"
|
||||
| "minecraft:piglin_head"
|
||||
| "minecraft:player_head"
|
||||
)
|
||||
})
|
||||
{
|
||||
return InteractionResult::Pass;
|
||||
}
|
||||
self.use_without_item(level, ticks, pos, face, hit, player)
|
||||
}
|
||||
|
||||
|
||||
@@ -1478,6 +1478,80 @@ impl<L: LevelAccess + ?Sized> Sim<'_, L> {
|
||||
let block = b.table.block_by_name(&format!("minecraft:{next}"))?;
|
||||
Some(b.table.with_properties_of(block, state))
|
||||
}
|
||||
/// `WeatheringCopper.getPrevious` (and `getFirst` by repeating it) by
|
||||
/// registry naming: the block one oxidation step back.
|
||||
fn copper_previous_name(path: &str) -> Option<String> {
|
||||
if let Some(rest) = path.strip_prefix("oxidized_") {
|
||||
Some(format!("weathered_{rest}"))
|
||||
} else if let Some(rest) = path.strip_prefix("weathered_") {
|
||||
Some(format!("exposed_{rest}"))
|
||||
} else {
|
||||
path.strip_prefix("exposed_").map(|rest| {
|
||||
if rest == "copper" {
|
||||
"copper_block".to_owned()
|
||||
} else {
|
||||
rest.to_owned()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
fn copper_stepped(&self, state: BlockStateId, all_the_way: bool) -> Option<BlockStateId> {
|
||||
let b = self.b;
|
||||
let name = &*b.table.info(b.block(state)).name;
|
||||
let mut path = Self::copper_previous_name(name.strip_prefix("minecraft:")?)?;
|
||||
while all_the_way && let Some(earlier) = Self::copper_previous_name(&path) {
|
||||
path = earlier;
|
||||
}
|
||||
let block = b.table.block_by_name(&format!("minecraft:{path}"))?;
|
||||
Some(b.table.with_properties_of(block, state))
|
||||
}
|
||||
/// `LightningBolt.clearCopperOnLightningStrike`: the struck copper goes
|
||||
/// back to unoxidized, then 3 to 5 random walks of up to 8 steps each
|
||||
/// scrape one step of oxidation off the weathering copper they land on.
|
||||
/// A waxed block is left as it is but still starts the walks.
|
||||
pub(crate) fn lightning_clear_copper(&mut self, struck: BlockPos) {
|
||||
let b = self.b;
|
||||
let state = self.state(struck);
|
||||
let weathering = b
|
||||
.data(state)
|
||||
.implements(super::classes::Interface::WeatheringCopper);
|
||||
let waxed = b.table.name(state).starts_with("minecraft:waxed_");
|
||||
if !(weathering || waxed) {
|
||||
return;
|
||||
}
|
||||
if weathering && let Some(first) = self.copper_stepped(state, true) {
|
||||
self.set_block_and_update(struck, first);
|
||||
}
|
||||
for _ in 0..self.rand_int(3) + 3 {
|
||||
let mut at = struck;
|
||||
for _ in 0..self.rand_int(8) + 1 {
|
||||
// randomStepCleaningCopper: up to 10 random blocks in the
|
||||
// 3x3x3 cube around the walk's position.
|
||||
let mut next = None;
|
||||
for _ in 0..10 {
|
||||
let x = at.x - 1 + self.rand_int(3);
|
||||
let y = at.y - 1 + self.rand_int(3);
|
||||
let z = at.z - 1 + self.rand_int(3);
|
||||
let candidate = BlockPos::new(x, y, z);
|
||||
let state = self.state(candidate);
|
||||
if b.data(state)
|
||||
.implements(super::classes::Interface::WeatheringCopper)
|
||||
{
|
||||
if let Some(previous) = self.copper_stepped(state, false) {
|
||||
self.set_block_and_update(candidate, previous);
|
||||
}
|
||||
self.level_event(3002, candidate, -1);
|
||||
next = Some(candidate);
|
||||
break;
|
||||
}
|
||||
}
|
||||
match next {
|
||||
Some(p) => at = p,
|
||||
None => break,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// `Biome.Precipitation` at a position.
|
||||
@@ -1661,6 +1735,15 @@ impl Behaviours {
|
||||
) {
|
||||
self.sim(level, ticks).random_tick_at(pos);
|
||||
}
|
||||
/// `LightningBolt.clearCopperOnLightningStrike` for the block at `struck`.
|
||||
pub fn lightning_clear_copper<L: LevelAccess + ?Sized>(
|
||||
&self,
|
||||
level: &mut L,
|
||||
ticks: &mut Ticks,
|
||||
struck: BlockPos,
|
||||
) {
|
||||
self.sim(level, ticks).lightning_clear_copper(struck);
|
||||
}
|
||||
/// Run one scheduled block tick at `pos` immediately (no queue check).
|
||||
pub fn scheduled_block_tick<L: LevelAccess + ?Sized>(
|
||||
&self,
|
||||
|
||||
Loaded 100 of 121 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user