Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Luis C.M committed 2024-03-19 22:13:38 -05:00
commit 16b93c4fcd
3 files changed
+5 -146

No files matched your search

@@ -1,139 +0,0 @@
package noppes.npcs.ai;
import net.minecraft.entity.EntityCreature;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.ai.EntityAIBase;
import net.minecraft.pathfinding.PathEntity;
import net.minecraft.pathfinding.PathPoint;
import net.minecraft.util.MathHelper;
import net.minecraft.util.Vec3;
import noppes.npcs.constants.AiMutex;
public class EntityAITwistTarget extends EntityAIBase
{
private EntityCreature theEntity;
private EntityLivingBase targetEntity;
private double movePosX;
private double movePosY;
private double movePosZ;
private int entityPosX;
private int entityPosY;
private int entityPosZ;
private double speed;
private float tacticalRange;
private boolean strafeLeft; // Flag to alternate between left and right strafes
private int strafeTimer; // Timer to control the strafing frequency
public EntityAITwistTarget(EntityCreature par1EntityCreature, double par2, float par4)
{
this.theEntity = par1EntityCreature;
this.speed = par2;
this.tacticalRange = par4;
this.strafeLeft = true; // Start with strafing to the left
this.strafeTimer = 0;
this.setMutexBits(AiMutex.PASSIVE + AiMutex.LOOK);
}
/**
* Returns whether the EntityAIBase should begin execution.
*/
public boolean shouldExecute()
{
this.targetEntity = this.theEntity.getAttackTarget();
if (this.targetEntity == null)
{
return false;
}
else if (this.targetEntity.getDistanceSqToEntity(this.theEntity) < (double)(this.tacticalRange * this.tacticalRange))
{
return false;
}
else
{
PathEntity pathentity = this.theEntity.getNavigator().getPathToEntityLiving(targetEntity);
if (pathentity != null)
{
if (pathentity.getCurrentPathLength() >= this.tacticalRange)
{
PathPoint pathpoint = pathentity.getPathPointFromIndex(MathHelper.floor_double(this.tacticalRange / 2.0D));
this.entityPosX = pathpoint.xCoord;
this.entityPosY = pathpoint.yCoord;
this.entityPosZ = pathpoint.zCoord;
// Enhanced movement logic with delay
Vec3 enhancedMovement = calculateEnhancedMovement(this.theEntity, this.targetEntity, this.tacticalRange);
if (this.targetEntity.getDistanceSq(enhancedMovement.xCoord, enhancedMovement.yCoord, enhancedMovement.zCoord) < this.targetEntity.getDistanceSq(entityPosX, entityPosY, entityPosZ)) {
this.movePosX = enhancedMovement.xCoord;
this.movePosY = enhancedMovement.yCoord;
this.movePosZ = enhancedMovement.zCoord;
return true;
}
}
}
}
return false;
}
/**
* Returns whether an in-progress EntityAIBase should continue executing
*/
public boolean continueExecuting()
{
return !this.theEntity.getNavigator().noPath() && this.targetEntity.isEntityAlive() && this.targetEntity.getDistanceSqToEntity(this.theEntity) > (double)(this.tacticalRange * this.tacticalRange);
}
/**
* Execute a one shot task or start executing a continuous task
*/
public void startExecuting()
{
this.theEntity.getNavigator().tryMoveToXYZ(this.movePosX, this.movePosY, this.movePosZ, this.speed);
}
/**
* Updates the task
*/
public void updateTask()
{
this.theEntity.getLookHelper().setLookPositionWithEntity(targetEntity, 30.0F, 30.0F);
}
/**
* Calculate enhanced movement logic with delay
*/
private Vec3 calculateEnhancedMovement(EntityCreature entity, EntityLivingBase target, float tacticalRange)
{
// Increment the strafe timer
this.strafeTimer++;
// Check if it's time to change strafe direction
if (this.strafeTimer >= 20) // Adjust the number to control the delay between strafes
{
// Reset the timer and toggle strafe direction
this.strafeTimer = 0;
this.strafeLeft = !this.strafeLeft;
}
double deltaX = target.posX - entity.posX;
double deltaZ = target.posZ - entity.posZ;
// Calculate the perpendicular direction to the target
double perpendicularX = -deltaZ;
double perpendicularZ = deltaX;
// Determine whether to strafe left or right
if (strafeLeft)
{
// Strafe to the left
return Vec3.createVectorHelper(entity.posX + perpendicularX, entity.posY, entity.posZ + perpendicularZ);
}
else
{
// Strafe to the right
return Vec3.createVectorHelper(entity.posX - perpendicularX, entity.posY, entity.posZ - perpendicularZ);
}
}
}
@@ -9,9 +9,8 @@ public enum EnumNavType {
HitNRun("aitactics.hitandrun"),
Ambush("aitactics.ambush"),
Stalk("aitactics.stalk"),
None("gui.none"),
Twist("aitactics.twist");
None("gui.none");
String name;
EnumNavType(String name){
this.name = name;
@@ -20,7 +19,7 @@ public enum EnumNavType {
ArrayList<String> list = new ArrayList<String>();
for(EnumNavType e : values())
list.add(e.name);
return list.toArray(new String[list.size()]);
}
}
@@ -711,11 +711,11 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
}
this.taskCount = 1;
this.addRegularEntries();
this.doorInteractType();
this.seekShelter();
this.setResponse();
this.setMoveType();
this.addRegularEntries();
}
private void removeTask(EntityAIBase task){
@@ -753,7 +753,6 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
case HitNRun : this.tasks.addTask(this.taskCount++, aiResponse = new EntityAIAvoidTarget(this)); break;
case Ambush : this.tasks.addTask(this.taskCount++, aiResponse = new EntityAIAmbushTarget(this, 1.2D, this.ai.tacticalRadius, false)); break;
case Stalk : this.tasks.addTask(this.taskCount++, aiResponse = new EntityAIStalkTarget(this, this.ai.tacticalRadius)); break;
case Twist: this.tasks.addTask(this.taskCount++, aiResponse = new EntityAITwistTarget(this, 1.3D, this.ai.tacticalRadius)); break;
default :
}
}
@@ -766,7 +765,7 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
case HitNRun : this.tasks.addTask(this.taskCount++, aiResponse = new EntityAIAvoidTarget(this)); break;
case Ambush : this.tasks.addTask(this.taskCount++, aiResponse = new EntityAIAmbushTarget(this, 1.2D, this.ai.tacticalRadius, false)); break;
case Stalk : this.tasks.addTask(this.taskCount++, aiResponse = new EntityAIStalkTarget(this, this.ai.tacticalRadius)); break;
default :
default :
}
}
this.tasks.addTask(this.taskCount, aiAttackTarget = new EntityAIAttackTarget(this));