mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-23 13:37:58 +01:00
Polearms can no longer accept the sweeping enchant. Closes #408
This commit is contained in:
parent
c7c8e0971b
commit
17b014939a
5 changed files with 48 additions and 1 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
"MixinChunkBlockLightProvider",
|
||||
"MutableBlockLightStorage",
|
||||
"MixinDamageSource",
|
||||
"MixinEnchantment",
|
||||
"MixinEnchantmentHelper",
|
||||
"MixinFallLocation",
|
||||
"MixinEntity",
|
||||
|
|
Loading…
Reference in a new issue