From 747730faceec53d312f1535c32497746a2288594 Mon Sep 17 00:00:00 2001 From: "Luis C.M" Date: Wed, 11 May 2022 02:33:56 -0500 Subject: [PATCH] Fixed a bug with item uses, custom items can now do block, bow, eat, and drink animations. --- .../java/noppes/npcs/items/ItemScripted.java | 24 ++++++++++++++++--- .../npcs/scripted/item/ScriptCustomItem.java | 19 ++++++++++++++- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/main/java/noppes/npcs/items/ItemScripted.java b/src/main/java/noppes/npcs/items/ItemScripted.java index 8b904612d..8150dfdb9 100644 --- a/src/main/java/noppes/npcs/items/ItemScripted.java +++ b/src/main/java/noppes/npcs/items/ItemScripted.java @@ -9,6 +9,7 @@ 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; @@ -51,9 +52,6 @@ public class ItemScripted extends Item implements ItemRenderInterface { public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer entityPlayer) { - if(!world.isRemote) - return stack; - if(entityPlayer.isSneaking()) { CustomNpcs.proxy.openGui(0, 0, 0, EnumGuiType.ScriptItem, entityPlayer); } @@ -116,6 +114,26 @@ public class ItemScripted extends Item implements ItemRenderInterface { return true; } + public EnumAction getItemUseAction(ItemStack stack) + { + IItemStack istack = NpcAPI.Instance().getIItemStack(stack); + if (istack instanceof ScriptCustomItem) { + switch (((ScriptCustomItem) 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() {} diff --git a/src/main/java/noppes/npcs/scripted/item/ScriptCustomItem.java b/src/main/java/noppes/npcs/scripted/item/ScriptCustomItem.java index 4046026fb..b9320b729 100644 --- a/src/main/java/noppes/npcs/scripted/item/ScriptCustomItem.java +++ b/src/main/java/noppes/npcs/scripted/item/ScriptCustomItem.java @@ -26,7 +26,9 @@ public class ScriptCustomItem extends ScriptItemStack implements ICustomItem, IS public int durabilityColor = -1; public int itemColor = 0x8B4513; public int stackSize = 64; + public int maxItemUseDuration = 20; + public int itemUseAction = 0; //0: none, 1: block, 2: bow, 3: eat, 4: drink public boolean isTool = false; public int digSpeed = 1; @@ -241,11 +243,20 @@ public class ScriptCustomItem extends ScriptItemStack implements ICustomItem, IS return this.maxItemUseDuration; } - public void setMaxItemUseDuration(int duration){ + public void setMaxItemUseDuration(int duration) { this.maxItemUseDuration = duration; saveItemData(); } + public void setItemUseAction(int action) { + this.itemUseAction = action; + saveItemData(); + } + + public int getItemUseAction() { + return this.itemUseAction; + } + public int getEnchantability(){ return this.enchantability; } @@ -396,6 +407,9 @@ public class ScriptCustomItem extends ScriptItemStack implements ICustomItem, IS 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; } @@ -428,6 +442,9 @@ public class ScriptCustomItem extends ScriptItemStack implements ICustomItem, IS 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() {