MinecraftMart Posted February 28, 2014 Posted February 28, 2014 (edited) I am searching for a ender pearl throw event so if it is throwed 10 times you get a achievement. Does somebody know wich event this is?And how to implement it? Edited February 4, 2018 by MinecraftMart Quote
coolAlias Posted February 28, 2014 Posted February 28, 2014 EnderTeleportEvent gets posted when the actual teleportation is about to occur, and EntityJoinWorldEvent is posted when the EntityEnderPearl is spawned, but if you want to intercept it just as it is about to be thrown, then the event mentioned by diesieben07 is your best bet. Quote http://i.imgur.com/NdrFdld.png[/img]
MinecraftMart Posted February 28, 2014 Author Posted February 28, 2014 So i did some testing and it didnt work r is my cod: package com.mart.achievements; import ibxm.Player; import net.minecraft.block.Block; import net.minecraft.init.Blocks; import net.minecraftforge.event.entity.living.EnderTeleportEvent; import net.minecraftforge.event.entity.player.EntityItemPickupEvent; import net.minecraftforge.event.entity.player.PlayerInteractEvent; import cpw.mods.fml.common.event.FMLMissingMappingsEvent.Action; import cpw.mods.fml.common.eventhandler.SubscribeEvent; public class ThrowingHandler { public int PT = 0; @SubscribeEvent public void onItemThrow(PlayerInteractEvent p){ if (p.action.RIGHT_CLICK_BLOCK != null){ System.out.println("Mart"); PT = PT + 1; } if(PT == 10) { p.entityPlayer.addStat(Achievements.Enderpearl, 1); } } } And wich on if this should i use? MinecraftForge.EVENT_BUS.register(new ThrowingHandler()); FMLCommonHandler.instance().bus().register(new ThrowingHandler()); Quote
coolAlias Posted February 28, 2014 Posted February 28, 2014 "if (p.action.RIGHT_CLICK_BLOCK != null)" ... <cough>, umm, that's not how enumerations are typically checked. I prefer to use a switch, but you can use if statements as well: if (event.action == Action.RIGHT_CLICK_AIR) { // do stuff } Look at the import for PlayerInteractEvent and you'll find out which event bus to register it with. import net.minecraftforge.event.entity.player.PlayerInteractEvent; Quote http://i.imgur.com/NdrFdld.png[/img]
MinecraftMart Posted February 28, 2014 Author Posted February 28, 2014 "if (p.action.RIGHT_CLICK_BLOCK != null)" ... <cough>, umm, that's not how enumerations are typically checked. I prefer to use a switch, but you can use if statements as well: if (event.action == Action.RIGHT_CLICK_AIR) { // do stuff } Look at the import for PlayerInteractEvent and you'll find out which event bus to register it with. import net.minecraftforge.event.entity.player.PlayerInteractEvent; Then this happens RIGHT_CLICK_AIR cannot be resolved or is not a field Quote
coolAlias Posted February 28, 2014 Posted February 28, 2014 You have to import the class. Press "ctrl-shift-o" if you are using Eclipse, it will automatically import what you need. Or hover your mouse over "Action" and see that Eclipse gives you some ideas of how to fix what's wrong, one of which should be to import the class. Quote http://i.imgur.com/NdrFdld.png[/img]
larsgerrits Posted February 28, 2014 Posted February 28, 2014 "if (p.action.RIGHT_CLICK_BLOCK != null)" ... <cough>, umm, that's not how enumerations are typically checked. I prefer to use a switch, but you can use if statements as well: if (event.action == Action.RIGHT_CLICK_AIR) { // do stuff } Import Action Look at the import for PlayerInteractEvent and you'll find out which event bus to register it with. import net.minecraftforge.event.entity.player.PlayerInteractEvent; Then this happens RIGHT_CLICK_AIR cannot be resolved or is not a field Quote Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/
MinecraftMart Posted February 28, 2014 Author Posted February 28, 2014 Okay all errors gone! But now on thing.. if you click in the air without trowing a ball it also activates te counter.. and it doesnt even trigger the achievement. package com.mart.achievements; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action; public class ThrowingHandler { public int PT = 0; @SubscribeEvent public void onItemThrow(PlayerInteractEvent event){ if (event.action == Action.RIGHT_CLICK_AIR){ PT = PT + 1; System.out.println(PT); if(PT == 10) { System.out.println("BRIKT"); event.entityPlayer.addStat(Achievements.Enderpearl, 1); } } } } Quote
Draco18s Posted February 28, 2014 Posted February 28, 2014 Gee golly willakers, you never checked to see if the item the player has in their hand is an ender pearl. Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
MinecraftMart Posted February 28, 2014 Author Posted February 28, 2014 1) You probably want to store that counter per-player. Right now if 10 players throw an EnderPearl, the 10th one will get the achievement, even though he only threw one ender pearl. 2) Your probably want to store that counter at all. Right now, if a player throws 9 pearls and then logs out, the counter is reset. 3) RIGHT_CLICK_AIR fires every time the player right clicks air. You should check if he's holding an Ender pearl. O wauw. Well i need some time to figure this out. Its really hard Quote
MinecraftMart Posted February 28, 2014 Author Posted February 28, 2014 Its really hard No it's not. This is fuckin basic java. Well I aint that good at Java. A bit but i try to learn it. And it would be cool if you wanted to help me a bit. This is really wat i want to do even if i dont know how to. Quote
MinecraftMart Posted March 1, 2014 Author Posted March 1, 2014 Okay i cant figure this out. Is somebody willing to help me? Quote
coolAlias Posted March 1, 2014 Posted March 1, 2014 Okay i cant figure this out. Is somebody willing to help me? event.entityPlayer gives you the player, right? What methods are there in EntityPlayer that give you the item the player is holding? There are at least 2, but the easiest one is getHeldItem(), which returns an ItemStack or null if the player is empty-handed. So the steps look like this: 1. Get the ItemStack the player is holding 2. Check if it's null 3. If it's not null, check that the item in the ItemStack is an Ender Pearl 4. Increment the counter for your player But as diesieben already pointed out, you are incrementing a single counter for all players, rather than a counter for each player. Perhaps you can tackle that another day after you have more Java under your belt, but if you're feeling adventurous, look into IExtendedEntityProperties. Quote http://i.imgur.com/NdrFdld.png[/img]
MinecraftMart Posted March 1, 2014 Author Posted March 1, 2014 Okay i cant figure this out. Is somebody willing to help me? event.entityPlayer gives you the player, right? What methods are there in EntityPlayer that give you the item the player is holding? There are at least 2, but the easiest one is getHeldItem(), which returns an ItemStack or null if the player is empty-handed. So the steps look like this: 1. Get the ItemStack the player is holding 2. Check if it's null 3. If it's not null, check that the item in the ItemStack is an Ender Pearl 4. Increment the counter for your player But as diesieben already pointed out, you are incrementing a single counter for all players, rather than a counter for each player. Perhaps you can tackle that another day after you have more Java under your belt, but if you're feeling adventurous, look into IExtendedEntityProperties. Thx! But now i got 1 little problem left. package com.mart.achievements; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action; public class ThrowingHandler { public int PT = 0; @SubscribeEvent public void onItemThrow(PlayerInteractEvent event, EntityPlayer k){ EntityPlayer player = (EntityPlayer) event.entity; ItemStack heldItem = k.getHeldItem(); if (event.entityPlayer.getHeldItem() == null){ return; } //THIS LINE What to say here? else if(heldItem == Items.ender_pearl){ } if(PT >= 10) { event.entityPlayer.addStat(Achievements.Enderpearl, 1); System.out.println("BRIKT"); } } } Quote
larsgerrits Posted March 1, 2014 Posted March 1, 2014 You are comparing a Itemstack:heldItem with a Item:Item.ender_pearl. If you want to compare those 2, you need to get the item out of the ItemStack and compare that with the item. Then you can update the PT variable. Quote Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/
MinecraftMart Posted March 1, 2014 Author Posted March 1, 2014 You are comparing a Itemstack:heldItem with a Item:Item.ender_pearl. If you want to compare those 2, you need to get the item out of the ItemStack and compare that with the item. Then you can update the PT variable. Okay i get that but now i need to put it in code it tried some things but wouldnt work. Can you give me a example or show it me? Quote
larsgerrits Posted March 1, 2014 Posted March 1, 2014 Can't you even do that? How do you even want to make a Minecraft mod that way? Quote Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/
MinecraftMart Posted March 1, 2014 Author Posted March 1, 2014 Can't you even do that? How do you even want to make a Minecraft mod that way? Nope, But is that even important? I do what i like to do and i just need help. I already got a few achievements ready and they work so im already proud of that. Im only 14 years and i am a beginner at java. I dont see the need to know all the stuff when i only need help with the basics. When i have te code i figure out myself how they work and i can make more progress. Im just doin what i like and you can help or you can not. Your decision. But it would be awesome if you could help Quote
sequituri Posted March 1, 2014 Posted March 1, 2014 Not to discourage you, little one, but their are many 30 year old java veterans who are struggling to write mods for Minecraft. And you think you can do it with no programming background or java experience whatsoever? You really should find a school class for programming unless you are a genius. Otherwise, your questions on the "basics" will just annoy people until you get booted. Think about it. Quote -S- (if I helped, please click Thank and applaud) http://6upnqa.dm2301.livefilestore.com/y2mtf-vG7Tqq1TiiVpIm53KWj7294NDPoHfSHHb4PzZiMAUfRCfK0UY0MwOu7Q3zTBNVTKqWjr2-xgBfFRpQT5p-QivtvknPpoABMNUw9br9WuZcBFkjePhnAbW500gVm-P/sequiturian.png[/img]
MinecraftMart Posted March 1, 2014 Author Posted March 1, 2014 Okay as i think about it it is pretty dumb yes. But its just i wanted to do this for a long time and now i finally understand the basics. I am learning java atm and try to understand every single bit of code. I will stop asking stupid questions and asking for basics. If you guyz could just help me finish this code that would be very awsome. Sorry for the trouble i caused or if i anoyed people. Quote
Draco18s Posted March 1, 2014 Posted March 1, 2014 ItemStack.getItem() perhaps? Use your god damn IDE for what it was built for. Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
MinecraftMart Posted March 2, 2014 Author Posted March 2, 2014 Already tried but it didnt work. Quote
coolAlias Posted March 2, 2014 Posted March 2, 2014 Chill guys, he's just a kid. Don't you remember what it was like when you first started coding? Everyone has to start somewhere. @OP: That being said, you would do yourself a huge favor by stopping what you're doing and spending some time learning Java or any other language. Try the New Boston for video tutorials, and / or spend some time browsing through the tutorials on Oracle's website. Regarding your problem, follow the steps I mentioned earlier: // get the held ItemStack (you may need to substitute 'player' with 'event.player' or whatever: ItemStack stack = player.getHeldItem(); // check if it's not null and the item contained therein is an ender pearl: if (stack != null && stack.getItem() == Items.ender_pearl) { // increment your counter or whatever else you want to do } This is very basic Java / IDE use, and as has been stated, this is not a Java help forum. Good luck. Quote http://i.imgur.com/NdrFdld.png[/img]
MinecraftMart Posted March 2, 2014 Author Posted March 2, 2014 It worked! Thank you! And yes i will stop with the hard ones. But i already have some basic ones and will continue making them since their easy. I watch te new boston and we are also learning java in class now so i hope this mod will be cool one day Thank you Quote
MinecraftMart Posted February 4, 2018 Author Posted February 4, 2018 Damn. I grew a lot in 4 years. Thanks for the help guyz, you helped me become what I am today haha Marked as SOLVED. Quote
Recommended Posts
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.