From 88878aff0662df5625cfb3aa3986b3b066b22167 Mon Sep 17 00:00:00 2001 From: s Date: Thu, 10 Apr 2025 19:37:43 +0300 Subject: [PATCH] Added sneak and mountArmor modifiers --- ...REntityAINearestAttackableTargetBasic.java | 72 ++++++++++++++----- .../mixins/MixinLOTREntityHorse.java | 38 ++++++++++ .../mixins/MixinLOTREntityWarg.java | 26 +++++++ .../assets/cinder_loe/lang/en_US.lang | 7 +- src/main/resources/mixins.cinder_loe.json | 4 +- 5 files changed, 128 insertions(+), 19 deletions(-) create mode 100644 src/main/java/com/zivilon/cinder_loe/mixins/MixinLOTREntityHorse.java diff --git a/src/main/java/com/zivilon/cinder_loe/mixins/MixinLOTREntityAINearestAttackableTargetBasic.java b/src/main/java/com/zivilon/cinder_loe/mixins/MixinLOTREntityAINearestAttackableTargetBasic.java index a3e8f1f..d52413c 100644 --- a/src/main/java/com/zivilon/cinder_loe/mixins/MixinLOTREntityAINearestAttackableTargetBasic.java +++ b/src/main/java/com/zivilon/cinder_loe/mixins/MixinLOTREntityAINearestAttackableTargetBasic.java @@ -10,6 +10,7 @@ import lotr.common.entity.ai.LOTREntityAINearestAttackableTargetBasic; import lotr.common.entity.ai.LOTREntityAINearestAttackableTargetBasic.TargetSorter; import lotr.common.entity.npc.LOTREntityNPC; import lotr.common.entity.npc.LOTREntityNPCRideable; +import lotr.common.item.LOTRItemArmor; import net.minecraft.command.IEntitySelector; import net.minecraft.entity.Entity; @@ -17,32 +18,32 @@ import net.minecraft.entity.EntityCreature; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.ai.EntityAITarget; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; import net.minecraft.world.World; import org.spongepowered.asm.mixin.*; import org.spongepowered.asm.mixin.injection.*; -import org.spongepowered.asm.mixin.injection.callback.*; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import java.util.UUID; import java.util.Collections; import java.util.List; +import java.util.UUID; +import net.minecraft.util.ChatComponentText; +import lotr.common.enchant.LOTREnchantment; +import lotr.common.enchant.LOTREnchantmentHelper; @Mixin(LOTREntityAINearestAttackableTargetBasic.class) public abstract class MixinLOTREntityAINearestAttackableTargetBasic extends EntityAITarget { - @Shadow - private final Class targetClass; - @Shadow - private EntityLivingBase targetEntity; - @Shadow - private final TargetSorter targetSorter; - @Shadow - private final IEntitySelector targetSelector; - @Shadow - private final int targetChance; + + @Shadow private final Class targetClass; + @Shadow private EntityLivingBase targetEntity; + @Shadow private final TargetSorter targetSorter; + @Shadow private final IEntitySelector targetSelector; + @Shadow private final int targetChance; public MixinLOTREntityAINearestAttackableTargetBasic(EntityCreature p_i1669_1_, boolean p_i1669_2_) { super(p_i1669_1_, p_i1669_2_); - targetClass = null; // Should never get applied because constructors can't be overwritten + targetClass = null; targetEntity = null; targetSorter = null; targetSelector = null; @@ -106,14 +107,51 @@ public abstract class MixinLOTREntityAINearestAttackableTargetBasic extends Enti } /** - * @author Shinare - * @reason Added corrupting potion effect that makes all NPCs hostile - */ + * @author Shinare + * @reason Added corrupting potion effect that makes all NPCs hostile + */ @Overwrite(remap = false) protected boolean isPlayerSuitableAlignmentTarget(EntityPlayer entityplayer) { float alignment = LOTRLevelData.getData(entityplayer).getAlignment(LOTRMod.getNPCFaction((Entity)this.taskOwner)); if (entityplayer == null || LoEPotions.corrupting == null) return alignment < 0.0F; - boolean corrupting = entityplayer.isPotionActive(LoEPotions.corrupting); // Needs to be implemented + boolean corrupting = entityplayer.isPotionActive(LoEPotions.corrupting); return (alignment < 0.0F || corrupting); } + + @Inject(method = "isPlayerSuitableTarget", at = @At("HEAD"), cancellable = true, remap = false) +private void cinderloe$applyStealthModifier(EntityPlayer player, CallbackInfoReturnable cir) { + int stealthPieces = 0; + System.out.println("Test 1"); +((EntityPlayer)player).addChatMessage(new ChatComponentText("Tested detection")); // Only if there is a player or target instance to refer to. + +for (ItemStack armor : player.inventory.armorInventory) { + System.out.println("Checking armor piece"); + if (armor != null && armor.getItem() instanceof LOTRItemArmor && armor.stackTagCompound != null) { + System.out.println("Found armor piece, testing if it has stealth modifier"); + if (LOTREnchantmentHelper.hasEnchant(armor, LOTREnchantment.getEnchantmentByName("stealth"))) { + System.out.println("Found modifier on armor piece"); + stealthPieces++; + } + } +} + + System.out.println("Test 2"); + ((EntityPlayer)player).addChatMessage(new ChatComponentText("Tested detection1")); // Only if there is a player or target instance to refer to. + + if (stealthPieces > 0 && taskOwner != null) { + double baseDetectionRange = taskOwner.getEntityAttribute(net.minecraft.entity.SharedMonsterAttributes.followRange).getAttributeValue(); + double multiplier = 1.0 - (0.15 * stealthPieces); + double effectiveRangeSq = (baseDetectionRange * multiplier) * (baseDetectionRange * multiplier); + double distanceSq = taskOwner.getDistanceSqToEntity(player); + + System.out.println("Test 3"); +((EntityPlayer)player).addChatMessage(new ChatComponentText("Tested detection3")); // Only if there is a player or target instance to refer to. + + if (distanceSq > effectiveRangeSq) { + cir.setReturnValue(false); + } + } + System.out.println("Test 4"); +((EntityPlayer)player).addChatMessage(new ChatComponentText("Tested detection4")); // Only if there is a player or target instance to refer to. +} } diff --git a/src/main/java/com/zivilon/cinder_loe/mixins/MixinLOTREntityHorse.java b/src/main/java/com/zivilon/cinder_loe/mixins/MixinLOTREntityHorse.java new file mode 100644 index 0000000..7f5d7da --- /dev/null +++ b/src/main/java/com/zivilon/cinder_loe/mixins/MixinLOTREntityHorse.java @@ -0,0 +1,38 @@ +package com.zivilon.cinder_loe.mixins; + +import lotr.common.entity.animal.LOTREntityHorse; +import lotr.common.enchant.LOTREnchantment; +import lotr.common.enchant.LOTREnchantmentHelper; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import lotr.common.item.LOTRItemArmor; + +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; + +@Mixin(LOTREntityHorse.class) +public class MixinLOTREntityHorse { + + @Inject(method = "func_70658_aO", at = @At("RETURN"), cancellable = true, remap = false) + private void cinderloe$boostArmorFromRider(CallbackInfoReturnable cir) { + LOTREntityHorse horse = (LOTREntityHorse)(Object)this; + + if (horse.riddenByEntity instanceof EntityPlayer) { + EntityPlayer rider = (EntityPlayer) horse.riddenByEntity; + + int bonus = 0; + for (ItemStack armor : rider.inventory.armorInventory) { + if (armor != null && LOTREnchantmentHelper.hasEnchant(armor, LOTREnchantment.getEnchantmentByName("mountArmor"))) { + bonus++; + } + } + + if (bonus > 0) { + int newArmorValue = cir.getReturnValue() + bonus; + cir.setReturnValue(newArmorValue); + } + } + } +} diff --git a/src/main/java/com/zivilon/cinder_loe/mixins/MixinLOTREntityWarg.java b/src/main/java/com/zivilon/cinder_loe/mixins/MixinLOTREntityWarg.java index 895c0d1..f5e23cb 100644 --- a/src/main/java/com/zivilon/cinder_loe/mixins/MixinLOTREntityWarg.java +++ b/src/main/java/com/zivilon/cinder_loe/mixins/MixinLOTREntityWarg.java @@ -9,7 +9,16 @@ import net.minecraft.item.ItemStack; import net.minecraft.world.World; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.Shadow; +import lotr.common.entity.animal.LOTREntityHorse; +import lotr.common.enchant.LOTREnchantment; +import lotr.common.enchant.LOTREnchantmentHelper; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import lotr.common.item.LOTRItemArmor; @Mixin(LOTREntityWarg.class) @@ -73,5 +82,22 @@ public abstract class MixinLOTREntityWarg extends Entity { entityDropItem(new ItemStack(LOTRMod.wargskinRug, 1, (getWargType()).wargID), 0.0F); } } + @Inject(method = "func_70658_aO", at = @At("RETURN"), cancellable = true, remap = false) + private void cinderloe$boostArmorFromRider(CallbackInfoReturnable cir) { + if (this.riddenByEntity instanceof EntityPlayer) { + EntityPlayer rider = (EntityPlayer) this.riddenByEntity; + + int bonus = 0; + for (ItemStack armor : rider.inventory.armorInventory) { + if (armor != null && LOTREnchantmentHelper.hasEnchant(armor, LOTREnchantment.getEnchantmentByName("mountArmor"))) { + bonus++; + } + } + if (bonus > 0) { + int newArmorValue = cir.getReturnValue() + bonus; + cir.setReturnValue(newArmorValue); + } + } + } } diff --git a/src/main/resources/assets/cinder_loe/lang/en_US.lang b/src/main/resources/assets/cinder_loe/lang/en_US.lang index f51ae63..ac0897b 100644 --- a/src/main/resources/assets/cinder_loe/lang/en_US.lang +++ b/src/main/resources/assets/cinder_loe/lang/en_US.lang @@ -347,7 +347,12 @@ lotr.enchant.rangedStrong4=Forceful lotr.enchant.fireRepair=Ashen lotr.enchant.fireRepair.desc=Repairs armor durability while on fire lotr.enchant.swiftness=Windy -lotr.enchant.swiftness.desc=+5% speed per armor piece +lotr.enchant.swiftness.desc=1.05x speed speed per armor piece +lotr.enchant.sneak=Cloaked +lotr.enchant.sneak.desc=Detection range decrease for each armor piece worn +lotr.enchant.mountArmor=Heavy +lotr.enchant.mountArmor.desc=Add +1 to the mount armor for each armor piece worn + lotr.unit.Banner_Warg=Warg Rider Banner lotr.unit.Banner_Horse=Mounted Banner Bearer diff --git a/src/main/resources/mixins.cinder_loe.json b/src/main/resources/mixins.cinder_loe.json index 755791d..cb9b9ce 100644 --- a/src/main/resources/mixins.cinder_loe.json +++ b/src/main/resources/mixins.cinder_loe.json @@ -51,7 +51,9 @@ "MixinLOTREntityAIAttackOnCollide", "MixinLOTREntityNPC", "MixinFoodStats", - "MixinLOTRItemMug" + "MixinLOTRItemMug", + "MixinLOTRNPCTargetSelector", + "MixinLOTREntityHorse" ], "client": [] }