From 7eacbc7f4a80b2cb09decf6f82e640bdec6b6a63 Mon Sep 17 00:00:00 2001 From: Sollace Date: Fri, 24 Dec 2021 22:59:03 +0200 Subject: [PATCH] Cleanup and remove some unused code --- .../client/particle/SphereParticle.java | 17 ++-- .../particle/FollowingParticleEffect.java | 2 +- .../unicopia/particle/ParticleEmitter.java | 99 ------------------- 3 files changed, 9 insertions(+), 109 deletions(-) delete mode 100644 src/main/java/com/minelittlepony/unicopia/particle/ParticleEmitter.java diff --git a/src/main/java/com/minelittlepony/unicopia/client/particle/SphereParticle.java b/src/main/java/com/minelittlepony/unicopia/client/particle/SphereParticle.java index cabe1ba3..67c5341f 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/particle/SphereParticle.java +++ b/src/main/java/com/minelittlepony/unicopia/client/particle/SphereParticle.java @@ -35,22 +35,21 @@ public class SphereParticle extends Particle implements Attachment { private static final SphereModel MODEL = new SphereModel(); - public SphereParticle(SphereParticleEffect effect, ClientWorld w, double x, double y, double z, double vX, double vY, double vZ) { - this(effect, w, x, y, z); + public SphereParticle(SphereParticleEffect parameters, ClientWorld w, double x, double y, double z, double vX, double vY, double vZ) { + this(parameters, w, x, y, z); this.velocityX = vX; this.velocityY = vY; this.velocityZ = vZ; } - public SphereParticle(SphereParticleEffect effect, ClientWorld w, double x, double y, double z) { + public SphereParticle(SphereParticleEffect parameters, ClientWorld w, double x, double y, double z) { super(w, x, y, z); - - this.radius = effect.getRadius(); - this.colorRed = effect.getColor().getX() / 255F; - this.colorGreen = effect.getColor().getY() / 255F; - this.colorBlue = effect.getColor().getZ() / 255F; - this.colorAlpha = effect.getAlpha(); + this.radius = parameters.getRadius(); + this.colorRed = parameters.getColor().getX() / 255F; + this.colorGreen = parameters.getColor().getY() / 255F; + this.colorBlue = parameters.getColor().getZ() / 255F; + this.colorAlpha = parameters.getAlpha(); setMaxAge(10); } diff --git a/src/main/java/com/minelittlepony/unicopia/particle/FollowingParticleEffect.java b/src/main/java/com/minelittlepony/unicopia/particle/FollowingParticleEffect.java index 2111f761..f6335de4 100644 --- a/src/main/java/com/minelittlepony/unicopia/particle/FollowingParticleEffect.java +++ b/src/main/java/com/minelittlepony/unicopia/particle/FollowingParticleEffect.java @@ -1,6 +1,7 @@ package com.minelittlepony.unicopia.particle; import java.util.Locale; + import com.mojang.brigadier.StringReader; import com.mojang.brigadier.exceptions.CommandSyntaxException; @@ -84,5 +85,4 @@ public class FollowingParticleEffect implements ParticleEffect { public String asString() { return String.format(Locale.ROOT, "%s %.2f %.2f %.2f %.2f", Registry.PARTICLE_TYPE.getId(getType()), fixedTarget.x, fixedTarget.y, fixedTarget.z, followSpeed); } - } diff --git a/src/main/java/com/minelittlepony/unicopia/particle/ParticleEmitter.java b/src/main/java/com/minelittlepony/unicopia/particle/ParticleEmitter.java deleted file mode 100644 index b5d30edd..00000000 --- a/src/main/java/com/minelittlepony/unicopia/particle/ParticleEmitter.java +++ /dev/null @@ -1,99 +0,0 @@ -package com.minelittlepony.unicopia.particle; - -import java.util.EnumSet; -import java.util.Random; - -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.entity.Entity; -import net.minecraft.particle.BlockStateParticleEffect; -import net.minecraft.particle.ParticleTypes; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.math.Direction; -import net.minecraft.util.math.Direction.Axis; -import net.minecraft.util.math.Vec3d; -import net.minecraft.world.World; - -public class ParticleEmitter { - - static final ParticleEmitter INSTANCE = new ParticleEmitter(); - - public static ParticleEmitter instance() { - return INSTANCE; - } - - private static final Vec3d BUFFER = new Vec3d(0.25, 0.25, 0.25); - private static final Vec3d HALF = new Vec3d(0.5, 0.5, 0.5); - - private static final EnumSet ALL_EXES = EnumSet.allOf(Axis.class); - - public void emitDestructionParticles(Entity entity, BlockState state) { - - float height = entity.getHeight(); - float width = entity.getWidth(); - - Vec3d dim = new Vec3d(width, height, width).add(BUFFER); - Vec3d origin = entity.getPos(); - - int total = (int)(32 * dim.length()); - - for (int i = 0; i < total; i++) { - Vec3d pos = centeredRange(entity.world.random, origin, dim); - Vec3d vel = pos.subtract(pos.floorAlongAxes(ALL_EXES).subtract(HALF)); - - spawnDiggingFX(entity.world, pos, vel, state, 1); - } - } - - public void emitDiggingParticles(Entity entity, Block block) { - emitDiggingParticles(entity, block.getDefaultState()); - } - - public void emitDiggingParticles(Entity entity, BlockState state) { - - Vec3d area = new Vec3d(entity.getWidth(), entity.getHeight(), entity.getWidth()).add(BUFFER); - Vec3d origin = entity.getPos(); - - for (Direction side : Direction.values()) { - Vec3d plane = Vec3d.of(side.getVector()); - - spawnDiggingFX(entity.getEntityWorld(), - clampPlane(side.getAxis(), - centeredRange(entity.world.random, origin, area), - origin.add(area.multiply(plane)) - ), - plane.multiply(0.5), state, 0.6F); - } - } - - private Vec3d clampPlane(Axis axis, Vec3d vector, Vec3d plane) { - return new Vec3d( - axis == Axis.X ? plane.x : vector.x, - axis == Axis.Y ? plane.y : vector.y, - axis == Axis.Z ? plane.z : vector.z - ); - } - - private Vec3d centeredRange(Random rand, Vec3d center, Vec3d max) { - return center - .add(new Vec3d( - rand.nextFloat(), - rand.nextFloat(), rand.nextFloat() - ).multiply(max)) - .subtract(max.multiply(0.5D)); - } - - protected void spawnDiggingFX(World w, Vec3d pos, Vec3d vel, BlockState blockState, float multVel) { - if (w instanceof ServerWorld) { - - double speed = vel.length() * multVel; - vel = vel.normalize(); - - ((ServerWorld)w).spawnParticles(new BlockStateParticleEffect(ParticleTypes.BLOCK, blockState), - pos.x, pos.y, pos.z, 1, - vel.x, vel.y, vel.z, - speed - ); - } - } -}