Posted August 21, 20169 yr Hello, I've made an item that is drunken to heal the player, and when it is drunk it reduces the uses by one. However, when I drink it in survival, a weird bug occurs: A red -1 appears on the icon, which briefly changes to a -3. When I hit something with it, it'll be instantly destroyed. What have I done wrong? [spoiler=Images] [spoiler=Item Code] package com.t10a.crystalflask.items; import com.t10a.crystalflask.CrystalFlask; import com.t10a.crystalflask.Reference; import com.t10a.crystalflask.init.ModItems; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.MobEffects; import net.minecraft.item.EnumAction; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.potion.PotionEffect; import net.minecraft.util.ActionResult; import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumHand; import net.minecraft.world.World; import javax.annotation.Nullable; import java.util.List; public class ItemCrystalFlask extends Item { public int uses; public ItemCrystalFlask() { setUnlocalizedName(Reference.MOD_ID + "." + Reference.ItemBase.ESTUS.getUnlocalizedName()); setRegistryName(Reference.ItemBase.ESTUS.getRegistryName()); setCreativeTab(CrystalFlask.ESTUSTAB); this.setMaxStackSize(1); this.uses = 5; this.setMaxDamage(uses); } @Override public void addInformation(ItemStack stack, EntityPlayer player, List<String> list, boolean par4) { list.add("A crystallised flask, containing a magical flame. Drink to restore HP."); list.add("(totally not an estus flask)"); } public int getMaxItemUseDuration(ItemStack stack) { return 32; } public EnumAction getItemUseAction(ItemStack stack) { return EnumAction.DRINK; } public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand) { playerIn.setActiveHand(hand); return new ActionResult(EnumActionResult.SUCCESS, itemStackIn); } @Nullable public ItemStack onItemUseFinish(ItemStack stack, World worldIn, EntityLivingBase entityLiving) { if (entityLiving instanceof EntityPlayer && !((EntityPlayer)entityLiving).capabilities.isCreativeMode) { --stack.stackSize; } if (!worldIn.isRemote) { entityLiving.addPotionEffect(new PotionEffect(MobEffects.INSTANT_HEALTH)); stack.damageItem(1, entityLiving); } if (entityLiving instanceof EntityPlayer && !((EntityPlayer)entityLiving).capabilities.isCreativeMode) { --stack.stackSize; } return super.onItemUseFinish(stack, worldIn, entityLiving); } } If I'm asking a whole bunch of questions, please don't get angry. I'm trying to learn.
August 21, 20169 yr You subtract from the stacksize then you damage the item? VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
August 21, 20169 yr Author Whoops, didn't see that. However, after fixing it and adding a tidbit of code that tells the game if it's empty or not, it'll just ignore it and allow the usage when (nearly) empty anyway. package com.t10a.crystalflask.items; import com.t10a.crystalflask.CrystalFlask; import com.t10a.crystalflask.Reference; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.MobEffects; import net.minecraft.item.EnumAction; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.potion.PotionEffect; import net.minecraft.util.ActionResult; import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumHand; import net.minecraft.world.World; import javax.annotation.Nullable; import java.util.List; public class ItemCrystalFlask extends Item { public int uses; public ItemCrystalFlask() { setUnlocalizedName(Reference.MOD_ID + "." + Reference.ItemBase.ESTUS.getUnlocalizedName()); setRegistryName(Reference.ItemBase.ESTUS.getRegistryName()); setCreativeTab(CrystalFlask.ESTUSTAB); this.setMaxStackSize(1); this.uses = 5; this.setMaxDamage(uses); } public boolean getIsEmpty() { if (this.getMaxDamage() == 1) return true; else return false; } @Override public void addInformation(ItemStack stack, EntityPlayer player, List<String> list, boolean par4) { list.add("A crystallised flask, containing a magical flame. Drink to restore HP."); list.add("(totally not an estus flask)"); } public int getMaxItemUseDuration(ItemStack stack) { return 32; } public EnumAction getItemUseAction(ItemStack stack) { if (getIsEmpty()) return EnumAction.NONE; else return EnumAction.DRINK; } public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand) { playerIn.setActiveHand(hand); return new ActionResult(EnumActionResult.SUCCESS, itemStackIn); } @Nullable public ItemStack onItemUseFinish(ItemStack stack, World worldIn, EntityLivingBase entityLiving) { if (!worldIn.isRemote) { entityLiving.addPotionEffect(new PotionEffect(MobEffects.INSTANT_HEALTH)); } if (entityLiving instanceof EntityPlayer && !((EntityPlayer)entityLiving).capabilities.isCreativeMode) { stack.damageItem(1, entityLiving); } return super.onItemUseFinish(stack, worldIn, entityLiving); } } If I'm asking a whole bunch of questions, please don't get angry. I'm trying to learn.
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.