2022-05-11 01:10:31 -05:00
|
|
|
package noppes.npcs.scripted.item;
|
|
|
|
|
|
|
|
|
|
import cpw.mods.fml.common.eventhandler.Event;
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
|
import noppes.npcs.EventHooks;
|
|
|
|
|
import noppes.npcs.NBTTags;
|
2023-01-12 21:33:06 -05:00
|
|
|
import noppes.npcs.api.item.IItemCustom;
|
2022-05-11 01:10:31 -05:00
|
|
|
import noppes.npcs.constants.EnumScriptType;
|
|
|
|
|
import noppes.npcs.controllers.ScriptContainer;
|
|
|
|
|
import noppes.npcs.controllers.ScriptController;
|
2023-01-12 21:33:06 -05:00
|
|
|
import noppes.npcs.controllers.data.IScriptHandler;
|
2022-05-11 01:10:31 -05:00
|
|
|
import noppes.npcs.scripted.CustomNPCsException;
|
|
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
2022-05-11 17:12:48 -05:00
|
|
|
public class ScriptCustomItem extends ScriptItemStack implements IItemCustom, IScriptHandler {
|
2022-05-11 01:10:31 -05:00
|
|
|
public List<ScriptContainer> scripts = new ArrayList();
|
2022-07-03 09:46:40 -05:00
|
|
|
public List<Integer> errored = new ArrayList();
|
2022-05-11 01:10:31 -05:00
|
|
|
public String scriptLanguage = "ECMAScript";
|
|
|
|
|
public boolean enabled = false;
|
|
|
|
|
public long lastInited = -1L;
|
2022-05-11 02:07:06 -05:00
|
|
|
public boolean loaded = false;
|
2022-05-11 01:10:31 -05:00
|
|
|
|
|
|
|
|
public boolean durabilityShow = false;
|
|
|
|
|
public double durabilityValue = 1.0D;
|
|
|
|
|
public int durabilityColor = -1;
|
|
|
|
|
public int itemColor = 0x8B4513;
|
|
|
|
|
public int stackSize = 64;
|
2022-05-11 02:33:56 -05:00
|
|
|
|
2022-05-11 01:10:31 -05:00
|
|
|
public int maxItemUseDuration = 20;
|
2022-05-11 02:33:56 -05:00
|
|
|
public int itemUseAction = 0; //0: none, 1: block, 2: bow, 3: eat, 4: drink
|
2022-05-11 02:07:06 -05:00
|
|
|
|
|
|
|
|
public boolean isTool = false;
|
|
|
|
|
public int digSpeed = 1;
|
|
|
|
|
public int armorType = -2; //-2: Fits in no armor slot, -1: Fits in all slots, 0 - 4: Fits in Head -> Boots slot respectively
|
|
|
|
|
public int enchantability;
|
2022-05-11 01:10:31 -05:00
|
|
|
|
|
|
|
|
public String texture = "minecraft:textures/items/iron_pickaxe.png";
|
|
|
|
|
|
|
|
|
|
public float translateX, translateY, translateZ;
|
|
|
|
|
public float scaleX = 1.0F, scaleY = 1.0F, scaleZ = 1.0F;
|
|
|
|
|
public float rotationX, rotationY, rotationZ;
|
2022-05-11 14:24:12 -05:00
|
|
|
public float rotationXRate, rotationYRate, rotationZRate;
|
2022-05-11 01:10:31 -05:00
|
|
|
|
|
|
|
|
public ScriptCustomItem(ItemStack item) {
|
|
|
|
|
super(item);
|
|
|
|
|
loadScriptData();
|
|
|
|
|
loadItemData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public NBTTagCompound getScriptNBT(NBTTagCompound compound) {
|
|
|
|
|
compound.setTag("Scripts", NBTTags.NBTScript(this.scripts));
|
|
|
|
|
compound.setString("ScriptLanguage", this.scriptLanguage);
|
|
|
|
|
compound.setBoolean("ScriptEnabled", this.enabled);
|
|
|
|
|
return compound;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setScriptNBT(NBTTagCompound compound) {
|
|
|
|
|
if (compound.hasKey("Scripts")) {
|
2023-02-19 13:38:43 -06:00
|
|
|
this.scripts = NBTTags.GetScriptOld(compound.getTagList("Scripts", 10), this);
|
2022-05-11 01:10:31 -05:00
|
|
|
this.scriptLanguage = compound.getString("ScriptLanguage");
|
|
|
|
|
this.enabled = compound.getBoolean("ScriptEnabled");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getType() {
|
|
|
|
|
return 6;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void callScript(EnumScriptType type, Event event) {
|
|
|
|
|
if (!this.loaded) {
|
|
|
|
|
this.loadScriptData();
|
|
|
|
|
this.loaded = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.isEnabled()) {
|
|
|
|
|
if (ScriptController.Instance.lastLoaded > this.lastInited) {
|
|
|
|
|
this.lastInited = ScriptController.Instance.lastLoaded;
|
|
|
|
|
if (type != EnumScriptType.INIT) {
|
|
|
|
|
EventHooks.onScriptItemInit(this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-03 09:46:40 -05:00
|
|
|
for (int i = 0; i < this.scripts.size(); i++) {
|
|
|
|
|
ScriptContainer script = this.scripts.get(i);
|
|
|
|
|
if (!this.errored.contains(i)) {
|
|
|
|
|
if(script == null || script.errored || !script.hasCode())
|
2023-01-29 18:01:00 -06:00
|
|
|
continue;
|
2022-05-11 01:10:31 -05:00
|
|
|
|
2022-07-03 09:46:40 -05:00
|
|
|
script.run(type, event);
|
|
|
|
|
|
|
|
|
|
if (script.errored) {
|
|
|
|
|
this.errored.add(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-05-11 01:10:31 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean isEnabled() {
|
|
|
|
|
return this.enabled && ScriptController.HasStart;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isClient() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean getEnabled() {
|
|
|
|
|
return this.enabled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setEnabled(boolean bo) {
|
|
|
|
|
this.enabled = bo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getLanguage() {
|
|
|
|
|
return this.scriptLanguage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setLanguage(String lang) {
|
|
|
|
|
this.scriptLanguage = lang;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-19 16:22:28 -06:00
|
|
|
public void setScripts(List<ScriptContainer> list) {
|
|
|
|
|
this.scripts = list;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-11 01:10:31 -05:00
|
|
|
public List<ScriptContainer> getScripts() {
|
|
|
|
|
return this.scripts;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String noticeString() {
|
|
|
|
|
return "ScriptedItem";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Map<Long, String> getConsoleText() {
|
2023-03-29 21:35:16 -05:00
|
|
|
return new TreeMap<>();
|
2022-05-11 01:10:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void clearConsole() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getTexture() {
|
|
|
|
|
return this.texture == null ? "" : this.texture;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setTexture(String texture){
|
|
|
|
|
if(texture == null)
|
|
|
|
|
texture = "";
|
|
|
|
|
this.texture = texture;
|
|
|
|
|
saveItemData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getMaxStackSize() {
|
|
|
|
|
return this.stackSize;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-02 03:15:38 -05:00
|
|
|
public void setArmorType(int armorType) {
|
2022-05-11 02:07:06 -05:00
|
|
|
this.armorType = armorType;
|
|
|
|
|
saveItemData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getArmorType(){
|
|
|
|
|
return this.armorType;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setIsTool(boolean isTool){
|
|
|
|
|
this.isTool = isTool;
|
|
|
|
|
saveItemData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isTool(){
|
|
|
|
|
return this.isTool;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setDigSpeed(int digSpeed){
|
|
|
|
|
this.digSpeed = digSpeed;
|
|
|
|
|
saveItemData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getDigSpeed(){
|
|
|
|
|
return this.digSpeed;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-11 01:10:31 -05:00
|
|
|
public void setMaxStackSize(int size) {
|
2022-07-02 03:14:06 -05:00
|
|
|
if (size >= 1 && size <= 127) {
|
2022-05-11 01:10:31 -05:00
|
|
|
this.stackSize = size;
|
|
|
|
|
saveItemData();
|
|
|
|
|
} else {
|
2022-07-02 03:14:06 -05:00
|
|
|
throw new CustomNPCsException("Stacksize has to be between 1 and 127", new Object[0]);
|
2022-05-11 01:10:31 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public double getDurabilityValue() {
|
|
|
|
|
return this.durabilityValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setDurabilityValue(float value) {
|
|
|
|
|
this.durabilityValue = (double)value;
|
|
|
|
|
saveItemData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean getDurabilityShow() {
|
|
|
|
|
return this.durabilityShow;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setDurabilityShow(boolean bo) {
|
|
|
|
|
this.durabilityShow = bo;
|
|
|
|
|
saveItemData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getDurabilityColor() {
|
|
|
|
|
return this.durabilityColor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setDurabilityColor(int color) {
|
|
|
|
|
this.durabilityColor = color;
|
|
|
|
|
saveItemData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getColor() {
|
|
|
|
|
return this.itemColor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setColor(int color) {
|
|
|
|
|
this.itemColor = color;
|
|
|
|
|
saveItemData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getMaxItemUseDuration(){
|
|
|
|
|
return this.maxItemUseDuration;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-11 02:33:56 -05:00
|
|
|
public void setMaxItemUseDuration(int duration) {
|
2022-05-11 01:10:31 -05:00
|
|
|
this.maxItemUseDuration = duration;
|
|
|
|
|
saveItemData();
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-11 02:33:56 -05:00
|
|
|
public void setItemUseAction(int action) {
|
|
|
|
|
this.itemUseAction = action;
|
|
|
|
|
saveItemData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getItemUseAction() {
|
|
|
|
|
return this.itemUseAction;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-11 02:07:06 -05:00
|
|
|
public int getEnchantability(){
|
|
|
|
|
return this.enchantability;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setEnchantability(int enchantability){
|
|
|
|
|
this.enchantability = enchantability;
|
|
|
|
|
saveItemData();
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-11 01:10:31 -05:00
|
|
|
public void setRotation(float rotationX, float rotationY, float rotationZ){
|
|
|
|
|
this.rotationX = rotationX;
|
|
|
|
|
this.rotationY = rotationY;
|
|
|
|
|
this.rotationZ = rotationZ;
|
|
|
|
|
saveItemData();
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-11 14:24:12 -05:00
|
|
|
public void setRotationRate(float rotationXRate, float rotationYRate, float rotationZRate){
|
|
|
|
|
this.rotationXRate = rotationXRate;
|
|
|
|
|
this.rotationYRate = rotationYRate;
|
|
|
|
|
this.rotationZRate = rotationZRate;
|
|
|
|
|
saveItemData();
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-11 01:10:31 -05:00
|
|
|
public void setScale(float scaleX, float scaleY, float scaleZ){
|
|
|
|
|
this.scaleX = scaleX;
|
|
|
|
|
this.scaleY = scaleY;
|
|
|
|
|
this.scaleZ = scaleZ;
|
|
|
|
|
saveItemData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setTranslate(float translateX, float translateY, float translateZ){
|
|
|
|
|
this.translateX = translateX;
|
|
|
|
|
this.translateY = translateY;
|
|
|
|
|
this.translateZ = translateZ;
|
|
|
|
|
saveItemData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float getRotationX() {
|
|
|
|
|
return rotationX;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float getRotationY() {
|
|
|
|
|
return rotationY;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float getRotationZ() {
|
|
|
|
|
return rotationZ;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-11 14:24:12 -05:00
|
|
|
public float getRotationXRate() {
|
|
|
|
|
return rotationXRate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float getRotationYRate() {
|
|
|
|
|
return rotationYRate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float getRotationZRate() {
|
|
|
|
|
return rotationZRate;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-11 01:10:31 -05:00
|
|
|
public float getScaleX() {
|
|
|
|
|
return scaleX;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float getScaleY() {
|
|
|
|
|
return scaleY;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float getScaleZ() {
|
|
|
|
|
return scaleZ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float getTranslateX() {
|
|
|
|
|
return translateX;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float getTranslateY() {
|
|
|
|
|
return translateY;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float getTranslateZ() {
|
|
|
|
|
return translateZ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public NBTTagCompound getMCNbt() {
|
|
|
|
|
NBTTagCompound compound = super.getMCNbt();
|
|
|
|
|
compound.setTag("ItemData", this.getItemNBT(new NBTTagCompound()));
|
|
|
|
|
compound.setTag("ScriptedData", this.getScriptNBT(new NBTTagCompound()));
|
|
|
|
|
return compound;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setMCNbt(NBTTagCompound compound) {
|
|
|
|
|
setScriptNBT(compound.getCompoundTag("ScriptedData"));
|
|
|
|
|
setItemNBT(compound.getCompoundTag("ItemData"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public NBTTagCompound getItemNBT(NBTTagCompound compound) {
|
|
|
|
|
compound.setBoolean("DurabilityShow",this.durabilityShow);
|
|
|
|
|
compound.setDouble("DurabilityValue",this.durabilityValue);
|
|
|
|
|
compound.setInteger("DurabilityColor",this.durabilityColor );
|
|
|
|
|
compound.setInteger("ItemColor",this.itemColor);
|
|
|
|
|
compound.setInteger("MaxStackSize",this.stackSize);
|
|
|
|
|
compound.setString("ItemTexture",this.texture);
|
|
|
|
|
|
|
|
|
|
compound.setFloat("RotationX",this.rotationX);
|
|
|
|
|
compound.setFloat("RotationY",this.rotationY);
|
|
|
|
|
compound.setFloat("RotationZ",this.rotationZ);
|
|
|
|
|
|
2022-05-11 14:24:12 -05:00
|
|
|
compound.setFloat("RotationXRate",this.rotationXRate);
|
|
|
|
|
compound.setFloat("RotationYRate",this.rotationYRate);
|
|
|
|
|
compound.setFloat("RotationZRate",this.rotationZRate);
|
|
|
|
|
|
2022-05-11 01:10:31 -05:00
|
|
|
compound.setFloat("ScaleX",this.scaleX);
|
|
|
|
|
compound.setFloat("ScaleY",this.scaleY);
|
|
|
|
|
compound.setFloat("ScaleZ",this.scaleZ);
|
|
|
|
|
|
|
|
|
|
compound.setFloat("TranslateX",this.translateX);
|
|
|
|
|
compound.setFloat("TranslateY",this.translateY);
|
|
|
|
|
compound.setFloat("TranslateZ",this.translateZ);
|
|
|
|
|
|
2022-05-11 02:07:06 -05:00
|
|
|
compound.setBoolean("IsTool", this.isTool);
|
|
|
|
|
compound.setInteger("DigSpeed", this.digSpeed);
|
|
|
|
|
compound.setInteger("ArmorType", this.armorType);
|
|
|
|
|
compound.setInteger("Enchantability", this.enchantability);
|
2022-05-11 02:33:56 -05:00
|
|
|
|
|
|
|
|
compound.setInteger("MaxItemUseDuration", this.maxItemUseDuration);
|
|
|
|
|
compound.setInteger("ItemUseAction", this.itemUseAction);
|
2022-05-11 01:10:31 -05:00
|
|
|
return compound;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setItemNBT(NBTTagCompound compound) {
|
|
|
|
|
this.durabilityShow = compound.getBoolean("DurabilityShow");
|
|
|
|
|
this.durabilityValue = compound.getDouble("DurabilityValue");
|
|
|
|
|
if (compound.hasKey("DurabilityColor")) {
|
|
|
|
|
this.durabilityColor = compound.getInteger("DurabilityColor");
|
|
|
|
|
}
|
|
|
|
|
this.itemColor = compound.getInteger("ItemColor");
|
|
|
|
|
this.stackSize = compound.getInteger("MaxStackSize");
|
|
|
|
|
this.texture = compound.getString("ItemTexture");
|
|
|
|
|
|
|
|
|
|
this.rotationX = compound.getFloat("RotationX");
|
|
|
|
|
this.rotationY = compound.getFloat("RotationY");
|
|
|
|
|
this.rotationZ = compound.getFloat("RotationZ");
|
|
|
|
|
|
2022-05-11 14:24:12 -05:00
|
|
|
this.rotationXRate = compound.getFloat("RotationXRate");
|
|
|
|
|
this.rotationYRate = compound.getFloat("RotationYRate");
|
|
|
|
|
this.rotationZRate = compound.getFloat("RotationZRate");
|
|
|
|
|
|
2022-05-11 01:10:31 -05:00
|
|
|
this.scaleX = compound.getFloat("ScaleX");
|
|
|
|
|
this.scaleY = compound.getFloat("ScaleY");
|
|
|
|
|
this.scaleZ = compound.getFloat("ScaleZ");
|
|
|
|
|
|
|
|
|
|
this.translateX = compound.getFloat("TranslateX");
|
|
|
|
|
this.translateY = compound.getFloat("TranslateY");
|
|
|
|
|
this.translateZ = compound.getFloat("TranslateZ");
|
|
|
|
|
|
2022-05-11 02:07:06 -05:00
|
|
|
this.isTool = compound.getBoolean("IsTool");
|
|
|
|
|
this.digSpeed = compound.getInteger("DigSpeed");
|
|
|
|
|
this.armorType = compound.getInteger("ArmorType");
|
|
|
|
|
this.enchantability = compound.getInteger("Enchantability");
|
2022-05-11 02:33:56 -05:00
|
|
|
|
|
|
|
|
this.maxItemUseDuration = compound.getInteger("MaxItemUseDuration");
|
|
|
|
|
this.itemUseAction = compound.getInteger("ItemUseAction");
|
2022-05-11 01:10:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void saveScriptData() {
|
|
|
|
|
NBTTagCompound c = this.item.getTagCompound();
|
|
|
|
|
if (c == null) {
|
|
|
|
|
this.item.setTagCompound(c = new NBTTagCompound());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c.setTag("ScriptedData", this.getScriptNBT(new NBTTagCompound()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void loadScriptData() {
|
|
|
|
|
NBTTagCompound c = this.item.getTagCompound();
|
|
|
|
|
if (c != null) {
|
|
|
|
|
this.setScriptNBT(c.getCompoundTag("ScriptedData"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void saveItemData() {
|
|
|
|
|
NBTTagCompound c = this.item.getTagCompound();
|
|
|
|
|
if (c == null) {
|
|
|
|
|
this.item.setTagCompound(c = new NBTTagCompound());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c.setTag("ItemData", this.getItemNBT(new NBTTagCompound()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void loadItemData() {
|
|
|
|
|
NBTTagCompound c = this.item.getTagCompound();
|
|
|
|
|
if (c != null){
|
|
|
|
|
this.setItemNBT(c.getCompoundTag("ItemData"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|