diff --git a/src/main/java/com/minelittlepony/unicopia/client/particle/CloudsEscapingParticle.java b/src/main/java/com/minelittlepony/unicopia/client/particle/CloudsEscapingParticle.java index ceb7ea5c..a9fbb4c2 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/particle/CloudsEscapingParticle.java +++ b/src/main/java/com/minelittlepony/unicopia/client/particle/CloudsEscapingParticle.java @@ -17,25 +17,7 @@ public class CloudsEscapingParticle extends GroundPoundParticle { } @Override - public void tick() { - this.prevPosX = this.x; - this.prevPosY = this.y; - this.prevPosZ = this.z; - if (this.age++ >= this.maxAge) { - this.markDead(); - } else { - this.velocityY -= 0.04D * this.gravityStrength; - this.move(this.velocityX, this.velocityY, this.velocityZ); - this.velocityX *= 0.9800000190734863D; - this.velocityY *= 0.9800000190734863D; - this.velocityZ *= 0.9800000190734863D; - if (this.onGround) { - this.velocityX *= 0.699999988079071D; - this.velocityZ *= 0.699999988079071D; - } - - } - + public void spawnChildParticles() { this.velocityY += 0.125; Vec3d center = getPos(); diff --git a/src/main/java/com/minelittlepony/unicopia/client/particle/GroundPoundParticle.java b/src/main/java/com/minelittlepony/unicopia/client/particle/GroundPoundParticle.java index 1d51493b..98c9d93b 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/particle/GroundPoundParticle.java +++ b/src/main/java/com/minelittlepony/unicopia/client/particle/GroundPoundParticle.java @@ -39,7 +39,10 @@ public class GroundPoundParticle extends Particle { @Override public void tick() { super.tick(); + spawnChildParticles(); + } + protected void spawnChildParticles() { Vec3d vel = new Vec3d(0, (0.5 + (Math.sin(age) * 2.5)) * 5, 0); new Sphere(true, age, 1, 0, 1).offset(getPos()).randomPoints(random).forEach(point -> { diff --git a/src/main/java/com/minelittlepony/unicopia/entity/FloatingArtefactEntity.java b/src/main/java/com/minelittlepony/unicopia/entity/FloatingArtefactEntity.java index 3e920ee8..390fb800 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/FloatingArtefactEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/FloatingArtefactEntity.java @@ -23,11 +23,21 @@ public class FloatingArtefactEntity extends Entity { private static final TrackedData ITEM = DataTracker.registerData(FloatingArtefactEntity.class, TrackedDataHandlerRegistry.ITEM_STACK); private static final TrackedData STATE = DataTracker.registerData(FloatingArtefactEntity.class, TrackedDataHandlerRegistry.BYTE); + private static final TrackedData SPIN = DataTracker.registerData(FloatingArtefactEntity.class, TrackedDataHandlerRegistry.FLOAT); + + private float bobAmount; + private float spinAmount; - private int age; private float health = 1; public final float positionSeed; + private int spinupDuration; + + private float sourceSpin = 1; + private float targetSpin = 1; + private float spinChange; + private float spinChangeProgress; + public FloatingArtefactEntity(EntityType entityType, World world) { super(entityType, world); @@ -38,6 +48,7 @@ public class FloatingArtefactEntity extends Entity { protected void initDataTracker() { dataTracker.startTracking(ITEM, ItemStack.EMPTY); dataTracker.startTracking(STATE, (byte)0); + dataTracker.startTracking(SPIN, 1F); } public ItemStack getStack() { @@ -56,12 +67,21 @@ public class FloatingArtefactEntity extends Entity { dataTracker.set(STATE, (byte)state.ordinal()); } - public void addSpin(int spin) { - if (age != -32768) { - age += spin; + public void addSpin(float spin, int duration) { + if (spin >= getSpin()) { + setSpin(spin); + spinupDuration = duration; } } + public void setSpin(float spin) { + dataTracker.set(SPIN, spin); + } + + public float getSpin() { + return dataTracker.get(SPIN); + } + @Override public void tick() { Vec3d pos = Vec3d.ofBottomCenter(getBlockPos()); @@ -76,6 +96,33 @@ public class FloatingArtefactEntity extends Entity { setStack(UItems.EMPTY_JAR.getDefaultStack()); } + if (world.isClient) { + float spin = getSpin(); + if (Math.abs(spin - targetSpin) > 1.0E-5F) { + spinChange = spin - targetSpin; + targetSpin = spin; + spinChangeProgress = 0; + } + + if (spinChange != 0) { + if (spinChangeProgress < 1) { + spinChangeProgress += 0.05F; + } else { + sourceSpin = targetSpin; + spinChange = 0; + spinChangeProgress = 0; + } + } + + spinAmount += sourceSpin + (spinChange * spinChangeProgress); + bobAmount++; + } else { + spinupDuration = Math.max(0, spinupDuration - 1); + if (spinupDuration <= 0) { + setSpin(1); + } + } + if (stack.getItem() instanceof Artifact) { ((Artifact)stack.getItem()).onArtifactTick(this); } @@ -84,16 +131,14 @@ public class FloatingArtefactEntity extends Entity { State state = getState(); playSound(SoundEvents.BLOCK_BEACON_AMBIENT, state.getVolume(), state.getPitch()); } - - addSpin(1); } public float getVerticalOffset(float tickDelta) { - return MathHelper.sin((age + tickDelta) / 10F + positionSeed) * 0.025F + 0.05F; + return MathHelper.sin((bobAmount + tickDelta) / 10F + positionSeed) * 0.025F + 0.05F; } public float getRotation(float tickDelta) { - return (age + tickDelta) / 20 + positionSeed; + return (spinAmount + tickDelta) / 20 + positionSeed; } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/item/CrystalHeartItem.java b/src/main/java/com/minelittlepony/unicopia/item/CrystalHeartItem.java index ad00cfb4..6e9c4c50 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/CrystalHeartItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/CrystalHeartItem.java @@ -88,7 +88,7 @@ public class CrystalHeartItem extends Item implements FloatingArtefactEntity.Art entity.setState(State.INITIALISING); } - entity.addSpin(2); + entity.addSpin(2, 10); BlockPos pos = entity.getBlockPos(); entity.world.addParticle(ParticleTypes.COMPOSTER, @@ -144,7 +144,8 @@ public class CrystalHeartItem extends Item implements FloatingArtefactEntity.Art ParticleUtils.spawnParticles(new FollowingParticleEffect(UParticles.HEALTH_DRAIN, output, 0.2F), entity, 1); output.heal(gives); }); - entity.addSpin((int)gives); + + entity.addSpin(gives > 0 ? 20 : 10, 30); } }