2021-09-08 13:41:57 -05:00
|
|
|
package noppes.npcs.scripted;
|
|
|
|
|
|
2022-07-02 06:22:43 -05:00
|
|
|
import net.minecraft.nbt.*;
|
2021-09-08 13:41:57 -05:00
|
|
|
import noppes.npcs.NoppesUtilServer;
|
2022-11-15 15:25:53 -05:00
|
|
|
import noppes.npcs.api.IParticle;
|
|
|
|
|
import noppes.npcs.api.IPos;
|
|
|
|
|
import noppes.npcs.api.IWorld;
|
|
|
|
|
import noppes.npcs.api.entity.IEntity;
|
2021-09-08 13:41:57 -05:00
|
|
|
|
2022-07-02 06:22:43 -05:00
|
|
|
import java.lang.reflect.Field;
|
|
|
|
|
|
2022-05-11 16:43:14 -05:00
|
|
|
public class ScriptParticle implements IParticle {
|
2022-07-02 06:22:43 -05:00
|
|
|
public String directory;
|
|
|
|
|
|
|
|
|
|
public int HEXColor = 0xFFFFFF;
|
|
|
|
|
public int HEXColor2 = 0xFFFFFF;
|
|
|
|
|
public float HEXColorRate = 0.0f;
|
|
|
|
|
public int HEXColorStart = 0;
|
|
|
|
|
|
|
|
|
|
public int amount = 1;
|
|
|
|
|
public int maxAge = 20;
|
|
|
|
|
public double x = 0,y = 0,z = 0;
|
|
|
|
|
public double motionX = 0,motionY = 0,motionZ = 0;
|
|
|
|
|
public float gravity = 0;
|
2023-02-16 18:43:22 -06:00
|
|
|
public float scaleX1 = 20.0f,scaleX2 = 20.0f,scaleXRate = 0.0f;
|
|
|
|
|
public float scaleY1 = 20.0f,scaleY2 = 20.0f,scaleYRate = 0.0f;
|
2022-07-02 06:22:43 -05:00
|
|
|
public float alpha1 = 1.0f,alpha2 = 1.0f,alphaRate = 0.0f;
|
2023-02-16 18:43:22 -06:00
|
|
|
public int scaleXRateStart = 0, scaleYRateStart, alphaRateStart = 0;
|
2021-09-08 13:41:57 -05:00
|
|
|
|
2022-03-02 18:18:03 -06:00
|
|
|
public float rotationX1 = 0;
|
|
|
|
|
public float rotationX2 = 0;
|
|
|
|
|
public float rotationXRate = 0.0F;
|
|
|
|
|
public int rotationXRateStart = 0;
|
|
|
|
|
|
|
|
|
|
public float rotationY1 = 0;
|
|
|
|
|
public float rotationY2 = 0;
|
|
|
|
|
public float rotationYRate = 0.0F;
|
|
|
|
|
public int rotationYRateStart = 0;
|
|
|
|
|
|
|
|
|
|
public float rotationZ1 = 0;
|
|
|
|
|
public float rotationZ2 = 0;
|
|
|
|
|
public float rotationZRate = 0.0F;
|
|
|
|
|
public int rotationZRateStart = 0;
|
|
|
|
|
|
2022-05-06 00:22:28 -05:00
|
|
|
public int width = -1, height = -1;
|
|
|
|
|
public int offsetX = 0, offsetY = 0;
|
2022-05-06 01:22:48 -05:00
|
|
|
|
2022-05-06 00:22:28 -05:00
|
|
|
public int animRate = 0;
|
2022-05-06 01:22:48 -05:00
|
|
|
public boolean animLoop = true;
|
|
|
|
|
public int animStart = 0, animEnd = -1;
|
2022-05-06 00:22:28 -05:00
|
|
|
|
2022-05-04 18:08:54 -05:00
|
|
|
public boolean facePlayer = true;
|
2022-07-02 03:10:11 -05:00
|
|
|
public boolean glows = true;
|
2022-07-02 06:22:43 -05:00
|
|
|
public boolean noClip = true;
|
2022-05-04 18:08:54 -05:00
|
|
|
|
2022-05-06 03:38:24 -05:00
|
|
|
public ScriptParticle(String directory){
|
2021-09-08 13:41:57 -05:00
|
|
|
this.directory = directory;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-02 06:22:43 -05:00
|
|
|
public NBTTagCompound writeToNBT() {
|
|
|
|
|
NBTTagCompound compound = new NBTTagCompound();
|
|
|
|
|
ScriptParticle newParticle = new ScriptParticle("");
|
|
|
|
|
|
|
|
|
|
//Iterate through fields, check if they're not equal to a new object, write to NBT
|
|
|
|
|
for (Field field : ScriptParticle.class.getDeclaredFields()) {
|
|
|
|
|
try {
|
|
|
|
|
if (!field.get(this).equals(field.get(newParticle))) {
|
|
|
|
|
compound = writeNBTTag(compound, field.getType(), field.getName(), field.get(this));
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception ignored) {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return compound;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public NBTTagCompound writeNBTTag(NBTTagCompound compound, Class<?> c, String key, Object value) {
|
|
|
|
|
if (c == boolean.class) {
|
|
|
|
|
compound.setBoolean(key, (Boolean) value);
|
|
|
|
|
}
|
|
|
|
|
if (c == int.class) {
|
|
|
|
|
compound.setInteger(key, (Integer) value);
|
|
|
|
|
}
|
|
|
|
|
if (c == double.class) {
|
|
|
|
|
compound.setDouble(key, (Double) value);
|
|
|
|
|
}
|
|
|
|
|
if (c == float.class) {
|
|
|
|
|
compound.setFloat(key, (Float) value);
|
|
|
|
|
}
|
|
|
|
|
if (c == String.class) {
|
|
|
|
|
compound.setString(key, (String) value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return compound;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static Object readNBTTag(NBTTagCompound compound, String key) {
|
|
|
|
|
if (compound.getTag(key) instanceof NBTTagByte) {
|
|
|
|
|
return compound.getBoolean(key);
|
|
|
|
|
}
|
|
|
|
|
if (compound.getTag(key) instanceof NBTTagInt) {
|
|
|
|
|
return compound.getInteger(key);
|
|
|
|
|
}
|
|
|
|
|
if (compound.getTag(key) instanceof NBTTagDouble) {
|
|
|
|
|
return compound.getDouble(key);
|
|
|
|
|
}
|
|
|
|
|
if (compound.getTag(key) instanceof NBTTagFloat) {
|
|
|
|
|
return compound.getFloat(key);
|
|
|
|
|
}
|
|
|
|
|
if (compound.getTag(key) instanceof NBTTagString) {
|
|
|
|
|
return compound.getString(key);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static ScriptParticle fromNBT(NBTTagCompound compound) {
|
|
|
|
|
ScriptParticle particle = new ScriptParticle(compound.getString("directory"));
|
|
|
|
|
|
|
|
|
|
//Iterate through fields, check if compound has a key equal to the field's name, and if so set the field equal to that value from NBT.
|
|
|
|
|
for (Field field : ScriptParticle.class.getDeclaredFields()) {
|
|
|
|
|
try {
|
|
|
|
|
if (compound.hasKey(field.getName())) {
|
|
|
|
|
Object val = ScriptParticle.readNBTTag(compound,field.getName());
|
|
|
|
|
if (val != null) {
|
|
|
|
|
field.set(particle, val);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception ignored) {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return particle;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-08 12:03:15 -05:00
|
|
|
public void spawn(IEntity entity){
|
2021-09-08 13:41:57 -05:00
|
|
|
int entityID = entity.getMCEntity().getEntityId();
|
2022-07-02 06:22:43 -05:00
|
|
|
|
|
|
|
|
NBTTagCompound compound = this.writeToNBT();
|
|
|
|
|
compound.setInteger("EntityID", entityID);
|
|
|
|
|
|
2022-07-02 13:07:23 -05:00
|
|
|
NoppesUtilServer.spawnScriptedParticle(compound, entity.getWorld().getDimensionID());
|
2021-09-08 13:41:57 -05:00
|
|
|
}
|
|
|
|
|
|
2022-07-08 12:03:15 -05:00
|
|
|
public void spawn(IWorld world){
|
2022-07-02 06:22:43 -05:00
|
|
|
NBTTagCompound compound = this.writeToNBT();
|
2022-07-02 13:07:23 -05:00
|
|
|
NoppesUtilServer.spawnScriptedParticle(compound, world.getDimensionID());
|
2022-05-07 01:40:41 -05:00
|
|
|
}
|
|
|
|
|
|
2022-07-08 12:03:15 -05:00
|
|
|
public void spawn(IWorld world, double x, double y, double z){
|
2022-07-02 06:22:43 -05:00
|
|
|
NBTTagCompound compound = this.writeToNBT();
|
2022-07-02 13:07:23 -05:00
|
|
|
NoppesUtilServer.spawnScriptedParticle(compound, world.getDimensionID());
|
2022-05-06 03:38:24 -05:00
|
|
|
}
|
|
|
|
|
|
2022-07-08 12:03:15 -05:00
|
|
|
public void spawnOnEntity(IEntity entity) {
|
|
|
|
|
spawn(entity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void spawnInWorld(IWorld world) {
|
|
|
|
|
spawn(world);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void spawnInWorld(IWorld world, double x, double y, double z){
|
|
|
|
|
spawn(world, x, y, z);
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-02 03:10:11 -05:00
|
|
|
public void setGlows(boolean glows) { this.glows = glows; }
|
|
|
|
|
public boolean getGlows() { return this.glows; }
|
|
|
|
|
|
2022-07-02 06:22:43 -05:00
|
|
|
public void setNoClip(boolean noClip) { this.noClip = noClip; }
|
|
|
|
|
public boolean getNoClip() { return this.noClip; }
|
|
|
|
|
|
2022-05-17 05:35:08 -05:00
|
|
|
public void setFacePlayer(boolean facePlayer) { this.facePlayer = facePlayer; }
|
|
|
|
|
public boolean getFacePlayer() { return facePlayer; }
|
|
|
|
|
|
|
|
|
|
public String getDirectory() {
|
|
|
|
|
return directory;
|
|
|
|
|
}
|
|
|
|
|
public void setDirectory(String directory) {
|
|
|
|
|
this.directory = directory;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setAmount(int amount) {
|
|
|
|
|
this.amount = amount;
|
|
|
|
|
}
|
|
|
|
|
public int getAmount() {
|
|
|
|
|
return amount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setMaxAge(int maxAge) {
|
|
|
|
|
this.maxAge = maxAge;
|
|
|
|
|
}
|
|
|
|
|
public int getMaxAge() {
|
|
|
|
|
return maxAge;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-06 00:22:28 -05:00
|
|
|
public void setSize(int width, int height){
|
|
|
|
|
this.width = width;
|
|
|
|
|
this.height = height;
|
|
|
|
|
}
|
|
|
|
|
public int getWidth() { return width; }
|
|
|
|
|
public int getHeight() { return height; }
|
|
|
|
|
|
|
|
|
|
public void setOffset(int offsetX, int offsetY){
|
|
|
|
|
this.offsetX = offsetX;
|
|
|
|
|
this.offsetY = offsetY;
|
|
|
|
|
}
|
|
|
|
|
public int getOffsetX() { return offsetX; }
|
|
|
|
|
public int getOffsetY() { return offsetY; }
|
|
|
|
|
|
2022-05-06 01:22:48 -05:00
|
|
|
public void setAnim(int animRate, boolean animLoop, int animStart, int animEnd){
|
|
|
|
|
this.animRate = animRate;
|
|
|
|
|
this.animLoop = animLoop;
|
|
|
|
|
this.animStart = animStart;
|
|
|
|
|
this.animEnd = animEnd;
|
|
|
|
|
}
|
2022-05-06 00:22:28 -05:00
|
|
|
public int getAnimRate() { return animRate; }
|
2022-05-06 01:22:48 -05:00
|
|
|
public boolean getAnimLoop() { return animLoop; }
|
|
|
|
|
public int getAnimStart() { return animStart; }
|
|
|
|
|
public int getAnimEnd() { return animEnd; }
|
2022-05-06 00:22:28 -05:00
|
|
|
|
2022-05-17 05:35:08 -05:00
|
|
|
public void setPosition(double x, double y, double z){
|
|
|
|
|
this.x = x;
|
|
|
|
|
this.y = y;
|
|
|
|
|
this.z = z;
|
2021-09-08 13:41:57 -05:00
|
|
|
}
|
|
|
|
|
public double getX() {
|
|
|
|
|
return x;
|
|
|
|
|
}
|
|
|
|
|
public double getY() {
|
|
|
|
|
return y;
|
|
|
|
|
}
|
|
|
|
|
public double getZ() {
|
|
|
|
|
return z;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-06 01:25:28 -06:00
|
|
|
public void setPosition(IPos pos) {
|
2023-07-07 17:51:51 -05:00
|
|
|
this.setPosition(pos.getXD(),pos.getYD(),pos.getZD());
|
2022-11-06 01:25:28 -06:00
|
|
|
}
|
|
|
|
|
public void getPos() {
|
|
|
|
|
NpcAPI.Instance().getIPos(x,y,z);
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-17 05:35:08 -05:00
|
|
|
public void setMotion(double motionX, double motionY, double motionZ, float gravity){
|
|
|
|
|
this.motionX = motionX;
|
|
|
|
|
this.motionY = motionY;
|
|
|
|
|
this.motionZ = motionZ;
|
|
|
|
|
this.gravity = gravity;
|
|
|
|
|
}
|
2021-09-08 13:41:57 -05:00
|
|
|
public double getMotionX() {
|
|
|
|
|
return motionX;
|
|
|
|
|
}
|
|
|
|
|
public double getMotionY() {
|
|
|
|
|
return motionY;
|
|
|
|
|
}
|
|
|
|
|
public double getMotionZ() {
|
|
|
|
|
return motionZ;
|
|
|
|
|
}
|
|
|
|
|
public float getGravity() {
|
|
|
|
|
return gravity;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-17 05:35:08 -05:00
|
|
|
public void setHEXColor(int HEXColor, int HEXColor2, float HEXColorRate, int HEXColorStart) {
|
|
|
|
|
this.HEXColor = HEXColor;
|
|
|
|
|
this.HEXColor2 = HEXColor2;
|
|
|
|
|
this.HEXColorRate = HEXColorRate;
|
|
|
|
|
this.HEXColorStart = HEXColorStart;
|
|
|
|
|
}
|
2022-05-11 16:43:14 -05:00
|
|
|
public int getHEXColor1() {
|
|
|
|
|
return HEXColor;
|
|
|
|
|
}
|
|
|
|
|
public int getHEXColor2() {
|
|
|
|
|
return HEXColor2;
|
|
|
|
|
}
|
|
|
|
|
public float getHEXColorRate() {
|
|
|
|
|
return HEXColorRate;
|
|
|
|
|
}
|
|
|
|
|
public int getHEXColorStart() {
|
|
|
|
|
return HEXColorStart;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-17 05:35:08 -05:00
|
|
|
public void setAlpha(float alpha1, float alpha2, float alphaRate, int alphaRateStart){
|
|
|
|
|
this.alpha1 = alpha1;
|
|
|
|
|
this.alpha2 = alpha2;
|
|
|
|
|
this.alphaRate = alphaRate;
|
|
|
|
|
this.alphaRateStart = alphaRateStart;
|
|
|
|
|
}
|
2021-09-08 13:41:57 -05:00
|
|
|
public float getAlpha1() {
|
|
|
|
|
return alpha1;
|
|
|
|
|
}
|
|
|
|
|
public float getAlpha2() {
|
|
|
|
|
return alpha2;
|
|
|
|
|
}
|
|
|
|
|
public float getAlphaRate() {
|
|
|
|
|
return alphaRate;
|
|
|
|
|
}
|
2022-03-02 18:18:03 -06:00
|
|
|
public int getAlphaRateStart() {
|
|
|
|
|
return alphaRateStart;
|
|
|
|
|
}
|
2021-09-08 13:41:57 -05:00
|
|
|
|
2023-02-16 18:43:22 -06:00
|
|
|
public void setScale(float scale1, float scale2, float scaleRate, int scaleRateStart) {
|
|
|
|
|
this.scaleX1 = this.scaleY1 = scale1;
|
|
|
|
|
this.scaleX2 = this.scaleY2 = scale2;
|
|
|
|
|
this.scaleXRate = this.scaleYRate = scaleRate;
|
|
|
|
|
this.scaleXRateStart = this.scaleYRateStart = scaleRateStart;
|
2022-05-17 05:35:08 -05:00
|
|
|
}
|
2023-02-16 18:43:22 -06:00
|
|
|
|
|
|
|
|
public void setScaleX(float scale1, float scale2, float scaleRate, int scaleRateStart){
|
|
|
|
|
this.scaleX1 = scale1;
|
|
|
|
|
this.scaleX2 = scale2;
|
|
|
|
|
this.scaleXRate = scaleRate;
|
|
|
|
|
this.scaleXRateStart = scaleRateStart;
|
|
|
|
|
}
|
|
|
|
|
public float getScaleX1() {
|
|
|
|
|
return scaleX1;
|
|
|
|
|
}
|
|
|
|
|
public float getScaleX2() {
|
|
|
|
|
return scaleX2;
|
|
|
|
|
}
|
|
|
|
|
public float getScaleXRate() {
|
|
|
|
|
return scaleXRate;
|
|
|
|
|
}
|
|
|
|
|
public int getScaleXRateStart() {
|
|
|
|
|
return scaleXRateStart;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setScaleY(float scale1, float scale2, float scaleRate, int scaleRateStart){
|
|
|
|
|
this.scaleY1 = scale1;
|
|
|
|
|
this.scaleY2 = scale2;
|
|
|
|
|
this.scaleYRate = scaleRate;
|
|
|
|
|
this.scaleYRateStart = scaleRateStart;
|
|
|
|
|
}
|
|
|
|
|
public float getScaleY1() {
|
|
|
|
|
return scaleY1;
|
2022-03-02 18:18:03 -06:00
|
|
|
}
|
2023-02-16 18:43:22 -06:00
|
|
|
public float getScaleY2() {
|
|
|
|
|
return scaleY2;
|
2022-03-02 18:18:03 -06:00
|
|
|
}
|
2023-02-16 18:43:22 -06:00
|
|
|
public float getScaleYRate() {
|
|
|
|
|
return scaleYRate;
|
2022-03-02 18:18:03 -06:00
|
|
|
}
|
2023-02-16 18:43:22 -06:00
|
|
|
public int getScaleYRateStart() {
|
|
|
|
|
return scaleYRateStart;
|
2021-09-08 13:41:57 -05:00
|
|
|
}
|
|
|
|
|
|
2022-03-02 18:18:03 -06:00
|
|
|
public void setRotationX(float rotationX1, float rotationX2, float rotationXRate, int rotationXRateStart){
|
|
|
|
|
this.rotationX1 = rotationX1;
|
|
|
|
|
this.rotationX2 = rotationX2;
|
|
|
|
|
this.rotationXRate = rotationXRate;
|
|
|
|
|
this.rotationXRateStart = rotationXRateStart;
|
|
|
|
|
}
|
2022-05-17 05:35:08 -05:00
|
|
|
public float getRotationX1() {return rotationX1;}
|
|
|
|
|
public float getRotationX2() {return rotationX2;}
|
|
|
|
|
public float getRotationXRate() {return rotationXRate;}
|
|
|
|
|
public int getRotationXRateStart() {return rotationXRateStart;}
|
2022-03-02 18:18:03 -06:00
|
|
|
|
|
|
|
|
public void setRotationY(float rotationY1, float rotationY2, float rotationYRate, int rotationYRateStart){
|
|
|
|
|
this.rotationY1 = rotationY1;
|
|
|
|
|
this.rotationY2 = rotationY2;
|
|
|
|
|
this.rotationYRate = rotationYRate;
|
|
|
|
|
this.rotationYRateStart = rotationYRateStart;
|
|
|
|
|
}
|
2022-05-17 05:35:08 -05:00
|
|
|
public float getRotationY1() {return rotationY1;}
|
|
|
|
|
public float getRotationY2() {return rotationY2;}
|
|
|
|
|
public float getRotationYRate() {return rotationYRate;}
|
|
|
|
|
public int getRotationYRateStart() {return rotationYRateStart;}
|
2022-03-02 18:18:03 -06:00
|
|
|
|
|
|
|
|
public void setRotationZ(float rotationZ1, float rotationZ2, float rotationZRate, int rotationZRateStart){
|
|
|
|
|
this.rotationZ1 = rotationZ1;
|
|
|
|
|
this.rotationZ2 = rotationZ2;
|
|
|
|
|
this.rotationZRate = rotationZRate;
|
|
|
|
|
this.rotationZRateStart = rotationZRateStart;
|
|
|
|
|
}
|
2022-05-17 05:35:08 -05:00
|
|
|
public float getRotationZ1() {return rotationZ1;}
|
|
|
|
|
public float getRotationZ2() {return rotationZ2;}
|
|
|
|
|
public float getRotationZRate() {return rotationZRate;}
|
|
|
|
|
public int getRotationZRateStart() {return rotationZRateStart;}
|
|
|
|
|
|
|
|
|
|
@Deprecated
|
|
|
|
|
public void setHEXColor(int HEXColor) {
|
|
|
|
|
this.HEXColor = HEXColor;
|
|
|
|
|
}
|
|
|
|
|
@Deprecated
|
|
|
|
|
public int getHEXColor() {
|
|
|
|
|
return HEXColor;
|
|
|
|
|
}
|
2021-09-08 13:41:57 -05:00
|
|
|
}
|