Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted
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.setUnlocalizedName(name);
        this.setRegistryName(name);
        this.maxStackSize = 1;
        this.setMaxDamage(238);
        this.setCreativeTab(CreativeTabs.MISC);   
    }
        
    
    @Override
    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);
            worldIn.spawnEntity(entityenderpearl);
        } 

        playerIn.addStat(StatList.getObjectUseStats(this));
        return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
    }
    
    @Override
    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

  • Author

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

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.

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.