Files
CustomNPC-Plus/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java
T

923 lines
24 KiB
Java
Raw Normal View History

package noppes.npcs.scripted.entity;
2018-09-13 12:03:28 -04:00
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.item.EntityItem;
2018-09-13 12:03:28 -04:00
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;
import net.minecraft.nbt.NBTTagIntArray;
2018-09-13 12:03:28 -04:00
import net.minecraft.nbt.NBTTagString;
import net.minecraft.util.MathHelper;
2023-03-15 19:17:39 -05:00
import net.minecraft.world.World;
2023-07-27 22:53:37 -05:00
import net.minecraft.world.WorldServer;
import noppes.npcs.NoppesUtilPlayer;
import noppes.npcs.NoppesUtilServer;
2023-01-12 21:33:06 -05:00
import noppes.npcs.api.INbt;
2022-11-15 15:25:53 -05:00
import noppes.npcs.api.IParticle;
2023-01-12 21:33:06 -05:00
import noppes.npcs.api.IPos;
2022-11-15 15:25:53 -05:00
import noppes.npcs.api.IWorld;
import noppes.npcs.api.entity.IEntity;
import noppes.npcs.api.item.IItemStack;
2023-01-12 21:33:06 -05:00
import noppes.npcs.controllers.ServerCloneController;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.scripted.CustomNPCsException;
import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.ScriptParticle;
import noppes.npcs.scripted.constants.EntityType;
import java.util.*;
2018-09-13 12:03:28 -04:00
public class ScriptEntity<T extends Entity> implements IEntity {
protected T entity;
2018-09-13 12:03:28 -04:00
private Map<String,Object> tempData = new HashMap<String,Object>();
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,
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
) {
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.scaleX1 = particle.scaleY1 = scale1;
particle.scaleX2 = particle.scaleY2 = scale2;
particle.scaleXRate = particle.scaleYRate = scaleRate;
particle.scaleXRateStart = particle.scaleYRateStart = scaleRateStart;
2022-07-02 06:22:43 -05:00
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);
NoppesUtilServer.spawnScriptedParticle(compound, this.getWorld().getDimensionID());
}
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,
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.scaleX1 = particle.scaleY1 = scale1;
particle.scaleX2 = particle.scaleY2 = scale2;
particle.scaleXRate = particle.scaleYRate = scaleRate;
particle.scaleXRateStart = particle.scaleYRateStart = scaleRateStart;
2022-07-02 06:22:43 -05:00
particle.alpha1 = alpha1;
particle.alpha2 = alpha2;
particle.alphaRate = alphaRate;
particle.alphaRateStart = alphaRateStart;
NBTTagCompound compound = particle.writeToNBT();
compound.setInteger("EntityID", entityID);
NoppesUtilServer.spawnScriptedParticle(compound, this.getWorld().getDimensionID());
}
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,
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.scaleX1 = particle.scaleY1 = scale1;
particle.scaleX2 = particle.scaleY2 = scale2;
particle.scaleXRate = particle.scaleYRate = scaleRate;
particle.scaleXRateStart = particle.scaleYRateStart = scaleRateStart;
2022-07-02 06:22:43 -05:00
NBTTagCompound compound = particle.writeToNBT();
compound.setInteger("EntityID", entityID);
NoppesUtilServer.spawnScriptedParticle(compound, this.getWorld().getDimensionID());
}
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,
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);
NoppesUtilServer.spawnScriptedParticle(compound, this.getWorld().getDimensionID());
}
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,
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);
NoppesUtilServer.spawnScriptedParticle(compound, this.getWorld().getDimensionID());
}
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
) {
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);
NoppesUtilServer.spawnScriptedParticle(compound, this.getWorld().getDimensionID());
}
2022-07-08 12:03:15 -05:00
public void spawnParticle(IParticle entityParticle) { entityParticle.spawn(this); }
2022-05-03 23:09:21 -05:00
public int getEntityId(){
return entity.getEntityId();
}
public String getUniqueID(){
return entity.getUniqueID().toString();
}
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){
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){
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){
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
}
public void setMotion(double x, double y, double z){
this.setMotionX(x);
this.setMotionY(y);
this.setMotionZ(z);
}
public void setMotion(IPos pos) {
this.setMotion(pos.getXD(),pos.getYD(),pos.getZD());
}
public IPos getMotion() {
return NpcAPI.Instance().getIPos(entity.motionX,entity.motionY,entity.motionZ);
}
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);
}
public IPos getPos() {
return NpcAPI.Instance().getIPos(entity.posX, entity.posY, entity.posZ);
}
public IPos getPosition() {
return getPos();
}
public void setPos(IPos pos) {
this.entity.setPosition(pos.getXD(), pos.getYD(), pos.getZD());
}
2021-10-19 02:49:46 -05:00
public void setPosition(IPos pos) {
this.setPos(pos);
}
public int getDimension(){
return entity.dimension;
}
2023-03-15 19:17:39 -05:00
public void setDimension(int dimensionId) {
IWorld world = NpcAPI.Instance().getIWorld(dimensionId);
if (world != null) {
2023-07-27 22:53:37 -05:00
WorldServer mcWorld = world.getMCWorld();
2023-03-15 19:17:39 -05:00
if (this.entity.riddenByEntity != null)
{
this.entity.riddenByEntity.mountEntity((Entity)null);
}
if (this.entity.ridingEntity != null)
{
this.entity.mountEntity((Entity)null);
}
2023-07-27 22:53:37 -05:00
WorldServer prevWorld = ((WorldServer)this.entity.worldObj);
prevWorld.unloadEntities(new ArrayList<Entity>(Collections.singleton(this.entity)));
prevWorld.resetUpdateEntityTick();
prevWorld.onEntityRemoved(this.entity);
2023-03-15 19:17:39 -05:00
this.entity.worldObj = mcWorld;
this.entity.dimension = dimensionId;
mcWorld.addLoadedEntities(new ArrayList<Entity>(Collections.singleton(this.entity)));
2023-07-27 22:53:37 -05:00
mcWorld.resetUpdateEntityTick();
mcWorld.updateEntityWithOptionalForce(this.entity, false);
if (this.entity instanceof EntityNPCInterface) {
((EntityNPCInterface) this.entity).updateClient();
}
mcWorld.spawnEntityInWorld(this.entity);
this.entity.velocityChanged = true;
2023-03-15 19:17:39 -05:00
}
}
2018-09-13 12:03:28 -04:00
/**
* @param range The search range for entities around this entity
* @return Array of entities within range
*/
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));
List<IEntity> list = new ArrayList<IEntity>();
2018-09-13 12:03:28 -04:00
for(Entity living : entities){
if(living != entity)
list.add(NpcAPI.Instance().getIEntity(living));
2018-09-13 12:03:28 -04: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
*/
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));
List<IEntity> list = new ArrayList<IEntity>();
2018-09-13 12:03:28 -04:00
for(Entity living : entities){
if(living != entity)
list.add(NpcAPI.Instance().getIEntity(living));
2018-09-13 12:03:28 -04: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
2022-12-27 16:46:59 -06:00
public String[] getTempDataKeys() {
return tempData.keySet().toArray(new String[0]);
}
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();
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);
}
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
2022-12-27 16:46:59 -06:00
public String[] getStoredDataKeys() {
NBTTagCompound compound = getStoredCompound();
2022-12-27 17:29:22 -06:00
Set strings = compound.func_150296_c();
ArrayList<String> stringList = new ArrayList<>();
for (Object o : strings) {
stringList.add((String)o);
}
return stringList.toArray(new String[0]);
2022-12-27 16:46:59 -06: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);
}
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
*/
public void dropItem(IItemStack item){
entity.entityDropItem(item.getMCItemStack(), 0);
2018-09-13 12:03:28 -04:00
}
/**
* @return Return the rider
*/
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
*/
public void setRider(IEntity entity){
2018-09-13 12:03:28 -04:00
if(entity != null){
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
*/
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
*/
public void setMount(IEntity entity){
2018-09-13 12:03:28 -04:00
if(entity == null)
this.entity.mountEntity(null);
else
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
public void setRotation(float rotationYaw, float rotationPitch) {
entity.rotationYaw = rotationYaw;
entity.rotationPitch = rotationPitch;
}
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()
*/
@Override
2018-09-13 12:03:28 -04:00
public void knockback(int power, float direction){
float v = direction * (float)Math.PI / 180.0F;
entity.addVelocity(-MathHelper.sin(v) * (float)power, power, MathHelper.cos(v) * (float)power);
entity.velocityChanged = true;
2018-09-13 12:03:28 -04:00
}
2021-10-19 02:49:46 -05:00
public void knockback(double xpower, double ypower, double zpower, float direction){
2021-10-19 02:49:46 -05:00
float v = direction * (float)Math.PI / 180.0F;
entity.addVelocity(-MathHelper.sin(v) * xpower, ypower, MathHelper.cos(v) * zpower);
entity.velocityChanged = true;
2021-10-19 02:49:46 -05:00
}
public void knockback(IPos pos, float direction){
this.knockback(pos.getXD(),pos.getYD(),pos.getZD(),direction);
}
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);
}
public boolean hasCollided() {
return entity.isCollided;
}
public boolean hasCollidedVertically() {
return entity.isCollidedVertically;
}
public boolean hasCollidedHorizontally() {
return entity.isCollidedHorizontally;
}
public boolean capturesDrops() {
return entity.captureDrops;
}
public void setCapturesDrops(boolean capture) {
entity.captureDrops = capture;
}
public void setCapturedDrops(IEntity[] capturedDrops) {
entity.capturedDrops.clear();
for (IEntity<?> iEntity : capturedDrops) {
if (iEntity.getMCEntity() instanceof EntityItem) {
entity.capturedDrops.add((EntityItem) iEntity.getMCEntity());
}
}
}
public IEntity<?>[] getCapturedDrops() {
ArrayList<IEntity<?>> iEntityList = new ArrayList<>();
for (EntityItem entityItem : entity.capturedDrops) {
iEntityList.add(NpcAPI.Instance().getIEntity(entityItem));
}
return iEntityList.toArray(new IEntity[0]);
}
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
*/
public T getMCEntity(){
2018-09-13 12:03:28 -04:00
return entity;
}
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);
}
public void setNbt(INbt nbt) {
this.entity.readFromNBT(nbt.getMCNBT());
}
public INbt getNbtOptional() {
NBTTagCompound compound = new NBTTagCompound();
return this.entity.writeToNBTOptional(compound) ? NpcAPI.Instance().getINbt(compound) : null;
}
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
public IWorld getWorld() {
return NpcAPI.Instance().getIWorld(entity.worldObj);
2021-12-13 16:47:15 -06:00
}
public boolean equals(Object object) {
return object instanceof IEntity && ((IEntity<?>)object).getMCEntity().equals(this.entity);
}
2023-11-22 17:12:30 -05:00
public void updateEntity() {
IWorld world = NpcAPI.Instance().getIWorld(entity.worldObj);
entity.dimension = world.getDimensionID();
}
2021-10-19 02:49:46 -05:00
}