From d27bf042a8100796b2f869f3fb208983d221b1f6 Mon Sep 17 00:00:00 2001 From: Max Hyper Date: Sat, 7 Sep 2024 11:09:08 -0300 Subject: [PATCH] optimized leaf particle code --- .../animation/FalloverAnimationHandler.java | 49 +++++++++++-------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/ferreusveritas/dynamictrees/entity/animation/FalloverAnimationHandler.java b/src/main/java/com/ferreusveritas/dynamictrees/entity/animation/FalloverAnimationHandler.java index 62198128b..151f8b233 100644 --- a/src/main/java/com/ferreusveritas/dynamictrees/entity/animation/FalloverAnimationHandler.java +++ b/src/main/java/com/ferreusveritas/dynamictrees/entity/animation/FalloverAnimationHandler.java @@ -105,32 +105,41 @@ protected void flingLeavesParticles(FallingTreeEntity entity, float fallSpeed){ if (bounces > 1) return; int maxParticleBlocks = DTConfigs.MAX_FALLING_TREE_LEAVES_PARTICLES.get(); if (maxParticleBlocks == 0) return; - double limitChance = 1; - if (entity.getDestroyData().getNumLeaves() > maxParticleBlocks){ - limitChance = maxParticleBlocks / (double)entity.getDestroyData().getNumLeaves(); - } - limitChance *= Math.exp(-bounces); + BranchDestructionData data = entity.getDestroyData(); Direction.Axis toolAxis = data.toolDir.getAxis(); - int particleCount = bounces == 0 ? (int)(fallSpeed*5) : 1; if (toolAxis == Direction.Axis.Y) return; //this one isn't possible anyways - Vec3 w = entity.getForward().scale(fallSpeed * data.toolDir.getAxisDirection().getStep()); - if (toolAxis == Direction.Axis.X) w = new Vec3(w.z, w.x, w.y); - double speedVar = 0; + + double limitChance = 1; + if (entity.getDestroyData().getNumLeaves() > maxParticleBlocks) + limitChance = maxParticleBlocks / (double)entity.getDestroyData().getNumLeaves(); + limitChance *= Math.exp(-bounces); + RandomSource rand = entity.level().random; + int particleCount = bounces == 0 ? (int)(fallSpeed*5) : 1; + + Vec3 angularVel = entity.getForward().scale(fallSpeed * -data.toolDir.getAxisDirection().getStep()); + //on the X axis, the entity forward is rotated, so we rotate the angular velocity back + if (toolAxis == Direction.Axis.X) angularVel = new Vec3(angularVel.z, angularVel.x, angularVel.y); + for (int i=0; i