mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-17 13:25:10 +00:00
progress on linked items
This commit is contained in:
1 parent
fb87e2a72c
commit
44e5c8b4c5
8 files changed
+546
-109
No files matched your search
@@ -28,7 +28,9 @@ public class CustomItems {
|
||||
public static Item mount;
|
||||
public static Item teleporter;
|
||||
public static Item tool;
|
||||
|
||||
public static Item scripted_item;
|
||||
public static Item linked_item;
|
||||
|
||||
public static Item soulstoneEmpty;
|
||||
public static Item soulstoneFull;
|
||||
@@ -245,6 +247,7 @@ public class CustomItems {
|
||||
mount = new ItemMounter().setUnlocalizedName("npcMounter").setFull3D();
|
||||
teleporter = new ItemTeleporter().setUnlocalizedName("npcTeleporter").setFull3D();
|
||||
scripted_item = new ItemScripted().setUnlocalizedName("scripted_item").setFull3D();
|
||||
linked_item = new ItemLinked().setUnlocalizedName("linked_item").setFull3D();
|
||||
tool = new ItemNpcTool().setUnlocalizedName("npcTool").setFull3D();
|
||||
|
||||
redstoneBlock = new BlockNpcRedstone().setHardness(50.0F).setResistance(2000).setBlockName("npcRedstoneBlock").setBlockTextureName("customnpcs:npcRedstoneBlock").setCreativeTab(tab);
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package noppes.npcs.controllers;
|
||||
|
||||
import noppes.npcs.controllers.data.LinkedItem;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
//TODO: load this data from somewhere, use in GUIs, create script wrapper
|
||||
public class LinkedItemController {
|
||||
private static LinkedItemController Instance;
|
||||
private final HashMap<String, LinkedItem> linkedItems = new HashMap<>();
|
||||
|
||||
private LinkedItemController() {
|
||||
}
|
||||
|
||||
public static LinkedItemController Instance() {
|
||||
if (Instance == null) {
|
||||
Instance = new LinkedItemController();
|
||||
}
|
||||
return Instance;
|
||||
}
|
||||
|
||||
public void add(LinkedItem linkedItem) {
|
||||
if (linkedItem != null) {
|
||||
String name = linkedItem.getName();
|
||||
if (name != null && !name.isEmpty()) {
|
||||
this.linkedItems.put(name.toLowerCase(), linkedItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public LinkedItem get(String name) {
|
||||
return name != null && !name.isEmpty() ? this.linkedItems.get(name.toLowerCase()) : null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class ItemDisplayData {
|
||||
public String texture = "minecraft:textures/items/iron_pickaxe.png";
|
||||
public Float translateX = 0F, translateY = 0F, translateZ = 0F;
|
||||
public Integer itemColor = 0x8B4513;
|
||||
public Float scaleX = 1.0F, scaleY = 1.0F, scaleZ = 1.0F;
|
||||
public Float rotationX = 0F, rotationY = 0F, rotationZ = 0F;
|
||||
public Float rotationXRate = 0F, rotationYRate = 0F, rotationZRate = 0F;
|
||||
public Boolean durabilityShow = false;
|
||||
public Integer durabilityColor = -1;
|
||||
|
||||
public NBTTagCompound writeToNBT() {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
this.writeToNBT(compound);
|
||||
return compound;
|
||||
}
|
||||
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
|
||||
this.setBoolean(compound, "DurabilityShow", this.durabilityShow);
|
||||
this.setInteger(compound, "DurabilityColor", this.durabilityColor);
|
||||
this.setInteger(compound, "ItemColor", this.itemColor);
|
||||
if (this.texture != null) {
|
||||
compound.setString("ItemTexture", this.texture);
|
||||
}
|
||||
|
||||
this.setFloat(compound, "RotationX", this.rotationX);
|
||||
this.setFloat(compound, "RotationY", this.rotationY);
|
||||
this.setFloat(compound, "RotationZ", this.rotationZ);
|
||||
|
||||
this.setFloat(compound, "RotationXRate", this.rotationXRate);
|
||||
this.setFloat(compound, "RotationYRate", this.rotationYRate);
|
||||
this.setFloat(compound, "RotationZRate", this.rotationZRate);
|
||||
|
||||
this.setFloat(compound, "ScaleX", this.scaleX);
|
||||
this.setFloat(compound, "ScaleY", this.scaleY);
|
||||
this.setFloat(compound, "ScaleZ", this.scaleZ);
|
||||
|
||||
this.setFloat(compound, "TranslateX", this.translateX);
|
||||
this.setFloat(compound, "TranslateY", this.translateY);
|
||||
this.setFloat(compound, "TranslateZ", this.translateZ);
|
||||
|
||||
return compound;
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
if (compound.hasKey("DurabilityShow")) {
|
||||
this.durabilityShow = compound.getBoolean("DurabilityShow");
|
||||
}
|
||||
if (compound.hasKey("DurabilityColor")) {
|
||||
this.durabilityColor = compound.getInteger("DurabilityColor");
|
||||
}
|
||||
if (compound.hasKey("ItemColor")) {
|
||||
this.itemColor = compound.getInteger("ItemColor");
|
||||
}
|
||||
if (compound.hasKey("ItemTexture")) {
|
||||
this.texture = compound.getString("ItemTexture");
|
||||
}
|
||||
|
||||
if (compound.hasKey("RotationX")) {
|
||||
this.rotationX = compound.getFloat("RotationX");
|
||||
}
|
||||
if (compound.hasKey("RotationY")) {
|
||||
this.rotationY = compound.getFloat("RotationY");
|
||||
}
|
||||
if (compound.hasKey("RotationZ")) {
|
||||
this.rotationZ = compound.getFloat("RotationZ");
|
||||
}
|
||||
|
||||
if (compound.hasKey("RotationXRate")) {
|
||||
this.rotationXRate = compound.getFloat("RotationXRate");
|
||||
}
|
||||
if (compound.hasKey("RotationYRate")) {
|
||||
this.rotationYRate = compound.getFloat("RotationYRate");
|
||||
}
|
||||
if (compound.hasKey("RotationZRate")) {
|
||||
this.rotationZRate = compound.getFloat("RotationZRate");
|
||||
}
|
||||
|
||||
if (compound.hasKey("ScaleX")) {
|
||||
this.scaleX = compound.getFloat("ScaleX");
|
||||
}
|
||||
if (compound.hasKey("ScaleY")) {
|
||||
this.scaleY = compound.getFloat("ScaleY");
|
||||
}
|
||||
if (compound.hasKey("ScaleZ")) {
|
||||
this.scaleZ = compound.getFloat("ScaleZ");
|
||||
}
|
||||
|
||||
if (compound.hasKey("TranslateX")) {
|
||||
this.translateX = compound.getFloat("TranslateX");
|
||||
}
|
||||
if (compound.hasKey("TranslateY")) {
|
||||
this.translateY = compound.getFloat("TranslateY");
|
||||
}
|
||||
if (compound.hasKey("TranslateZ")) {
|
||||
this.translateZ = compound.getFloat("TranslateZ");
|
||||
}
|
||||
}
|
||||
|
||||
private void setBoolean(NBTTagCompound compound, String key, Boolean value) {
|
||||
if (value != null) {
|
||||
compound.setBoolean(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
private void setInteger(NBTTagCompound compound, String key, Integer value) {
|
||||
if (value != null) {
|
||||
compound.setInteger(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
private void setFloat(NBTTagCompound compound, String key, Float value) {
|
||||
if (value != null) {
|
||||
compound.setFloat(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagString;
|
||||
import noppes.npcs.CustomItems;
|
||||
|
||||
public class LinkedItem {
|
||||
public static final String LINKED_NBT_TAG = "LinkedName";
|
||||
|
||||
private final String name;
|
||||
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;
|
||||
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 LinkedItem(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public ItemStack createStack() {
|
||||
ItemStack linkedStack = new ItemStack(CustomItems.linked_item);
|
||||
linkedStack.setTagInfo(LinkedItem.LINKED_NBT_TAG, new NBTTagString(this.getName()));
|
||||
return linkedStack;
|
||||
}
|
||||
|
||||
public NBTTagCompound writeToNBT() {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
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;
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
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");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
package noppes.npcs.items;
|
||||
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.EnumAction;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.EventHooks;
|
||||
import noppes.npcs.api.item.IItemStack;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.scripted.event.ItemEvent;
|
||||
import noppes.npcs.scripted.item.ScriptCustomItem;
|
||||
import noppes.npcs.scripted.item.ScriptLinkedItem;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public class ItemLinked extends Item implements ItemRenderInterface {
|
||||
|
||||
public ItemLinked() {
|
||||
maxStackSize = 1;
|
||||
CustomNpcs.proxy.registerItem(this);
|
||||
setHasSubtypes(true);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerIcons(IIconRegister par1IconRegister){
|
||||
this.itemIcon = Items.iron_pickaxe.getIconFromDamage(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColorFromItemStack(ItemStack itemStack, int par2){
|
||||
return 0x8B4513;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requiresMultipleRenderPasses(){
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item setUnlocalizedName(String name){
|
||||
GameRegistry.registerItem(this, name);
|
||||
return super.setUnlocalizedName(name);
|
||||
}
|
||||
|
||||
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
|
||||
{
|
||||
player.setItemInUse(stack, this.getMaxItemUseDuration(stack));
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onEntitySwing(EntityLivingBase entityLivingBase, ItemStack stack){
|
||||
if (entityLivingBase.worldObj.isRemote) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//TODO: re-implement item attack swing hook
|
||||
// IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
|
||||
// ItemEvent.AttackEvent eve = new ItemEvent.AttackEvent((ScriptLinkedItem) istack, NpcAPI.Instance().getIEntity(entityLivingBase), 2, null);
|
||||
// return EventHooks.onScriptItemAttack((ScriptLinkedItem) istack, eve);
|
||||
return true;
|
||||
}
|
||||
|
||||
public int getMaxItemUseDuration(ItemStack stack){
|
||||
return (new ScriptLinkedItem(stack)).getMaxItemUseDuration();
|
||||
}
|
||||
|
||||
//TODO: Use this in existing item scripted rendering. Refactor the renderer to use the new abstract ScriptCustomizableItem class
|
||||
public static ScriptLinkedItem GetWrapper(ItemStack stack) {
|
||||
return new ScriptLinkedItem(stack);
|
||||
}
|
||||
|
||||
public boolean showDurabilityBar(ItemStack stack) {
|
||||
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
|
||||
return istack instanceof ScriptLinkedItem && (new ScriptLinkedItem(stack)).itemDisplay.durabilityShow;
|
||||
}
|
||||
|
||||
public double getDurabilityForDisplay(ItemStack stack) {
|
||||
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
|
||||
return istack instanceof ScriptLinkedItem ? 1.0D - (new ScriptLinkedItem(stack)).getDurabilityValue() : 1.0D;
|
||||
}
|
||||
|
||||
public int getItemStackLimit(ItemStack stack) {
|
||||
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
|
||||
return istack instanceof ScriptLinkedItem ? (new ScriptLinkedItem(stack)).getMaxStackSize() : super.getItemStackLimit(stack);
|
||||
}
|
||||
|
||||
public boolean isItemTool(ItemStack stack)
|
||||
{
|
||||
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
|
||||
return istack instanceof ScriptLinkedItem ? (new ScriptLinkedItem(stack)).isTool() : super.isItemTool(stack);
|
||||
}
|
||||
|
||||
public float getDigSpeed(ItemStack stack, Block block, int metadata)
|
||||
{
|
||||
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
|
||||
return istack instanceof ScriptLinkedItem ? (new ScriptLinkedItem(stack)).getDigSpeed() : super.getDigSpeed(stack, block, metadata);
|
||||
}
|
||||
|
||||
public boolean isValidArmor(ItemStack stack, int armorType, Entity entity)
|
||||
{
|
||||
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
|
||||
|
||||
if((new ScriptLinkedItem(stack)).getArmorType() == -1)
|
||||
return true;
|
||||
|
||||
return istack instanceof ScriptLinkedItem ? armorType == (new ScriptLinkedItem(stack)).getArmorType() : super.isValidArmor(stack, armorType, entity);
|
||||
}
|
||||
|
||||
public int getItemEnchantability(ItemStack stack)
|
||||
{
|
||||
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
|
||||
return istack instanceof ScriptLinkedItem ? (new ScriptLinkedItem(stack)).getEnchantability() : super.getItemEnchantability(stack);
|
||||
}
|
||||
|
||||
public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker) {
|
||||
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
|
||||
|
||||
//TODO: re-implement item attack hook
|
||||
// ItemEvent.AttackEvent eve = new ItemEvent.AttackEvent( (ScriptLinkedItem) istack, NpcAPI.Instance().getIEntity(attacker), 1, NpcAPI.Instance().getIEntity(target));
|
||||
// return EventHooks.onScriptItemAttack((ScriptLinkedItem) istack, eve);
|
||||
return true;
|
||||
}
|
||||
|
||||
public EnumAction getItemUseAction(ItemStack stack)
|
||||
{
|
||||
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
|
||||
if (istack instanceof ScriptLinkedItem) {
|
||||
switch (((ScriptLinkedItem) istack).getItemUseAction()) {
|
||||
case 0:
|
||||
return EnumAction.none;
|
||||
case 1:
|
||||
return EnumAction.block;
|
||||
case 2:
|
||||
return EnumAction.bow;
|
||||
case 3:
|
||||
return EnumAction.eat;
|
||||
case 4:
|
||||
return EnumAction.drink;
|
||||
}
|
||||
}
|
||||
return super.getItemUseAction(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderSpecial() {}
|
||||
|
||||
public void renderOffset(ScriptLinkedItem scriptCustomItem) {
|
||||
GL11.glTranslatef(0.135F * scriptCustomItem.itemDisplay.scaleX, 0.2F * scriptCustomItem.itemDisplay.scaleY, 0.07F * scriptCustomItem.itemDisplay.scaleZ);
|
||||
}
|
||||
}
|
||||
@@ -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,11 @@ public class NpcAPI extends AbstractNpcAPI {
|
||||
if (scriptItemCache.containsKey(itemstack)) {
|
||||
scriptStack = scriptItemCache.get(itemstack).getObject();
|
||||
} else {
|
||||
if (itemstack.getItem() instanceof ItemScripted) {
|
||||
String linkedItemName = itemstack.getTagCompound().getString(LinkedItem.LINKED_NBT_TAG);
|
||||
LinkedItem linkedItem = LinkedItemController.Instance().get(linkedItemName);
|
||||
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);
|
||||
|
||||
@@ -2,9 +2,10 @@ package noppes.npcs.scripted.item;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.controllers.data.ItemDisplayData;
|
||||
|
||||
public abstract class ScriptCustomizableItem extends ScriptItemStack {
|
||||
public final Display itemDisplay = new Display();
|
||||
public final ItemDisplayData itemDisplay = new ItemDisplayData();
|
||||
|
||||
public ScriptCustomizableItem(ItemStack item) {
|
||||
super(item);
|
||||
@@ -188,112 +189,12 @@ public abstract class ScriptCustomizableItem extends ScriptItemStack {
|
||||
}
|
||||
|
||||
public NBTTagCompound getItemNBT(NBTTagCompound compound) {
|
||||
this.setBoolean(compound, "DurabilityShow",this.itemDisplay.durabilityShow);
|
||||
this.setInteger(compound, "DurabilityColor",this.itemDisplay.durabilityColor);
|
||||
this.setInteger(compound, "ItemColor",this.itemDisplay.itemColor);
|
||||
if (this.itemDisplay.texture != null) {
|
||||
compound.setString("ItemTexture", this.itemDisplay.texture);
|
||||
}
|
||||
|
||||
this.setFloat(compound, "RotationX",this.itemDisplay.rotationX);
|
||||
this.setFloat(compound, "RotationY",this.itemDisplay.rotationY);
|
||||
this.setFloat(compound, "RotationZ",this.itemDisplay.rotationZ);
|
||||
|
||||
this.setFloat(compound, "RotationXRate",this.itemDisplay.rotationXRate);
|
||||
this.setFloat(compound, "RotationYRate",this.itemDisplay.rotationYRate);
|
||||
this.setFloat(compound, "RotationZRate",this.itemDisplay.rotationZRate);
|
||||
|
||||
this.setFloat(compound, "ScaleX",this.itemDisplay.scaleX);
|
||||
this.setFloat(compound, "ScaleY",this.itemDisplay.scaleY);
|
||||
this.setFloat(compound, "ScaleZ",this.itemDisplay.scaleZ);
|
||||
|
||||
this.setFloat(compound, "TranslateX",this.itemDisplay.translateX);
|
||||
this.setFloat(compound, "TranslateY",this.itemDisplay.translateY);
|
||||
this.setFloat(compound, "TranslateZ",this.itemDisplay.translateZ);
|
||||
this.itemDisplay.writeToNBT(compound);
|
||||
return compound;
|
||||
}
|
||||
|
||||
private void setBoolean(NBTTagCompound compound, String key, Boolean value) {
|
||||
if (value != null) {
|
||||
compound.setBoolean(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
private void setInteger(NBTTagCompound compound, String key, Integer value) {
|
||||
if (value != null) {
|
||||
compound.setInteger(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
private void setFloat(NBTTagCompound compound, String key, Float value) {
|
||||
if (value != null) {
|
||||
compound.setFloat(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
public void setItemNBT(NBTTagCompound compound) {
|
||||
if (compound.hasKey("DurabilityShow")) {
|
||||
this.itemDisplay.durabilityShow = compound.getBoolean("DurabilityShow");
|
||||
}
|
||||
if (compound.hasKey("DurabilityColor")) {
|
||||
this.itemDisplay.durabilityColor = compound.getInteger("DurabilityColor");
|
||||
}
|
||||
if (compound.hasKey("ItemColor")) {
|
||||
this.itemDisplay.itemColor = compound.getInteger("ItemColor");
|
||||
}
|
||||
if (compound.hasKey("ItemTexture")) {
|
||||
this.itemDisplay.texture = compound.getString("ItemTexture");
|
||||
}
|
||||
|
||||
if (compound.hasKey("RotationX")) {
|
||||
this.itemDisplay.rotationX = compound.getFloat("RotationX");
|
||||
}
|
||||
if (compound.hasKey("RotationY")) {
|
||||
this.itemDisplay.rotationY = compound.getFloat("RotationY");
|
||||
}
|
||||
if (compound.hasKey("RotationZ")) {
|
||||
this.itemDisplay.rotationZ = compound.getFloat("RotationZ");
|
||||
}
|
||||
|
||||
if (compound.hasKey("RotationXRate")) {
|
||||
this.itemDisplay.rotationXRate = compound.getFloat("RotationXRate");
|
||||
}
|
||||
if (compound.hasKey("RotationYRate")) {
|
||||
this.itemDisplay.rotationYRate = compound.getFloat("RotationYRate");
|
||||
}
|
||||
if (compound.hasKey("RotationZRate")) {
|
||||
this.itemDisplay.rotationZRate = compound.getFloat("RotationZRate");
|
||||
}
|
||||
|
||||
if (compound.hasKey("ScaleX")) {
|
||||
this.itemDisplay.scaleX = compound.getFloat("ScaleX");
|
||||
}
|
||||
if (compound.hasKey("ScaleY")) {
|
||||
this.itemDisplay.scaleY = compound.getFloat("ScaleY");
|
||||
}
|
||||
if (compound.hasKey("ScaleZ")) {
|
||||
this.itemDisplay.scaleZ = compound.getFloat("ScaleZ");
|
||||
}
|
||||
|
||||
if (compound.hasKey("TranslateX")) {
|
||||
this.itemDisplay.translateX = compound.getFloat("TranslateX");
|
||||
}
|
||||
if (compound.hasKey("TranslateY")) {
|
||||
this.itemDisplay.translateY = compound.getFloat("TranslateY");
|
||||
}
|
||||
if (compound.hasKey("TranslateZ")) {
|
||||
this.itemDisplay.translateZ = compound.getFloat("TranslateZ");
|
||||
}
|
||||
this.itemDisplay.readFromNBT(compound);
|
||||
}
|
||||
|
||||
public static class Display {
|
||||
public String texture = "minecraft:textures/items/iron_pickaxe.png";
|
||||
public Float translateX = 0F, translateY = 0F, translateZ = 0F;
|
||||
public Integer itemColor = 0x8B4513;
|
||||
public Float scaleX = 1.0F, scaleY = 1.0F, scaleZ = 1.0F;
|
||||
public Float rotationX = 0F, rotationY = 0F, rotationZ = 0F;
|
||||
public Float rotationXRate = 0F, rotationYRate = 0F, rotationZRate = 0F;
|
||||
public Boolean durabilityShow = false;
|
||||
public Integer durabilityColor = -1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
package noppes.npcs.scripted.item;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import noppes.npcs.controllers.LinkedItemController;
|
||||
import noppes.npcs.controllers.data.LinkedItem;
|
||||
|
||||
public class ScriptLinkedItem extends ScriptCustomizableItem {
|
||||
private final LinkedItem linkedItem;
|
||||
|
||||
public ScriptLinkedItem(ItemStack item) {
|
||||
super(item);
|
||||
String linkedItemName = item.getTagCompound().getString(LinkedItem.LINKED_NBT_TAG);
|
||||
this.linkedItem = LinkedItemController.Instance().get(linkedItemName);
|
||||
|
||||
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 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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user