Merge branch 'packet' into animation-events-2

This commit is contained in:
Kam committed 2025-02-14 15:22:59 -05:00
commit 25d917c338
19 files changed
+1029 -773

No files matched your search

+13 -6
View File
@@ -48,13 +48,11 @@ import noppes.npcs.config.ConfigScript;
import noppes.npcs.constants.EnumAnimationPart;
import noppes.npcs.containers.ContainerNpcInterface;
import noppes.npcs.controllers.*;
import noppes.npcs.controllers.data.Animation;
import noppes.npcs.controllers.data.Frame;
import noppes.npcs.controllers.data.FramePart;
import noppes.npcs.controllers.data.SkinOverlay;
import noppes.npcs.controllers.data.*;
import noppes.npcs.entity.EntityCustomNpc;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.entity.EntityProjectile;
import noppes.npcs.items.ItemLinked;
import noppes.npcs.items.ItemScripted;
import noppes.npcs.scripted.entity.*;
import noppes.npcs.scripted.gui.ScriptGui;
@@ -64,7 +62,6 @@ import noppes.npcs.util.*;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;
import java.util.concurrent.ExecutorService;
@@ -473,7 +470,17 @@ public class NpcAPI extends AbstractNpcAPI {
if (scriptItemCache.containsKey(itemstack)) {
scriptStack = scriptItemCache.get(itemstack).getObject();
} else {
if (itemstack.getItem() instanceof ItemScripted) {
LinkedItem linkedItem;
if (itemstack.hasTagCompound()) {
int linkedItemId = itemstack.getTagCompound().getInteger(LinkedItem.LINKED_NBT_TAG);
linkedItem = LinkedItemController.Instance().get(linkedItemId);
} else {
linkedItem = null;
}
if (linkedItem != null && itemstack.getItem() instanceof ItemLinked) {
scriptStack = new ScriptLinkedItem(itemstack);
} else if (itemstack.getItem() instanceof ItemScripted) {
scriptStack = new ScriptCustomItem(itemstack);
} else if (itemstack.getItem() instanceof ItemArmor) {
scriptStack = new ScriptItemArmor(itemstack);
@@ -5,16 +5,17 @@ import noppes.npcs.api.entity.IEntity;
import noppes.npcs.api.entity.IPlayer;
import noppes.npcs.api.event.IItemEvent;
import noppes.npcs.api.item.IItemCustom;
import noppes.npcs.api.item.IItemCustomizable;
import noppes.npcs.constants.EnumScriptType;
public class ItemEvent extends CustomNPCsEvent implements IItemEvent {
public final IItemCustom item;
public final IItemCustomizable item;
public ItemEvent(IItemCustom item) {
public ItemEvent(IItemCustomizable item) {
this.item = item;
}
public IItemCustom getItem() {
public IItemCustomizable getItem() {
return item;
}
@@ -23,7 +24,7 @@ public class ItemEvent extends CustomNPCsEvent implements IItemEvent {
}
public static class InitEvent extends ItemEvent implements IItemEvent.InitEvent {
public InitEvent(IItemCustom item) {
public InitEvent(IItemCustomizable item) {
super(item);
}
@@ -35,7 +36,7 @@ public class ItemEvent extends CustomNPCsEvent implements IItemEvent {
public static class UpdateEvent extends ItemEvent implements IItemEvent.UpdateEvent {
public final IEntity entity;
public UpdateEvent(IItemCustom item, IEntity entity) {
public UpdateEvent(IItemCustomizable item, IEntity entity) {
super(item);
this.entity = entity;
}
@@ -54,7 +55,7 @@ public class ItemEvent extends CustomNPCsEvent implements IItemEvent {
public final IEntity entity;
public final IPlayer player;
public TossedEvent(IItemCustom item, IPlayer player, IEntity entity) {
public TossedEvent(IItemCustomizable item, IPlayer player, IEntity entity) {
super(item);
this.entity = entity;
this.player = player;
@@ -76,7 +77,7 @@ public class ItemEvent extends CustomNPCsEvent implements IItemEvent {
public static class PickedUpEvent extends ItemEvent implements IItemEvent.PickedUpEvent {
public final IPlayer player;
public PickedUpEvent(IItemCustom item, IPlayer player) {
public PickedUpEvent(IItemCustomizable item, IPlayer player) {
super(item);
this.player = player;
}
@@ -94,7 +95,7 @@ public class ItemEvent extends CustomNPCsEvent implements IItemEvent {
public static class SpawnEvent extends ItemEvent implements IItemEvent.SpawnEvent {
public final IEntity entity;
public SpawnEvent(IItemCustom item, IEntity entity){
public SpawnEvent(IItemCustomizable item, IEntity entity){
super(item);
this.entity = entity;
}
@@ -114,7 +115,7 @@ public class ItemEvent extends CustomNPCsEvent implements IItemEvent {
public final IEntity target;
public final IPlayer player;
public InteractEvent(IItemCustom item, IPlayer player, int type, IEntity target) {
public InteractEvent(IItemCustomizable item, IPlayer player, int type, IEntity target) {
super(item);
this.type = type;
this.target = target;
@@ -148,7 +149,7 @@ public class ItemEvent extends CustomNPCsEvent implements IItemEvent {
public final Object target;
public final IPlayer player;
public RightClickEvent(IItemCustom item, IPlayer player, int type, Object target) {
public RightClickEvent(IItemCustomizable item, IPlayer player, int type, Object target) {
super(item);
this.type = type;
this.target = target;
@@ -178,7 +179,7 @@ public class ItemEvent extends CustomNPCsEvent implements IItemEvent {
public final IEntity target;
public final IEntity swingingEntity;
public AttackEvent(IItemCustom item, IEntity swingingEntity, int type, IEntity target) {
public AttackEvent(IItemCustomizable item, IEntity swingingEntity, int type, IEntity target) {
super(item);
this.type = type;
this.target = target;
@@ -207,7 +208,7 @@ public class ItemEvent extends CustomNPCsEvent implements IItemEvent {
public final IPlayer player;
public final int duration;
public StartUsingItem(IItemCustom item, IPlayer player, int duration){
public StartUsingItem(IItemCustomizable item, IPlayer player, int duration){
super(item);
this.player = player;
this.duration = duration;
@@ -231,7 +232,7 @@ public class ItemEvent extends CustomNPCsEvent implements IItemEvent {
public final IPlayer player;
public final int duration;
public UsingItem(IItemCustom item, IPlayer player, int duration){
public UsingItem(IItemCustomizable item, IPlayer player, int duration){
super(item);
this.player = player;
this.duration = duration;
@@ -255,7 +256,7 @@ public class ItemEvent extends CustomNPCsEvent implements IItemEvent {
public final IPlayer player;
public final int duration;
public StopUsingItem(IItemCustom item, IPlayer player, int duration){
public StopUsingItem(IItemCustomizable item, IPlayer player, int duration){
super(item);
this.player = player;
this.duration = duration;
@@ -279,7 +280,7 @@ public class ItemEvent extends CustomNPCsEvent implements IItemEvent {
public final IPlayer player;
public final int duration;
public FinishUsingItem(IItemCustom item, IPlayer player, int duration){
public FinishUsingItem(IItemCustomizable item, IPlayer player, int duration){
super(item);
this.player = player;
this.duration = duration;
@@ -14,7 +14,7 @@ import noppes.npcs.scripted.CustomNPCsException;
import java.util.*;
public class ScriptCustomItem extends ScriptItemStack implements IItemCustom, INpcScriptHandler {
public class ScriptCustomItem extends ScriptCustomizableItem implements IItemCustom, INpcScriptHandler {
public List<ScriptContainer> scripts = new ArrayList();
public List<Integer> errored = new ArrayList();
public String scriptLanguage = "ECMAScript";
@@ -33,8 +33,6 @@ public class ScriptCustomItem extends ScriptItemStack implements IItemCustom, IN
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;
public Display itemDisplay = new Display();
public long lastInited = -1;
public ScriptCustomItem(ItemStack item) {
@@ -65,6 +63,11 @@ public class ScriptCustomItem extends ScriptItemStack implements IItemCustom, IN
return this.enabled && ScriptController.HasStart;
}
@Override
public INpcScriptHandler getScriptHandler() {
return this;
}
public void callScript(EnumScriptType type, Event event) {
this.callScript(type.function, event);
}
@@ -140,17 +143,6 @@ public class ScriptCustomItem extends ScriptItemStack implements IItemCustom, IN
public void clearConsole() {
}
public String getTexture() {
return this.itemDisplay.texture == null ? "" : this.itemDisplay.texture;
}
public void setTexture(String texture){
if(texture == null)
texture = "";
this.itemDisplay.texture = texture;
saveItemData();
}
public int getMaxStackSize() {
return this.stackSize;
}
@@ -210,33 +202,6 @@ public class ScriptCustomItem extends ScriptItemStack implements IItemCustom, IN
saveItemData();
}
public boolean getDurabilityShow() {
return this.itemDisplay.durabilityShow;
}
public void setDurabilityShow(boolean bo) {
this.itemDisplay.durabilityShow = bo;
saveItemData();
}
public int getDurabilityColor() {
return this.itemDisplay.durabilityColor;
}
public void setDurabilityColor(int color) {
this.itemDisplay.durabilityColor = color;
saveItemData();
}
public int getColor() {
return this.itemDisplay.itemColor;
}
public void setColor(int color) {
this.itemDisplay.itemColor = color;
saveItemData();
}
public int getMaxItemUseDuration(){
return this.maxItemUseDuration;
}
@@ -264,165 +229,6 @@ public class ScriptCustomItem extends ScriptItemStack implements IItemCustom, IN
saveItemData();
}
public void setRotation(float rotationX, float rotationY, float rotationZ){
this.itemDisplay.rotationX = rotationX;
this.itemDisplay.rotationY = rotationY;
this.itemDisplay.rotationZ = rotationZ;
saveItemData();
}
public void setRotationRate(float rotationXRate, float rotationYRate, float rotationZRate){
this.itemDisplay.rotationXRate = rotationXRate;
this.itemDisplay.rotationYRate = rotationYRate;
this.itemDisplay.rotationZRate = rotationZRate;
saveItemData();
}
public void setScale(float scaleX, float scaleY, float scaleZ){
this.itemDisplay.scaleX = scaleX;
this.itemDisplay.scaleY = scaleY;
this.itemDisplay.scaleZ = scaleZ;
saveItemData();
}
public void setTranslate(float translateX, float translateY, float translateZ){
this.itemDisplay.translateX = translateX;
this.itemDisplay.translateY = translateY;
this.itemDisplay.translateZ = translateZ;
saveItemData();
}
public float getRotationX() {
return this.itemDisplay.rotationX;
}
public float getRotationY() {
return this.itemDisplay.rotationY;
}
public float getRotationZ() {
return this.itemDisplay.rotationZ;
}
public float getRotationXRate() {
return this.itemDisplay.rotationXRate;
}
public float getRotationYRate() {
return this.itemDisplay.rotationYRate;
}
public float getRotationZRate() {
return this.itemDisplay.rotationZRate;
}
public float getScaleX() {
return this.itemDisplay.scaleX;
}
public float getScaleY() {
return this.itemDisplay.scaleY;
}
public float getScaleZ() {
return this.itemDisplay.scaleZ;
}
public float getTranslateX() {
return this.itemDisplay.translateX;
}
public float getTranslateY() {
return this.itemDisplay.translateY;
}
public float getTranslateZ() {
return this.itemDisplay.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.itemDisplay.durabilityShow);
compound.setDouble("DurabilityValue",this.durabilityValue);
compound.setInteger("DurabilityColor",this.itemDisplay.durabilityColor );
compound.setInteger("ItemColor",this.itemDisplay.itemColor);
compound.setInteger("MaxStackSize",this.stackSize);
compound.setString("ItemTexture",this.itemDisplay.texture);
compound.setFloat("RotationX",this.itemDisplay.rotationX);
compound.setFloat("RotationY",this.itemDisplay.rotationY);
compound.setFloat("RotationZ",this.itemDisplay.rotationZ);
compound.setFloat("RotationXRate",this.itemDisplay.rotationXRate);
compound.setFloat("RotationYRate",this.itemDisplay.rotationYRate);
compound.setFloat("RotationZRate",this.itemDisplay.rotationZRate);
compound.setFloat("ScaleX",this.itemDisplay.scaleX);
compound.setFloat("ScaleY",this.itemDisplay.scaleY);
compound.setFloat("ScaleZ",this.itemDisplay.scaleZ);
compound.setFloat("TranslateX",this.itemDisplay.translateX);
compound.setFloat("TranslateY",this.itemDisplay.translateY);
compound.setFloat("TranslateZ",this.itemDisplay.translateZ);
compound.setBoolean("IsTool", this.isTool);
compound.setBoolean("IsNormalItem", this.isNormalItem);
compound.setInteger("DigSpeed", this.digSpeed);
compound.setInteger("ArmorType", this.armorType);
compound.setInteger("Enchantability", this.enchantability);
compound.setInteger("MaxItemUseDuration", this.maxItemUseDuration);
compound.setInteger("ItemUseAction", this.itemUseAction);
return compound;
}
public void setItemNBT(NBTTagCompound compound) {
this.itemDisplay.durabilityShow = compound.getBoolean("DurabilityShow");
this.durabilityValue = compound.getDouble("DurabilityValue");
if (compound.hasKey("DurabilityColor")) {
this.itemDisplay.durabilityColor = compound.getInteger("DurabilityColor");
}
this.itemDisplay.itemColor = compound.getInteger("ItemColor");
this.stackSize = compound.getInteger("MaxStackSize");
this.itemDisplay.texture = compound.getString("ItemTexture");
this.itemDisplay.rotationX = compound.getFloat("RotationX");
this.itemDisplay.rotationY = compound.getFloat("RotationY");
this.itemDisplay.rotationZ = compound.getFloat("RotationZ");
this.itemDisplay.rotationXRate = compound.getFloat("RotationXRate");
this.itemDisplay.rotationYRate = compound.getFloat("RotationYRate");
this.itemDisplay.rotationZRate = compound.getFloat("RotationZRate");
this.itemDisplay.scaleX = compound.getFloat("ScaleX");
this.itemDisplay.scaleY = compound.getFloat("ScaleY");
this.itemDisplay.scaleZ = compound.getFloat("ScaleZ");
this.itemDisplay.translateX = compound.getFloat("TranslateX");
this.itemDisplay.translateY = compound.getFloat("TranslateY");
this.itemDisplay.translateZ = compound.getFloat("TranslateZ");
this.isTool = compound.getBoolean("IsTool");
this.isNormalItem = compound.getBoolean("IsNormalItem");
this.digSpeed = compound.getInteger("DigSpeed");
this.armorType = compound.getInteger("ArmorType");
this.enchantability = compound.getInteger("Enchantability");
this.maxItemUseDuration = compound.getInteger("MaxItemUseDuration");
this.itemUseAction = compound.getInteger("ItemUseAction");
}
public void saveScriptData() {
NBTTagCompound c = this.item.getTagCompound();
if (c == null) {
@@ -439,31 +245,45 @@ public class ScriptCustomItem extends ScriptItemStack implements IItemCustom, IN
}
}
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 NBTTagCompound getMCNbt() {
NBTTagCompound compound = super.getMCNbt();
compound.setTag("ScriptedData", this.getScriptNBT(new NBTTagCompound()));
return compound;
}
public void loadItemData() {
NBTTagCompound c = this.item.getTagCompound();
if (c != null && !c.getCompoundTag("ItemData").hasNoTags()){
this.setItemNBT(c.getCompoundTag("ItemData"));
}
public void setMCNbt(NBTTagCompound compound) {
super.setMCNbt(compound);
setScriptNBT(compound.getCompoundTag("ScriptedData"));
}
public NBTTagCompound getItemNBT(NBTTagCompound compound) {
super.getItemNBT(compound);
compound.setDouble("DurabilityValue",this.durabilityValue);
compound.setInteger("MaxStackSize",this.stackSize);
public static class Display {
public String texture = "minecraft:textures/items/iron_pickaxe.png";
public float translateX, translateY, translateZ;
public int itemColor = 0x8B4513;
public float scaleX = 1.0F, scaleY = 1.0F, scaleZ = 1.0F;
public float rotationX, rotationY, rotationZ;
public float rotationXRate, rotationYRate, rotationZRate;
public boolean durabilityShow = false;
public int durabilityColor = -1;
compound.setBoolean("IsTool", this.isTool);
compound.setBoolean("IsNormalItem", this.isNormalItem);
compound.setInteger("DigSpeed", this.digSpeed);
compound.setInteger("ArmorType", this.armorType);
compound.setInteger("Enchantability", this.enchantability);
compound.setInteger("MaxItemUseDuration", this.maxItemUseDuration);
compound.setInteger("ItemUseAction", this.itemUseAction);
return compound;
}
public void setItemNBT(NBTTagCompound compound) {
super.setItemNBT(compound);
this.durabilityValue = compound.getDouble("DurabilityValue");
this.stackSize = compound.getInteger("MaxStackSize");
this.isTool = compound.getBoolean("IsTool");
this.isNormalItem = compound.getBoolean("IsNormalItem");
this.digSpeed = compound.getInteger("DigSpeed");
this.armorType = compound.getInteger("ArmorType");
this.enchantability = compound.getInteger("Enchantability");
this.maxItemUseDuration = compound.getInteger("MaxItemUseDuration");
this.itemUseAction = compound.getInteger("ItemUseAction");
}
}
@@ -0,0 +1,201 @@
package noppes.npcs.scripted.item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.api.item.IItemCustomizable;
import noppes.npcs.controllers.data.ItemDisplayData;
public abstract class ScriptCustomizableItem extends ScriptItemStack implements IItemCustomizable {
public final ItemDisplayData itemDisplay = new ItemDisplayData();
public ScriptCustomizableItem(ItemStack item) {
super(item);
}
public abstract int getMaxStackSize();
// public abstract void setArmorType(int armorType);
public abstract int getArmorType();
// public abstract void setIsTool(boolean isTool);
public abstract boolean isTool();
// public abstract void setIsNormalItem(boolean normalItem);
public abstract boolean isNormalItem();
// public abstract void setDigSpeed(int digSpeed);
public abstract int getDigSpeed();
// public abstract void setMaxStackSize(int size);
public abstract double getDurabilityValue();
// public abstract void setDurabilityValue(float value);
public abstract int getMaxItemUseDuration();
// public abstract void setMaxItemUseDuration(int duration);
public abstract int getItemUseAction();
// public abstract void setItemUseAction(int action);
public abstract int getEnchantability();
// public abstract void setEnchantability(int enchantability);
public String getTexture() {
return this.itemDisplay.texture == null ? "" : this.itemDisplay.texture;
}
public void setTexture(String texture){
if(texture == null)
texture = "";
this.itemDisplay.texture = texture;
saveItemData();
}
public Boolean getDurabilityShow() {
return this.itemDisplay.durabilityShow != null ? this.itemDisplay.durabilityShow : false;
}
public void setDurabilityShow(Boolean bo) {
this.itemDisplay.durabilityShow = bo;
saveItemData();
}
public Integer getDurabilityColor() {
return this.itemDisplay.durabilityColor != null ? this.itemDisplay.durabilityColor : -1;
}
public void setDurabilityColor(Integer color) {
this.itemDisplay.durabilityColor = color;
saveItemData();
}
public Integer getColor() {
return this.itemDisplay.itemColor != null ? this.itemDisplay.itemColor : 0x8B4513;
}
public void setColor(Integer color) {
this.itemDisplay.itemColor = color;
saveItemData();
}
public void setRotation(Float rotationX, Float rotationY, Float rotationZ){
this.itemDisplay.rotationX = rotationX;
this.itemDisplay.rotationY = rotationY;
this.itemDisplay.rotationZ = rotationZ;
saveItemData();
}
public void setRotationRate(Float rotationXRate, Float rotationYRate, Float rotationZRate){
this.itemDisplay.rotationXRate = rotationXRate;
this.itemDisplay.rotationYRate = rotationYRate;
this.itemDisplay.rotationZRate = rotationZRate;
saveItemData();
}
public void setScale(Float scaleX, Float scaleY, Float scaleZ){
this.itemDisplay.scaleX = scaleX;
this.itemDisplay.scaleY = scaleY;
this.itemDisplay.scaleZ = scaleZ;
saveItemData();
}
public void setTranslate(Float translateX, Float translateY, Float translateZ){
this.itemDisplay.translateX = translateX;
this.itemDisplay.translateY = translateY;
this.itemDisplay.translateZ = translateZ;
saveItemData();
}
public Float getRotationX() {
return this.itemDisplay.rotationX != null ? this.itemDisplay.rotationX : 0;
}
public Float getRotationY() {
return this.itemDisplay.rotationY != null ? this.itemDisplay.rotationY : 0;
}
public Float getRotationZ() {
return this.itemDisplay.rotationZ != null ? this.itemDisplay.rotationZ : 0;
}
public Float getRotationXRate() {
return this.itemDisplay.rotationXRate != null ? this.itemDisplay.rotationXRate : 0;
}
public Float getRotationYRate() {
return this.itemDisplay.rotationYRate != null ? this.itemDisplay.rotationYRate : 0;
}
public Float getRotationZRate() {
return this.itemDisplay.rotationZRate != null ? this.itemDisplay.rotationZRate : 0;
}
public Float getScaleX() {
return this.itemDisplay.scaleX != null ? this.itemDisplay.scaleX : 0;
}
public Float getScaleY() {
return this.itemDisplay.scaleY != null ? this.itemDisplay.scaleY : 0;
}
public Float getScaleZ() {
return this.itemDisplay.scaleZ != null ? this.itemDisplay.scaleZ : 0;
}
public Float getTranslateX() {
return this.itemDisplay.translateX != null ? this.itemDisplay.translateX : 0;
}
public Float getTranslateY() {
return this.itemDisplay.translateY != null ? this.itemDisplay.translateY : 0;
}
public Float getTranslateZ() {
return this.itemDisplay.translateZ != null ? this.itemDisplay.translateZ : 0;
}
public NBTTagCompound getMCNbt() {
NBTTagCompound compound = super.getMCNbt();
compound.setTag("ItemData", this.getItemNBT(new NBTTagCompound()));
return compound;
}
public void setMCNbt(NBTTagCompound compound) {
super.setMCNbt(compound);
setItemNBT(compound.getCompoundTag("ItemData"));
}
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 && !c.getCompoundTag("ItemData").hasNoTags()){
this.setItemNBT(c.getCompoundTag("ItemData"));
}
}
public NBTTagCompound getItemNBT(NBTTagCompound compound) {
this.itemDisplay.writeToNBT(compound);
return compound;
}
public void setItemNBT(NBTTagCompound compound) {
this.itemDisplay.readFromNBT(compound);
}
}
@@ -16,6 +16,9 @@ import net.minecraftforge.common.IPlantable;
import noppes.npcs.NoppesUtilPlayer;
import noppes.npcs.api.INbt;
import noppes.npcs.api.item.IItemStack;
import noppes.npcs.controllers.LinkedItemController;
import noppes.npcs.controllers.data.LinkedItem;
import noppes.npcs.items.ItemLinked;
import noppes.npcs.items.ItemScripted;
import noppes.npcs.scripted.CustomNPCsException;
import noppes.npcs.scripted.NpcAPI;
@@ -313,6 +316,16 @@ public class ScriptItemStack implements IItemStack {
if(item == null)
return null;
if (item.getItem() instanceof ItemLinked) {
LinkedItem linkedItem;
if (item.hasTagCompound()) {
int linkedItemId = item.getTagCompound().getInteger(LinkedItem.LINKED_NBT_TAG);
linkedItem = LinkedItemController.Instance().get(linkedItemId);
if (linkedItem != null) {
return new ScriptLinkedItem(item);
}
}
}
if(item.getItem() instanceof ItemScripted) {
return new ScriptCustomItem(item);
}
@@ -0,0 +1,152 @@
package noppes.npcs.scripted.item;
import net.minecraft.item.ItemStack;
import noppes.npcs.api.item.IItemLinked;
import noppes.npcs.controllers.LinkedItemController;
import noppes.npcs.controllers.data.INpcScriptHandler;
import noppes.npcs.controllers.data.LinkedItem;
public class ScriptLinkedItem extends ScriptCustomizableItem implements IItemLinked {
private final LinkedItem linkedItem;
public ScriptLinkedItem(ItemStack item) {
super(item);
int linkedItemId = item.getTagCompound().getInteger(LinkedItem.LINKED_NBT_TAG);
this.linkedItem = LinkedItemController.Instance().get(linkedItemId);
this.itemDisplay.texture = null;
this.itemDisplay.translateX = null;
this.itemDisplay.translateY = null;
this.itemDisplay.translateZ = null;
this.itemDisplay.itemColor = null;
this.itemDisplay.scaleX = null;
this.itemDisplay.scaleY = null;
this.itemDisplay.scaleZ = null;
this.itemDisplay.rotationX = null;
this.itemDisplay.rotationY = null;
this.itemDisplay.rotationZ = null;
this.itemDisplay.rotationXRate = null;
this.itemDisplay.rotationYRate = null;
this.itemDisplay.rotationZRate = null;
this.itemDisplay.durabilityShow = null;
this.itemDisplay.durabilityColor = null;
}
public LinkedItem getLinkedItem() {
return this.linkedItem;
}
@Override
public INpcScriptHandler getScriptHandler() {
return this.getLinkedItem().getScriptHandler();
}
@Override
public int getMaxStackSize() {
return this.linkedItem.stackSize;
}
@Override
public int getArmorType() {
return this.linkedItem.armorType;
}
@Override
public boolean isTool() {
return this.linkedItem.isTool;
}
@Override
public boolean isNormalItem() {
return this.linkedItem.isNormalItem;
}
@Override
public int getDigSpeed() {
return this.linkedItem.digSpeed;
}
@Override
public double getDurabilityValue() {
return this.linkedItem.durabilityValue;
}
@Override
public int getMaxItemUseDuration() {
return this.linkedItem.maxItemUseDuration;
}
@Override
public int getItemUseAction() {
return this.linkedItem.itemUseAction;
}
@Override
public int getEnchantability() {
return this.linkedItem.enchantability;
}
public String getTexture() {
return this.itemDisplay.texture == null ? this.linkedItem.display.texture : this.itemDisplay.texture;
}
public Boolean getDurabilityShow() {
return this.itemDisplay.durabilityShow != null ? this.itemDisplay.durabilityShow : this.linkedItem.display.durabilityShow;
}
public Integer getDurabilityColor() {
return this.itemDisplay.durabilityColor != null ? this.itemDisplay.durabilityColor : this.linkedItem.display.durabilityColor;
}
public Integer getColor() {
return this.itemDisplay.itemColor != null ? this.itemDisplay.itemColor : this.linkedItem.display.itemColor;
}
public Float getRotationX() {
return this.itemDisplay.rotationX != null ? this.itemDisplay.rotationX : this.linkedItem.display.rotationX;
}
public Float getRotationY() {
return this.itemDisplay.rotationY != null ? this.itemDisplay.rotationY : this.linkedItem.display.rotationY;
}
public Float getRotationZ() {
return this.itemDisplay.rotationZ != null ? this.itemDisplay.rotationZ : this.linkedItem.display.rotationZ;
}
public Float getRotationXRate() {
return this.itemDisplay.rotationXRate != null ? this.itemDisplay.rotationXRate : this.linkedItem.display.rotationXRate;
}
public Float getRotationYRate() {
return this.itemDisplay.rotationYRate != null ? this.itemDisplay.rotationYRate : this.linkedItem.display.rotationYRate;
}
public Float getRotationZRate() {
return this.itemDisplay.rotationZRate != null ? this.itemDisplay.rotationZRate : this.linkedItem.display.rotationZRate;
}
public Float getScaleX() {
return this.itemDisplay.scaleX != null ? this.itemDisplay.scaleX : this.linkedItem.display.scaleX;
}
public Float getScaleY() {
return this.itemDisplay.scaleY != null ? this.itemDisplay.scaleY : this.linkedItem.display.scaleY;
}
public Float getScaleZ() {
return this.itemDisplay.scaleZ != null ? this.itemDisplay.scaleZ : this.linkedItem.display.scaleZ;
}
public Float getTranslateX() {
return this.itemDisplay.translateX != null ? this.itemDisplay.translateX : this.linkedItem.display.translateX;
}
public Float getTranslateY() {
return this.itemDisplay.translateY != null ? this.itemDisplay.translateY : this.linkedItem.display.translateY;
}
public Float getTranslateZ() {
return this.itemDisplay.translateZ != null ? this.itemDisplay.translateZ : this.linkedItem.display.translateZ;
}
}