Fix up the merged parity branches so the workspace builds
Resolve the places where union merges kept both sides: the persist rewrite of level.dat now carries item components, XP seed and effects; mob ticking uses the creatures module (with Thorns); explosions damage mobs through the new damage source and emit particles; TNT's white flash moves to overlay 5 since clouds use 4; End gateway data follows the new dimensions/ folder layout. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -72,16 +72,6 @@ impl BlockEntity {
|
||||
if name == "minecraft:brewing_stand" {
|
||||
return Some(Self::Brewing(Box::new(crate::brewing::BrewingStand::new())));
|
||||
}
|
||||
matches!(
|
||||
name,
|
||||
"minecraft:chest" | "minecraft:trapped_chest" | "minecraft:barrel"
|
||||
)
|
||||
.then(|| Self::Chest(vec![None; 27]))
|
||||
}
|
||||
pub fn id(&self) -> &'static str {
|
||||
match self {
|
||||
Self::Chest(_) => "minecraft:chest",
|
||||
Self::Brewing(_) => "minecraft:brewing_stand",
|
||||
let size = match name {
|
||||
"minecraft:chest" | "minecraft:trapped_chest" | "minecraft:barrel" => 27,
|
||||
"minecraft:hopper" => 5,
|
||||
@@ -117,6 +107,7 @@ impl BlockEntity {
|
||||
FurnaceKind::BlastFurnace => "minecraft:blast_furnace",
|
||||
FurnaceKind::Smoker => "minecraft:smoker",
|
||||
},
|
||||
Self::Brewing(_) => "minecraft:brewing_stand",
|
||||
Self::Sign(s) => s.id(),
|
||||
}
|
||||
}
|
||||
@@ -125,13 +116,15 @@ impl BlockEntity {
|
||||
Self::Chest(items) => items.iter().flatten().cloned().collect(),
|
||||
Self::Furnace(f) => f.items.iter().flatten().cloned().collect(),
|
||||
Self::Brewing(b) => b.items.iter().flatten().cloned().collect(),
|
||||
Self::Sign(_) => Vec::new(),
|
||||
}
|
||||
}
|
||||
pub fn slots(&self) -> &[Option<ItemStack>] {
|
||||
match self {
|
||||
Self::Chest(items) => items,
|
||||
Self::Furnace(f) => &f.items,
|
||||
Self::Sign(_) => Vec::new(),
|
||||
Self::Brewing(b) => &b.items,
|
||||
Self::Sign(_) => &[],
|
||||
}
|
||||
}
|
||||
pub fn slots_mut(&mut self) -> &mut [Option<ItemStack>] {
|
||||
|
||||
@@ -23,7 +23,7 @@ struct Out {
|
||||
@location(1) color: vec4<f32>,
|
||||
@location(2) spherical: f32,
|
||||
@location(3) cylindrical: f32,
|
||||
@location(4) flash: f32,
|
||||
@location(5) flash: f32,
|
||||
@location(4) @interpolate(flat) overlay: u32,
|
||||
}
|
||||
@vertex fn vs_entity(@location(0) position: vec3<f32>, @location(1) uv: vec2<f32>,
|
||||
@@ -39,11 +39,11 @@ struct Out {
|
||||
// Hurt overlay (OverlayTexture red tint).
|
||||
if overlay == 1u { c = vec4(mix(c.rgb, vec3(1.0, 0.0, 0.0), 0.3), c.a); }
|
||||
out.color = c;
|
||||
// Overlay 4: OverlayTexture white flash (primed TNT), applied after texturing.
|
||||
out.flash = select(0.0, 0.75, overlay == 4u);
|
||||
// Overlay 5: OverlayTexture white flash (primed TNT), applied after texturing.
|
||||
out.flash = select(0.0, 0.75, overlay == 5u);
|
||||
// Sky geometry (clouds, celestial bodies) is exempt from render-distance fog.
|
||||
out.spherical = select(length(position), 0.0, overlay >= 2u);
|
||||
out.cylindrical = select(max(length(position.xz), abs(position.y)), 0.0, overlay >= 2u);
|
||||
out.spherical = select(length(position), 0.0, overlay >= 2u && overlay <= 4u);
|
||||
out.cylindrical = select(max(length(position.xz), abs(position.y)), 0.0, overlay >= 2u && overlay <= 4u);
|
||||
out.overlay = overlay;
|
||||
if overlay == 4u { out.spherical = length(position); }
|
||||
return out;
|
||||
@@ -55,7 +55,6 @@ fn linear_fog(d: f32, start: f32, end: f32) -> f32 {
|
||||
}
|
||||
@fragment fn fs_entity(in: Out) -> @location(0) vec4<f32> {
|
||||
var color = textureSample(atlas, atlas_sampler, in.uv) * in.color;
|
||||
let color = textureSample(atlas, atlas_sampler, in.uv) * in.color;
|
||||
if in.overlay == 4u {
|
||||
// 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)));
|
||||
|
||||
@@ -321,7 +321,7 @@ mod tests {
|
||||
fn item_entities_round_trip() {
|
||||
let e = ItemEntity {
|
||||
id: 7,
|
||||
stack: ItemStack { item: Arc::from("minecraft:diamond_pickaxe"), count: 1, damage: 5 },
|
||||
stack: ItemStack { item: Arc::from("minecraft:diamond_pickaxe"), count: 1, damage: 5, extra: None },
|
||||
position: Vec3::new(100.5, 64.0, -31.5),
|
||||
previous: Vec3::ZERO,
|
||||
velocity: Vec3::new(0.0, -0.04, 0.0),
|
||||
|
||||
@@ -17,7 +17,6 @@ mod tnt;
|
||||
mod remote;
|
||||
mod chat;
|
||||
mod commands;
|
||||
mod control;
|
||||
mod options;
|
||||
mod packs;
|
||||
mod screens;
|
||||
@@ -233,6 +232,7 @@ struct GameLevel<'w> {
|
||||
behaviours: &'w Behaviours,
|
||||
items: &'w Items,
|
||||
registry: &'static horizon_world::registry::BlockRegistry,
|
||||
rules: horizon_world::level::GameRules,
|
||||
}
|
||||
impl LevelAccess for GameLevel<'_> {
|
||||
fn precipitation(&self, pos: BlockPos) -> Option<horizon_world::level::Precipitation> {
|
||||
@@ -253,9 +253,7 @@ impl LevelAccess for GameLevel<'_> {
|
||||
}
|
||||
fn day_time(&self) -> i64 {
|
||||
self.world.day_time
|
||||
rules: horizon_world::level::GameRules,
|
||||
}
|
||||
impl LevelAccess for GameLevel<'_> {
|
||||
}
|
||||
fn game_rules(&self) -> horizon_world::level::GameRules {
|
||||
self.rules
|
||||
}
|
||||
@@ -277,9 +275,8 @@ impl LevelAccess for GameLevel<'_> {
|
||||
if self.dimension != LevelDimension::Overworld { 0 } else { MIN_Y }
|
||||
}
|
||||
fn max_y(&self) -> i32 {
|
||||
if self.dimension != LevelDimension::Overworld { 255 } else { MIN_Y + HEIGHT - 1 }
|
||||
// Exclusive, as LevelAccess::max_y documents.
|
||||
if self.dimension == LevelDimension::Nether { 256 } else { MIN_Y + HEIGHT }
|
||||
if self.dimension != LevelDimension::Overworld { 256 } else { MIN_Y + HEIGHT }
|
||||
}
|
||||
fn random(&mut self) -> &mut horizon_core::random::LegacyRandom {
|
||||
&mut self.world.random
|
||||
@@ -497,14 +494,6 @@ impl Dim {
|
||||
_ => Self::Overworld,
|
||||
}
|
||||
}
|
||||
/// Region folder inside the world (vanilla's DIM-1 for the Nether).
|
||||
fn folder(self) -> Option<&'static str> {
|
||||
match self {
|
||||
Self::Overworld => None,
|
||||
Self::Nether => Some("DIM-1"),
|
||||
Self::End => Some("DIM1"),
|
||||
}
|
||||
}
|
||||
}
|
||||
fn facing_offset(facing: &str) -> [i32; 3] {
|
||||
match facing {
|
||||
@@ -775,7 +764,6 @@ impl Game<'_> {
|
||||
Dim::Nether => LevelDimension::Nether,
|
||||
Dim::End => LevelDimension::End,
|
||||
};
|
||||
let dimension = if self.dim == Dim::Nether { LevelDimension::Nether } else { LevelDimension::Overworld };
|
||||
let rules = self.level_rules();
|
||||
let mut level = GameLevel {
|
||||
world: &mut self.world,
|
||||
@@ -917,7 +905,7 @@ impl Game<'_> {
|
||||
LevelEvent::BlockEvent { pos, state, kind: "dispense" } => self.dispense_from(pos, state)?,
|
||||
LevelEvent::BlockEvent { pos, state, kind: "pop_block_item" } => {
|
||||
let item = self.res.facts.get(state).item.clone();
|
||||
self.pop_resource([pos.x, pos.y, pos.z], ItemStack { item, count: 1, damage: 0 });
|
||||
self.pop_resource([pos.x, pos.y, pos.z], ItemStack { item, count: 1, damage: 0, extra: None });
|
||||
}
|
||||
LevelEvent::GrowTree { .. } | LevelEvent::PlaceFeature { .. } | LevelEvent::BlockEvent { .. } | LevelEvent::GameEvent { .. } => {}
|
||||
}
|
||||
@@ -1080,8 +1068,7 @@ impl Game<'_> {
|
||||
}
|
||||
let Some(stack) = self.held().cloned() else { return Ok(()) };
|
||||
let Some(info) = self.res.items.get(&stack.item).cloned() else { return Ok(()) };
|
||||
if self.use_potion_item(&stack)? {
|
||||
if self.throw_item(&stack)? {
|
||||
if self.use_potion_item(&stack)? || self.throw_item(&stack)? {
|
||||
return Ok(());
|
||||
}
|
||||
if &*stack.item == "minecraft:bow" {
|
||||
@@ -1549,12 +1536,6 @@ impl Game<'_> {
|
||||
}
|
||||
self.tick_block_entities()?;
|
||||
self.tick_brewing_stands()?;
|
||||
let facts = &self.res.facts;
|
||||
let world = &self.world;
|
||||
self.particles.retain_mut(|p| p.tick(world, |id| facts.states[id as usize].full_collision));
|
||||
if self.particles.len() > 4000 {
|
||||
let excess = self.particles.len() - 4000;
|
||||
self.particles.drain(..excess);
|
||||
if let Some(r) = &self.renderer {
|
||||
let eye = self.player.as_ref().map(|p| [p.position.x, p.position.y + f64::from(self.eye), p.position.z]);
|
||||
self.res.block_entity_render.tick(r.block_entities(), eye);
|
||||
@@ -1896,8 +1877,7 @@ impl Game<'_> {
|
||||
}
|
||||
/// InventoryMenu / CraftingMenu slot layouts.
|
||||
fn slot_position(&self, i: usize) -> (f32, f32) {
|
||||
if let Some(p) = self.station_slot_position(i) {
|
||||
if let Some(p) = self.machine_slot_position(i) {
|
||||
if let Some(p) = self.station_slot_position(i).or_else(|| self.machine_slot_position(i)) {
|
||||
return p;
|
||||
}
|
||||
let table = self.craft_size == 3;
|
||||
@@ -2066,6 +2046,7 @@ impl Game<'_> {
|
||||
fn click_inventory(&mut self, right: bool) {
|
||||
if self.station_click(right) {
|
||||
return;
|
||||
}
|
||||
if self.remote.is_some() {
|
||||
return self.remote_click(right);
|
||||
}
|
||||
@@ -2372,11 +2353,6 @@ impl Game<'_> {
|
||||
}
|
||||
}
|
||||
self.tnt_geometry(camera, alpha, &mut out);
|
||||
// Camera-facing particle quads.
|
||||
let (yaw, pitch) = (self.yaw.to_radians(), self.pitch.to_radians());
|
||||
let forward = glam::Vec3::new(-yaw.sin() * pitch.cos(), -pitch.sin(), yaw.cos() * pitch.cos());
|
||||
let right = forward.cross(glam::Vec3::Y).normalize_or_zero();
|
||||
let up = right.cross(forward).normalize_or_zero();
|
||||
// Particles (ParticleEngine.extract): camera-facing quads.
|
||||
let world = &self.world;
|
||||
self.particles.render(camera, self.yaw, self.pitch, alpha as f32, &|b| world.light(b[0], b[1], b[2]), &mut out);
|
||||
@@ -2531,90 +2507,6 @@ impl Game<'_> {
|
||||
/// default mobGriefing rule).
|
||||
fn explode(&mut self, center: [f64; 3], radius: f32) -> Result<()> {
|
||||
self.server_explode(center, radius, explosion::BlockInteraction::DestroyWithDecay, false)
|
||||
let mut destroyed = HashSet::new();
|
||||
for j in 0..16 {
|
||||
for k in 0..16 {
|
||||
for l in 0..16 {
|
||||
if !(j == 0 || j == 15 || k == 0 || k == 15 || l == 0 || l == 15) {
|
||||
continue;
|
||||
}
|
||||
let mut d = [f64::from(j) / 15.0 * 2.0 - 1.0, f64::from(k) / 15.0 * 2.0 - 1.0, f64::from(l) / 15.0 * 2.0 - 1.0];
|
||||
let len = (d[0] * d[0] + d[1] * d[1] + d[2] * d[2]).sqrt();
|
||||
d = d.map(|v| v / len);
|
||||
let mut h = radius * (0.7 + self.world.random.next_float() * 0.6);
|
||||
let mut p = center;
|
||||
while h > 0.0 {
|
||||
let b = [p[0].floor() as i32, p[1].floor() as i32, p[2].floor() as i32];
|
||||
let state = self.world.block(b[0], b[1], b[2]);
|
||||
if !self.res.facts.is_air(state) {
|
||||
let f = self.res.facts.get(state);
|
||||
let resistance = if f.fluid != Fluid::None && !f.waterlogged { 100.0 } else { f.explosion_resistance };
|
||||
h -= (resistance + 0.3) * 0.3;
|
||||
if h > 0.0 && f.hardness >= 0.0 {
|
||||
destroyed.insert(b);
|
||||
}
|
||||
}
|
||||
p = [p[0] + d[0] * 0.3, p[1] + d[1] * 0.3, p[2] + d[2] * 0.3];
|
||||
h -= 0.225_000_01;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let destroyed_count = destroyed.len();
|
||||
for b in destroyed {
|
||||
let state = self.world.block(b[0], b[1], b[2]);
|
||||
if self.res.facts.is_air(state) {
|
||||
continue;
|
||||
}
|
||||
// Explosion decay: each drop survives with probability 1 / radius.
|
||||
if self.world.random.next_float() < 1.0 / radius {
|
||||
let drops = self.res.items.block_drops(&self.res.assets.registry, state, None, &mut self.world.random);
|
||||
for d in drops {
|
||||
self.pop_resource(b, d);
|
||||
}
|
||||
}
|
||||
self.world.set(b[0], b[1], b[2], self.world.air)?;
|
||||
}
|
||||
let (world, facts) = (&self.world, &self.res.facts);
|
||||
self.particles.explosion(center, radius, destroyed_count, &|b| facts.is_air(world.block(b[0], b[1], b[2])));
|
||||
self.audio.play("minecraft:entity.generic.explode", Some(center), 4.0, (1.0 + (self.world.random.next_float() - self.world.random.next_float()) * 0.2) * 0.7);
|
||||
// Entity damage by distance (exposure approximated as unobstructed).
|
||||
let diameter = f64::from(radius) * 2.0;
|
||||
let mut armor_damage = None;
|
||||
if let Some(player) = self.player.as_mut() {
|
||||
let p = [player.position.x, player.position.y, player.position.z];
|
||||
let dist = ((p[0] - center[0]).powi(2) + (p[1] - center[1]).powi(2) + (p[2] - center[2]).powi(2)).sqrt() / diameter;
|
||||
if dist <= 1.0 {
|
||||
let impact = 1.0 - dist;
|
||||
let damage = ((impact * impact + impact) / 2.0 * 7.0 * diameter + 1.0) as f32;
|
||||
if let Some(id) = self.motion.health.damage.id("minecraft:explosion") {
|
||||
let _ = player.hurt(&self.motion.health, self.world.health_rules, id, damage);
|
||||
armor_damage = Some(damage);
|
||||
}
|
||||
let (dx, dy, dz) = (p[0] - center[0], p[1] - center[1], p[2] - center[2]);
|
||||
let l = (dx * dx + dy * dy + dz * dz).sqrt().max(1e-4);
|
||||
player.velocity = Vec3::new(player.velocity.x + dx / l * impact, player.velocity.y + dy / l * impact, player.velocity.z + dz / l * impact);
|
||||
}
|
||||
}
|
||||
if let Some(d) = armor_damage
|
||||
&& !self.creative
|
||||
{
|
||||
self.hurt_armor(d);
|
||||
}
|
||||
for m in &mut self.mobs {
|
||||
let dist = ((m.position.x - center[0]).powi(2) + (m.position.y - center[1]).powi(2) + (m.position.z - center[2]).powi(2)).sqrt() / diameter;
|
||||
if dist <= 1.0 && m.alive() {
|
||||
let impact = 1.0 - dist;
|
||||
let source = horizon_client::mobs::Damage { kind: horizon_client::mobs::DamageKind::Explosion, attacker: None, from: Some(center) };
|
||||
if m.damage(((impact * impact + impact) / 2.0 * 7.0 * diameter + 1.0) as f32, source) {
|
||||
let (dx, dy, dz) = (m.position.x - center[0], m.position.y - center[1], m.position.z - center[2]);
|
||||
let l = (dx * dx + dy * dy + dz * dz).sqrt().max(1e-4);
|
||||
let k = impact * (1.0 - m.kind.knockback_resistance);
|
||||
m.velocity = Vec3::new(m.velocity.x + dx / l * k, m.velocity.y + dy / l * k, m.velocity.z + dz / l * k);
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
fn tick_block_entities(&mut self) -> Result<()> {
|
||||
self.tick_hoppers()?;
|
||||
@@ -2663,153 +2555,6 @@ impl Game<'_> {
|
||||
Arc::new(c)
|
||||
}
|
||||
fn tick_mobs(&mut self) -> Result<()> {
|
||||
self.attack_ticks = self.attack_ticks.saturating_add(1);
|
||||
// Generation-time creature packs for newly generated chunks.
|
||||
let fresh: Vec<(i32, i32)> = self.world.chunks.iter().filter(|(_, c)| c.fresh && c.lit).map(|(k, _)| *k).collect();
|
||||
for key in fresh {
|
||||
if let Some(c) = self.world.chunks.get_mut(&key) {
|
||||
Arc::make_mut(c).fresh = false;
|
||||
}
|
||||
self.spawn_chunk_creatures(key.0, key.1);
|
||||
}
|
||||
if self.ticks % 2 == 0 {
|
||||
self.spawn_monsters();
|
||||
}
|
||||
let player = self.player.as_ref().map(|p| ([p.position.x, p.position.y + 0.5, p.position.z], !p.health.dead_or_dying()));
|
||||
let daylight = self.sky_darken() < 4 && self.world.weather.levels(1.0).0 < 0.2;
|
||||
let mut events = Vec::new();
|
||||
let mut mobs = std::mem::take(&mut self.mobs);
|
||||
{
|
||||
let w = MobWorld { world: &self.world, facts: &self.res.facts, collision: self.collision, player, daylight };
|
||||
let random = &mut self.world.random.clone();
|
||||
let loaded = |m: &Mob| w.world.loaded(m.position.x.floor() as i32, m.position.z.floor() as i32);
|
||||
let mut dead = Vec::new();
|
||||
mobs.retain_mut(|m| {
|
||||
if !loaded(m) {
|
||||
return !m.hostile() || m.persistent;
|
||||
}
|
||||
let keep = m.tick(&w, random, &mut events);
|
||||
if !keep && !m.alive() {
|
||||
dead.push((m.kind.id.clone(), [m.position.x, m.position.y, m.position.z], m.id));
|
||||
}
|
||||
keep
|
||||
});
|
||||
self.world.random = random.clone();
|
||||
for (kind, pos, id) in dead {
|
||||
let by_player = self.last_hurt_by_player.remove(&id);
|
||||
let held = self.held().cloned();
|
||||
let drops = self.res.items.entity_drops(&kind, by_player, held.as_ref(), &mut self.world.random);
|
||||
for d in drops {
|
||||
self.spawn_item(d, [pos[0], pos[1] + 0.5, pos[2]], [0.0, 0.2, 0.0], 10);
|
||||
}
|
||||
if by_player {
|
||||
// Animal: 1 + random(3); Monster: 5.
|
||||
let hostile = self.res.mob_types.get(&kind).is_some_and(|t| t.category == "monster");
|
||||
let xp = if hostile { 5 } else { 1 + self.world.random.next_int_bound(3).unwrap_or(0) as u32 };
|
||||
self.spawn_orbs([pos[0], pos[1] + 0.5, pos[2]], xp);
|
||||
}
|
||||
}
|
||||
}
|
||||
self.mobs = mobs;
|
||||
for e in events {
|
||||
match e {
|
||||
MobEvent::Sound(name, at, volume, pitch) => self.audio.play(&format!("minecraft:{name}"), Some(at), volume, pitch),
|
||||
MobEvent::AttackPlayer(amount, from) => {
|
||||
if self.creative {
|
||||
continue;
|
||||
}
|
||||
if let Some(player) = self.player.as_mut()
|
||||
&& let Some(id) = self.motion.health.damage.id("minecraft:mob_attack")
|
||||
&& player.hurt(&self.motion.health, self.world.health_rules, id, amount).unwrap_or(false)
|
||||
{
|
||||
let (dx, dz) = (player.position.x - from[0], player.position.z - from[2]);
|
||||
let l = (dx * dx + dz * dz).sqrt().max(1e-4);
|
||||
player.velocity = Vec3::new(player.velocity.x / 2.0 + dx / l * 0.4, (player.velocity.y / 2.0 + 0.4).min(0.4), player.velocity.z / 2.0 + dz / l * 0.4);
|
||||
let at = [player.position.x, player.position.y, player.position.z];
|
||||
self.audio.play("minecraft:entity.player.hurt", Some(at), 1.0, 1.0);
|
||||
self.hurt_armor(amount);
|
||||
self.thorns(from);
|
||||
}
|
||||
}
|
||||
MobEvent::Shoot(from, target) => {
|
||||
// Skeleton.performRangedAttack: aim above by 20% of distance, inaccuracy 14 - 4 * difficulty(2).
|
||||
let (dx, dz) = (target[0] - from[0], target[2] - from[2]);
|
||||
let horizontal = (dx * dx + dz * dz).sqrt();
|
||||
let dy = target[1] + 0.5 - from[1] + horizontal * 0.2;
|
||||
let len = (dx * dx + dy * dy + dz * dz).sqrt().max(1e-4);
|
||||
let spread = 0.0075 * 6.0;
|
||||
let r = &mut self.world.random;
|
||||
let mut gauss = || f64::from(r.next_float() + r.next_float() - 1.0) * spread;
|
||||
let v = [(dx / len + gauss()) * 1.6, (dy / len + gauss()) * 1.6, (dz / len + gauss()) * 1.6];
|
||||
let p = Vec3::new(from[0], from[1] - 0.1, from[2]);
|
||||
self.arrows.push(Arrow { from_player: false, critical: false, position: p, previous: p, velocity: Vec3::new(v[0], v[1], v[2]), stuck: false, age: 0, base_damage: 2.0 });
|
||||
self.audio.play("minecraft:entity.skeleton.shoot", Some(from), 1.0, 1.0 / (self.world.random.next_float() * 0.4 + 0.8));
|
||||
}
|
||||
MobEvent::Explode(at, radius) => self.explode(at, radius)?,
|
||||
}
|
||||
}
|
||||
// Arrows.
|
||||
let bounds = self.player.as_ref().map(|p| {
|
||||
let w = f64::from(p.dimensions.width) / 2.0;
|
||||
horizon_core::geometry::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 mut arrows = std::mem::take(&mut self.arrows);
|
||||
let mut hits = Vec::new();
|
||||
let mobs = &mut self.mobs;
|
||||
let mut random_state = self.world.random.clone();
|
||||
let random = &mut random_state;
|
||||
let mut mob_hits = Vec::new();
|
||||
arrows.retain_mut(|a| {
|
||||
if a.from_player && !a.stuck {
|
||||
let (keep, _) = a.tick(&self.world, &self.res.facts, None);
|
||||
for m in mobs.iter_mut().filter(|m| m.alive()) {
|
||||
let b = m.bounds();
|
||||
let (lo, hi) = (b.min_position(), b.max_position());
|
||||
let p = a.position;
|
||||
if p.x > lo.x - 0.3 && p.x < hi.x + 0.3 && p.y > lo.y - 0.3 && p.y < hi.y + 0.3 && p.z > lo.z - 0.3 && p.z < hi.z + 0.3 {
|
||||
// AbstractArrow.onHitEntity: ceil(speed * base), crits add random(damage / 2 + 2).
|
||||
let speed = (a.velocity.x.powi(2) + a.velocity.y.powi(2) + a.velocity.z.powi(2)).sqrt();
|
||||
let mut damage = (speed * a.base_damage).ceil().max(0.0) as i32;
|
||||
if a.critical {
|
||||
damage += random.next_int_bound(damage / 2 + 2).unwrap_or(0);
|
||||
}
|
||||
if m.hurt(damage as f32, Some([a.previous.x, a.previous.y, a.previous.z]), random) {
|
||||
mob_hits.push((m.id, [p.x, p.y, p.z]));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return keep;
|
||||
}
|
||||
let (keep, hit) = a.tick(&self.world, &self.res.facts, if a.from_player { None } else { bounds });
|
||||
if let ArrowHit::Player(d) = hit {
|
||||
hits.push(d);
|
||||
}
|
||||
keep
|
||||
});
|
||||
self.arrows = arrows;
|
||||
self.world.random = random_state;
|
||||
for (id, at) in mob_hits {
|
||||
self.last_hurt_by_player.insert(id);
|
||||
self.audio.play("minecraft:entity.arrow.hit", Some(at), 1.0, 1.2 / (self.world.random.next_float() * 0.2 + 0.9));
|
||||
}
|
||||
for d in hits {
|
||||
if self.creative {
|
||||
continue;
|
||||
}
|
||||
if let Some(player) = self.player.as_mut()
|
||||
&& let Some(id) = self.motion.health.damage.id("minecraft:arrow")
|
||||
{
|
||||
let _ = player.hurt(&self.motion.health, self.world.health_rules, id, d);
|
||||
let at = [player.position.x, player.position.y, player.position.z];
|
||||
self.audio.play("minecraft:entity.arrow.hit_player", Some(at), 1.0, 1.0);
|
||||
self.hurt_armor(d);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
self.tick_creatures()
|
||||
}
|
||||
/// SkyRenderer.renderSunMoonAndStars: bodies on a frame rotated Y -90 then X by angle.
|
||||
@@ -3642,8 +3387,7 @@ impl Game<'_> {
|
||||
// BowItem.shootProjectile: shootFromRotation(power * 3, inaccuracy 1).
|
||||
let p = Vec3::new(eye[0], eye[1] - 0.1, eye[2]);
|
||||
let (power_bonus, infinity) = self.bow_enchantments();
|
||||
self.arrows.push(Arrow { from_player: true, critical: power >= 1.0, position: p, previous: p, velocity: Vec3::new(v[0], v[1], v[2]), stuck: false, age: 0, base_damage: 2.0 + power_bonus });
|
||||
let kind = horizon_client::projectiles::ProjectileKind::Arrow { base_damage: 2.0, critical: power >= 1.0, effect: None };
|
||||
let kind = horizon_client::projectiles::ProjectileKind::Arrow { base_damage: 2.0 + power_bonus, critical: power >= 1.0, effect: None };
|
||||
let mut arrow = horizon_client::projectiles::Projectile::new(kind, p, Some(horizon_client::mobs::Who::Player));
|
||||
let (velocity, on_ground) = self.player.as_ref().map_or((Vec3::ZERO, true), |pl| (pl.velocity, pl.ground.on_ground));
|
||||
arrow.shoot_from_rotation(&mut self.world.random, self.pitch, self.yaw, 0.0, power * 3.0, 1.0, velocity, on_ground);
|
||||
@@ -4632,32 +4376,6 @@ impl ApplicationHandler for Game<'_> {
|
||||
Screen::Creative if pressed => {
|
||||
self.click_creative(button == MouseButton::Right);
|
||||
}
|
||||
Screen::Paused if pressed => {
|
||||
let size = self.renderer.as_ref().map(|r| [r.config.width, r.config.height]).unwrap_or([1, 1]);
|
||||
let b = HudBatch::new(size);
|
||||
for i in 0..3 {
|
||||
let (bx, by) = (b.width / 2.0 - 100.0, b.height / 4.0 + 24.0 + i as f32 * 24.0 + 16.0);
|
||||
if self.cursor.0 >= bx && self.cursor.0 < bx + 200.0 && self.cursor.1 >= by && self.cursor.1 < by + 20.0 {
|
||||
if i == 0 {
|
||||
self.screen = Screen::Playing;
|
||||
self.capture(true);
|
||||
} else if i == 1 {
|
||||
self.screen = Screen::Options;
|
||||
self.options_from_title = false;
|
||||
} else {
|
||||
self.close_world()?;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Screen::Dead if pressed && self.remote.is_some() => self.remote_respawn(),
|
||||
Screen::Dead if pressed => {
|
||||
self.respawn_out_of_end()?;
|
||||
self.player = None;
|
||||
self.screen = Screen::Playing;
|
||||
self.spawn_player()?;
|
||||
self.capture(true);
|
||||
}
|
||||
Screen::Paused if pressed => self.pause_click()?,
|
||||
Screen::Dead if pressed => self.death_click()?,
|
||||
_ => {}
|
||||
|
||||
@@ -125,6 +125,7 @@ impl Game<'_> {
|
||||
item: item.as_str().into(),
|
||||
count,
|
||||
damage: 0,
|
||||
extra: None,
|
||||
});
|
||||
}
|
||||
let entity = self
|
||||
|
||||
@@ -406,7 +406,7 @@ impl Game<'_> {
|
||||
while remaining > 0 {
|
||||
let size = remaining.min(max_stack);
|
||||
remaining -= size;
|
||||
let left = self.give(ItemStack { item: id.as_str().into(), count: size as u32, damage: 0 });
|
||||
let left = self.give(ItemStack { item: id.as_str().into(), count: size as u32, damage: 0, extra: None });
|
||||
if let Some(rest) = left {
|
||||
// Inventory full: drop the rest at the player's feet without pickup delay.
|
||||
let p = self.source_position();
|
||||
@@ -706,11 +706,11 @@ impl Game<'_> {
|
||||
}
|
||||
let short = kind.trim_start_matches("minecraft:").to_owned();
|
||||
let name;
|
||||
if let Some(t) = self.res.mob_types.get(&short).cloned() {
|
||||
if let Some(t) = self.res.mob_types.get(&format!("minecraft:{short}")).cloned() {
|
||||
if self.ui.difficulty == 0 && t.category == "monster" {
|
||||
return Err(err("commands.summon.failed.peaceful", &[]));
|
||||
}
|
||||
self.add_mob(&short, pos[0], pos[1], pos[2], true);
|
||||
self.spawn_mob(&short, pos, true);
|
||||
name = Text::translate(&format!("entity.minecraft.{short}"), &[]);
|
||||
} else {
|
||||
match short.as_str() {
|
||||
|
||||
@@ -79,9 +79,12 @@ impl Game<'_> {
|
||||
return Ok(Some(value));
|
||||
}
|
||||
match words[0] {
|
||||
"help" => Ok(Some(json!({ "commands": HELP.iter().chain(super::station_control::HELP).collect::<Vec<_>>() }))),
|
||||
"help" => Ok(Some(json!({ "commands": HELP.iter().chain(super::blockctl::HELP).collect::<Vec<_>>() }))),
|
||||
"help" => Ok(Some(json!({ "commands": HELP.iter().chain(super::render_control::HELP).collect::<Vec<_>>() }))),
|
||||
"help" => Ok(Some(json!({ "commands": HELP
|
||||
.iter()
|
||||
.chain(super::station_control::HELP)
|
||||
.chain(super::blockctl::HELP)
|
||||
.chain(super::render_control::HELP)
|
||||
.collect::<Vec<_>>() }))),
|
||||
"setblock" | "fill" | "particle" | "signedit" => self.render_command(&words),
|
||||
"status" => Ok(Some(self.control_status())),
|
||||
"key" => {
|
||||
@@ -243,27 +246,6 @@ impl Game<'_> {
|
||||
let id = self.summon(arg(1)?, at, baby)?;
|
||||
Ok(Some(json!({ "ok": true, "id": id })))
|
||||
}
|
||||
"fill" => {
|
||||
self.require_world()?;
|
||||
let c: Vec<i32> = (1..=6).map(|i| arg(i).and_then(|v| v.parse::<i32>().map_err(|e| e.to_string()))).collect::<std::result::Result<_, _>>()?;
|
||||
let name = arg(7)?;
|
||||
let name = if name.contains(':') { name.to_owned() } else { format!("minecraft:{name}") };
|
||||
let state = self.res.assets.registry.default_state(&name).ok_or_else(|| format!("unknown block {name}"))?;
|
||||
let (lo, hi) = ([c[0].min(c[3]), c[1].min(c[4]), c[2].min(c[5])], [c[0].max(c[3]), c[1].max(c[4]), c[2].max(c[5])]);
|
||||
if (hi[0] - lo[0] + 1) * (hi[1] - lo[1] + 1) * (hi[2] - lo[2] + 1) > 1 << 20 {
|
||||
return Err("fill volume too large".into());
|
||||
}
|
||||
for x in lo[0]..=hi[0] {
|
||||
for y in lo[1]..=hi[1] {
|
||||
for z in lo[2]..=hi[2] {
|
||||
if self.world.loaded(x, z) {
|
||||
self.world.set(x, y, z, state)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ok()
|
||||
}
|
||||
"mobs" => {
|
||||
self.require_world()?;
|
||||
let radius: f64 = words.get(1).map_or(Ok(64.0), |r| r.parse())?;
|
||||
@@ -285,8 +267,12 @@ impl Game<'_> {
|
||||
Ok(None)
|
||||
}
|
||||
"chat" => {
|
||||
self.require_world()?;
|
||||
let text = line.trim_start().strip_prefix("chat").unwrap_or("").trim();
|
||||
if self.remote.is_some() {
|
||||
self.send_chat(text);
|
||||
return ok();
|
||||
}
|
||||
self.require_world()?;
|
||||
self.handle_chat_input(text);
|
||||
Ok(Some(json!({ "ok": true, "chat": self.ui.chat.recent_lines(5) })))
|
||||
}
|
||||
@@ -364,14 +350,6 @@ impl Game<'_> {
|
||||
self.connect_server(arg(1)?, &name)?;
|
||||
ok()
|
||||
}
|
||||
"chat" => {
|
||||
if self.remote.is_none() {
|
||||
return Err("not connected to a server".into());
|
||||
}
|
||||
let message = line.trim_start().strip_prefix("chat").unwrap_or("").trim();
|
||||
self.send_chat(message);
|
||||
ok()
|
||||
}
|
||||
"respawn" => {
|
||||
if self.remote.is_none() || self.screen != Screen::Dead {
|
||||
return Err("respawn needs the death screen on a server".into());
|
||||
|
||||
@@ -582,6 +582,7 @@ impl Game<'_> {
|
||||
item: item.clone(),
|
||||
count: 1,
|
||||
damage: 0,
|
||||
extra: None,
|
||||
},
|
||||
pos,
|
||||
[0.0, 0.2, 0.0],
|
||||
@@ -679,6 +680,7 @@ impl Game<'_> {
|
||||
item,
|
||||
count,
|
||||
damage: 0,
|
||||
extra: None,
|
||||
},
|
||||
at,
|
||||
[0.0, 0.2, 0.0],
|
||||
@@ -829,6 +831,7 @@ impl Game<'_> {
|
||||
self.audio
|
||||
.play("minecraft:entity.player.hurt", Some(at), 1.0, 1.0);
|
||||
self.hurt_armor(amount);
|
||||
self.thorns(from);
|
||||
}
|
||||
}
|
||||
/// Poison, wither, hunger and burning applied to the player by mobs.
|
||||
@@ -1314,6 +1317,7 @@ impl Game<'_> {
|
||||
item: g.into(),
|
||||
count: 1,
|
||||
damage: 0,
|
||||
extra: None,
|
||||
};
|
||||
if self.inventory[selected].is_none() {
|
||||
self.inventory[selected] = Some(stack);
|
||||
@@ -1334,6 +1338,7 @@ impl Game<'_> {
|
||||
item: item.as_str().into(),
|
||||
count: 1,
|
||||
damage: 0,
|
||||
extra: None,
|
||||
},
|
||||
[center[0], center[1] + 0.5, center[2]],
|
||||
v,
|
||||
|
||||
@@ -644,7 +644,7 @@ impl Game<'_> {
|
||||
|
||||
fn gateway_exits(&mut self) -> &mut HashMap<[i32; 3], ([i32; 3], bool)> {
|
||||
if self.end.exits.is_none() {
|
||||
let path = self.world_root.join("DIM1").join(GATEWAY_FILE);
|
||||
let path = horizon_client::save::dimension_dir(&self.world_root, "minecraft:the_end").join(GATEWAY_FILE);
|
||||
let parsed: Option<Vec<([i32; 3], [i32; 3], bool)>> = std::fs::read(&path)
|
||||
.ok()
|
||||
.and_then(|b| serde_json::from_slice(&b).ok());
|
||||
@@ -666,7 +666,7 @@ impl Game<'_> {
|
||||
.iter()
|
||||
.map(|(g, (e, x))| (*g, *e, *x))
|
||||
.collect();
|
||||
let dir = self.world_root.join("DIM1");
|
||||
let dir = horizon_client::save::dimension_dir(&self.world_root, "minecraft:the_end");
|
||||
std::fs::create_dir_all(&dir)?;
|
||||
std::fs::write(dir.join(GATEWAY_FILE), serde_json::to_vec(&list)?)?;
|
||||
Ok(())
|
||||
@@ -1278,6 +1278,7 @@ impl Game<'_> {
|
||||
item: "minecraft:ender_eye".into(),
|
||||
count: 1,
|
||||
damage: 0,
|
||||
extra: None,
|
||||
};
|
||||
self.spawn_item(stack, at, [vx, 0.2, vz], 0);
|
||||
}
|
||||
|
||||
@@ -247,9 +247,12 @@ impl Game<'_> {
|
||||
[feet[0] - w, feet[1], feet[2] - w],
|
||||
[feet[0] + w, feet[1] + h, feet[2] + w],
|
||||
);
|
||||
m.hurt(damage(dist, exposure), None, &mut self.world.random);
|
||||
let source = horizon_client::mobs::Damage { kind: horizon_client::mobs::DamageKind::Explosion, attacker: None, from: Some(center) };
|
||||
if !m.damage(damage(dist, exposure), source) {
|
||||
continue;
|
||||
}
|
||||
let dir = direction(eye);
|
||||
let power = (1.0 - dist) * f64::from(exposure);
|
||||
let power = (1.0 - dist) * f64::from(exposure) * (1.0 - m.kind.knockback_resistance);
|
||||
m.velocity = Vec3::new(
|
||||
m.velocity.x + dir[0] * power,
|
||||
m.velocity.y + dir[1] * power,
|
||||
@@ -354,6 +357,10 @@ impl Game<'_> {
|
||||
let pitch = (1.0 + (client_float() - client_float()) * 0.2) * 0.7;
|
||||
self.audio
|
||||
.play("minecraft:entity.generic.explode", Some(center), 4.0, pitch);
|
||||
let block_count = if interaction == BlockInteraction::Keep { 0 } else { targets.len() };
|
||||
let (world, facts) = (&self.world, &self.res.facts);
|
||||
self.particles
|
||||
.explosion(center, radius, block_count, &|b| facts.is_air(world.block(b[0], b[1], b[2])));
|
||||
Ok(())
|
||||
}
|
||||
/// `BlockBehaviour.onExplosionHit` (TNT: `wasExploded` primes a short fuse).
|
||||
@@ -448,6 +455,7 @@ mod tests {
|
||||
item: item.into(),
|
||||
count: 1,
|
||||
damage: 0,
|
||||
extra: None,
|
||||
};
|
||||
let mut stacks = Vec::new();
|
||||
for _ in 0..20 {
|
||||
|
||||
@@ -865,6 +865,7 @@ impl Game<'_> {
|
||||
item: "minecraft:bucket".into(),
|
||||
count: 1,
|
||||
damage: 0,
|
||||
extra: None,
|
||||
},
|
||||
)
|
||||
} else if (self.res.facts.is_air(target_state) || f.replaceable)
|
||||
@@ -896,6 +897,7 @@ impl Game<'_> {
|
||||
item: "minecraft:bucket".into(),
|
||||
count: 1,
|
||||
damage: 0,
|
||||
extra: None,
|
||||
},
|
||||
)
|
||||
} else {
|
||||
@@ -949,6 +951,7 @@ impl Game<'_> {
|
||||
item: filled.into(),
|
||||
count: 1,
|
||||
damage: 0,
|
||||
extra: None,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@@ -139,20 +139,44 @@ impl Game<'_> {
|
||||
let player_type = horizon_client::mobs::load_model(&root, "minecraft:player#main").map(|model| {
|
||||
Arc::new(MobType {
|
||||
id: "minecraft:player".into(),
|
||||
// Players render as a humanoid; the species only drives local AI.
|
||||
species: horizon_client::mobs::Species::Zombie,
|
||||
width: 0.6,
|
||||
height: 1.8,
|
||||
eye_height: 1.62,
|
||||
category: "misc".into(),
|
||||
max_health: 20.0,
|
||||
speed: 0.1,
|
||||
flying_speed: 0.02,
|
||||
attack_damage: 1.0,
|
||||
attack_knockback: 0.0,
|
||||
follow_range: 0.0,
|
||||
step_height: 0.6,
|
||||
armor: 0.0,
|
||||
armor_toughness: 0.0,
|
||||
knockback_resistance: 0.0,
|
||||
jump_strength: 0.42,
|
||||
gravity: 0.08,
|
||||
safe_fall_distance: 3.0,
|
||||
fall_damage_multiplier: 1.0,
|
||||
water_efficiency: 0.0,
|
||||
water_slowdown: 0.8,
|
||||
air_speed: 0.02,
|
||||
baby_scale: 0.5,
|
||||
head_rot_speed: 10.0,
|
||||
max_head_x_rot: 40.0,
|
||||
max_head_y_rot: 75.0,
|
||||
ambient_interval: 80,
|
||||
flags: Default::default(),
|
||||
model: Arc::new(model),
|
||||
layers: Default::default(),
|
||||
texture: "entity/player/wide/steve".into(),
|
||||
brain: Brain::Passive,
|
||||
anim: Anim::Humanoid { zombie_arms: false },
|
||||
sounds: ["entity.player.hurt", "entity.player.hurt", "entity.player.death"],
|
||||
step_sound: None,
|
||||
food: Arc::from([]),
|
||||
tempt: Arc::from([]),
|
||||
})
|
||||
});
|
||||
let mut streaming = Streaming::new(Arc::new(NoTerrain), self.res.context.clone(), self.res.threads);
|
||||
@@ -282,7 +306,7 @@ impl Game<'_> {
|
||||
}
|
||||
fn to_stack(&self, s: &Option<Stack>) -> Option<ItemStack> {
|
||||
let s = s.as_ref()?;
|
||||
Some(ItemStack { item: self.item_name(s.item), count: s.count.max(0) as u32, damage: s.damage().max(0) as u32 })
|
||||
Some(ItemStack { item: self.item_name(s.item), count: s.count.max(0) as u32, damage: s.damage().max(0) as u32, extra: None })
|
||||
}
|
||||
fn to_network(&self, s: &Option<ItemStack>) -> Option<Stack> {
|
||||
let s = s.as_ref()?;
|
||||
@@ -1016,9 +1040,7 @@ impl Game<'_> {
|
||||
}
|
||||
self.tick_remote_entities();
|
||||
self.tick_hand();
|
||||
let facts = &self.res.facts;
|
||||
let world = &self.world;
|
||||
self.particles.retain_mut(|p| p.tick(world, |id| facts.states[id as usize].full_collision));
|
||||
self.tick_particles();
|
||||
let Some(player) = self.player.as_mut() else { return Ok(()) };
|
||||
let (cx, cz) = ((player.position.x.floor() as i32) >> 4, (player.position.z.floor() as i32) >> 4);
|
||||
if !self.streaming.is_lit(cx, cz) {
|
||||
|
||||
@@ -106,7 +106,12 @@ impl Game<'_> {
|
||||
let b = HudBatch::new(size);
|
||||
let hit = death_buttons(b.width, b.height).into_iter().find(|d| ui::hovered(self.cursor, d.0, d.1, 200.0, 20.0)).map(|d| d.3);
|
||||
match hit {
|
||||
Some(0) if self.remote.is_some() => {
|
||||
self.ui.death_text = None;
|
||||
self.remote_respawn();
|
||||
}
|
||||
Some(0) => {
|
||||
self.respawn_out_of_end()?;
|
||||
self.player = None;
|
||||
self.screen = Screen::Playing;
|
||||
self.ui.death_text = None;
|
||||
|
||||
@@ -243,11 +243,11 @@ impl Game<'_> {
|
||||
.iter()
|
||||
.zip([[r.u0, r.v1], [r.u1, r.v1], [r.u1, r.v0], [r.u0, r.v0]])
|
||||
{
|
||||
// Overlay 4: OverlayTexture white flash.
|
||||
// Overlay 5: OverlayTexture white flash.
|
||||
out.push(Vertex {
|
||||
pos: p.to_array(),
|
||||
uv,
|
||||
layer: if lit { 4 } else { 0 },
|
||||
layer: if lit { 5 } else { 0 },
|
||||
color,
|
||||
light: packed,
|
||||
});
|
||||
|
||||
@@ -1281,15 +1281,13 @@ impl Renderer {
|
||||
..Default::default()
|
||||
});
|
||||
pass.set_bind_group(0, &self.group, &[]);
|
||||
if !frame.underwater && (frame.skybox || frame.end_sky) {
|
||||
if !frame.title && frame.skybox {
|
||||
// LevelRenderer: no sky inside lava or powder snow (sky fog ends within 2 blocks).
|
||||
let sky_visible = match frame.fog {
|
||||
Some(f) => f.sky_end > 2.0,
|
||||
None => !frame.underwater,
|
||||
};
|
||||
if sky_visible && frame.skybox {
|
||||
if !frame.title {
|
||||
if sky_visible && (frame.skybox || frame.end_sky) {
|
||||
if !frame.title && frame.skybox {
|
||||
pass.set_pipeline(&self.sky);
|
||||
pass.draw(0..3, 0..1);
|
||||
}
|
||||
|
||||
@@ -61,7 +61,8 @@ fn walk(dir: &Path, out: &mut Vec<PathBuf>) {
|
||||
impl HudAtlas {
|
||||
/// A font glyph's atlas cell (8x8 GUI pixels) and advance.
|
||||
pub fn glyph(&self, ch: char) -> Option<(Rect, f32)> {
|
||||
self.glyphs.get(&ch).map(|g| (g.rect, g.advance))
|
||||
let g = self.font.glyph(ch);
|
||||
g.rect.map(|rect| (rect, g.advance))
|
||||
}
|
||||
pub fn build(root: &Path) -> Result<Self> {
|
||||
let textures = root.join("assets/minecraft/textures");
|
||||
|
||||
@@ -282,7 +282,7 @@ pub struct Particle {
|
||||
removed: bool,
|
||||
pub age: i32,
|
||||
pub lifetime: i32,
|
||||
gravity: f32,
|
||||
pub gravity: f32,
|
||||
friction: f32,
|
||||
speed_up_when_y_blocked: bool,
|
||||
/// `quadSize`.
|
||||
|
||||
@@ -251,8 +251,8 @@ fn fluid_id(name: &str) -> Option<u32> {
|
||||
|
||||
fn encode_item(stack: &crate::items::ItemStack) -> Vec<(&'static str, Tag)> {
|
||||
let mut entries = vec![("id", string(&stack.item)), ("count", Tag::Int(stack.count as i32))];
|
||||
if stack.damage > 0 {
|
||||
entries.push(("components", Tag::compound([("minecraft:damage", Tag::Int(stack.damage as i32))])));
|
||||
if let Some(components) = crate::item_data::encode_components(stack) {
|
||||
entries.push(("components", components));
|
||||
}
|
||||
entries
|
||||
}
|
||||
@@ -266,8 +266,8 @@ pub fn item_from_nbt(tag: &Tag) -> Option<crate::items::ItemStack> {
|
||||
return None;
|
||||
}
|
||||
let count = number(tag.get("count")).or_else(|| number(tag.get("Count"))).unwrap_or(1).max(1) as u32;
|
||||
let damage = number(tag.get("components").and_then(|c| c.get("minecraft:damage"))).unwrap_or(0).max(0) as u32;
|
||||
Some(crate::items::ItemStack { item: Arc::from(id.as_str()), count, damage })
|
||||
let (damage, extra) = crate::item_data::decode_components(tag.get("components"));
|
||||
Some(crate::items::ItemStack { item: Arc::from(id.as_str()), count, damage, extra })
|
||||
}
|
||||
pub fn encode_items(slots: &[Option<crate::items::ItemStack>]) -> Tag {
|
||||
Tag::List(
|
||||
@@ -277,15 +277,6 @@ pub fn encode_items(slots: &[Option<crate::items::ItemStack>]) -> Tag {
|
||||
.filter_map(|(i, s)| {
|
||||
let mut entries = vec![("Slot", Tag::Byte(i as i8))];
|
||||
entries.extend(encode_item(s.as_ref()?));
|
||||
let s = s.as_ref()?;
|
||||
let mut entries = vec![
|
||||
("Slot", Tag::Byte(i as i8)),
|
||||
("id", string(&s.item)),
|
||||
("count", Tag::Int(s.count as i32)),
|
||||
];
|
||||
if let Some(components) = crate::item_data::encode_components(s) {
|
||||
entries.push(("components", components));
|
||||
}
|
||||
Some(Tag::compound(entries))
|
||||
})
|
||||
.collect(),
|
||||
@@ -298,16 +289,6 @@ pub fn decode_items(tag: Option<&Tag>, size: usize) -> Vec<Option<crate::items::
|
||||
let slot = number(it.get("Slot")).unwrap_or(0) as u8 as usize;
|
||||
if let Some(cell) = slots.get_mut(slot) {
|
||||
*cell = item_from_nbt(it);
|
||||
let Some(Tag::Byte(slot)) = it.get("Slot") else { continue };
|
||||
let Some(Tag::String(id)) = it.get("id") else { continue };
|
||||
let count = match it.get("count") {
|
||||
Some(Tag::Int(c)) => *c as u32,
|
||||
Some(Tag::Byte(c)) => *c as u32,
|
||||
_ => 1,
|
||||
};
|
||||
let (damage, extra) = crate::item_data::decode_components(it.get("components"));
|
||||
if let Some(cell) = slots.get_mut(*slot as u8 as usize) {
|
||||
*cell = Some(crate::items::ItemStack { item: Arc::from(id.to_string_lossy().as_str()), count, damage, extra });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -317,7 +298,7 @@ pub fn decode_items(tag: Option<&Tag>, size: usize) -> Vec<Option<crate::items::
|
||||
/// is a chest, trapped chest or barrel).
|
||||
fn block_entity_id(e: &crate::containers::BlockEntity, block: &str) -> String {
|
||||
match (e, block) {
|
||||
(crate::containers::BlockEntity::Chest(_), "minecraft:trapped_chest" | "minecraft:barrel") => block.to_owned(),
|
||||
(crate::containers::BlockEntity::Chest(_), "minecraft:trapped_chest" | "minecraft:barrel" | "minecraft:dropper") => block.to_owned(),
|
||||
_ => e.id().to_owned(),
|
||||
}
|
||||
}
|
||||
@@ -559,28 +540,6 @@ pub fn encode_with(chunk: &Chunk, registry: &BlockRegistry, biomes: &Biomes, tab
|
||||
("block_entities", Tag::List(block_entities)),
|
||||
] {
|
||||
put(&mut root, key, value);
|
||||
NamedTag {
|
||||
name: "".into(),
|
||||
tag: Tag::compound([
|
||||
("DataVersion", Tag::Int(DATA_VERSION)),
|
||||
("xPos", Tag::Int(chunk.x)),
|
||||
("zPos", Tag::Int(chunk.z)),
|
||||
("yPos", Tag::Int(MIN_Y >> 4)),
|
||||
("Status", string("minecraft:full")),
|
||||
("LastUpdate", Tag::Long(0)),
|
||||
("InhabitedTime", Tag::Long(0)),
|
||||
("isLightOn", Tag::Byte(0)),
|
||||
("sections", Tag::List(sections)),
|
||||
("block_entities", Tag::List(chunk.block_entities.iter().map(|(p, e)| {
|
||||
// The block's own entity id (barrels, droppers, trapped chests).
|
||||
let mut tag = encode_block_entity(*p, e);
|
||||
let state = chunk.block(p.0 & 15, p.1, p.2 & 15);
|
||||
if let (Tag::Compound(entries), Some(id)) = (&mut tag, registry.state(state).and_then(|s| crate::containers::BlockEntity::id_for_block(&s.name))) {
|
||||
entries.insert("id".into(), string(id));
|
||||
}
|
||||
tag
|
||||
}).collect())),
|
||||
]),
|
||||
}
|
||||
if let Some(Tag::Compound(map)) = Some(&mut root) {
|
||||
map.entry("InhabitedTime".into()).or_insert(Tag::Long(0));
|
||||
@@ -1141,10 +1100,15 @@ impl Level {
|
||||
self.spawn = Some([f64::from(pos[0]), f64::from(pos[1]), f64::from(pos[2])]);
|
||||
}
|
||||
let mut inventory = Vec::new();
|
||||
let mut inventory_components = HashMap::new();
|
||||
if let Some(Tag::List(items)) = p.get("Inventory") {
|
||||
for it in items {
|
||||
let slot = number(it.get("Slot")).unwrap_or(0) as i8 as u8;
|
||||
if let Some(stack) = item_from_nbt(it) {
|
||||
let slot = if slot as i8 == -106 { 150 } else { slot };
|
||||
if let Some(extra) = &stack.extra {
|
||||
inventory_components.insert(slot, extra.clone());
|
||||
}
|
||||
// Legacy armor slots 100..103 and offhand -106 (150).
|
||||
let slot = if slot as i8 == -106 { 150 } else { slot };
|
||||
inventory.push((slot, stack.item.to_string(), stack.count, stack.damage));
|
||||
@@ -1155,76 +1119,27 @@ impl Level {
|
||||
for (name, slot) in [("feet", 100u8), ("legs", 101), ("chest", 102), ("head", 103), ("offhand", 150)] {
|
||||
if let Some(stack) = eq.get(name).and_then(item_from_nbt) {
|
||||
inventory.retain(|(s, ..)| *s != slot);
|
||||
if let Some(extra) = &stack.extra {
|
||||
inventory_components.insert(slot, extra.clone());
|
||||
}
|
||||
inventory.push((slot, stack.item.to_string(), stack.count, stack.damage));
|
||||
}
|
||||
}
|
||||
}
|
||||
self.inventory = inventory;
|
||||
let mut inventory_components = HashMap::new();
|
||||
if let Some(Tag::List(items)) = player.and_then(|p| p.get("Inventory")) {
|
||||
for it in items {
|
||||
let slot = if let Some(Tag::Byte(s)) = it.get("Slot") { *s as u8 } else { continue };
|
||||
let id = if let Some(Tag::String(s)) = it.get("id") { s.to_string_lossy() } else { continue };
|
||||
let count = long(it.get("count")).max(1) as u32;
|
||||
let damage = it
|
||||
.get("components")
|
||||
.and_then(|c| c.get("minecraft:damage"))
|
||||
.map_or(0, |d| long(Some(d)) as u32);
|
||||
if let (_, Some(extra)) = crate::item_data::decode_components(it.get("components")) {
|
||||
inventory_components.insert(slot, extra);
|
||||
}
|
||||
inventory.push((slot, id, count, damage));
|
||||
}
|
||||
}
|
||||
let rotation = match player.and_then(|p| p.get("Rotation")) {
|
||||
Some(Tag::List(r)) if r.len() == 2 => [float(r.first()), float(r.get(1))],
|
||||
_ => [0.0; 2],
|
||||
self.inventory_components = inventory_components;
|
||||
self.xp_seed = n("XpSeed").unwrap_or(0) as i32;
|
||||
self.active_effects = match p.get("active_effects") {
|
||||
Some(Tag::List(list)) => list
|
||||
.iter()
|
||||
.filter_map(|e| {
|
||||
let id = text(e.get("id"))?;
|
||||
let get = |k: &str| number(e.get(k));
|
||||
Some((id, get("duration").unwrap_or(0) as i32, get("amplifier").unwrap_or(0) as i32, get("ambient").unwrap_or(0) != 0, get("show_icon").is_none_or(|v| v != 0)))
|
||||
})
|
||||
.collect(),
|
||||
_ => Vec::new(),
|
||||
};
|
||||
Some(Self {
|
||||
name: match data.get("LevelName") {
|
||||
Some(Tag::String(s)) => s.to_string_lossy(),
|
||||
_ => "World".into(),
|
||||
},
|
||||
seed: long(data.get("WorldGenSettings").and_then(|w| w.get("seed"))),
|
||||
creative: long(data.get("GameType")) == 1,
|
||||
time: long(data.get("Time")),
|
||||
day_time: long(data.get("DayTime")),
|
||||
spawn: Some([long(data.get("SpawnX")) as f64, long(data.get("SpawnY")) as f64, long(data.get("SpawnZ")) as f64]),
|
||||
position: doubles(player.and_then(|p| p.get("Pos"))),
|
||||
rotation,
|
||||
health: player.map_or(20.0, |p| float(p.get("Health"))),
|
||||
food: player.map_or(20, |p| long(p.get("foodLevel")) as i32),
|
||||
saturation: player.map_or(5.0, |p| float(p.get("foodSaturationLevel"))),
|
||||
dimension: match player.and_then(|p| p.get("Dimension")) {
|
||||
Some(Tag::String(s)) => s.to_string_lossy(),
|
||||
_ => "minecraft:overworld".into(),
|
||||
},
|
||||
weather: crate::world::Weather {
|
||||
clear_time: long(data.get("clearWeatherTime")) as i32,
|
||||
rain_time: long(data.get("rainTime")) as i32,
|
||||
thunder_time: long(data.get("thunderTime")) as i32,
|
||||
raining: long(data.get("raining")) != 0,
|
||||
thundering: long(data.get("thundering")) != 0,
|
||||
rain_level: if long(data.get("raining")) != 0 { (1.0, 1.0) } else { (0.0, 0.0) },
|
||||
thunder_level: if long(data.get("thundering")) != 0 { (1.0, 1.0) } else { (0.0, 0.0) },
|
||||
},
|
||||
xp_level: player.map_or(0, |p| long(p.get("XpLevel")) as i32),
|
||||
xp_progress: player.map_or(0.0, |p| float(p.get("XpP"))),
|
||||
xp_total: player.map_or(0, |p| long(p.get("XpTotal")) as i32),
|
||||
xp_seed: player.map_or(0, |p| long(p.get("XpSeed")) as i32),
|
||||
active_effects: match player.and_then(|p| p.get("active_effects")) {
|
||||
Some(Tag::List(list)) => list
|
||||
.iter()
|
||||
.filter_map(|e| {
|
||||
let Some(Tag::String(id)) = e.get("id") else { return None };
|
||||
Some((id.to_string_lossy(), long(e.get("duration")) as i32, long(e.get("amplifier")) as i32, long(e.get("ambient")) != 0, e.get("show_icon").is_none_or(|v| long(Some(v)) != 0)))
|
||||
})
|
||||
.collect(),
|
||||
_ => Vec::new(),
|
||||
},
|
||||
inventory,
|
||||
inventory_components,
|
||||
})
|
||||
}
|
||||
/// The player compound: the loaded one with Horizon's state written over it.
|
||||
fn player_tag(&self) -> Tag {
|
||||
@@ -1238,7 +1153,8 @@ impl Level {
|
||||
let mut inventory = Vec::new();
|
||||
let mut equipment = Vec::new();
|
||||
for (slot, id, count, damage) in &self.inventory {
|
||||
let stack = crate::items::ItemStack { item: Arc::from(id.as_str()), count: *count, damage: *damage };
|
||||
let extra = self.inventory_components.get(slot).cloned();
|
||||
let stack = crate::items::ItemStack { item: Arc::from(id.as_str()), count: *count, damage: *damage, extra };
|
||||
match slot {
|
||||
0..=35 => {
|
||||
let mut entries = vec![("Slot", Tag::Byte(*slot as i8))];
|
||||
@@ -1409,23 +1325,6 @@ impl Level {
|
||||
("yaw", Tag::Float(0f32.to_bits())),
|
||||
("pitch", Tag::Float(0f32.to_bits())),
|
||||
]),
|
||||
"Inventory",
|
||||
Tag::List(
|
||||
self.inventory
|
||||
.iter()
|
||||
.map(|(slot, id, count, damage)| {
|
||||
let mut entries = vec![
|
||||
("Slot", Tag::Byte(*slot as i8)),
|
||||
("id", string(id)),
|
||||
("count", Tag::Int(*count as i32)),
|
||||
];
|
||||
if let Some(components) = crate::item_data::components_tag(*damage, self.inventory_components.get(slot).map(|d| &**d)) {
|
||||
entries.push(("components", components));
|
||||
}
|
||||
Tag::compound(entries)
|
||||
})
|
||||
.collect(),
|
||||
),
|
||||
),
|
||||
("difficulty_settings", difficulty),
|
||||
("initialized", Tag::Byte(1)),
|
||||
|
||||
@@ -63,6 +63,7 @@ pub fn block_entities(
|
||||
item: Arc::from(s.item.as_str()),
|
||||
count: s.count.max(0) as u32,
|
||||
damage: s.damage.max(0) as u32,
|
||||
extra: None,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
//!
|
||||
//! chunkgen_bench <client resource dir> [--seed S] [--size N] [--threads T]
|
||||
//! [--center CX CZ] [--verify <material-stage parity dir>] [--no-decorate]
|
||||
//! [--dimension minecraft:the_nether|minecraft:the_end]
|
||||
//! [--dimension overworld|the_nether|the_end]
|
||||
use horizon_core::position::ChunkPos;
|
||||
use horizon_world::{
|
||||
@@ -278,7 +277,6 @@ fn main() -> Result<(), Error> {
|
||||
let mut decorate = true;
|
||||
let mut dimension = String::from("minecraft:overworld");
|
||||
let mut starts: Option<(i32, i32, i32, i32, PathBuf)> = None;
|
||||
let mut dimension = "minecraft:overworld".to_owned();
|
||||
while let Some(arg) = args.next() {
|
||||
let mut next = || args.next().expect("argument value");
|
||||
match arg.as_str() {
|
||||
@@ -288,8 +286,10 @@ fn main() -> Result<(), Error> {
|
||||
"--center" => center = (next().parse()?, next().parse()?),
|
||||
"--verify" => parity = Some(PathBuf::from(next())),
|
||||
"--no-decorate" => decorate = false,
|
||||
"--dimension" => dimension = next(),
|
||||
"--dimension" => dimension = format!("minecraft:{}", next()),
|
||||
"--dimension" => {
|
||||
let d = next();
|
||||
dimension = if d.contains(':') { d } else { format!("minecraft:{d}") };
|
||||
}
|
||||
"--starts" => {
|
||||
starts = Some((
|
||||
next().parse()?,
|
||||
|
||||
Reference in New Issue
Block a user