Jump to content

[1.12.2] Item doesn't get damaged


Recommended Posts

package com.goingcrowd9.blazemod.items;

import javax.annotation.Nullable;

import com.goingcrowd9.blazemod.init.ModItems;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityEnderPearl;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.IItemPropertyGetter;
import net.minecraft.item.ItemEnderPearl;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatList;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundCategory;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class ItemMagicPearl extends ItemEnderPearl {
    public ItemMagicPearl(String name){
        this.maxStackSize = 1;
    public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn){    
        ItemStack itemstack = playerIn.getHeldItem(handIn);

        worldIn.playSound((EntityPlayer)null, playerIn.posX, playerIn.posY, playerIn.posZ, SoundEvents.ENTITY_ENDERPEARL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
        //playerIn.getCooldownTracker().setCooldown(this, 20);

        if (!worldIn.isRemote){
            EntityEnderPearl entityenderpearl = new EntityEnderPearl(worldIn, playerIn);
            entityenderpearl.shoot(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0F, 1.5F, 1.0F);

        return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
    public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft) {
        System.out.println("hello, I'm here !!!!!!!!!!!!!!!!!!!!!!!");
        System.out.println("Is this Item damageable ?: " + this.isDamageable() );
        EntityPlayer entityplayer = (EntityPlayer)entityLiving;
        stack.damageItem(1, entityplayer);
    public int getMaxItemUseDuration(ItemStack stack)
        return 7200;

I'm trying to make an ender pearl-like Item that gets damaged after you throw it, but it doesn't work...

The Item itself is working, but it seems it doesn't even reach onPlayerStoppedUsing since nothing gets printed on the console (println)

Obviously I'm doing something wrong, but I don't know what..

Any help appreciated

Link to comment
Share on other sites

I tought onPlayerStoppedUsing was just for every Item when you release the key to use it.

The package name was just something I used because of a tutorial.

At least that works now.

Now I just got to figure out how to make a model for the EntityMagicPearl, wich is now used instead of EntityEnderPearl 

(It works fine, it just doesn't use any model)

But at least thanks for pointing out the Item doesn't "get used" like I tought

Link to comment
Share on other sites

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.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

By using this site, you agree to our Terms of Use.