Files
CustomNPC-Plus/src/main/java/noppes/npcs/controllers/data/LinkedItem.java
T

212 lines
5.5 KiB
Java
Raw Normal View History

2025-02-13 18:11:58 -06:00
package noppes.npcs.controllers.data;
import net.minecraft.nbt.NBTTagCompound;
2025-02-15 19:37:25 -05:00
import noppes.npcs.api.handler.data.ILinkedItem;
2025-02-14 12:28:17 -06:00
import noppes.npcs.controllers.LinkedItemController;
2025-02-13 18:11:58 -06:00
2025-02-15 19:37:25 -05:00
public class LinkedItem implements ILinkedItem {
public static final String LINKED_VERSION_VERSION_TAG = "LinkedVersion";
public static final String LINKED_DATA_NBT_TAG = "LinkedData";
2025-02-13 18:11:58 -06:00
2025-02-15 19:37:25 -05:00
public int id = -1;
2025-02-16 04:54:21 -05:00
public int version = 0;
2025-02-15 19:37:25 -05:00
public String name;
2025-02-13 18:11:58 -06:00
public final ItemDisplayData display = new ItemDisplayData();
public double durabilityValue = 1.0D;
public int stackSize = 64;
public int maxItemUseDuration = 20;
public int itemUseAction = 0; //0: none, 1: block, 2: bow, 3: eat, 4: drink
public boolean isNormalItem = false;
public boolean isTool = false;
public int digSpeed = 1;
2025-02-16 04:54:21 -05:00
public int armorType = -2; //-2: Fits in no armor slot, -1: Fits in all slots, 0 - 3: Fits in Head -> Boots slot respectively
2025-02-13 18:11:58 -06:00
public int enchantability;
2025-02-14 12:28:17 -06:00
public LinkedItem() {
this("New");
}
2025-02-13 18:11:58 -06:00
public LinkedItem(String name) {
this.name = name;
}
2025-02-14 12:28:17 -06:00
public INpcScriptHandler getScriptHandler() {
2025-02-16 04:54:21 -05:00
return LinkedItemController.getInstance().getScriptHandler(this.getId());
2025-02-13 18:11:58 -06:00
}
public NBTTagCompound writeToNBT() {
NBTTagCompound compound = new NBTTagCompound();
2025-02-14 12:28:17 -06:00
compound.setInteger("Id", this.id);
2025-02-15 19:37:25 -05:00
compound.setInteger("Version", this.version);
2025-02-14 12:28:17 -06:00
compound.setString("Name", this.name);
2025-02-13 18:11:58 -06:00
compound.setTag("Display", this.display.writeToNBT());
compound.setDouble("DurabilityValue",this.durabilityValue);
compound.setInteger("MaxStackSize",this.stackSize);
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;
}
2025-02-15 19:37:25 -05:00
public void readFromNBT(NBTTagCompound compound, boolean checkID) {
if(checkID)
2025-02-16 04:54:21 -05:00
this.id = compound.hasKey("Id") ? compound.getInteger("Id") : LinkedItemController.getInstance().getUnusedId();
2025-02-15 19:37:25 -05:00
else
this.id = compound.getInteger("Id");
2025-02-14 12:28:17 -06:00
this.name = compound.getString("Name");
2025-02-15 19:37:25 -05:00
this.version = compound.getInteger("Version");
2025-02-14 12:28:17 -06:00
2025-02-13 18:11:58 -06:00
this.display.readFromNBT(compound.getCompoundTag("Display"));
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");
}
2025-02-15 19:37:25 -05:00
public ILinkedItem save() {
2025-02-16 04:54:21 -05:00
return LinkedItemController.getInstance().saveLinkedItem(this);
2025-02-15 19:37:25 -05:00
}
@Override
public int getId() {
return id;
}
@Override
public void setId(int id) {
this.id = id;
}
@Override
public int getVersion() {
return version;
}
@Override
public void setVersion(int version) {
this.version = version;
}
@Override
public String getName() {
return name;
}
@Override
public void setName(String name) {
this.name = name;
}
@Override
public double getDurabilityValue() {
return durabilityValue;
}
@Override
public void setDurabilityValue(double durabilityValue) {
this.durabilityValue = durabilityValue;
}
@Override
public int getStackSize() {
return stackSize;
}
@Override
public void setStackSize(int stackSize) {
this.stackSize = stackSize;
}
@Override
public int getMaxItemUseDuration() {
return maxItemUseDuration;
}
@Override
public void setMaxItemUseDuration(int maxItemUseDuration) {
this.maxItemUseDuration = maxItemUseDuration;
}
@Override
public int getItemUseAction() {
return itemUseAction;
}
@Override
public void setItemUseAction(int itemUseAction) {
this.itemUseAction = itemUseAction;
}
@Override
public boolean isNormalItem() {
return isNormalItem;
}
@Override
public void setNormalItem(boolean normalItem) {
isNormalItem = normalItem;
}
@Override
public boolean isTool() {
return isTool;
}
@Override
public void setTool(boolean tool) {
isTool = tool;
}
@Override
public int getDigSpeed() {
return digSpeed;
}
@Override
public void setDigSpeed(int digSpeed) {
this.digSpeed = digSpeed;
}
@Override
public int getArmorType() {
return armorType;
}
@Override
public void setArmorType(int armorType) {
this.armorType = armorType;
}
@Override
public int getEnchantability() {
return enchantability;
}
@Override
public void setEnchantability(int enchantability) {
this.enchantability = enchantability;
}
// ADD / GET SETS FOR LINKED ITEM DISPLAY THINGS
2025-02-13 18:11:58 -06:00
}