mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-17 02:55:26 +00:00
IPlayer:
-Removed vector functions, moved to IEntityLivingBase IEntityLivingBase: -Added vector functions from IPlayer
This commit is contained in:
1 parent
c554251165
commit
5fdef1cd0c
4 files changed
+91
-54
No files matched your search
@@ -6,6 +6,11 @@ import net.minecraft.potion.Potion;
|
||||
import net.minecraft.potion.PotionEffect;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.util.EntityDamageSource;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import noppes.npcs.scripted.ScriptBlockPos;
|
||||
import noppes.npcs.scripted.interfaces.IBlock;
|
||||
import noppes.npcs.scripted.interfaces.IPos;
|
||||
import noppes.npcs.scripted.interfaces.entity.IEntity;
|
||||
import noppes.npcs.scripted.interfaces.item.IItemStack;
|
||||
import noppes.npcs.scripted.constants.EntityType;
|
||||
@@ -13,6 +18,9 @@ import noppes.npcs.scripted.interfaces.entity.IEntityLivingBase;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.scripted.ScriptDamageSource;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
public class ScriptLivingBase<T extends EntityLivingBase> extends ScriptEntity<T> implements IEntityLivingBase {
|
||||
protected T entity;
|
||||
|
||||
@@ -97,6 +105,55 @@ public class ScriptLivingBase<T extends EntityLivingBase> extends ScriptEntity<T
|
||||
public boolean canSeeEntity(IEntity entity){
|
||||
return this.entity.canEntityBeSeen(entity.getMCEntity());
|
||||
}
|
||||
|
||||
public IPos getLookVector() {
|
||||
Vec3 lookVec = entity.getLookVec();
|
||||
return new ScriptBlockPos(new BlockPos(lookVec.xCoord,lookVec.yCoord,lookVec.zCoord));
|
||||
}
|
||||
|
||||
public IBlock getLookingAtBlock(int maxDistance) {
|
||||
Vec3 lookVec = entity.getLookVec();
|
||||
return getWorld().rayCastBlock(
|
||||
new double[] {entity.posX, entity.posY+entity.getEyeHeight(), entity.posZ},
|
||||
new double[] {lookVec.xCoord, lookVec.yCoord, lookVec.zCoord},
|
||||
maxDistance);
|
||||
}
|
||||
|
||||
public IPos getLookingAtPos(int maxDistance) {
|
||||
Vec3 lookVec = entity.getLookVec();
|
||||
return getWorld().rayCastPos(
|
||||
new double[] {entity.posX, entity.posY+entity.getEyeHeight(), entity.posZ},
|
||||
new double[] {lookVec.xCoord, lookVec.yCoord, lookVec.zCoord},
|
||||
maxDistance);
|
||||
}
|
||||
|
||||
public IEntity[] getLookingAtEntities(int maxDistance, int range) {
|
||||
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));
|
||||
|
||||
Collections.addAll(entities, getWorld().getEntitiesNear(pos,range));
|
||||
|
||||
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]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Expert use only
|
||||
@@ -116,10 +173,6 @@ public class ScriptLivingBase<T extends EntityLivingBase> extends ScriptEntity<T
|
||||
public void swingHand(){
|
||||
entity.swingItem();
|
||||
}
|
||||
|
||||
public String getLookVec(){
|
||||
return entity.getLookVec().toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Works the same as the <a href="http://minecraft.gamepedia.com/Commands#effect">/effect command</a>
|
||||
|
||||
@@ -546,50 +546,6 @@ public class ScriptPlayer<T extends EntityPlayerMP> extends ScriptLivingBase<T>
|
||||
return new ScriptPixelmonPlayerData(player);
|
||||
}
|
||||
|
||||
public IBlock getLookingAtBlock(int maxDistance) {
|
||||
Vec3 lookVec = player.getLookVec();
|
||||
return getWorld().rayCastBlock(
|
||||
new double[] {player.posX, player.posY+player.getEyeHeight(), player.posZ},
|
||||
new double[] {lookVec.xCoord, lookVec.yCoord, lookVec.zCoord},
|
||||
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 IEntity[] getLookingAtEntities(int maxDistance, int range) {
|
||||
Vec3 lookVec = player.getLookVec();
|
||||
double[] startPos = new double[] {player.posX, player.posY+player.getEyeHeight(), player.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));
|
||||
|
||||
Collections.addAll(entities, getWorld().getEntitiesNear(pos,range));
|
||||
|
||||
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 ITimers getTimers() {
|
||||
return PlayerDataController.instance.getPlayerData(player).timers;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package noppes.npcs.scripted.interfaces.entity;
|
||||
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import noppes.npcs.scripted.interfaces.IBlock;
|
||||
import noppes.npcs.scripted.interfaces.IPos;
|
||||
import noppes.npcs.scripted.interfaces.item.IItemStack;
|
||||
import noppes.npcs.scripted.ScriptDamageSource;
|
||||
|
||||
@@ -50,6 +52,38 @@ public interface IEntityLivingBase<T extends EntityLivingBase> extends IEntity<T
|
||||
*/
|
||||
boolean canSeeEntity(IEntity entity);
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Returns the look vector of this entity as an IPos object.
|
||||
*/
|
||||
IPos getLookVector();
|
||||
|
||||
/**
|
||||
*
|
||||
* @param maxDistance The max distance to perform checks before stopping
|
||||
* @return The first block found by following along the entity's look vector.
|
||||
*/
|
||||
IBlock getLookingAtBlock(int maxDistance);
|
||||
|
||||
/**
|
||||
* Returns an IPos object corresponding to the final obstructed point following along the
|
||||
* entity's look vector. If no obstructions are found (entity is looking in a straight path of
|
||||
* air with no blocks in the way), the final position is returned.
|
||||
*
|
||||
* @param maxDistance The max distance to perform checks before stopping
|
||||
* @return The position the entity is looking at.
|
||||
*/
|
||||
IPos getLookingAtPos(int maxDistance);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param maxDistance The max distance to perform checks before stopping
|
||||
* @param range The radius to check for surrounding entities at every point on the vector
|
||||
* @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);
|
||||
|
||||
/**
|
||||
* Expert use only
|
||||
* @return Returns the minecraft entity object
|
||||
|
||||
@@ -226,12 +226,6 @@ public interface IPlayer<T extends EntityPlayerMP> extends IEntityLivingBase<T>
|
||||
*/
|
||||
ScriptPixelmonPlayerData getPixelmonData();
|
||||
|
||||
IBlock getLookingAtBlock(int maxDistance);
|
||||
|
||||
IPos getLookingAtPos(int maxDistance);
|
||||
|
||||
IEntity[] getLookingAtEntities(int maxDistance, int range);
|
||||
|
||||
ITimers getTimers();
|
||||
|
||||
void updatePlayerInventory();
|
||||
|
||||
Reference in new issue
Block a user