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;
|
|
|
|
|
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;
|
2018-09-13 12:03:28 -04:00
|
|
|
import noppes.npcs.controllers.ScriptController;
|
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;
|
2021-12-13 16:47:15 -06:00
|
|
|
import noppes.npcs.scripted.*;
|
2018-09-13 12:03:28 -04:00
|
|
|
import noppes.npcs.scripted.constants.EntityType;
|
2021-10-18 06:33:39 -05:00
|
|
|
import noppes.npcs.scripted.interfaces.IEntity;
|
|
|
|
|
import noppes.npcs.scripted.interfaces.INbt;
|
2022-01-04 03:50:50 -06:00
|
|
|
import noppes.npcs.scripted.interfaces.IPos;
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-06 01:24:38 -05:00
|
|
|
/**
|
|
|
|
|
* @param directory The particle's directory. Use only forward slashes when writing a directory. Example: "customnpcs:textures/particle/tail.png"
|
|
|
|
|
* @param HEXcolor The particle's color as a HEX integer
|
|
|
|
|
* @param amount The amount of particles to spawn
|
|
|
|
|
* @param maxAge The particle's maximum age in MC ticks
|
|
|
|
|
|
|
|
|
|
* @param x The particle's x position
|
|
|
|
|
* @param y The particle's y position
|
|
|
|
|
* @param z The particle's z position
|
|
|
|
|
|
|
|
|
|
* @param motionX The particle's speed in the x axis
|
|
|
|
|
* @param motionY The particle's speed in the y axis
|
|
|
|
|
* @param motionZ The particle's speed in the z axis
|
|
|
|
|
* @param gravity The particle's gravity
|
2021-09-08 13:41:57 -05:00
|
|
|
|
|
|
|
|
* @param scale1 The particle's starting scale
|
|
|
|
|
* @param scale2 The particle's ending scale
|
|
|
|
|
* @param scaleRate Multiplier for the particle's scale growth rate
|
|
|
|
|
* @param scaleRateStart The time at which the particle begins growing/shrinking
|
|
|
|
|
|
|
|
|
|
* @param alpha1 The particle's starting transparency
|
|
|
|
|
* @param alpha2 The particle's ending transparency
|
|
|
|
|
* @param scaleRate Multiplier for the particle's transparency growth rate
|
|
|
|
|
* @param alphaRateStart The time at which the particle begins appearing/fading
|
2021-09-06 01:24:38 -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
|
2021-09-06 01:24:38 -05:00
|
|
|
) {
|
2021-09-06 12:28:14 -05:00
|
|
|
int entityID = entity.getEntityId();
|
2022-03-02 18:18:03 -06:00
|
|
|
NoppesUtilServer.spawnScriptedParticle(directory, HEXcolor, amount, maxAge,
|
2021-09-06 01:24:38 -05:00
|
|
|
x, y, z,
|
|
|
|
|
motionX, motionY, motionZ, gravity,
|
|
|
|
|
scale1, scale2, scaleRate, scaleRateStart,
|
|
|
|
|
alpha1, alpha2, alphaRate, alphaRateStart,
|
2022-03-02 18:18:03 -06:00
|
|
|
rotationX1, rotationX2, rotationXRate, rotationXRateStart,
|
|
|
|
|
rotationY1, rotationY2, rotationYRate, rotationYRateStart,
|
|
|
|
|
rotationZ1, rotationZ2, rotationZRate, rotationZRateStart,
|
2022-05-06 01:22:48 -05:00
|
|
|
true, -1, -1, 0,0,
|
|
|
|
|
0, true, 0, 0,
|
2022-05-07 01:40:41 -05:00
|
|
|
entityID, entity.dimension
|
2021-09-06 01:24:38 -05:00
|
|
|
);
|
|
|
|
|
}
|
2022-03-16 23:15:30 -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();
|
|
|
|
|
NoppesUtilServer.spawnScriptedParticle(directory, HEXcolor, amount, maxAge,
|
|
|
|
|
x, y, z,
|
|
|
|
|
motionX, motionY, motionZ, gravity,
|
|
|
|
|
scale1, scale2, scaleRate, scaleRateStart,
|
|
|
|
|
alpha1, alpha2, alphaRate, alphaRateStart,
|
|
|
|
|
0, 0, 0, 0,
|
|
|
|
|
0, 0, 0, 0,
|
|
|
|
|
0, 0, 0, 0,
|
2022-05-06 01:22:48 -05:00
|
|
|
true, -1, -1, 0,0,
|
|
|
|
|
0, true, 0, 0,
|
2022-05-07 01:40:41 -05:00
|
|
|
entityID, entity.dimension
|
2022-03-16 23:15:30 -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();
|
|
|
|
|
NoppesUtilServer.spawnScriptedParticle(directory, HEXcolor, amount, maxAge,
|
|
|
|
|
x, y, z,
|
|
|
|
|
motionX, motionY, motionZ, gravity,
|
|
|
|
|
scale1, scale2, scaleRate, scaleRateStart,
|
|
|
|
|
0, 0, 0, 0,
|
|
|
|
|
0, 0, 0, 0,
|
|
|
|
|
0, 0, 0, 0,
|
|
|
|
|
0, 0, 0, 0,
|
2022-05-06 01:22:48 -05:00
|
|
|
true, -1, -1, 0,0,
|
|
|
|
|
0, true, 0, 0,
|
2022-05-07 01:40:41 -05:00
|
|
|
entityID, entity.dimension
|
2022-03-16 23:15:30 -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();
|
|
|
|
|
NoppesUtilServer.spawnScriptedParticle(directory, HEXcolor, amount, maxAge,
|
|
|
|
|
x, y, z,
|
|
|
|
|
motionX, motionY, motionZ, gravity,
|
|
|
|
|
0, 0, 0, 0,
|
|
|
|
|
0, 0, 0, 0,
|
|
|
|
|
0, 0, 0, 0,
|
|
|
|
|
0, 0, 0, 0,
|
|
|
|
|
0, 0, 0, 0,
|
2022-05-06 01:22:48 -05:00
|
|
|
true, -1, -1, 0,0,
|
|
|
|
|
0, true, 0, 0,
|
2022-05-07 01:40:41 -05:00
|
|
|
entityID, entity.dimension
|
2022-03-16 23:15:30 -05:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
public void spawnParticle(String directory, int HEXcolor, int amount, int maxAge,
|
|
|
|
|
double x, double y, double z
|
|
|
|
|
) {
|
|
|
|
|
int entityID = entity.getEntityId();
|
|
|
|
|
NoppesUtilServer.spawnScriptedParticle(directory, HEXcolor, amount, maxAge,
|
|
|
|
|
x, y, z,
|
|
|
|
|
0, 0, 0, 0,
|
|
|
|
|
0, 0, 0, 0,
|
|
|
|
|
0, 0, 0, 0,
|
|
|
|
|
0, 0, 0, 0,
|
|
|
|
|
0, 0, 0, 0,
|
|
|
|
|
0, 0, 0, 0,
|
2022-05-06 01:22:48 -05:00
|
|
|
true, -1, -1, 0,0,
|
|
|
|
|
0, true, 0, 0,
|
2022-05-07 01:40:41 -05:00
|
|
|
entityID, entity.dimension
|
2022-03-16 23:15:30 -05:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
public void spawnParticle(String directory, int HEXcolor, int amount, int maxAge
|
|
|
|
|
) {
|
|
|
|
|
int entityID = entity.getEntityId();
|
|
|
|
|
NoppesUtilServer.spawnScriptedParticle(directory, HEXcolor, amount, maxAge,
|
|
|
|
|
0, 0, 0,
|
|
|
|
|
0, 0, 0, 0,
|
|
|
|
|
0, 0, 0, 0,
|
|
|
|
|
0, 0, 0, 0,
|
|
|
|
|
0, 0, 0, 0,
|
|
|
|
|
0, 0, 0, 0,
|
|
|
|
|
0, 0, 0, 0,
|
2022-05-06 01:22:48 -05:00
|
|
|
true, -1, -1, 0,0,
|
|
|
|
|
0, true, 0, 0,
|
2022-05-07 01:40:41 -05:00
|
|
|
entityID, entity.dimension
|
2022-03-16 23:15:30 -05:00
|
|
|
);
|
|
|
|
|
}
|
2022-05-06 03:38:24 -05:00
|
|
|
public void spawnParticle(ScriptParticle 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-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
|
|
|
|
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 ScriptEntity[] getSurroundingEntities(int range){
|
|
|
|
|
List<Entity> entities = entity.worldObj.getEntitiesWithinAABB(Entity.class, entity.boundingBox.expand(range, range, range));
|
|
|
|
|
List<ScriptEntity> list = new ArrayList<ScriptEntity>();
|
|
|
|
|
for(Entity living : entities){
|
|
|
|
|
if(living != entity)
|
|
|
|
|
list.add(ScriptController.Instance.getScriptForEntity(living));
|
|
|
|
|
}
|
|
|
|
|
return list.toArray(new ScriptEntity[list.size()]);
|
|
|
|
|
}
|
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 ScriptEntity[] getSurroundingEntities(int range, int type){
|
|
|
|
|
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<ScriptEntity> list = new ArrayList<ScriptEntity>();
|
|
|
|
|
for(Entity living : entities){
|
|
|
|
|
if(living != entity)
|
|
|
|
|
list.add(ScriptController.Instance.getScriptForEntity(living));
|
|
|
|
|
}
|
|
|
|
|
return list.toArray(new ScriptEntity[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();
|
|
|
|
|
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);
|
|
|
|
|
}
|
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);
|
|
|
|
|
}
|
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(ScriptItemStack item){
|
|
|
|
|
entity.entityDropItem(item.item, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return Return the rider
|
|
|
|
|
*/
|
|
|
|
|
public ScriptEntity getRider(){
|
|
|
|
|
return ScriptController.Instance.getScriptForEntity(entity.riddenByEntity);
|
|
|
|
|
}
|
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(ScriptEntity entity){
|
|
|
|
|
if(entity != null){
|
|
|
|
|
entity.entity.mountEntity(this.entity);;
|
|
|
|
|
}
|
|
|
|
|
else if(this.entity.riddenByEntity != null)
|
|
|
|
|
this.entity.riddenByEntity.mountEntity(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return Return the entity, this entity is riding
|
|
|
|
|
*/
|
|
|
|
|
public ScriptEntity getMount(){
|
|
|
|
|
return ScriptController.Instance.getScriptForEntity(entity.ridingEntity);
|
|
|
|
|
}
|
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(ScriptEntity entity){
|
|
|
|
|
if(entity == null)
|
|
|
|
|
this.entity.mountEntity(null);
|
|
|
|
|
else
|
|
|
|
|
this.entity.mountEntity(entity.entity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @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
|
|
|
|
|
|
|
|
public ScriptWorld getWorld() {
|
|
|
|
|
return (ScriptWorld)NpcAPI.Instance().getIWorld((WorldServer) entity.worldObj);
|
|
|
|
|
}
|
2021-10-19 02:49:46 -05:00
|
|
|
}
|