Polearms can no longer accept the sweeping enchant. Closes #408

This commit is contained in:
Sollace 2024-09-24 18:35:26 +01:00
parent c7c8e0971b
commit 17b014939a
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
5 changed files with 48 additions and 1 deletions

View file

@ -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<EntityAttribute, EntityAttributeModifier> attributeModifiers;
@ -65,4 +68,9 @@ public class PolearmItem extends SwordItem {
return true;
}
@Override
public boolean isAcceptableEnchant(ItemStack stack, Enchantment enchantment) {
return enchantment != Enchantments.SWEEPING;
}
}

View file

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

View file

@ -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<Boolean> info) {
if (stack.getItem() instanceof CustomEnchantableItem item && !item.isAcceptableEnchant(stack, (Enchantment)(Object)this)) {
info.setReturnValue(false);
}
}
}

View file

@ -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<List<EnchantmentLevelEntry>> info) {
info.getReturnValue().removeIf(entry -> !entry.enchantment.isAcceptableItem(stack));
}
}

View file

@ -17,6 +17,7 @@
"MixinChunkBlockLightProvider",
"MutableBlockLightStorage",
"MixinDamageSource",
"MixinEnchantment",
"MixinEnchantmentHelper",
"MixinFallLocation",
"MixinEntity",