Merge pull request #465 from LookImEcho-Rick/codex/fix-happy-ghast-riding
Fix Happy Ghast riding controls and standing after dismount
This commit is contained in:
@@ -100,6 +100,7 @@ fn main() -> Result<()> {
|
||||
player.auto_jump_enabled = p["enabled"].as_bool().unwrap();
|
||||
player.auto_jump_time = p["time"].as_i64().unwrap() as i32;
|
||||
MotionWorld {
|
||||
entities: &[],
|
||||
player: &mut player,
|
||||
scene: &mut scene,
|
||||
assets: &assets,
|
||||
|
||||
@@ -902,6 +902,10 @@ fn main() -> horizon_client::Result<()> {
|
||||
for flag in &spec.flags {
|
||||
match flag.as_str() {
|
||||
"persistent" => m.persistent = true,
|
||||
"ridden" => {
|
||||
m.extra.head = Some("minecraft:red_harness".into());
|
||||
m.rider = Some(horizon_client::mobs::equine::Rider::default());
|
||||
}
|
||||
"noai" => m.no_ai = true,
|
||||
// Warden.finalizeSpawn's own part.
|
||||
"digcooldown" | "emerge" => horizon_client::mobs::warden::finalize(
|
||||
|
||||
@@ -2,6 +2,11 @@
|
||||
#![forbid(unsafe_code)]
|
||||
use horizon_client::{assets, collisions, world};
|
||||
use horizon_core::geometry::{Aabb, Vec3};
|
||||
use horizon_world::{
|
||||
collision_context::CollisionContext,
|
||||
entity_obstruction::EntityIdentity,
|
||||
world_movement::{self, CollisionCheckRequest, MovementRequest},
|
||||
};
|
||||
use serde_json::Value;
|
||||
use std::{
|
||||
fs,
|
||||
@@ -57,21 +62,55 @@ fn main() -> Result<()> {
|
||||
f["step"].as_str().ok_or("expected step bits")?,
|
||||
16,
|
||||
)?);
|
||||
let movement = scene.resolve(
|
||||
bounds,
|
||||
delta,
|
||||
step,
|
||||
f["grounded"].as_bool().ok_or("expected grounded flag")?,
|
||||
let entities = f["entities"]
|
||||
.as_array()
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.map(|v| {
|
||||
let a = v.as_array().ok_or("expected entity box")?;
|
||||
Ok(Aabb::new(
|
||||
vector(&Value::Array(a[..3].to_vec()))?,
|
||||
vector(&Value::Array(a[3..].to_vec()))?,
|
||||
))
|
||||
})
|
||||
.collect::<Result<Vec<_>>>()?;
|
||||
let mut selected = collisions::EntityCollisions {
|
||||
blocks: scene,
|
||||
entities: &entities,
|
||||
};
|
||||
let movement = world_movement::resolve_world_movement(
|
||||
&mut selected,
|
||||
MovementRequest {
|
||||
entity: EntityIdentity(0),
|
||||
context: CollisionContext::position(bounds.min_position().y),
|
||||
bounds,
|
||||
movement: delta,
|
||||
max_step: step,
|
||||
on_ground: f["grounded"].as_bool().ok_or("expected grounded flag")?,
|
||||
candidate_budget: 1_000_000,
|
||||
},
|
||||
)?;
|
||||
let mut unobstructed = |bounds: Aabb| {
|
||||
world_movement::no_world_collision(
|
||||
&mut selected,
|
||||
CollisionCheckRequest {
|
||||
entity: EntityIdentity(0),
|
||||
context: CollisionContext::position(bounds.min_position().y),
|
||||
bounds,
|
||||
candidate_budget: 1_000_000,
|
||||
},
|
||||
)
|
||||
};
|
||||
writeln!(
|
||||
output,
|
||||
"move {:016x} {:016x} {:016x} clear {} {}",
|
||||
movement.x.to_bits(),
|
||||
movement.y.to_bits(),
|
||||
movement.z.to_bits(),
|
||||
scene.unobstructed(bounds)?,
|
||||
scene.unobstructed(bounds.move_by(movement))?
|
||||
unobstructed(bounds)?,
|
||||
unobstructed(bounds.move_by(movement))?
|
||||
)?;
|
||||
scene = selected.blocks;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -298,6 +298,7 @@ fn main() -> Result<()> {
|
||||
let mut travel: Option<horizon_core::position::BlockPos> = None;
|
||||
for op in f["ops"].as_array().unwrap() {
|
||||
let mut world = MotionWorld {
|
||||
entities: &[],
|
||||
player: &mut player,
|
||||
scene: &mut scene,
|
||||
assets: &assets,
|
||||
|
||||
@@ -65,6 +65,68 @@ pub struct SceneCollisions<'w, 'r> {
|
||||
/// The entity colliding, for powder snow; None: no fall, no boots.
|
||||
pub subject: Option<PowderSnowSubject>,
|
||||
}
|
||||
/// Already selected entity boxes alongside the resident block collision world.
|
||||
pub struct EntityCollisions<'a, W> {
|
||||
pub blocks: W,
|
||||
pub entities: &'a [Aabb],
|
||||
}
|
||||
impl<W: BlockCollisionWorld> BlockCollisionWorld for EntityCollisions<'_, W> {
|
||||
type Error = W::Error;
|
||||
type Chunk = W::Chunk;
|
||||
fn collision_chunk(
|
||||
&mut self,
|
||||
p: ChunkPos,
|
||||
) -> std::result::Result<Option<Self::Chunk>, Self::Error> {
|
||||
self.blocks.collision_chunk(p)
|
||||
}
|
||||
fn collision_block(
|
||||
&mut self,
|
||||
chunk: Self::Chunk,
|
||||
p: BlockPos,
|
||||
) -> std::result::Result<CollisionBlock, Self::Error> {
|
||||
self.blocks.collision_block(chunk, p)
|
||||
}
|
||||
fn is_suffocating(
|
||||
&mut self,
|
||||
chunk: Self::Chunk,
|
||||
block: CollisionBlock,
|
||||
p: BlockPos,
|
||||
) -> std::result::Result<bool, Self::Error> {
|
||||
self.blocks.is_suffocating(chunk, block, p)
|
||||
}
|
||||
fn context_shape(
|
||||
&mut self,
|
||||
block: CollisionBlock,
|
||||
p: BlockPos,
|
||||
context: &CollisionContext<'_>,
|
||||
) -> std::result::Result<VoxelShape, Self::Error> {
|
||||
self.blocks.context_shape(block, p, context)
|
||||
}
|
||||
}
|
||||
impl<W: EntityMovementWorld<Error = io::Error>> EntityMovementWorld for EntityCollisions<'_, W> {
|
||||
type Error = io::Error;
|
||||
fn entity_collisions(
|
||||
&mut self,
|
||||
entity: EntityIdentity,
|
||||
bounds: Aabb,
|
||||
) -> io::Result<Vec<VoxelShape>> {
|
||||
let mut shapes = self.blocks.entity_collisions(entity, bounds)?;
|
||||
for &aabb in self.entities {
|
||||
// EntityGetter.getEntityCollisions expands its entity query by 1e-7.
|
||||
if aabb.intersects(bounds.inflate(Vec3::new(1.0e-7, 1.0e-7, 1.0e-7))) {
|
||||
shapes.push(VoxelShape::from_box(aabb).map_err(io::Error::other)?);
|
||||
}
|
||||
}
|
||||
Ok(shapes)
|
||||
}
|
||||
fn movement_border(
|
||||
&mut self,
|
||||
entity: EntityIdentity,
|
||||
bounds: Aabb,
|
||||
) -> io::Result<Option<VoxelShape>> {
|
||||
self.blocks.movement_border(entity, bounds)
|
||||
}
|
||||
}
|
||||
impl SceneCollisions<'_, '_> {
|
||||
/// Position contexts permit geometric movement probes without inventing a
|
||||
/// player, inventory, effects or fluid-standing behavior; a lava walker
|
||||
|
||||
@@ -3016,6 +3016,7 @@ impl Game<'_> {
|
||||
self.tick_riding(keys)?;
|
||||
}
|
||||
let riding = self.riding.is_some();
|
||||
let ghast_collisions = self.happy_ghast_player_collisions();
|
||||
let Some(player) = self.player.as_mut() else {
|
||||
// A dedicated server has no local player: the world still runs.
|
||||
if self.options.dedicated.is_some() {
|
||||
@@ -3101,6 +3102,7 @@ impl Game<'_> {
|
||||
);
|
||||
if !riding {
|
||||
MotionWorld {
|
||||
entities: &ghast_collisions,
|
||||
player,
|
||||
scene: &mut self.world,
|
||||
assets: &self.res.assets,
|
||||
|
||||
@@ -6,10 +6,26 @@ use horizon_client::{
|
||||
items::ItemStack,
|
||||
mobs::{MobEvent, happy_ghast},
|
||||
};
|
||||
use horizon_core::geometry::Vec3;
|
||||
use horizon_core::geometry::{Aabb, Vec3};
|
||||
use horizon_world::registry::BlockStateId;
|
||||
|
||||
impl Game<'_> {
|
||||
/// Client `EntityGetter.getEntityCollisions`: only solid happy ghasts,
|
||||
/// excluding the player's own vehicle.
|
||||
pub(super) fn happy_ghast_player_collisions(&self) -> Vec<Aabb> {
|
||||
let Some(p) = &self.player else {
|
||||
return Vec::new();
|
||||
};
|
||||
self.mobs
|
||||
.iter()
|
||||
.filter(|m| {
|
||||
m.species() == horizon_client::mobs::Species::HappyGhast
|
||||
&& Some(m.id) != self.riding
|
||||
&& happy_ghast::collides_with_player(m, p.position.y)
|
||||
})
|
||||
.map(|m| m.bounds())
|
||||
.collect()
|
||||
}
|
||||
/// `HappyGhast.mobInteract`. Returns whether the click was used.
|
||||
pub(super) fn interact_happy_ghast(&mut self, index: usize, item: &str) -> bool {
|
||||
let m = &self.mobs[index];
|
||||
|
||||
@@ -785,6 +785,7 @@ impl Game<'_> {
|
||||
return;
|
||||
};
|
||||
let mut w = MotionWorld {
|
||||
entities: &[],
|
||||
player,
|
||||
scene: &mut game.world,
|
||||
assets: &game.res.assets,
|
||||
|
||||
@@ -1736,6 +1736,7 @@ impl Game<'_> {
|
||||
self.tick_block_entity_anims();
|
||||
self.tick_hand();
|
||||
self.tick_particles();
|
||||
let ghast_collisions = self.happy_ghast_player_collisions();
|
||||
let Some(player) = self.player.as_mut() else {
|
||||
return Ok(());
|
||||
};
|
||||
@@ -1788,6 +1789,7 @@ impl Game<'_> {
|
||||
let dead = self.screen == Screen::Dead;
|
||||
if !dead {
|
||||
MotionWorld {
|
||||
entities: &ghast_collisions,
|
||||
player,
|
||||
scene: &mut self.world,
|
||||
assets: &self.res.assets,
|
||||
|
||||
@@ -769,6 +769,8 @@ fn push_entities(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
|
||||
&& !(m.species() == Species::Creaking && !super::creaking::can_move(m));
|
||||
let mut targets: Vec<(Who, Vec3)> = Vec::new();
|
||||
if let Some(p) = &w.player
|
||||
// Entity.push: passengers of the same vehicle never push each other.
|
||||
&& m.rider.is_none()
|
||||
&& p.alive
|
||||
&& !p.spectator
|
||||
&& p.bounds.intersects(bounds)
|
||||
|
||||
@@ -311,14 +311,14 @@ pub fn ridden_step(m: &mut Mob) {
|
||||
if super::nautilus::is_nautilus(m.species()) {
|
||||
return super::nautilus::ridden(m);
|
||||
}
|
||||
if m.species() == Species::HappyGhast {
|
||||
return super::happy_ghast::ridden(m);
|
||||
}
|
||||
m.yaw = r.yaw;
|
||||
m.head_pitch = r.pitch * 0.5;
|
||||
m.body_yaw = r.yaw;
|
||||
m.head_yaw = r.yaw;
|
||||
m.ai.nav.stop();
|
||||
if m.species() == Species::HappyGhast {
|
||||
return super::happy_ghast::ridden(m);
|
||||
}
|
||||
|
||||
if matches!(m.species(), Species::Pig | Species::Strider) {
|
||||
// Pig/Strider: always forward along the rider's look, at a fraction
|
||||
|
||||
@@ -96,6 +96,19 @@ fn within_home(m: &Mob, p: Vec3) -> bool {
|
||||
pub fn on_still_timeout(m: &Mob) -> bool {
|
||||
!m.is_baby() && m.extra.counter > 0
|
||||
}
|
||||
/// Client-side `HappyGhast.canBeCollidedWith(Player)`.
|
||||
pub fn collides_with_player(m: &Mob, feet_y: f64) -> bool {
|
||||
player_collision(
|
||||
m.alive(),
|
||||
m.is_baby(),
|
||||
on_still_timeout(m),
|
||||
feet_y,
|
||||
m.bounds().max_position().y,
|
||||
)
|
||||
}
|
||||
fn player_collision(alive: bool, baby: bool, still: bool, feet_y: f64, top: f64) -> bool {
|
||||
alive && !baby && (feet_y >= top || still)
|
||||
}
|
||||
/// `Mob.stopInPlace`.
|
||||
fn stop_in_place(m: &mut Mob) {
|
||||
m.ai.nav.stop();
|
||||
@@ -609,6 +622,16 @@ pub fn goggles(down: bool, m: &Mob) -> MobEvent {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn player_collision_matches_vanilla_top_and_still_timeout_rules() {
|
||||
assert!(player_collision(true, false, false, 84.0, 84.0));
|
||||
assert!(player_collision(true, false, false, 85.0, 84.0));
|
||||
assert!(!player_collision(true, false, false, 83.99, 84.0));
|
||||
assert!(player_collision(true, false, true, 83.99, 84.0));
|
||||
assert!(!player_collision(true, true, true, 84.0, 84.0));
|
||||
assert!(!player_collision(false, false, true, 84.0, 84.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_harness_names_its_texture() {
|
||||
assert_eq!(
|
||||
|
||||
@@ -583,6 +583,8 @@ impl PlayerMotion {
|
||||
}
|
||||
|
||||
pub struct MotionWorld<'p, 'w, 'r> {
|
||||
/// Entity boxes selected by the host for this player's collision queries.
|
||||
pub entities: &'w [Aabb],
|
||||
pub player: &'p mut PlayerMotion,
|
||||
pub scene: &'w mut World,
|
||||
pub assets: &'r Assets,
|
||||
@@ -612,10 +614,18 @@ impl MotionWorld<'_, '_, '_> {
|
||||
subject: Some(self.player.powder_snow_subject()),
|
||||
}
|
||||
}
|
||||
fn movement_collisions(
|
||||
&self,
|
||||
) -> crate::collisions::EntityCollisions<'_, SceneCollisions<'_, '_>> {
|
||||
crate::collisions::EntityCollisions {
|
||||
blocks: self.collisions(),
|
||||
entities: self.entities,
|
||||
}
|
||||
}
|
||||
pub(crate) fn no_player_collision(&mut self, bounds: Aabb) -> Result<bool> {
|
||||
let context = self.context();
|
||||
Ok(world_movement::no_world_collision(
|
||||
&mut self.collisions(),
|
||||
&mut self.movement_collisions(),
|
||||
world_movement::CollisionCheckRequest {
|
||||
entity: EntityIdentity(0),
|
||||
context,
|
||||
@@ -1462,7 +1472,7 @@ impl EntityMoveWorld for MotionWorld<'_, '_, '_> {
|
||||
fn collide(&mut self, movement: Vec3) -> Result<Vec3> {
|
||||
let max_step = self.player.attribute("minecraft:step_height")? as f32;
|
||||
Ok(world_movement::resolve_world_movement(
|
||||
&mut self.collisions(),
|
||||
&mut self.movement_collisions(),
|
||||
MovementRequest {
|
||||
entity: EntityIdentity(0),
|
||||
context: self.context(),
|
||||
@@ -1976,6 +1986,80 @@ impl LivingMotionWorld for MotionWorld<'_, '_, '_> {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn player_stands_walks_sneaks_and_jumps_on_ghast() {
|
||||
let root = std::env::var_os("HORIZON_TEST_RESOURCES")
|
||||
.map(std::path::PathBuf::from)
|
||||
.unwrap_or_else(|| {
|
||||
Path::new(env!("CARGO_MANIFEST_DIR")).join("../../.local/horizon-client/26.3")
|
||||
});
|
||||
if !root.join("movement-properties.nbt").exists() {
|
||||
return;
|
||||
}
|
||||
let assets = Assets::load(&root).unwrap();
|
||||
let binding = crate::collisions::load(&root, assets.registry).unwrap();
|
||||
let resources = MotionResources::load(&root, &assets).unwrap();
|
||||
let mut scene = World::test_scene(&assets, 1).unwrap();
|
||||
let entities = [Aabb::new(
|
||||
Vec3::new(10.0, 80.0, 10.0),
|
||||
Vec3::new(14.0, 84.0, 14.0),
|
||||
)];
|
||||
let mut player = PlayerMotion::new(&resources, Vec3::new(12.0, 84.0, 12.0)).unwrap();
|
||||
let mut tick = |player: &mut PlayerMotion, keys| {
|
||||
MotionWorld {
|
||||
entities: &entities,
|
||||
player,
|
||||
scene: &mut scene,
|
||||
assets: &assets,
|
||||
collision_binding: &binding,
|
||||
resources: &resources,
|
||||
}
|
||||
.controlled_simulation_tick(keys)
|
||||
.unwrap()
|
||||
};
|
||||
for _ in 0..20 {
|
||||
tick(&mut player, Default::default());
|
||||
}
|
||||
assert_eq!(player.position.y, 84.0);
|
||||
assert!(player.ground.on_ground);
|
||||
let forward = crate::sprint::Keys {
|
||||
forward: true,
|
||||
..Default::default()
|
||||
};
|
||||
for _ in 0..5 {
|
||||
tick(&mut player, forward);
|
||||
}
|
||||
assert!(player.position.z > 12.0);
|
||||
assert_eq!(player.position.y, 84.0);
|
||||
tick(
|
||||
&mut player,
|
||||
crate::sprint::Keys {
|
||||
jump: true,
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
assert!(player.position.y > 84.0);
|
||||
for _ in 0..30 {
|
||||
tick(&mut player, Default::default());
|
||||
}
|
||||
assert_eq!(player.position.y, 84.0);
|
||||
for _ in 0..80 {
|
||||
tick(
|
||||
&mut player,
|
||||
crate::sprint::Keys {
|
||||
shift: true,
|
||||
..forward
|
||||
},
|
||||
);
|
||||
}
|
||||
assert_eq!(player.position.y, 84.0);
|
||||
assert!(player.position.z < 14.3);
|
||||
for _ in 0..30 {
|
||||
tick(&mut player, forward);
|
||||
}
|
||||
assert!(player.position.y < 84.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resident_spectator_flight_ignores_solid_and_climbable_blocks() {
|
||||
let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../.local/horizon-client/26.3");
|
||||
@@ -2007,6 +2091,7 @@ mod tests {
|
||||
let mut trajectory = Vec::new();
|
||||
for _ in 0..4 {
|
||||
MotionWorld {
|
||||
entities: &[],
|
||||
player: &mut player,
|
||||
scene: &mut scene,
|
||||
assets: &assets,
|
||||
@@ -2178,6 +2263,7 @@ mod tests {
|
||||
let mut player = PlayerMotion::new(&resources, Vec3::new(20.5, 20.0, 20.5)).unwrap();
|
||||
player.fall_distance = 30.0;
|
||||
let mut w = MotionWorld {
|
||||
entities: &[],
|
||||
player: &mut player,
|
||||
scene: &mut scene,
|
||||
assets: &assets,
|
||||
@@ -2216,6 +2302,7 @@ mod tests {
|
||||
}
|
||||
}
|
||||
let mut w = MotionWorld {
|
||||
entities: &[],
|
||||
player: &mut player,
|
||||
scene: &mut scene,
|
||||
assets: &assets,
|
||||
@@ -2433,6 +2520,7 @@ mod tests {
|
||||
}
|
||||
let mut player = PlayerMotion::new(&resources, Vec3::new(20.5, 4.0, 20.5)).unwrap();
|
||||
let mut w = MotionWorld {
|
||||
entities: &[],
|
||||
player: &mut player,
|
||||
scene: &mut scene,
|
||||
assets: &assets,
|
||||
@@ -2505,6 +2593,7 @@ mod tests {
|
||||
player.fire_ticks = 160;
|
||||
player.fall_distance = 8.0;
|
||||
let mut w = MotionWorld {
|
||||
entities: &[],
|
||||
player: &mut player,
|
||||
scene: &mut scene,
|
||||
assets: &assets,
|
||||
@@ -2553,6 +2642,7 @@ mod tests {
|
||||
scene.set(20, 5, 20, water).unwrap();
|
||||
let mut player = PlayerMotion::new(&resources, Vec3::new(20.5, 4.0, 20.5)).unwrap();
|
||||
let mut w = MotionWorld {
|
||||
entities: &[],
|
||||
player: &mut player,
|
||||
scene: &mut scene,
|
||||
assets: &assets,
|
||||
@@ -2634,6 +2724,7 @@ mod tests {
|
||||
let mut player = PlayerMotion::new(&resources, Vec3::new(21.0, 4.0, 20.5)).unwrap();
|
||||
player.ground.on_ground = true;
|
||||
let mut w = MotionWorld {
|
||||
entities: &[],
|
||||
player: &mut player,
|
||||
scene: &mut scene,
|
||||
assets: &assets,
|
||||
@@ -2668,6 +2759,7 @@ mod tests {
|
||||
let mut count = 0;
|
||||
for _ in 0..ticks {
|
||||
MotionWorld {
|
||||
entities: &[],
|
||||
player: &mut *player,
|
||||
scene: &mut scene,
|
||||
assets: &assets,
|
||||
|
||||
@@ -553,6 +553,9 @@ public final class VanillaMobAiOracle {
|
||||
String v = kv.length > 1 ? kv[1] : "";
|
||||
switch (kv[0]) {
|
||||
case "persistent" -> mob.setPersistenceRequired();
|
||||
case "ridden" -> mob.setItemSlot(net.minecraft.world.entity.EquipmentSlot.BODY,
|
||||
new net.minecraft.world.item.ItemStack(BuiltInRegistries.ITEM.getValue(
|
||||
net.minecraft.resources.Identifier.parse("minecraft:red_harness"))));
|
||||
case "noai" -> mob.setNoAi(true);
|
||||
case "profession" -> {
|
||||
Villager villager = (Villager) mob;
|
||||
@@ -641,6 +644,9 @@ public final class VanillaMobAiOracle {
|
||||
// Leads: to the player ("leashed") or to the n-th mob ("leashto=n").
|
||||
for (int i = 0; i < s.mobs.size(); i++) {
|
||||
for (String flag : s.mobs.get(i).flags) {
|
||||
if (flag.equals("ridden")) {
|
||||
if (!player.startRiding(ENTS.get(i))) throw new IllegalStateException("Could not mount fixture");
|
||||
}
|
||||
if (flag.equals("leashed")) ((net.minecraft.world.entity.Leashable) ENTS.get(i)).setLeashedTo(player, true);
|
||||
else if (flag.startsWith("leashto=")) ((net.minecraft.world.entity.Leashable) ENTS.get(i))
|
||||
.setLeashedTo(ENTS.get(Integer.parseInt(flag.substring(8))), true);
|
||||
|
||||
+2
-1
@@ -38,10 +38,11 @@ public final class VanillaRegistryCollisionScanOracle {
|
||||
}
|
||||
static final class StepLevel extends net.minecraft.server.level.ServerLevel {
|
||||
Trace trace;StepBorder border;List<VoxelShape> entities;CollisionGetter world;CollisionContext context;LevelReader liquidWorld;Collection<Chunk> chunks;
|
||||
boolean filterEntities;
|
||||
private StepLevel(){super(null,null,null,null,null,null,false,0L,List.of(),false);}
|
||||
@Override public boolean containsAnyLiquid(AABB bounds){for(var c:chunks)c.liquidTrace=true;try{return liquidWorld.containsAnyLiquid(bounds);}finally{for(var c:chunks)c.liquidTrace=false;}}
|
||||
@Override public net.minecraft.world.level.border.WorldBorder getWorldBorder(){trace.query("border");return border;}
|
||||
@Override public List<VoxelShape> getEntityCollisions(net.minecraft.world.entity.Entity entity,AABB bounds){trace.query(boxText("entities",bounds));return entities;}
|
||||
@Override public List<VoxelShape> getEntityCollisions(net.minecraft.world.entity.Entity entity,AABB bounds){trace.query(boxText("entities",bounds));return filterEntities ? entities.stream().filter(s -> s.bounds().intersects(bounds.inflate(1.0e-7))).toList() : entities;}
|
||||
@Override public Iterable<VoxelShape> getBlockCollisions(net.minecraft.world.entity.Entity entity,AABB bounds){return ()->new BlockCollisions<VoxelShape>(world,context,bounds,false,(p,shape)->shape);}
|
||||
}
|
||||
static final class StepEntity extends net.minecraft.world.entity.decoration.ArmorStand {
|
||||
|
||||
@@ -86,12 +86,15 @@ public final class VanillaSceneCollisionOracle {
|
||||
var allocator=Class.forName("sun.misc.Unsafe");var access=allocator.getDeclaredField("theUnsafe");access.setAccessible(true);
|
||||
var unsafe=access.get(null);var allocate=allocator.getMethod("allocateInstance",Class.class);
|
||||
var level=(StepLevel)allocate.invoke(unsafe,StepLevel.class);level.trace=trace;level.world=world;level.entities=List.of();
|
||||
level.filterEntities=true;
|
||||
level.border=new StepBorder();level.border.trace=trace;
|
||||
var entity=(StepEntity)allocate.invoke(unsafe,StepEntity.class);
|
||||
var collide=net.minecraft.world.entity.Entity.class.getDeclaredMethod("collide",Vec3.class);collide.setAccessible(true);
|
||||
try(var out=new PrintWriter(Files.newBufferedWriter(dir.resolve(args[0]+".txt")));var lines=Files.lines(dir.resolve("inputs.txt"))) {
|
||||
for(var line:(Iterable<String>)lines::iterator) {
|
||||
var f=JsonParser.parseString(line).getAsJsonObject();var bounds=new AABB(vector(f.get("min")),vector(f.get("max")));
|
||||
level.entities=new ArrayList<>();
|
||||
if(f.has("entities"))for(var shape:f.getAsJsonArray("entities"))level.entities.add(boxShape(shape));
|
||||
float step=Float.intBitsToFloat(Integer.parseUnsignedInt(f.get("step").getAsString(),16));
|
||||
entity.configure(level,bounds,step,f.get("grounded").getAsBoolean());level.context=CollisionContext.positionContext(bounds.minY);
|
||||
var movement=(Vec3)collide.invoke(entity,vector(f.get("delta")));
|
||||
|
||||
@@ -157,6 +157,11 @@ def scenarios():
|
||||
# Happy ghasts float above the grass; ghastlings follow players and adults.
|
||||
add('happy_ghast_player', 200, ['player 6.5 -60 0.5', 'mob minecraft:happy_ghast 0.5 -55 0.5 0 81 persistent'])
|
||||
add('happy_ghast_alone', 200, ['mob minecraft:happy_ghast 0.5 -55 0.5 90 82 persistent'])
|
||||
# The driver's seat overlaps the front of the ghast: it must not push its own rider.
|
||||
# One tick isolates riding input and turning from later passenger repositioning.
|
||||
for name, yaw in [('hover', 0), ('turn', 90)]:
|
||||
add(f'happy_ghast_ridden_{name}', 1, ['player 0.5 -51.6 2.2',
|
||||
f'mob minecraft:happy_ghast 0.5 -55 0.5 {yaw} 82 persistent ridden'])
|
||||
add('ghastling_player', 200, ['player 8.5 -60 0.5', 'mob minecraft:happy_ghast 0.5 -57 0.5 0 83 persistent baby'])
|
||||
add('ghastling_alone', 200, ['mob minecraft:happy_ghast 0.5 -57 0.5 0 84 persistent baby'])
|
||||
add('ghastling_adult', 200, ['mob minecraft:happy_ghast 10.5 -55 0.5 0 85 persistent',
|
||||
|
||||
@@ -25,6 +25,13 @@ def corpus(radius):
|
||||
'max': list(map(bits, [x+width/2, y+height, z+width/2])),
|
||||
'delta': list(map(bits, delta)), 'step': struct.pack('>f', step).hex(), 'grounded': ground}
|
||||
# All gallery placements, all approach axes, ledges, ceilings and embedded starts.
|
||||
# A four-block-wide ghast in midair: land, walk, jump and leave its edges.
|
||||
for x in [10.3, 12.0, 13.7, 14.4]:
|
||||
for y in [84.0, 84.5]:
|
||||
for delta in [(0, -0.08, 0), (0, -1, 0), (0.2, -0.08, 0), (-0.2, -0.08, 0), (0, 0.42, 0)]:
|
||||
fixture = row(x, y, 12.0, delta, ground=y == 84.0)
|
||||
fixture['entities'] = [list(map(bits, [10, 80, 10, 14, 84, 14]))]
|
||||
yield fixture
|
||||
for index in range(16):
|
||||
x, z = index % 4 * 4 - 7, index // 4 * 4 + 14
|
||||
for dx, dz in [(1, 0), (-1, 0), (0, 1), (0, -1), (1, 1), (-1, -1)]:
|
||||
|
||||
Reference in New Issue
Block a user