Skip to content

Commit

Permalink
Update to 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
emortaldev committed Aug 5, 2024
1 parent 3b13a9c commit 7d51ed3
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 24 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/dev/emortal/minestom/marathon/MarathonGame.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
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;
import org.jetbrains.annotations.NotNull;
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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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() {
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 7d51ed3

Please sign in to comment.