diff --git a/Dockerfile b/Dockerfile index 41834773..37d939f5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM eclipse-temurin:17-jre +FROM eclipse-temurin:20-jre RUN mkdir /app WORKDIR /app diff --git a/build.gradle.kts b/build.gradle.kts index c98fe9d8..6188668a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,10 +1,8 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar plugins { - `java-library` + java id("com.github.johnrengelman.shadow") version "8.1.1" - id("application") - id("io.freefair.lombok") version "6.6" } group = "pink.zak.minestom" @@ -12,37 +10,58 @@ version = "1.0-SNAPSHOT" repositories { mavenCentral() - mavenLocal() - maven("https://jitpack.io") maven("https://repo.emortal.dev/snapshots") maven("https://repo.emortal.dev/releases") + + maven("https://jitpack.io") maven("https://packages.confluent.io/maven/") } dependencies { - implementation("dev.emortal.minestom:core:1aa2d5e") + implementation("dev.emortal.minestom:core:9c52249") implementation("com.github.hollow-cube.common:schem:db5eab9512") - // TNT world format + // Polar world format implementation("dev.hollowcube:polar:1.3.1") implementation("com.github.ben-manes.caffeine:caffeine:3.1.6") } -application { - mainClass.set("pink.zak.minestom.towerdefence.TowerDefenceServer") -} -tasks.named("shadowJar") { - mergeServiceFiles() +java { + toolchain { + languageVersion.set(JavaLanguageVersion.of(20)) + } } -tasks.withType { - options.encoding = "UTF-8" -} +tasks { + withType { + options.encoding = "UTF-8" + } -java { - sourceCompatibility = JavaVersion.VERSION_17 - targetCompatibility = JavaVersion.VERSION_17 -} \ No newline at end of file + compileJava { + options.compilerArgs.addAll(listOf( + "--release", "20", + "--enable-preview" + )) + } + + shadowJar { + mergeServiceFiles() + + manifest { + attributes( + "Main-Class" to "pink.zak.minestom.towerdefence.TowerDefenceServer", + "Multi-Release" to true + ) + } + } + + withType { + isPreserveFileTimestamps = false + isReproducibleFileOrder = true + } + + build { dependsOn(shadowJar) } +} diff --git a/src/main/java/pink/zak/minestom/towerdefence/TowerDefenceModule.java b/src/main/java/pink/zak/minestom/towerdefence/TowerDefenceModule.java index 11be7190..9ff99b29 100644 --- a/src/main/java/pink/zak/minestom/towerdefence/TowerDefenceModule.java +++ b/src/main/java/pink/zak/minestom/towerdefence/TowerDefenceModule.java @@ -1,7 +1,8 @@ package pink.zak.minestom.towerdefence; -import dev.emortal.api.modules.ModuleData; -import dev.emortal.api.modules.ModuleEnvironment; +import dev.emortal.api.modules.annotation.Dependency; +import dev.emortal.api.modules.annotation.ModuleData; +import dev.emortal.api.modules.env.ModuleEnvironment; import dev.emortal.minestom.core.module.MinestomModule; import dev.emortal.minestom.core.module.kubernetes.KubernetesModule; import net.minestom.server.MinecraftServer; @@ -23,7 +24,7 @@ import pink.zak.minestom.towerdefence.world.TowerDefenceInstance; import pink.zak.minestom.towerdefence.world.WorldLoader; -@ModuleData(name = "towerdefence", required = false, softDependencies = {KubernetesModule.class}) +@ModuleData(name = "towerdefence", dependencies = @Dependency(name = "kubernetes")) public class TowerDefenceModule extends MinestomModule { private final KubernetesModule kubernetesModule; private final AgonesManager agonesManager; diff --git a/src/main/java/pink/zak/minestom/towerdefence/agones/AgonesManager.java b/src/main/java/pink/zak/minestom/towerdefence/agones/AgonesManager.java index 5559ca4f..9b2d06fd 100644 --- a/src/main/java/pink/zak/minestom/towerdefence/agones/AgonesManager.java +++ b/src/main/java/pink/zak/minestom/towerdefence/agones/AgonesManager.java @@ -2,7 +2,7 @@ import com.google.protobuf.InvalidProtocolBufferException; import dev.agones.sdk.AgonesSDKProto; -import dev.emortal.api.kurushimi.AllocationData; +import dev.emortal.api.model.matchmaker.AllocationData; import dev.emortal.minestom.core.module.kubernetes.KubernetesModule; import io.grpc.stub.StreamObserver; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/pink/zak/minestom/towerdefence/agones/GameCreationInfo.java b/src/main/java/pink/zak/minestom/towerdefence/agones/GameCreationInfo.java index c8b68c27..6393fb38 100644 --- a/src/main/java/pink/zak/minestom/towerdefence/agones/GameCreationInfo.java +++ b/src/main/java/pink/zak/minestom/towerdefence/agones/GameCreationInfo.java @@ -1,8 +1,8 @@ package pink.zak.minestom.towerdefence.agones; -import dev.emortal.api.kurushimi.AllocationData; -import dev.emortal.api.kurushimi.Match; -import dev.emortal.api.kurushimi.Ticket; +import dev.emortal.api.model.matchmaker.AllocationData; +import dev.emortal.api.model.matchmaker.Match; +import dev.emortal.api.model.matchmaker.Ticket; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/pink/zak/minestom/towerdefence/game/GameHandler.java b/src/main/java/pink/zak/minestom/towerdefence/game/GameHandler.java index d9161b33..0f6c24ca 100644 --- a/src/main/java/pink/zak/minestom/towerdefence/game/GameHandler.java +++ b/src/main/java/pink/zak/minestom/towerdefence/game/GameHandler.java @@ -3,9 +3,9 @@ import dev.agones.sdk.AgonesSDKProto; import dev.emortal.api.agonessdk.IgnoredStreamObserver; -import dev.emortal.api.kurushimi.KurushimiMinestomUtils; import dev.emortal.minestom.core.Environment; import dev.emortal.minestom.core.module.kubernetes.KubernetesModule; +import dev.emortal.minestom.core.utils.KurushimiMinestomUtils; import dev.emortal.minestom.core.utils.ProgressBar; import net.kyori.adventure.bossbar.BossBar; import net.kyori.adventure.text.Component; diff --git a/src/main/java/pink/zak/minestom/towerdefence/model/mob/config/EnemyMob.java b/src/main/java/pink/zak/minestom/towerdefence/model/mob/config/EnemyMob.java index 093d58f5..d6f17f41 100644 --- a/src/main/java/pink/zak/minestom/towerdefence/model/mob/config/EnemyMob.java +++ b/src/main/java/pink/zak/minestom/towerdefence/model/mob/config/EnemyMob.java @@ -2,7 +2,6 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import lombok.ToString; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; @@ -19,7 +18,6 @@ import java.util.stream.Collectors; import java.util.stream.StreamSupport; -@ToString public class EnemyMob { private static final MiniMessage MINI_MESSAGE = MiniMessage.miniMessage(); diff --git a/src/main/java/pink/zak/minestom/towerdefence/model/mob/config/EnemyMobLevel.java b/src/main/java/pink/zak/minestom/towerdefence/model/mob/config/EnemyMobLevel.java index d70a33d0..352fdb93 100644 --- a/src/main/java/pink/zak/minestom/towerdefence/model/mob/config/EnemyMobLevel.java +++ b/src/main/java/pink/zak/minestom/towerdefence/model/mob/config/EnemyMobLevel.java @@ -1,7 +1,6 @@ package pink.zak.minestom.towerdefence.model.mob.config; import com.google.gson.JsonObject; -import lombok.ToString; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; @@ -22,7 +21,6 @@ import java.util.ArrayList; import java.util.List; -@ToString public class EnemyMobLevel implements Diffable { private static final String SEND_ITEM_NAME = " "; private static final String UPGRADE_ITEM_NAME = "<%s> - $"; diff --git a/src/main/java/pink/zak/minestom/towerdefence/model/mob/living/SingleEnemyTDMob.java b/src/main/java/pink/zak/minestom/towerdefence/model/mob/living/SingleEnemyTDMob.java index 74c3fb72..7778ec62 100644 --- a/src/main/java/pink/zak/minestom/towerdefence/model/mob/living/SingleEnemyTDMob.java +++ b/src/main/java/pink/zak/minestom/towerdefence/model/mob/living/SingleEnemyTDMob.java @@ -159,6 +159,7 @@ private void updatePos() { } // TODO go fix in Minestom, teleport should call setView internally as it never updates + // TODO NOTE: This should be fixed in ce now, test. this.sendPacketsToViewers(new EntityHeadLookPacket(this.getEntityId(), newPos.yaw())); } diff --git a/src/main/java/pink/zak/minestom/towerdefence/model/tower/placed/types/ArcherTower.java b/src/main/java/pink/zak/minestom/towerdefence/model/tower/placed/types/ArcherTower.java index be16b4da..266202d5 100644 --- a/src/main/java/pink/zak/minestom/towerdefence/model/tower/placed/types/ArcherTower.java +++ b/src/main/java/pink/zak/minestom/towerdefence/model/tower/placed/types/ArcherTower.java @@ -1,6 +1,7 @@ package pink.zak.minestom.towerdefence.model.tower.placed.types; import net.kyori.adventure.text.Component; +import net.minestom.server.MinecraftServer; import net.minestom.server.adventure.audience.Audiences; import net.minestom.server.coordinate.Point; import net.minestom.server.coordinate.Pos; @@ -14,7 +15,9 @@ import net.minestom.server.event.trait.InstanceEvent; import net.minestom.server.instance.Instance; import net.minestom.server.item.Material; +import net.minestom.server.timer.Task; import net.minestom.server.utils.Direction; +import net.minestom.server.utils.time.TimeUnit; import org.jetbrains.annotations.NotNull; import pink.zak.minestom.towerdefence.model.mob.living.LivingTDEnemyMob; import pink.zak.minestom.towerdefence.model.prediction.Prediction; @@ -49,10 +52,10 @@ public ArcherTower(Instance instance, AttackingTower tower, Material towerBaseMa this.fakeShooter.setInstance(this.instance, this.basePoint.add(0, 4, 0)); } + // TODO it regularly misses on short distances when firing completely straight from the tower as the mob moves a lot in relation. // todo adjust arrow mid-flight // todo entity location prediction? // todo stick arrow in entity - // todo predict that we will kill the entity and don't target that entity any more. private void betterFire() { LivingTDEnemyMob target = this.targets.get(0); float damage = this.level.getDamage(); @@ -63,14 +66,27 @@ private void betterFire() { Point fPoint = this.getFiringPoint(targetPos); double distanceToTarget = fPoint.distance(targetPos); - double speed = (distanceToTarget / 4.5); + double speed = 0.75 + (distanceToTarget / 3.55); + double expansionSpeed = 10 + (distanceToTarget / 4.5); // NOTE: We can't expand the bounding box of the arrow MORE, or it will collide with the tower. this.fakeShooter.lookAt(targetPos); - ArcGuidedProjectile projectile = new ArcGuidedProjectile(EntityType.ARROW, this.fakeShooter, speed, 1.15); - projectile.setBoundingBox(projectile.getBoundingBox().expand(0.2, 0.2, 0.2)); + ArcGuidedProjectile projectile = new ArcGuidedProjectile(EntityType.ARROW, this.fakeShooter, speed, 1.25); + projectile.setBoundingBox(projectile.getBoundingBox().expand(0.25, 0.25, 0.25)); projectile.shoot(this.instance, fPoint, targetPos); + double increment = 0.0125 * expansionSpeed; + Audiences.all().sendMessage(Component.text("Increment: %s Distance: %s Speed: %s".formatted(increment, distanceToTarget, speed))); + + Task task = projectile.scheduler().buildTask(() -> { + Audiences.all().sendMessage(Component.text("Running arrow task for %s".formatted(projectile.getEntityId()))); + projectile.setBoundingBox(projectile.getBoundingBox().expand(increment, increment, increment)); + }).schedule(); + + projectile.scheduler().buildTask(task::cancel) + .delay(20L * MinecraftServer.TICK_PER_SECOND, TimeUnit.SERVER_TICK) + .schedule(); + this.eventNode.addListener(ProjectileCollideWithEntityEvent.class, event -> { Entity eventEntity = event.getEntity(); if (eventEntity != projectile) return; diff --git a/src/main/java/pink/zak/minestom/towerdefence/utils/projectile/ProjectileParent.java b/src/main/java/pink/zak/minestom/towerdefence/utils/projectile/ProjectileParent.java index 8dc76d5b..163a4d65 100644 --- a/src/main/java/pink/zak/minestom/towerdefence/utils/projectile/ProjectileParent.java +++ b/src/main/java/pink/zak/minestom/towerdefence/utils/projectile/ProjectileParent.java @@ -114,7 +114,8 @@ public void tick(long time) { PhysicsResult collided = CollisionUtils.checkEntityCollisions( this.instance, this.getBoundingBox(), posBefore, diff, 3, - entity -> entity != this && entity != this.shooter && entity instanceof LivingTDEnemyMob, + entity -> entity != this && entity != this.shooter && entity instanceof LivingTDEnemyMob + && !entity.isRemoved(), result ); diff --git a/src/main/java/pink/zak/minestom/towerdefence/world/TowerDefenceInstance.java b/src/main/java/pink/zak/minestom/towerdefence/world/TowerDefenceInstance.java index 5fd355cc..bd6cf591 100644 --- a/src/main/java/pink/zak/minestom/towerdefence/world/TowerDefenceInstance.java +++ b/src/main/java/pink/zak/minestom/towerdefence/world/TowerDefenceInstance.java @@ -4,7 +4,6 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import dev.emortal.minestom.core.Environment; -import lombok.SneakyThrows; import net.hollowcube.polar.PolarLoader; import net.minestom.server.coordinate.Point; import net.minestom.server.instance.Chunk; @@ -24,6 +23,7 @@ import java.io.FileNotFoundException; import java.io.FileReader; +import java.io.IOException; import java.nio.file.Path; import java.time.Instant; import java.util.HashSet; @@ -48,12 +48,17 @@ public class TowerDefenceInstance extends InstanceContainer { private final Path towerMapPath; private final TowerMap towerMap; - @SneakyThrows public TowerDefenceInstance(DimensionType dimensionType, String worldName) { super(UUID.randomUUID(), dimensionType, (IChunkLoader) null); Path mapPath = MAP_PATH.resolve(worldName); - PolarLoader loader = new PolarLoader(mapPath.resolve("world.polar")); + PolarLoader loader; + try { + loader = new PolarLoader(mapPath.resolve("world.polar")); + } catch (IOException e) { + throw new RuntimeException(e); + } + this.setChunkLoader(loader); this.preLoadDataPath = mapPath.resolve("preload_data.json");