Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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.

  • Author
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!

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.

  • Author
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...

5953cc7f1ea0d_Screenshotfrom2017-06-2817-34-08.png.48f3fe4cffbfc0b672f572b54bd0d5ad.png

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.

  • Author
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...

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:

5953d4352c155_ScreenShot2017-06-28at17_05_28.thumb.png.ffe580146ab86f6bc79c1e9098c6cfe8.png

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.

  • Author
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:

5953d4352c155_ScreenShot2017-06-28at17_05_28.thumb.png.ffe580146ab86f6bc79c1e9098c6cfe8.png

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!

Under Eclipse, you could juste press CTRL + SHIFT + T and type Item to find the class.

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

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.