Posted February 4, 201312 yr Is it possible to get an achievement when right-clicking an item??? Also what is the code to activate and achievement when picking up an item. No signature for you!
February 4, 201312 yr Author Maybe I'm doing something wrong here but neither method isn't working. Here is the code I have: package mod.ElementalWorld; import net.minecraft.src.EntityPlayer; import net.minecraft.src.IInventory; import net.minecraft.src.ItemStack; import cpw.mods.fml.common.ICraftingHandler; public class AchievementManager implements ICraftingHandler { //This is how you check if a player has crafted something that returns the block/item you want them to gain an achievement for public void EntityItemPickupEvent(EntityPlayer player, ItemStack item, IInventory craftMatrix) { if (item.itemID == ElementalWorld.magicEco.shiftedIndex) { player.addStat(ElementalWorld.MagicAchieve, 1); } } //This is how you check if a player has smelted something that returns the block/item you want them to gain an achievement for @Override public void onSmelting(EntityPlayer player, ItemStack item) { } @Override public void onCrafting(EntityPlayer player, ItemStack item, IInventory craftMatrix) { // TODO Auto-generated method stub } } Do I have to put the code somewhere else? Is that what I'm missing here? No signature for you!
February 5, 201312 yr Have you tried this tutorial yet? http://www.minecraftforge.net/wiki/How_to_add_an_Achievement If you found this post helpful, please take your time to give me a "Thank You".
February 5, 201312 yr Author Yes I have, that is basically where I got the achievement code from. But I want to know how to get an achievement when picking up an item. No signature for you!
February 5, 201312 yr Well, like diesieben07 said you need to make a class that implements EntityItemPickupEvent. If you found this post helpful, please take your time to give me a "Thank You".
February 5, 201312 yr Author Ummmm.... I've looked on the Wiki but it says that the page on Forge Events was deleted... Anybody know another link to somewhere that can explain it? No signature for you!
February 5, 201312 yr Author Okay thanks, but at the moment I have no idea what to put in the centre of the event. No signature for you!
February 5, 201312 yr Author Yes I know that, but what is the code for checking if the item that has been picked up is the right item No signature for you!
February 6, 201312 yr Author *Bump Anybody know what to put inside onItemPickup event??? No signature for you!
February 6, 201312 yr *sighs* When you got the last answer did you open up the EntityItemPickupEvent.java file and check how it works? did you try event.item? That will give you the EntityItem which was on the ground and is now being picked up by the player(event.player). Futher looking into the EntityItem.java file, trying to find a clue as to how to return the ItemStack it represents, I have NEVER seen this file before, so it took me a few minutes of reading the whole file before I found a method that MAYBE returns the correct ItemStack. If you read the file you should find it, and be able to test if it works. EntityItem.java has a function "func_92014_d()" which seems to return an ItemStack. Also the String getEntityName() - method is using that method in order to get the item's name. Which gives reason to believe that it is indeed func_92014_d we want. Now without looking at the spolier, you should be able to find the method which gives you what you need in order for this to work. If not, look at the spoiler(s) and see if it works, mind you that this is a proposed solution after just reading the files and not having done this myself I can't be 100% sure that it works. Also if you needed the instructions inn the spoilers, you might want to check out these: http://thenewboston.org/list.php?cat=31 <--- They will be invaluable to you, for learning to mod minecraft and program in any OOP language! @ForgeSubscribe public void onItemPickup(EntityItemPickupEvent event) { ItemStack item = event.item.func_92014_d(); if (item.itemID == myMod.myItemHere.ItemID){ event.player.addStat(ElementalWorld.MagicAchieve, 1); } } If you guys dont get it.. then well ya.. try harder...
February 6, 201312 yr Author *sighs* Yes indeed I did look through the file and then proceed to look through the EntityItem file. I looked through it alot and found a section where it triggered some achievements, looking through that I realised it was using item.itemID. So then I spent the next hour trying to use varying parts of the EntityItem file to trigger the achievement. I got very close on some occasions, but alas to no avail. But I didn't look at the func_92014_d(). Looking at what you have said, I basically had what was there just without the func part. But anyway thank you for that. It will help alot. No signature for you!
February 6, 201312 yr Well the point above was not to just be a douch, but to be sure that you do try to solve it by learning the code and studying what is happening Also the point is to get you to tell us what you have tried and thought of before asking, which helps the people helping you, not only to understand what solution you need but also what you are thinking and have tried. Another problem is that the people responding to these threads are mostly people who are learning modding with the forge api themselfs(like me) and they inn turn don't know every corner of the API themselfs. Even people with experience inn modding minecraft will have problems answering questions about areas of the API they never have had reason to use or look at Therefor describing the steps you have taken, does not only show that you are interested inn doing things yourself, but also helps others find the correct solution to give you, faster In any case, let me know if func_92014_d() worked as we think it should, and if it not well then we have to find a different way If you guys dont get it.. then well ya.. try harder...
February 7, 201312 yr Author Sorry to say but the func not only doesn't work, it doesn't exist (in EntityItem). :'( I dunno where you found it. I am in 1.4.7 of MCP so maybe you're in another version. Anyway I was looking around in EntityItem and found this: public String getEntityName() { return StatCollector.translateToLocal("item." + this.getEntityItem().getItemName()); } Looking at this I came up with what I thought would work: @ForgeSubscribe public void onItemPickup(EntityItemPickupEvent event) { String item = event.item.getEntityName(); if (item == "item.YourItem") { event.entityPlayer.addStat(YourMainModFile.YouAchievement, 1); } } Sadly that still doesn't work. Looking further I found the code for the achievements again: ItemStack var2 = this.getEntityItem(); int var3 = var2.stackSize; if (this.delayBeforeCanPickup <= 0 && (event.getResult() == Result.ALLOW || var3 <= 0 || par1EntityPlayer.inventory.addItemStackToInventory(var2))) { if (var2.itemID == Block.wood.blockID) { par1EntityPlayer.triggerAchievement(AchievementList.mineWood); } if (var2.itemID == Item.leather.itemID) { par1EntityPlayer.triggerAchievement(AchievementList.killCow); } if (var2.itemID == Item.diamond.itemID) { par1EntityPlayer.triggerAchievement(AchievementList.diamonds); } if (var2.itemID == Item.blazeRod.itemID) { par1EntityPlayer.triggerAchievement(AchievementList.blazeRod); } GameRegistry.onPickupNotification(par1EntityPlayer, this); Now I've been looking at this code trying to figure out how I can implement this. I am posting this now to see if you can figure it out before I can. Hopefully one of us does. So now I'll go and fiddle some more and get back to you when I'm done. Bye, bye, and good luck. P.S. Could you look at the new link I put on the Mod Holding Items post. No signature for you!
February 7, 201312 yr Author Okay, I have found something interesting. When I was looking at EntityItemPickupEvent I saw 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() */ So I thought I could just add setResult(ALLOW) somewhere, but apparently not. I traced all the way back to Entity.class and looked there. But I still can't figure out what to do. What I'm thinking is that if I get setResult(ALLOW) to work then the Achievement will work. So if anyone knows how to change that please tell me. If someone knows that changing this can be bad then please tell me as well. EDIT: This part here in Event.java: private boolean isCanceled = false; private final boolean isCancelable; private Result result = Result.DEFAULT; private final boolean hasResult; private static ListenerList listeners = new ListenerList(); DO NOT, I repeat DO NOT change private Result result = Result.DEFAULT; to private Result result = Result.ALLOW; . It breaks alot of things No signature for you!
February 7, 201312 yr Author Code for others: AchievementManager.class package mod.ElementalWorld; import net.minecraft.block.Block; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.stats.AchievementList; import net.minecraftforge.event.ForgeSubscribe; import net.minecraftforge.event.Event.Result; import net.minecraftforge.event.entity.player.EntityItemPickupEvent; import cpw.mods.fml.common.ICraftingHandler; public class AchievementManager implements ICraftingHandler { @ForgeSubscribe public void onItemPickup(EntityItemPickupEvent event) { if (event.item.entityId == ElementalWorld.magicEco.itemID) { System.out.println("Test"); event.entityPlayer.addStat(ElementalWorld.MagicAchieve, 1); } } @Override public void onCrafting(EntityPlayer player, ItemStack item, IInventory craftMatrix) { // TODO Auto-generated method stub } @Override public void onSmelting(EntityPlayer player, ItemStack item) { // TODO Auto-generated method stub } } No signature for you!
February 7, 201312 yr Author Some thoughts on your thoughts: 1) Yes I worked that out a while ago. 2) I have been looking for the past few days. I wouldn't be here if had found it. 3) The reason for that is when I set up this file I used the 'How To Make An Achievement' from the forum wiki. 4) I am learning. No signature for you!
February 7, 201312 yr Well my version of forge&mcp is 2 weeks old or so I believe, it might have been renamed since then... But even so opening the EntityItem.java inn eclipse shows only ONE method returning an ItemStack, the one I mentioned so it can't be that hard to find. If you want a quick answer now, then show me the 4-5 lines that make the getName method of your EntityItem.java file, as mentioned before that method uses the itemStack given from a method to give the item name. It can't be removed from your file.. If you guys dont get it.. then well ya.. try harder...
February 7, 201312 yr Author Here is the code: /** * Gets the username of the entity. */ public String getEntityName() { return StatCollector.translateToLocal("item." + this.getEntityItem().getItemName()); } I tried earlier today to use event.item.getEntityName(). I used system.out.println to print the name of the item and got this: item.item.magicEco. So then i decided to use this code to check for the right item: if(event.item.getEntityName() == "item.item.magicEco") and then added a println to check if it worked, but it never worked, even though the name was the same each time. P.S. like I said before could you look at the updated PasteBin link I put in the topic about the Mob Holding Item issue. No signature for you!
February 7, 201312 yr As everyone has said before me, look in EntityItem as there is a method to get an ItemStack (depending on Forge version it's either obfuscated (has func_###### as a name) or it's named getItem()), then compare it's itemID with the itemID if the item in your main mod file. the ItemStack itemId is easy to get: theItemstack.getItem().itemID; Your itemID is also easy (assuming you made the item refrence static, which you should): myMod.myItem.itemID; Unlike strings, you CAN use '==' with these are both are integers.
February 7, 201312 yr Here is the code: /** * Gets the username of the entity. */ public String getEntityName() { return StatCollector.translateToLocal("item." + this.getEntityItem().getItemName()); } So then i decided to use this code to check for the right item: if(event.item.getEntityName() == "item.item.magicEco") Why would you compare the EntityName with your item? That doesn't make sense at all, when you see this you should see which method's are being called inn the return statement and know which one to use. The getItemName says it gives you the NAME while the getEntityItem says it's getting an ITEM. If you open the getEntityItem method, what does it do? it returns an ItemStack! Futher: 4) I am learning. I assume you mean you are learning Java by modding Minecraft and following tutorials on minecraft modding? This is ONE way to do it, but you aren't learning Java, you are just learning some stuff about the Minecraft API without having any clue as to why and how it's done, thereby your problem here. Save yourself a lot of trouble and watch/read some stuff on Java, start with some basic java projects. I recommend creating a simple game such as Snake or Tetris in Java, once you do that you know the basics ya need for most minecraft modding I do recommend that at the very least you take your time to go trough the first parts of this Java series: http://thenewboston.org/list.php?cat=31 There's a lot of them, but I do recommend understanding all of them up to he's starting with Jfram and stuff(even tough those are good for understanding GUI's, they are different from GL11 which Minecraft uses tough). As I have told people before, countless times: If you learn Java first, then forge API, everything will be shit easy! Going the other way makes you fight like hell for every inch of progress without being able to get anywhere on your own. I don't want to be mean or upfront rude towards you(or any other aspiring programmer/modder) but if you want to create mods, it's stupid to do so without studying some Java first. It may be hard and most likely boring if you aren't into coding yet but starting off by creating any kind of mod without knowing the basics leads to countless of bugs and hours of frustration over simple problems. Above many people have tried to help you, all of them with the intention to be helpful towards you. I hope you realize that when they and I say, go learn Java basics, we do mean it as the single biggest advice to you! In anycase your problem should now have been answered by me and others in such a way that you should be okay If there are problems still, of course by all means do keep asking questions, but please for your own good: Learn java basics! If you guys dont get it.. then well ya.. try harder...
February 7, 201312 yr This is my code that works. Post this as a new class, and only change the achievement, the class names, and the item names. package net.minecraft.mardiff; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import cpw.mods.fml.common.IPickupNotifier; public class MardiffAchievementsPickup implements IPickupNotifier { @Override public void notifyPickup(EntityItem item, EntityPlayer player) { if(item.func_92014_d().itemID == MardiffBase.ruby.itemID) { player.addStat(MardiffBase.MardiffGem, 1); } } } If you really want help, give that modder a thank you. Modders LOVE thank yous.
February 8, 201312 yr Author Guys Here is what my EntityItem.java is: http://pastebin.com/wVH1GbPc Could you compare to yours (The ones of you that have func_92014_d()) and tell me what it's been renamed too. No signature for you!
February 9, 201312 yr Author No I am not. I knew that existed. I ahve tried that. But FOR SOME REASON IT DOESN"T WORK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! I'm going to give up now. Goodbye. No signature for you!
February 9, 201312 yr Author I've deleted it because it doesn't work. I even copied madriff's code but it still doesn't work even when I rename the things. import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import cpw.mods.fml.common.IPickupNotifier; public class AchievementPickupManager implements IPickupNotifier { @Override public void notifyPickup(EntityItem item, EntityPlayer player) { if(item.getEntityItem().itemID == ElementalWorld.magicEco.itemID) { player.addStat(ElementalWorld.MagicAchieve, 1); } } } EDIT: Forgot to say that I've added System.out.println("Test"); to test whether it works and everything works besides notifyPickup. So the class is working. But for somereason the item.getEntityItem().itemID is returning a different itemID than the magicEco.itemID even when I pickup the item. No signature for you!
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.