Jump to content

Recommended Posts

Posted

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.

Posted

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.

Posted

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.

Posted

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

Posted

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).

Posted

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.

Posted

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.

Guest
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.