Skip to content

Commit a6f0039

Browse files
committed
Replace VanillaInterface#getDynamicDrops with actual behaviour
1 parent 5b31fa7 commit a6f0039

File tree

4 files changed

+39
-16
lines changed

4 files changed

+39
-16
lines changed

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

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

3+
import net.goldenstack.loot.util.ExternalTags;
34
import net.goldenstack.loot.util.Serial;
45
import net.goldenstack.loot.util.Template;
5-
import net.goldenstack.loot.util.VanillaInterface;
6-
import net.kyori.adventure.nbt.CompoundBinaryTag;
76
import net.minestom.server.instance.block.Block;
87
import net.minestom.server.item.ItemStack;
98
import net.minestom.server.item.Material;
@@ -200,16 +199,22 @@ record Dynamic(@NotNull List<LootPredicate> predicates, @NotNull List<LootFuncti
200199
Dynamic::new
201200
);
202201

203-
@SuppressWarnings("DataFlowIssue")
204202
@Override
205203
public @NotNull List<ItemStack> apply(@NotNull LootContext context) {
206204
Block block = context.get(LootContext.BLOCK_STATE);
207205
if (block == null) return List.of();
208206

209-
CompoundBinaryTag nbt = block.hasNbt() ? block.nbt() : CompoundBinaryTag.empty();
210-
211-
VanillaInterface vanilla = context.require(LootContext.VANILLA_INTERFACE);
212-
return vanilla.getDynamicDrops(name, nbt);
207+
return switch (name.asString()) {
208+
case "minecraft:sherds" -> {
209+
List<ItemStack> items = new ArrayList<>();
210+
for (Material material : block.getTag(ExternalTags.DECORATED_POT_SHERDS)) {
211+
items.add(ItemStack.of(material));
212+
}
213+
yield items;
214+
}
215+
case "minecraft:contents" -> block.getTag(ExternalTags.CONTAINER_ITEMS);
216+
default -> List.of();
217+
};
213218
}
214219
}
215220

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import net.minestom.server.potion.PotionType;
2525
import net.minestom.server.registry.DynamicRegistry;
2626
import net.minestom.server.registry.Registries;
27-
import net.minestom.server.tag.Tag;
2827
import net.minestom.server.utils.NamespaceID;
2928
import net.minestom.server.utils.nbt.BinaryTagSerializer;
3029
import org.jetbrains.annotations.NotNull;
@@ -277,8 +276,6 @@ record CopyName(@NotNull List<LootPredicate> predicates, @NotNull RelevantTarget
277276
CopyName::new
278277
);
279278

280-
private static final @NotNull Tag<Component> BLOCK_CUSTOM_NAME = Tag.Component("CustomName");
281-
282279
@Override
283280
public @NotNull ItemStack apply(@NotNull ItemStack input, @NotNull LootContext context) {
284281
if (!LootPredicate.all(predicates, context)) return input;
@@ -288,8 +285,8 @@ record CopyName(@NotNull List<LootPredicate> predicates, @NotNull RelevantTarget
288285
Component customName;
289286
if (key instanceof Entity entity && entity.getCustomName() != null) {
290287
customName = entity.getCustomName();
291-
} else if (key instanceof Block block && block.hasTag(BLOCK_CUSTOM_NAME)) {
292-
customName = block.getTag(BLOCK_CUSTOM_NAME);
288+
} else if (key instanceof Block block && block.hasTag(ExternalTags.CUSTOM_NAME)) {
289+
customName = block.getTag(ExternalTags.CUSTOM_NAME);
293290
} else {
294291
return input;
295292
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package net.goldenstack.loot.util;
2+
3+
import net.kyori.adventure.text.Component;
4+
import net.minestom.server.item.ItemStack;
5+
import net.minestom.server.item.Material;
6+
import net.minestom.server.tag.Tag;
7+
import net.minestom.server.utils.NamespaceID;
8+
import org.jetbrains.annotations.NotNull;
9+
10+
import java.util.List;
11+
12+
public class ExternalTags {
13+
14+
private ExternalTags() {}
15+
16+
public static final @NotNull Tag<Component> CUSTOM_NAME = Tag.Component("CustomName");
17+
18+
public static final @NotNull Tag<List<Material>> DECORATED_POT_SHERDS = Tag.String("sherds")
19+
.map(NamespaceID::from, NamespaceID::asString)
20+
.map(Material::fromNamespaceId, Material::namespace)
21+
.list().defaultValue(List::of);
22+
23+
public static final @NotNull Tag<List<ItemStack>> CONTAINER_ITEMS = Tag.ItemStack("Items").list().defaultValue(List::of);
24+
25+
}

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

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

33
import net.kyori.adventure.nbt.BinaryTag;
4-
import net.kyori.adventure.nbt.CompoundBinaryTag;
54
import net.minestom.server.entity.Entity;
65
import net.minestom.server.item.ItemStack;
76
import net.minestom.server.item.enchant.Enchantment;
87
import net.minestom.server.registry.DynamicRegistry;
9-
import net.minestom.server.utils.NamespaceID;
108
import org.jetbrains.annotations.NotNull;
119
import org.jetbrains.annotations.Nullable;
1210

@@ -23,8 +21,6 @@ public interface VanillaInterface {
2321

2422
@NotNull ItemStack enchantItem(@NotNull Random random, @NotNull ItemStack item, int levels, @Nullable List<DynamicRegistry.Key<Enchantment>> enchantments);
2523

26-
@NotNull List<ItemStack> getDynamicDrops(@NotNull NamespaceID choiceID, @NotNull CompoundBinaryTag blockNBT);
27-
2824
@Nullable ItemStack smelt(@NotNull ItemStack input);
2925

3026
}

0 commit comments

Comments
 (0)