mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 02:37:27 +00:00
world.getNearestAir returns IPos and takes IPos as parameter
This commit is contained in:
1 parent
bc85756476
commit
6698e8619c
2 files changed
+31
-16
No files matched your search
@@ -28,6 +28,7 @@ import noppes.npcs.controllers.ServerCloneController;
|
||||
import noppes.npcs.scripted.entity.ScriptEntity;
|
||||
import noppes.npcs.scripted.entity.ScriptPlayer;
|
||||
import noppes.npcs.scripted.interfaces.IBlock;
|
||||
import noppes.npcs.scripted.interfaces.IPos;
|
||||
import noppes.npcs.scripted.interfaces.IWorld;
|
||||
|
||||
public class ScriptWorld implements IWorld {
|
||||
@@ -67,6 +68,14 @@ public class ScriptWorld implements IWorld {
|
||||
return null;
|
||||
return new ScriptBlock(world, block, new BlockPos(x,y,z));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param pos
|
||||
* @return The block at the given position. Returns null if there isn't a block
|
||||
*/
|
||||
public IBlock getBlock(IPos pos){
|
||||
return getBlock(pos.getX(), pos.getY(), pos.getZ());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param x World position x
|
||||
@@ -155,35 +164,33 @@ public class ScriptWorld implements IWorld {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Vec3 getNearestAir(Vec3 pos, int maxHeight) {
|
||||
public IPos getNearestAir(IPos pos, int maxHeight) {
|
||||
if (pos == null) return null;
|
||||
Vec3 currentPos = pos;
|
||||
IPos currentPos = pos;
|
||||
IBlock block = null; int rep = 0;
|
||||
while (rep++ < maxHeight) {
|
||||
//check +x
|
||||
currentPos = currentPos.addVector(1, 0, 0);
|
||||
block = getBlock((int)currentPos.xCoord, (int)currentPos.yCoord, (int)currentPos.zCoord);
|
||||
currentPos = currentPos.add(1, 0, 0);
|
||||
block = getBlock(currentPos);
|
||||
if (block == null) break;
|
||||
//check -x
|
||||
currentPos = currentPos.addVector(-2, 0, 0);
|
||||
block = getBlock((int)currentPos.xCoord, (int)currentPos.yCoord, (int)currentPos.zCoord);
|
||||
currentPos = currentPos.add(-2, 0, 0);
|
||||
block = getBlock(currentPos);
|
||||
if (block == null) break;
|
||||
//check +z
|
||||
currentPos = currentPos.addVector(1, 0, 1);
|
||||
block = getBlock((int)currentPos.xCoord, (int)currentPos.yCoord, (int)currentPos.zCoord);
|
||||
currentPos = currentPos.add(1, 0, 1);
|
||||
block = getBlock(currentPos);
|
||||
if (block == null) break;
|
||||
//check -z
|
||||
currentPos = currentPos.addVector(0, 0, -2);
|
||||
block = getBlock((int)currentPos.xCoord, (int)currentPos.yCoord, (int)currentPos.zCoord);
|
||||
currentPos = currentPos.add(0, 0, -2);
|
||||
block = getBlock(currentPos);
|
||||
if (block == null) break;
|
||||
//check up 1
|
||||
currentPos = currentPos.addVector(0, 1, 1);
|
||||
block = getBlock((int)currentPos.xCoord, (int)currentPos.yCoord, (int)currentPos.zCoord);
|
||||
currentPos = currentPos.add(0, 1, 1);
|
||||
block = getBlock(currentPos);
|
||||
if (block == null) break;
|
||||
}
|
||||
Vec3 posInt = Vec3.createVectorHelper((int)currentPos.xCoord,
|
||||
(int)currentPos.yCoord, (int)currentPos.zCoord);
|
||||
return posInt;
|
||||
return currentPos;
|
||||
}
|
||||
|
||||
public boolean canSeeSky(int x, int y, int z) {
|
||||
|
||||
Reference in new issue
Block a user