MGlolenstine Posted June 28, 2017 Posted June 28, 2017 What is rightClick event or something similar? Quote
Jay Avery Posted June 28, 2017 Posted June 28, 2017 There are various events and methods used in different situations. What particular case do you want to use? E.g. using an item, right-clicking a block, interacting with an entity? Is it with something you control (i.e. you added the code in your own mod), or not (i.e. something from vanilla or another mod)? In general, you can look through events in the net.minecraftforge.events package - most of them have good documentation and you can also use your IDE to find the places where a particular event is used. 1 Quote
MGlolenstine Posted June 28, 2017 Author Posted June 28, 2017 Just now, Jay Avery said: There are various events and methods used in different situations. What particular case do you want to use? E.g. using an item, right-clicking a block, interacting with an entity? Is it with something you control (i.e. you added the code in your own mod), or not (i.e. something from vanilla or another mod)? In general, you can look through events in the net.minecraftforge.events package - most of them have good documentation and you can also use your IDE to find the places where a particular event is used. Actually I was looking for using an item, thanks! Could I get the link to the documentation? I just don't seem to be able to get anything else than the ItemPickup event in this docs: https://mcforge.readthedocs.io/en/latest/events/intro/ Thanks once again! Quote
Jay Avery Posted June 28, 2017 Posted June 28, 2017 For an item you've coded, it's easier to override the onItemRightClick method in your item class. Otherwise you can use PlayerInteractEvent.RightClickItem. I don't know if there's a place in the docs website with all the events, but the event classes in the code have doc comments explaining how and when they are called. 1 Quote
MGlolenstine Posted June 28, 2017 Author Posted June 28, 2017 12 minutes ago, Jay Avery said: For an item you've coded, it's easier to override the onItemRightClick method in your item class. Otherwise you can use PlayerInteractEvent.RightClickItem. I don't know if there's a place in the docs website with all the events, but the event classes in the code have doc comments explaining how and when they are called. Ok, so I tried to override the method... My current WoodenRing.java is package xyz.mglolenstine.SimpleRings; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.item.EntityTNTPrimed; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.world.World; public class WoodenRing extends Item{ public WoodenRing(String registryName, int MaxStackSize){ super(); this.setRegistryName(registryName); this.setUnlocalizedName(registryName); this.setCreativeTab(CreativeTabs.REDSTONE); this.setMaxStackSize(MaxStackSize); } @Override public ItemStack onItemRightClick(ItemStack item, World world, EntityPlayer player) { return item; } } but the @Override has some interesting stuff to say... Quote
Jay Avery Posted June 28, 2017 Posted June 28, 2017 That means the method signature doesn't match the one in the superclass. Take a look in the Item class (net.minecraft.item.Item) and search for "onItemRightClick", and make sure you have exactly the same parameters and return type. The parameters and return type changed around a lot in the last few minecraft versions, so if you've looked at a different version it probably won't match. 1 Quote
MGlolenstine Posted June 28, 2017 Author Posted June 28, 2017 7 minutes ago, Jay Avery said: That means the method signature doesn't match the one in the superclass. Take a look in the Item class (net.minecraft.item.Item) and search for "onItemRightClick", and make sure you have exactly the same parameters and return type. The parameters and return type changed around a lot in the last few minecraft versions, so if you've looked at a different version it probably won't match. I know that I'm gonna sound stupid because I don't know anything about this stuff, but where can I find that net.minecraft.item.Item class? In the build/tmp/recompileMc/compiled/net/minecraft/item I don't see any methods named "onItemRightClick" smh... Quote
Jay Avery Posted June 28, 2017 Posted June 28, 2017 In your workspace there should be something called "referenced libraries" or similar, and inside there will be a folder called something like forgeSrc. Here is what it looks like in my eclipse workspace: You can also get directly to a particular class by right-clicking and choosing "open declaration" (again, in eclipse - but other IDEs should have something similar) - for example you can click on Item where your class extends it. Quote
MGlolenstine Posted June 28, 2017 Author Posted June 28, 2017 1 minute ago, Jay Avery said: In your workspace there should be something called "referenced libraries" or similar, and inside there will be a folder called something like forgeSrc. Here is what it looks like in my eclipse workspace: You can also get directly to a particular class by right-clicking and choosing "open declaration" (again, in eclipse - but other IDEs should have something similar) - for example you can click on Item where your class extends it. Aha, I see it now... Thanks! Quote
Dylem Posted June 29, 2017 Posted June 29, 2017 Under Eclipse, you could juste press CTRL + SHIFT + T and type Item to find the class. 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.