From 8c38e3230de54c5a838709fb908111c08f484299 Mon Sep 17 00:00:00 2001 From: cheaterpaul Date: Fri, 18 Oct 2024 21:07:43 +0200 Subject: [PATCH] re-add armor slot mixin close #214 --- .../werewolves/mixin/ArmorSlotMixin.java | 26 +++++++++++++++++++ .../resources/META-INF/accesstransformer.cfg | 3 ++- src/main/resources/werewolves.mixins.json | 1 + 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/main/java/de/teamlapen/werewolves/mixin/ArmorSlotMixin.java diff --git a/src/main/java/de/teamlapen/werewolves/mixin/ArmorSlotMixin.java b/src/main/java/de/teamlapen/werewolves/mixin/ArmorSlotMixin.java new file mode 100644 index 00000000..1495fd8b --- /dev/null +++ b/src/main/java/de/teamlapen/werewolves/mixin/ArmorSlotMixin.java @@ -0,0 +1,26 @@ +package de.teamlapen.werewolves.mixin; + +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import de.teamlapen.werewolves.api.entities.player.IWerewolfPlayer; +import de.teamlapen.werewolves.api.items.IWerewolfArmor; +import de.teamlapen.werewolves.entities.player.werewolf.WerewolfPlayer; +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.ArmorSlot; +import net.minecraft.world.item.ItemStack; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +@Mixin(ArmorSlot.class) +public class ArmorSlotMixin { + + @WrapOperation(method = "mayPlace", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;canEquip(Lnet/minecraft/world/entity/EquipmentSlot;Lnet/minecraft/world/entity/LivingEntity;)Z")) + private boolean test(ItemStack instance, EquipmentSlot equipmentSlot, LivingEntity entity, Operation original) { + if (entity instanceof Player player && !(instance.getItem() instanceof IWerewolfArmor) && !WerewolfPlayer.get(player).canWearArmor(instance)) { + return false; + } + return original.call(instance, equipmentSlot, entity); + } +} diff --git a/src/main/resources/META-INF/accesstransformer.cfg b/src/main/resources/META-INF/accesstransformer.cfg index 23bad15c..9e3124c2 100644 --- a/src/main/resources/META-INF/accesstransformer.cfg +++ b/src/main/resources/META-INF/accesstransformer.cfg @@ -10,4 +10,5 @@ public net.minecraft.client.renderer.entity.layers.PlayerItemInHandLayer m_17451 public net.minecraft.client.renderer.entity.layers.PlayerItemInHandLayer f_234864_ # itemInHandRenderer public net.minecraft.world.level.biome.MultiNoiseBiomeSourceParameterList$Preset$SourceProvider -protected net.minecraft.data.recipes.RecipeProvider m_236371_(Ljava/util/function/Consumer;Lnet/minecraft/world/level/ItemLike;Lnet/minecraft/world/level/ItemLike;)V # chestBoat \ No newline at end of file +protected net.minecraft.data.recipes.RecipeProvider m_236371_(Ljava/util/function/Consumer;Lnet/minecraft/world/level/ItemLike;Lnet/minecraft/world/level/ItemLike;)V # chestBoat +public net.minecraft.world.inventory.ArmorSlot \ No newline at end of file diff --git a/src/main/resources/werewolves.mixins.json b/src/main/resources/werewolves.mixins.json index ba3e9bae..8eddb5c6 100644 --- a/src/main/resources/werewolves.mixins.json +++ b/src/main/resources/werewolves.mixins.json @@ -4,6 +4,7 @@ "compatibilityLevel": "JAVA_21", "plugin": "de.teamlapen.werewolves.WerewolvesMixinConfigPlugin", "mixins": [ + "ArmorSlotMixin", "BlockFamiliesAccessor", "FoodStatsAccessor", "GoalSelectorAccessor",