From 48183abcad6e28d98cb8fc550b5ec927dfc35a3e Mon Sep 17 00:00:00 2001 From: Patbox <39821509+Patbox@users.noreply.github.com> Date: Sat, 15 Jun 2024 08:37:50 +0200 Subject: [PATCH] Update to 1.21 (#319) * Start working on 1.21 update * Maybe use this for now * Add support for trinket enchantments * Add method for adding trinkets slots to definitions for datagen usage * Use getId instead of creating it by hand * Update to rc * Style fix --- build.gradle | 2 +- gradle.properties | 12 +-- .../emi/trinkets/TrinketScreenManager.java | 2 +- .../dev/emi/trinkets/TrinketSlotTarget.java | 11 +++ .../java/dev/emi/trinkets/TrinketsMain.java | 2 +- .../dev/emi/trinkets/TrinketsNetwork.java | 6 +- .../api/LivingEntityTrinketComponent.java | 7 +- .../dev/emi/trinkets/api/SlotAttributes.java | 18 ++-- .../java/dev/emi/trinkets/api/SlotType.java | 12 ++- .../java/dev/emi/trinkets/api/Trinket.java | 17 ++-- .../emi/trinkets/api/TrinketInventory.java | 17 ++-- .../dev/emi/trinkets/api/TrinketsApi.java | 32 +++++-- .../TrinketsAttributeModifiersComponent.java | 4 +- .../emi/trinkets/data/EntitySlotLoader.java | 10 +- .../dev/emi/trinkets/data/SlotLoader.java | 18 ++-- .../mixin/EnchantmentDefinitionMixin.java | 46 ++++++++++ .../mixin/EnchantmentHelperMixin.java | 92 +++++++++++++++++++ .../mixin/ExperienceOrbEntityMixin.java | 82 ----------------- .../trinkets/mixin/HandledScreenMixin.java | 4 +- .../emi/trinkets/mixin/ItemStackMixin.java | 4 +- .../emi/trinkets/mixin/LivingEntityMixin.java | 17 ++-- .../trinkets/mixin/PlayerManagerMixin.java | 2 +- .../mixin/datafixer/Schema1460Mixin.java | 10 +- src/main/resources/trinkets.accesswidener | 3 +- src/main/resources/trinkets.mixins.json | 3 +- .../java/dev/emi/trinkets/TestTrinket.java | 14 +-- .../java/dev/emi/trinkets/TrinketsTest.java | 2 +- .../enchantment/test_armor.json | 30 ++++++ .../enchantment/test_trinket.json | 31 +++++++ .../tags/{items => item}/head/hat.json | 0 30 files changed, 332 insertions(+), 178 deletions(-) create mode 100644 src/main/java/dev/emi/trinkets/TrinketSlotTarget.java create mode 100644 src/main/java/dev/emi/trinkets/mixin/EnchantmentDefinitionMixin.java create mode 100644 src/main/java/dev/emi/trinkets/mixin/EnchantmentHelperMixin.java delete mode 100644 src/main/java/dev/emi/trinkets/mixin/ExperienceOrbEntityMixin.java create mode 100644 src/testmod/resources/data/trinkets-testmod/enchantment/test_armor.json create mode 100644 src/testmod/resources/data/trinkets-testmod/enchantment/test_trinket.json rename src/testmod/resources/data/trinkets/tags/{items => item}/head/hat.json (100%) diff --git a/build.gradle b/build.gradle index 0e5a982a..e8123de1 100644 --- a/build.gradle +++ b/build.gradle @@ -56,7 +56,7 @@ dependencies { // Dev Runtime testmodImplementation sourceSets.main.output - modLocalRuntime "dev.emi:emi-fabric:${emi_version}" + //modLocalRuntime "dev.emi:emi-fabric:${emi_version}" //modRuntimeOnly "me.shedaniel:RoughlyEnoughItems-fabric:${project.rei_version}" //modLocalRuntime "com.terraformersmc:modmenu:${project.mod_menu_version}" } diff --git a/gradle.properties b/gradle.properties index 3588924f..09e5e685 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,16 +1,16 @@ # Done to increase the memory available to gradle. org.gradle.jvmargs=-Xmx2G -minecraft_version=1.20.6 -yarn_mappings=1.20.6+build.1 -loader_version=0.15.10 +minecraft_version=1.21-rc1 +yarn_mappings=1.21-rc1+build.1 +loader_version=0.15.11 -mod_version = 3.9.0 +mod_version = 3.10.0 maven_group = dev.emi archives_base_name = trinkets -fabric_version=0.97.6+1.20.6 -cca_version=6.0.0-beta.3 +fabric_version=0.100.0+1.21 +cca_version=6.1.0 mod_menu_version=10.0.0-beta.1 emi_version=1.1.6+1.20.6 rei_version=15.0.728 diff --git a/src/main/java/dev/emi/trinkets/TrinketScreenManager.java b/src/main/java/dev/emi/trinkets/TrinketScreenManager.java index c7ecb057..c14ac248 100644 --- a/src/main/java/dev/emi/trinkets/TrinketScreenManager.java +++ b/src/main/java/dev/emi/trinkets/TrinketScreenManager.java @@ -14,7 +14,7 @@ import net.minecraft.util.Identifier; public class TrinketScreenManager { - private static final Identifier MORE_SLOTS = new Identifier("trinkets", "textures/gui/more_slots.png"); + private static final Identifier MORE_SLOTS = Identifier.of("trinkets", "textures/gui/more_slots.png"); public static TrinketScreen currentScreen; public static Rect2i currentBounds = new Rect2i(0, 0, 0, 0); public static Rect2i typeBounds = new Rect2i(0, 0, 0, 0); diff --git a/src/main/java/dev/emi/trinkets/TrinketSlotTarget.java b/src/main/java/dev/emi/trinkets/TrinketSlotTarget.java new file mode 100644 index 00000000..ddef7d62 --- /dev/null +++ b/src/main/java/dev/emi/trinkets/TrinketSlotTarget.java @@ -0,0 +1,11 @@ +package dev.emi.trinkets; + +import org.jetbrains.annotations.Nullable; + +import java.util.Optional; +import java.util.Set; + +public interface TrinketSlotTarget { + Set trinkets$slots(); + void trinkets$slots(Set slots); +} diff --git a/src/main/java/dev/emi/trinkets/TrinketsMain.java b/src/main/java/dev/emi/trinkets/TrinketsMain.java index 91c59373..68ecb14d 100644 --- a/src/main/java/dev/emi/trinkets/TrinketsMain.java +++ b/src/main/java/dev/emi/trinkets/TrinketsMain.java @@ -68,7 +68,7 @@ public void onInitialize() { } return TypedActionResult.pass(stack); }); - Registry.register(Registries.DATA_COMPONENT_TYPE, new Identifier(MOD_ID, "attribute_modifiers"), TrinketsAttributeModifiersComponent.TYPE); + Registry.register(Registries.DATA_COMPONENT_TYPE, Identifier.of(MOD_ID, "attribute_modifiers"), TrinketsAttributeModifiersComponent.TYPE); PayloadTypeRegistry.playS2C().register(TrinketsNetwork.BREAK, BreakPayload.CODEC); PayloadTypeRegistry.playS2C().register(TrinketsNetwork.SYNC_INVENTORY, SyncInventoryPayload.CODEC); PayloadTypeRegistry.playS2C().register(TrinketsNetwork.SYNC_SLOTS, SyncSlotsPayload.CODEC); diff --git a/src/main/java/dev/emi/trinkets/TrinketsNetwork.java b/src/main/java/dev/emi/trinkets/TrinketsNetwork.java index 0548c842..2bd7b5b5 100644 --- a/src/main/java/dev/emi/trinkets/TrinketsNetwork.java +++ b/src/main/java/dev/emi/trinkets/TrinketsNetwork.java @@ -8,9 +8,9 @@ public class TrinketsNetwork { - public static final CustomPayload.Id SYNC_SLOTS = new CustomPayload.Id<>(new Identifier(TrinketsMain.MOD_ID, "sync_slots")); - public static final CustomPayload.Id SYNC_INVENTORY = new CustomPayload.Id<>(new Identifier(TrinketsMain.MOD_ID, "sync_inventory")); - public static final CustomPayload.Id BREAK = new CustomPayload.Id<>(new Identifier(TrinketsMain.MOD_ID, "break")); + public static final CustomPayload.Id SYNC_SLOTS = new CustomPayload.Id<>(Identifier.of(TrinketsMain.MOD_ID, "sync_slots")); + public static final CustomPayload.Id SYNC_INVENTORY = new CustomPayload.Id<>(Identifier.of(TrinketsMain.MOD_ID, "sync_inventory")); + public static final CustomPayload.Id BREAK = new CustomPayload.Id<>(Identifier.of(TrinketsMain.MOD_ID, "break")); private TrinketsNetwork() { } diff --git a/src/main/java/dev/emi/trinkets/api/LivingEntityTrinketComponent.java b/src/main/java/dev/emi/trinkets/api/LivingEntityTrinketComponent.java index 7ae2fb1c..03faca18 100644 --- a/src/main/java/dev/emi/trinkets/api/LivingEntityTrinketComponent.java +++ b/src/main/java/dev/emi/trinkets/api/LivingEntityTrinketComponent.java @@ -18,6 +18,7 @@ import net.minecraft.network.RegistryByteBuf; import net.minecraft.registry.RegistryWrapper; import net.minecraft.registry.entry.RegistryEntry; +import net.minecraft.util.Identifier; import org.ladysnake.cca.api.v3.component.sync.AutoSyncedComponent; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.attribute.EntityAttribute; @@ -161,7 +162,7 @@ public void removeModifiers(Multimap modifiers) if (groupInv != null) { TrinketInventory inv = groupInv.get(slot); if (inv != null) { - inv.removeModifier(modifier.uuid()); + inv.removeModifier(modifier.id()); } } } @@ -234,9 +235,9 @@ public void readFromNbt(NbtCompound tag, RegistryWrapper.WrapperLookup lookup) { Multimap slotMap = HashMultimap.create(); this.forEach((ref, stack) -> { if (!stack.isEmpty()) { - UUID uuid = SlotAttributes.getUuid(ref); + Identifier identifier = SlotAttributes.getIdentifier(ref); Trinket trinket = TrinketsApi.getTrinket(stack.getItem()); - Multimap, EntityAttributeModifier> map = trinket.getModifiers(stack, ref, entity, uuid); + Multimap, EntityAttributeModifier> map = trinket.getModifiers(stack, ref, entity, identifier); for (RegistryEntry entityAttribute : map.keySet()) { if (entityAttribute.hasKeyAndValue() && entityAttribute.value() instanceof SlotAttributes.SlotEntityAttribute slotEntityAttribute) { slotMap.putAll(slotEntityAttribute.slot, map.get(entityAttribute)); diff --git a/src/main/java/dev/emi/trinkets/api/SlotAttributes.java b/src/main/java/dev/emi/trinkets/api/SlotAttributes.java index c2cacc4f..68169d30 100644 --- a/src/main/java/dev/emi/trinkets/api/SlotAttributes.java +++ b/src/main/java/dev/emi/trinkets/api/SlotAttributes.java @@ -1,7 +1,6 @@ package dev.emi.trinkets.api; import java.util.Map; -import java.util.UUID; import com.google.common.collect.Maps; import com.google.common.collect.Multimap; @@ -9,24 +8,25 @@ import net.minecraft.entity.attribute.EntityAttribute; import net.minecraft.entity.attribute.EntityAttributeModifier; import net.minecraft.registry.entry.RegistryEntry; +import net.minecraft.util.Identifier; public class SlotAttributes { - private static Map CACHED_UUIDS= Maps.newHashMap(); - private static Map> CACHED_ATTRIBUTES = Maps.newHashMap(); + private static final Map CACHED_IDS = Maps.newHashMap(); + private static final Map> CACHED_ATTRIBUTES = Maps.newHashMap(); /** * Adds an Entity Attribute Nodifier for slot count to the provided multimap */ - public static void addSlotModifier(Multimap, EntityAttributeModifier> map, String slot, UUID uuid, double amount, + public static void addSlotModifier(Multimap, EntityAttributeModifier> map, String slot, Identifier identifier, double amount, EntityAttributeModifier.Operation operation) { CACHED_ATTRIBUTES.putIfAbsent(slot, RegistryEntry.of(new SlotEntityAttribute(slot))); - map.put(CACHED_ATTRIBUTES.get(slot), new EntityAttributeModifier(uuid, slot, amount, operation)); + map.put(CACHED_ATTRIBUTES.get(slot), new EntityAttributeModifier(identifier, amount, operation)); } - public static UUID getUuid(SlotReference ref) { - String key = ref.inventory().getSlotType().getGroup() + "/" + ref.inventory().getSlotType().getName() + "/" + ref.index(); - CACHED_UUIDS.putIfAbsent(key, UUID.nameUUIDFromBytes(key.getBytes())); - return CACHED_UUIDS.get(key); + public static Identifier getIdentifier(SlotReference ref) { + String key = ref.inventory().getSlotType().getId() + "/" + ref.index(); + CACHED_IDS.computeIfAbsent(key, Identifier::of); + return CACHED_IDS.get(key); } public static class SlotEntityAttribute extends EntityAttribute { diff --git a/src/main/java/dev/emi/trinkets/api/SlotType.java b/src/main/java/dev/emi/trinkets/api/SlotType.java index 9c0a39b9..2d52d560 100644 --- a/src/main/java/dev/emi/trinkets/api/SlotType.java +++ b/src/main/java/dev/emi/trinkets/api/SlotType.java @@ -115,24 +115,24 @@ public static SlotType read(NbtCompound data) { String name = slotData.getString("Name"); int order = slotData.getInt("Order"); int amount = slotData.getInt("Amount"); - Identifier icon = new Identifier(slotData.getString("Icon")); + Identifier icon = Identifier.of(slotData.getString("Icon")); NbtList quickMoveList = slotData.getList("QuickMovePredicates", NbtElement.STRING_TYPE); Set quickMovePredicates = new HashSet<>(); for (NbtElement tag : quickMoveList) { - quickMovePredicates.add(new Identifier(tag.asString())); + quickMovePredicates.add(Identifier.of(tag.asString())); } NbtList validatorList = slotData.getList("ValidatorPredicates", NbtElement.STRING_TYPE); Set validatorPredicates = new HashSet<>(); for (NbtElement tag : validatorList) { - validatorPredicates.add(new Identifier(tag.asString())); + validatorPredicates.add(Identifier.of(tag.asString())); } NbtList tooltipList = slotData.getList("TooltipPredicates", NbtElement.STRING_TYPE); Set tooltipPredicates = new HashSet<>(); for (NbtElement tag : tooltipList) { - tooltipPredicates.add(new Identifier(tag.asString())); + tooltipPredicates.add(Identifier.of(tag.asString())); } String dropRuleName = slotData.getString("DropRule"); DropRule dropRule = DropRule.DEFAULT; @@ -155,4 +155,8 @@ public boolean equals(Object o) { public int hashCode() { return Objects.hash(group, name); } + + public String getId() { + return this.group + "/" + this.name; + } } diff --git a/src/main/java/dev/emi/trinkets/api/Trinket.java b/src/main/java/dev/emi/trinkets/api/Trinket.java index 8451e456..6283c819 100644 --- a/src/main/java/dev/emi/trinkets/api/Trinket.java +++ b/src/main/java/dev/emi/trinkets/api/Trinket.java @@ -1,13 +1,15 @@ package dev.emi.trinkets.api; import java.util.ArrayList; -import java.util.UUID; import com.google.common.collect.Maps; import com.google.common.collect.Multimap; import com.google.common.collect.Multimaps; import dev.emi.trinkets.mixin.accessor.LivingEntityAccessor; +import java.util.function.Consumer; + +import net.minecraft.component.EnchantmentEffectComponentTypes; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.attribute.EntityAttribute; @@ -17,8 +19,9 @@ import net.minecraft.item.ItemStack; import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.server.world.ServerWorld; import net.minecraft.sound.SoundEvent; -import net.minecraft.util.math.random.Random; +import net.minecraft.util.Identifier; public interface Trinket { @@ -73,7 +76,7 @@ default boolean canEquip(ItemStack stack, SlotReference slot, LivingEntity entit * @return Whether the stack can be unequipped */ default boolean canUnequip(ItemStack stack, SlotReference slot, LivingEntity entity) { - return !EnchantmentHelper.hasBindingCurse(stack) || (entity instanceof PlayerEntity player && player.isCreative()); + return !EnchantmentHelper.hasAnyEnchantmentsWith(stack, EnchantmentEffectComponentTypes.PREVENT_ARMOR_CHANGE) || (entity instanceof PlayerEntity player && player.isCreative()); } /** @@ -107,14 +110,14 @@ default RegistryEntry getEquipSound(ItemStack stack, SlotReference s * If modifiers do not change based on stack, slot, or entity, caching based on passed UUID * should be considered * - * @param uuid The UUID to use for creating attributes + * @param slotIdentifier The Identifier to use for creating attributes */ - default Multimap, EntityAttributeModifier> getModifiers(ItemStack stack, SlotReference slot, LivingEntity entity, UUID uuid) { + default Multimap, EntityAttributeModifier> getModifiers(ItemStack stack, SlotReference slot, LivingEntity entity, Identifier slotIdentifier) { Multimap, EntityAttributeModifier> map = Multimaps.newMultimap(Maps.newLinkedHashMap(), ArrayList::new); if (stack.contains(TrinketsAttributeModifiersComponent.TYPE)) { for (var entry : stack.getOrDefault(TrinketsAttributeModifiersComponent.TYPE, TrinketsAttributeModifiersComponent.DEFAULT).modifiers()) { - if (entry.slot().isEmpty() || entry.slot().get().equals(slot.inventory().getSlotType().getGroup() + "/" + slot.inventory().getSlotType().getName())) { + if (entry.slot().isEmpty() || entry.slot().get().equals(slot.inventory().getSlotType().getId())) { map.put(entry.attribute(), entry.modifier()); } } @@ -124,7 +127,7 @@ default Multimap, EntityAttributeModifier> getMod /** * Called by Trinkets when a trinket is broken on the client if {@link TrinketsApi#onTrinketBroken} - * is called by the callback in {@link ItemStack#damage(int, Random, ServerPlayerEntity, Runnable)} server side + * is called by the callback in {@link ItemStack#damage(int, ServerWorld, ServerPlayerEntity, Consumer)} server side *

* The default implementation works the same as breaking vanilla equipment, a sound is played and * particles are spawned based on the item diff --git a/src/main/java/dev/emi/trinkets/api/TrinketInventory.java b/src/main/java/dev/emi/trinkets/api/TrinketInventory.java index 3d8eccc9..44ce7b78 100644 --- a/src/main/java/dev/emi/trinkets/api/TrinketInventory.java +++ b/src/main/java/dev/emi/trinkets/api/TrinketInventory.java @@ -10,6 +10,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtList; +import net.minecraft.util.Identifier; import net.minecraft.util.collection.DefaultedList; import java.util.*; @@ -20,7 +21,7 @@ public class TrinketInventory implements Inventory { private final SlotType slotType; private final int baseSize; private final TrinketComponent component; - private final Map modifiers = new HashMap<>(); + private final Map modifiers = new HashMap<>(); private final Set persistentModifiers = new HashSet<>(); private final Set cachedModifiers = new HashSet<>(); private final Multimap modifiersByOperation = HashMultimap.create(); @@ -105,7 +106,7 @@ public boolean canPlayerUse(PlayerEntity player) { return true; } - public Map getModifiers() { + public Map getModifiers() { return this.modifiers; } @@ -114,7 +115,7 @@ public Collection getModifiersByOperation(EntityAttribu } public void addModifier(EntityAttributeModifier modifier) { - this.modifiers.put(modifier.uuid(), modifier); + this.modifiers.put(modifier.id(), modifier); this.getModifiersByOperation(modifier.operation()).add(modifier); this.markUpdate(); } @@ -124,8 +125,8 @@ public void addPersistentModifier(EntityAttributeModifier modifier) { this.persistentModifiers.add(modifier); } - public void removeModifier(UUID uuid) { - EntityAttributeModifier modifier = this.modifiers.remove(uuid); + public void removeModifier(Identifier identifier) { + EntityAttributeModifier modifier = this.modifiers.remove(identifier); if (modifier != null) { this.persistentModifiers.remove(modifier); this.getModifiersByOperation(modifier.operation()).remove(modifier); @@ -134,7 +135,7 @@ public void removeModifier(UUID uuid) { } public void clearModifiers() { - Iterator iter = this.getModifiers().keySet().iterator(); + Iterator iter = this.getModifiers().keySet().iterator(); while(iter.hasNext()) { this.removeModifier(iter.next()); @@ -147,7 +148,7 @@ public void removeCachedModifier(EntityAttributeModifier attributeModifier) { public void clearCachedModifiers() { for (EntityAttributeModifier cachedModifier : this.cachedModifiers) { - this.removeModifier(cachedModifier.uuid()); + this.removeModifier(cachedModifier.id()); } this.cachedModifiers.clear(); } @@ -271,7 +272,7 @@ public NbtCompound getSyncTag() { NbtCompound NbtCompound = new NbtCompound(); if (!this.modifiers.isEmpty()) { NbtList NbtList = new NbtList(); - for (Map.Entry modifier : this.modifiers.entrySet()) { + for (Map.Entry modifier : this.modifiers.entrySet()) { NbtList.add(modifier.getValue().toNbt()); } diff --git a/src/main/java/dev/emi/trinkets/api/TrinketsApi.java b/src/main/java/dev/emi/trinkets/api/TrinketsApi.java index 843e54cf..4474bff2 100644 --- a/src/main/java/dev/emi/trinkets/api/TrinketsApi.java +++ b/src/main/java/dev/emi/trinkets/api/TrinketsApi.java @@ -2,10 +2,12 @@ import com.google.common.collect.ImmutableMap; import com.mojang.datafixers.util.Function3; +import dev.emi.trinkets.TrinketSlotTarget; import dev.emi.trinkets.TrinketsMain; import dev.emi.trinkets.data.EntitySlotLoader; import dev.emi.trinkets.payload.BreakPayload; -import net.minecraft.util.math.random.Random; +import net.minecraft.enchantment.Enchantment; +import net.minecraft.server.world.ServerWorld; import org.ladysnake.cca.api.v3.component.ComponentKey; import org.ladysnake.cca.api.v3.component.ComponentRegistryV3; import net.fabricmc.api.EnvType; @@ -28,11 +30,13 @@ import java.util.Map; import java.util.Optional; import java.util.Set; +import java.util.function.Consumer; + import net.minecraft.world.World; public class TrinketsApi { public static final ComponentKey TRINKET_COMPONENT = ComponentRegistryV3.INSTANCE - .getOrCreate(new Identifier(TrinketsMain.MOD_ID, "trinkets"), TrinketComponent.class); + .getOrCreate(Identifier.of(TrinketsMain.MOD_ID, "trinkets"), TrinketComponent.class); private static final Map> PREDICATES = new HashMap<>(); private static final Map TRINKETS = new HashMap<>(); @@ -63,7 +67,7 @@ public static Optional getTrinketComponent(LivingEntity living /** * Called to sync a trinket breaking event with clients. Should generally be - * called in the callback of {@link ItemStack#damage(int, Random, ServerPlayerEntity, Runnable)} + * called in the callback of {@link ItemStack#damage(int, ServerWorld, ServerPlayerEntity, Consumer)} */ public static void onTrinketBroken(ItemStack stack, SlotReference ref, LivingEntity entity) { World world = entity.getWorld(); @@ -157,22 +161,30 @@ public static boolean evaluatePredicateSet(Set set, ItemStack stack, return state.get(); } + public static Enchantment.Definition withTrinketSlots(Enchantment.Definition definition, Set slots) { + var def = new Enchantment.Definition(definition.supportedItems(), definition.primaryItems(), definition.weight(), definition.maxLevel(), + definition.minCost(), definition.maxCost(), definition.anvilCost(), definition.slots()); + + ((TrinketSlotTarget) (Object) def).trinkets$slots(slots); + return def; + } + static { - TrinketsApi.registerTrinketPredicate(new Identifier("trinkets", "all"), (stack, ref, entity) -> TriState.TRUE); - TrinketsApi.registerTrinketPredicate(new Identifier("trinkets", "none"), (stack, ref, entity) -> TriState.FALSE); - TagKey trinketsAll = TagKey.of(RegistryKeys.ITEM, new Identifier("trinkets", "all")); + TrinketsApi.registerTrinketPredicate(Identifier.of("trinkets", "all"), (stack, ref, entity) -> TriState.TRUE); + TrinketsApi.registerTrinketPredicate(Identifier.of("trinkets", "none"), (stack, ref, entity) -> TriState.FALSE); + TagKey trinketsAll = TagKey.of(RegistryKeys.ITEM, Identifier.of("trinkets", "all")); - TrinketsApi.registerTrinketPredicate(new Identifier("trinkets", "tag"), (stack, ref, entity) -> { + TrinketsApi.registerTrinketPredicate(Identifier.of("trinkets", "tag"), (stack, ref, entity) -> { SlotType slot = ref.inventory().getSlotType(); - TagKey tag = TagKey.of(RegistryKeys.ITEM, new Identifier("trinkets", slot.getGroup() + "/" + slot.getName())); + TagKey tag = TagKey.of(RegistryKeys.ITEM, Identifier.of("trinkets", slot.getId())); if (stack.isIn(tag) || stack.isIn(trinketsAll)) { return TriState.TRUE; } return TriState.DEFAULT; }); - TrinketsApi.registerTrinketPredicate(new Identifier("trinkets", "relevant"), (stack, ref, entity) -> { - var map = TrinketsApi.getTrinket(stack.getItem()).getModifiers(stack, ref, entity, SlotAttributes.getUuid(ref)); + TrinketsApi.registerTrinketPredicate(Identifier.of("trinkets", "relevant"), (stack, ref, entity) -> { + var map = TrinketsApi.getTrinket(stack.getItem()).getModifiers(stack, ref, entity, SlotAttributes.getIdentifier(ref)); if (!map.isEmpty()) { return TriState.TRUE; } diff --git a/src/main/java/dev/emi/trinkets/api/TrinketsAttributeModifiersComponent.java b/src/main/java/dev/emi/trinkets/api/TrinketsAttributeModifiersComponent.java index 291b7d28..7eda75ad 100644 --- a/src/main/java/dev/emi/trinkets/api/TrinketsAttributeModifiersComponent.java +++ b/src/main/java/dev/emi/trinkets/api/TrinketsAttributeModifiersComponent.java @@ -7,7 +7,7 @@ import java.util.List; import java.util.Optional; -import net.minecraft.component.DataComponentType; +import net.minecraft.component.ComponentType; import net.minecraft.entity.attribute.EntityAttribute; import net.minecraft.entity.attribute.EntityAttributeModifier; import net.minecraft.network.RegistryByteBuf; @@ -36,7 +36,7 @@ public record TrinketsAttributeModifiersComponent(List modifiers, boolean TrinketsAttributeModifiersComponent::showInTooltip, TrinketsAttributeModifiersComponent::new); - public static final DataComponentType TYPE = DataComponentType.builder().codec(CODEC).packetCodec(PACKET_CODEC).build(); + public static final ComponentType TYPE = ComponentType.builder().codec(CODEC).packetCodec(PACKET_CODEC).build(); public TrinketsAttributeModifiersComponent(List modifiers, boolean showInTooltip) { this.modifiers = modifiers; diff --git a/src/main/java/dev/emi/trinkets/data/EntitySlotLoader.java b/src/main/java/dev/emi/trinkets/data/EntitySlotLoader.java index 1886bcc1..0247035e 100644 --- a/src/main/java/dev/emi/trinkets/data/EntitySlotLoader.java +++ b/src/main/java/dev/emi/trinkets/data/EntitySlotLoader.java @@ -43,7 +43,7 @@ public class EntitySlotLoader extends SinglePreparationResourceReloader, Map> slots = new HashMap<>(); @@ -94,9 +94,9 @@ protected Map>> prepare(ResourceManager resource String id; if (name.startsWith("#")) { - id = "#" + new Identifier(name.substring(1)); + id = "#" + Identifier.of(name.substring(1)); } else { - id = new Identifier(name).toString(); + id = Identifier.of(name).toString(); } Map> slots = map.computeIfAbsent(id, (k) -> new HashMap<>()); @@ -136,7 +136,7 @@ protected void apply(Map>> loader, ResourceManag // TODO rewrite this to work with the new tag system TrinketsMain.LOGGER.error("[trinkets] Attempted to assign entity entry to tag"); /* - TagKey> tag = TagKey.of(Registry.ENTITY_TYPE_KEY, new Identifier(entityName.substring(1))); + TagKey> tag = TagKey.of(Registry.ENTITY_TYPE_KEY, Identifier.of(entityName.substring(1))); List> entityTypes = Registry.ENTITY_TYPE.getEntryList(tag) .orElseThrow(() -> new IllegalArgumentException("Unknown entity tag '" + entityName + "'")) .stream() @@ -145,7 +145,7 @@ protected void apply(Map>> loader, ResourceManag types.addAll(entityTypes);*/ } else { - types.add(Registries.ENTITY_TYPE.getOrEmpty(new Identifier(entityName)) + types.add(Registries.ENTITY_TYPE.getOrEmpty(Identifier.of(entityName)) .orElseThrow(() -> new IllegalArgumentException("Unknown entity '" + entityName + "'"))); } } catch (IllegalArgumentException e) { diff --git a/src/main/java/dev/emi/trinkets/data/SlotLoader.java b/src/main/java/dev/emi/trinkets/data/SlotLoader.java index e6b84659..bf8ac01e 100644 --- a/src/main/java/dev/emi/trinkets/data/SlotLoader.java +++ b/src/main/java/dev/emi/trinkets/data/SlotLoader.java @@ -34,7 +34,7 @@ public class SlotLoader extends SinglePreparationResourceReloader DEFAULT_QUICK_MOVE_PREDICATES = ImmutableSet.of(new Identifier("trinkets", "all")); - private static final Set DEFAULT_VALIDATOR_PREDICATES = ImmutableSet.of(new Identifier("trinkets", "tag")); - private static final Set DEFAULT_TOOLTIP_PREDICATES = ImmutableSet.of(new Identifier("trinkets", "all")); + private static final Set DEFAULT_QUICK_MOVE_PREDICATES = ImmutableSet.of(Identifier.of("trinkets", "all")); + private static final Set DEFAULT_VALIDATOR_PREDICATES = ImmutableSet.of(Identifier.of("trinkets", "tag")); + private static final Set DEFAULT_TOOLTIP_PREDICATES = ImmutableSet.of(Identifier.of("trinkets", "all")); private int order = 0; private int amount = -1; @@ -136,11 +136,11 @@ static class SlotData { private String dropRule = DropRule.DEFAULT.toString(); SlotType create(String group, String name) { - Identifier finalIcon = new Identifier(icon); - finalIcon = new Identifier(finalIcon.getNamespace(), "textures/" + finalIcon.getPath() + ".png"); - Set finalValidatorPredicates = validatorPredicates.stream().map(Identifier::new).collect(Collectors.toSet()); - Set finalQuickMovePredicates = quickMovePredicates.stream().map(Identifier::new).collect(Collectors.toSet()); - Set finalTooltipPredicates = tooltipPredicates.stream().map(Identifier::new).collect(Collectors.toSet()); + Identifier finalIcon = Identifier.of(icon); + finalIcon = Identifier.of(finalIcon.getNamespace(), "textures/" + finalIcon.getPath() + ".png"); + Set finalValidatorPredicates = validatorPredicates.stream().map(Identifier::of).collect(Collectors.toSet()); + Set finalQuickMovePredicates = quickMovePredicates.stream().map(Identifier::of).collect(Collectors.toSet()); + Set finalTooltipPredicates = tooltipPredicates.stream().map(Identifier::of).collect(Collectors.toSet()); if (finalValidatorPredicates.isEmpty()) { finalValidatorPredicates = DEFAULT_VALIDATOR_PREDICATES; } diff --git a/src/main/java/dev/emi/trinkets/mixin/EnchantmentDefinitionMixin.java b/src/main/java/dev/emi/trinkets/mixin/EnchantmentDefinitionMixin.java new file mode 100644 index 00000000..74337e64 --- /dev/null +++ b/src/main/java/dev/emi/trinkets/mixin/EnchantmentDefinitionMixin.java @@ -0,0 +1,46 @@ +package dev.emi.trinkets.mixin; + +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import com.llamalad7.mixinextras.injector.ModifyReturnValue; +import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import dev.emi.trinkets.TrinketSlotTarget; +import net.minecraft.enchantment.Enchantment; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; + +import java.util.List; +import java.util.Set; +import java.util.function.Function; + +@Mixin(Enchantment.Definition.class) +public class EnchantmentDefinitionMixin implements TrinketSlotTarget { + @Unique + private Set trinketSlots = Set.of(); + + + @Override + public Set trinkets$slots() { + return this.trinketSlots; + } + + @Override + public void trinkets$slots(Set slots) { + this.trinketSlots = slots; + } + + @ModifyExpressionValue(method = "", at = @At(value = "INVOKE", target = "Lcom/mojang/serialization/codecs/RecordCodecBuilder;mapCodec(Ljava/util/function/Function;)Lcom/mojang/serialization/MapCodec;")) + private static MapCodec extendCodec(MapCodec codec) { + return RecordCodecBuilder.mapCodec(instance -> instance.group( + codec.forGetter(Function.identity()), + Codec.list(Codec.STRING).xmap(Set::copyOf, List::copyOf) + .optionalFieldOf("trinkets:slots", Set.of()) + .forGetter(x -> ((TrinketSlotTarget) (Object) x).trinkets$slots()) + ).apply(instance, (Enchantment.Definition def, Set slots) -> { + ((TrinketSlotTarget) (Object) def).trinkets$slots(slots); + return def; + })); + } +} diff --git a/src/main/java/dev/emi/trinkets/mixin/EnchantmentHelperMixin.java b/src/main/java/dev/emi/trinkets/mixin/EnchantmentHelperMixin.java new file mode 100644 index 00000000..3b740055 --- /dev/null +++ b/src/main/java/dev/emi/trinkets/mixin/EnchantmentHelperMixin.java @@ -0,0 +1,92 @@ +package dev.emi.trinkets.mixin; + +import java.util.List; +import java.util.Optional; +import java.util.Set; +import java.util.function.Predicate; + +import com.llamalad7.mixinextras.sugar.Local; +import dev.emi.trinkets.TrinketSlotTarget; +import dev.emi.trinkets.api.TrinketComponent; +import dev.emi.trinkets.api.TrinketsApi; +import it.unimi.dsi.fastutil.objects.Object2IntMap; +import net.minecraft.component.ComponentType; +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.AttributeModifierSlot; +import net.minecraft.component.type.ItemEnchantmentsComponent; +import net.minecraft.enchantment.Enchantment; +import net.minecraft.enchantment.EnchantmentEffectContext; +import net.minecraft.entity.LivingEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.registry.entry.RegistryEntry; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.enchantment.EnchantmentHelper; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +/** + * Allows enchantments to work on trinket items when used in global entity context + * + * @author Patbox + */ +@Mixin(EnchantmentHelper.class) +public abstract class EnchantmentHelperMixin { + + @Inject(at = @At("TAIL"), method = "forEachEnchantment(Lnet/minecraft/entity/LivingEntity;Lnet/minecraft/enchantment/EnchantmentHelper$ContextAwareConsumer;)V") + private static void forEachTrinket(LivingEntity entity, EnchantmentHelper.ContextAwareConsumer contextAwareConsumer, CallbackInfo info) { + Optional optional = TrinketsApi.getTrinketComponent(entity); + if (optional.isPresent()) { + TrinketComponent comp = optional.get(); + comp.forEach((ref, stack) -> { + if (!stack.isEmpty()) { + ItemEnchantmentsComponent enchantments = stack.get(DataComponentTypes.ENCHANTMENTS); + if (enchantments != null && !enchantments.isEmpty()) { + EnchantmentEffectContext context = new EnchantmentEffectContext(stack, null, entity, (item) -> { + TrinketsApi.onTrinketBroken(stack, ref, entity); + }); + + for (Object2IntMap.Entry> entry : enchantments.getEnchantmentEntries()) { + RegistryEntry registryEntry = entry.getKey(); + List slots = registryEntry.value().definition().slots(); + Set trinketSlots = ((TrinketSlotTarget) (Object) registryEntry.value().definition()).trinkets$slots(); + + if (slots.contains(AttributeModifierSlot.ANY) || slots.contains(AttributeModifierSlot.ARMOR) || trinketSlots.contains(ref.inventory().getSlotType().getId())) { + contextAwareConsumer.accept(registryEntry, entry.getIntValue(),context); + } + } + } + } + }); + } + } + + @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/EquipmentSlot;values()[Lnet/minecraft/entity/EquipmentSlot;"), method = "chooseEquipmentWith") + private static void addTrinketsAsChoices(ComponentType componentType, LivingEntity entity, Predicate stackPredicate, CallbackInfoReturnable> info, @Local List list) { + Optional optional = TrinketsApi.getTrinketComponent(entity); + if (optional.isPresent()) { + TrinketComponent comp = optional.get(); + comp.forEach((ref, stack) -> { + if (stackPredicate.test(stack)) { + ItemEnchantmentsComponent enchantments = stack.getOrDefault(DataComponentTypes.ENCHANTMENTS, ItemEnchantmentsComponent.DEFAULT); + for(Object2IntMap.Entry> entry : enchantments.getEnchantmentEntries()) { + RegistryEntry registryEntry = entry.getKey(); + List slots = registryEntry.value().definition().slots(); + Set trinketSlots = ((TrinketSlotTarget) (Object) registryEntry.value().definition()).trinkets$slots(); + + if (registryEntry.value().effects().contains(componentType) + && (slots.contains(AttributeModifierSlot.ANY) || slots.contains(AttributeModifierSlot.ARMOR) + || trinketSlots.contains(ref.inventory().getSlotType().getId())) + ) { + list.add(new EnchantmentEffectContext(stack, null, entity, (item) -> { + TrinketsApi.onTrinketBroken(stack, ref, entity); + })); + } + } + } + }); + } + } +} diff --git a/src/main/java/dev/emi/trinkets/mixin/ExperienceOrbEntityMixin.java b/src/main/java/dev/emi/trinkets/mixin/ExperienceOrbEntityMixin.java deleted file mode 100644 index 8f396df6..00000000 --- a/src/main/java/dev/emi/trinkets/mixin/ExperienceOrbEntityMixin.java +++ /dev/null @@ -1,82 +0,0 @@ -package dev.emi.trinkets.mixin; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -import com.google.common.collect.Maps; - -import java.util.Optional; - -import java.util.function.Predicate; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.ModifyVariable; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import dev.emi.trinkets.api.SlotReference; -import dev.emi.trinkets.api.TrinketComponent; -import dev.emi.trinkets.api.TrinketsApi; -import net.minecraft.enchantment.EnchantmentHelper; -import net.minecraft.enchantment.Enchantments; -import net.minecraft.entity.EquipmentSlot; -import net.minecraft.entity.ExperienceOrbEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.util.Pair; - -/** - * Applies mending to trinkets (fairly) - * - * @author Emi - */ -@Mixin(ExperienceOrbEntity.class) -public class ExperienceOrbEntityMixin { - @Unique - private PlayerEntity mendingPlayer; - - @Inject(at = @At("HEAD"), method = "repairPlayerGears") - private void repairPlayerGears(PlayerEntity player, int amount, CallbackInfoReturnable info) { - mendingPlayer = player; - } - - @ModifyVariable(at = @At(value = "INVOKE_ASSIGN", target = "net/minecraft/enchantment/EnchantmentHelper.chooseEquipmentWith(Lnet/minecraft/enchantment/Enchantment;Lnet/minecraft/entity/LivingEntity;Ljava/util/function/Predicate;)Ljava/util/Map$Entry;"), - method = "repairPlayerGears") - private Entry modifyEntry(Entry entry) { - Optional optional = TrinketsApi.getTrinketComponent(mendingPlayer); - if (optional.isPresent()) { - TrinketComponent comp = optional.get(); - Predicate predicate = stack -> !stack.isEmpty() && stack.isDamaged() && EnchantmentHelper.getLevel(Enchantments.MENDING, stack) > 0; - List> list = comp.getEquipped(predicate); - int totalSize = list.size(); - - if (entry != null) { - Map map = Enchantments.MENDING.getEquipment(mendingPlayer); - // The map contains ALL equipped items, so we need to filter for Mending candidates specifically - ArrayList> originalList = new ArrayList<>(); - for (Map.Entry ent : map.entrySet()) { - if (predicate.test(ent.getValue())) { - originalList.add(ent); - } - } - totalSize += originalList.size(); - } - - if (totalSize == 0) { - return entry; - } - int selected = mendingPlayer.getRandom().nextInt(totalSize); - if (selected < list.size()) { - Pair pair = list.get(selected); - Map dummyMap = Maps.newHashMap(); - dummyMap.put(EquipmentSlot.MAINHAND, pair.getRight()); - entry = dummyMap.entrySet().iterator().next(); - } - } - mendingPlayer = null; - return entry; - } -} diff --git a/src/main/java/dev/emi/trinkets/mixin/HandledScreenMixin.java b/src/main/java/dev/emi/trinkets/mixin/HandledScreenMixin.java index c5b56d39..1f871ee9 100644 --- a/src/main/java/dev/emi/trinkets/mixin/HandledScreenMixin.java +++ b/src/main/java/dev/emi/trinkets/mixin/HandledScreenMixin.java @@ -29,9 +29,9 @@ @Mixin(HandledScreen.class) public abstract class HandledScreenMixin extends Screen { @Unique - private static final Identifier MORE_SLOTS = new Identifier("trinkets", "textures/gui/more_slots.png"); + private static final Identifier MORE_SLOTS = Identifier.of("trinkets", "textures/gui/more_slots.png"); @Unique - private static final Identifier BLANK_BACK = new Identifier("trinkets", "textures/gui/blank_back.png"); + private static final Identifier BLANK_BACK = Identifier.of("trinkets", "textures/gui/blank_back.png"); private HandledScreenMixin() { super(null); diff --git a/src/main/java/dev/emi/trinkets/mixin/ItemStackMixin.java b/src/main/java/dev/emi/trinkets/mixin/ItemStackMixin.java index 38db5e4c..531f47ec 100644 --- a/src/main/java/dev/emi/trinkets/mixin/ItemStackMixin.java +++ b/src/main/java/dev/emi/trinkets/mixin/ItemStackMixin.java @@ -11,7 +11,6 @@ import dev.emi.trinkets.api.Trinket; import dev.emi.trinkets.api.TrinketInventory; import dev.emi.trinkets.api.TrinketsApi; -import net.minecraft.client.item.TooltipType; import net.minecraft.component.DataComponentTypes; import net.minecraft.component.type.AttributeModifiersComponent; import net.minecraft.entity.attribute.EntityAttribute; @@ -20,6 +19,7 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.item.tooltip.TooltipType; import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.text.Text; import net.minecraft.util.Formatting; @@ -81,7 +81,7 @@ private void getTooltip(Item.TooltipContext context, PlayerEntity player, Toolti Trinket trinket = TrinketsApi.getTrinket((self).getItem()); Multimap, EntityAttributeModifier> map = - trinket.getModifiers(self, ref, player, SlotAttributes.getUuid(ref)); + trinket.getModifiers(self, ref, player, SlotAttributes.getIdentifier(ref)); if (defaultModifier == null) { defaultModifier = map; diff --git a/src/main/java/dev/emi/trinkets/mixin/LivingEntityMixin.java b/src/main/java/dev/emi/trinkets/mixin/LivingEntityMixin.java index 08938872..514fd9a7 100644 --- a/src/main/java/dev/emi/trinkets/mixin/LivingEntityMixin.java +++ b/src/main/java/dev/emi/trinkets/mixin/LivingEntityMixin.java @@ -4,7 +4,6 @@ import java.util.Map; import java.util.Optional; import java.util.Set; -import java.util.UUID; import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; @@ -18,9 +17,11 @@ import dev.emi.trinkets.api.TrinketInventory; import dev.emi.trinkets.api.TrinketsApi; import dev.emi.trinkets.payload.SyncInventoryPayload; +import net.minecraft.component.EnchantmentEffectComponentTypes; import net.minecraft.entity.attribute.EntityAttributeInstance; import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.registry.tag.ItemTags; +import net.minecraft.util.Identifier; import net.minecraft.util.Pair; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -106,7 +107,7 @@ private void dropInventory(CallbackInfo info) { if (keepInv && entity.getType() == EntityType.PLAYER) { dropRule = DropRule.KEEP; } else { - if (EnchantmentHelper.hasVanishingCurse(stack)) { + if (EnchantmentHelper.hasAnyEnchantmentsWith(stack, EnchantmentEffectComponentTypes.PREVENT_EQUIPMENT_DROP)) { dropRule = DropRule.DESTROY; } else { dropRule = DropRule.DROP; @@ -165,11 +166,11 @@ private void tick(CallbackInfo info) { World world = this.getWorld(); if (!world.isClient) { contentUpdates.put(newRef, newStackCopy); - UUID uuid = SlotAttributes.getUuid(ref); + Identifier identifier = SlotAttributes.getIdentifier(ref); if (!oldStack.isEmpty()) { Trinket trinket = TrinketsApi.getTrinket(oldStack.getItem()); - Multimap, EntityAttributeModifier> map = trinket.getModifiers(oldStack, ref, entity, uuid); + Multimap, EntityAttributeModifier> map = trinket.getModifiers(oldStack, ref, entity, identifier); Multimap slotMap = HashMultimap.create(); Set> toRemove = Sets.newHashSet(); for (RegistryEntry attr : map.keySet()) { @@ -185,7 +186,7 @@ private void tick(CallbackInfo info) { map.asMap().forEach((attribute, modifiers) -> { EntityAttributeInstance entityAttributeInstance = this.getAttributes().getCustomInstance(attribute); if (entityAttributeInstance != null) { - modifiers.forEach(modifier -> entityAttributeInstance.removeModifier(modifier.uuid())); + modifiers.forEach(modifier -> entityAttributeInstance.removeModifier(modifier.id())); } }); @@ -194,7 +195,7 @@ private void tick(CallbackInfo info) { if (!newStack.isEmpty()) { Trinket trinket = TrinketsApi.getTrinket(newStack.getItem()); - Multimap, EntityAttributeModifier> map = trinket.getModifiers(newStack, ref, entity, uuid); + Multimap, EntityAttributeModifier> map = trinket.getModifiers(newStack, ref, entity, identifier); Multimap slotMap = HashMultimap.create(); Set> toRemove = Sets.newHashSet(); for (RegistryEntry attr : map.keySet()) { @@ -210,7 +211,7 @@ private void tick(CallbackInfo info) { map.forEach((attribute, attributeModifier) -> { EntityAttributeInstance entityAttributeInstance = this.getAttributes().getCustomInstance(attribute); if (entityAttributeInstance != null) { - entityAttributeInstance.removeModifier(attributeModifier.uuid()); + entityAttributeInstance.removeModifier(attributeModifier.id()); entityAttributeInstance.addTemporaryModifier(attributeModifier); } @@ -237,7 +238,7 @@ private void tick(CallbackInfo info) { Map map = new HashMap<>(); for (TrinketInventory trinketInventory : inventoriesToSend) { - map.put(trinketInventory.getSlotType().getGroup() + "/" + trinketInventory.getSlotType().getName(), trinketInventory.getSyncTag()); + map.put(trinketInventory.getSlotType().getId(), trinketInventory.getSyncTag()); } SyncInventoryPayload packet = new SyncInventoryPayload(this.getId(), contentUpdates, map); diff --git a/src/main/java/dev/emi/trinkets/mixin/PlayerManagerMixin.java b/src/main/java/dev/emi/trinkets/mixin/PlayerManagerMixin.java index b72e6975..3ea403d0 100644 --- a/src/main/java/dev/emi/trinkets/mixin/PlayerManagerMixin.java +++ b/src/main/java/dev/emi/trinkets/mixin/PlayerManagerMixin.java @@ -39,7 +39,7 @@ private void onPlayerConnect(ClientConnection connection, ServerPlayerEntity pla Set inventoriesToSend = trinkets.getTrackingUpdates(); for (TrinketInventory trinketInventory : inventoriesToSend) { - tag.put(trinketInventory.getSlotType().getGroup() + "/" + trinketInventory.getSlotType().getName(), trinketInventory.getSyncTag()); + tag.put(trinketInventory.getSlotType().getId(), trinketInventory.getSyncTag()); } ServerPlayNetworking.send(player, new SyncInventoryPayload(player.getId(), Map.of(), tag)); inventoriesToSend.clear(); diff --git a/src/main/java/dev/emi/trinkets/mixin/datafixer/Schema1460Mixin.java b/src/main/java/dev/emi/trinkets/mixin/datafixer/Schema1460Mixin.java index 5b17332d..e1d63700 100644 --- a/src/main/java/dev/emi/trinkets/mixin/datafixer/Schema1460Mixin.java +++ b/src/main/java/dev/emi/trinkets/mixin/datafixer/Schema1460Mixin.java @@ -15,10 +15,12 @@ import java.util.Map; import java.util.function.Supplier; -/* +/** * This is main schema where Minecraft defines most post-flattening data formats. * Trinkets injects here adding support for basic datafixing in case of other mods supporting it or just general vanilla nbt * format changes. + * + * @author Patbox */ @Mixin(Schema1460.class) public class Schema1460Mixin { @@ -40,9 +42,9 @@ private void captureSchema(Schema schemax, Map> e @ModifyReturnValue(method = {"method_5260", "method_5236"}, at = @At("RETURN")) private static TypeTemplate attachTrinketFixer(TypeTemplate original) { // Add schema for trinkets to existing datafixers - return DSL.allWithRemainder(original, + return DSL.allWithRemainder( // cardinal_components might not exist, so add it as an optional field. - DSL.optionalFields("cardinal_components", + DSL.optional(DSL.field("cardinal_components", // trinkets:trinkets might not exist, so add it as an optional field. DSL.optionalFields("trinkets:trinkets", // Define it as (optional) compound list / map (Map). Keys are slot groups. @@ -54,7 +56,7 @@ private static TypeTemplate attachTrinketFixer(TypeTemplate original) { )) )) ) - ) + )), original ); } } diff --git a/src/main/resources/trinkets.accesswidener b/src/main/resources/trinkets.accesswidener index 484e4d9e..97d94af5 100644 --- a/src/main/resources/trinkets.accesswidener +++ b/src/main/resources/trinkets.accesswidener @@ -1,3 +1,4 @@ accessWidener v1 named -accessible class net/minecraft/client/gui/screen/ingame/CreativeInventoryScreen$CreativeSlot \ No newline at end of file +accessible class net/minecraft/client/gui/screen/ingame/CreativeInventoryScreen$CreativeSlot +accessible class net/minecraft/enchantment/EnchantmentHelper$ContextAwareConsumer \ No newline at end of file diff --git a/src/main/resources/trinkets.mixins.json b/src/main/resources/trinkets.mixins.json index b714326b..e6563ad3 100644 --- a/src/main/resources/trinkets.mixins.json +++ b/src/main/resources/trinkets.mixins.json @@ -5,7 +5,8 @@ "mixins": [ "accessor.ScreenHandlerAccessor", "datafixer.Schema1460Mixin", - "ExperienceOrbEntityMixin", + "EnchantmentDefinitionMixin", + "EnchantmentHelperMixin", "LivingEntityMixin", "PlayerManagerMixin", "PlayerScreenHandlerMixin", diff --git a/src/testmod/java/dev/emi/trinkets/TestTrinket.java b/src/testmod/java/dev/emi/trinkets/TestTrinket.java index caae859e..a1595419 100644 --- a/src/testmod/java/dev/emi/trinkets/TestTrinket.java +++ b/src/testmod/java/dev/emi/trinkets/TestTrinket.java @@ -27,7 +27,7 @@ public class TestTrinket extends TrinketItem implements TrinketRenderer { - private static final Identifier TEXTURE = new Identifier(TrinketsTest.MOD_ID, "textures/entity/trinket/hat.png"); + private static final Identifier TEXTURE = Identifier.of(TrinketsTest.MOD_ID, "textures/entity/trinket/hat.png"); private BipedEntityModel model; public TestTrinket(Settings settings) { @@ -42,13 +42,13 @@ public void tick(ItemStack stack, SlotReference slot, LivingEntity entity) { } @Override - public Multimap, EntityAttributeModifier> getModifiers(ItemStack stack, SlotReference slot, LivingEntity entity, UUID uuid) { - Multimap, EntityAttributeModifier> modifiers = super.getModifiers(stack, slot, entity, uuid); - EntityAttributeModifier speedModifier = new EntityAttributeModifier(uuid, "trinkets-testmod:movement_speed", + public Multimap, EntityAttributeModifier> getModifiers(ItemStack stack, SlotReference slot, LivingEntity entity, Identifier id) { + Multimap, EntityAttributeModifier> modifiers = super.getModifiers(stack, slot, entity, id); + EntityAttributeModifier speedModifier = new EntityAttributeModifier(id.withSuffixedPath("trinkets-testmod/movement_speed"), 0.4, EntityAttributeModifier.Operation.ADD_MULTIPLIED_TOTAL); modifiers.put(EntityAttributes.GENERIC_MOVEMENT_SPEED, speedModifier); - SlotAttributes.addSlotModifier(modifiers, "offhand/ring", uuid, 6, EntityAttributeModifier.Operation.ADD_VALUE); - SlotAttributes.addSlotModifier(modifiers, "hand/glove", uuid, 1, EntityAttributeModifier.Operation.ADD_VALUE); + SlotAttributes.addSlotModifier(modifiers, "offhand/ring", id.withSuffixedPath("trinkets-testmod/ring_slot"), 6, EntityAttributeModifier.Operation.ADD_VALUE); + SlotAttributes.addSlotModifier(modifiers, "hand/glove", id.withSuffixedPath("trinkets-testmod/glove_slot"), 1, EntityAttributeModifier.Operation.ADD_VALUE); return modifiers; } @@ -60,7 +60,7 @@ public void render(ItemStack stack, SlotReference slotReference, EntityModel