diff --git a/src/main/java/net/goldenstack/loot/LootEntry.java b/src/main/java/net/goldenstack/loot/LootEntry.java index c395730..b1944e1 100644 --- a/src/main/java/net/goldenstack/loot/LootEntry.java +++ b/src/main/java/net/goldenstack/loot/LootEntry.java @@ -1,8 +1,8 @@ package net.goldenstack.loot; -import net.goldenstack.loot.util.ExternalTags; import net.goldenstack.loot.util.Serial; import net.goldenstack.loot.util.Template; +import net.goldenstack.loot.util.VanillaInterface; import net.minestom.server.instance.block.Block; import net.minestom.server.item.ItemStack; import net.minestom.server.item.Material; @@ -207,12 +207,12 @@ record Dynamic(@NotNull List predicates, @NotNull List { List items = new ArrayList<>(); - for (Material material : block.getTag(ExternalTags.DECORATED_POT_SHERDS)) { + for (Material material : block.getTag(VanillaInterface.DECORATED_POT_SHERDS)) { items.add(ItemStack.of(material)); } yield items; } - case "minecraft:contents" -> block.getTag(ExternalTags.CONTAINER_ITEMS); + case "minecraft:contents" -> block.getTag(VanillaInterface.CONTAINER_ITEMS); default -> List.of(); }; } @@ -249,7 +249,7 @@ record LootTable(@NotNull List predicates, @NotNull List apply(@NotNull LootContext context) { - var table = context.vanilla().getRegisteredTable(value); + var table = context.vanilla().tableRegistry(value); if (table == null) return List.of(); return LootFunction.apply(functions, table.apply(context), context); diff --git a/src/main/java/net/goldenstack/loot/LootFunction.java b/src/main/java/net/goldenstack/loot/LootFunction.java index 487c19c..e09ebe3 100644 --- a/src/main/java/net/goldenstack/loot/LootFunction.java +++ b/src/main/java/net/goldenstack/loot/LootFunction.java @@ -211,7 +211,7 @@ record Reference(@NotNull List predicates, @NotNull NamespaceID n public @NotNull ItemStack apply(@NotNull ItemStack input, @NotNull LootContext context) { if (!LootPredicate.all(predicates, context)) return input; - LootFunction function = context.vanilla().getRegisteredFunction(name); + LootFunction function = context.vanilla().functionRegistry(name); return function != null ? function.apply(input, context) : input; } @@ -346,8 +346,8 @@ record CopyName(@NotNull List predicates, @NotNull RelevantTarget Component customName; if (key instanceof Entity entity && entity.getCustomName() != null) { customName = entity.getCustomName(); - } else if (key instanceof Block block && block.hasTag(ExternalTags.CUSTOM_NAME)) { - customName = block.getTag(ExternalTags.CUSTOM_NAME); + } else if (key instanceof Block block && block.hasTag(VanillaInterface.CUSTOM_NAME)) { + customName = block.getTag(VanillaInterface.CUSTOM_NAME); } else { return input; } @@ -624,7 +624,7 @@ record CopyComponents(@NotNull List predicates, @NotNull Relevant @Override public @NotNull ItemStack apply(@NotNull ItemStack input, @NotNull LootContext context) { if (!LootPredicate.all(predicates, context)) return input; - + throw new UnsupportedOperationException("TODO: Implement Tag for blocks."); } } @@ -795,7 +795,7 @@ record EnchantWithLevels(@NotNull List predicates, @NotNull LootN public @NotNull ItemStack apply(@NotNull ItemStack input, @NotNull LootContext context) { if (!LootPredicate.all(predicates, context)) return input; - return context.vanilla().enchantItem(context.require(LootContext.RANDOM), input, levels.getInt(context), options); + return context.vanilla().enchant(context.require(LootContext.RANDOM), input, levels.getInt(context), options); } } diff --git a/src/main/java/net/goldenstack/loot/LootNBT.java b/src/main/java/net/goldenstack/loot/LootNBT.java index 28d2144..59eedc6 100644 --- a/src/main/java/net/goldenstack/loot/LootNBT.java +++ b/src/main/java/net/goldenstack/loot/LootNBT.java @@ -46,7 +46,7 @@ record Storage(@NotNull NamespaceID source) implements LootNBT { @Override public @Nullable BinaryTag getNBT(@NotNull LootContext context) { - return context.vanilla().getCommandStorage(source); + return context.vanilla().commandStorage(source); } } diff --git a/src/main/java/net/goldenstack/loot/LootNumber.java b/src/main/java/net/goldenstack/loot/LootNumber.java index e6c5316..063015a 100644 --- a/src/main/java/net/goldenstack/loot/LootNumber.java +++ b/src/main/java/net/goldenstack/loot/LootNumber.java @@ -174,7 +174,7 @@ public double getDouble(@NotNull LootContext context) { } private NumberBinaryTag get(@NotNull LootContext context) { - CompoundBinaryTag compound = context.vanilla().getCommandStorage(storage); + CompoundBinaryTag compound = context.vanilla().commandStorage(storage); List refs = path.get(compound != null ? compound : CompoundBinaryTag.empty()); if (refs.size() != 1) return IntBinaryTag.intBinaryTag(0); diff --git a/src/main/java/net/goldenstack/loot/LootPredicate.java b/src/main/java/net/goldenstack/loot/LootPredicate.java index 664cc97..4cb9552 100644 --- a/src/main/java/net/goldenstack/loot/LootPredicate.java +++ b/src/main/java/net/goldenstack/loot/LootPredicate.java @@ -233,7 +233,7 @@ record Reference(@NotNull NamespaceID name) implements LootPredicate { @Override public boolean test(@NotNull LootContext context) { - LootPredicate predicate = context.vanilla().getRegisteredPredicate(name); + LootPredicate predicate = context.vanilla().predicateRegistry(name); return predicate != null && predicate.test(context); } @@ -359,7 +359,7 @@ public boolean test(@NotNull LootContext context) { if (entity == null) return false; for (var entry : scores.entrySet()) { - Integer score = context.vanilla().getScore(entity, entry.getKey()); + Integer score = context.vanilla().score(entity, entry.getKey()); if (score == null || !entry.getValue().check(context, score)) { return false; } diff --git a/src/main/java/net/goldenstack/loot/LootScore.java b/src/main/java/net/goldenstack/loot/LootScore.java index fa9b30d..15d1b81 100644 --- a/src/main/java/net/goldenstack/loot/LootScore.java +++ b/src/main/java/net/goldenstack/loot/LootScore.java @@ -34,7 +34,7 @@ record Context(@NotNull RelevantEntity name) implements LootScore { @Override public @NotNull Function<@NotNull String, @Nullable Integer> apply(@NotNull LootContext context) { - return objective -> context.vanilla().getScore(context.require(name.key()), objective); + return objective -> context.vanilla().score(context.require(name.key()), objective); } } @@ -47,7 +47,7 @@ record Fixed(@NotNull String name) implements LootScore { @Override public @NotNull Function<@NotNull String, @Nullable Integer> apply(@NotNull LootContext context) { - return objective -> context.vanilla().getScore(name, objective); + return objective -> context.vanilla().score(name, objective); } } diff --git a/src/main/java/net/goldenstack/loot/util/ExternalTags.java b/src/main/java/net/goldenstack/loot/util/ExternalTags.java deleted file mode 100644 index 428743d..0000000 --- a/src/main/java/net/goldenstack/loot/util/ExternalTags.java +++ /dev/null @@ -1,25 +0,0 @@ -package net.goldenstack.loot.util; - -import net.kyori.adventure.text.Component; -import net.minestom.server.item.ItemStack; -import net.minestom.server.item.Material; -import net.minestom.server.tag.Tag; -import net.minestom.server.utils.NamespaceID; -import org.jetbrains.annotations.NotNull; - -import java.util.List; - -public class ExternalTags { - - private ExternalTags() {} - - public static final @NotNull Tag CUSTOM_NAME = Tag.Component("CustomName"); - - public static final @NotNull Tag> DECORATED_POT_SHERDS = Tag.String("sherds") - .map(NamespaceID::from, NamespaceID::asString) - .map(Material::fromNamespaceId, Material::namespace) - .list().defaultValue(List::of); - - public static final @NotNull Tag> CONTAINER_ITEMS = Tag.ItemStack("Items").list().defaultValue(List::of); - -} diff --git a/src/main/java/net/goldenstack/loot/util/VanillaInterface.java b/src/main/java/net/goldenstack/loot/util/VanillaInterface.java index 4d4df70..9e892f7 100644 --- a/src/main/java/net/goldenstack/loot/util/VanillaInterface.java +++ b/src/main/java/net/goldenstack/loot/util/VanillaInterface.java @@ -5,10 +5,13 @@ import net.goldenstack.loot.LootTable; import net.kyori.adventure.nbt.BinaryTag; import net.kyori.adventure.nbt.CompoundBinaryTag; +import net.kyori.adventure.text.Component; import net.minestom.server.entity.Entity; import net.minestom.server.item.ItemStack; +import net.minestom.server.item.Material; import net.minestom.server.item.enchant.Enchantment; import net.minestom.server.registry.DynamicRegistry; +import net.minestom.server.tag.Tag; import net.minestom.server.utils.NamespaceID; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -18,22 +21,31 @@ public interface VanillaInterface { - @Nullable Integer getScore(@NotNull Entity entity, @NotNull String objective); + @NotNull Tag CUSTOM_NAME = Tag.Component("CustomName"); - @Nullable Integer getScore(@NotNull String name, @NotNull String objective); + @NotNull Tag> DECORATED_POT_SHERDS = Tag.String("sherds") + .map(NamespaceID::from, NamespaceID::asString) + .map(Material::fromNamespaceId, Material::namespace) + .list().defaultValue(List::of); + + @NotNull Tag> CONTAINER_ITEMS = Tag.ItemStack("Items").list().defaultValue(List::of); + + @Nullable Integer score(@NotNull Entity entity, @NotNull String objective); + + @Nullable Integer score(@NotNull String name, @NotNull String objective); @NotNull BinaryTag serializeEntity(@NotNull Entity entity); - @NotNull ItemStack enchantItem(@NotNull Random random, @NotNull ItemStack item, int levels, @Nullable List> enchantments); + @NotNull ItemStack enchant(@NotNull Random random, @NotNull ItemStack item, int levels, @Nullable List> enchantments); @Nullable ItemStack smelt(@NotNull ItemStack input); - @Nullable LootTable getRegisteredTable(@NotNull NamespaceID key); + @Nullable LootTable tableRegistry(@NotNull NamespaceID key); - @Nullable LootPredicate getRegisteredPredicate(@NotNull NamespaceID key); + @Nullable LootPredicate predicateRegistry(@NotNull NamespaceID key); - @Nullable LootFunction getRegisteredFunction(@NotNull NamespaceID key); + @Nullable LootFunction functionRegistry(@NotNull NamespaceID key); - @Nullable CompoundBinaryTag getCommandStorage(@NotNull NamespaceID key); + @Nullable CompoundBinaryTag commandStorage(@NotNull NamespaceID key); }