diff --git a/src/main/java/net/goldenstack/loot/LootEntry.java b/src/main/java/net/goldenstack/loot/LootEntry.java index 5fbe511..7c0a8b7 100644 --- a/src/main/java/net/goldenstack/loot/LootEntry.java +++ b/src/main/java/net/goldenstack/loot/LootEntry.java @@ -24,10 +24,10 @@ public interface LootEntry { @NotNull BinaryTagSerializer SERIALIZER = Template.registry("type", Template.entry("empty", Empty.class, Empty.SERIALIZER), Template.entry("item", Item.class, Item.SERIALIZER), - Template.entry("loot_table", Table.class, Table.SERIALIZER), + Template.entry("loot_table", LootTable.class, LootTable.SERIALIZER), Template.entry("dynamic", Dynamic.class, Dynamic.SERIALIZER), Template.entry("tag", Tag.class, Tag.SERIALIZER), - Template.entry("alternatives", Alternative.class, Alternative.SERIALIZER), + Template.entry("alternatives", Alternatives.class, Alternatives.SERIALIZER), Template.entry("sequence", Sequence.class, Sequence.SERIALIZER), Template.entry("group", Group.class, Group.SERIALIZER) ); @@ -104,12 +104,12 @@ interface Single extends LootEntry, LootEntry.Choice, Standard { } - record Alternative(@NotNull List predicates, @NotNull List children) implements LootEntry { + record Alternatives(@NotNull List predicates, @NotNull List children) implements LootEntry { - public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( - "conditions", LootPredicate.SERIALIZER.list().optional(List.of()), Alternative::predicates, - "children", Serial.lazy(() -> LootEntry.SERIALIZER).list().optional(List.of()), Alternative::children, - Alternative::new + public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( + "conditions", LootPredicate.SERIALIZER.list().optional(List.of()), Alternatives::predicates, + "children", Serial.lazy(() -> LootEntry.SERIALIZER).list().optional(List.of()), Alternatives::children, + Alternatives::new ); @Override @@ -171,32 +171,32 @@ record Group(@NotNull List predicates, @NotNull List c } record Item(@NotNull List predicates, @NotNull List functions, - long weight, long quality, @NotNull Material material) implements Choice.Single { + long weight, long quality, @NotNull Material name) implements Choice.Single { public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( "conditions", LootPredicate.SERIALIZER.list().optional(List.of()), Item::predicates, "functions", LootFunction.SERIALIZER.list().optional(List.of()), Item::functions, "weight", Serial.LONG.optional(1L), Item::weight, "quality", Serial.LONG.optional(0L), Item::quality, - "name", Material.NBT_TYPE, Item::material, + "name", Material.NBT_TYPE, Item::name, Item::new ); @Override public @NotNull List apply(@NotNull LootContext context) { - return List.of(LootFunction.apply(functions, ItemStack.of(material), context)); + return List.of(LootFunction.apply(functions, ItemStack.of(name), context)); } } record Dynamic(@NotNull List predicates, @NotNull List functions, - long weight, long quality, @NotNull NamespaceID choiceID) implements Choice.Single { + long weight, long quality, @NotNull NamespaceID name) implements Choice.Single { public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( "conditions", LootPredicate.SERIALIZER.list().optional(List.of()), Dynamic::predicates, "functions", LootFunction.SERIALIZER.list().optional(List.of()), Dynamic::functions, "weight", Serial.LONG.optional(1L), Dynamic::weight, "quality", Serial.LONG.optional(0L), Dynamic::quality, - "name", Serial.KEY, Dynamic::choiceID, + "name", Serial.KEY, Dynamic::name, Dynamic::new ); @@ -209,7 +209,7 @@ record Dynamic(@NotNull List predicates, @NotNull List predicates, @NotNull List predicates, @NotNull List functions, - long weight, long quality, @NotNull NamespaceID tableID) implements Choice.Single { + record LootTable(@NotNull List predicates, @NotNull List functions, + long weight, long quality, @NotNull NamespaceID value) implements Choice.Single { - public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( - "conditions", LootPredicate.SERIALIZER.list().optional(List.of()), Table::predicates, - "functions", LootFunction.SERIALIZER.list().optional(List.of()), Table::functions, - "weight", Serial.LONG.optional(1L), Table::weight, - "quality", Serial.LONG.optional(0L), Table::quality, - "value", Serial.KEY, Table::tableID, - Table::new + public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( + "conditions", LootPredicate.SERIALIZER.list().optional(List.of()), LootTable::predicates, + "functions", LootFunction.SERIALIZER.list().optional(List.of()), LootTable::functions, + "weight", Serial.LONG.optional(1L), LootTable::weight, + "quality", Serial.LONG.optional(0L), LootTable::quality, + "value", Serial.KEY, LootTable::value, + LootTable::new ); @Override @@ -247,7 +247,7 @@ record Table(@NotNull List predicates, @NotNull List predicates, @NotNull List predicates, @NotNull List functions, - long weight, long quality, @NotNull net.minestom.server.gamedata.tags.Tag tag, boolean expand) implements Choice.Single { + long weight, long quality, @NotNull net.minestom.server.gamedata.tags.Tag name, boolean expand) implements Choice.Single { public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( "conditions", LootPredicate.SERIALIZER.list().optional(List.of()), Tag::predicates, "functions", LootFunction.SERIALIZER.list().optional(List.of()), Tag::functions, "weight", Serial.LONG.optional(1L), Tag::weight, "quality", Serial.LONG.optional(0L), Tag::quality, - "name", Serial.tag(net.minestom.server.gamedata.tags.Tag.BasicType.ITEMS), Tag::tag, + "name", Serial.tag(net.minestom.server.gamedata.tags.Tag.BasicType.ITEMS), Tag::name, "expand", BinaryTagSerializer.BOOLEAN, Tag::expand, Tag::new ); @@ -276,7 +276,7 @@ record Tag(@NotNull List predicates, @NotNull List } List choices = new ArrayList<>(); - for (var key : tag.getValues()) { + for (var key : name.getValues()) { Material material = Material.fromNamespaceId(key); if (material == null) continue; choices.add(new Choice() { @@ -298,7 +298,7 @@ record Tag(@NotNull List predicates, @NotNull List @Override public @NotNull List apply(@NotNull LootContext context) { List items = new ArrayList<>(); - for (var key : tag.getValues()) { + for (var key : name.getValues()) { Material material = Material.fromNamespaceId(key); if (material == null) continue; diff --git a/src/main/java/net/goldenstack/loot/LootFunction.java b/src/main/java/net/goldenstack/loot/LootFunction.java index 01eb089..ca2f106 100644 --- a/src/main/java/net/goldenstack/loot/LootFunction.java +++ b/src/main/java/net/goldenstack/loot/LootFunction.java @@ -42,27 +42,27 @@ public interface LootFunction { @NotNull BinaryTagSerializer SERIALIZER = Template.compoundSplit( - Serial.lazy(() -> LootFunction.SERIALIZER).list().map(All::new, All::functions), + Serial.lazy(() -> LootFunction.SERIALIZER).list().map(Sequence::new, Sequence::functions), Template.registry("function", - Template.entry("sequence", All.class, All.SERIALIZER), + Template.entry("sequence", Sequence.class, Sequence.SERIALIZER), Template.entry("filtered", Filtered.class, Filtered.SERIALIZER), Template.entry("set_potion", SetPotion.class, SetPotion.SERIALIZER), Template.entry("explosion_decay", ExplosionDecay.class, ExplosionDecay.SERIALIZER), Template.entry("reference", Reference.class, Reference.SERIALIZER), - Template.entry("apply_bonus", Bonus.class, Bonus.SERIALIZER), + Template.entry("apply_bonus", ApplyBonus.class, ApplyBonus.SERIALIZER), Template.entry("copy_name", CopyName.class, CopyName.SERIALIZER), Template.entry("toggle_tooltips", ToggleTooltips.class, ToggleTooltips.SERIALIZER), - Template.entry("set_stew_effect", StewEffect.class, StewEffect.SERIALIZER), - Template.entry("set_ominous_bottle_amplifier", OminousBottleAmplifier.class, OminousBottleAmplifier.SERIALIZER), - Template.entry("copy_custom_data", CopyNBT.class, CopyNBT.SERIALIZER), + Template.entry("set_stew_effect", SetStewEffect.class, SetStewEffect.SERIALIZER), + Template.entry("set_ominous_bottle_amplifier", SetOminousBottleAmplifier.class, SetOminousBottleAmplifier.SERIALIZER), + Template.entry("copy_custom_data", CopyCustomData.class, CopyCustomData.SERIALIZER), Template.entry("limit_count", LimitCount.class, LimitCount.SERIALIZER), Template.entry("set_count", SetCount.class, SetCount.SERIALIZER), - Template.entry("set_item", SetMaterial.class, SetMaterial.SERIALIZER), + Template.entry("set_item", SetItem.class, SetItem.SERIALIZER), Template.entry("set_loot_table", SetLootTable.class, SetLootTable.SERIALIZER), Template.entry("copy_components", CopyComponents.class, CopyComponents.SERIALIZER), Template.entry("copy_state", CopyState.class, CopyState.SERIALIZER), - Template.entry("enchanted_count_increase", MoreByLevel.class, MoreByLevel.SERIALIZER), - Template.entry("set_custom_data", SetNBT.class, SetNBT.SERIALIZER), + Template.entry("enchanted_count_increase", EnchantedCountIncrease.class, EnchantedCountIncrease.SERIALIZER), + Template.entry("set_custom_data", SetCustomData.class, SetCustomData.SERIALIZER), Template.entry("set_custom_model_data", SetCustomModelData.class, SetCustomModelData.SERIALIZER), Template.entry("set_damage", SetDamage.class, SetDamage.SERIALIZER), Template.entry("set_enchantments", SetEnchantments.class, SetEnchantments.SERIALIZER), @@ -109,11 +109,11 @@ public interface LootFunction { return newItems; } - record All(@NotNull List functions) implements LootFunction { + record Sequence(@NotNull List functions) implements LootFunction { - public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( - "functions", Serial.lazy(() -> LootFunction.SERIALIZER).list(), All::functions, - All::new + public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( + "functions", Serial.lazy(() -> LootFunction.SERIALIZER).list(), Sequence::functions, + Sequence::new ); @Override @@ -122,27 +122,27 @@ record All(@NotNull List functions) implements LootFunction { } } - record Filtered(@NotNull List predicates, @NotNull ItemPredicate predicate, @NotNull LootFunction function) implements LootFunction { + record Filtered(@NotNull List predicates, @NotNull ItemPredicate predicate, @NotNull LootFunction modifier) implements LootFunction { public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( "conditions", Serial.lazy(() -> LootPredicate.SERIALIZER).list().optional(List.of()), Filtered::predicates, "item_filter", Serial.lazy(ItemPredicate.SERIALIZER::get), Filtered::predicate, - "modifier", Serial.lazy(() -> LootFunction.SERIALIZER), Filtered::function, + "modifier", Serial.lazy(() -> LootFunction.SERIALIZER), Filtered::modifier, Filtered::new ); @Override public @NotNull ItemStack apply(@NotNull ItemStack input, @NotNull LootContext context) { return LootPredicate.all(predicates, context) && predicate.test(input) ? - function.apply(input, context) : input; + modifier.apply(input, context) : input; } } - record SetPotion(@NotNull List predicates, @NotNull NamespaceID potion) implements LootFunction { + record SetPotion(@NotNull List predicates, @NotNull NamespaceID id) implements LootFunction { public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( "conditions", Serial.lazy(() -> LootPredicate.SERIALIZER).list().optional(List.of()), SetPotion::predicates, - "id", Serial.KEY, SetPotion::potion, + "id", Serial.KEY, SetPotion::id, SetPotion::new ); @@ -150,12 +150,12 @@ record SetPotion(@NotNull List predicates, @NotNull NamespaceID p public @NotNull ItemStack apply(@NotNull ItemStack input, @NotNull LootContext context) { if (!LootPredicate.all(predicates, context)) return input; - if (potion.asString().equals("minecraft:empty")) { + if (id.asString().equals("minecraft:empty")) { return input.without(ItemComponent.POTION_CONTENTS); } PotionContents existing = input.get(ItemComponent.POTION_CONTENTS, PotionContents.EMPTY); - PotionContents updated = new PotionContents(PotionType.fromNamespaceId(potion), existing.customColor(), existing.customEffects()); + PotionContents updated = new PotionContents(PotionType.fromNamespaceId(id), existing.customColor(), existing.customEffects()); return input.with(ItemComponent.POTION_CONTENTS, updated); } @@ -192,11 +192,11 @@ record ExplosionDecay(@NotNull List predicates) implements LootFu } } - record Reference(@NotNull List predicates, @NotNull NamespaceID key) implements LootFunction { + record Reference(@NotNull List predicates, @NotNull NamespaceID name) implements LootFunction { public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( "conditions", Serial.lazy(() -> LootPredicate.SERIALIZER).list().optional(List.of()), Reference::predicates, - "name", Serial.KEY, Reference::key, + "name", Serial.KEY, Reference::name, Reference::new ); @@ -204,19 +204,19 @@ record Reference(@NotNull List predicates, @NotNull NamespaceID k public @NotNull ItemStack apply(@NotNull ItemStack input, @NotNull LootContext context) { if (!LootPredicate.all(predicates, context)) return input; - LootFunction function = context.require(LootContext.REGISTERED_FUNCTIONS).apply(key); + LootFunction function = context.require(LootContext.REGISTERED_FUNCTIONS).apply(name); return function != null ? function.apply(input, context) : input; } } - record Bonus(@NotNull List predicates, @NotNull DynamicRegistry.Key enchantment, @NotNull Formula formula) implements LootFunction { + record ApplyBonus(@NotNull List predicates, @NotNull DynamicRegistry.Key enchantment, @NotNull Formula formula) implements LootFunction { - public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( - "conditions", Serial.lazy(() -> LootPredicate.SERIALIZER).list().optional(List.of()), Bonus::predicates, - "enchantment", Serial.key(), Bonus::enchantment, - "formula", Template.todo("formula"), Bonus::formula, - Bonus::new + public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( + "conditions", Serial.lazy(() -> LootPredicate.SERIALIZER).list().optional(List.of()), ApplyBonus::predicates, + "enchantment", Serial.key(), ApplyBonus::enchantment, + "formula", Template.todo("formula"), ApplyBonus::formula, + ApplyBonus::new ); public sealed interface Formula { @@ -266,11 +266,11 @@ public int calculate(@NotNull Random random, int count, int level) { } } - record CopyName(@NotNull List predicates, @NotNull RelevantTarget target) implements LootFunction { + record CopyName(@NotNull List predicates, @NotNull RelevantTarget source) implements LootFunction { public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( "conditions", Serial.lazy(() -> LootPredicate.SERIALIZER).list().optional(List.of()), CopyName::predicates, - "source", RelevantTarget.SERIALIZER, CopyName::target, + "source", RelevantTarget.SERIALIZER, CopyName::source, CopyName::new ); @@ -280,7 +280,7 @@ record CopyName(@NotNull List predicates, @NotNull RelevantTarget public @NotNull ItemStack apply(@NotNull ItemStack input, @NotNull LootContext context) { if (!LootPredicate.all(predicates, context)) return input; - Object key = context.get(target.key()); + Object key = context.get(source.key()); Component customName; if (key instanceof Entity entity && entity.getCustomName() != null) { @@ -295,7 +295,7 @@ record CopyName(@NotNull List predicates, @NotNull RelevantTarget } } - record ToggleTooltips(@NotNull List predicates, @NotNull Map, Boolean> toggles) implements LootFunction { + record ToggleTooltips(@NotNull List predicates, @NotNull Map, Boolean> source) implements LootFunction { public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( "conditions", Serial.lazy(() -> LootPredicate.SERIALIZER).list().optional(List.of()), ToggleTooltips::predicates, @@ -303,7 +303,7 @@ record ToggleTooltips(@NotNull List predicates, @NotNull Map t.data().name(), Function.identity()))::get, t -> t.data().name(), BinaryTagSerializer.BOOLEAN - ), ToggleTooltips::toggles, + ), ToggleTooltips::source, ToggleTooltips::new ); @@ -333,7 +333,7 @@ public record ComponentToggler(@NotNull DataComponent data, @NotNull BiFun public @NotNull ItemStack apply(@NotNull ItemStack input, @NotNull LootContext context) { if (!LootPredicate.all(predicates, context)) return input; - for (var toggle : toggles.entrySet()) { + for (var toggle : source.entrySet()) { input = toggle.getKey().apply(input, toggle.getValue()); } @@ -341,12 +341,12 @@ public record ComponentToggler(@NotNull DataComponent data, @NotNull BiFun } } - record StewEffect(@NotNull List predicates, @NotNull List effects) implements LootFunction { + record SetStewEffect(@NotNull List predicates, @NotNull List effects) implements LootFunction { - public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( - "conditions", Serial.lazy(() -> LootPredicate.SERIALIZER).list().optional(List.of()), StewEffect::predicates, - "effects", AddedEffect.SERIALIZER.list(), StewEffect::effects, - StewEffect::new + public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( + "conditions", Serial.lazy(() -> LootPredicate.SERIALIZER).list().optional(List.of()), SetStewEffect::predicates, + "effects", AddedEffect.SERIALIZER.list(), SetStewEffect::effects, + SetStewEffect::new ); public record AddedEffect(@NotNull PotionEffect effect, @NotNull LootNumber duration) { @@ -379,12 +379,12 @@ public record AddedEffect(@NotNull PotionEffect effect, @NotNull LootNumber dura } } - record OminousBottleAmplifier(@NotNull List predicates, @NotNull LootNumber amplifier) implements LootFunction { + record SetOminousBottleAmplifier(@NotNull List predicates, @NotNull LootNumber amplifier) implements LootFunction { - public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( - "conditions", Serial.lazy(() -> LootPredicate.SERIALIZER).list().optional(List.of()), OminousBottleAmplifier::predicates, - "amplifier", LootNumber.SERIALIZER, OminousBottleAmplifier::amplifier, - OminousBottleAmplifier::new + public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( + "conditions", Serial.lazy(() -> LootPredicate.SERIALIZER).list().optional(List.of()), SetOminousBottleAmplifier::predicates, + "amplifier", LootNumber.SERIALIZER, SetOminousBottleAmplifier::amplifier, + SetOminousBottleAmplifier::new ); @Override @@ -397,21 +397,21 @@ record OminousBottleAmplifier(@NotNull List predicates, @NotNull } } - record CopyNBT(@NotNull List predicates, @NotNull LootNBT source, @NotNull List operations) implements LootFunction { + record CopyCustomData(@NotNull List predicates, @NotNull LootNBT source, @NotNull List ops) implements LootFunction { - public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( - "conditions", Serial.lazy(() -> LootPredicate.SERIALIZER).list().optional(List.of()), CopyNBT::predicates, - "source", LootNBT.SERIALIZER, CopyNBT::source, - "ops", Operation.SERIALIZER.list(), CopyNBT::operations, - CopyNBT::new + public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( + "conditions", Serial.lazy(() -> LootPredicate.SERIALIZER).list().optional(List.of()), CopyCustomData::predicates, + "source", LootNBT.SERIALIZER, CopyCustomData::source, + "ops", Operation.SERIALIZER.list(), CopyCustomData::ops, + CopyCustomData::new ); - public record Operation(@NotNull NBTPath source, @NotNull NBTPath target, @NotNull Operator operator) { + public record Operation(@NotNull NBTPath source, @NotNull NBTPath target, @NotNull Operator op) { public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( "source", NBTPath.SERIALIZER, Operation::source, "target", NBTPath.SERIALIZER, Operation::target, - "op", Operator.SERIALIZER, Operation::operator, + "op", Operator.SERIALIZER, Operation::op, Operation::new ); @@ -420,7 +420,7 @@ public void execute(@NotNull NBTReference nbt, @NotNull BinaryTag sourceTag) { source.get(sourceTag).forEach(ref -> nbts.add(ref.get())); if (nbts.isEmpty()) return; - operator.merge(nbt, target, nbts); + op.merge(nbt, target, nbts); } } @@ -472,7 +472,7 @@ public void merge(@NotNull NBTReference nbt, @NotNull NBTPath target, @NotNull L NBTReference targetNBT = NBTReference.of(input.get(ItemComponent.CUSTOM_DATA, CustomData.EMPTY).nbt()); - for (Operation operation : operations) { + for (Operation operation : ops) { operation.execute(targetNBT, sourceNBT); } @@ -484,18 +484,18 @@ public void merge(@NotNull NBTReference nbt, @NotNull NBTPath target, @NotNull L } } - record LimitCount(@NotNull List predicates, @NotNull LootNumberRange range) implements LootFunction { + record LimitCount(@NotNull List predicates, @NotNull LootNumberRange limit) implements LootFunction { public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( "conditions", Serial.lazy(() -> LootPredicate.SERIALIZER).list().optional(List.of()), LimitCount::predicates, - "limit", LootNumberRange.SERIALIZER, LimitCount::range, + "limit", LootNumberRange.SERIALIZER, LimitCount::limit, LimitCount::new ); @Override public @NotNull ItemStack apply(@NotNull ItemStack input, @NotNull LootContext context) { if (!LootPredicate.all(predicates, context)) return input; - return input.withAmount(i -> (int) range.limit(context, i)); + return input.withAmount(i -> (int) limit.limit(context, i)); } } @@ -515,27 +515,27 @@ record SetCount(@NotNull List predicates, @NotNull LootNumber cou } } - record SetMaterial(@NotNull List predicates, @NotNull Material material) implements LootFunction { + record SetItem(@NotNull List predicates, @NotNull Material item) implements LootFunction { - public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( - "conditions", Serial.lazy(() -> LootPredicate.SERIALIZER).list().optional(List.of()), SetMaterial::predicates, - "item", Material.NBT_TYPE, SetMaterial::material, - SetMaterial::new + public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( + "conditions", Serial.lazy(() -> LootPredicate.SERIALIZER).list().optional(List.of()), SetItem::predicates, + "item", Material.NBT_TYPE, SetItem::item, + SetItem::new ); @Override public @NotNull ItemStack apply(@NotNull ItemStack input, @NotNull LootContext context) { if (!LootPredicate.all(predicates, context)) return input; - return input.builder().material(material).build(); + return input.builder().material(item).build(); } } - record SetLootTable(@NotNull List predicates, @NotNull NamespaceID key, long seed) implements LootFunction { + record SetLootTable(@NotNull List predicates, @NotNull NamespaceID name, long seed) implements LootFunction { public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( "conditions", Serial.lazy(() -> LootPredicate.SERIALIZER).list().optional(List.of()), SetLootTable::predicates, - "name", Serial.KEY, SetLootTable::key, + "name", Serial.KEY, SetLootTable::name, "seed", Serial.LONG.optional(0L), SetLootTable::seed, SetLootTable::new ); @@ -545,7 +545,7 @@ record SetLootTable(@NotNull List predicates, @NotNull NamespaceI if (!LootPredicate.all(predicates, context)) return input; if (input.isAir()) return input; - return input.with(ItemComponent.CONTAINER_LOOT, new SeededContainerLoot(key.asString(), seed)); + return input.with(ItemComponent.CONTAINER_LOOT, new SeededContainerLoot(name.asString(), seed)); } } @@ -605,15 +605,15 @@ record CopyState(@NotNull List predicates, @NotNull Block block, } } - record MoreByLevel(@NotNull List predicates, @NotNull DynamicRegistry.Key enchantment, - @NotNull LootNumber count, @Nullable Integer limit) implements LootFunction { + record EnchantedCountIncrease(@NotNull List predicates, @NotNull DynamicRegistry.Key enchantment, + @NotNull LootNumber count, @Nullable Integer limit) implements LootFunction { - public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( - "conditions", Serial.lazy(() -> LootPredicate.SERIALIZER).list().optional(List.of()), MoreByLevel::predicates, - "enchantment", Serial.key(), MoreByLevel::enchantment, - "count", LootNumber.SERIALIZER, MoreByLevel::count, - "limit", BinaryTagSerializer.INT.optional(), MoreByLevel::limit, - MoreByLevel::new + public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( + "conditions", Serial.lazy(() -> LootPredicate.SERIALIZER).list().optional(List.of()), EnchantedCountIncrease::predicates, + "enchantment", Serial.key(), EnchantedCountIncrease::enchantment, + "count", LootNumber.SERIALIZER, EnchantedCountIncrease::count, + "limit", BinaryTagSerializer.INT.optional(), EnchantedCountIncrease::limit, + EnchantedCountIncrease::new ); @Override @@ -631,33 +631,33 @@ record MoreByLevel(@NotNull List predicates, @NotNull DynamicRegi } } - record SetNBT(@NotNull List predicates, @NotNull CompoundBinaryTag nbt) implements LootFunction { + record SetCustomData(@NotNull List predicates, @NotNull CompoundBinaryTag tag) implements LootFunction { - public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( - "conditions", Serial.lazy(() -> LootPredicate.SERIALIZER).list().optional(List.of()), SetNBT::predicates, + public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( + "conditions", Serial.lazy(() -> LootPredicate.SERIALIZER).list().optional(List.of()), SetCustomData::predicates, "tag", BinaryTagSerializer.STRING.map(s -> { try { return TagStringIO.get().asCompound(s); } catch (IOException e) { throw new RuntimeException(e); } - }, TagStringIOExt::writeTag), SetNBT::nbt, - SetNBT::new + }, TagStringIOExt::writeTag), SetCustomData::tag, + SetCustomData::new ); @Override public @NotNull ItemStack apply(@NotNull ItemStack input, @NotNull LootContext context) { if (!LootPredicate.all(predicates, context)) return input; - return input.with(ItemComponent.CUSTOM_DATA, new CustomData(nbt)); + return input.with(ItemComponent.CUSTOM_DATA, new CustomData(tag)); } } - record SetCustomModelData(@NotNull List predicates, @NotNull LootNumber data) implements LootFunction { + record SetCustomModelData(@NotNull List predicates, @NotNull LootNumber value) implements LootFunction { public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( "conditions", Serial.lazy(() -> LootPredicate.SERIALIZER).list().optional(List.of()), SetCustomModelData::predicates, - "value", LootNumber.SERIALIZER, SetCustomModelData::data, + "value", LootNumber.SERIALIZER, SetCustomModelData::value, SetCustomModelData::new ); @@ -665,7 +665,7 @@ record SetCustomModelData(@NotNull List predicates, @NotNull Loot public @NotNull ItemStack apply(@NotNull ItemStack input, @NotNull LootContext context) { if (!LootPredicate.all(predicates, context)) return input; - return input.with(ItemComponent.CUSTOM_MODEL_DATA, data.getInt(context)); + return input.with(ItemComponent.CUSTOM_MODEL_DATA, value.getInt(context)); } } @@ -700,7 +700,7 @@ record SetEnchantments(@NotNull List predicates, @NotNull Map SERIALIZER = Template.template( "conditions", Serial.lazy(() -> LootPredicate.SERIALIZER).list().optional(List.of()), SetEnchantments::predicates, - "damage", Serial.map(DynamicRegistry.Key::of, DynamicRegistry.Key::name, LootNumber.SERIALIZER), SetEnchantments::enchantments, + "enchantments", Serial.map(DynamicRegistry.Key::of, DynamicRegistry.Key::name, LootNumber.SERIALIZER), SetEnchantments::enchantments, "add", BinaryTagSerializer.BOOLEAN.optional(false), SetEnchantments::add, SetEnchantments::new ); @@ -729,12 +729,12 @@ record SetEnchantments(@NotNull List predicates, @NotNull Map predicates, @NotNull LootNumber levels, @Nullable List> enchantments) implements LootFunction { + record EnchantWithLevels(@NotNull List predicates, @NotNull LootNumber levels, @Nullable List> options) implements LootFunction { public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( "conditions", Serial.lazy(() -> LootPredicate.SERIALIZER).list().optional(List.of()), EnchantWithLevels::predicates, "levels", LootNumber.SERIALIZER, EnchantWithLevels::levels, - "add", Template.todo("enchantwithlevels list"), EnchantWithLevels::enchantments, + "options", Template.todo("enchantwithlevels list"), EnchantWithLevels::options, EnchantWithLevels::new ); @@ -744,7 +744,7 @@ record EnchantWithLevels(@NotNull List predicates, @NotNull LootN VanillaInterface vanilla = context.require(LootContext.VANILLA_INTERFACE); - return vanilla.enchantItem(context.require(LootContext.RANDOM), input, levels.getInt(context), enchantments); + return vanilla.enchantItem(context.require(LootContext.RANDOM), input, levels.getInt(context), options); } } @@ -777,11 +777,11 @@ record SetBookCover(@NotNull List predicates, @Nullable FilteredT } } - record FillPlayerHead(@NotNull List predicates, @NotNull RelevantEntity target) implements LootFunction { + record FillPlayerHead(@NotNull List predicates, @NotNull RelevantEntity entity) implements LootFunction { public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( "conditions", Serial.lazy(() -> LootPredicate.SERIALIZER).list().optional(List.of()), FillPlayerHead::predicates, - "entity", RelevantEntity.SERIALIZER, FillPlayerHead::target, + "entity", RelevantEntity.SERIALIZER, FillPlayerHead::entity, FillPlayerHead::new ); @@ -791,7 +791,7 @@ record FillPlayerHead(@NotNull List predicates, @NotNull Relevant if (!input.material().equals(Material.PLAYER_HEAD)) return input; - if (!(context.get(target.key()) instanceof Player player)) return input; + if (!(context.get(entity.key()) instanceof Player player)) return input; PlayerSkin skin = player.getSkin(); if (skin == null) return input; diff --git a/src/main/java/net/goldenstack/loot/LootNBT.java b/src/main/java/net/goldenstack/loot/LootNBT.java index e251b33..2654832 100644 --- a/src/main/java/net/goldenstack/loot/LootNBT.java +++ b/src/main/java/net/goldenstack/loot/LootNBT.java @@ -27,7 +27,7 @@ public interface LootNBT { BinaryTagSerializer.STRING.map(Context.Target::fromString, Context.Target::toString).map(Context::new, Context::target), Template.registry("type", Template.entry("context", Context.class, Context.SERIALIZER), - Template.entry("storage", CommandStorage.class, CommandStorage.SERIALIZER) + Template.entry("storage", Storage.class, Storage.SERIALIZER) ) ); @@ -38,11 +38,11 @@ public interface LootNBT { */ @Nullable BinaryTag getNBT(@NotNull LootContext context); - record CommandStorage(@NotNull NamespaceID source) implements LootNBT { + record Storage(@NotNull NamespaceID source) implements LootNBT { - public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( - "source", Serial.KEY, CommandStorage::source, - CommandStorage::new + public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( + "source", Serial.KEY, Storage::source, + Storage::new ); @Override diff --git a/src/main/java/net/goldenstack/loot/LootNumber.java b/src/main/java/net/goldenstack/loot/LootNumber.java index a67ebc6..104692b 100644 --- a/src/main/java/net/goldenstack/loot/LootNumber.java +++ b/src/main/java/net/goldenstack/loot/LootNumber.java @@ -28,7 +28,7 @@ public interface LootNumber { Template.entry("uniform", Uniform.class, Uniform.SERIALIZER), Template.entry("binomial", Binomial.class, Binomial.SERIALIZER), Template.entry("score", Score.class, Score.SERIALIZER), - Template.entry("storage", CommandStorage.class, CommandStorage.SERIALIZER), + Template.entry("storage", Storage.class, Storage.SERIALIZER), Template.entry("enchantment_level", EnchantmentLevel.class, EnchantmentLevel.SERIALIZER) ) ); @@ -115,10 +115,10 @@ public double getDouble(@NotNull LootContext context) { } } - record EnchantmentLevel(@NotNull LevelBasedValue value) implements LootNumber { + record EnchantmentLevel(@NotNull LevelBasedValue amount) implements LootNumber { public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( - "amount", LevelBasedValue.NBT_TYPE, EnchantmentLevel::value, + "amount", LevelBasedValue.NBT_TYPE, EnchantmentLevel::amount, EnchantmentLevel::new ); @@ -129,7 +129,7 @@ public int getInt(@NotNull LootContext context) { @Override public double getDouble(@NotNull LootContext context) { - return value.calc(context.require(LootContext.ENCHANTMENT_LEVEL)); + return amount.calc(context.require(LootContext.ENCHANTMENT_LEVEL)); } } @@ -155,12 +155,12 @@ public double getDouble(@NotNull LootContext context) { } } - record CommandStorage(@NotNull NamespaceID storage, @NotNull NBTPath path) implements LootNumber { + record Storage(@NotNull NamespaceID storage, @NotNull NBTPath path) implements LootNumber { - public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( - "storage", Serial.KEY, CommandStorage::storage, - "path", NBTPath.SERIALIZER, CommandStorage::path, - CommandStorage::new + public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( + "storage", Serial.KEY, Storage::storage, + "path", NBTPath.SERIALIZER, Storage::path, + Storage::new ); @Override diff --git a/src/main/java/net/goldenstack/loot/LootPredicate.java b/src/main/java/net/goldenstack/loot/LootPredicate.java index d40019e..8a753bf 100644 --- a/src/main/java/net/goldenstack/loot/LootPredicate.java +++ b/src/main/java/net/goldenstack/loot/LootPredicate.java @@ -28,24 +28,24 @@ public interface LootPredicate extends Predicate<@NotNull LootContext> { @NotNull BinaryTagSerializer SERIALIZER = Template.registry("condition", - Template.entry("all_of", All.class, All.SERIALIZER), - Template.entry("any_of", Any.class, Any.SERIALIZER), - Template.entry("block_state_property", BlockState.class, BlockState.SERIALIZER), - Template.entry("damage_source_properties", DamageSource.class, DamageSource.SERIALIZER), - Template.entry("enchantment_active_check", EnchantmentActive.class, EnchantmentActive.SERIALIZER), + Template.entry("all_of", AllOf.class, AllOf.SERIALIZER), + Template.entry("any_of", AnyOf.class, AnyOf.SERIALIZER), + Template.entry("block_state_property", BlockStateProperty.class, BlockStateProperty.SERIALIZER), + Template.entry("damage_source_properties", DamageSourceProperties.class, DamageSourceProperties.SERIALIZER), + Template.entry("enchantment_active_check", EnchantmentActiveCheck.class, EnchantmentActiveCheck.SERIALIZER), Template.entry("entity_properties", EntityProperties.class, EntityProperties.SERIALIZER), - Template.entry("entity_scores", Scores.class, Scores.SERIALIZER), + Template.entry("entity_scores", EntityScores.class, EntityScores.SERIALIZER), Template.entry("inverted", Inverted.class, Inverted.SERIALIZER), Template.entry("killed_by_player", KilledByPlayer.class, KilledByPlayer.SERIALIZER), - Template.entry("location_check", Location.class, Location.SERIALIZER), - Template.entry("match_tool", Tool.class, Tool.SERIALIZER), + Template.entry("location_check", LocationCheck.class, LocationCheck.SERIALIZER), + Template.entry("match_tool", MatchTool.class, MatchTool.SERIALIZER), Template.entry("random_chance", RandomChance.class, RandomChance.SERIALIZER), - Template.entry("random_chance_with_enchanted_bonus", EnchantmentBasedRandomChance.class, EnchantmentBasedRandomChance.SERIALIZER), + Template.entry("random_chance_with_enchanted_bonus", RandomChanceWithEnchantedBonus.class, RandomChanceWithEnchantedBonus.SERIALIZER), Template.entry("reference", Reference.class, Reference.SERIALIZER), Template.entry("survives_explosion", SurvivesExplosion.class, SurvivesExplosion.SERIALIZER), Template.entry("table_bonus", TableBonus.class, TableBonus.SERIALIZER), Template.entry("time_check", TimeCheck.class, TimeCheck.SERIALIZER), - Template.entry("value_check", RangeCheck.class, RangeCheck.SERIALIZER), + Template.entry("value_check", ValueCheck.class, ValueCheck.SERIALIZER), Template.entry("weather_check", WeatherCheck.class, WeatherCheck.SERIALIZER) ); @@ -72,32 +72,32 @@ static boolean all(@NotNull List predicates, @NotNull LootContext return true; } - record All(@NotNull List predicates) implements LootPredicate { + record AllOf(@NotNull List terms) implements LootPredicate { - public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( - "terms", Serial.lazy(() -> LootPredicate.SERIALIZER).list(), All::predicates, - All::new + public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( + "terms", Serial.lazy(() -> LootPredicate.SERIALIZER).list(), AllOf::terms, + AllOf::new ); @Override public boolean test(@NotNull LootContext context) { - return all(predicates, context); + return all(terms, context); } } - record Any(@NotNull List predicates) implements LootPredicate { + record AnyOf(@NotNull List terms) implements LootPredicate { - public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( - "terms", Serial.lazy(() -> LootPredicate.SERIALIZER).list(), Any::predicates, - Any::new + public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( + "terms", Serial.lazy(() -> LootPredicate.SERIALIZER).list(), AnyOf::terms, + AnyOf::new ); @Override public boolean test(@NotNull LootContext context) { - if (predicates.isEmpty()) { + if (terms.isEmpty()) { return false; } - for (var predicate : predicates) { + for (var predicate : terms) { if (predicate.test(context)) { return true; } @@ -106,16 +106,16 @@ public boolean test(@NotNull LootContext context) { } } - record Inverted(@NotNull LootPredicate child) implements LootPredicate { + record Inverted(@NotNull LootPredicate term) implements LootPredicate { public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( - "term", Serial.lazy(() -> LootPredicate.SERIALIZER), Inverted::child, + "term", Serial.lazy(() -> LootPredicate.SERIALIZER), Inverted::term, Inverted::new ); @Override public boolean test(@NotNull LootContext context) { - return !child.test(context); + return !term.test(context); } } @@ -140,16 +140,16 @@ public boolean test(@NotNull LootContext context) { } } - record RandomChance(@NotNull LootNumber number) implements LootPredicate { + record RandomChance(@NotNull LootNumber chance) implements LootPredicate { public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( - "chance", LootNumber.SERIALIZER, RandomChance::number, + "chance", LootNumber.SERIALIZER, RandomChance::chance, RandomChance::new ); @Override public boolean test(@NotNull LootContext context) { - return context.require(LootContext.RANDOM).nextDouble() < number.getDouble(context); + return context.require(LootContext.RANDOM).nextDouble() < chance.getDouble(context); } } @@ -170,25 +170,25 @@ public boolean test(@NotNull LootContext context) { } } - record RangeCheck(@NotNull LootNumber source, @NotNull LootNumberRange range) implements LootPredicate { + record ValueCheck(@NotNull LootNumber value, @NotNull LootNumberRange range) implements LootPredicate { - public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( - "value", LootNumber.SERIALIZER, RangeCheck::source, - "range", LootNumberRange.SERIALIZER, RangeCheck::range, - RangeCheck::new + public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( + "value", LootNumber.SERIALIZER, ValueCheck::value, + "range", LootNumberRange.SERIALIZER, ValueCheck::range, + ValueCheck::new ); @Override public boolean test(@NotNull LootContext context) { - return range.check(context, source.getInt(context)); + return range.check(context, value.getInt(context)); } } - record TimeCheck(@Nullable Long period, @NotNull LootNumberRange range) implements LootPredicate { + record TimeCheck(@Nullable Long period, @NotNull LootNumberRange value) implements LootPredicate { public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( "period", Serial.LONG.optional(), TimeCheck::period, - "value", LootNumberRange.SERIALIZER, TimeCheck::range, + "value", LootNumberRange.SERIALIZER, TimeCheck::value, TimeCheck::new ); @@ -200,7 +200,7 @@ public boolean test(@NotNull LootContext context) { time %= period; } - return range.check(context, time); + return value.check(context, time); } } @@ -224,26 +224,26 @@ public boolean test(@NotNull LootContext context) { } } - record Reference(@NotNull NamespaceID key) implements LootPredicate { + record Reference(@NotNull NamespaceID name) implements LootPredicate { public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( - "name", Serial.KEY, Reference::key, + "name", Serial.KEY, Reference::name, Reference::new ); @Override public boolean test(@NotNull LootContext context) { - LootPredicate predicate = context.require(LootContext.REGISTERED_PREDICATES).apply(key); + LootPredicate predicate = context.require(LootContext.REGISTERED_PREDICATES).apply(name); return predicate != null && predicate.test(context); } } - record EnchantmentActive(boolean active) implements LootPredicate { + record EnchantmentActiveCheck(boolean active) implements LootPredicate { - public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( - "active", BinaryTagSerializer.BOOLEAN, EnchantmentActive::active, - EnchantmentActive::new + public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( + "active", BinaryTagSerializer.BOOLEAN, EnchantmentActiveCheck::active, + EnchantmentActiveCheck::new ); @Override @@ -252,27 +252,27 @@ public boolean test(@NotNull LootContext context) { } } - record BlockState(@NotNull NamespaceID key, @Nullable BlockPredicate predicate) implements LootPredicate { + record BlockStateProperty(@NotNull NamespaceID block, @Nullable BlockPredicate predicate) implements LootPredicate { - public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( - "block", Serial.KEY, BlockState::key, - "properties", BlockPredicate.SERIALIZER.optional(), BlockState::predicate, - BlockState::new + public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( + "block", Serial.KEY, BlockStateProperty::block, + "properties", BlockPredicate.SERIALIZER.optional(), BlockStateProperty::predicate, + BlockStateProperty::new ); @Override public boolean test(@NotNull LootContext context) { Block block = context.get(LootContext.BLOCK_STATE); - return block != null && key.equals(block.namespace()) && (predicate == null || predicate.test(block)); + return block != null && this.block.equals(block.namespace()) && (predicate == null || predicate.test(block)); } } - record DamageSource(@Nullable DamageSourcePredicate predicate) implements LootPredicate { + record DamageSourceProperties(@Nullable DamageSourcePredicate predicate) implements LootPredicate { - public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( - "predicate",Serial.lazy(DamageSourcePredicate.SERIALIZER::get).optional(), DamageSource::predicate, - DamageSource::new + public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( + "predicate",Serial.lazy(DamageSourcePredicate.SERIALIZER::get).optional(), DamageSourceProperties::predicate, + DamageSourceProperties::new ); @Override @@ -289,31 +289,31 @@ public boolean test(@NotNull LootContext context) { } } - record EntityProperties(@Nullable EntityPredicate predicate, @NotNull RelevantEntity relevantEntity) implements LootPredicate { + record EntityProperties(@Nullable EntityPredicate predicate, @NotNull RelevantEntity entity) implements LootPredicate { public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( "predicate", Serial.lazy(EntityPredicate.SERIALIZER::get), EntityProperties::predicate, - "entity", RelevantEntity.SERIALIZER, EntityProperties::relevantEntity, + "entity", RelevantEntity.SERIALIZER, EntityProperties::entity, EntityProperties::new ); @Override public boolean test(@NotNull LootContext context) { - Entity entity = context.get(relevantEntity.key()); + Entity entity = context.get(this.entity.key()); Point origin = context.get(LootContext.ORIGIN); return predicate == null || predicate.test(context.require(LootContext.WORLD), origin, entity); } } - record Location(@Nullable LocationPredicate predicate, double offsetX, double offsetY, double offsetZ) implements LootPredicate { + record LocationCheck(@Nullable LocationPredicate predicate, double offsetX, double offsetY, double offsetZ) implements LootPredicate { - public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( - "predicate", Serial.lazy(LocationPredicate.SERIALIZER::get), Location::predicate, - "offsetX", Serial.DOUBLE.optional(0D), Location::offsetX, - "offsetY", Serial.DOUBLE.optional(0D), Location::offsetY, - "offsetZ", Serial.DOUBLE.optional(0D), Location::offsetZ, - Location::new + public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( + "predicate", Serial.lazy(LocationPredicate.SERIALIZER::get), LocationCheck::predicate, + "offsetX", Serial.DOUBLE.optional(0D), LocationCheck::offsetX, + "offsetY", Serial.DOUBLE.optional(0D), LocationCheck::offsetY, + "offsetZ", Serial.DOUBLE.optional(0D), LocationCheck::offsetZ, + LocationCheck::new ); @Override @@ -327,11 +327,11 @@ public boolean test(@NotNull LootContext context) { } } - record Tool(@Nullable ItemPredicate predicate) implements LootPredicate { + record MatchTool(@Nullable ItemPredicate predicate) implements LootPredicate { - public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( - "predicate", Serial.lazy(ItemPredicate.SERIALIZER::get), Tool::predicate, - Tool::new + public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( + "predicate", Serial.lazy(ItemPredicate.SERIALIZER::get), MatchTool::predicate, + MatchTool::new ); @Override @@ -345,17 +345,17 @@ public boolean test(@NotNull LootContext context) { } } - record Scores(@NotNull Map scores, @NotNull RelevantEntity relevantEntity) implements LootPredicate { + record EntityScores(@NotNull Map scores, @NotNull RelevantEntity entity) implements LootPredicate { - public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( - "scores", Serial.map(LootNumberRange.SERIALIZER), Scores::scores, - "entity", RelevantEntity.SERIALIZER, Scores::relevantEntity, - Scores::new + public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( + "scores", Serial.map(LootNumberRange.SERIALIZER), EntityScores::scores, + "entity", RelevantEntity.SERIALIZER, EntityScores::entity, + EntityScores::new ); @Override public boolean test(@NotNull LootContext context) { - Entity entity = context.get(relevantEntity.key()); + Entity entity = context.get(this.entity.key()); if (entity == null) return false; VanillaInterface vanilla = context.require(LootContext.VANILLA_INTERFACE); @@ -371,13 +371,13 @@ public boolean test(@NotNull LootContext context) { } } - record EnchantmentBasedRandomChance(@NotNull DynamicRegistry.Key enchantment, float defaultChance, @NotNull LevelBasedValue modifiedChance) implements LootPredicate { + record RandomChanceWithEnchantedBonus(@NotNull DynamicRegistry.Key enchantment, float unenchantedChance, @NotNull LevelBasedValue enchantedChance) implements LootPredicate { - public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( - "enchantment", Serial.key(), EnchantmentBasedRandomChance::enchantment, - "unenchanted_chance", BinaryTagSerializer.FLOAT, EnchantmentBasedRandomChance::defaultChance, - "enchanted_chance", LevelBasedValue.NBT_TYPE, EnchantmentBasedRandomChance::modifiedChance, - EnchantmentBasedRandomChance::new + public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( + "enchantment", Serial.key(), RandomChanceWithEnchantedBonus::enchantment, + "unenchanted_chance", BinaryTagSerializer.FLOAT, RandomChanceWithEnchantedBonus::unenchantedChance, + "enchanted_chance", LevelBasedValue.NBT_TYPE, RandomChanceWithEnchantedBonus::enchantedChance, + RandomChanceWithEnchantedBonus::new ); @Override @@ -386,7 +386,7 @@ public boolean test(@NotNull LootContext context) { int level = EnchantmentUtils.level(attacker, enchantment); - float chance = level > 0 ? modifiedChance.calc(level) : defaultChance; + float chance = level > 0 ? enchantedChance.calc(level) : unenchantedChance; return context.require(LootContext.RANDOM).nextFloat() < chance; } } diff --git a/src/main/java/net/goldenstack/loot/LootScore.java b/src/main/java/net/goldenstack/loot/LootScore.java index f99f3a8..cdb6360 100644 --- a/src/main/java/net/goldenstack/loot/LootScore.java +++ b/src/main/java/net/goldenstack/loot/LootScore.java @@ -15,7 +15,7 @@ public interface LootScore extends Function<@NotNull LootContext, Function<@NotNull String, @Nullable Integer>> { @NotNull BinaryTagSerializer SERIALIZER = Template.compoundSplit( - RelevantEntity.SERIALIZER.map(Context::new, Context::entity), + RelevantEntity.SERIALIZER.map(Context::new, Context::name), Template.registry("type", Template.entry("fixed", Fixed.class, Fixed.SERIALIZER), Template.entry("context", Context.class, Context.SERIALIZER) @@ -25,16 +25,16 @@ public interface LootScore extends Function<@NotNull LootContext, Function<@NotN @Override @NotNull Function<@NotNull String, @Nullable Integer> apply(@NotNull LootContext context); - record Context(@NotNull RelevantEntity entity) implements LootScore { + record Context(@NotNull RelevantEntity name) implements LootScore { public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( - "name", RelevantEntity.SERIALIZER, Context::entity, + "name", RelevantEntity.SERIALIZER, Context::name, Context::new ); @Override public @NotNull Function<@NotNull String, @Nullable Integer> apply(@NotNull LootContext context) { - return objective -> context.require(LootContext.VANILLA_INTERFACE).getScore(context.require(entity.key()), objective); + return objective -> context.require(LootContext.VANILLA_INTERFACE).getScore(context.require(name.key()), objective); } } diff --git a/src/main/java/net/goldenstack/loot/LootTable.java b/src/main/java/net/goldenstack/loot/LootTable.java index 792e704..fbd7b6d 100644 --- a/src/main/java/net/goldenstack/loot/LootTable.java +++ b/src/main/java/net/goldenstack/loot/LootTable.java @@ -14,15 +14,15 @@ * A loot table. * @param pools the pools that generate items in this table * @param functions the functions applied to each output item of this table - * @param sequence An ID specifying the name of the random sequence that is used to generate loot from this loot table. + * @param randomSequence An ID specifying the name of the random sequence that is used to generate loot from this loot table. */ -public record LootTable(@NotNull List pools, @NotNull List functions, @Nullable NamespaceID sequence) implements LootGenerator { +public record LootTable(@NotNull List pools, @NotNull List functions, @Nullable NamespaceID randomSequence) implements LootGenerator { @SuppressWarnings("UnstableApiUsage") public static final @NotNull BinaryTagSerializer SERIALIZER = Template.template( "pools", LootPool.SERIALIZER.list(), LootTable::pools, "functions", LootFunction.SERIALIZER.list(), LootTable::functions, - "random_sequence", Template.template(() -> null), LootTable::sequence, + "random_sequence", Template.template(() -> null), LootTable::randomSequence, LootTable::new );