|
| 1 | +package io.wdsj.hybridfix.mixin.late.so_many_enchantments.enchants; |
| 2 | + |
| 3 | +import com.shultrea.rin.enchantments.base.EnchantmentBase; |
| 4 | +import com.shultrea.rin.enchantments.weapon.EnchantmentDisarmament; |
| 5 | +import com.shultrea.rin.mixin.vanilla.IEntityLivingMixin; |
| 6 | +import com.shultrea.rin.util.compat.CompatUtil; |
| 7 | +import com.shultrea.rin.util.compat.RLCombatCompat; |
| 8 | +import net.minecraft.enchantment.EnchantmentHelper; |
| 9 | +import net.minecraft.entity.EntityLiving; |
| 10 | +import net.minecraft.entity.EntityLivingBase; |
| 11 | +import net.minecraft.inventory.EntityEquipmentSlot; |
| 12 | +import net.minecraft.item.ItemStack; |
| 13 | +import net.minecraft.util.EnumHand; |
| 14 | +import net.minecraftforge.event.entity.living.LivingAttackEvent; |
| 15 | +import net.minecraftforge.event.entity.living.LivingDamageEvent; |
| 16 | +import net.minecraftforge.fml.common.eventhandler.EventPriority; |
| 17 | +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; |
| 18 | +import org.spongepowered.asm.mixin.Mixin; |
| 19 | +import org.spongepowered.asm.mixin.Unique; |
| 20 | +import org.spongepowered.asm.mixin.injection.At; |
| 21 | +import org.spongepowered.asm.mixin.injection.Inject; |
| 22 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
| 23 | + |
| 24 | +@Mixin(value = EnchantmentDisarmament.class, remap = false) |
| 25 | +public abstract class EnchantmentDisarmamentMixin extends EnchantmentBase { |
| 26 | + |
| 27 | + public EnchantmentDisarmamentMixin(String name, Rarity rarity, EntityEquipmentSlot... slots) { |
| 28 | + super(name, rarity, slots); |
| 29 | + } |
| 30 | + |
| 31 | + @Inject( |
| 32 | + method = "onLivingAttackEvent", |
| 33 | + at = @At( |
| 34 | + value = "HEAD" |
| 35 | + ), |
| 36 | + cancellable = true |
| 37 | + ) |
| 38 | + public void onLivingAttackEvent(LivingAttackEvent event, CallbackInfo ci) { |
| 39 | + ci.cancel(); |
| 40 | + } |
| 41 | + |
| 42 | + @Unique |
| 43 | + @SubscribeEvent(priority = EventPriority.HIGH) |
| 44 | + public void hybridFix$onLivingDamageEvent(LivingDamageEvent event) { |
| 45 | + if (!this.isEnabled()) return; |
| 46 | + if (!EnchantmentBase.isDamageSourceAllowed(event.getSource())) return; |
| 47 | + if (CompatUtil.isRLCombatLoaded() && !RLCombatCompat.isAttackEntityFromStrong()) return; |
| 48 | + if (event.getAmount() <= 1.0F) return; |
| 49 | + EntityLivingBase attacker = (EntityLivingBase) event.getSource().getTrueSource(); |
| 50 | + if (attacker == null) return; |
| 51 | + EntityLivingBase victim = event.getEntityLiving(); |
| 52 | + if (victim == null) return; |
| 53 | + // if (victim.world.isRemote) return; |
| 54 | + ItemStack stack = attacker.getHeldItemMainhand(); |
| 55 | + if (stack.isEmpty()) return; |
| 56 | + |
| 57 | + int level = EnchantmentHelper.getEnchantmentLevel(this, stack); |
| 58 | + if (level > 0) { |
| 59 | + if (attacker.getRNG().nextFloat() < 0.02F * (float) level) { |
| 60 | + if (!victim.getHeldItemMainhand().isEmpty()) { |
| 61 | + if (victim instanceof EntityLiving && attacker.getRNG().nextFloat() >= ((IEntityLivingMixin) victim).getInventoryHandsDropChances()[0]) |
| 62 | + return; |
| 63 | + victim.entityDropItem(victim.getHeldItemMainhand(), 0.5F); |
| 64 | + victim.setHeldItem(EnumHand.MAIN_HAND, ItemStack.EMPTY); |
| 65 | + } else if (!victim.getHeldItemOffhand().isEmpty()) { |
| 66 | + if (victim instanceof EntityLiving && attacker.getRNG().nextFloat() >= ((IEntityLivingMixin) victim).getInventoryHandsDropChances()[1]) |
| 67 | + return; |
| 68 | + victim.entityDropItem(victim.getHeldItemOffhand(), 0.5F); |
| 69 | + victim.setHeldItem(EnumHand.OFF_HAND, ItemStack.EMPTY); |
| 70 | + } |
| 71 | + } |
| 72 | + } |
| 73 | + } |
| 74 | +} |
0 commit comments