Skip to content

Commit

Permalink
Move ExternalTags to VanillaInterface and rename methods
Browse files Browse the repository at this point in the history
  • Loading branch information
GoldenStack committed Aug 30, 2024
1 parent eddf073 commit 44acdba
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 47 deletions.
8 changes: 4 additions & 4 deletions src/main/java/net/goldenstack/loot/LootEntry.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -207,12 +207,12 @@ record Dynamic(@NotNull List<LootPredicate> predicates, @NotNull List<LootFuncti
return switch (name.asString()) {
case "minecraft:sherds" -> {
List<ItemStack> 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();
};
}
Expand Down Expand Up @@ -249,7 +249,7 @@ record LootTable(@NotNull List<LootPredicate> predicates, @NotNull List<LootFunc

@Override
public @NotNull List<ItemStack> 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);
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/net/goldenstack/loot/LootFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ record Reference(@NotNull List<LootPredicate> 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;
}
Expand Down Expand Up @@ -346,8 +346,8 @@ record CopyName(@NotNull List<LootPredicate> 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;
}
Expand Down Expand Up @@ -624,7 +624,7 @@ record CopyComponents(@NotNull List<LootPredicate> 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<DataComponentMap> for blocks.");
}
}
Expand Down Expand Up @@ -795,7 +795,7 @@ record EnchantWithLevels(@NotNull List<LootPredicate> 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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/goldenstack/loot/LootNBT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/goldenstack/loot/LootNumber.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<NBTReference> refs = path.get(compound != null ? compound : CompoundBinaryTag.empty());
if (refs.size() != 1) return IntBinaryTag.intBinaryTag(0);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/goldenstack/loot/LootPredicate.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/goldenstack/loot/LootScore.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}

Expand Down
25 changes: 0 additions & 25 deletions src/main/java/net/goldenstack/loot/util/ExternalTags.java

This file was deleted.

26 changes: 19 additions & 7 deletions src/main/java/net/goldenstack/loot/util/VanillaInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -18,22 +21,31 @@

public interface VanillaInterface {

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

@Nullable Integer getScore(@NotNull String name, @NotNull String objective);
@NotNull Tag<List<Material>> DECORATED_POT_SHERDS = Tag.String("sherds")
.map(NamespaceID::from, NamespaceID::asString)
.map(Material::fromNamespaceId, Material::namespace)
.list().defaultValue(List::of);

@NotNull Tag<List<ItemStack>> 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<DynamicRegistry.Key<Enchantment>> enchantments);
@NotNull ItemStack enchant(@NotNull Random random, @NotNull ItemStack item, int levels, @Nullable List<DynamicRegistry.Key<Enchantment>> 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);

}

0 comments on commit 44acdba

Please sign in to comment.