From 2cf748b5ad0a70ca309994d4db34616befc0f32f Mon Sep 17 00:00:00 2001
From: Zak <34372536+ZakShearman@users.noreply.github.com>
Date: Fri, 27 Sep 2024 14:36:31 +0100
Subject: [PATCH] feat: update to 1.21
---
.run/TowerDefenceServer.run.xml | 2 +-
build.gradle.kts | 11 +++---
.../towerdefence/enums/TowerSize.java | 16 ---------
.../towerdefence/game/GameHandler.java | 4 +--
.../towerdefence/lobby/SpawnItemHandler.java | 9 +++--
.../model/mob/config/EnemyMob.java | 22 +++++++-----
.../model/mob/config/EnemyMobLevel.java | 34 ++++++++-----------
.../model/mob/living/SingleEnemyTDMob.java | 29 ++++++++--------
.../model/mob/living/SingleTDMob.java | 12 +++++--
.../model/tower/config/Tower.java | 18 +++++-----
.../model/tower/config/TowerLevel.java | 18 +++++-----
.../model/tower/placed/Projectile.java | 3 +-
.../model/tower/placed/types/BomberTower.java | 24 ++++++-------
.../tower/placed/types/EarthquakeTower.java | 9 ++---
.../tower/placed/types/NecromancerTower.java | 23 +++----------
.../towerdefence/model/user/TDPlayer.java | 1 -
.../minestom/towerdefence/queue/MobQueue.java | 19 ++++++-----
.../towerdefence/ui/ConfirmationUI.java | 8 +++--
.../towerdefence/ui/UserSettingsUI.java | 22 ++++++------
.../ui/spawner/TroopSpawnerUI.java | 17 +++++-----
.../ui/spawner/TroopUpgradeUI.java | 6 ++--
.../ui/tower/TowerManagementUI.java | 27 ++++++++-------
.../towerdefence/ui/tower/TowerOutliner.java | 3 +-
.../towerdefence/ui/tower/TowerPlaceUI.java | 9 ++---
.../towerdefence/utils/ItemUtils.java | 34 ++++++-------------
.../world/TowerDefenceInstance.java | 2 +-
.../towerdefence/world/WorldLoader.java | 17 ++++++----
27 files changed, 191 insertions(+), 208 deletions(-)
diff --git a/.run/TowerDefenceServer.run.xml b/.run/TowerDefenceServer.run.xml
index 784ac79f..67a75862 100644
--- a/.run/TowerDefenceServer.run.xml
+++ b/.run/TowerDefenceServer.run.xml
@@ -7,7 +7,7 @@
-
+
diff --git a/build.gradle.kts b/build.gradle.kts
index 57b52704..264972ab 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -19,15 +19,16 @@ repositories {
}
dependencies {
- implementation("dev.emortal.minestom:core:eafe4f7") {
+ implementation("dev.emortal.minestom:core:80be174") {
exclude(group = "net.minestom", module = "minestom-snapshots")
}
- implementation("net.minestom:minestom-snapshots:7e59603d5f")
- implementation("dev.emortal.api:common-proto-sdk:15284aa")
- implementation("dev.hollowcube:schem:1.0.1")
+ implementation("net.minestom:minestom-snapshots:d0754f2a15")
+ implementation("dev.emortal.api:common-proto-sdk:2584fd2")
+
+ implementation("dev.hollowcube:schem:1.2.0")
// Polar world format
- implementation("dev.hollowcube:polar:1.7.2")
+ implementation("dev.hollowcube:polar:1.11.3")
implementation("com.github.ben-manes.caffeine:caffeine:3.1.8")
}
diff --git a/src/main/java/pink/zak/minestom/towerdefence/enums/TowerSize.java b/src/main/java/pink/zak/minestom/towerdefence/enums/TowerSize.java
index d0e01dbc..42c11b55 100644
--- a/src/main/java/pink/zak/minestom/towerdefence/enums/TowerSize.java
+++ b/src/main/java/pink/zak/minestom/towerdefence/enums/TowerSize.java
@@ -1,22 +1,6 @@
package pink.zak.minestom.towerdefence.enums;
-import java.util.HashSet;
-import java.util.Set;
-import net.kyori.adventure.text.format.TextColor;
-import net.minestom.server.collision.Shape;
-import net.minestom.server.coordinate.Point;
-import net.minestom.server.coordinate.Pos;
-import net.minestom.server.entity.Player;
-import net.minestom.server.instance.Instance;
-import net.minestom.server.instance.block.Block;
-import net.minestom.server.item.Material;
-import net.minestom.server.network.packet.server.SendablePacket;
-import net.minestom.server.network.packet.server.play.ParticlePacket;
-import net.minestom.server.particle.Particle;
-import net.minestom.server.particle.data.DustParticleData;
import org.jetbrains.annotations.NotNull;
-import pink.zak.minestom.towerdefence.model.tower.placed.PlacedTower;
-import pink.zak.minestom.towerdefence.world.TowerDefenceInstance;
public enum TowerSize {
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 557b1ed4..f87c8343 100644
--- a/src/main/java/pink/zak/minestom/towerdefence/game/GameHandler.java
+++ b/src/main/java/pink/zak/minestom/towerdefence/game/GameHandler.java
@@ -238,12 +238,12 @@ private void shutdownTask() {
if (Environment.isProduction()) {
KurushimiMinestomUtils.sendToLobby(MinecraftServer.getConnectionManager().getOnlinePlayers(), () -> {
- this.kubernetesModule.getSdk().shutdown(AgonesSDKProto.Empty.getDefaultInstance(), new IgnoredStreamObserver<>());
+ this.kubernetesModule.getAgonesSdk().shutdown(AgonesSDKProto.Empty.getDefaultInstance(), new IgnoredStreamObserver<>());
}, () -> {
for (Player player : MinecraftServer.getConnectionManager().getOnlinePlayers()) {
player.kick(Component.text("Server shutting down"));
}
- this.kubernetesModule.getSdk().shutdown(AgonesSDKProto.Empty.getDefaultInstance(), new IgnoredStreamObserver<>());
+ this.kubernetesModule.getAgonesSdk().shutdown(AgonesSDKProto.Empty.getDefaultInstance(), new IgnoredStreamObserver<>());
});
}
})
diff --git a/src/main/java/pink/zak/minestom/towerdefence/lobby/SpawnItemHandler.java b/src/main/java/pink/zak/minestom/towerdefence/lobby/SpawnItemHandler.java
index 9ee067ef..28c0ef2e 100644
--- a/src/main/java/pink/zak/minestom/towerdefence/lobby/SpawnItemHandler.java
+++ b/src/main/java/pink/zak/minestom/towerdefence/lobby/SpawnItemHandler.java
@@ -15,6 +15,7 @@
import net.minestom.server.event.player.PlayerUseItemEvent;
import net.minestom.server.event.player.PlayerUseItemOnBlockEvent;
import net.minestom.server.inventory.click.ClickType;
+import net.minestom.server.item.ItemComponent;
import net.minestom.server.item.ItemStack;
import net.minestom.server.item.Material;
import pink.zak.minestom.towerdefence.api.event.player.PlayerTeamSwitchEvent;
@@ -105,13 +106,14 @@ private void updateTeamItems() {
private synchronized void updateTeamItem(Team team) {
Material material;
String name;
- List extends Component> lore;
+ List lore;
if (team == Team.BLUE) {
material = Material.BLUE_WOOL;
name = "Blue Team (" + this.lobbyManager.getTeamSize(Team.BLUE).get() + "/6)";
lore = this.lobbyManager.getLobbyPlayers().stream()
.filter(lobbyPlayer -> lobbyPlayer.getTeam() == Team.BLUE)
.map(lobbyPlayer -> Component.text(" - " + lobbyPlayer.getPlayer().getUsername(), Style.style(NamedTextColor.AQUA, TextDecoration.ITALIC.withState(TextDecoration.State.FALSE))))
+ .map(c -> (Component) c)
.toList();
} else {
material = Material.RED_WOOL;
@@ -119,12 +121,13 @@ private synchronized void updateTeamItem(Team team) {
lore = this.lobbyManager.getLobbyPlayers().stream()
.filter(lobbyPlayer -> lobbyPlayer.getTeam() == Team.RED)
.map(lobbyPlayer -> Component.text(" - " + lobbyPlayer.getPlayer().getUsername(), Style.style(NamedTextColor.RED, TextDecoration.ITALIC.withState(TextDecoration.State.FALSE))))
+ .map(c -> (Component) c)
.toList();
}
ItemStack teamItem = ItemStack.builder(material)
- .displayName(Component.text(name, team.getColor()).decoration(TextDecoration.ITALIC, false))
- .lore(lore)
+ .set(ItemComponent.CUSTOM_NAME, Component.text(name, team.getColor()).decoration(TextDecoration.ITALIC, false))
+ .set(ItemComponent.LORE, lore)
.build();
if (team == Team.BLUE)
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 99e7a963..9ba5a329 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,15 +2,10 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
-import java.util.ArrayList;
-import java.util.Comparator;
-import java.util.List;
-import java.util.Set;
-import java.util.stream.Collectors;
-import java.util.stream.StreamSupport;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
+import net.minestom.server.item.ItemComponent;
import net.minestom.server.item.ItemStack;
import net.minestom.server.item.Material;
import org.jetbrains.annotations.NotNull;
@@ -18,6 +13,13 @@
import pink.zak.minestom.towerdefence.model.mob.statuseffect.StatusEffectType;
import pink.zak.minestom.towerdefence.utils.ItemUtils;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
+
public class EnemyMob {
private static final MiniMessage MINI_MESSAGE = MiniMessage.miniMessage();
@@ -51,7 +53,7 @@ public EnemyMob(@NotNull JsonObject jsonObject) {
ItemStack item = jsonObject.has("item") ? ItemUtils.fromJsonObject(jsonObject.get("item").getAsJsonObject(), null) : null;
if (item == null) {
- this.baseItem = ItemStack.builder(Material.BARRIER).displayName(Component.text("No item set")).build();
+ this.baseItem = ItemStack.builder(Material.BARRIER).set(ItemComponent.CUSTOM_NAME, Component.text("No item set")).build();
} else {
EnemyMobLevel levelOne = this.levels.get(1);
List lore = new ArrayList<>();
@@ -61,8 +63,10 @@ public EnemyMob(@NotNull JsonObject jsonObject) {
lore.addAll(levelOne.generateDiff(levelOne).generateStatLines());
this.baseItem = item
- .withDisplayName(MINI_MESSAGE.deserialize(BASE_ITEM_DISPLAY_NAME, Placeholder.unparsed("mob_name", this.commonName)))
- .withLore(lore);
+ .with(builder -> {
+ builder.set(ItemComponent.CUSTOM_NAME, MINI_MESSAGE.deserialize(BASE_ITEM_DISPLAY_NAME, Placeholder.unparsed("mob_name", this.commonName)));
+ builder.set(ItemComponent.LORE, lore);
+ });
}
}
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 9e417fcb..633aebaa 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,16 +1,13 @@
package pink.zak.minestom.towerdefence.model.mob.config;
import com.google.gson.JsonObject;
-import java.text.DecimalFormat;
-import java.util.ArrayList;
-import java.util.List;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
-import net.minestom.server.MinecraftServer;
import net.minestom.server.ServerFlag;
import net.minestom.server.entity.EntityType;
+import net.minestom.server.item.ItemComponent;
import net.minestom.server.item.ItemStack;
import net.minestom.server.item.Material;
import org.jetbrains.annotations.NotNull;
@@ -21,6 +18,10 @@
import pink.zak.minestom.towerdefence.utils.ItemUtils;
import pink.zak.minestom.towerdefence.utils.NumberUtils;
+import java.text.DecimalFormat;
+import java.util.ArrayList;
+import java.util.List;
+
public class EnemyMobLevel implements Diffable, Comparable {
private static final String SEND_ITEM_NAME = " ";
private static final String UPGRADE_ITEM_NAME = "<%s> - $";
@@ -70,25 +71,18 @@ public EnemyMobLevel(@NotNull String name, @NotNull JsonObject jsonObject) {
}
public ItemStack createSendItem() {
- return ItemStack.builder(this.sendItem.material())
- .meta(this.sendItem.meta())
- .displayName(MiniMessage.miniMessage().deserialize(SEND_ITEM_NAME,
- Placeholder.unparsed("mob_name", this.name),
- Placeholder.unparsed("level_numeral", NumberUtils.toRomanNumerals(this.level)),
- Placeholder.unparsed("cost", String.valueOf(this.sendCost))))
- .lore(this.createStatLore())
- .build();
- }
-
- public @NotNull ItemStack createPreviewItem() {
- return ItemStack.builder(this.sendItem.material())
- .meta(this.sendItem.meta())
- .build();
+ return this.sendItem.with(builder -> {
+ builder.set(ItemComponent.CUSTOM_NAME, MiniMessage.miniMessage().deserialize(SEND_ITEM_NAME,
+ Placeholder.unparsed("mob_name", this.name),
+ Placeholder.unparsed("level_numeral", NumberUtils.toRomanNumerals(this.level)),
+ Placeholder.unparsed("cost", String.valueOf(this.sendCost))));
+ builder.set(ItemComponent.LORE, this.createStatLore());
+ });
}
public ItemStack createStatUpgradeItem(int cost, boolean canAfford, boolean owned) {
return ItemStack.builder(owned ? Material.GREEN_STAINED_GLASS_PANE : canAfford ? Material.ORANGE_STAINED_GLASS_PANE : Material.RED_STAINED_GLASS_PANE)
- .displayName(MiniMessage.miniMessage().deserialize(
+ .set(ItemComponent.CUSTOM_NAME, MiniMessage.miniMessage().deserialize(
UPGRADE_ITEM_NAME.formatted(owned ? "green" : canAfford ? "gold" : "red"),
Placeholder.unparsed("level_numeral", NumberUtils.toRomanNumerals(this.level)),
Placeholder.unparsed("cost", String.valueOf(cost))))
@@ -100,7 +94,7 @@ public ItemStack createStatUpgradeItem(int cost, boolean canAfford, boolean owne
String itemName = UPGRADE_ITEM_NAME.formatted(canAfford ? "gold" : "red");
return ItemStack.builder(canAfford ? Material.ORANGE_STAINED_GLASS_PANE : Material.RED_STAINED_GLASS_PANE)
- .displayName(MiniMessage.miniMessage().deserialize(itemName,
+ .set(ItemComponent.CUSTOM_NAME, MiniMessage.miniMessage().deserialize(itemName,
Placeholder.unparsed("level_numeral", NumberUtils.toRomanNumerals(this.level)),
Placeholder.unparsed("cost", String.valueOf(cost))))
.lore(this.createUpgradeLore(currentLevel))
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 afe2b114..15d6bf12 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
@@ -1,24 +1,15 @@
package pink.zak.minestom.towerdefence.model.mob.living;
-import java.time.temporal.ChronoUnit;
-import java.util.Collections;
-import java.util.EnumMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.CopyOnWriteArraySet;
-import java.util.concurrent.ThreadLocalRandom;
import net.kyori.adventure.sound.Sound;
import net.kyori.adventure.text.Component;
import net.minestom.server.MinecraftServer;
-import net.minestom.server.attribute.Attribute;
import net.minestom.server.coordinate.Pos;
import net.minestom.server.entity.Entity;
import net.minestom.server.entity.EntityType;
import net.minestom.server.entity.Metadata;
import net.minestom.server.entity.Player;
-import net.minestom.server.entity.damage.DamageType;
+import net.minestom.server.entity.attribute.Attribute;
+import net.minestom.server.entity.damage.Damage;
import net.minestom.server.instance.Instance;
import net.minestom.server.network.packet.server.play.EntityAnimationPacket;
import net.minestom.server.network.packet.server.play.EntityHeadLookPacket;
@@ -49,6 +40,16 @@
import pink.zak.minestom.towerdefence.utils.DirectionUtil;
import pink.zak.minestom.towerdefence.utils.TDEnvUtils;
+import java.time.temporal.ChronoUnit;
+import java.util.Collections;
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArraySet;
+import java.util.concurrent.ThreadLocalRandom;
+
public class SingleEnemyTDMob extends SingleTDMob implements LivingTDEnemyMob {
protected final MobHandler mobHandler;
protected final EnemyMob enemyMob;
@@ -108,7 +109,7 @@ public SingleEnemyTDMob(@NotNull GameHandler gameHandler, @NotNull EnemyMob enem
this.currentCornerLengthModifier = this.getRandomLengthModifier();
- this.getAttribute(Attribute.MAX_HEALTH).setBaseValue(this.level.getHealth());
+ this.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(this.level.getHealth());
this.health = this.level.getHealth();
this.setCustomNameVisible(true);
@@ -251,7 +252,7 @@ public float damage(@NotNull DamageSource source, float value) {
if (sound != null) {
Sound.Source soundSource = Sound.Source.PLAYER;
- SoundEffectPacket damageSoundPacket = new SoundEffectPacket(sound, null, soundSource, this.getPosition(), 1.0f, 1.0f, 0);
+ SoundEffectPacket damageSoundPacket = new SoundEffectPacket(sound, soundSource, this.getPosition(), 1.0f, 1.0f, 0);
this.sendPacketToViewersAndSelf(damageSoundPacket);
}
@@ -268,7 +269,7 @@ public void updateCustomName() {
}
@Override
- public boolean damage(@NotNull DamageType type, float value) {
+ public boolean damage(@NotNull Damage damage) {
throw new UnsupportedOperationException("Use damage(DamageSource, float) instead");
}
diff --git a/src/main/java/pink/zak/minestom/towerdefence/model/mob/living/SingleTDMob.java b/src/main/java/pink/zak/minestom/towerdefence/model/mob/living/SingleTDMob.java
index df01d008..6c68adec 100644
--- a/src/main/java/pink/zak/minestom/towerdefence/model/mob/living/SingleTDMob.java
+++ b/src/main/java/pink/zak/minestom/towerdefence/model/mob/living/SingleTDMob.java
@@ -1,8 +1,5 @@
package pink.zak.minestom.towerdefence.model.mob.living;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
import net.kyori.adventure.text.Component;
import net.minestom.server.entity.Entity;
import net.minestom.server.entity.EntityCreature;
@@ -14,6 +11,10 @@
import net.minestom.server.network.packet.server.play.EntityMetaDataPacket;
import org.jetbrains.annotations.NotNull;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
public class SingleTDMob extends EntityCreature implements LivingTDMob {
private final int level;
@@ -27,6 +28,11 @@ public int getLevel() {
return this.level;
}
+ @Override
+ public float getMaxHealth() {
+ return 0; // todo idk what this is meant to be??
+ }
+
@Override
public void updateCustomName() {
for (Player player : this.getViewers()) {
diff --git a/src/main/java/pink/zak/minestom/towerdefence/model/tower/config/Tower.java b/src/main/java/pink/zak/minestom/towerdefence/model/tower/config/Tower.java
index 35c43d24..8b031849 100644
--- a/src/main/java/pink/zak/minestom/towerdefence/model/tower/config/Tower.java
+++ b/src/main/java/pink/zak/minestom/towerdefence/model/tower/config/Tower.java
@@ -2,10 +2,6 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
-import java.util.ArrayList;
-import java.util.Comparator;
-import java.util.List;
-import java.util.Map;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;
@@ -13,6 +9,7 @@
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.minestom.server.coordinate.Point;
import net.minestom.server.instance.block.Block;
+import net.minestom.server.item.ItemComponent;
import net.minestom.server.item.ItemStack;
import net.minestom.server.item.Material;
import org.jetbrains.annotations.NotNull;
@@ -23,6 +20,11 @@
import pink.zak.minestom.towerdefence.utils.StringUtils;
import pink.zak.minestom.towerdefence.world.TowerDefenceInstance;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+
public class Tower {
private static final MiniMessage MINI_MESSAGE = MiniMessage.miniMessage();
@@ -58,10 +60,10 @@ public Tower(@NotNull JsonObject jsonObject, @NotNull Map l
.toList();
this.baseItem = this.item.with(builder -> {
- builder.displayName(MINI_MESSAGE.deserialize(BASE_ITEM_DISPLAY_NAME,
+ builder.set(ItemComponent.CUSTOM_NAME, MINI_MESSAGE.deserialize(BASE_ITEM_DISPLAY_NAME,
Placeholder.unparsed("tower_name", this.name),
- Placeholder.unparsed("tower_cost", String.valueOf(this.levels.get(1).getCost())))
- );
+ Placeholder.unparsed("tower_cost", String.valueOf(this.levels.get(1).getCost()))
+ ));
List description = new ArrayList<>();
description.add(Component.empty());
@@ -71,7 +73,7 @@ public Tower(@NotNull JsonObject jsonObject, @NotNull Map l
.append(Component.text(this.type.getSize().getFormattedName(), NamedTextColor.YELLOW))
.decoration(TextDecoration.ITALIC, false));
- builder.lore(description);
+ builder.set(ItemComponent.LORE, description);
});
}
diff --git a/src/main/java/pink/zak/minestom/towerdefence/model/tower/config/TowerLevel.java b/src/main/java/pink/zak/minestom/towerdefence/model/tower/config/TowerLevel.java
index fda6a1fb..698389fc 100644
--- a/src/main/java/pink/zak/minestom/towerdefence/model/tower/config/TowerLevel.java
+++ b/src/main/java/pink/zak/minestom/towerdefence/model/tower/config/TowerLevel.java
@@ -1,15 +1,12 @@
package pink.zak.minestom.towerdefence.model.tower.config;
import com.google.gson.JsonObject;
-import java.nio.file.Path;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.function.BiFunction;
import net.hollowcube.schem.Schematic;
import net.hollowcube.schem.SchematicReader;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
+import net.minestom.server.item.ItemComponent;
import net.minestom.server.item.ItemStack;
import net.minestom.server.item.Material;
import org.jetbrains.annotations.NotNull;
@@ -18,6 +15,11 @@
import pink.zak.minestom.towerdefence.statdiff.types.IntStatDiff;
import pink.zak.minestom.towerdefence.utils.NumberUtils;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.function.BiFunction;
+
public class TowerLevel implements Diffable, Comparable {
private static final BiFunction SCHEMATIC_PATH_FUNCTION = (towerName, level) ->
Path.of("towers", towerName.toLowerCase(), "builds", level + ".schem");
@@ -40,16 +42,16 @@ public TowerLevel(@NotNull String towerName, @NotNull JsonObject jsonObject) {
this.range = jsonObject.get("range").getAsInt();
Path schematicPath = SCHEMATIC_PATH_FUNCTION.apply(towerName, String.valueOf(this.level));
- this.schematic = SchematicReader.read(schematicPath);
+ this.schematic = new SchematicReader().read(schematicPath);
}
private ItemStack createOwnedUpgradeItem() {
return ItemStack.builder(Material.GREEN_STAINED_GLASS_PANE)
- .displayName(MiniMessage.miniMessage().deserialize(UPGRADE_ITEM_NAME.formatted("green"),
+ .set(ItemComponent.CUSTOM_NAME, MiniMessage.miniMessage().deserialize(UPGRADE_ITEM_NAME.formatted("green"),
Placeholder.unparsed("tower_name", this.towerName),
Placeholder.unparsed("level_numeral", NumberUtils.toRomanNumerals(this.level)),
Placeholder.unparsed("cost", String.valueOf(this.cost))))
- .lore(this.createStatLore())
+ .set(ItemComponent.LORE, this.createStatLore())
.build();
}
@@ -73,7 +75,7 @@ public ItemStack getOwnedUpgradeItem() {
String itemName = UPGRADE_ITEM_NAME.formatted(canAfford ? "gold" : "red");
return ItemStack.builder(canAfford ? Material.ORANGE_STAINED_GLASS_PANE : Material.RED_STAINED_GLASS_PANE)
- .displayName(MiniMessage.miniMessage().deserialize(itemName,
+ .set(ItemComponent.CUSTOM_NAME, MiniMessage.miniMessage().deserialize(itemName,
Placeholder.unparsed("tower_name", this.towerName),
Placeholder.unparsed("level_numeral", NumberUtils.toRomanNumerals(this.level)),
Placeholder.unparsed("cost", String.valueOf(cost))))
diff --git a/src/main/java/pink/zak/minestom/towerdefence/model/tower/placed/Projectile.java b/src/main/java/pink/zak/minestom/towerdefence/model/tower/placed/Projectile.java
index 92e9e990..dcc43d1d 100644
--- a/src/main/java/pink/zak/minestom/towerdefence/model/tower/placed/Projectile.java
+++ b/src/main/java/pink/zak/minestom/towerdefence/model/tower/placed/Projectile.java
@@ -4,7 +4,6 @@
import net.minestom.server.coordinate.Vec;
import net.minestom.server.entity.Entity;
import net.minestom.server.entity.EntityType;
-import net.minestom.server.timer.ExecutionType;
import net.minestom.server.timer.TaskSchedule;
import org.jetbrains.annotations.NotNull;
@@ -20,7 +19,7 @@ public Projectile(@NotNull EntityType entityType) {
// remove arrows after 15 seconds
MinecraftServer.getSchedulerManager().scheduleTask(() -> {
if (!this.isRemoved()) this.remove();
- }, TaskSchedule.seconds(15), TaskSchedule.stop(), ExecutionType.ASYNC);
+ }, TaskSchedule.seconds(15), TaskSchedule.stop());
}
@Override
diff --git a/src/main/java/pink/zak/minestom/towerdefence/model/tower/placed/types/BomberTower.java b/src/main/java/pink/zak/minestom/towerdefence/model/tower/placed/types/BomberTower.java
index 67161d45..aeecb754 100644
--- a/src/main/java/pink/zak/minestom/towerdefence/model/tower/placed/types/BomberTower.java
+++ b/src/main/java/pink/zak/minestom/towerdefence/model/tower/placed/types/BomberTower.java
@@ -2,6 +2,7 @@
import net.kyori.adventure.sound.Sound;
import net.minestom.server.ServerFlag;
+import net.minestom.server.collision.Aerodynamics;
import net.minestom.server.coordinate.Point;
import net.minestom.server.coordinate.Pos;
import net.minestom.server.coordinate.Vec;
@@ -29,8 +30,8 @@
import java.util.concurrent.ThreadLocalRandom;
public final class BomberTower extends PlacedAttackingTower {
- private static final double GRAVITY_PER_TICK = 0.04;
- private static final double DRAG_PER_TICK = 0;
+ private static final double GRAVITY = 0.04;
+ private static final double AIR_RESISTANCE = 1;
private static final int RAISE_TICKS = 6;
private static final double RAISE_BLOCKS = 1.5;
@@ -39,7 +40,7 @@ public final class BomberTower extends PlacedAttackingTower {
private static final @NotNull Vec RAISE_VELOCITY;
static {
- RAISE_VELOCITY = new Vec(0, findVelocity(RAISE_BLOCKS, -GRAVITY_PER_TICK, RAISE_TICKS), 0);
+ RAISE_VELOCITY = new Vec(0, findVelocity(RAISE_BLOCKS, -GRAVITY, RAISE_TICKS), 0);
}
private Point spawnPoint;
@@ -95,11 +96,10 @@ private static class BombTnt extends Entity {
super(EntityType.TNT);
this.tower = tower;
- super.hasPhysics = false;
((PrimedTntMeta) this.getEntityMeta()).setFuseTime(RAISE_TICKS + FLYING_TICKS);
this.setInstance(tower.gameHandler.getInstance(), tower.spawnPoint);
- this.setGravity(DRAG_PER_TICK, GRAVITY_PER_TICK);
+ this.setAerodynamics(new Aerodynamics(GRAVITY, AIR_RESISTANCE, AIR_RESISTANCE));
this.setVelocity(RAISE_VELOCITY);
this.fallbackPos = fallbackTarget.getPosition();
@@ -118,7 +118,7 @@ public void tick(long time) {
} else if (aliveTicks == RAISE_TICKS + FLYING_TICKS) {
Pos pos = this.getPosition();
- ServerPacket soundPacket = new SoundEffectPacket(null, SoundEvent.ENTITY_GENERIC_EXPLODE.name(), 20f, Sound.Source.PLAYER,
+ ServerPacket soundPacket = new SoundEffectPacket(SoundEvent.ENTITY_GENERIC_EXPLODE, Sound.Source.PLAYER,
pos.blockX(), pos.blockY(), pos.blockZ(), 1f, 1f, ThreadLocalRandom.current().nextLong());
ParticlePacket particlePacket = new ParticlePacket(
@@ -135,13 +135,13 @@ public void tick(long time) {
}
public Vec calculateLaunchVec(@NotNull Point current, @NotNull Point target) {
- double x = target.x() - current.x();
- double z = target.z() - current.z();
- double y = target.y() - current.y();
+ double xd = target.x() - current.x();
+ double zd = target.z() - current.z();
+ double yd = target.y() - current.y();
- double xVel = findVelocity(x, -DRAG_PER_TICK, FLYING_TICKS);
- double zVel = findVelocity(z, -DRAG_PER_TICK, FLYING_TICKS);
- double yVel = findVelocity(y, -GRAVITY_PER_TICK, FLYING_TICKS);
+ double xVel = findVelocity(xd, AIR_RESISTANCE - 1, FLYING_TICKS);
+ double yVel = findVelocity(yd, -GRAVITY, FLYING_TICKS);
+ double zVel = findVelocity(zd, AIR_RESISTANCE - 1, FLYING_TICKS);
return new Vec(xVel, yVel, zVel);
}
diff --git a/src/main/java/pink/zak/minestom/towerdefence/model/tower/placed/types/EarthquakeTower.java b/src/main/java/pink/zak/minestom/towerdefence/model/tower/placed/types/EarthquakeTower.java
index c536d56b..a1f42dbc 100644
--- a/src/main/java/pink/zak/minestom/towerdefence/model/tower/placed/types/EarthquakeTower.java
+++ b/src/main/java/pink/zak/minestom/towerdefence/model/tower/placed/types/EarthquakeTower.java
@@ -1,6 +1,5 @@
package pink.zak.minestom.towerdefence.model.tower.placed.types;
-import java.util.List;
import net.minestom.server.MinecraftServer;
import net.minestom.server.coordinate.Point;
import net.minestom.server.coordinate.Vec;
@@ -23,6 +22,8 @@
import pink.zak.minestom.towerdefence.model.tower.placed.PlacedAttackingTower;
import pink.zak.minestom.towerdefence.model.user.GameUser;
+import java.util.List;
+
public final class EarthquakeTower extends PlacedAttackingTower {
private static final Tag ORIGINAL_GRAVITY_TAG = Tag.Double("originalGravity");
@@ -65,12 +66,12 @@ private void launchMob(@NotNull LivingTDEnemyMob target) {
return;
}
- singleMob.setTag(ORIGINAL_GRAVITY_TAG, singleMob.getGravityAcceleration());
- singleMob.setGravity(singleMob.getGravityDragPerTick(), 0.04);
+ singleMob.setTag(ORIGINAL_GRAVITY_TAG, singleMob.getAerodynamics().gravity());
+ singleMob.setAerodynamics(singleMob.getAerodynamics().withGravity(0.04));
singleMob.setVelocity(new Vec(0, 4.5, 0));
MinecraftServer.getSchedulerManager().buildTask(() -> {
- singleMob.setGravity(singleMob.getGravityDragPerTick(), singleMob.getTag(ORIGINAL_GRAVITY_TAG));
+ singleMob.setAerodynamics(singleMob.getAerodynamics().withGravity(singleMob.getTag(ORIGINAL_GRAVITY_TAG)));
singleMob.removeTag(ORIGINAL_GRAVITY_TAG);
}).delay(this.level.getStunTicks(), TimeUnit.SERVER_TICK).schedule();
}
diff --git a/src/main/java/pink/zak/minestom/towerdefence/model/tower/placed/types/NecromancerTower.java b/src/main/java/pink/zak/minestom/towerdefence/model/tower/placed/types/NecromancerTower.java
index d4e08d92..0921d4da 100644
--- a/src/main/java/pink/zak/minestom/towerdefence/model/tower/placed/types/NecromancerTower.java
+++ b/src/main/java/pink/zak/minestom/towerdefence/model/tower/placed/types/NecromancerTower.java
@@ -1,19 +1,14 @@
package pink.zak.minestom.towerdefence.model.tower.placed.types;
-import com.extollit.gaming.ai.path.HydrazinePathFinder;
-import com.extollit.gaming.ai.path.SchedulingPriority;
-import java.util.concurrent.atomic.AtomicInteger;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
-import net.minestom.server.attribute.Attribute;
import net.minestom.server.coordinate.Point;
import net.minestom.server.entity.Player;
import net.minestom.server.entity.ai.EntityAIGroupBuilder;
import net.minestom.server.entity.ai.goal.MeleeAttackGoal;
import net.minestom.server.entity.ai.target.ClosestEntityTarget;
-import net.minestom.server.entity.pathfinding.Navigator;
-import net.minestom.server.entity.pathfinding.PFPathingEntity;
+import net.minestom.server.entity.attribute.Attribute;
import net.minestom.server.utils.Direction;
import net.minestom.server.utils.time.TimeUnit;
import org.jetbrains.annotations.NotNull;
@@ -30,6 +25,8 @@
import pink.zak.minestom.towerdefence.model.user.TDPlayer;
import pink.zak.minestom.towerdefence.utils.StringUtils;
+import java.util.concurrent.atomic.AtomicInteger;
+
public final class NecromancerTower extends PlacedTower {
private final AtomicInteger necromancedMobCount = new AtomicInteger(0);
@@ -66,22 +63,12 @@ public NecromancedMob(@NotNull NecromancerTower originTower, @NotNull Necromance
this.enemyMobLevel = originalMob.getEnemyMobLevel();
this.owner = owner;
- this.getAttribute(Attribute.MOVEMENT_SPEED).setBaseValue((float) this.enemyMobLevel.getMovementSpeed() + 0.050f);
- this.getAttribute(Attribute.MAX_HEALTH).setBaseValue(towerLevel.getNecromancedHealth());
-
- Navigator navigator = this.getNavigator();
- PFPathingEntity pathingEntity = navigator.getPathingEntity();
-
- this.setNoGravity(originalMob.getEnemyMob().isFlying());
- pathingEntity.setAvian(this.hasNoGravity());
+ this.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).setBaseValue((float) this.enemyMobLevel.getMovementSpeed() + 0.050f);
+ this.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(towerLevel.getNecromancedHealth());
this.setHealth(towerLevel.getNecromancedHealth());
this.setCustomNameVisible(true);
- HydrazinePathFinder pathFinder = new HydrazinePathFinder(this.getNavigator().getPathingEntity(), originalMob.getInstance().getInstanceSpace());
- pathFinder.schedulingPriority(SchedulingPriority.high);
-
- navigator.setPathFinder(pathFinder);
this.addAIGroup(
new EntityAIGroupBuilder()
diff --git a/src/main/java/pink/zak/minestom/towerdefence/model/user/TDPlayer.java b/src/main/java/pink/zak/minestom/towerdefence/model/user/TDPlayer.java
index 03f41968..185c5b6a 100644
--- a/src/main/java/pink/zak/minestom/towerdefence/model/user/TDPlayer.java
+++ b/src/main/java/pink/zak/minestom/towerdefence/model/user/TDPlayer.java
@@ -27,7 +27,6 @@ public TDPlayer(@NotNull UUID uuid, @NotNull String username, @NotNull PlayerCon
public TDPlayer(@NotNull UUID uuid, @NotNull String username, @NotNull PlayerConnection connection) {
super(uuid, username, connection);
- this.uuid = uuid;
}
public @NotNull HealthDisplayMode getHealthMode() {
diff --git a/src/main/java/pink/zak/minestom/towerdefence/queue/MobQueue.java b/src/main/java/pink/zak/minestom/towerdefence/queue/MobQueue.java
index 4f92edb9..6f59cf5f 100644
--- a/src/main/java/pink/zak/minestom/towerdefence/queue/MobQueue.java
+++ b/src/main/java/pink/zak/minestom/towerdefence/queue/MobQueue.java
@@ -1,17 +1,12 @@
package pink.zak.minestom.towerdefence.queue;
-import java.util.List;
-import java.util.Map;
-import java.util.Queue;
-import java.util.concurrent.ConcurrentLinkedQueue;
-import java.util.stream.Collectors;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;
import net.minestom.server.MinecraftServer;
+import net.minestom.server.item.ItemComponent;
import net.minestom.server.item.ItemStack;
import net.minestom.server.item.Material;
-import net.minestom.server.item.metadata.BundleMeta;
import net.minestom.server.timer.Task;
import net.minestom.server.timer.TaskSchedule;
import org.jetbrains.annotations.NotNull;
@@ -22,11 +17,17 @@
import pink.zak.minestom.towerdefence.model.user.GameUser;
import pink.zak.minestom.towerdefence.utils.Result;
+import java.util.List;
+import java.util.Map;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.stream.Collectors;
+
public final class MobQueue {
private static final int MAX_QUEUE_TIME = 45_000; // 45 seconds
private static final @NotNull ItemStack BASE_QUEUE_ITEM = ItemStack.builder(Material.BUNDLE)
- .displayName(Component.text("Current Queue", NamedTextColor.YELLOW).decoration(TextDecoration.ITALIC, false))
+ .set(ItemComponent.CUSTOM_NAME, Component.text("Current Queue", NamedTextColor.YELLOW).decoration(TextDecoration.ITALIC, false))
.build();
private final @NotNull Queue queue = new ConcurrentLinkedQueue<>();
@@ -123,7 +124,7 @@ private void callUpdateEvent() {
long amount = entry.getValue();
return mob.getBaseItem().withAmount((int) amount);
}).toList();
- return BASE_QUEUE_ITEM.withMeta(BundleMeta.class, meta -> meta.items(items));
- }
+ return BASE_QUEUE_ITEM.with(ItemComponent.BUNDLE_CONTENTS, items);
+ }
}
diff --git a/src/main/java/pink/zak/minestom/towerdefence/ui/ConfirmationUI.java b/src/main/java/pink/zak/minestom/towerdefence/ui/ConfirmationUI.java
index 46c4c039..59f82113 100644
--- a/src/main/java/pink/zak/minestom/towerdefence/ui/ConfirmationUI.java
+++ b/src/main/java/pink/zak/minestom/towerdefence/ui/ConfirmationUI.java
@@ -1,7 +1,6 @@
package pink.zak.minestom.towerdefence.ui;
import it.unimi.dsi.fastutil.booleans.BooleanConsumer;
-import java.util.List;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;
@@ -9,19 +8,22 @@
import net.minestom.server.entity.Player;
import net.minestom.server.inventory.Inventory;
import net.minestom.server.inventory.InventoryType;
+import net.minestom.server.item.ItemComponent;
import net.minestom.server.item.ItemStack;
import net.minestom.server.item.Material;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
+import java.util.List;
+
public final class ConfirmationUI extends Inventory {
private static final @NotNull Component TITLE = Component.text("Are you sure?", NamedTextColor.DARK_GRAY);
private static final @NotNull ItemStack CONFIRM_ITEM = ItemStack.builder(Material.GREEN_STAINED_GLASS_PANE)
- .displayName(Component.text("Confirm", NamedTextColor.GREEN).decoration(TextDecoration.ITALIC, false))
+ .set(ItemComponent.CUSTOM_NAME, Component.text("Confirm", NamedTextColor.GREEN).decoration(TextDecoration.ITALIC, false))
.build();
private static final @NotNull ItemStack CANCEL_ITEM = ItemStack.builder(Material.RED_STAINED_GLASS_PANE)
- .displayName(Component.text("Cancel", NamedTextColor.RED).decoration(TextDecoration.ITALIC, false))
+ .set(ItemComponent.CUSTOM_NAME, Component.text("Cancel", NamedTextColor.RED).decoration(TextDecoration.ITALIC, false))
.build();
private final @NotNull Player player;
diff --git a/src/main/java/pink/zak/minestom/towerdefence/ui/UserSettingsUI.java b/src/main/java/pink/zak/minestom/towerdefence/ui/UserSettingsUI.java
index 2168e38f..a245e17d 100644
--- a/src/main/java/pink/zak/minestom/towerdefence/ui/UserSettingsUI.java
+++ b/src/main/java/pink/zak/minestom/towerdefence/ui/UserSettingsUI.java
@@ -1,42 +1,44 @@
package pink.zak.minestom.towerdefence.ui;
-import java.util.ArrayList;
-import java.util.List;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;
import net.minestom.server.color.Color;
import net.minestom.server.inventory.Inventory;
import net.minestom.server.inventory.InventoryType;
-import net.minestom.server.item.ItemHideFlag;
+import net.minestom.server.item.ItemComponent;
import net.minestom.server.item.ItemStack;
import net.minestom.server.item.Material;
-import net.minestom.server.item.metadata.PotionMeta;
+import net.minestom.server.item.component.PotionContents;
import org.jetbrains.annotations.NotNull;
import pink.zak.minestom.towerdefence.model.user.TDPlayer;
import pink.zak.minestom.towerdefence.model.user.settings.FlySpeed;
import pink.zak.minestom.towerdefence.model.user.settings.HealthDisplayMode;
import pink.zak.minestom.towerdefence.model.user.settings.ParticleThickness;
+import java.util.ArrayList;
+import java.util.List;
+
public final class UserSettingsUI extends Inventory {
public static final @NotNull ItemStack HOTBAR_ITEM = ItemStack.builder(Material.COMMAND_BLOCK_MINECART)
- .displayName(Component.text("User Settings", NamedTextColor.YELLOW).decoration(TextDecoration.ITALIC, false))
+ .set(ItemComponent.CUSTOM_NAME, Component.text("User Settings", NamedTextColor.YELLOW).decoration(TextDecoration.ITALIC, false))
.build();
private static final @NotNull Component MENU_TITLE = Component.text("User Settings", NamedTextColor.DARK_GRAY);
private static final @NotNull ItemStack BASE_DAMAGE_INDICATORS_ITEM = ItemStack.builder(Material.OAK_SIGN)
- .displayName(Component.text("Show Damage Indicators", NamedTextColor.AQUA).decoration(TextDecoration.ITALIC, false))
+ .set(ItemComponent.CUSTOM_NAME, Component.text("Show Damage Indicators", NamedTextColor.AQUA).decoration(TextDecoration.ITALIC, false))
.build();
private static final @NotNull ItemStack BASE_HEATH_DISPLAY_ITEM = ItemStack.builder(Material.POTION)
- .displayName(Component.text("Health Display Mode", NamedTextColor.AQUA).decoration(TextDecoration.ITALIC, false))
- .meta(PotionMeta.class, meta -> meta.color(new Color(NamedTextColor.RED)).hideFlag(ItemHideFlag.HIDE_POTION_EFFECTS))
+ .set(ItemComponent.CUSTOM_NAME, Component.text("Health Display Mode", NamedTextColor.AQUA).decoration(TextDecoration.ITALIC, false))
+ .set(ItemComponent.POTION_CONTENTS, new PotionContents(null, new Color(NamedTextColor.RED), List.of()))
+ .set(ItemComponent.HIDE_TOOLTIP)
.build();
private static final @NotNull ItemStack BASE_FLIGHT_SPEED_ITEM = ItemStack.builder(Material.FEATHER)
- .displayName(Component.text("Fly Speed", NamedTextColor.AQUA).decoration(TextDecoration.ITALIC, false))
+ .set(ItemComponent.CUSTOM_NAME, Component.text("Fly Speed", NamedTextColor.AQUA).decoration(TextDecoration.ITALIC, false))
.build();
private static final @NotNull ItemStack BASE_PARTICLE_THICKNESS_ITEM = ItemStack.builder(Material.REDSTONE)
- .displayName(Component.text("Particle Thickness", NamedTextColor.AQUA).decoration(TextDecoration.ITALIC, false))
+ .set(ItemComponent.CUSTOM_NAME, Component.text("Particle Thickness", NamedTextColor.AQUA).decoration(TextDecoration.ITALIC, false))
.build();
private final @NotNull TDPlayer player;
diff --git a/src/main/java/pink/zak/minestom/towerdefence/ui/spawner/TroopSpawnerUI.java b/src/main/java/pink/zak/minestom/towerdefence/ui/spawner/TroopSpawnerUI.java
index ebee31c6..393d427d 100644
--- a/src/main/java/pink/zak/minestom/towerdefence/ui/spawner/TroopSpawnerUI.java
+++ b/src/main/java/pink/zak/minestom/towerdefence/ui/spawner/TroopSpawnerUI.java
@@ -1,10 +1,5 @@
package pink.zak.minestom.towerdefence.ui.spawner;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Optional;
-import java.util.stream.Stream;
-
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.JoinConfiguration;
import net.kyori.adventure.text.format.NamedTextColor;
@@ -19,6 +14,7 @@
import net.minestom.server.inventory.Inventory;
import net.minestom.server.inventory.InventoryType;
import net.minestom.server.inventory.click.ClickType;
+import net.minestom.server.item.ItemComponent;
import net.minestom.server.item.ItemStack;
import net.minestom.server.item.Material;
import org.jetbrains.annotations.NotNull;
@@ -35,15 +31,20 @@
import pink.zak.minestom.towerdefence.upgrade.UpgradeHandler;
import pink.zak.minestom.towerdefence.utils.Result;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Stream;
+
public final class TroopSpawnerUI extends Inventory {
public static final @NotNull ItemStack HOTBAR_ITEM = ItemStack.builder(Material.CHEST)
- .displayName(Component.text("Send Troops", NamedTextColor.YELLOW).decoration(TextDecoration.ITALIC, false))
+ .set(ItemComponent.CUSTOM_NAME, Component.text("Send Troops", NamedTextColor.YELLOW).decoration(TextDecoration.ITALIC, false))
.build();
private static final @NotNull Component SEND_TITLE = Component.text("Send Troops", NamedTextColor.DARK_GRAY);
private static final @NotNull ItemStack SHORTCUTS_ITEM = ItemStack.builder(Material.PAPER)
- .displayName(Component.text("Shortcuts", NamedTextColor.YELLOW).decoration(TextDecoration.ITALIC, false))
+ .set(ItemComponent.CUSTOM_NAME, Component.text("Shortcuts", NamedTextColor.YELLOW).decoration(TextDecoration.ITALIC, false))
.lore(Stream.of(
"",
"Quick Send Mobs ( HOLD 1 )",
@@ -97,7 +98,7 @@ private void refresh() {
.map(level -> level.createSendItem().withAmount(level.asInteger()))
.orElse(enemyMob.getBaseItem());
- List<@NotNull Component> lore = new ArrayList<>(item.getLore());
+ List<@NotNull Component> lore = new ArrayList<>(item.get(ItemComponent.LORE, List.of()));
JoinConfiguration separator = JoinConfiguration.separator(Component.space());
lore.add(Component.empty());
diff --git a/src/main/java/pink/zak/minestom/towerdefence/ui/spawner/TroopUpgradeUI.java b/src/main/java/pink/zak/minestom/towerdefence/ui/spawner/TroopUpgradeUI.java
index c4bb3538..9aceafa4 100644
--- a/src/main/java/pink/zak/minestom/towerdefence/ui/spawner/TroopUpgradeUI.java
+++ b/src/main/java/pink/zak/minestom/towerdefence/ui/spawner/TroopUpgradeUI.java
@@ -1,11 +1,11 @@
package pink.zak.minestom.towerdefence.ui.spawner;
-import java.util.Optional;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;
import net.minestom.server.inventory.Inventory;
import net.minestom.server.inventory.InventoryType;
+import net.minestom.server.item.ItemComponent;
import net.minestom.server.item.ItemStack;
import net.minestom.server.item.Material;
import org.jetbrains.annotations.NotNull;
@@ -16,10 +16,12 @@
import pink.zak.minestom.towerdefence.upgrade.UpgradeHandler;
import pink.zak.minestom.towerdefence.utils.Result;
+import java.util.Optional;
+
public final class TroopUpgradeUI extends Inventory {
private static final @NotNull ItemStack BACK_ITEM = ItemStack.builder(Material.BARRIER)
- .displayName(Component.text("Back", NamedTextColor.YELLOW).decoration(TextDecoration.ITALIC, false))
+ .set(ItemComponent.CUSTOM_NAME, Component.text("Back", NamedTextColor.YELLOW).decoration(TextDecoration.ITALIC, false))
.build();
private final @NotNull Inventory parent;
diff --git a/src/main/java/pink/zak/minestom/towerdefence/ui/tower/TowerManagementUI.java b/src/main/java/pink/zak/minestom/towerdefence/ui/tower/TowerManagementUI.java
index d0dc0eae..584e7a9c 100644
--- a/src/main/java/pink/zak/minestom/towerdefence/ui/tower/TowerManagementUI.java
+++ b/src/main/java/pink/zak/minestom/towerdefence/ui/tower/TowerManagementUI.java
@@ -1,12 +1,5 @@
package pink.zak.minestom.towerdefence.ui.tower;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;
@@ -16,12 +9,12 @@
import net.minestom.server.inventory.Inventory;
import net.minestom.server.inventory.InventoryType;
import net.minestom.server.inventory.click.ClickType;
+import net.minestom.server.item.ItemComponent;
import net.minestom.server.item.ItemStack;
import net.minestom.server.item.Material;
import net.minestom.server.network.packet.server.SendablePacket;
import net.minestom.server.network.packet.server.play.ParticlePacket;
import net.minestom.server.particle.Particle;
-import net.minestom.server.particle.data.DustParticleData;
import net.minestom.server.timer.Task;
import net.minestom.server.utils.time.TimeUnit;
import org.jetbrains.annotations.NotNull;
@@ -32,18 +25,26 @@
import pink.zak.minestom.towerdefence.model.user.GameUser;
import pink.zak.minestom.towerdefence.model.user.TDPlayer;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
public final class TowerManagementUI extends Inventory {
private static final @NotNull MiniMessage MINI_MESSAGE = MiniMessage.miniMessage();
private static final @NotNull ItemStack BASE_PREVIEW_TOWER_RADIUS_ITEM = ItemStack.builder(Material.REDSTONE)
- .displayName(Component.text("Preview Tower Radius", NamedTextColor.RED).decoration(TextDecoration.ITALIC, false))
+ .set(ItemComponent.CUSTOM_NAME, Component.text("Preview Tower Radius", NamedTextColor.RED).decoration(TextDecoration.ITALIC, false))
.build();
private static final @NotNull ItemStack REMOVE_TOWER_ITEM = ItemStack.builder(Material.BARRIER)
- .displayName(Component.text("Remove Tower", NamedTextColor.RED).decoration(TextDecoration.ITALIC, false))
- .lore(List.of(
+ .set(ItemComponent.CUSTOM_NAME, Component.text("Remove Tower", NamedTextColor.RED).decoration(TextDecoration.ITALIC, false))
+ .set(ItemComponent.LORE, List.of(
Component.empty(),
Component.text("Removes the tower", NamedTextColor.RED).decoration(TextDecoration.ITALIC, false)
- )).build();
+ ))
+ .build();
private final @NotNull PlacedTower> tower;
private final @NotNull GameUser user;
@@ -176,7 +177,7 @@ private void showTowerRadius(@NotNull ClickType clickType) {
packets.add(
new ParticlePacket(
- Particle.DUST.withData(new DustParticleData(NamedTextColor.RED, 1)),
+ Particle.DUST.withColor(NamedTextColor.RED).withScale(1),
circumference.x(), circumference.y(), circumference.z(),
0, 0, 0, 0.1f, 1
)
diff --git a/src/main/java/pink/zak/minestom/towerdefence/ui/tower/TowerOutliner.java b/src/main/java/pink/zak/minestom/towerdefence/ui/tower/TowerOutliner.java
index 59299149..25cf9b65 100644
--- a/src/main/java/pink/zak/minestom/towerdefence/ui/tower/TowerOutliner.java
+++ b/src/main/java/pink/zak/minestom/towerdefence/ui/tower/TowerOutliner.java
@@ -8,7 +8,6 @@
import net.minestom.server.network.packet.server.SendablePacket;
import net.minestom.server.network.packet.server.play.ParticlePacket;
import net.minestom.server.particle.Particle;
-import net.minestom.server.particle.data.DustParticleData;
import org.jetbrains.annotations.NotNull;
import pink.zak.minestom.towerdefence.enums.TowerSize;
import pink.zak.minestom.towerdefence.enums.TowerType;
@@ -91,7 +90,7 @@ public TowerOutliner(@NotNull TowerDefenceInstance instance) {
if (material != null && material.name().contains("slab")) offset += 0.5;
return new ParticlePacket(
- Particle.DUST.withData(new DustParticleData(color, 1)),
+ Particle.DUST.withColor(color).withScale(1),
point.x(), point.y() + offset, point.z(),
0, 0, 0,
1f, 1
diff --git a/src/main/java/pink/zak/minestom/towerdefence/ui/tower/TowerPlaceUI.java b/src/main/java/pink/zak/minestom/towerdefence/ui/tower/TowerPlaceUI.java
index 484a7f17..1b92a3f7 100644
--- a/src/main/java/pink/zak/minestom/towerdefence/ui/tower/TowerPlaceUI.java
+++ b/src/main/java/pink/zak/minestom/towerdefence/ui/tower/TowerPlaceUI.java
@@ -5,6 +5,7 @@
import net.kyori.adventure.text.format.TextDecoration;
import net.minestom.server.inventory.Inventory;
import net.minestom.server.inventory.InventoryType;
+import net.minestom.server.item.ItemComponent;
import net.minestom.server.item.ItemStack;
import net.minestom.server.item.Material;
import net.minestom.server.tag.Tag;
@@ -26,8 +27,8 @@ public final class TowerPlaceUI extends Inventory {
public static final @NotNull Tag TOWER_TYPE = Tag.Byte("tower_type").map(b -> TowerType.values()[b], t -> (byte) t.ordinal());
public static final @NotNull ItemStack HOTBAR_ITEM = ItemStack.builder(Material.ENDER_CHEST)
- .displayName(Component.text("Place Tower", NamedTextColor.YELLOW).decoration(TextDecoration.ITALIC, false))
- .lore(createItemLore(null))
+ .set(ItemComponent.CUSTOM_NAME, Component.text("Place Tower", NamedTextColor.YELLOW).decoration(TextDecoration.ITALIC, false))
+ .set(ItemComponent.LORE, createItemLore(null))
.set(UI_TAG, true)
.build();
@@ -67,8 +68,8 @@ private void onClick(int slot) {
private static ItemStack createItemStack(@NotNull Tower tower) {
return ItemStack.builder(tower.getBaseItem().material())
- .displayName(Component.text("Place Tower: " + tower.getName(), NamedTextColor.YELLOW).decoration(TextDecoration.ITALIC, false))
- .lore(createItemLore(tower))
+ .set(ItemComponent.CUSTOM_NAME, Component.text("Place Tower: " + tower.getName(), NamedTextColor.YELLOW).decoration(TextDecoration.ITALIC, false))
+ .set(ItemComponent.LORE, createItemLore(tower))
.set(UI_TAG, true)
.set(TOWER_TYPE, tower.getType())
.build();
diff --git a/src/main/java/pink/zak/minestom/towerdefence/utils/ItemUtils.java b/src/main/java/pink/zak/minestom/towerdefence/utils/ItemUtils.java
index 30370314..7139f9fe 100644
--- a/src/main/java/pink/zak/minestom/towerdefence/utils/ItemUtils.java
+++ b/src/main/java/pink/zak/minestom/towerdefence/utils/ItemUtils.java
@@ -4,12 +4,14 @@
import com.google.gson.JsonObject;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import net.minestom.server.entity.PlayerSkin;
+import net.minestom.server.item.ItemComponent;
import net.minestom.server.item.ItemStack;
import net.minestom.server.item.Material;
-import net.minestom.server.item.metadata.PlayerHeadMeta;
+import net.minestom.server.item.component.HeadProfile;
import net.minestom.server.utils.mojang.MojangUtils;
import org.jetbrains.annotations.Nullable;
+import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
@@ -21,25 +23,23 @@ public static ItemStack fromJsonObject(JsonObject jsonObject, @Nullable TagResol
ItemStack.Builder builder = ItemStack.builder(material);
if (material == Material.PLAYER_HEAD) {
- PlayerHeadMeta.Builder metaBuilder = new PlayerHeadMeta.Builder();
+ HeadProfile profile = null;
if (jsonObject.has("owner-uuid")) {
String uuid = jsonObject.get("owner-uuid").getAsString();
- metaBuilder.skullOwner(UUID.fromString(uuid));
- metaBuilder.playerSkin(PlayerSkin.fromUuid(uuid)); // is this necessary?
+ profile = new HeadProfile(null, UUID.fromString(uuid), List.of());
} else if (jsonObject.has("owner-username")) {
- String uuid = MojangUtils.fromUsername(jsonObject.get("owner-username").getAsString()).get("id").getAsString();
- metaBuilder.skullOwner(UUID.fromString(uuid));
- metaBuilder.playerSkin(PlayerSkin.fromUuid(uuid)); // is this necessary?
+ String username = MojangUtils.fromUsername(jsonObject.get("owner-username").getAsString()).get("id").getAsString();
+ profile = new HeadProfile(username, null, List.of());
} else if (jsonObject.has("texture")) {
- metaBuilder.skullOwner(UUID.randomUUID());
- metaBuilder.playerSkin(new PlayerSkin(jsonObject.get("texture").getAsString(), null));
- builder.meta(metaBuilder.build());
+ profile = new HeadProfile(new PlayerSkin(jsonObject.get("texture").getAsString(), null));
}
+
+ if (profile != null) builder.set(ItemComponent.PROFILE, profile);
}
if (jsonObject.has("displayName"))
- builder.displayName(StringUtils.parseMessage(jsonObject.get("displayName").getAsString(), tagResolver));
+ builder.set(ItemComponent.CUSTOM_NAME, StringUtils.parseMessage(jsonObject.get("displayName").getAsString(), tagResolver));
if (jsonObject.has("lore"))
builder.lore(StringUtils.parseMessages(
@@ -54,16 +54,4 @@ public static ItemStack fromJsonObject(JsonObject jsonObject, @Nullable TagResol
return builder.build();
}
-
- public static ItemStack withMaterial(ItemStack itemStack, Material material) {
- return withMaterialBuilder(itemStack, material).build();
- }
-
- public static ItemStack.Builder withMaterialBuilder(ItemStack itemStack, Material material) {
- return ItemStack.builder(material)
- .displayName(itemStack.getDisplayName())
- .lore(itemStack.getLore())
- .amount(itemStack.amount())
- .meta(itemStack.meta());
- }
}
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 bd6cf591..7db1869d 100644
--- a/src/main/java/pink/zak/minestom/towerdefence/world/TowerDefenceInstance.java
+++ b/src/main/java/pink/zak/minestom/towerdefence/world/TowerDefenceInstance.java
@@ -49,7 +49,7 @@ public class TowerDefenceInstance extends InstanceContainer {
private final TowerMap towerMap;
public TowerDefenceInstance(DimensionType dimensionType, String worldName) {
- super(UUID.randomUUID(), dimensionType, (IChunkLoader) null);
+ super(UUID.randomUUID(), WorldLoader.DIMENSION_TYPE_KEY, (IChunkLoader) null);
Path mapPath = MAP_PATH.resolve(worldName);
PolarLoader loader;
diff --git a/src/main/java/pink/zak/minestom/towerdefence/world/WorldLoader.java b/src/main/java/pink/zak/minestom/towerdefence/world/WorldLoader.java
index ff61d545..8729651b 100644
--- a/src/main/java/pink/zak/minestom/towerdefence/world/WorldLoader.java
+++ b/src/main/java/pink/zak/minestom/towerdefence/world/WorldLoader.java
@@ -1,27 +1,30 @@
package pink.zak.minestom.towerdefence.world;
import net.minestom.server.MinecraftServer;
+import net.minestom.server.instance.IChunkLoader;
import net.minestom.server.instance.InstanceManager;
+import net.minestom.server.registry.DynamicRegistry;
import net.minestom.server.utils.NamespaceID;
import net.minestom.server.world.DimensionType;
-import net.minestom.server.world.DimensionTypeManager;
public class WorldLoader {
- private static final DimensionType DIMENSION_TYPE = DimensionType.builder(NamespaceID.from("towerdefence:main"))
+ public static final NamespaceID DIMENSION_TYPE_ID = NamespaceID.from("towerdefence", "dimension_type");
+ public static final DynamicRegistry.Key DIMENSION_TYPE_KEY = DynamicRegistry.Key.of(DIMENSION_TYPE_ID);
+
+ private static final DimensionType DIMENSION_TYPE = DimensionType.builder()
.fixedTime(1000L)
- .skylightEnabled(true)
+ .hasSkylight(true)
.build();
public TowerDefenceInstance load() {
- DimensionTypeManager dimensionTypeManager = MinecraftServer.getDimensionTypeManager();
- dimensionTypeManager.addDimension(DIMENSION_TYPE);
+ DynamicRegistry dimensionRegistry = MinecraftServer.getDimensionTypeRegistry();
+ dimensionRegistry.register(DIMENSION_TYPE_ID, DIMENSION_TYPE);
InstanceManager instanceManager = MinecraftServer.getInstanceManager();
TowerDefenceInstance instance = new TowerDefenceInstance(DIMENSION_TYPE, "world");
instanceManager.registerInstance(instance);
- // Remove the chunk loader to save memory (like 50MB, 7MB per most chunks!)
- instance.setChunkLoader(null);
+ instance.setChunkLoader(IChunkLoader.noop());
return instance;
}