mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-12-17 23:48:00 +01:00
Smoothly animate the spinning of the crystal heart
This commit is contained in:
parent
374bf84548
commit
5a24a6162e
4 changed files with 60 additions and 29 deletions
|
@ -17,25 +17,7 @@ public class CloudsEscapingParticle extends GroundPoundParticle {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tick() {
|
public void spawnChildParticles() {
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
this.velocityY += 0.125;
|
this.velocityY += 0.125;
|
||||||
|
|
||||||
Vec3d center = getPos();
|
Vec3d center = getPos();
|
||||||
|
|
|
@ -39,7 +39,10 @@ public class GroundPoundParticle extends Particle {
|
||||||
@Override
|
@Override
|
||||||
public void tick() {
|
public void tick() {
|
||||||
super.tick();
|
super.tick();
|
||||||
|
spawnChildParticles();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void spawnChildParticles() {
|
||||||
Vec3d vel = new Vec3d(0, (0.5 + (Math.sin(age) * 2.5)) * 5, 0);
|
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 -> {
|
new Sphere(true, age, 1, 0, 1).offset(getPos()).randomPoints(random).forEach(point -> {
|
||||||
|
|
|
@ -23,11 +23,21 @@ public class FloatingArtefactEntity extends Entity {
|
||||||
|
|
||||||
private static final TrackedData<ItemStack> ITEM = DataTracker.registerData(FloatingArtefactEntity.class, TrackedDataHandlerRegistry.ITEM_STACK);
|
private static final TrackedData<ItemStack> ITEM = DataTracker.registerData(FloatingArtefactEntity.class, TrackedDataHandlerRegistry.ITEM_STACK);
|
||||||
private static final TrackedData<Byte> STATE = DataTracker.registerData(FloatingArtefactEntity.class, TrackedDataHandlerRegistry.BYTE);
|
private static final TrackedData<Byte> STATE = DataTracker.registerData(FloatingArtefactEntity.class, TrackedDataHandlerRegistry.BYTE);
|
||||||
|
private static final TrackedData<Float> SPIN = DataTracker.registerData(FloatingArtefactEntity.class, TrackedDataHandlerRegistry.FLOAT);
|
||||||
|
|
||||||
|
private float bobAmount;
|
||||||
|
private float spinAmount;
|
||||||
|
|
||||||
private int age;
|
|
||||||
private float health = 1;
|
private float health = 1;
|
||||||
public final float positionSeed;
|
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) {
|
public FloatingArtefactEntity(EntityType<?> entityType, World world) {
|
||||||
super(entityType, world);
|
super(entityType, world);
|
||||||
|
|
||||||
|
@ -38,6 +48,7 @@ public class FloatingArtefactEntity extends Entity {
|
||||||
protected void initDataTracker() {
|
protected void initDataTracker() {
|
||||||
dataTracker.startTracking(ITEM, ItemStack.EMPTY);
|
dataTracker.startTracking(ITEM, ItemStack.EMPTY);
|
||||||
dataTracker.startTracking(STATE, (byte)0);
|
dataTracker.startTracking(STATE, (byte)0);
|
||||||
|
dataTracker.startTracking(SPIN, 1F);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack getStack() {
|
public ItemStack getStack() {
|
||||||
|
@ -56,12 +67,21 @@ public class FloatingArtefactEntity extends Entity {
|
||||||
dataTracker.set(STATE, (byte)state.ordinal());
|
dataTracker.set(STATE, (byte)state.ordinal());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addSpin(int spin) {
|
public void addSpin(float spin, int duration) {
|
||||||
if (age != -32768) {
|
if (spin >= getSpin()) {
|
||||||
age += spin;
|
setSpin(spin);
|
||||||
|
spinupDuration = duration;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setSpin(float spin) {
|
||||||
|
dataTracker.set(SPIN, spin);
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getSpin() {
|
||||||
|
return dataTracker.get(SPIN);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tick() {
|
public void tick() {
|
||||||
Vec3d pos = Vec3d.ofBottomCenter(getBlockPos());
|
Vec3d pos = Vec3d.ofBottomCenter(getBlockPos());
|
||||||
|
@ -76,6 +96,33 @@ public class FloatingArtefactEntity extends Entity {
|
||||||
setStack(UItems.EMPTY_JAR.getDefaultStack());
|
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) {
|
if (stack.getItem() instanceof Artifact) {
|
||||||
((Artifact)stack.getItem()).onArtifactTick(this);
|
((Artifact)stack.getItem()).onArtifactTick(this);
|
||||||
}
|
}
|
||||||
|
@ -84,16 +131,14 @@ public class FloatingArtefactEntity extends Entity {
|
||||||
State state = getState();
|
State state = getState();
|
||||||
playSound(SoundEvents.BLOCK_BEACON_AMBIENT, state.getVolume(), state.getPitch());
|
playSound(SoundEvents.BLOCK_BEACON_AMBIENT, state.getVolume(), state.getPitch());
|
||||||
}
|
}
|
||||||
|
|
||||||
addSpin(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getVerticalOffset(float tickDelta) {
|
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) {
|
public float getRotation(float tickDelta) {
|
||||||
return (age + tickDelta) / 20 + positionSeed;
|
return (spinAmount + tickDelta) / 20 + positionSeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -88,7 +88,7 @@ public class CrystalHeartItem extends Item implements FloatingArtefactEntity.Art
|
||||||
entity.setState(State.INITIALISING);
|
entity.setState(State.INITIALISING);
|
||||||
}
|
}
|
||||||
|
|
||||||
entity.addSpin(2);
|
entity.addSpin(2, 10);
|
||||||
|
|
||||||
BlockPos pos = entity.getBlockPos();
|
BlockPos pos = entity.getBlockPos();
|
||||||
entity.world.addParticle(ParticleTypes.COMPOSTER,
|
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);
|
ParticleUtils.spawnParticles(new FollowingParticleEffect(UParticles.HEALTH_DRAIN, output, 0.2F), entity, 1);
|
||||||
output.heal(gives);
|
output.heal(gives);
|
||||||
});
|
});
|
||||||
entity.addSpin((int)gives);
|
|
||||||
|
entity.addSpin(gives > 0 ? 20 : 10, 30);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue