Fixed a bug with item uses, custom items can now do block, bow, eat, and drink animations.

This commit is contained in:
Luis C.M committed 2022-05-11 02:33:56 -05:00
1 parent a18cf5625b
commit 747730face
2 files changed
+39 -4

No files matched your search

@@ -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() {}
@@ -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() {