diff --git a/src/main/java/com/minelittlepony/unicopia/item/PolearmItem.java b/src/main/java/com/minelittlepony/unicopia/item/PolearmItem.java index 5dc90908..85517dc5 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/PolearmItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/PolearmItem.java @@ -7,14 +7,17 @@ import com.google.common.collect.Multimap; import com.minelittlepony.unicopia.UTags; import com.minelittlepony.unicopia.entity.Living; import com.minelittlepony.unicopia.entity.mob.UEntityAttributes; +import com.minelittlepony.unicopia.item.enchantment.CustomEnchantableItem; import net.minecraft.block.*; +import net.minecraft.enchantment.Enchantment; +import net.minecraft.enchantment.Enchantments; import net.minecraft.entity.EquipmentSlot; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.attribute.*; import net.minecraft.item.*; -public class PolearmItem extends SwordItem { +public class PolearmItem extends SwordItem implements CustomEnchantableItem { static final UUID ATTACK_RANGE_MODIFIER_ID = UUID.fromString("A7B3659C-AA74-469C-963A-09A391DCAA0F"); private final Multimap attributeModifiers; @@ -65,4 +68,9 @@ public class PolearmItem extends SwordItem { return true; } + + @Override + public boolean isAcceptableEnchant(ItemStack stack, Enchantment enchantment) { + return enchantment != Enchantments.SWEEPING; + } } diff --git a/src/main/java/com/minelittlepony/unicopia/item/enchantment/CustomEnchantableItem.java b/src/main/java/com/minelittlepony/unicopia/item/enchantment/CustomEnchantableItem.java new file mode 100644 index 00000000..5fbec700 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/item/enchantment/CustomEnchantableItem.java @@ -0,0 +1,8 @@ +package com.minelittlepony.unicopia.item.enchantment; + +import net.minecraft.enchantment.Enchantment; +import net.minecraft.item.ItemStack; + +public interface CustomEnchantableItem { + boolean isAcceptableEnchant(ItemStack stack, Enchantment enchantment); +} diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/MixinEnchantment.java b/src/main/java/com/minelittlepony/unicopia/mixin/MixinEnchantment.java new file mode 100644 index 00000000..5143711c --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/mixin/MixinEnchantment.java @@ -0,0 +1,21 @@ +package com.minelittlepony.unicopia.mixin; + +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.CallbackInfoReturnable; + +import com.minelittlepony.unicopia.item.enchantment.CustomEnchantableItem; + +import net.minecraft.enchantment.Enchantment; +import net.minecraft.item.ItemStack; + +@Mixin(Enchantment.class) +abstract class MixinEnchantment { + @Inject(method = "isAcceptableItem", at = @At("HEAD"), cancellable = true) + private void onIsAcceptableItem(ItemStack stack, CallbackInfoReturnable info) { + if (stack.getItem() instanceof CustomEnchantableItem item && !item.isAcceptableEnchant(stack, (Enchantment)(Object)this)) { + info.setReturnValue(false); + } + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/MixinEnchantmentHelper.java b/src/main/java/com/minelittlepony/unicopia/mixin/MixinEnchantmentHelper.java index 4458399c..0dd1aacf 100644 --- a/src/main/java/com/minelittlepony/unicopia/mixin/MixinEnchantmentHelper.java +++ b/src/main/java/com/minelittlepony/unicopia/mixin/MixinEnchantmentHelper.java @@ -1,5 +1,7 @@ package com.minelittlepony.unicopia.mixin; +import java.util.List; + import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -9,7 +11,9 @@ import com.minelittlepony.unicopia.entity.player.Pony; import net.minecraft.enchantment.Enchantment; import net.minecraft.enchantment.EnchantmentHelper; +import net.minecraft.enchantment.EnchantmentLevelEntry; import net.minecraft.entity.LivingEntity; +import net.minecraft.item.ItemStack; @Mixin(EnchantmentHelper.class) abstract class MixinEnchantmentHelper { @@ -23,4 +27,9 @@ abstract class MixinEnchantmentHelper { } }); } + + @Inject(method = "getPossibleEntries", at = @At("RETURN")) + private static void onGetPossibleEntries(int power, ItemStack stack, boolean treasureAllowed, CallbackInfoReturnable> info) { + info.getReturnValue().removeIf(entry -> !entry.enchantment.isAcceptableItem(stack)); + } } diff --git a/src/main/resources/unicopia.mixin.json b/src/main/resources/unicopia.mixin.json index 17bd2121..be3b67d5 100644 --- a/src/main/resources/unicopia.mixin.json +++ b/src/main/resources/unicopia.mixin.json @@ -17,6 +17,7 @@ "MixinChunkBlockLightProvider", "MutableBlockLightStorage", "MixinDamageSource", + "MixinEnchantment", "MixinEnchantmentHelper", "MixinFallLocation", "MixinEntity",