Posted June 25, 201411 yr I'm trying to use the PlayerUseItemEvent but I keep getting this error: java.lang.InstantiationException at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at cpw.mods.fml.common.eventhandler.EventBus.register(EventBus.java:90) at cpw.mods.fml.common.eventhandler.EventBus.register(EventBus.java:72) at com.gegy1000.advancedgravity.event.AdvancedGravityEvents.registerEvents(AdvancedGravityEvents.java:13) at com.gegy1000.advancedgravity.proxy.CommonProxy.init(CommonProxy.java:12) at com.gegy1000.advancedgravity.proxy.ClientProxy.init(ClientProxy.java:21) at com.gegy1000.advancedgravity.AdvancedGravityMod.load(AdvancedGravityMod.java:106) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:74) at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:47) at com.google.common.eventbus.EventBus.dispatch(EventBus.java:314) at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:296) at com.google.common.eventbus.EventBus.post(EventBus.java:267) at cpw.mods.fml.common.LoadController.sendEventToModContainer(LoadController.java:209) at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:188) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:74) at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:47) at com.google.common.eventbus.EventBus.dispatch(EventBus.java:314) at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:296) at com.google.common.eventbus.EventBus.post(EventBus.java:267) at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:119) at cpw.mods.fml.common.Loader.loadMods(Loader.java:500) at cpw.mods.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:202) at net.minecraft.client.Minecraft.startGame(Minecraft.java:520) at net.minecraft.client.Minecraft.run(Minecraft.java:890) at net.minecraft.client.main.Main.main(Main.java:112) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at net.minecraft.launchwrapper.Launch.launch(Launch.java:134) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) Registry Code: MinecraftForge.EVENT_BUS.register(new EventPlayerUseItem()); Event Class: package com.gegy1000.advancedgravity.event; import net.minecraft.entity.passive.EntityCow; import net.minecraft.init.Items; import net.minecraft.world.World; import net.minecraftforge.event.entity.player.PlayerUseItemEvent; import com.gegy1000.advancedgravity.handler.AdvancedGravityGravityHandler; import com.gegy1000.advancedgravity.rotated.RotatedEntity; import cpw.mods.fml.common.eventhandler.SubscribeEvent; public class EventPlayerUseItem { @SubscribeEvent public void onRightClick(PlayerUseItemEvent event) //Changed PlayerUseItemEvent to PlayerUseItemEvent.Finish. And now it doesn't give me an error but the event never get's called { if(event.item.getItem() == Items.stick) { RotatedEntity rotatedentity = (RotatedEntity) AdvancedGravityGravityHandler.getRotatedEntities(event.entityPlayer.worldObj).get(event.entityPlayer.getUniqueID().toString()); if(rotatedentity != null) { if(rotatedentity.rotation == 1) { World world = event.entityPlayer.worldObj; EntityCow cow = new EntityCow(world); world.spawnEntityInWorld(cow); AdvancedGravityGravityHandler.rotateEntity(cow, 1); } } } } }
June 25, 201411 yr Diesieben07's somewhat cryptic remark means that you have to look at the extended events from PlayerUseItemEvent and find the one you want. There is actually these events available: PlayerUseItemEvent.Start PlayerUseItemEvent.Tick PlayerUseItemEvent.Finish PlayerUseItemEvent.Stop By the way, I know it is hard to figure out all the available events, and also you can get ideas from mods by learning all the available events so I've tried to compile a list in my tutorial, you might want to check it out: http://jabelarminecraft.blogspot.com/p/minecraft-forge-172-event-handling.html Check out my tutorials here: http://jabelarminecraft.blogspot.com/
June 25, 201411 yr How is it hard to find all events? Just let your IDE display the Type-hierarchy on the Event base class. In eclipse I don't know the shortcut but in Intellij it's Ctrl-Alt-B. Yes, of course that is how I find them (in Eclipse it is F4). But it is easier I think to have a list that already filters out the abstract ones (the problem encounterred by the person on this thread) and further organizes them by what bus to register on (as that is another common noob mistake). Plus in my list I am starting to link tutorials on interesting examples of uses for each one, and other comments as needed. Anyway, it could be said that most of the questions on this forum can be solved by following the code in Eclipse ... Check out my tutorials here: http://jabelarminecraft.blogspot.com/
June 27, 201411 yr Author Diesieben07's somewhat cryptic remark means that you have to look at the extended events from PlayerUseItemEvent and find the one you want. There is actually these events available: PlayerUseItemEvent.Start PlayerUseItemEvent.Tick PlayerUseItemEvent.Finish PlayerUseItemEvent.Stop By the way, I know it is hard to figure out all the available events, and also you can get ideas from mods by learning all the available events so I've tried to compile a list in my tutorial, you might want to check it out: http://jabelarminecraft.blogspot.com/p/minecraft-forge-172-event-handling.html I've used PlayerUseItemEvent.Finish and it doesn't give an error but the even never get's called.
June 27, 201411 yr I've used PlayerUseItemEvent.Finish and it doesn't give an error but the even never get's called. Well if you follow the call hierarchy in Eclipse, this event is created and posted in the onItemUseFinish() method in the FMLEventFactory class, which is called by the onItemUseFinish() method in EntityPlayer. And that is called by onUpdate() method in EntityPlayer as well as onItemUseFinish() in EntityPlayerMP as well as handleHealUpdate() in EntityPlayer. So it seems likely that it is getting posted. How did you test this? You need to completely eat something, or similar. What bus did your register the event handler to? Check out my tutorials here: http://jabelarminecraft.blogspot.com/
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.