Merge upstream/main into fix/armadillo-roll-ball
Co-Authored-By: minimax-m3.1-flash (Claude Code) <noreply@users.noreply.github.com>
This commit is contained in:
@@ -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());
|
||||
|
||||
@@ -1049,6 +1049,7 @@ pub fn main() -> horizon_client::Result<()> {
|
||||
alive: true,
|
||||
creative: s.creative,
|
||||
sneaking: false,
|
||||
swimming: false,
|
||||
look: [0.0, 0.0, 1.0],
|
||||
main_hand: s.hand.as_deref().map(Into::into),
|
||||
off_hand: None,
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
//! conditions advancements use).
|
||||
use serde_json::Value;
|
||||
use std::{
|
||||
collections::{BTreeMap, HashMap},
|
||||
collections::{BTreeMap, BTreeSet, HashMap},
|
||||
path::Path,
|
||||
};
|
||||
|
||||
@@ -753,6 +753,41 @@ 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 {
|
||||
|
||||
@@ -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::{
|
||||
@@ -75,6 +75,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),
|
||||
/// `WetSpongeBlock.animateTick`.
|
||||
WetSponge,
|
||||
}
|
||||
@@ -91,6 +107,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),
|
||||
@@ -172,6 +189,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
|
||||
})
|
||||
}
|
||||
"wet_sponge" => Animate::WetSponge,
|
||||
// BrushableBlock has no dust colour of its own, so the dust is the map colour.
|
||||
"suspicious_sand" => Animate::Falling(0xF7E9A3, false),
|
||||
@@ -250,6 +299,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> {
|
||||
@@ -315,8 +366,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"),
|
||||
@@ -350,6 +418,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.
|
||||
@@ -398,6 +474,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
|
||||
@@ -1079,6 +1158,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();
|
||||
@@ -1382,6 +1554,68 @@ fn leaves_ambient_sound(
|
||||
}
|
||||
}
|
||||
}
|
||||
/// `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]);
|
||||
}
|
||||
/// `AmbientDesertBlockSoundsPlayer.shouldPlayAmbientSandSound`: sand in the
|
||||
/// surface column eight blocks away on all four sides.
|
||||
fn sand_sound_nearby(tables: &AnimateTables, ctx: &AnimateContext, pos: [i32; 3]) -> bool {
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -938,6 +938,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)
|
||||
@@ -1439,22 +1463,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 => {
|
||||
|
||||
@@ -4023,6 +4023,10 @@ impl Game<'_> {
|
||||
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);
|
||||
|
||||
@@ -719,6 +719,19 @@ impl Game<'_> {
|
||||
adv::conditions(&c["player"], &pctx, w) && adv::conditions(&c[&key], &ectx, w)
|
||||
});
|
||||
}
|
||||
/// `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)
|
||||
});
|
||||
}
|
||||
/// `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) {
|
||||
@@ -863,6 +876,22 @@ impl Game<'_> {
|
||||
let it = item_view(stack);
|
||||
self.trigger(name, |c, w| adv::item_entity(c, &me, target, &it, 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))
|
||||
});
|
||||
}
|
||||
/// `BrewedPotionTrigger`: the potion contents of a stack taken from a
|
||||
/// brewing stand.
|
||||
pub(super) fn trigger_brewed_potion(&mut self, stack: &ItemStack) {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -201,6 +201,7 @@ impl Game<'_> {
|
||||
// EntitySelector.NO_CREATIVE_OR_SPECTATOR.
|
||||
creative: self.creative || self.spectator(),
|
||||
sneaking: self.keys.contains(&winit::keyboard::KeyCode::ShiftLeft),
|
||||
swimming: p.swimming,
|
||||
look: view_vector(self.yaw, self.pitch),
|
||||
main_hand: self.held().map(|s| s.item.clone()),
|
||||
off_hand: None,
|
||||
@@ -1433,6 +1434,27 @@ impl Game<'_> {
|
||||
.list
|
||||
.retain(|e| e.id != "mining_fatigue");
|
||||
}
|
||||
MobEvent::DolphinTreasure { mob } => {
|
||||
// ServerLevel.findNearestMapStructure(#dolphin_located, 50).
|
||||
let Some(at) = self.mobs.iter().find(|m| m.id == mob).map(|m| {
|
||||
[
|
||||
m.position.x.floor() as i32,
|
||||
m.position.y.floor() as i32,
|
||||
m.position.z.floor() as i32,
|
||||
]
|
||||
}) else {
|
||||
continue;
|
||||
};
|
||||
let names = self.structure_tag("minecraft:dolphin_located");
|
||||
let found = self
|
||||
.end
|
||||
.locator()
|
||||
.filter(|_| !names.is_empty())
|
||||
.and_then(|t| t.locate(&names, at, 50));
|
||||
if let Some(m) = self.mobs.iter_mut().find(|m| m.id == mob) {
|
||||
m.extra.home = found.map(|(_, p)| p);
|
||||
}
|
||||
}
|
||||
MobEvent::EffectPlayer {
|
||||
effect,
|
||||
ticks,
|
||||
@@ -2673,6 +2695,17 @@ impl Game<'_> {
|
||||
};
|
||||
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
|
||||
}
|
||||
@@ -3164,6 +3197,12 @@ impl Game<'_> {
|
||||
.item_tags
|
||||
.get("minecraft:creeper_igniters")
|
||||
.is_some_and(|t| t.contains(&*item));
|
||||
let fish = self
|
||||
.res
|
||||
.items()
|
||||
.item_tags
|
||||
.get("minecraft:fishes")
|
||||
.is_some_and(|t| t.contains(&*item));
|
||||
let damageable = self
|
||||
.res
|
||||
.items()
|
||||
@@ -3459,6 +3498,18 @@ impl Game<'_> {
|
||||
self.trigger_entity("minecraft:tame_animal", "entity", &view);
|
||||
}
|
||||
}
|
||||
// Dolphin.mobInteract: a fish makes a baby grow by a tenth and an
|
||||
// adult remember it (`gotFish`), to swim to a treasure.
|
||||
Species::Dolphin if fish => {
|
||||
eat = Some(("entity.dolphin.eat", 1.0, 1.0));
|
||||
if m.extra.age < 0 {
|
||||
let secs = ((-m.extra.age / 20) as f32 * 0.1) as i32;
|
||||
horizon_client::mobs::ai::age_up(m, secs, true);
|
||||
} else {
|
||||
m.extra.flag = true;
|
||||
}
|
||||
consume = true;
|
||||
}
|
||||
// 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 => {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -374,6 +374,7 @@ mod tests {
|
||||
alive: true,
|
||||
creative,
|
||||
sneaking: false,
|
||||
swimming: false,
|
||||
look: [0.0; 3],
|
||||
main_hand: None,
|
||||
off_hand: None,
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -46,7 +46,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))),
|
||||
}
|
||||
|
||||
@@ -868,9 +868,8 @@ impl Game<'_> {
|
||||
(d * 2.0 + 0.5) as i8
|
||||
}
|
||||
};
|
||||
let y = f64::from(yaw);
|
||||
let adjusted = if y < 0.0 { y - 8.0 } else { y + 8.0 };
|
||||
let rot = ((adjusted * 16.0 / 360.0) as i32 & 15) as u8;
|
||||
// calculateRotation: the arrow spins in the Nether.
|
||||
let rot = decoration_rotation(nether, game_time, f64::from(yaw));
|
||||
let sprite = if inside {
|
||||
Some("map/decorations/player")
|
||||
} else if dx.abs() < 320.0 && dz.abs() < 320.0 {
|
||||
|
||||
@@ -1215,9 +1215,28 @@ impl Game<'_> {
|
||||
}
|
||||
}
|
||||
}
|
||||
/// `Hud.extractEffects`: icons top-right, beneficial row then harmful row.
|
||||
/// `Screen.showsActiveEffects`: the survival and creative inventories
|
||||
/// draw their own effect list when `EffectsInInventory.canSeeEffects`
|
||||
/// (32 or more pixels right of the screen).
|
||||
fn screen_shows_active_effects(&self, batch: &HudBatch) -> bool {
|
||||
let (ox, image_width) = match self.screen {
|
||||
Screen::Inventory
|
||||
if self.container.is_none() && self.craft_size == 2 && !self.mount_active() =>
|
||||
{
|
||||
(self.inventory_origin(batch).0, 176)
|
||||
}
|
||||
Screen::Creative => (
|
||||
Self::creative_origin(batch).0,
|
||||
horizon_client::creative::Creative::WIDTH as i32,
|
||||
),
|
||||
_ => return false,
|
||||
};
|
||||
batch.width as i32 - (ox as i32 + image_width + 2) >= 32
|
||||
}
|
||||
/// `Hud.extractEffects`: icons top-right, beneficial row then harmful row;
|
||||
/// every screen but the inventories keeps them.
|
||||
pub(super) fn draw_effect_icons(&self, batch: &mut HudBatch) {
|
||||
if self.screen != Screen::Playing || self.potions.effects.list.is_empty() {
|
||||
if self.potions.effects.list.is_empty() || self.screen_shows_active_effects(batch) {
|
||||
return;
|
||||
}
|
||||
let icons: Vec<hud_overlays::EffectIcon> = self
|
||||
|
||||
@@ -293,6 +293,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,
|
||||
@@ -301,6 +311,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 = [
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ pub mod creaking;
|
||||
pub mod creaking_heart;
|
||||
pub mod cube;
|
||||
pub mod data;
|
||||
pub mod dolphin;
|
||||
pub mod doors;
|
||||
pub mod drops;
|
||||
pub mod enderman;
|
||||
@@ -1158,6 +1159,12 @@ pub enum MobEvent {
|
||||
},
|
||||
/// Regeneration support after an axolotl-assisted kill.
|
||||
AxolotlSupportPlayer,
|
||||
/// A dolphin that was given a fish asks the game for the nearest
|
||||
/// shipwreck or ocean ruin (`DolphinSwimToTreasureGoal.start`): the game
|
||||
/// sets the dolphin's `extra.home` to it, or leaves it empty.
|
||||
DolphinTreasure {
|
||||
mob: u32,
|
||||
},
|
||||
/// Apply an effect to the player (witch potions, bee stings, cave spider poison).
|
||||
EffectPlayer {
|
||||
effect: &'static str,
|
||||
@@ -1634,6 +1641,8 @@ pub struct PlayerView {
|
||||
pub alive: bool,
|
||||
pub creative: bool,
|
||||
pub sneaking: bool,
|
||||
/// `Entity.isSwimming`.
|
||||
pub swimming: bool,
|
||||
pub look: [f64; 3],
|
||||
pub main_hand: Option<Arc<str>>,
|
||||
pub off_hand: Option<Arc<str>>,
|
||||
|
||||
@@ -128,9 +128,12 @@ pub fn register(m: &mut Mob) {
|
||||
let g = &mut m.ai.goals;
|
||||
g.add(0, BreathAir);
|
||||
g.add(0, TryFindWater::default());
|
||||
g.add(1, super::dolphin::SwimToTreasure::default());
|
||||
g.add(2, super::dolphin::SwimWithPlayer::new(4.0));
|
||||
g.add(4, Stroll::swimming(1.0, 10));
|
||||
g.add(4, RandomLookAround::default());
|
||||
g.add(5, LookAtPlayer::new(6.0));
|
||||
g.add(5, super::dolphin::Jump::new(10));
|
||||
g.add(6, MeleeAttack::new(1.2, true));
|
||||
m.ai.targets.add(1, HurtByTarget::new().alert());
|
||||
m.ai.mov.kind = MoveKind::SmoothSwimming {
|
||||
|
||||
@@ -0,0 +1,265 @@
|
||||
//! Dolphin goals: `DolphinSwimToTreasureGoal`, `DolphinSwimWithPlayerGoal`
|
||||
//! and `DolphinJumpGoal`. `extra.flag` is `gotFish` and `extra.home` the
|
||||
//! `treasurePos` the game found for it (`MobEvent::DolphinTreasure`).
|
||||
use super::{
|
||||
Mob, MobEvent, Who,
|
||||
goals::{Cx, Goal, JUMP, LOOK, MOVE, goal_clone, reduced},
|
||||
};
|
||||
use crate::blocks::Fluid;
|
||||
use horizon_core::random::RandomSource;
|
||||
|
||||
/// `Entity.getMotionDirection`: the horizontal step of the yaw
|
||||
/// (`Direction.fromYRot`: south, west, north, east).
|
||||
fn motion_step(yaw: f32) -> [i32; 2] {
|
||||
match (yaw / 90.0 + 0.5).floor() as i32 & 3 {
|
||||
0 => [0, 1],
|
||||
1 => [-1, 0],
|
||||
2 => [0, -1],
|
||||
_ => [1, 0],
|
||||
}
|
||||
}
|
||||
|
||||
/// `DolphinSwimToTreasureGoal`: a dolphin that was fed a fish leads the way to
|
||||
/// a shipwreck or an ocean ruin within 50 sectors.
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct SwimToTreasure {
|
||||
stuck: bool,
|
||||
}
|
||||
impl SwimToTreasure {
|
||||
/// `BlockPos.containing(x, dolphin.getY(), z).closerToCenterThan(position, 4)`.
|
||||
fn arrived(m: &Mob) -> bool {
|
||||
let Some(t) = m.extra.home else { return false };
|
||||
let d = [
|
||||
f64::from(t[0]) + 0.5 - m.position.x,
|
||||
m.position.y.floor() + 0.5 - m.position.y,
|
||||
f64::from(t[2]) + 0.5 - m.position.z,
|
||||
];
|
||||
d[0] * d[0] + d[1] * d[1] + d[2] * d[2] < 16.0
|
||||
}
|
||||
}
|
||||
impl Goal for SwimToTreasure {
|
||||
goal_clone!();
|
||||
fn flags(&self) -> u8 {
|
||||
MOVE | LOOK
|
||||
}
|
||||
fn interruptable(&self) -> bool {
|
||||
false
|
||||
}
|
||||
fn can_use(&mut self, m: &mut Mob, _: &mut Cx) -> bool {
|
||||
m.extra.flag && m.air >= 100
|
||||
}
|
||||
fn can_continue(&mut self, m: &mut Mob, _: &mut Cx) -> bool {
|
||||
m.extra.home.is_some() && !Self::arrived(m) && !self.stuck && m.air >= 100
|
||||
}
|
||||
fn start(&mut self, m: &mut Mob, cx: &mut Cx) {
|
||||
self.stuck = false;
|
||||
m.nav_stop();
|
||||
// The game looks for the structure and sets the position, or none.
|
||||
m.extra.home = None;
|
||||
cx.events.push(MobEvent::DolphinTreasure { mob: m.id });
|
||||
}
|
||||
fn stop(&mut self, m: &mut Mob, _: &mut Cx) {
|
||||
if m.extra.home.is_none() || Self::arrived(m) || self.stuck {
|
||||
m.extra.flag = false;
|
||||
}
|
||||
}
|
||||
fn tick(&mut self, m: &mut Mob, cx: &mut Cx) {
|
||||
let Some(t) = m.extra.home else { return };
|
||||
let close = m.ai.nav.target_pos.is_some_and(|p| {
|
||||
let d = [
|
||||
f64::from(p[0]) + 0.5 - m.position.x,
|
||||
f64::from(p[1]) + 0.5 - m.position.y,
|
||||
f64::from(p[2]) + 0.5 - m.position.z,
|
||||
];
|
||||
d[0] * d[0] + d[1] * d[1] + d[2] * d[2] < 144.0
|
||||
});
|
||||
if !close && !m.ai.nav.is_done() {
|
||||
return;
|
||||
}
|
||||
let treasure = [
|
||||
f64::from(t[0]) + 0.5,
|
||||
f64::from(t[1]) + 0.5,
|
||||
f64::from(t[2]) + 0.5,
|
||||
];
|
||||
let eighth = f64::from(std::f32::consts::FRAC_PI_8);
|
||||
let half = f64::from(std::f32::consts::FRAC_PI_2);
|
||||
let mut next = m.default_random_pos_towards(cx.w, 16, 1, treasure, eighth);
|
||||
if next.is_none() {
|
||||
next = m.default_random_pos_towards(cx.w, 8, 4, treasure, half);
|
||||
}
|
||||
// isPathfindable(WATER) is a water fluid state.
|
||||
if let Some(n) = next
|
||||
&& cx.w.fluid(
|
||||
n[0].floor() as i32,
|
||||
n[1].floor() as i32,
|
||||
n[2].floor() as i32,
|
||||
) != Fluid::Water
|
||||
{
|
||||
next = m.default_random_pos_towards(cx.w, 8, 5, treasure, half);
|
||||
}
|
||||
let Some(next) = next else {
|
||||
self.stuck = true;
|
||||
return;
|
||||
};
|
||||
let (y, x) = (m.kind.max_head_y_rot + 20.0, m.kind.max_head_x_rot);
|
||||
m.look_at_speed(next, y, x);
|
||||
m.nav_move_to(cx.w, next, 1.3);
|
||||
if m.random.next_int_bound(80).unwrap_or(1) == 0 {
|
||||
// Entity event 38: happy villager particles about the dolphin.
|
||||
cx.events.push(MobEvent::AroundSelf {
|
||||
mob: m.id,
|
||||
event: 38,
|
||||
kind: "happy_villager",
|
||||
feet: [m.position.x, m.position.y, m.position.z],
|
||||
width: f64::from(m.width()),
|
||||
height: f64::from(m.height()),
|
||||
burst: crate::particles::Burst::DOLPHIN,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// `DolphinSwimWithPlayerGoal`: swim up to a swimming player and give them
|
||||
/// Dolphin's Grace.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct SwimWithPlayer {
|
||||
speed: f64,
|
||||
}
|
||||
impl SwimWithPlayer {
|
||||
pub fn new(speed: f64) -> Self {
|
||||
Self { speed }
|
||||
}
|
||||
}
|
||||
impl Goal for SwimWithPlayer {
|
||||
goal_clone!();
|
||||
fn flags(&self) -> u8 {
|
||||
MOVE | LOOK
|
||||
}
|
||||
fn can_use(&mut self, m: &mut Mob, cx: &mut Cx) -> bool {
|
||||
// getNearestPlayer(forNonCombat().range(10).ignoreLineOfSight()).
|
||||
m.can_see_player_through_walls(cx.w, 10.0)
|
||||
&& cx.w.player.as_ref().is_some_and(|p| p.swimming)
|
||||
&& m.ai.target != Some(Who::Player)
|
||||
}
|
||||
fn can_continue(&mut self, m: &mut Mob, cx: &mut Cx) -> bool {
|
||||
cx.w.player
|
||||
.as_ref()
|
||||
.is_some_and(|p| p.swimming && m.distance_sqr(p.position) < 256.0)
|
||||
}
|
||||
fn start(&mut self, _: &mut Mob, cx: &mut Cx) {
|
||||
cx.events.push(grace());
|
||||
}
|
||||
fn stop(&mut self, m: &mut Mob, _: &mut Cx) {
|
||||
m.nav_stop();
|
||||
}
|
||||
fn tick(&mut self, m: &mut Mob, cx: &mut Cx) {
|
||||
let Some(p) = cx.w.player.clone() else { return };
|
||||
let (y, x) = (m.kind.max_head_y_rot + 20.0, m.kind.max_head_x_rot);
|
||||
m.look_at_speed(p.eye, y, x);
|
||||
if m.distance_sqr(p.position) < 6.25 {
|
||||
m.nav_stop();
|
||||
} else {
|
||||
m.nav_move_to_entity(
|
||||
cx.w,
|
||||
[p.position.x, p.position.y, p.position.z],
|
||||
1,
|
||||
self.speed,
|
||||
);
|
||||
}
|
||||
if p.swimming && m.random.next_int_bound(6).unwrap_or(1) == 0 {
|
||||
cx.events.push(grace());
|
||||
}
|
||||
}
|
||||
}
|
||||
/// `MobEffectInstance(DOLPHINS_GRACE, 100)`.
|
||||
fn grace() -> MobEvent {
|
||||
MobEvent::EffectPlayer {
|
||||
effect: "minecraft:dolphins_grace",
|
||||
ticks: 100,
|
||||
amplifier: 0,
|
||||
}
|
||||
}
|
||||
|
||||
/// `DolphinJumpGoal`: leap out of clear water and arc back in.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Jump {
|
||||
interval: i32,
|
||||
breached: bool,
|
||||
}
|
||||
impl Jump {
|
||||
pub fn new(interval: i32) -> Self {
|
||||
Self {
|
||||
interval: reduced(interval),
|
||||
breached: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl Goal for Jump {
|
||||
goal_clone!();
|
||||
fn flags(&self) -> u8 {
|
||||
JUMP | MOVE
|
||||
}
|
||||
fn interruptable(&self) -> bool {
|
||||
false
|
||||
}
|
||||
fn can_use(&mut self, m: &mut Mob, cx: &mut Cx) -> bool {
|
||||
if m.random.next_int_bound(self.interval).unwrap_or(1) != 0 {
|
||||
return false;
|
||||
}
|
||||
let [sx, sz] = motion_step(m.yaw);
|
||||
let (bx, by, bz) = (
|
||||
m.position.x.floor() as i32,
|
||||
m.position.y.floor() as i32,
|
||||
m.position.z.floor() as i32,
|
||||
);
|
||||
let w = cx.w;
|
||||
[0, 1, 4, 5, 6, 7].into_iter().all(|i| {
|
||||
let (x, z) = (bx + sx * i, bz + sz * i);
|
||||
// waterIsClear, then surfaceIsClear.
|
||||
w.fluid(x, by, z) == Fluid::Water
|
||||
&& !w.has_tag("minecraft:blocks_dolphin_jump", w.block_name(x, by, z))
|
||||
&& w.facts.is_air(w.world.block(x, by + 1, z))
|
||||
&& w.facts.is_air(w.world.block(x, by + 2, z))
|
||||
})
|
||||
}
|
||||
fn can_continue(&mut self, m: &mut Mob, _: &mut Cx) -> bool {
|
||||
let yd = m.velocity.y;
|
||||
(yd * yd >= f64::from(0.03f32)
|
||||
|| m.head_pitch == 0.0
|
||||
|| m.head_pitch.abs() >= 10.0
|
||||
|| !m.fluids.in_water)
|
||||
&& !m.on_ground
|
||||
}
|
||||
fn start(&mut self, m: &mut Mob, _: &mut Cx) {
|
||||
let [sx, sz] = motion_step(m.yaw);
|
||||
m.velocity.x += f64::from(sx) * 0.6;
|
||||
m.velocity.y += 0.7;
|
||||
m.velocity.z += f64::from(sz) * 0.6;
|
||||
m.nav_stop();
|
||||
}
|
||||
fn stop(&mut self, m: &mut Mob, _: &mut Cx) {
|
||||
m.head_pitch = 0.0;
|
||||
}
|
||||
fn tick(&mut self, m: &mut Mob, cx: &mut Cx) {
|
||||
let already = self.breached;
|
||||
if !already {
|
||||
self.breached = cx.w.fluid(
|
||||
m.position.x.floor() as i32,
|
||||
m.position.y.floor() as i32,
|
||||
m.position.z.floor() as i32,
|
||||
) == Fluid::Water;
|
||||
}
|
||||
if self.breached && !already {
|
||||
m.sound("entity.dolphin.jump", cx.events);
|
||||
}
|
||||
let v = m.velocity;
|
||||
if v.y * v.y < f64::from(0.03f32) && m.head_pitch != 0.0 {
|
||||
// Mth.rotLerp(0.2, xRot, 0).
|
||||
m.head_pitch += 0.2 * super::living::wrap(0.0 - m.head_pitch);
|
||||
} else if v.length() > f64::from(1.0e-5f32) {
|
||||
let horizontal = v.x.hypot(v.z);
|
||||
m.head_pitch = ((-v.y).atan2(horizontal) * f64::from(180.0f32)
|
||||
/ f64::from(std::f32::consts::PI)) as f32;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -604,6 +604,11 @@ impl Mob {
|
||||
pub fn can_see_player(&mut self, w: &MobWorld, range: f64) -> bool {
|
||||
self.player_in_range(w, range, true, true)
|
||||
}
|
||||
/// `TargetingConditions.forNonCombat().range(range).ignoreLineOfSight()`
|
||||
/// for the player (still scaled by visibility).
|
||||
pub fn can_see_player_through_walls(&mut self, w: &MobWorld, range: f64) -> bool {
|
||||
self.player_in_range(w, range, false, true)
|
||||
}
|
||||
/// `scale` is `TargetingConditions.testInvisible`: scale the range by
|
||||
/// the player's visibility.
|
||||
fn player_in_range(
|
||||
|
||||
@@ -81,6 +81,11 @@ impl Opt {
|
||||
Opt::Narrator
|
||||
| Opt::NarratorHotkey
|
||||
| Opt::ChatDelay
|
||||
// Stored, but there are no blocked players, signed chat or
|
||||
// chat drafts yet.
|
||||
| Opt::HideMatchedNames
|
||||
| Opt::OnlySecureChat
|
||||
| Opt::SaveChatDrafts
|
||||
| Opt::DistortionEffects
|
||||
| Opt::MonochromeLogo
|
||||
| Opt::RotateWithMinecarts
|
||||
@@ -96,6 +101,9 @@ impl Opt {
|
||||
Opt::Narrator => "narrator",
|
||||
Opt::TextBackground => "backgroundForChatOnly",
|
||||
Opt::ChatDelay => "chatDelay",
|
||||
Opt::HideMatchedNames => "hideMatchedNames",
|
||||
Opt::OnlySecureChat => "onlyShowSecureChat",
|
||||
Opt::SaveChatDrafts => "saveChatDrafts",
|
||||
Opt::DistortionEffects => "screenEffectScale",
|
||||
Opt::FovEffects => "fovEffectScale",
|
||||
Opt::DarknessPulsing => "darknessEffectScale",
|
||||
@@ -164,6 +172,9 @@ impl Opt {
|
||||
Opt::ChatHeightUnfocused => "options.chat.height.unfocused",
|
||||
Opt::ChatLineSpacing => "options.chat.line_spacing",
|
||||
Opt::AutoSuggestions => "options.autoSuggestCommands",
|
||||
Opt::HideMatchedNames => "options.hideMatchedNames",
|
||||
Opt::OnlySecureChat => "options.onlyShowSecureChat",
|
||||
Opt::SaveChatDrafts => "options.chat.drafts",
|
||||
Opt::ReducedDebugInfo => "options.reducedDebugInfo",
|
||||
Opt::HighContrast => "options.accessibility.high_contrast",
|
||||
Opt::ShowSubtitles => "options.showSubtitles",
|
||||
@@ -437,6 +448,9 @@ impl Opt {
|
||||
Opt::HideLightningFlashes => on_off(s.file.bool("hideLightningFlashes")),
|
||||
Opt::MonochromeLogo => on_off(s.file.bool("darkMojangStudiosBackground")),
|
||||
Opt::HideSplashTexts => on_off(s.file.bool("hideSplashTexts")),
|
||||
Opt::HideMatchedNames | Opt::OnlySecureChat | Opt::SaveChatDrafts => {
|
||||
on_off(s.file.bool(self.file_key().unwrap()))
|
||||
}
|
||||
Opt::NarratorHotkey => on_off(s.file.bool("narratorHotkey")),
|
||||
Opt::RotateWithMinecarts => on_off(s.file.bool("rotateWithMinecart")),
|
||||
Opt::HighContrastBlockOutlines => on_off(s.file.bool("highContrastBlockOutline")),
|
||||
@@ -635,7 +649,12 @@ impl Opt {
|
||||
value + 1
|
||||
};
|
||||
}
|
||||
Opt::TextBackground | Opt::HideLightningFlashes | Opt::HideSplashTexts => {
|
||||
Opt::TextBackground
|
||||
| Opt::HideLightningFlashes
|
||||
| Opt::HideSplashTexts
|
||||
| Opt::HideMatchedNames
|
||||
| Opt::OnlySecureChat
|
||||
| Opt::SaveChatDrafts => {
|
||||
let key = self.file_key().unwrap();
|
||||
s.file
|
||||
.set(key, crate::options_file::V::Bool(!s.file.bool(key)));
|
||||
@@ -1434,7 +1453,10 @@ impl OptionsUi {
|
||||
Opt::ChatHeightFocused,
|
||||
Opt::ChatHeightUnfocused,
|
||||
Opt::AutoSuggestions,
|
||||
Opt::HideMatchedNames,
|
||||
Opt::ReducedDebugInfo,
|
||||
Opt::OnlySecureChat,
|
||||
Opt::SaveChatDrafts,
|
||||
]),
|
||||
Page::Accessibility => {
|
||||
let mut rows = vec![Row::Buttons(
|
||||
|
||||
@@ -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])
|
||||
|
||||
@@ -659,7 +659,10 @@ pub enum Opt {
|
||||
ChatHeightUnfocused,
|
||||
ChatLineSpacing,
|
||||
AutoSuggestions,
|
||||
HideMatchedNames,
|
||||
ReducedDebugInfo,
|
||||
OnlySecureChat,
|
||||
SaveChatDrafts,
|
||||
HighContrast,
|
||||
ShowSubtitles,
|
||||
MusicFrequency,
|
||||
|
||||
@@ -619,8 +619,9 @@ impl Behaviours {
|
||||
}
|
||||
|
||||
/// `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.
|
||||
/// lights the ore, `DragonEggBlock.attack` teleports the egg,
|
||||
/// `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,
|
||||
@@ -630,6 +631,9 @@ impl Behaviours {
|
||||
let mut sim = self.sim(level, ticks);
|
||||
let state = sim.state(pos);
|
||||
let chain = &self.data(state).chain;
|
||||
if chain.contains(&Class::DragonEgg) {
|
||||
sim.dragon_egg_teleport(pos, state);
|
||||
}
|
||||
if chain.contains(&Class::Note) {
|
||||
sim.note_play(pos, state);
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user