mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-16 16:34:46 +00:00
IEntityLivingBase:
-Added stopOnBlock, stopOnLiquid, and stopOnCollision options for getLookingAtEntities() IWorld: -Added stopOnBlock, stopOnLiquid, and stopOnCollision options for rayCastBlock & rayCastPos
This commit is contained in:
1 parent
4e5ed2d758
commit
d54035687c
6 files changed
+87
-64
No files matched your search
@@ -4,6 +4,7 @@ import java.util.*;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockLiquid;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.effect.EntityLightningBolt;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -315,47 +316,8 @@ public class ScriptWorld implements IWorld {
|
||||
public void removeBlock(int x, int y, int z){
|
||||
world.setBlock(x, y, z, Blocks.air);
|
||||
}
|
||||
|
||||
/**
|
||||
* starting at the start position, draw a line in the lookVector direction until a block is detected
|
||||
* @param startPos
|
||||
* @param lookVector should be a normalized direction vector
|
||||
* @param maxDistance
|
||||
* @return the first detected block but null if maxDistance is reached
|
||||
*/
|
||||
public IBlock rayCastBlock(double[] startPos, double[] lookVector, int maxDistance) {
|
||||
if (startPos.length != 3 || lookVector.length != 3) return null;
|
||||
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]);
|
||||
IBlock block = getBlock((int)currentPos.xCoord, (int)currentPos.yCoord, (int)currentPos.zCoord);
|
||||
//System.out.println("Checking block at ["+(int)currentPos.xCoord+","+(int)currentPos.yCoord+","+(int)currentPos.zCoord+"]");
|
||||
if (block == null) continue;
|
||||
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);
|
||||
//System.out.println("current distance check: "+distance+" on rep "+rep);
|
||||
if (distance > maxDistance) return null;
|
||||
return block;
|
||||
}
|
||||
//System.out.println("ScriptWorld:WARNING: Repeated a ray cast to many times");
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* starting at the start position, draw a line in the lookVector direction until a block is detected
|
||||
* @param startPos
|
||||
* @param lookVector will normalize x, y, z to get a direction vector
|
||||
* @param maxDistance
|
||||
* @return the first detected block but null if maxDistance is reached
|
||||
*/
|
||||
public IBlock rayCastBlock(IPos startPos, IPos lookVector, int maxDistance) {
|
||||
return rayCastBlock(new double[] {startPos.getX(), startPos.getY(), startPos.getZ()}, lookVector.normalize(), maxDistance);
|
||||
}
|
||||
|
||||
public IPos rayCastPos(double[] startPos, double[] lookVector, int maxDistance) {
|
||||
public IPos rayCastPos(double[] startPos, double[] lookVector, int maxDistance, boolean stopOnBlock, boolean stopOnLiquid, boolean stopOnCollision) {
|
||||
if (startPos.length != 3 || lookVector.length != 3) {
|
||||
return null;
|
||||
}
|
||||
@@ -368,7 +330,9 @@ public class ScriptWorld implements IWorld {
|
||||
pos = new ScriptBlockPos(new BlockPos(currentPos.xCoord, currentPos.yCoord, currentPos.zCoord));
|
||||
|
||||
IBlock block = getBlock((int)currentPos.xCoord, (int)currentPos.yCoord, (int)currentPos.zCoord);
|
||||
if (block != null) {
|
||||
if (block != null && stopOnBlock) {
|
||||
if ((!stopOnLiquid || block.getMCBlock() instanceof BlockLiquid)
|
||||
&& (!stopOnCollision || block.isCollidable()))
|
||||
return pos;
|
||||
}
|
||||
|
||||
@@ -385,8 +349,32 @@ public class ScriptWorld implements IWorld {
|
||||
return null;
|
||||
}
|
||||
|
||||
public IPos rayCastPos(double[] startPos, double[] lookVector, int maxDistance) {
|
||||
return rayCastPos(startPos,lookVector,maxDistance,true, false, false);
|
||||
}
|
||||
|
||||
public IPos rayCastPos(IPos startPos, IPos lookVector, int maxDistance, boolean stopOnBlock, boolean stopOnLiquid, boolean stopOnCollision) {
|
||||
return rayCastPos(new double[] {startPos.getX(), startPos.getY(), startPos.getZ()}, lookVector.normalize(), maxDistance, stopOnBlock, stopOnLiquid, stopOnCollision);
|
||||
}
|
||||
|
||||
public IPos rayCastPos(IPos startPos, IPos lookVector, int maxDistance) {
|
||||
return rayCastPos(new double[] {startPos.getX(), startPos.getY(), startPos.getZ()}, lookVector.normalize(), maxDistance);
|
||||
return rayCastPos(new double[] {startPos.getX(), startPos.getY(), startPos.getZ()}, lookVector.normalize(), maxDistance, true, false, false);
|
||||
}
|
||||
|
||||
public IBlock rayCastBlock(double[] startPos, double[] lookVector, int maxDistance, boolean stopOnBlock, boolean stopOnLiquid, boolean stopOnCollision) {
|
||||
return getBlock(rayCastPos(startPos,lookVector,maxDistance,stopOnBlock,stopOnLiquid,stopOnCollision));
|
||||
}
|
||||
|
||||
public IBlock rayCastBlock(double[] startPos, double[] lookVector, int maxDistance) {
|
||||
return rayCastBlock(startPos, lookVector, maxDistance, true, false, false);
|
||||
}
|
||||
|
||||
public IBlock rayCastBlock(IPos startPos, IPos lookVector, int maxDistance, boolean stopOnBlock, boolean stopOnLiquid, boolean stopOnCollision) {
|
||||
return rayCastBlock(new double[] {startPos.getX(), startPos.getY(), startPos.getZ()}, lookVector.normalize(), maxDistance, stopOnBlock, stopOnLiquid, stopOnCollision);
|
||||
}
|
||||
|
||||
public IBlock rayCastBlock(IPos startPos, IPos lookVector, int maxDistance) {
|
||||
return rayCastBlock(new double[] {startPos.getX(), startPos.getY(), startPos.getZ()}, lookVector.normalize(), maxDistance);
|
||||
}
|
||||
|
||||
public IPos getNearestAir(IPos pos, int maxHeight) {
|
||||
|
||||
Reference in new issue
Block a user