diff --git a/build.gradle.kts b/build.gradle.kts index 22fd74a..1c16603 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -17,7 +17,7 @@ repositories { } dependencies { - implementation("dev.emortal.minestom:game-sdk:ecc0cee") + implementation("dev.emortal.minestom:game-sdk:24f5059") implementation("net.kyori:adventure-text-minimessage:4.16.0") } diff --git a/src/main/java/dev/emortal/minestom/marathon/MarathonGame.java b/src/main/java/dev/emortal/minestom/marathon/MarathonGame.java index 183873a..435252c 100644 --- a/src/main/java/dev/emortal/minestom/marathon/MarathonGame.java +++ b/src/main/java/dev/emortal/minestom/marathon/MarathonGame.java @@ -1,7 +1,7 @@ package dev.emortal.minestom.marathon; import dev.emortal.minestom.marathon.animator.BlockAnimator; -import dev.emortal.minestom.marathon.animator.SuvatAnimator; +import dev.emortal.minestom.marathon.animator.PathAnimator; import dev.emortal.minestom.marathon.generator.DefaultGenerator; import dev.emortal.minestom.marathon.generator.Generator; import dev.emortal.minestom.marathon.palette.BlockPalette; @@ -17,7 +17,6 @@ import net.minestom.server.entity.Entity; import net.minestom.server.entity.GameMode; import net.minestom.server.entity.Player; -import net.minestom.server.event.instance.InstanceChunkUnloadEvent; import net.minestom.server.event.player.PlayerChunkUnloadEvent; import net.minestom.server.instance.Chunk; import net.minestom.server.instance.Instance; @@ -29,7 +28,6 @@ import net.minestom.server.timer.Task; import net.minestom.server.timer.TaskSchedule; import net.minestom.server.utils.MathUtils; -import net.minestom.server.utils.NamespaceID; import net.minestom.server.world.DimensionType; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -71,7 +69,7 @@ public final class MarathonGame { this.player = player; this.generator = DefaultGenerator.INSTANCE; - this.animator = new SuvatAnimator(); + this.animator = new PathAnimator(); this.palette = BlockPalette.OVERWORLD; this.instance = MinecraftServer.getInstanceManager().createInstanceContainer(dimension); diff --git a/src/main/java/dev/emortal/minestom/marathon/animator/PathAnimator.java b/src/main/java/dev/emortal/minestom/marathon/animator/PathAnimator.java index aad7183..cec02d4 100644 --- a/src/main/java/dev/emortal/minestom/marathon/animator/PathAnimator.java +++ b/src/main/java/dev/emortal/minestom/marathon/animator/PathAnimator.java @@ -1,13 +1,13 @@ package dev.emortal.minestom.marathon.animator; import dev.emortal.minestom.marathon.MarathonGame; -import net.minestom.server.ServerFlag; +import dev.emortal.minestom.marathon.util.NoPhysicsEntity; import net.minestom.server.coordinate.Point; import net.minestom.server.coordinate.Pos; import net.minestom.server.coordinate.Vec; import net.minestom.server.entity.Entity; import net.minestom.server.entity.EntityType; -import net.minestom.server.entity.metadata.other.FallingBlockMeta; +import net.minestom.server.entity.metadata.display.BlockDisplayMeta; import net.minestom.server.instance.Instance; import net.minestom.server.instance.block.Block; import net.minestom.server.timer.TaskSchedule; @@ -15,8 +15,6 @@ import org.jetbrains.annotations.Nullable; public final class PathAnimator implements BlockAnimator { - private static final double TIME_TO_ANIMATE = 0.6; - private @Nullable Entity lastEntity = null; @Override @@ -26,29 +24,28 @@ public void setBlockAnimated(@NotNull Instance instance, @NotNull Point point, @ realLastPoint = this.lastEntity.getPosition(); } - this.lastEntity = new Entity(EntityType.FALLING_BLOCK); + this.lastEntity = new NoPhysicsEntity(EntityType.BLOCK_DISPLAY); this.lastEntity.setTag(MarathonGame.MARATHON_ENTITY_TAG, true); this.lastEntity.setNoGravity(true); - - FallingBlockMeta meta = (FallingBlockMeta) this.lastEntity.getEntityMeta(); - meta.setBlock(block); - - Vec newVelocity = Vec.fromPoint(point.sub(realLastPoint)) - .normalize() - .mul(point.distance(realLastPoint) / TIME_TO_ANIMATE); - this.lastEntity.setVelocity(newVelocity); - - this.lastEntity.setInstance(instance, realLastPoint); - + this.lastEntity.editEntityMeta(BlockDisplayMeta.class, meta -> { + meta.setBlockState(block); + meta.setTranslation(new Vec(-0.5, 0.0, -0.5)); + meta.setPosRotInterpolationDuration(3); + }); Entity finalEntity = this.lastEntity; + this.lastEntity.setInstance(instance, realLastPoint).thenRun(() -> { + finalEntity.scheduler().buildTask(() -> { + finalEntity.teleport(Pos.fromPoint(point)); + }).repeat(TaskSchedule.tick(1)).schedule(); + }); + this.lastEntity.scheduler() .buildTask(() -> { - finalEntity.remove(); instance.setBlock(point, block); + finalEntity.scheduleNextTick(Entity::remove); }) - .delay(TaskSchedule.tick((int) (TIME_TO_ANIMATE * ServerFlag.SERVER_TICKS_PER_SECOND))) + .delay(TaskSchedule.tick(13)) .schedule(); -// lastEntity.scheduleRemove(Duration.ofMillis((long) (timeToAnimate * 1000))); } @Override diff --git a/src/main/java/dev/emortal/minestom/marathon/animator/ScaleAnimator.java b/src/main/java/dev/emortal/minestom/marathon/animator/ScaleAnimator.java new file mode 100755 index 0000000..f0b1ab8 --- /dev/null +++ b/src/main/java/dev/emortal/minestom/marathon/animator/ScaleAnimator.java @@ -0,0 +1,53 @@ +package dev.emortal.minestom.marathon.animator; + +import dev.emortal.minestom.marathon.MarathonGame; +import dev.emortal.minestom.marathon.util.NoPhysicsEntity; +import net.minestom.server.coordinate.Point; +import net.minestom.server.coordinate.Vec; +import net.minestom.server.entity.Entity; +import net.minestom.server.entity.EntityType; +import net.minestom.server.entity.metadata.display.BlockDisplayMeta; +import net.minestom.server.instance.Instance; +import net.minestom.server.instance.block.Block; +import net.minestom.server.timer.TaskSchedule; +import org.jetbrains.annotations.NotNull; + +public final class ScaleAnimator implements BlockAnimator { + @Override + public void setBlockAnimated(@NotNull Instance instance, @NotNull Point point, @NotNull Block block, @NotNull Point lastPoint) { + int effectDuration = 3; + + Entity entity = new NoPhysicsEntity(EntityType.BLOCK_DISPLAY); + entity.setNoGravity(true); + entity.setTag(MarathonGame.MARATHON_ENTITY_TAG, true); + entity.editEntityMeta(BlockDisplayMeta.class, meta -> { + meta.setBlockState(Block.AIR); + meta.setScale(new Vec(0.5)); + meta.setTranslation(new Vec(-0.25, 0.0, -0.25)); + meta.setTransformationInterpolationStartDelta(0); + meta.setTransformationInterpolationDuration(effectDuration); + }); + + entity.setInstance(instance, point).thenRun(() -> { + entity.scheduler().buildTask(() -> { + entity.editEntityMeta(BlockDisplayMeta.class, meta -> { + meta.setBlockState(block); + meta.setTranslation(new Vec(-0.5, 0.0, -0.5)); + meta.setScale(new Vec(1)); + }); + }).delay(TaskSchedule.tick(2)).schedule(); + }); + + entity.scheduler() + .buildTask(() -> { + instance.setBlock(point, block); + entity.scheduleNextTick(Entity::remove); + }) + .delay(TaskSchedule.tick(effectDuration + 4)) + .schedule(); + } + + @Override + public void reset() { + } +} diff --git a/src/main/java/dev/emortal/minestom/marathon/util/NoPhysicsEntity.java b/src/main/java/dev/emortal/minestom/marathon/util/NoPhysicsEntity.java new file mode 100644 index 0000000..5287d82 --- /dev/null +++ b/src/main/java/dev/emortal/minestom/marathon/util/NoPhysicsEntity.java @@ -0,0 +1,12 @@ +package dev.emortal.minestom.marathon.util; + +import net.minestom.server.entity.Entity; +import net.minestom.server.entity.EntityType; + +public class NoPhysicsEntity extends Entity { + + public NoPhysicsEntity(EntityType entityType) { + super(entityType); + hasPhysics = false; + } +}