mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-16 23:25:07 +00:00
IWorld:
-Added rayTraceEntities() functions, and added an offset parameter. IEntityLivingBase: -Made getLookingAtEntities() function use IWorld's rayTraceEntities() function, and added an offset parameter.
This commit is contained in:
1 parent
e048496e4d
commit
80916de553
4 files changed
+69
-38
No files matched your search
@@ -402,6 +402,61 @@ public class ScriptWorld implements IWorld {
|
||||
return currentPos;
|
||||
}
|
||||
|
||||
public IEntity[] rayCastEntities(double[] startPos, double[] lookVector,
|
||||
int maxDistance, double offset, double range,
|
||||
boolean stopOnBlock, boolean stopOnLiquid, boolean stopOnCollision) {
|
||||
ArrayList<IEntity> entities = new ArrayList<>();
|
||||
|
||||
Vec3 currentPos = Vec3.createVectorHelper(startPos[0], startPos[1], startPos[2]); int rep = 0;
|
||||
currentPos.addVector(lookVector[0]*offset, lookVector[1]*offset, lookVector[2]*offset);
|
||||
|
||||
while (rep++ < maxDistance + 10) {
|
||||
currentPos = currentPos.addVector(lookVector[0], lookVector[1], lookVector[2]);
|
||||
IPos pos = new ScriptBlockPos(new BlockPos(currentPos.xCoord, currentPos.yCoord, currentPos.zCoord));
|
||||
IBlock block = getBlock(pos);
|
||||
|
||||
if (block != null && stopOnBlock) {
|
||||
if ((!stopOnLiquid || block.getMCBlock() instanceof BlockLiquid)
|
||||
&& (!stopOnCollision || block.canCollide()))
|
||||
return entities.toArray(new IEntity[0]);
|
||||
}
|
||||
|
||||
IEntity[] entitiesNear = getEntitiesNear(pos,range);
|
||||
for (IEntity entity : entitiesNear) {
|
||||
if (!entities.contains(entity)) {
|
||||
entities.add(entity);
|
||||
}
|
||||
}
|
||||
|
||||
double distance = Math.pow(
|
||||
Math.pow(currentPos.xCoord-startPos[0],2)
|
||||
+Math.pow(currentPos.yCoord-startPos[1],2)
|
||||
+Math.pow(currentPos.zCoord-startPos[2],2)
|
||||
, 0.5);
|
||||
if (distance > maxDistance) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return entities.toArray(new IEntity[0]);
|
||||
}
|
||||
|
||||
public IEntity[] rayCastEntities(IPos startPos, IPos lookVector,
|
||||
int maxDistance, double offset, double range,
|
||||
boolean stopOnBlock, boolean stopOnLiquid, boolean stopOnCollision) {
|
||||
return rayCastEntities(new double[] {startPos.getX(), startPos.getY(), startPos.getZ()}, lookVector.normalize(), maxDistance, offset, range, stopOnBlock, stopOnLiquid, stopOnCollision);
|
||||
}
|
||||
|
||||
public IEntity[] rayCastEntities(double[] startPos, double[] lookVector,
|
||||
int maxDistance, double offset, double range) {
|
||||
return rayCastEntities(startPos, lookVector, maxDistance, offset, range, true, false, true);
|
||||
}
|
||||
|
||||
public IEntity[] rayCastEntities(IPos startPos, IPos lookVector,
|
||||
int maxDistance, double offset, double range) {
|
||||
return rayCastEntities(new double[] {startPos.getX(), startPos.getY(), startPos.getZ()}, lookVector.normalize(), maxDistance, offset, range, true, false, true);
|
||||
}
|
||||
|
||||
public boolean canSeeSky(int x, int y, int z) {
|
||||
return world.canBlockSeeTheSky(x, y, z);
|
||||
}
|
||||
|
||||
@@ -135,48 +135,16 @@ public class ScriptLivingBase<T extends EntityLivingBase> extends ScriptEntity<T
|
||||
return getLookingAtPos(maxDistance, true, false, false);
|
||||
}
|
||||
|
||||
public IEntity[] getLookingAtEntities(int maxDistance, int range, boolean stopOnBlock, boolean stopOnLiquid, boolean stopOnCollision) {
|
||||
public IEntity[] getLookingAtEntities(int maxDistance, double offset, double range, boolean stopOnBlock, boolean stopOnLiquid, boolean stopOnCollision) {
|
||||
Vec3 lookVec = entity.getLookVec();
|
||||
double[] startPos = new double[] {entity.posX, entity.posY+entity.getEyeHeight(), entity.posZ};
|
||||
double[] lookVector = new double[] {lookVec.xCoord, lookVec.yCoord, lookVec.zCoord};
|
||||
|
||||
ArrayList<IEntity> entities = new ArrayList<>();
|
||||
|
||||
Vec3 currentPos = Vec3.createVectorHelper(startPos[0], startPos[1], startPos[2]); int rep = 0;
|
||||
|
||||
while (rep++ < maxDistance + 10) {
|
||||
currentPos = currentPos.addVector(lookVector[0], lookVector[1], lookVector[2]);
|
||||
IPos pos = new ScriptBlockPos(new BlockPos(currentPos.xCoord, currentPos.yCoord, currentPos.zCoord));
|
||||
IBlock block = getWorld().getBlock(pos);
|
||||
|
||||
if (block != null && stopOnBlock) {
|
||||
if ((!stopOnLiquid || block.getMCBlock() instanceof BlockLiquid)
|
||||
&& (!stopOnCollision || block.canCollide()))
|
||||
return entities.toArray(new IEntity[0]);
|
||||
}
|
||||
|
||||
IEntity[] entitiesNear = getWorld().getEntitiesNear(pos,range);
|
||||
for (IEntity entity : entitiesNear) {
|
||||
if (!entities.contains(entity)) {
|
||||
entities.add(entity);
|
||||
}
|
||||
}
|
||||
|
||||
double distance = Math.pow(
|
||||
Math.pow(currentPos.xCoord-startPos[0],2)
|
||||
+Math.pow(currentPos.yCoord-startPos[1],2)
|
||||
+Math.pow(currentPos.zCoord-startPos[2],2)
|
||||
, 0.5);
|
||||
if (distance > maxDistance) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return entities.toArray(new IEntity[0]);
|
||||
return getWorld().rayCastEntities(startPos,lookVector,maxDistance,offset,range,stopOnBlock,stopOnLiquid,stopOnCollision);
|
||||
}
|
||||
|
||||
public IEntity[] getLookingAtEntities(int maxDistance, int range) {
|
||||
return getLookingAtEntities(maxDistance,range,true,false,true);
|
||||
public IEntity[] getLookingAtEntities(int maxDistance, double offset, double range) {
|
||||
return getLookingAtEntities(maxDistance,offset,range,true,false,true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -193,6 +193,14 @@ public interface IWorld {
|
||||
*/
|
||||
public IPos getNearestAir(IPos startPos, int maxHeight);
|
||||
|
||||
IEntity[] rayCastEntities(double[] startPos, double[] lookVector, int maxDistance, double offset, double range, boolean stopOnBlock, boolean stopOnLiquid, boolean stopOnCollision);
|
||||
|
||||
IEntity[] rayCastEntities(IPos startPos, IPos lookVector, int maxDistance, double offset, double range, boolean stopOnBlock, boolean stopOnLiquid, boolean stopOnCollision);
|
||||
|
||||
IEntity[] rayCastEntities(double[] startPos, double[] lookVector, int maxDistance, double offset, double range);
|
||||
|
||||
IEntity[] rayCastEntities(IPos startPos, IPos lookVector, int maxDistance, double offset, double range);
|
||||
|
||||
/**
|
||||
* @param x
|
||||
* @param y
|
||||
|
||||
@@ -82,9 +82,9 @@ public interface IEntityLivingBase<T extends EntityLivingBase> extends IEntity<T
|
||||
* @return A list of entities, sorted first by closest to the entity along the look vector, then by which
|
||||
* entities are closest to the vector.
|
||||
*/
|
||||
IEntity[] getLookingAtEntities(int maxDistance, int range, boolean stopOnBlock, boolean stopOnLiquid, boolean stopOnCollision);
|
||||
IEntity[] getLookingAtEntities(int maxDistance, double offset, double range, boolean stopOnBlock, boolean stopOnLiquid, boolean stopOnCollision);
|
||||
|
||||
IEntity[] getLookingAtEntities(int maxDistance, int range);
|
||||
IEntity[] getLookingAtEntities(int maxDistance, double offset, double range);
|
||||
|
||||
/**
|
||||
* Expert use only
|
||||
|
||||
Reference in new issue
Block a user