mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-17 18:05:10 +00:00
IPlayer:
-Added getLookPos, which uses the rayCastPos function in IWorld. IWorld: -Added getEntitiesNear function with 3 double or one IPos parameter, and a range parameter for checking what entities are near a position. -Added rayCastPos, for cases where rayCastBlock returns null.
This commit is contained in:
1 parent
84958cfd02
commit
6a852d9578
4 files changed
+80
-4
No files matched your search
@@ -16,6 +16,7 @@ import net.minecraft.nbt.NBTTagString;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntitySign;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.WorldServer;
|
||||
@@ -191,6 +192,32 @@ public class ScriptWorld implements IWorld {
|
||||
return list.toArray(new IEntity[0]);
|
||||
}
|
||||
|
||||
public IEntity[] getEntitiesNear(double x, double y, double z, double range) {
|
||||
ArrayList<IEntity> list = new ArrayList<>();
|
||||
|
||||
List<Entity> entities = world.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(
|
||||
x - range, y - range, z - range,
|
||||
x + range, y + range, z + range));
|
||||
for(Entity entity : entities){
|
||||
list.add(NpcAPI.Instance().getIEntity(entity));
|
||||
}
|
||||
|
||||
return list.toArray(new IEntity[0]);
|
||||
}
|
||||
|
||||
public IEntity[] getEntitiesNear(IPos position, double range) {
|
||||
ArrayList<IEntity> list = new ArrayList<>();
|
||||
|
||||
List<Entity> entities = world.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(
|
||||
position.getX() - range, position.getY() - range, position.getZ() - range,
|
||||
position.getX() + range, position.getY() + range, position.getZ() + range));
|
||||
for(Entity entity : entities){
|
||||
list.add(NpcAPI.Instance().getIEntity(entity));
|
||||
}
|
||||
|
||||
return list.toArray(new IEntity[0]);
|
||||
}
|
||||
|
||||
public void setTileEntity(int x, int y, int z, ITileEntity tileEntity){
|
||||
world.setTileEntity(x,y,z,tileEntity.getMCTileEntity());
|
||||
}
|
||||
@@ -325,6 +352,40 @@ public class ScriptWorld implements IWorld {
|
||||
return rayCastBlock(new double[] {startPos.getX(), startPos.getY(), startPos.getZ()}, lookVector.normalize(), maxDistance);
|
||||
}
|
||||
|
||||
public IPos rayCastPos(double[] startPos, double[] lookVector, int maxDistance) {
|
||||
if (startPos.length != 3 || lookVector.length != 3) {
|
||||
return null;
|
||||
}
|
||||
|
||||
IPos pos;
|
||||
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]);
|
||||
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) {
|
||||
return pos;
|
||||
}
|
||||
|
||||
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) {
|
||||
return pos;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public IPos rayCastPos(IPos startPos, IPos lookVector, int maxDistance) {
|
||||
return rayCastPos(new double[] {startPos.getX(), startPos.getY(), startPos.getZ()}, lookVector.normalize(), maxDistance);
|
||||
}
|
||||
|
||||
public IPos getNearestAir(IPos pos, int maxHeight) {
|
||||
if (pos == null) return null;
|
||||
IPos currentPos = pos;
|
||||
|
||||
@@ -43,15 +43,12 @@ import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.scripted.ScriptPixelmonPlayerData;
|
||||
import noppes.npcs.scripted.constants.EntityType;
|
||||
import noppes.npcs.scripted.gui.ScriptGui;
|
||||
import noppes.npcs.scripted.interfaces.IParticle;
|
||||
import noppes.npcs.scripted.interfaces.*;
|
||||
import noppes.npcs.scripted.interfaces.handler.IPlayerData;
|
||||
import noppes.npcs.scripted.interfaces.handler.data.IQuest;
|
||||
import noppes.npcs.scripted.interfaces.IBlock;
|
||||
import noppes.npcs.scripted.interfaces.IContainer;
|
||||
import noppes.npcs.scripted.interfaces.gui.ICustomGui;
|
||||
import noppes.npcs.scripted.interfaces.overlay.ICustomOverlay;
|
||||
import noppes.npcs.scripted.interfaces.entity.IPlayer;
|
||||
import noppes.npcs.scripted.interfaces.ITimers;
|
||||
import noppes.npcs.scripted.interfaces.entity.IEntity;
|
||||
import noppes.npcs.scripted.interfaces.handler.IOverlayHandler;
|
||||
import noppes.npcs.scripted.interfaces.item.IItemStack;
|
||||
@@ -558,6 +555,14 @@ public class ScriptPlayer<T extends EntityPlayerMP> extends ScriptLivingBase<T>
|
||||
maxDistance);
|
||||
}
|
||||
|
||||
public IPos getLookingAtPos(int maxDistance) {
|
||||
Vec3 lookVec = player.getLookVec();
|
||||
return getWorld().rayCastPos(
|
||||
new double[] {player.posX, player.posY+player.getEyeHeight(), player.posZ},
|
||||
new double[] {lookVec.xCoord, lookVec.yCoord, lookVec.zCoord},
|
||||
maxDistance);
|
||||
}
|
||||
|
||||
public ITimers getTimers() {
|
||||
return PlayerDataController.instance.getPlayerData(player).timers;
|
||||
}
|
||||
|
||||
@@ -100,6 +100,10 @@ public interface IWorld {
|
||||
|
||||
IEntity[] getLoadedEntities();
|
||||
|
||||
IEntity[] getEntitiesNear(double x, double y, double z, double range);
|
||||
|
||||
IEntity[] getEntitiesNear(IPos position, double range);
|
||||
|
||||
/**
|
||||
* Sets the block's tile entity at the given position.
|
||||
*/
|
||||
@@ -174,6 +178,10 @@ public interface IWorld {
|
||||
*/
|
||||
public IBlock rayCastBlock(IPos startPos, IPos lookVector, int maxDistance);
|
||||
|
||||
public IPos rayCastPos(double[] startPos, double[] lookVector, int maxDistance);
|
||||
|
||||
public IPos rayCastPos(IPos startPos, IPos lookVector, int maxDistance);
|
||||
|
||||
/**
|
||||
* @param startPos
|
||||
* @param maxHeight
|
||||
|
||||
@@ -228,6 +228,8 @@ public interface IPlayer<T extends EntityPlayerMP> extends IEntityLivingBase<T>
|
||||
|
||||
IBlock getLookingAtBlock(int maxDistance);
|
||||
|
||||
IPos getLookingAtPos(int maxDistance);
|
||||
|
||||
ITimers getTimers();
|
||||
|
||||
void updatePlayerInventory();
|
||||
|
||||
Reference in new issue
Block a user