2
0
Fork 0
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
4.7 KiB
Java

package com.zivilon.cinder_loe.mixins;
import com.zivilon.cinder_loe.entity.Renegade;
import com.zivilon.cinder_loe.potion.LoEPotions;
import com.zivilon.cinder_loe.util.IEntityLivingBase;
import lotr.common.LOTRLevelData;
import lotr.common.LOTRMod;
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 net.minecraft.command.IEntitySelector;
import net.minecraft.entity.Entity;
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.world.World;
import org.spongepowered.asm.mixin.*;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.*;
import java.util.UUID;
import java.util.Collections;
import java.util.List;
@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;
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
targetEntity = null;
targetSorter = null;
targetSelector = null;
targetChance = 0;
}
@Overwrite(remap = true)
public boolean shouldExecute() {
EntityCreature self = taskOwner;
if (!(self instanceof IEntityLivingBase)) return original_should_execute();
UUID leader_id = ((IEntityLivingBase) self).get_warband_uuid();
if (leader_id == null) return original_should_execute();
Entity leader = find_entity_by_uuid(self.worldObj, leader_id);
if (leader == null) return original_should_execute();
double distance_squared = self.getDistanceSqToEntity(leader);
if (distance_squared > 576.0D) {
self.setAttackTarget(null);
self.getNavigator().tryMoveToEntityLiving(leader, 1.3D);
return false;
}
return original_should_execute();
}
public boolean original_should_execute() {
if (this.targetChance > 0 && this.taskOwner.getRNG().nextInt(this.targetChance) != 0)
return false;
if (this.taskOwner instanceof LOTREntityNPC) {
LOTREntityNPC npc = (LOTREntityNPC)this.taskOwner;
if (npc.hiredNPCInfo.isActive && npc.hiredNPCInfo.isHalted())
return false;
if (npc.isChild())
return false;
}
if (this.taskOwner instanceof LOTREntityNPCRideable) {
LOTREntityNPCRideable rideable = (LOTREntityNPCRideable)this.taskOwner;
if (rideable.isNPCTamed() || rideable.riddenByEntity instanceof EntityPlayer)
return false;
}
double range = getTargetDistance();
double rangeY = Math.min(range, 8.0D);
List<?> entities = this.taskOwner.worldObj.selectEntitiesWithinAABB(this.targetClass, this.taskOwner.boundingBox.expand(range, rangeY, range), this.targetSelector);
List<? extends Entity> entity_list = (List<? extends Entity>)entities;
Collections.sort(entity_list, this.targetSorter);
if (entities.isEmpty())
return false;
this.targetEntity = (EntityLivingBase)entities.get(0);
return true;
}
private Entity find_entity_by_uuid(World world, UUID uuid) {
for (Object obj : world.loadedEntityList) {
if (obj instanceof Entity && uuid.equals(((Entity) obj).getUniqueID())) {
return (Entity)obj;
}
}
return null;
}
/**
* @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
return (alignment < 0.0F || corrupting);
}
}