Posted January 31, 201411 yr I would like to add a right click event to vanilla axes to make them throwable and would like to know how to go about doing this. I know I need to use events, but I have no idea how to set those up.
January 31, 201411 yr You might find this link useful to learn about events http://www.minecraftforum.net/topic/1419836-forge-4x-events-howto/ -TGG
January 31, 201411 yr Author You might find this link useful to learn about events http://www.minecraftforum.net/topic/1419836-forge-4x-events-howto/ -TGG @ForgeSubscribe seems to not work in 1.7. Any suggestions?
January 31, 201411 yr I may be wrong as I haven't modded for 1.7 yet myself, but I believe they changed it to '@SubscribeEvent'. http://i.imgur.com/NdrFdld.png[/img]
January 31, 201411 yr Author All right, @SubscribeEvent seems to be okay, but I'm not sure how to use the event. I was looking at the PlayerUseItemEvent and the item is final, meaning I can't set it.
January 31, 201411 yr Just because the Item is final doesn't mean you can't change what the player is doing with it. You want right-click to throw, so when the UseEvent fires, check if the item is an axe and, if so, spawn a new EntityThrowingAxe or whatever into the world and set the player's currently held item slot to null. Make sure to cancel the event if possible so you don't subsequently throw a null-pointer exception. http://i.imgur.com/NdrFdld.png[/img]
January 31, 201411 yr Author All right, I thought I had it, but it doesn't seem to work. Any ideas? Here is the current event class. https://github.com/Renkin42/Renkin42SWT_Gradle/blob/unreleased/src/main/java/renkin42/stuffWorthThrowing/event/StuffWorthThrowingEvents.java
January 31, 201411 yr You can't compare ItemStack instances this way. Use the comparators defined within the ItemStack class.
January 31, 201411 yr HI You can't compare ItemStack instances this way. Use the comparators defined within the ItemStack class. FYI the reason == doesn't work is explained in this link. It talks about Strings but the idea is the same. http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java -TGG
February 1, 201411 yr Author I switched to using ItemStack.areItemStacksEqual, but still nothing. I've tried both @SubscribeEvent and @EventHandler annotations. I am, however, getting a rather interesting error in my log: [17:22:47] [Client thread/ERROR] [FML]: Unable to determine registrant mod for net.minecraftforge.common.ForgeInternalHandler@5f0f176. This is a critical error and should be impossible
February 1, 201411 yr You are declaring a new ItemStack in your eventhandler and checking if the item the player is using is that new ItemStack... what did you expect to happen? How could the player possibly be using an ItemStack stored in your EventHandler class??? EDIT: of course, using ItemStacks.areEqual method should still work for detecting if two itemstacks have the same item, but if your player's wooden axe is damaged at all, it will not be considered equal to the undamaged stack from your event handler. You need to check if the Item that the player is using is some kind of Axe and create a new thrown entity based off of, oh I don't know, the axe's material or something. // let me preface by saying that I don't have 1.7.2, so I am not sure exactly what the variables are called // but the logic will be the same // check if the Item is an Axe (if Item is really an ItemStack, then you'd use event.item.getItem()) if (event.item instanceof ItemAxe) { // assuming there is a player available from the event // and assuming you have an EntityThrowable that takes a world and player object in the constructor // then the following will set the position and heading automatically EntityThrowingAxe axe = new EntityThrowingAxe(event.player.worldObj, event.player); // now let's assume you created a method in your throwing axe entity to parse through items and get // the correct material, or you could just get the AttackDamage attribute modifier from the Item's // multimap and set the damage that way axe.setMaterial(event.item); // then spawn it into the world if (!event.player.worldObj.isRemote) { event.player.worldObj.spawnEntityInWorld(axe); } } Obviously the code will probably not work exactly as written, but that is what you need to do (logically speaking). http://i.imgur.com/NdrFdld.png[/img]
February 1, 201411 yr ItemStack#getItem()? 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.
February 1, 201411 yr Author At this point I'm not even worried about the item thing, I just want to get the event register working. Here is the full error from my log: [20:34:28] [Client thread/ERROR] [FML/]: Unable to determine registrant mod for net.minecraftforge.common.ForgeInternalHandler@6b8302a4. This is a critical error and should be impossible java.lang.Throwable at cpw.mods.fml.common.eventhandler.EventBus.register(EventBus.java:42) [EventBus.class:?] at net.minecraftforge.common.MinecraftForge.initialize(MinecraftForge.java:46) [MinecraftForge.class:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_21] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_21] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_21] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_21] at cpw.mods.fml.common.FMLCommonHandler.callForgeMethod(FMLCommonHandler.java:184) [FMLCommonHandler.class:?] at cpw.mods.fml.common.FMLCommonHandler.beginLoading(FMLCommonHandler.java:96) [FMLCommonHandler.class:?] at cpw.mods.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:178) [FMLClientHandler.class:?] at net.minecraft.client.Minecraft.startGame(Minecraft.java:561) [Minecraft.class:?] at net.minecraft.client.Minecraft.run(Minecraft.java:928) [Minecraft.class:?] at net.minecraft.client.main.Main.main(Main.java:112) [Main.class:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_21] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_21] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_21] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_21] at net.minecraft.launchwrapper.Launch.launch(Launch.java:134) [launchwrapper-1.9.jar:?] at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.9.jar:?]
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.