Jump to content

[1.7.2][Solved]Issues with ItemPickup events


Recommended Posts

Hello again!


This time I'm looking for some tips/advice/help with some events (particularly EntityItemPickupEvent).


So what I am attempting to do is add some achievements to my mod, mainly when Items are crafted, and when certain items are picked up off the ground. The "onCrafted" part I have down and working. I'm having an issue with the "onItemPickup" events. The achievements for an item pickup are simply not triggering. :( I think that I'm doing something wrong, but just don't know what. :x


Here is my custom Events.class:


package aceofkings.rangermod.events;

import net.minecraft.init.Items;
import net.minecraftforge.event.entity.player.EntityItemPickupEvent;
import aceofkings.rangermod.RangerMain;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.PlayerEvent;

public class RangerEvents {

public void OnCraftEvent(PlayerEvent.ItemCraftedEvent e) {

	//gets item and checks it against other item //not having any problems so far with this.
		//What it should do.








public void OnItemPickup(EntityItemPickupEvent e){ //I also tried PlayerEvent.pickUp.equals(mymod.myitem), no avail.

                //what I'm having issues with




And here is the Main.class:



package aceofkings.rangermod;

import aceofkings.rangermod.events.RangerEvents;
import net.minecraft.block.Block;
import net.minecraft.block.BlockOre;
import net.minecraft.block.material.Material;
import net.minecraft.client.Minecraft;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.Achievement;
import net.minecraftforge.common.AchievementPage;
import net.minecraftforge.common.MinecraftForge;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;

@Mod(modid = RangerMain.MODID, name = RangerMain.NAME, version = RangerMain.VERSION)
//@NetworkMod(clientSideRequired = true, serverSideRequired = false) //Not used in 1.7

public class RangerMain {

protected final static String MODID = "rangerMod";
protected final static String NAME = "Ranger Mod";
protected final static String VERSION = "0.0.1";

//Creative Tab(s)
//blocks tab
public static CreativeTabs tabRangerModBlocks = new CreativeTabs("tabRangerModBlocks"){

	public Item getTabIconItem() {
		return Item.getItemFromBlock(crystal_block);

//Items tab
public static CreativeTabs tabRangerModItems = new CreativeTabs("tabRangerModItems"){

	public Item getTabIconItem() {

		return RangerMain.crystal_gem;

//weapons/combat tab
public static CreativeTabs tabRangerModCombat = new CreativeTabs("tabRangerModCombat"){

	public Item getTabIconItem(){

		return RangerMain.crystal_bow;


public static Achievement craftBow;
public static Achievement findPlantFibers;
public static Achievement craftBowString;
public static Achievement brewRangedPotion;
public static Achievement mineCrystals;
public static Achievement shatterCrystal;
public static Achievement craftStoneBow;
public static Achievement craftIronBow;
public static Achievement craftGoldBow;
public static Achievement craftDiamondBow;
public static Achievement craftCrystalBow;

public static AchievementPage RangerModPage;

public static final Item bowString = new RangerItem(64, tabRangerModItems,
		"rangermod:bow_string", "bowString");
//	public static final Item standardQuiver = new RangerItem(1, CreativeTabs.tabCombat,
//			"rangermod:quiver", "standardQuiver"); //Create new item: RangerQuiver
public static final Item plantFibers = new RangerItem(64, tabRangerModItems,
		"rangermod:plant_fibres", "plantFibers");
public static final Item rawResin = new RangerItem(64, tabRangerModItems,
		"rangermod:raw_resin", "rawResin");
public static final Item cookedResin = new RangerItem(64, tabRangerModItems,
		"rangermod:cooked_resin", "resin");
public static final Item dLeather_black = new RangerDragonItem(64, tabRangerModItems,
		"rangermod:dragonleather_black", "BlackDLeather");
public static final Item dLeather_green = new RangerDragonItem(64, tabRangerModItems,
		"rangermod:dragonleather_green", "GreenDLeather");
public static final Item dLeather_red = new RangerDragonItem(64, tabRangerModItems,
		"rangermod:dragonleather_red", "RedDLeather");
public static final Item crystal_dust = new RangerItem(64, tabRangerModItems,
		"rangermod:crystal_dust", "crystalDust");
public static final Item crystal_gem = new RangerItem(64, tabRangerModItems, 
		"rangermod:crystal_gem", "crystalGem");
public static final Item crystal_orb = new RangerItemMagic(tabRangerModCombat,
		"rangermod:crystal_orb", "crystalOrb", 0);
public static final Item crystal_fragments = new RangerItem(43, tabRangerModItems,
		"rangermod:crystal_fragments", "crystalFragments");

//v test bow, will remove at one point, or just have in creative
public static final Item ranger_bow = new RangerBow(10.0F, 0, 3, 6, -1)
public static final Item crystal_bow = new RangerBowMagic(30.0F, 0, 18, 26)
public static final Item stone_bow = new RangerBow(50.0F, 0, 28, 46, 0)
public static final Item iron_bow = new RangerBow(25.0F, 0, 13, 21, 1)
public static final Item gold_bow = new RangerBow(18.0F, 0, 6, 14, 2)
public static final Item diamond_bow = new RangerBow(22.0F, 0, 10, 18, 3)

public static final Block crystal_block = new RangerBlock(Material.packedIce,
		tabRangerModBlocks, 3.5F, "pickaxe", 2, "rangermod:block_crystal", "crystaBlock")
		.setStepSound(Block.soundTypeStone); //Other methods can be chained in as well.


public static RangerMain instance;

public static CommonProxy proxy;

@EventHandler //Items and blocks go here.
//	@PreInit //used in 1.5.2
public void preInit(FMLPreInitializationEvent event){

	GameRegistry.registerItem(plantFibers, "plantFibers");
	GameRegistry.registerItem(bowString, "bowString");
//		LanguageRegistry.addName(bowString, "Bow String");
	GameRegistry.registerItem(rawResin, "rawResin");
	GameRegistry.registerItem(cookedResin, "resin");
	GameRegistry.registerItem(dLeather_black, "blackDLeather");
	GameRegistry.registerItem(dLeather_green, "greenDLeather");
	GameRegistry.registerItem(dLeather_red, "redDLeather");
	GameRegistry.registerItem(crystal_dust, "crystalDust");
	GameRegistry.registerItem(crystal_fragments, "crystalFragments");
	GameRegistry.registerItem(crystal_gem, "crystalGem");
	GameRegistry.registerItem(crystal_orb, "crystalOrb");

	GameRegistry.registerItem(stone_bow, "bowStone");
	GameRegistry.registerItem(iron_bow, "bowIron");
	GameRegistry.registerItem(gold_bow, "bowGold");
	GameRegistry.registerItem(diamond_bow, "bowDiamond");
	GameRegistry.registerItem(crystal_bow, "bowCrystal");
	GameRegistry.registerItem(ranger_bow, "rangerBow");

	GameRegistry.registerBlock(crystal_block, "crystalBlock");

	craftBow = new Achievement("achievement.craftBow", "craftBow",
			0, 0, Items.bow,

	findPlantFibers = new Achievement("achievement.findPlantFibers", "findPlantFibers",
		//  x  y +down -up
			1, 3, RangerMain.plantFibers, craftBow).registerStat();

//		brewRangedPotion = new Achievement("achievement.brewRangedPotion", "brewRangedPotion",
//				3, 2, RangerMain.rangedPotion, findPlantFibers).registerStat();

	craftBowString = new Achievement("achievement.craftBowString", "cBowString",
			4, 3, RangerMain.bowString, findPlantFibers).registerStat();

	mineCrystals = new Achievement("achievement.mineCrystals", "mCrystals",
			-2, 1, RangerMain.crystal_gem, craftBow).registerStat();

	shatterCrystal = new Achievement("achievement.shatterCrystal", "sCrystal",
			-1, 4, RangerMain.crystal_fragments, mineCrystals).registerStat();

	craftStoneBow = new Achievement("achievement.craftStoneBow", "cStoneBow",
			5, 5, RangerMain.stone_bow, craftBowString).registerStat();

	craftIronBow = new Achievement("achievement.craftIronBow", "cIronBow",
			3, 6, RangerMain.iron_bow, craftStoneBow).registerStat();

	craftGoldBow = new Achievement("achievement.craftGoldBow", "cGoldBow",
			5, 8, RangerMain.gold_bow, craftIronBow).registerStat();

	craftDiamondBow = new Achievement("achievement.craftDiamondBow", "cDiamondBow",
			4, -2, RangerMain.bowString, craftGoldBow).registerStat();

	craftCrystalBow = new Achievement("achievement.craftCrystalBow", "cCrystalBow",
			-2, 6, RangerMain.crystal_bow, mineCrystals).registerStat();

	//Achievement page(s)
	RangerModPage = new AchievementPage("Ranger Mod", new Achievement[]{
			craftBow, findPlantFibers, craftBowString, mineCrystals, shatterCrystal, craftStoneBow, craftIronBow, craftGoldBow, craftDiamondBow, craftCrystalBow


	 * TODO:
	 * + assets/lang/en_US.lang
	 * + items in en_US.lang
	 * + achievements in en_US.lang
	 * + onSmeltEvent
	 * > fix achievement page (DONE!)
	 * > get the oncraft event to work (DONE!)
	 * > get the onitempickup event to work


@EventHandler //Recipes go here
//	@Init //used in 1.5.2
public void load(FMLInitializationEvent event){

	GameRegistry.addRecipe(new ItemStack(bowString, 3), new Object[]{
		"xy", 'x', plantFibers, 'y', cookedResin 
	//will change to 1, when I know how to use NBT tags to store uses.
	//might have to make a few new item classes.
	GameRegistry.addRecipe(new ItemStack(crystal_orb, 1), new Object[]{
		"bcb",  'b', Items.blaze_powder, 'c', crystal_gem,
				'p', new ItemStack(Items.potionitem, 1, 8268)//potion of ins. damage.
	//Crystal Fragments
	GameRegistry.addRecipe(new ItemStack(crystal_fragments, 23), new Object[]{
		" t ",
		" t ", 't', Blocks.tnt, 'o', Blocks.obsidian, 'c', crystal_gem

	GameRegistry.addRecipe(new ItemStack(crystal_block), new Object[]{
		"ccc", 'c', crystal_gem


	//Stone Bow
	GameRegistry.addRecipe(new ItemStack(stone_bow, 1), new Object[]{
		" xs",
		" xs", 'x', Blocks.stone, 'y', Items.bow, 's', bowString

	//Iron Bow
	GameRegistry.addRecipe(new ItemStack(iron_bow, 1), new Object[]{
		" xs",
		" xs", 'x', Items.iron_ingot, 'y', Items.lava_bucket, 's', bowString

	//Gold Bow
	GameRegistry.addRecipe(new ItemStack(gold_bow, 1), new Object[]{
		" xs",
		" xs", 'x', Items.gold_ingot, 'y', new ItemStack(Items.potionitem, 1, 8193), 's', bowString

	//Diamond Bow
	GameRegistry.addRecipe(new ItemStack(diamond_bow, 1), new Object[]{
		" xs",
		" xs", 'x', Items.diamond, 'y', new ItemStack(Items.skull, 1, 1), 's', bowString

	//Crystal Bow
	GameRegistry.addRecipe(new ItemStack(crystal_bow, 1), new Object[]{
		" xs",
		" xs", 'x', crystal_gem, 'y', Items.nether_star, 's', bowString

	GameRegistry.addSmelting(new ItemStack(rawResin), new ItemStack(cookedResin), 0.2F);


@EventHandler //I have no idea what goes here.
//	@PostInit //used in 1.5.2
public static void postInit(FMLPostInitializationEvent event){
	//Stub method
	//Displays active potion(s) in upper left corner. Needs fixing: icons wont display.
	MinecraftForge.EVENT_BUS.register(new RangerGuiBar(Minecraft.getMinecraft()));

	//Used for the custom events
	FMLCommonHandler.instance().bus().register(new RangerEvents());



Again, any help is much appreciated!

Link to comment
Share on other sites


public void OnItemPickup(EntityItemPickupEvent e) { ...

The event you're using contain a single property:

EntityItem item;

(the EntityItem picked up)

It inherits from event PlayerEvent:

EntityPlayer entityPlayer;

(the player picking it up)

and from event LivingEvent:

EntityLivingBase entityLiving;

(which is not set for this event)

and from event EntityEvent:

Entity entity;

(also not used for this event)


So, what you should be looking at is e.item /* the EntityItem */ .getEntityItem() /* the ItemStack */ .getItem() /* the Item */;

(Comments may added for informational purposes and should be removed)

Check for nulls at appropriate places.

Link to comment
Share on other sites

Okay, so I updated the method and if statement to:

public void OnItemPickup(EntityItemPickupEvent e){

		System.out.println("Event fired");


and threw in a print line so that I could see in the console if the event did indeed fire when I picked up the item (plantFibers). I did this for the OnCraftingEvent, to have a visual of when it fired.


However, when I run everything, and toss some of the item on the ground (from Creative, as there is no recipe and grass does not yet drop it), nothing happens. No line in the console that says "Event fired".


When I hover over item in eclipse it brings up this:

     * This event is called when a player collides with a EntityItem on the ground.
     * The event can be canceled, and no further processing will be done.
     *  You can set the result of this event to ALLOW which will trigger the 
     *  processing of achievements, FML's event, play the sound, and kill the 
     *  entity if all the items are picked up.
     *  setResult(ALLOW) is the same as the old setHandled()


How might I go about using setResult(ALLOW)?

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.