Skip to content

Commit 44acdba

Browse files
committed
Move ExternalTags to VanillaInterface and rename methods
1 parent eddf073 commit 44acdba

File tree

8 files changed

+34
-47
lines changed

8 files changed

+34
-47
lines changed

src/main/java/net/goldenstack/loot/LootEntry.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package net.goldenstack.loot;
22

3-
import net.goldenstack.loot.util.ExternalTags;
43
import net.goldenstack.loot.util.Serial;
54
import net.goldenstack.loot.util.Template;
5+
import net.goldenstack.loot.util.VanillaInterface;
66
import net.minestom.server.instance.block.Block;
77
import net.minestom.server.item.ItemStack;
88
import net.minestom.server.item.Material;
@@ -207,12 +207,12 @@ record Dynamic(@NotNull List<LootPredicate> predicates, @NotNull List<LootFuncti
207207
return switch (name.asString()) {
208208
case "minecraft:sherds" -> {
209209
List<ItemStack> items = new ArrayList<>();
210-
for (Material material : block.getTag(ExternalTags.DECORATED_POT_SHERDS)) {
210+
for (Material material : block.getTag(VanillaInterface.DECORATED_POT_SHERDS)) {
211211
items.add(ItemStack.of(material));
212212
}
213213
yield items;
214214
}
215-
case "minecraft:contents" -> block.getTag(ExternalTags.CONTAINER_ITEMS);
215+
case "minecraft:contents" -> block.getTag(VanillaInterface.CONTAINER_ITEMS);
216216
default -> List.of();
217217
};
218218
}
@@ -249,7 +249,7 @@ record LootTable(@NotNull List<LootPredicate> predicates, @NotNull List<LootFunc
249249

250250
@Override
251251
public @NotNull List<ItemStack> apply(@NotNull LootContext context) {
252-
var table = context.vanilla().getRegisteredTable(value);
252+
var table = context.vanilla().tableRegistry(value);
253253
if (table == null) return List.of();
254254

255255
return LootFunction.apply(functions, table.apply(context), context);

src/main/java/net/goldenstack/loot/LootFunction.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ record Reference(@NotNull List<LootPredicate> predicates, @NotNull NamespaceID n
211211
public @NotNull ItemStack apply(@NotNull ItemStack input, @NotNull LootContext context) {
212212
if (!LootPredicate.all(predicates, context)) return input;
213213

214-
LootFunction function = context.vanilla().getRegisteredFunction(name);
214+
LootFunction function = context.vanilla().functionRegistry(name);
215215

216216
return function != null ? function.apply(input, context) : input;
217217
}
@@ -346,8 +346,8 @@ record CopyName(@NotNull List<LootPredicate> predicates, @NotNull RelevantTarget
346346
Component customName;
347347
if (key instanceof Entity entity && entity.getCustomName() != null) {
348348
customName = entity.getCustomName();
349-
} else if (key instanceof Block block && block.hasTag(ExternalTags.CUSTOM_NAME)) {
350-
customName = block.getTag(ExternalTags.CUSTOM_NAME);
349+
} else if (key instanceof Block block && block.hasTag(VanillaInterface.CUSTOM_NAME)) {
350+
customName = block.getTag(VanillaInterface.CUSTOM_NAME);
351351
} else {
352352
return input;
353353
}
@@ -624,7 +624,7 @@ record CopyComponents(@NotNull List<LootPredicate> predicates, @NotNull Relevant
624624
@Override
625625
public @NotNull ItemStack apply(@NotNull ItemStack input, @NotNull LootContext context) {
626626
if (!LootPredicate.all(predicates, context)) return input;
627-
627+
628628
throw new UnsupportedOperationException("TODO: Implement Tag<DataComponentMap> for blocks.");
629629
}
630630
}
@@ -795,7 +795,7 @@ record EnchantWithLevels(@NotNull List<LootPredicate> predicates, @NotNull LootN
795795
public @NotNull ItemStack apply(@NotNull ItemStack input, @NotNull LootContext context) {
796796
if (!LootPredicate.all(predicates, context)) return input;
797797

798-
return context.vanilla().enchantItem(context.require(LootContext.RANDOM), input, levels.getInt(context), options);
798+
return context.vanilla().enchant(context.require(LootContext.RANDOM), input, levels.getInt(context), options);
799799
}
800800
}
801801

src/main/java/net/goldenstack/loot/LootNBT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ record Storage(@NotNull NamespaceID source) implements LootNBT {
4646

4747
@Override
4848
public @Nullable BinaryTag getNBT(@NotNull LootContext context) {
49-
return context.vanilla().getCommandStorage(source);
49+
return context.vanilla().commandStorage(source);
5050
}
5151
}
5252

src/main/java/net/goldenstack/loot/LootNumber.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public double getDouble(@NotNull LootContext context) {
174174
}
175175

176176
private NumberBinaryTag get(@NotNull LootContext context) {
177-
CompoundBinaryTag compound = context.vanilla().getCommandStorage(storage);
177+
CompoundBinaryTag compound = context.vanilla().commandStorage(storage);
178178

179179
List<NBTReference> refs = path.get(compound != null ? compound : CompoundBinaryTag.empty());
180180
if (refs.size() != 1) return IntBinaryTag.intBinaryTag(0);

src/main/java/net/goldenstack/loot/LootPredicate.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ record Reference(@NotNull NamespaceID name) implements LootPredicate {
233233

234234
@Override
235235
public boolean test(@NotNull LootContext context) {
236-
LootPredicate predicate = context.vanilla().getRegisteredPredicate(name);
236+
LootPredicate predicate = context.vanilla().predicateRegistry(name);
237237

238238
return predicate != null && predicate.test(context);
239239
}
@@ -359,7 +359,7 @@ public boolean test(@NotNull LootContext context) {
359359
if (entity == null) return false;
360360

361361
for (var entry : scores.entrySet()) {
362-
Integer score = context.vanilla().getScore(entity, entry.getKey());
362+
Integer score = context.vanilla().score(entity, entry.getKey());
363363
if (score == null || !entry.getValue().check(context, score)) {
364364
return false;
365365
}

src/main/java/net/goldenstack/loot/LootScore.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ record Context(@NotNull RelevantEntity name) implements LootScore {
3434

3535
@Override
3636
public @NotNull Function<@NotNull String, @Nullable Integer> apply(@NotNull LootContext context) {
37-
return objective -> context.vanilla().getScore(context.require(name.key()), objective);
37+
return objective -> context.vanilla().score(context.require(name.key()), objective);
3838
}
3939
}
4040

@@ -47,7 +47,7 @@ record Fixed(@NotNull String name) implements LootScore {
4747

4848
@Override
4949
public @NotNull Function<@NotNull String, @Nullable Integer> apply(@NotNull LootContext context) {
50-
return objective -> context.vanilla().getScore(name, objective);
50+
return objective -> context.vanilla().score(name, objective);
5151
}
5252
}
5353

src/main/java/net/goldenstack/loot/util/ExternalTags.java

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/main/java/net/goldenstack/loot/util/VanillaInterface.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
import net.goldenstack.loot.LootTable;
66
import net.kyori.adventure.nbt.BinaryTag;
77
import net.kyori.adventure.nbt.CompoundBinaryTag;
8+
import net.kyori.adventure.text.Component;
89
import net.minestom.server.entity.Entity;
910
import net.minestom.server.item.ItemStack;
11+
import net.minestom.server.item.Material;
1012
import net.minestom.server.item.enchant.Enchantment;
1113
import net.minestom.server.registry.DynamicRegistry;
14+
import net.minestom.server.tag.Tag;
1215
import net.minestom.server.utils.NamespaceID;
1316
import org.jetbrains.annotations.NotNull;
1417
import org.jetbrains.annotations.Nullable;
@@ -18,22 +21,31 @@
1821

1922
public interface VanillaInterface {
2023

21-
@Nullable Integer getScore(@NotNull Entity entity, @NotNull String objective);
24+
@NotNull Tag<Component> CUSTOM_NAME = Tag.Component("CustomName");
2225

23-
@Nullable Integer getScore(@NotNull String name, @NotNull String objective);
26+
@NotNull Tag<List<Material>> DECORATED_POT_SHERDS = Tag.String("sherds")
27+
.map(NamespaceID::from, NamespaceID::asString)
28+
.map(Material::fromNamespaceId, Material::namespace)
29+
.list().defaultValue(List::of);
30+
31+
@NotNull Tag<List<ItemStack>> CONTAINER_ITEMS = Tag.ItemStack("Items").list().defaultValue(List::of);
32+
33+
@Nullable Integer score(@NotNull Entity entity, @NotNull String objective);
34+
35+
@Nullable Integer score(@NotNull String name, @NotNull String objective);
2436

2537
@NotNull BinaryTag serializeEntity(@NotNull Entity entity);
2638

27-
@NotNull ItemStack enchantItem(@NotNull Random random, @NotNull ItemStack item, int levels, @Nullable List<DynamicRegistry.Key<Enchantment>> enchantments);
39+
@NotNull ItemStack enchant(@NotNull Random random, @NotNull ItemStack item, int levels, @Nullable List<DynamicRegistry.Key<Enchantment>> enchantments);
2840

2941
@Nullable ItemStack smelt(@NotNull ItemStack input);
3042

31-
@Nullable LootTable getRegisteredTable(@NotNull NamespaceID key);
43+
@Nullable LootTable tableRegistry(@NotNull NamespaceID key);
3244

33-
@Nullable LootPredicate getRegisteredPredicate(@NotNull NamespaceID key);
45+
@Nullable LootPredicate predicateRegistry(@NotNull NamespaceID key);
3446

35-
@Nullable LootFunction getRegisteredFunction(@NotNull NamespaceID key);
47+
@Nullable LootFunction functionRegistry(@NotNull NamespaceID key);
3648

37-
@Nullable CompoundBinaryTag getCommandStorage(@NotNull NamespaceID key);
49+
@Nullable CompoundBinaryTag commandStorage(@NotNull NamespaceID key);
3850

3951
}

0 commit comments

Comments
 (0)