diff options
Diffstat (limited to 'azalea-physics/src')
| -rw-r--r-- | azalea-physics/src/collision/mod.rs | 47 | ||||
| -rwxr-xr-x | azalea-physics/src/collision/shape.rs | 33 | ||||
| -rw-r--r-- | azalea-physics/src/collision/world_collisions.rs | 7 | ||||
| -rw-r--r-- | azalea-physics/src/lib.rs | 22 |
4 files changed, 64 insertions, 45 deletions
diff --git a/azalea-physics/src/collision/mod.rs b/azalea-physics/src/collision/mod.rs index 7fb2cf97..c057f8d7 100644 --- a/azalea-physics/src/collision/mod.rs +++ b/azalea-physics/src/collision/mod.rs @@ -36,25 +36,29 @@ pub trait MovableEntity { impl HasCollision for World { // private Vec3 collide(Vec3 var1) { // AABB var2 = this.getBoundingBox(); - // List var3 = this.level.getEntityCollisions(this, var2.expandTowards(var1)); - // Vec3 var4 = var1.lengthSqr() == 0.0D ? var1 : collideBoundingBox(this, var1, var2, this.level, var3); + // List var3 = this.level.getEntityCollisions(this, + // var2.expandTowards(var1)); Vec3 var4 = var1.lengthSqr() == 0.0D ? + // var1 : collideBoundingBox(this, var1, var2, this.level, var3); // boolean var5 = var1.x != var4.x; // boolean var6 = var1.y != var4.y; // boolean var7 = var1.z != var4.z; // boolean var8 = this.onGround || var6 && var1.y < 0.0D; // if (this.maxUpStep > 0.0F && var8 && (var5 || var7)) { - // Vec3 var9 = collideBoundingBox(this, new Vec3(var1.x, (double)this.maxUpStep, var1.z), var2, this.level, var3); - // Vec3 var10 = collideBoundingBox(this, new Vec3(0.0D, (double)this.maxUpStep, 0.0D), var2.expandTowards(var1.x, 0.0D, var1.z), this.level, var3); + // Vec3 var9 = collideBoundingBox(this, new Vec3(var1.x, + // (double)this.maxUpStep, var1.z), var2, this.level, var3); Vec3 + // var10 = collideBoundingBox(this, new Vec3(0.0D, (double)this.maxUpStep, + // 0.0D), var2.expandTowards(var1.x, 0.0D, var1.z), this.level, var3); // if (var10.y < (double)this.maxUpStep) { - // Vec3 var11 = collideBoundingBox(this, new Vec3(var1.x, 0.0D, var1.z), var2.move(var10), this.level, var3).add(var10); - // if (var11.horizontalDistanceSqr() > var9.horizontalDistanceSqr()) { + // Vec3 var11 = collideBoundingBox(this, new Vec3(var1.x, 0.0D, + // var1.z), var2.move(var10), this.level, var3).add(var10); if + // (var11.horizontalDistanceSqr() > var9.horizontalDistanceSqr()) { // var9 = var11; // } // } // if (var9.horizontalDistanceSqr() > var4.horizontalDistanceSqr()) { - // return var9.add(collideBoundingBox(this, new Vec3(0.0D, -var9.y + var1.y, 0.0D), var2.move(var9), this.level, var3)); - // } + // return var9.add(collideBoundingBox(this, new Vec3(0.0D, -var9.y + + // var1.y, 0.0D), var2.move(var9), this.level, var3)); } // } // return var4; @@ -62,7 +66,8 @@ impl HasCollision for World { fn collide(&self, movement: &Vec3, entity: &EntityData) -> Vec3 { let entity_bounding_box = entity.bounding_box; // TODO: get_entity_collisions - // let entity_collisions = world.get_entity_collisions(self, entity_bounding_box.expand_towards(movement)); + // let entity_collisions = world.get_entity_collisions(self, + // entity_bounding_box.expand_towards(movement)); let entity_collisions = Vec::new(); if movement.length_sqr() == 0.0 { *movement @@ -144,7 +149,8 @@ impl<D: DerefMut<Target = World>> MovableEntity for Entity<'_, D> { // .get_block_state(&block_pos_below) // .expect("Couldn't get block state below"); - // self.check_fall_damage(collide_result.y, on_ground, block_state_below, block_pos_below); + // self.check_fall_damage(collide_result.y, on_ground, block_state_below, + // block_pos_below); // if self.isRemoved() { return; } @@ -159,12 +165,14 @@ impl<D: DerefMut<Target = World>> MovableEntity for Entity<'_, D> { if vertical_collision { // blockBelow.updateEntityAfterFallOn(this.level, this); - // the default implementation of updateEntityAfterFallOn sets the y movement to 0 + // the default implementation of updateEntityAfterFallOn sets the y movement to + // 0 self.delta.y = 0.; } if on_ground { - // blockBelow.stepOn(this.level, blockPosBelow, blockStateBelow, this); + // blockBelow.stepOn(this.level, blockPosBelow, blockStateBelow, + // this); } // sounds @@ -172,21 +180,22 @@ impl<D: DerefMut<Target = World>> MovableEntity for Entity<'_, D> { // this.tryCheckInsideBlocks(); // float var25 = this.getBlockSpeedFactor(); - // this.setDeltaMovement(this.getDeltaMovement().multiply((double)var25, 1.0D, (double)var25)); - // if (this.level.getBlockStatesIfLoaded(this.getBoundingBox().deflate(1.0E-6D)).noneMatch((var0) -> { + // this.setDeltaMovement(this.getDeltaMovement().multiply((double)var25, 1.0D, + // (double)var25)); if (this.level.getBlockStatesIfLoaded(this. + // getBoundingBox().deflate(1.0E-6D)).noneMatch((var0) -> { // return var0.is(BlockTags.FIRE) || var0.is(Blocks.LAVA); // })) { // if (this.remainingFireTicks <= 0) { // this.setRemainingFireTicks(-this.getFireImmuneTicks()); // } - // if (this.wasOnFire && (this.isInPowderSnow || this.isInWaterRainOrBubble())) { - // this.playEntityOnFireExtinguishedSound(); - // } + // if (this.wasOnFire && (this.isInPowderSnow || + // this.isInWaterRainOrBubble())) { this. + // playEntityOnFireExtinguishedSound(); } // } - // if (this.isOnFire() && (this.isInPowderSnow || this.isInWaterRainOrBubble())) { - // this.setRemainingFireTicks(-this.getFireImmuneTicks()); + // if (this.isOnFire() && (this.isInPowderSnow || this.isInWaterRainOrBubble())) + // { this.setRemainingFireTicks(-this.getFireImmuneTicks()); // } Ok(()) diff --git a/azalea-physics/src/collision/shape.rs b/azalea-physics/src/collision/shape.rs index e6bc6cf7..bb2ed2e5 100755 --- a/azalea-physics/src/collision/shape.rs +++ b/azalea-physics/src/collision/shape.rs @@ -143,11 +143,17 @@ impl Shapes { if b.is_empty() { return if op_true_false { a } else { empty_shape() }; } - // IndexMerger var5 = createIndexMerger(1, a.getCoords(Direction.Axis.X), b.getCoords(Direction.Axis.X), var3, var4); - // IndexMerger var6 = createIndexMerger(var5.size() - 1, a.getCoords(Direction.Axis.Y), b.getCoords(Direction.Axis.Y), var3, var4); - // IndexMerger var7 = createIndexMerger((var5.size() - 1) * (var6.size() - 1), a.getCoords(Direction.Axis.Z), b.getCoords(Direction.Axis.Z), var3, var4); - // BitSetDiscreteVoxelShape var8 = BitSetDiscreteVoxelShape.join(a.shape, b.shape, var5, var6, var7, op); - // return (VoxelShape)(var5 instanceof DiscreteCubeMerger && var6 instanceof DiscreteCubeMerger && var7 instanceof DiscreteCubeMerger ? new CubeVoxelShape(var8) : new ArrayVoxelShape(var8, var5.getList(), var6.getList(), var7.getList())); + // IndexMerger var5 = createIndexMerger(1, a.getCoords(Direction.Axis.X), + // b.getCoords(Direction.Axis.X), var3, var4); IndexMerger var6 = + // createIndexMerger(var5.size() - 1, a.getCoords(Direction.Axis.Y), + // b.getCoords(Direction.Axis.Y), var3, var4); IndexMerger var7 = + // createIndexMerger((var5.size() - 1) * (var6.size() - 1), + // a.getCoords(Direction.Axis.Z), b.getCoords(Direction.Axis.Z), var3, var4); + // BitSetDiscreteVoxelShape var8 = BitSetDiscreteVoxelShape.join(a.shape, + // b.shape, var5, var6, var7, op); return (VoxelShape)(var5 instanceof + // DiscreteCubeMerger && var6 instanceof DiscreteCubeMerger && var7 instanceof + // DiscreteCubeMerger ? new CubeVoxelShape(var8) : new ArrayVoxelShape(var8, + // var5.getList(), var6.getList(), var7.getList())); let var5 = Self::create_index_merger( 1, a.get_coords(Axis::X), @@ -266,8 +272,8 @@ impl Shapes { ) -> IndexMerger { let var5 = var1.len() - 1; let var6 = var2.len() - 1; - // if (&var1 as &dyn Any).is::<CubePointRange>() && (&var2 as &dyn Any).is::<CubePointRange>() - // { + // if (&var1 as &dyn Any).is::<CubePointRange>() && (&var2 as &dyn + // Any).is::<CubePointRange>() { // return new DiscreteCubeMerger(var0, var5, var6, var3, var4); // let var7: i64 = lcm(var5 as u32, var6 as u32).try_into().unwrap(); // // if ((long)var0 * var7 <= 256L) { @@ -305,8 +311,8 @@ pub enum VoxelShape { impl VoxelShape { // public double min(Direction.Axis var1) { // int var2 = this.shape.firstFull(var1); - // return var2 >= this.shape.getSize(var1) ? 1.0D / 0.0 : this.get(var1, var2); - // } + // return var2 >= this.shape.getSize(var1) ? 1.0D / 0.0 : this.get(var1, + // var2); } // public double max(Direction.Axis var1) { // int var2 = this.shape.lastFull(var1); // return var2 <= 0 ? -1.0D / 0.0 : this.get(var1, var2); @@ -467,8 +473,8 @@ impl VoxelShape { // public VoxelShape optimize() { // VoxelShape[] var1 = new VoxelShape[]{Shapes.empty()}; // this.forAllBoxes((var1x, var3, var5, var7, var9, var11) -> { - // var1[0] = Shapes.joinUnoptimized(var1[0], Shapes.box(var1x, var3, var5, var7, var9, var11), BooleanOp.OR); - // }); + // var1[0] = Shapes.joinUnoptimized(var1[0], Shapes.box(var1x, var3, + // var5, var7, var9, var11), BooleanOp.OR); }); // return var1[0]; // } fn optimize(&self) -> VoxelShape { @@ -497,8 +503,9 @@ impl VoxelShape { // DoubleList var3 = this.getCoords(Direction.Axis.Y); // DoubleList var4 = this.getCoords(Direction.Axis.Z); // this.shape.forAllBoxes((var4x, var5, var6, var7, var8, var9) -> { - // var1.consume(var2.getDouble(var4x), var3.getDouble(var5), var4.getDouble(var6), var2.getDouble(var7), var3.getDouble(var8), var4.getDouble(var9)); - // }, true); + // var1.consume(var2.getDouble(var4x), var3.getDouble(var5), + // var4.getDouble(var6), var2.getDouble(var7), var3.getDouble(var8), + // var4.getDouble(var9)); }, true); // } pub fn for_all_boxes(&self, mut consumer: impl FnMut(f64, f64, f64, f64, f64, f64)) where diff --git a/azalea-physics/src/collision/world_collisions.rs b/azalea-physics/src/collision/world_collisions.rs index a4062fcc..a28bce14 100644 --- a/azalea-physics/src/collision/world_collisions.rs +++ b/azalea-physics/src/collision/world_collisions.rs @@ -69,8 +69,8 @@ impl<'a> BlockCollisions<'a> { // if (this.cachedBlockGetter != null && this.cachedBlockGetterPos == var5) { // return this.cachedBlockGetter; // } else { - // BlockGetter var7 = this.collisionGetter.getChunkForCollisions(chunkX, chunkZ); - // this.cachedBlockGetter = var7; + // BlockGetter var7 = this.collisionGetter.getChunkForCollisions(chunkX, + // chunkZ); this.cachedBlockGetter = var7; // this.cachedBlockGetterPos = chunkPosLong; // return var7; // } @@ -100,7 +100,8 @@ impl<'a> Iterator for BlockCollisions<'a> { .get(&(&pos).into(), self.world.min_y()) .unwrap_or(BlockState::Air); - // TODO: continue if self.only_suffocating_blocks and the block is not suffocating + // TODO: continue if self.only_suffocating_blocks and the block is not + // suffocating let block_shape = block_state.shape(); diff --git a/azalea-physics/src/lib.rs b/azalea-physics/src/lib.rs index bcf22429..d419535e 100644 --- a/azalea-physics/src/lib.rs +++ b/azalea-physics/src/lib.rs @@ -61,8 +61,8 @@ impl<D: DerefMut<Target = World>> HasPhysics for Entity<'_, D> { // if (this.shouldDiscardFriction()) { // this.setDeltaMovement(movement.x, yMovement, movement.z); // } else { - // this.setDeltaMovement(movement.x * (double)inertia, yMovement * 0.9800000190734863D, movement.z * (double)inertia); - // } + // this.setDeltaMovement(movement.x * (double)inertia, yMovement * + // 0.9800000190734863D, movement.z * (double)inertia); } // if should_discard_friction(self) { if false { @@ -79,7 +79,8 @@ impl<D: DerefMut<Target = World>> HasPhysics for Entity<'_, D> { /// applies air resistance, calls self.travel(), and some other random /// stuff. fn ai_step(&mut self) { - // vanilla does movement interpolation here, doesn't really matter much for a bot though + // vanilla does movement interpolation here, doesn't really matter much for a + // bot though if self.delta.x.abs() < 0.003 { self.delta.x = 0.; @@ -157,17 +158,18 @@ fn handle_relative_friction_and_calculate_movement<D: DerefMut<Target = World>>( .expect("Entity should exist."); // let delta_movement = entity.delta; // ladders - // if ((entity.horizontalCollision || entity.jumping) && (entity.onClimbable() || entity.getFeetBlockState().is(Blocks.POWDER_SNOW) && PowderSnowBlock.canEntityWalkOnPowderSnow(entity))) { - // var3 = new Vec3(var3.x, 0.2D, var3.z); - // } + // if ((entity.horizontalCollision || entity.jumping) && (entity.onClimbable() + // || entity.getFeetBlockState().is(Blocks.POWDER_SNOW) && + // PowderSnowBlock.canEntityWalkOnPowderSnow(entity))) { var3 = new + // Vec3(var3.x, 0.2D, var3.z); } // TODO: powdered snow entity.delta } // private float getFrictionInfluencedSpeed(float friction) { -// return this.onGround ? this.getSpeed() * (0.21600002F / (friction * friction * friction)) : this.flyingSpeed; -// } +// return this.onGround ? this.getSpeed() * (0.21600002F / (friction * +// friction * friction)) : this.flyingSpeed; } fn get_friction_influenced_speed(entity: &EntityData, friction: f32) -> f32 { // TODO: have speed & flying_speed fields in entity if entity.on_ground { @@ -207,8 +209,8 @@ fn block_jump_factor<D: DerefMut<Target = World>>(entity: &Entity<D>) -> f32 { // return 0.42F * this.getBlockJumpFactor(); // } // public double getJumpBoostPower() { -// return this.hasEffect(MobEffects.JUMP) ? (double)(0.1F * (float)(this.getEffect(MobEffects.JUMP).getAmplifier() + 1)) : 0.0D; -// } +// return this.hasEffect(MobEffects.JUMP) ? (double)(0.1F * +// (float)(this.getEffect(MobEffects.JUMP).getAmplifier() + 1)) : 0.0D; } fn jump_power<D: DerefMut<Target = World>>(entity: &Entity<D>) -> f32 { 0.42 * block_jump_factor(entity) } |
