Skip to content

Commit

Permalink
Update minestom core
Browse files Browse the repository at this point in the history
  • Loading branch information
ZakShearman committed Aug 31, 2023
1 parent c984aa4 commit 1d93ffb
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 40 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM eclipse-temurin:17-jre
FROM eclipse-temurin:20-jre

RUN mkdir /app
WORKDIR /app
Expand Down
57 changes: 38 additions & 19 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,48 +1,67 @@
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"
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>("shadowJar") {
mergeServiceFiles()
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(20))
}
}

tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
}
tasks {
withType<JavaCompile> {
options.encoding = "UTF-8"
}

java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
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<AbstractArchiveTask> {
isPreserveFileTimestamps = false
isReproducibleFileOrder = true
}

build { dependsOn(shadowJar) }
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -22,7 +21,6 @@
import java.util.ArrayList;
import java.util.List;

@ToString
public class EnemyMobLevel implements Diffable<EnemyMobLevel> {
private static final String SEND_ITEM_NAME = "<i:false><mob_name> <level_numeral>";
private static final String UPGRADE_ITEM_NAME = "<i:false><%s><level_numeral> - <yellow>$<cost></yellow>";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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");
Expand Down

0 comments on commit 1d93ffb

Please sign in to comment.