2021-10-18 06:33:39 -05:00
|
|
|
package noppes.npcs.scripted.entity;
|
2018-09-13 12:03:28 -04:00
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
import net.minecraft.block.material.Material;
|
|
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
|
import net.minecraft.entity.EntityList;
|
|
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
|
|
|
import net.minecraft.entity.monster.EntityMob;
|
|
|
|
|
import net.minecraft.entity.passive.EntityAnimal;
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
|
import net.minecraft.nbt.NBTBase;
|
|
|
|
|
import net.minecraft.nbt.NBTBase.NBTPrimitive;
|
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2022-05-24 03:06:16 -05:00
|
|
|
import net.minecraft.nbt.NBTTagIntArray;
|
2018-09-13 12:03:28 -04:00
|
|
|
import net.minecraft.nbt.NBTTagString;
|
|
|
|
|
import net.minecraft.util.MathHelper;
|
2022-01-04 03:50:50 -06:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2021-12-13 16:47:15 -06:00
|
|
|
import net.minecraft.world.WorldServer;
|
2021-09-06 01:24:38 -05:00
|
|
|
import noppes.npcs.NoppesUtilServer;
|
2021-10-18 07:02:19 -05:00
|
|
|
import noppes.npcs.controllers.ServerCloneController;
|
2018-09-13 12:03:28 -04:00
|
|
|
import noppes.npcs.entity.EntityNPCInterface;
|
2022-07-02 06:22:43 -05:00
|
|
|
import noppes.npcs.scripted.*;
|
2018-09-13 12:03:28 -04:00
|
|
|
import noppes.npcs.scripted.constants.EntityType;
|
2022-05-27 15:54:12 -05:00
|
|
|
import noppes.npcs.scripted.interfaces.IParticle;
|
2022-06-10 17:25:58 -05:00
|
|
|
import noppes.npcs.scripted.interfaces.IWorld;
|
2022-05-11 16:43:14 -05:00
|
|
|
import noppes.npcs.scripted.interfaces.entity.IEntity;
|
2021-10-18 06:33:39 -05:00
|
|
|
import noppes.npcs.scripted.interfaces.INbt;
|
2022-01-04 03:50:50 -06:00
|
|
|
import noppes.npcs.scripted.interfaces.IPos;
|
2022-05-11 22:08:31 -05:00
|
|
|
import noppes.npcs.scripted.interfaces.item.IItemStack;
|
2018-09-13 12:03:28 -04:00
|
|
|
|
2021-10-18 06:33:39 -05:00
|
|
|
public class ScriptEntity<T extends Entity> implements IEntity {
|
2021-10-12 02:57:32 -05:00
|
|
|
protected T entity;
|
2018-09-13 12:03:28 -04:00
|
|
|
private Map<String,Object> tempData = new HashMap<String,Object>();
|
2021-09-08 13:41:57 -05:00
|
|
|
|
2021-10-12 02:57:32 -05:00
|
|
|
public ScriptEntity(T entity){
|
2018-09-13 12:03:28 -04:00
|
|
|
this.entity = entity;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-07 03:46:37 -05:00
|
|
|
@Deprecated
|
2022-07-02 06:22:43 -05:00
|
|
|
public void spawnParticle(String directory, int HEXColor, int amount, int maxAge,
|
2021-09-06 01:24:38 -05:00
|
|
|
double x, double y, double z,
|
|
|
|
|
double motionX, double motionY, double motionZ, float gravity,
|
|
|
|
|
float scale1, float scale2, float scaleRate, int scaleRateStart,
|
2022-03-02 18:18:03 -06:00
|
|
|
float alpha1, float alpha2, float alphaRate, int alphaRateStart,
|
|
|
|
|
float rotation1, float rotation2, float rotationRate, int rotationRateStart,
|
|
|
|
|
float rotationX1, float rotationX2, float rotationXRate, int rotationXRateStart,
|
|
|
|
|
float rotationY1, float rotationY2, float rotationYRate, int rotationYRateStart,
|
|
|
|
|
float rotationZ1, float rotationZ2, float rotationZRate, int rotationZRateStart
|
2021-09-06 01:24:38 -05:00
|
|
|
) {
|
2021-09-06 12:28:14 -05:00
|
|
|
int entityID = entity.getEntityId();
|
2022-07-02 06:22:43 -05:00
|
|
|
ScriptParticle particle = new ScriptParticle(directory);
|
|
|
|
|
|
|
|
|
|
particle.HEXColor = HEXColor;
|
|
|
|
|
particle.HEXColor2 = HEXColor;
|
|
|
|
|
particle.HEXColorRate = 0;
|
|
|
|
|
particle.HEXColorStart = 0;
|
|
|
|
|
|
|
|
|
|
particle.amount = amount;
|
|
|
|
|
particle.maxAge = maxAge;
|
|
|
|
|
|
|
|
|
|
particle.x = x;
|
|
|
|
|
particle.y = y;
|
|
|
|
|
particle.z = z;
|
|
|
|
|
particle.motionX = motionX;
|
|
|
|
|
particle.motionY = motionY;
|
|
|
|
|
particle.motionZ = motionZ;
|
|
|
|
|
particle.gravity = gravity;
|
|
|
|
|
|
|
|
|
|
particle.scale1 = scale1;
|
|
|
|
|
particle.scale2 = scale2;
|
|
|
|
|
particle.scaleRate = scaleRate;
|
|
|
|
|
particle.scaleRateStart = scaleRateStart;
|
|
|
|
|
|
|
|
|
|
particle.alpha1 = alpha1;
|
|
|
|
|
particle.alpha2 = alpha2;
|
|
|
|
|
particle.alphaRate = alphaRate;
|
|
|
|
|
particle.alphaRateStart = alphaRateStart;
|
|
|
|
|
|
|
|
|
|
particle.rotationX1 = rotationX1;
|
|
|
|
|
particle.rotationX2 = rotationX2;
|
|
|
|
|
particle.rotationXRate = rotationXRate;
|
|
|
|
|
particle.rotationXRateStart = rotationXRateStart;
|
|
|
|
|
|
|
|
|
|
particle.rotationY1 = rotationY1;
|
|
|
|
|
particle.rotationY2 = rotationY2;
|
|
|
|
|
particle.rotationYRate = rotationYRate;
|
|
|
|
|
particle.rotationYRateStart = rotationYRateStart;
|
|
|
|
|
|
|
|
|
|
particle.rotationZ1 = rotationZ1;
|
|
|
|
|
particle.rotationZ2 = rotationZ2;
|
|
|
|
|
particle.rotationZRate = rotationZRate;
|
|
|
|
|
particle.rotationZRateStart = rotationZRateStart;
|
|
|
|
|
|
|
|
|
|
NBTTagCompound compound = particle.writeToNBT();
|
|
|
|
|
compound.setInteger("EntityID", entityID);
|
2022-07-02 13:07:23 -05:00
|
|
|
NoppesUtilServer.spawnScriptedParticle(compound, this.getWorld().getDimensionID());
|
2021-09-06 01:24:38 -05:00
|
|
|
}
|
2022-05-07 03:46:37 -05:00
|
|
|
|
|
|
|
|
@Deprecated
|
2022-07-02 06:22:43 -05:00
|
|
|
public void spawnParticle(String directory, int HEXColor, int amount, int maxAge,
|
2022-03-16 23:15:30 -05:00
|
|
|
double x, double y, double z,
|
|
|
|
|
double motionX, double motionY, double motionZ, float gravity,
|
|
|
|
|
float scale1, float scale2, float scaleRate, int scaleRateStart,
|
|
|
|
|
float alpha1, float alpha2, float alphaRate, int alphaRateStart
|
|
|
|
|
) {
|
|
|
|
|
int entityID = entity.getEntityId();
|
2022-07-02 06:22:43 -05:00
|
|
|
ScriptParticle particle = new ScriptParticle(directory);
|
|
|
|
|
|
|
|
|
|
particle.HEXColor = HEXColor;
|
|
|
|
|
particle.HEXColor2 = HEXColor;
|
|
|
|
|
particle.HEXColorRate = 0;
|
|
|
|
|
particle.HEXColorStart = 0;
|
|
|
|
|
|
|
|
|
|
particle.amount = amount;
|
|
|
|
|
particle.maxAge = maxAge;
|
|
|
|
|
|
|
|
|
|
particle.x = x;
|
|
|
|
|
particle.y = y;
|
|
|
|
|
particle.z = z;
|
|
|
|
|
particle.motionX = motionX;
|
|
|
|
|
particle.motionY = motionY;
|
|
|
|
|
particle.motionZ = motionZ;
|
|
|
|
|
particle.gravity = gravity;
|
|
|
|
|
|
|
|
|
|
particle.scale1 = scale1;
|
|
|
|
|
particle.scale2 = scale2;
|
|
|
|
|
particle.scaleRate = scaleRate;
|
|
|
|
|
particle.scaleRateStart = scaleRateStart;
|
|
|
|
|
|
|
|
|
|
particle.alpha1 = alpha1;
|
|
|
|
|
particle.alpha2 = alpha2;
|
|
|
|
|
particle.alphaRate = alphaRate;
|
|
|
|
|
particle.alphaRateStart = alphaRateStart;
|
|
|
|
|
|
|
|
|
|
NBTTagCompound compound = particle.writeToNBT();
|
|
|
|
|
compound.setInteger("EntityID", entityID);
|
2022-07-02 13:07:23 -05:00
|
|
|
NoppesUtilServer.spawnScriptedParticle(compound, this.getWorld().getDimensionID());
|
2022-03-16 23:15:30 -05:00
|
|
|
}
|
2022-05-07 03:46:37 -05:00
|
|
|
|
|
|
|
|
@Deprecated
|
2022-07-02 06:22:43 -05:00
|
|
|
public void spawnParticle(String directory, int HEXColor, int amount, int maxAge,
|
2022-03-16 23:15:30 -05:00
|
|
|
double x, double y, double z,
|
|
|
|
|
double motionX, double motionY, double motionZ, float gravity,
|
|
|
|
|
float scale1, float scale2, float scaleRate, int scaleRateStart
|
|
|
|
|
) {
|
|
|
|
|
int entityID = entity.getEntityId();
|
2022-07-02 06:22:43 -05:00
|
|
|
ScriptParticle particle = new ScriptParticle(directory);
|
|
|
|
|
|
|
|
|
|
particle.HEXColor = HEXColor;
|
|
|
|
|
particle.HEXColor2 = HEXColor;
|
|
|
|
|
particle.HEXColorRate = 0;
|
|
|
|
|
particle.HEXColorStart = 0;
|
|
|
|
|
|
|
|
|
|
particle.amount = amount;
|
|
|
|
|
particle.maxAge = maxAge;
|
|
|
|
|
|
|
|
|
|
particle.x = x;
|
|
|
|
|
particle.y = y;
|
|
|
|
|
particle.z = z;
|
|
|
|
|
particle.motionX = motionX;
|
|
|
|
|
particle.motionY = motionY;
|
|
|
|
|
particle.motionZ = motionZ;
|
|
|
|
|
particle.gravity = gravity;
|
|
|
|
|
|
|
|
|
|
particle.scale1 = scale1;
|
|
|
|
|
particle.scale2 = scale2;
|
|
|
|
|
particle.scaleRate = scaleRate;
|
|
|
|
|
particle.scaleRateStart = scaleRateStart;
|
|
|
|
|
|
|
|
|
|
NBTTagCompound compound = particle.writeToNBT();
|
|
|
|
|
compound.setInteger("EntityID", entityID);
|
2022-07-02 13:07:23 -05:00
|
|
|
NoppesUtilServer.spawnScriptedParticle(compound, this.getWorld().getDimensionID());
|
2022-03-16 23:15:30 -05:00
|
|
|
}
|
2022-05-07 03:46:37 -05:00
|
|
|
|
|
|
|
|
@Deprecated
|
2022-07-02 06:22:43 -05:00
|
|
|
public void spawnParticle(String directory, int HEXColor, int amount, int maxAge,
|
2022-03-16 23:15:30 -05:00
|
|
|
double x, double y, double z,
|
|
|
|
|
double motionX, double motionY, double motionZ, float gravity
|
|
|
|
|
) {
|
|
|
|
|
int entityID = entity.getEntityId();
|
2022-07-02 06:22:43 -05:00
|
|
|
ScriptParticle particle = new ScriptParticle(directory);
|
|
|
|
|
|
|
|
|
|
particle.HEXColor = HEXColor;
|
|
|
|
|
particle.HEXColor2 = HEXColor;
|
|
|
|
|
particle.HEXColorRate = 0;
|
|
|
|
|
particle.HEXColorStart = 0;
|
|
|
|
|
|
|
|
|
|
particle.amount = amount;
|
|
|
|
|
particle.maxAge = maxAge;
|
|
|
|
|
|
|
|
|
|
particle.x = x;
|
|
|
|
|
particle.y = y;
|
|
|
|
|
particle.z = z;
|
|
|
|
|
particle.motionX = motionX;
|
|
|
|
|
particle.motionY = motionY;
|
|
|
|
|
particle.motionZ = motionZ;
|
|
|
|
|
particle.gravity = gravity;
|
|
|
|
|
|
|
|
|
|
NBTTagCompound compound = particle.writeToNBT();
|
|
|
|
|
compound.setInteger("EntityID", entityID);
|
2022-07-02 13:07:23 -05:00
|
|
|
NoppesUtilServer.spawnScriptedParticle(compound, this.getWorld().getDimensionID());
|
2022-03-16 23:15:30 -05:00
|
|
|
}
|
2022-05-07 03:46:37 -05:00
|
|
|
|
|
|
|
|
@Deprecated
|
2022-07-02 06:22:43 -05:00
|
|
|
public void spawnParticle(String directory, int HEXColor, int amount, int maxAge,
|
2022-03-16 23:15:30 -05:00
|
|
|
double x, double y, double z
|
|
|
|
|
) {
|
|
|
|
|
int entityID = entity.getEntityId();
|
2022-07-02 06:22:43 -05:00
|
|
|
ScriptParticle particle = new ScriptParticle(directory);
|
|
|
|
|
|
|
|
|
|
particle.HEXColor = HEXColor;
|
|
|
|
|
particle.HEXColor2 = HEXColor;
|
|
|
|
|
particle.HEXColorRate = 0;
|
|
|
|
|
particle.HEXColorStart = 0;
|
|
|
|
|
|
|
|
|
|
particle.amount = amount;
|
|
|
|
|
particle.maxAge = maxAge;
|
|
|
|
|
|
|
|
|
|
particle.x = x;
|
|
|
|
|
particle.y = y;
|
|
|
|
|
particle.z = z;
|
|
|
|
|
|
|
|
|
|
NBTTagCompound compound = particle.writeToNBT();
|
|
|
|
|
compound.setInteger("EntityID", entityID);
|
2022-07-02 13:07:23 -05:00
|
|
|
NoppesUtilServer.spawnScriptedParticle(compound, this.getWorld().getDimensionID());
|
2022-03-16 23:15:30 -05:00
|
|
|
}
|
2022-05-07 03:46:37 -05:00
|
|
|
|
|
|
|
|
@Deprecated
|
2022-07-02 06:22:43 -05:00
|
|
|
public void spawnParticle(String directory, int HEXColor, int amount, int maxAge
|
2022-03-16 23:15:30 -05:00
|
|
|
) {
|
|
|
|
|
int entityID = entity.getEntityId();
|
2022-07-02 06:22:43 -05:00
|
|
|
ScriptParticle particle = new ScriptParticle(directory);
|
|
|
|
|
|
|
|
|
|
particle.HEXColor = HEXColor;
|
|
|
|
|
particle.HEXColor2 = HEXColor;
|
|
|
|
|
particle.HEXColorRate = 0;
|
|
|
|
|
particle.HEXColorStart = 0;
|
|
|
|
|
|
|
|
|
|
particle.amount = amount;
|
|
|
|
|
particle.maxAge = maxAge;
|
|
|
|
|
|
|
|
|
|
NBTTagCompound compound = particle.writeToNBT();
|
|
|
|
|
compound.setInteger("EntityID", entityID);
|
2022-07-02 13:07:23 -05:00
|
|
|
NoppesUtilServer.spawnScriptedParticle(compound, this.getWorld().getDimensionID());
|
2022-03-16 23:15:30 -05:00
|
|
|
}
|
2022-05-11 16:31:14 -05:00
|
|
|
|
2022-05-27 15:54:12 -05:00
|
|
|
public void spawnParticle(IParticle entityParticle) { entityParticle.spawnOnEntity(this); }
|
2021-09-06 01:24:38 -05:00
|
|
|
|
2022-05-03 23:09:21 -05:00
|
|
|
public int getEntityId(){
|
|
|
|
|
return entity.getEntityId();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getUniqueID(){
|
|
|
|
|
return entity.getUniqueID().toString();
|
|
|
|
|
}
|
2021-09-06 01:24:38 -05:00
|
|
|
|
2021-09-05 23:01:25 -05:00
|
|
|
public double getYOffset() { return entity.getYOffset(); }
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return The entities width
|
|
|
|
|
*/
|
|
|
|
|
public double getWidth(){ return entity.width; }
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return The entities height
|
|
|
|
|
*/
|
|
|
|
|
public double getHeight(){ return entity.height; }
|
2018-09-13 12:03:28 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return The entities x position
|
|
|
|
|
*/
|
|
|
|
|
public double getX(){
|
|
|
|
|
return entity.posX;
|
|
|
|
|
}
|
2021-10-19 02:49:46 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
/**
|
|
|
|
|
* @param x The entities x position
|
|
|
|
|
*/
|
|
|
|
|
public void setX(double x){
|
2021-12-29 16:22:05 -06:00
|
|
|
entity.setPosition(x, entity.posY, entity.posZ);;
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|
2021-10-19 02:49:46 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
/**
|
|
|
|
|
* @return The entities y position
|
|
|
|
|
*/
|
|
|
|
|
public double getY(){
|
|
|
|
|
return entity.posY;
|
|
|
|
|
}
|
2021-10-19 02:49:46 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
/**
|
|
|
|
|
* @param y The entities y position
|
|
|
|
|
*/
|
|
|
|
|
public void setY(double y){
|
2021-12-29 16:22:05 -06:00
|
|
|
entity.setPosition(entity.posX, y, entity.posZ);
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|
2021-10-19 02:49:46 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
/**
|
|
|
|
|
* @return The entities x position
|
|
|
|
|
*/
|
|
|
|
|
public double getZ(){
|
|
|
|
|
return entity.posZ;
|
|
|
|
|
}
|
2021-10-19 02:49:46 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
/**
|
|
|
|
|
* @param z The entities x position
|
|
|
|
|
*/
|
|
|
|
|
public void setZ(double z){
|
2021-12-29 16:22:05 -06:00
|
|
|
entity.setPosition(entity.posX, entity.posY, z);;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return The entities z motion
|
|
|
|
|
*/
|
|
|
|
|
public double getMotionX(){
|
|
|
|
|
return entity.motionX;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param x The entities x motion
|
|
|
|
|
*/
|
|
|
|
|
public void setMotionX(double x){
|
|
|
|
|
entity.motionX = x;
|
|
|
|
|
entity.velocityChanged = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return The entities x motion
|
|
|
|
|
*/
|
|
|
|
|
public double getMotionY(){
|
|
|
|
|
return entity.motionY;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param y The entities y motion
|
|
|
|
|
*/
|
|
|
|
|
public void setMotionY(double y){
|
|
|
|
|
entity.motionY = y;
|
|
|
|
|
entity.velocityChanged = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return The entities y motion
|
|
|
|
|
*/
|
|
|
|
|
public double getMotionZ(){
|
|
|
|
|
return entity.motionZ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param z The entities z motion
|
|
|
|
|
*/
|
|
|
|
|
public void setMotionZ(double z){
|
|
|
|
|
entity.motionZ = z;
|
|
|
|
|
entity.velocityChanged = true;
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|
|
|
|
|
|
2022-01-31 23:59:15 -06:00
|
|
|
public void setMotion(double x, double y, double z){
|
|
|
|
|
this.setMotionX(x);
|
|
|
|
|
this.setMotionY(y);
|
|
|
|
|
this.setMotionZ(z);
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-01 02:30:50 -06:00
|
|
|
public boolean isAirborne(){
|
|
|
|
|
return entity.isAirBorne;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
/**
|
|
|
|
|
* @return The block x position
|
|
|
|
|
*/
|
|
|
|
|
public int getBlockX(){
|
|
|
|
|
return MathHelper.floor_double(entity.posX);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return The block y position
|
|
|
|
|
*/
|
|
|
|
|
public int getBlockY(){
|
|
|
|
|
return MathHelper.floor_double(entity.posY);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return The block z position
|
|
|
|
|
*/
|
|
|
|
|
public int getBlockZ(){
|
|
|
|
|
return MathHelper.floor_double(entity.posZ);
|
|
|
|
|
}
|
2021-10-19 02:49:46 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
/**
|
|
|
|
|
* @param x The x position
|
|
|
|
|
* @param y The y position
|
|
|
|
|
* @param z The z position
|
|
|
|
|
*/
|
|
|
|
|
public void setPosition(double x, double y, double z){
|
|
|
|
|
entity.setPosition(x, y, z);
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-04 03:50:50 -06:00
|
|
|
public IPos getPos() {
|
|
|
|
|
return new ScriptBlockPos(new BlockPos(entity.posX,entity.posY,entity.posZ));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setPos(IPos pos) {
|
|
|
|
|
this.entity.setPosition((double)((float)pos.getX() + 0.5F), (double)pos.getY(), (double)((float)pos.getZ() + 0.5F));
|
|
|
|
|
}
|
2021-10-19 02:49:46 -05:00
|
|
|
|
2022-05-11 16:31:14 -05:00
|
|
|
public int getDimension(){
|
|
|
|
|
return entity.dimension;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
/**
|
|
|
|
|
* @param range The search range for entities around this entity
|
|
|
|
|
* @return Array of entities within range
|
|
|
|
|
*/
|
2022-05-11 22:08:31 -05:00
|
|
|
public IEntity[] getSurroundingEntities(int range){
|
2018-09-13 12:03:28 -04:00
|
|
|
List<Entity> entities = entity.worldObj.getEntitiesWithinAABB(Entity.class, entity.boundingBox.expand(range, range, range));
|
2022-05-11 22:08:31 -05:00
|
|
|
List<IEntity> list = new ArrayList<IEntity>();
|
2018-09-13 12:03:28 -04:00
|
|
|
for(Entity living : entities){
|
|
|
|
|
if(living != entity)
|
2022-05-11 22:08:31 -05:00
|
|
|
list.add(NpcAPI.Instance().getIEntity(living));
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|
2022-05-11 22:08:31 -05:00
|
|
|
return list.toArray(new IEntity[list.size()]);
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|
2021-10-19 02:49:46 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
/**
|
|
|
|
|
* @param range The search range for entities around this entity
|
|
|
|
|
* @param type The EntityType you want to find
|
|
|
|
|
* @return Array of entities within range
|
|
|
|
|
*/
|
2022-05-11 22:08:31 -05:00
|
|
|
public IEntity[] getSurroundingEntities(int range, int type){
|
2018-09-13 12:03:28 -04:00
|
|
|
Class cls = Entity.class;
|
|
|
|
|
if(type == EntityType.LIVING)
|
|
|
|
|
cls = EntityLivingBase.class;
|
|
|
|
|
else if(type == EntityType.PLAYER)
|
|
|
|
|
cls = EntityPlayer.class;
|
|
|
|
|
else if(type == EntityType.ANIMAL)
|
|
|
|
|
cls = EntityAnimal.class;
|
|
|
|
|
else if(type == EntityType.MONSTER)
|
|
|
|
|
cls = EntityMob.class;
|
|
|
|
|
else if(type == EntityType.NPC)
|
|
|
|
|
cls = EntityNPCInterface.class;
|
2021-10-19 02:49:46 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
List<Entity> entities = entity.worldObj.getEntitiesWithinAABB(cls, entity.boundingBox.expand(range, range, range));
|
2022-05-11 22:08:31 -05:00
|
|
|
List<IEntity> list = new ArrayList<IEntity>();
|
2018-09-13 12:03:28 -04:00
|
|
|
for(Entity living : entities){
|
|
|
|
|
if(living != entity)
|
2022-05-11 22:08:31 -05:00
|
|
|
list.add(NpcAPI.Instance().getIEntity(living));
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|
2022-05-11 22:08:31 -05:00
|
|
|
return list.toArray(new IEntity[list.size()]);
|
2021-10-19 02:49:46 -05:00
|
|
|
}
|
|
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return Whether the entity is alive or not
|
|
|
|
|
*/
|
|
|
|
|
public boolean isAlive(){
|
|
|
|
|
return entity.isEntityAlive();
|
|
|
|
|
}
|
2021-10-19 02:49:46 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
/**
|
|
|
|
|
* @param key Get temp data for this key
|
|
|
|
|
* @return Returns the stored temp data
|
|
|
|
|
*/
|
|
|
|
|
public Object getTempData(String key){
|
|
|
|
|
return tempData.get(key);
|
|
|
|
|
}
|
2021-10-19 02:49:46 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
/**
|
|
|
|
|
* Tempdata gets cleared when the entity gets unloaded or the world restarts
|
|
|
|
|
* @param key The key for the data stored
|
|
|
|
|
* @param value The data stored
|
|
|
|
|
*/
|
|
|
|
|
public void setTempData(String key, Object value){
|
|
|
|
|
tempData.put(key, value);
|
|
|
|
|
}
|
2021-10-19 02:49:46 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
/**
|
|
|
|
|
* @param key The key thats going to be tested against the temp data
|
|
|
|
|
* @return Whether or not temp data containes the key
|
|
|
|
|
*/
|
|
|
|
|
public boolean hasTempData(String key){
|
|
|
|
|
return tempData.containsKey(key);
|
|
|
|
|
}
|
2021-10-19 02:49:46 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
/**
|
|
|
|
|
* @param key The key for the temp data to be removed
|
|
|
|
|
*/
|
|
|
|
|
public void removeTempData(String key){
|
|
|
|
|
tempData.remove(key);
|
|
|
|
|
}
|
2021-10-19 02:49:46 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
/**
|
|
|
|
|
* Remove all tempdata
|
|
|
|
|
*/
|
|
|
|
|
public void clearTempData(){
|
|
|
|
|
tempData.clear();
|
|
|
|
|
}
|
2021-10-19 02:49:46 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
/**
|
|
|
|
|
* @param key The key of the data to be returned
|
|
|
|
|
* @return Returns the stored data
|
|
|
|
|
*/
|
|
|
|
|
public Object getStoredData(String key){
|
|
|
|
|
NBTTagCompound compound = getStoredCompound();
|
|
|
|
|
if(!compound.hasKey(key))
|
|
|
|
|
return null;
|
|
|
|
|
NBTBase base = compound.getTag(key);
|
|
|
|
|
if(base instanceof NBTPrimitive)
|
|
|
|
|
return ((NBTPrimitive)base).func_150286_g();
|
2022-05-24 03:06:16 -05:00
|
|
|
else if (base instanceof NBTTagIntArray)
|
|
|
|
|
return ((NBTTagIntArray)base).func_150302_c();
|
2018-09-13 12:03:28 -04:00
|
|
|
return ((NBTTagString)base).func_150285_a_();
|
|
|
|
|
}
|
2021-10-19 02:49:46 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
/**
|
|
|
|
|
* Stored data persists through world restart. Unlike tempdata only Strings and Numbers can be saved
|
|
|
|
|
* @param key The key for the data stored
|
|
|
|
|
* @param value The data stored. This data can be either a Number or a String. Other data is not stored
|
|
|
|
|
*/
|
|
|
|
|
public void setStoredData(String key, Object value){
|
|
|
|
|
NBTTagCompound compound = getStoredCompound();
|
|
|
|
|
if(value instanceof Number){
|
|
|
|
|
compound.setDouble(key, ((Number) value).doubleValue());
|
|
|
|
|
}
|
|
|
|
|
else if(value instanceof String)
|
|
|
|
|
compound.setString(key, (String)value);
|
|
|
|
|
saveStoredCompound(compound);
|
|
|
|
|
}
|
2022-05-24 03:06:16 -05:00
|
|
|
|
|
|
|
|
public void setStoredData(String key, int[] array){
|
|
|
|
|
NBTTagCompound compound = getStoredCompound();
|
|
|
|
|
compound.setIntArray(key, array);
|
|
|
|
|
saveStoredCompound(compound);
|
|
|
|
|
}
|
2021-10-19 02:49:46 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
/**
|
|
|
|
|
* @param key The key of the data to be checked
|
|
|
|
|
* @return Returns whether or not the stored data contains the key
|
|
|
|
|
*/
|
|
|
|
|
public boolean hasStoredData(String key){
|
|
|
|
|
return getStoredCompound().hasKey(key);
|
|
|
|
|
}
|
2021-10-19 02:49:46 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
/**
|
|
|
|
|
* @param key The key of the data to be removed
|
|
|
|
|
*/
|
|
|
|
|
public void removeStoredData(String key){
|
|
|
|
|
NBTTagCompound compound = getStoredCompound();
|
|
|
|
|
compound.removeTag(key);
|
|
|
|
|
saveStoredCompound(compound);
|
|
|
|
|
}
|
2021-10-19 02:49:46 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
/**
|
|
|
|
|
* Remove all stored data
|
|
|
|
|
*/
|
|
|
|
|
public void clearStoredData(){
|
|
|
|
|
entity.getEntityData().removeTag("CNPCStoredData");
|
|
|
|
|
}
|
2021-10-19 02:49:46 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
private NBTTagCompound getStoredCompound(){
|
|
|
|
|
NBTTagCompound compound = entity.getEntityData().getCompoundTag("CNPCStoredData");
|
|
|
|
|
if(compound == null)
|
|
|
|
|
entity.getEntityData().setTag("CNPCStoredData", compound = new NBTTagCompound());
|
|
|
|
|
return compound;
|
|
|
|
|
}
|
2021-10-19 02:49:46 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
private void saveStoredCompound(NBTTagCompound compound){
|
|
|
|
|
entity.getEntityData().setTag("CNPCStoredData", compound);
|
|
|
|
|
}
|
2021-10-19 02:49:46 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
/**
|
|
|
|
|
* @return The age of this entity in ticks
|
|
|
|
|
*/
|
|
|
|
|
public long getAge(){
|
|
|
|
|
return entity.ticksExisted;
|
|
|
|
|
}
|
2021-10-19 02:49:46 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
/**
|
|
|
|
|
* Despawns this entity. Removes it permanently
|
|
|
|
|
*/
|
|
|
|
|
public void despawn(){
|
|
|
|
|
entity.isDead = true;
|
|
|
|
|
}
|
2021-10-19 02:49:46 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
/**
|
|
|
|
|
* @return Return whether or not this entity is standing in water
|
|
|
|
|
*/
|
|
|
|
|
public boolean inWater(){
|
|
|
|
|
return entity.isInsideOfMaterial(Material.water);
|
|
|
|
|
}
|
2021-10-19 02:49:46 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
/**
|
|
|
|
|
* @return Return whether or not this entity is standing in lava
|
|
|
|
|
*/
|
|
|
|
|
public boolean inLava(){
|
|
|
|
|
return entity.isInsideOfMaterial(Material.lava);
|
|
|
|
|
}
|
2021-10-19 02:49:46 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
/**
|
|
|
|
|
* @return Return whether or not this entity is standing in fire
|
|
|
|
|
*/
|
|
|
|
|
public boolean inFire(){
|
|
|
|
|
return entity.isInsideOfMaterial(Material.fire);
|
|
|
|
|
}
|
2021-10-19 02:49:46 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
/**
|
|
|
|
|
* @return Return whether or not this entity is on fire
|
|
|
|
|
*/
|
|
|
|
|
public boolean isBurning(){
|
|
|
|
|
return entity.isBurning();
|
|
|
|
|
}
|
2021-10-19 02:49:46 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
/**
|
|
|
|
|
* @param ticks Amount of world ticks this entity will burn. 20 ticks equals 1 second
|
|
|
|
|
*/
|
|
|
|
|
public void setBurning(int ticks){
|
|
|
|
|
entity.setFire(ticks);
|
|
|
|
|
}
|
2021-10-19 02:49:46 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
/**
|
|
|
|
|
* Removes fire from this entity
|
|
|
|
|
*/
|
|
|
|
|
public void extinguish(){
|
|
|
|
|
entity.extinguish();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return Name as which it's registered in minecraft
|
|
|
|
|
*/
|
|
|
|
|
public String getTypeName(){
|
|
|
|
|
return EntityList.getEntityString(entity);
|
|
|
|
|
}
|
2022-05-24 03:06:16 -05:00
|
|
|
|
|
|
|
|
public void playSound(String name, float volume, float pitch) {
|
|
|
|
|
entity.playSound(name, volume, pitch);
|
|
|
|
|
}
|
2021-10-19 02:49:46 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
/**
|
|
|
|
|
* @param item Item to be dropped
|
|
|
|
|
*/
|
2022-05-11 22:08:31 -05:00
|
|
|
public void dropItem(IItemStack item){
|
|
|
|
|
entity.entityDropItem(item.getMCItemStack(), 0);
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return Return the rider
|
|
|
|
|
*/
|
2022-05-11 22:08:31 -05:00
|
|
|
public IEntity getRider(){
|
|
|
|
|
return NpcAPI.Instance().getIEntity(entity.riddenByEntity);
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|
2021-10-19 02:49:46 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
/**
|
|
|
|
|
* @param entity The entity to ride this entity
|
|
|
|
|
*/
|
2022-05-11 22:08:31 -05:00
|
|
|
public void setRider(IEntity entity){
|
2018-09-13 12:03:28 -04:00
|
|
|
if(entity != null){
|
2022-05-11 22:08:31 -05:00
|
|
|
entity.getMCEntity().mountEntity(this.entity);;
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|
|
|
|
|
else if(this.entity.riddenByEntity != null)
|
|
|
|
|
this.entity.riddenByEntity.mountEntity(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return Return the entity, this entity is riding
|
|
|
|
|
*/
|
2022-05-11 22:08:31 -05:00
|
|
|
public IEntity getMount(){
|
|
|
|
|
return NpcAPI.Instance().getIEntity(entity.ridingEntity);
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|
2021-10-19 02:49:46 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
/**
|
|
|
|
|
* @param entity The entity this entity will mount
|
|
|
|
|
*/
|
2022-05-11 22:08:31 -05:00
|
|
|
public void setMount(IEntity entity){
|
2018-09-13 12:03:28 -04:00
|
|
|
if(entity == null)
|
|
|
|
|
this.entity.mountEntity(null);
|
|
|
|
|
else
|
2022-05-11 22:08:31 -05:00
|
|
|
this.entity.mountEntity(entity.getMCEntity());
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @see noppes.npcs.scripted.constants.EntityType
|
|
|
|
|
* @return Returns the EntityType of this entity
|
|
|
|
|
*/
|
|
|
|
|
public int getType(){
|
|
|
|
|
return EntityType.UNKNOWN;
|
|
|
|
|
}
|
2021-10-19 02:49:46 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
/**
|
|
|
|
|
* @since 1.7.10c
|
|
|
|
|
* @param type @EntityType to check
|
|
|
|
|
* @return Returns whether the entity is type of the given @EntityType
|
|
|
|
|
*/
|
|
|
|
|
public boolean typeOf(int type){
|
|
|
|
|
return type == EntityType.UNKNOWN;
|
|
|
|
|
}
|
2021-10-19 02:49:46 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
/**
|
|
|
|
|
* @param rotation The rotation to be set (0-360)
|
|
|
|
|
*/
|
|
|
|
|
public void setRotation(float rotation){
|
|
|
|
|
entity.rotationYaw = rotation;
|
|
|
|
|
}
|
2021-10-19 02:49:46 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
/**
|
2022-02-01 05:10:38 -06:00
|
|
|
* @return Current rotation of the entity
|
2018-09-13 12:03:28 -04:00
|
|
|
*/
|
|
|
|
|
public float getRotation(){
|
|
|
|
|
return entity.rotationYaw;
|
|
|
|
|
}
|
2021-10-19 02:49:46 -05:00
|
|
|
|
2022-02-01 05:10:38 -06:00
|
|
|
public void setPitch(float pitch){entity.rotationPitch = pitch;}
|
|
|
|
|
|
|
|
|
|
public float getPitch(){return entity.rotationPitch;}
|
|
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
/**
|
|
|
|
|
* @param power How strong the knockback is
|
|
|
|
|
* @param direction The direction in which he flies back (0-360). Usually based on getRotation()
|
|
|
|
|
*/
|
2021-12-06 00:10:10 -06:00
|
|
|
@Override
|
2018-09-13 12:03:28 -04:00
|
|
|
public void knockback(int power, float direction){
|
|
|
|
|
float v = direction * (float)Math.PI / 180.0F;
|
2021-12-08 17:48:35 -06:00
|
|
|
entity.addVelocity(-MathHelper.sin(v) * (float)power, power, MathHelper.cos(v) * (float)power);
|
2021-12-08 04:41:41 -06:00
|
|
|
entity.velocityChanged = true;
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|
2021-10-19 02:49:46 -05:00
|
|
|
|
|
|
|
|
public void knockback(int xpower, int ypower, int zpower, float direction){
|
|
|
|
|
float v = direction * (float)Math.PI / 180.0F;
|
2021-12-08 17:48:35 -06:00
|
|
|
entity.addVelocity(-MathHelper.sin(v) * (float)xpower, ypower, MathHelper.cos(v) * (float)zpower);
|
2021-12-08 04:41:41 -06:00
|
|
|
entity.velocityChanged = true;
|
2021-10-19 02:49:46 -05:00
|
|
|
}
|
|
|
|
|
|
2021-10-28 16:46:09 -05:00
|
|
|
public void setImmune(int ticks) {
|
|
|
|
|
entity.hurtResistantTime = ticks;
|
|
|
|
|
};
|
|
|
|
|
|
2022-05-03 11:26:04 -05:00
|
|
|
public void setInvisible(boolean invisible){
|
|
|
|
|
entity.setInvisible(invisible);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setSneaking(boolean sneaking){
|
|
|
|
|
entity.setSneaking(sneaking);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setSprinting(boolean sprinting){
|
|
|
|
|
entity.setSprinting(sprinting);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-28 16:54:41 -05:00
|
|
|
public boolean hasCollided() {
|
|
|
|
|
return entity.isCollided;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
/**
|
|
|
|
|
* @since 1.7.10c
|
|
|
|
|
* @return Returns whether or not this entity is sneaking
|
|
|
|
|
*/
|
|
|
|
|
public boolean isSneaking(){
|
|
|
|
|
return entity.isSneaking();
|
|
|
|
|
}
|
2021-10-19 02:49:46 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
/**
|
|
|
|
|
* @since 1.7.10c
|
|
|
|
|
* @return Returns whether or not this entity is sprinting
|
|
|
|
|
*/
|
|
|
|
|
public boolean isSprinting(){
|
|
|
|
|
return entity.isSprinting();
|
|
|
|
|
}
|
2021-10-19 02:49:46 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
/**
|
|
|
|
|
* @since 1.7.10c
|
|
|
|
|
* Expert users only
|
|
|
|
|
* @return Returns minecrafts entity
|
|
|
|
|
*/
|
2021-10-12 02:57:32 -05:00
|
|
|
public T getMCEntity(){
|
2018-09-13 12:03:28 -04:00
|
|
|
return entity;
|
|
|
|
|
}
|
2021-10-12 03:23:56 -05:00
|
|
|
|
|
|
|
|
public INbt getNbt() {
|
|
|
|
|
return NpcAPI.Instance().getINbt(this.entity.getEntityData());
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-19 14:48:59 -05:00
|
|
|
public INbt getAllNbt() {
|
|
|
|
|
NBTTagCompound compound = new NBTTagCompound();
|
|
|
|
|
this.entity.writeToNBT(compound);
|
|
|
|
|
return NpcAPI.Instance().getINbt(compound);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-12 03:23:56 -05:00
|
|
|
public void setNbt(INbt nbt) {
|
|
|
|
|
this.entity.readFromNBT(nbt.getMCNBT());
|
|
|
|
|
}
|
2021-10-18 07:02:19 -05:00
|
|
|
|
|
|
|
|
public void storeAsClone(int tab, String name) {
|
|
|
|
|
NBTTagCompound compound = new NBTTagCompound();
|
|
|
|
|
if (!this.entity.writeToNBTOptional(compound)) {
|
|
|
|
|
throw new CustomNPCsException("Cannot store dead entities", new Object[0]);
|
|
|
|
|
} else {
|
|
|
|
|
ServerCloneController.Instance.addClone(compound, name, tab);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-12-13 16:47:15 -06:00
|
|
|
|
2022-06-10 17:25:58 -05:00
|
|
|
public IWorld getWorld() {
|
|
|
|
|
return NpcAPI.Instance().getIWorld(entity.worldObj);
|
2021-12-13 16:47:15 -06:00
|
|
|
}
|
2021-10-19 02:49:46 -05:00
|
|
|
}
|