2025-02-13 18:11:58 -06:00
|
|
|
package noppes.npcs.scripted.item;
|
|
|
|
|
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
2025-02-15 19:37:25 -05:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2025-02-14 12:29:53 -06:00
|
|
|
import noppes.npcs.api.item.IItemLinked;
|
2025-02-13 18:11:58 -06:00
|
|
|
import noppes.npcs.controllers.LinkedItemController;
|
2025-02-14 12:28:17 -06:00
|
|
|
import noppes.npcs.controllers.data.INpcScriptHandler;
|
2025-02-13 18:11:58 -06:00
|
|
|
import noppes.npcs.controllers.data.LinkedItem;
|
|
|
|
|
|
2025-02-14 12:29:53 -06:00
|
|
|
public class ScriptLinkedItem extends ScriptCustomizableItem implements IItemLinked {
|
2025-02-17 13:44:01 -05:00
|
|
|
public LinkedItem linkedItem = new LinkedItem();
|
2025-02-15 19:37:25 -05:00
|
|
|
public double durabilityValue = 1.0D;
|
|
|
|
|
public int linkedVersion = 1;
|
2025-02-13 18:11:58 -06:00
|
|
|
public ScriptLinkedItem(ItemStack item) {
|
|
|
|
|
super(item);
|
2025-02-17 14:06:26 -05:00
|
|
|
setDefaults();
|
2025-02-15 19:37:25 -05:00
|
|
|
loadItemData();
|
2025-02-13 18:11:58 -06:00
|
|
|
}
|
|
|
|
|
|
2025-02-17 14:06:26 -05:00
|
|
|
// For Building new Linked Item
|
|
|
|
|
public ScriptLinkedItem(ItemStack item, LinkedItem linkedItem) {
|
|
|
|
|
super(item);
|
|
|
|
|
this.linkedItem = linkedItem.clone();
|
|
|
|
|
this.linkedVersion = this.linkedItem.version;
|
|
|
|
|
setDefaults();
|
|
|
|
|
saveItemData();
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-16 05:50:03 -05:00
|
|
|
public void setDefaults(){
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-13 18:11:58 -06:00
|
|
|
public LinkedItem getLinkedItem() {
|
2025-02-16 04:54:21 -05:00
|
|
|
return LinkedItemController.getInstance().get(this.linkedItem.getId());
|
2025-02-13 18:11:58 -06:00
|
|
|
}
|
|
|
|
|
|
2025-02-14 12:28:17 -06:00
|
|
|
@Override
|
|
|
|
|
public INpcScriptHandler getScriptHandler() {
|
2025-02-18 02:15:06 -05:00
|
|
|
if(this.getLinkedItem() == null)
|
|
|
|
|
return null;
|
2025-02-14 12:28:17 -06:00
|
|
|
return this.getLinkedItem().getScriptHandler();
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-13 18:11:58 -06:00
|
|
|
@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() {
|
2025-02-15 19:37:25 -05:00
|
|
|
return this.durabilityValue;
|
2025-02-13 18:11:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getMaxItemUseDuration() {
|
|
|
|
|
return this.linkedItem.maxItemUseDuration;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getItemUseAction() {
|
|
|
|
|
return this.linkedItem.itemUseAction;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getEnchantability() {
|
|
|
|
|
return this.linkedItem.enchantability;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-15 19:37:25 -05:00
|
|
|
@Override
|
2025-02-13 18:11:58 -06:00
|
|
|
public String getTexture() {
|
|
|
|
|
return this.itemDisplay.texture == null ? this.linkedItem.display.texture : this.itemDisplay.texture;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-15 19:37:25 -05:00
|
|
|
@Override
|
2025-02-13 18:11:58 -06:00
|
|
|
public Boolean getDurabilityShow() {
|
|
|
|
|
return this.itemDisplay.durabilityShow != null ? this.itemDisplay.durabilityShow : this.linkedItem.display.durabilityShow;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-15 19:37:25 -05:00
|
|
|
@Override
|
2025-02-13 18:11:58 -06:00
|
|
|
public Integer getDurabilityColor() {
|
|
|
|
|
return this.itemDisplay.durabilityColor != null ? this.itemDisplay.durabilityColor : this.linkedItem.display.durabilityColor;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-15 19:37:25 -05:00
|
|
|
@Override
|
2025-02-13 18:11:58 -06:00
|
|
|
public Integer getColor() {
|
|
|
|
|
return this.itemDisplay.itemColor != null ? this.itemDisplay.itemColor : this.linkedItem.display.itemColor;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-15 19:37:25 -05:00
|
|
|
@Override
|
2025-02-13 18:11:58 -06:00
|
|
|
public Float getRotationX() {
|
|
|
|
|
return this.itemDisplay.rotationX != null ? this.itemDisplay.rotationX : this.linkedItem.display.rotationX;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-15 19:37:25 -05:00
|
|
|
@Override
|
2025-02-13 18:11:58 -06:00
|
|
|
public Float getRotationY() {
|
|
|
|
|
return this.itemDisplay.rotationY != null ? this.itemDisplay.rotationY : this.linkedItem.display.rotationY;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-15 19:37:25 -05:00
|
|
|
@Override
|
2025-02-13 18:11:58 -06:00
|
|
|
public Float getRotationZ() {
|
|
|
|
|
return this.itemDisplay.rotationZ != null ? this.itemDisplay.rotationZ : this.linkedItem.display.rotationZ;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-15 19:37:25 -05:00
|
|
|
@Override
|
2025-02-13 18:11:58 -06:00
|
|
|
public Float getRotationXRate() {
|
|
|
|
|
return this.itemDisplay.rotationXRate != null ? this.itemDisplay.rotationXRate : this.linkedItem.display.rotationXRate;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-15 19:37:25 -05:00
|
|
|
@Override
|
2025-02-13 18:11:58 -06:00
|
|
|
public Float getRotationYRate() {
|
|
|
|
|
return this.itemDisplay.rotationYRate != null ? this.itemDisplay.rotationYRate : this.linkedItem.display.rotationYRate;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-15 19:37:25 -05:00
|
|
|
@Override
|
2025-02-13 18:11:58 -06:00
|
|
|
public Float getRotationZRate() {
|
|
|
|
|
return this.itemDisplay.rotationZRate != null ? this.itemDisplay.rotationZRate : this.linkedItem.display.rotationZRate;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-15 19:37:25 -05:00
|
|
|
@Override
|
2025-02-13 18:11:58 -06:00
|
|
|
public Float getScaleX() {
|
|
|
|
|
return this.itemDisplay.scaleX != null ? this.itemDisplay.scaleX : this.linkedItem.display.scaleX;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-15 19:37:25 -05:00
|
|
|
@Override
|
2025-02-13 18:11:58 -06:00
|
|
|
public Float getScaleY() {
|
|
|
|
|
return this.itemDisplay.scaleY != null ? this.itemDisplay.scaleY : this.linkedItem.display.scaleY;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-15 19:37:25 -05:00
|
|
|
@Override
|
2025-02-13 18:11:58 -06:00
|
|
|
public Float getScaleZ() {
|
|
|
|
|
return this.itemDisplay.scaleZ != null ? this.itemDisplay.scaleZ : this.linkedItem.display.scaleZ;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-15 19:37:25 -05:00
|
|
|
@Override
|
2025-02-13 18:11:58 -06:00
|
|
|
public Float getTranslateX() {
|
|
|
|
|
return this.itemDisplay.translateX != null ? this.itemDisplay.translateX : this.linkedItem.display.translateX;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-15 19:37:25 -05:00
|
|
|
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);
|
2025-02-17 14:38:42 -05:00
|
|
|
compound.setTag(LinkedItem.LINKED_DATA_NBT_TAG, this.linkedItem.writeToNBT(false));
|
2025-02-15 19:37:25 -05:00
|
|
|
compound.setInteger(LinkedItem.LINKED_VERSION_VERSION_TAG, this.linkedVersion);
|
|
|
|
|
return compound;
|
2025-02-13 18:11:58 -06:00
|
|
|
}
|
|
|
|
|
|
2025-02-15 19:37:25 -05:00
|
|
|
public void setItemNBT(NBTTagCompound compound) {
|
|
|
|
|
this.itemDisplay.readFromNBT(compound);
|
2025-02-17 14:38:42 -05:00
|
|
|
this.linkedItem.readFromNBT(compound.getCompoundTag(LinkedItem.LINKED_DATA_NBT_TAG));
|
2025-02-15 19:37:25 -05:00
|
|
|
this.linkedVersion = compound.getInteger(LinkedItem.LINKED_VERSION_VERSION_TAG);
|
2025-02-13 18:11:58 -06:00
|
|
|
}
|
|
|
|
|
}
|