Posted March 27, 201411 yr 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. 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 { @SubscribeEvent public void OnCraftEvent(PlayerEvent.ItemCraftedEvent e) { //gets item and checks it against other item //not having any problems so far with this. if(e.crafting.getItem().equals(Items.bow)){ //What it should do. e.player.triggerAchievement(RangerMain.craftBow); } if(e.crafting.getItem().equals(RangerMain.bowString)){ e.player.triggerAchievement(RangerMain.craftBowString); } if(e.crafting.getItem().equals(RangerMain.crystal_fragments)){ e.player.triggerAchievement(RangerMain.shatterCrystal); } if(e.crafting.getItem().equals(RangerMain.stone_bow)){ e.player.triggerAchievement(RangerMain.craftStoneBow); } if(e.crafting.getItem().equals(RangerMain.iron_bow)){ e.player.triggerAchievement(RangerMain.craftIronBow); } if(e.crafting.getItem().equals(RangerMain.gold_bow)){ e.player.triggerAchievement(RangerMain.craftGoldBow); } if(e.crafting.getItem().equals(RangerMain.diamond_bow)){ e.player.triggerAchievement(RangerMain.craftDiamondBow); } if(e.crafting.getItem().equals(RangerMain.crystal_bow)){ e.player.triggerAchievement(RangerMain.craftCrystalBow); } } @SubscribeEvent public void OnItemPickup(EntityItemPickupEvent e){ //I also tried PlayerEvent.pickUp.equals(mymod.myitem), no avail. //what I'm having issues with if(e.entity.equals(RangerMain.plantFibers)){ e.entityPlayer.triggerAchievement(RangerMain.findPlantFibers); } if(e.entity.equals(RangerMain.crystal_gem)){ e.entityPlayer.triggerAchievement(RangerMain.mineCrystals); } } } 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"){ @Override public Item getTabIconItem() { //CANNOT RETURN NULL! EVER. return Item.getItemFromBlock(crystal_block); } }; //Items tab public static CreativeTabs tabRangerModItems = new CreativeTabs("tabRangerModItems"){ @Override public Item getTabIconItem() { return RangerMain.crystal_gem; } }; //weapons/combat tab public static CreativeTabs tabRangerModCombat = new CreativeTabs("tabRangerModCombat"){ @Override public Item getTabIconItem(){ return RangerMain.crystal_bow; } }; //Achievements 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; //Items 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"); //Combat //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) .setTextureName("rangerBow").setUnlocalizedName("rangerBow"); public static final Item crystal_bow = new RangerBowMagic(30.0F, 0, 18, 26) .setTextureName("bowCrystal").setUnlocalizedName("bowCrystal"); public static final Item stone_bow = new RangerBow(50.0F, 0, 28, 46, 0) .setTextureName("bowStone").setUnlocalizedName("bowStone"); public static final Item iron_bow = new RangerBow(25.0F, 0, 13, 21, 1) .setTextureName("bowIron").setUnlocalizedName("bowIron"); public static final Item gold_bow = new RangerBow(18.0F, 0, 6, 14, 2) .setTextureName("bowGold").setUnlocalizedName("bowGold"); public static final Item diamond_bow = new RangerBow(22.0F, 0, 10, 18, 3) .setTextureName("bowDiamond").setUnlocalizedName("bowDiamond"); //Blocks 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. //Ores @Instance("rangerMod") public static RangerMain instance; @SidedProxy(clientSide="aceofkings.rangermod.client.ClientProxy", serverSide="aceofkings.rangermod.CommonProxy") public static CommonProxy proxy; @EventHandler //Items and blocks go here. // @PreInit //used in 1.5.2 public void preInit(FMLPreInitializationEvent event){ //Items 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"); //Combat 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"); //Blocks GameRegistry.registerBlock(crystal_block, "crystalBlock"); //Achievements craftBow = new Achievement("achievement.craftBow", "craftBow", 0, 0, Items.bow, (Achievement)null).initIndependentStat().registerStat(); 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 }); AchievementPage.registerAchievementPage(RangerModPage); /** * 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){ proxy.registerRenderers(); //Items //BowString GameRegistry.addRecipe(new ItemStack(bowString, 3), new Object[]{ "xy", "yx", "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", "cpc", "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 ", "oco", " t ", 't', Blocks.tnt, 'o', Blocks.obsidian, 'c', crystal_gem }); //Blocks GameRegistry.addRecipe(new ItemStack(crystal_block), new Object[]{ "ccc", "ccc", "ccc", 'c', crystal_gem }); //Combat //Stone Bow GameRegistry.addRecipe(new ItemStack(stone_bow, 1), new Object[]{ " xs", "xys", " xs", 'x', Blocks.stone, 'y', Items.bow, 's', bowString }); //Iron Bow GameRegistry.addRecipe(new ItemStack(iron_bow, 1), new Object[]{ " xs", "xys", " xs", 'x', Items.iron_ingot, 'y', Items.lava_bucket, 's', bowString }); //Gold Bow GameRegistry.addRecipe(new ItemStack(gold_bow, 1), new Object[]{ " xs", "xys", " 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", "xys", " 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", "xys", " xs", 'x', crystal_gem, 'y', Items.nether_star, 's', bowString }); //Smelting 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!
March 27, 201411 yr public void OnItemPickup(EntityItemPickupEvent e) { ... if(e.entity.equals(RangerMain.plantFibers)){ ... 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. -S- (if I helped, please click Thank and applaud) http://6upnqa.dm2301.livefilestore.com/y2mtf-vG7Tqq1TiiVpIm53KWj7294NDPoHfSHHb4PzZiMAUfRCfK0UY0MwOu7Q3zTBNVTKqWjr2-xgBfFRpQT5p-QivtvknPpoABMNUw9br9WuZcBFkjePhnAbW500gVm-P/sequiturian.png[/img]
March 28, 201411 yr Author Okay, so I updated the method and if statement to: @SubscribeEvent public void OnItemPickup(EntityItemPickupEvent e){ if(e.item.getEntityItem().getItem().equals(RangerMain.plantFibers)){ 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)?
March 28, 201411 yr EntityItemPickupEvent is on the MinecraftForge EVENT_BUS, not on FMLCommonHandler; you will need at least two separate event handler classes, one for each of the event buses. http://i.imgur.com/NdrFdld.png[/img]
March 28, 201411 yr Author Ah, this solved the problem! Thank you very much! I'll have to look into the different event buses, so I don't make the same mistake in the future.
March 28, 201411 yr Ah, this solved the problem! Thank you very much! I'll have to look into the different event buses, so I don't make the same mistake in the future. Usually you can tell which bus an event should be on by looking at the import path. http://i.imgur.com/NdrFdld.png[/img]
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.