mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-16 19:55:06 +00:00
world.rayCastBlock uses double[] for parameters
This commit is contained in:
1 parent
77ee403720
commit
3d02ce3ce0
3 files changed
+12
-10
No files matched your search
@@ -144,17 +144,18 @@ public class ScriptWorld implements IWorld {
|
||||
world.setBlock(x, y, z, Blocks.air);
|
||||
}
|
||||
|
||||
public IBlock rayCastBlock(Vec3 pos, Vec3 look, int maxDistance) {
|
||||
Vec3 currentPos = pos; int rep = 0;
|
||||
public IBlock rayCastBlock(double[] pos, double[] look, int maxDistance) {
|
||||
if (pos.length != 3 || look.length != 3) return null;
|
||||
Vec3 currentPos = Vec3.createVectorHelper(pos[0], pos[1], pos[2]); int rep = 0;
|
||||
while (rep++ < maxDistance + 10) {
|
||||
currentPos = currentPos.addVector(look.xCoord, look.yCoord, look.zCoord);
|
||||
currentPos = currentPos.addVector(look[0], look[1], look[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-pos.xCoord,2)
|
||||
+Math.pow(currentPos.yCoord-pos.yCoord,2)
|
||||
+Math.pow(currentPos.zCoord-pos.zCoord,2)
|
||||
Math.pow(currentPos.xCoord-pos[0],2)
|
||||
+Math.pow(currentPos.yCoord-pos[1],2)
|
||||
+Math.pow(currentPos.zCoord-pos[2],2)
|
||||
, 0.5);
|
||||
//System.out.println("current distance check: "+distance+" on rep "+rep);
|
||||
if (distance > maxDistance) return null;
|
||||
|
||||
@@ -479,10 +479,11 @@ public class ScriptPlayer<T extends EntityPlayerMP> extends ScriptLivingBase<T>
|
||||
}
|
||||
|
||||
public IBlock getLookingAtBlock(int maxDistance) {
|
||||
Vec3 posVec = Vec3.createVectorHelper(player.posX,
|
||||
player.posY+player.getEyeHeight(), player.posZ);
|
||||
Vec3 lookVec = player.getLookVec();
|
||||
return getWorld().rayCastBlock(posVec, lookVec, maxDistance);
|
||||
return getWorld().rayCastBlock(
|
||||
new double[] {player.posX, player.posY+player.getEyeHeight(), player.posZ},
|
||||
new double[] {lookVec.xCoord, lookVec.yCoord, lookVec.zCoord},
|
||||
maxDistance);
|
||||
}
|
||||
|
||||
public ITimers getTimers() {
|
||||
|
||||
@@ -69,7 +69,7 @@ public interface IWorld {
|
||||
*/
|
||||
public void removeBlock(int x, int y, int z);
|
||||
|
||||
public IBlock rayCastBlock(Vec3 pos, Vec3 look, int maxDistance);
|
||||
public IBlock rayCastBlock(double[] pos, double[] look, int maxDistance);
|
||||
|
||||
public IPos getNearestAir(IPos pos, int maxHeight);
|
||||
|
||||
|
||||
Reference in new issue
Block a user