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

Posted

So, I'm trying to make an item that when it is right clicked with the effect changes (adds the shiny nether start effect over it). I looked at some things online, and I'm ending up using this:

 

@SideOnly(Side.CLIENT)

    public boolean hasEffect(ItemStack itemStack)

    {

        return effectChange;

    }

 

 

effectChange is:

 

@Override

    public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer entityPlayer)

    {

        effectChange = !effectChange;

        return itemStack;

    }

 

 

However, when I look at my overridden hasEffect in IntellijIdea, it crosses it out and shows that its deprecated. What should I use instead then?

Also, don't store the hasEffect in the item class, else it will be shared across all item instances.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

  • Author

So, where would I want it?

 

EDIT: Hmm, I see another declaration of hasEffect below, with int pass as one of the arguments. I'll look into that. But still. Where would I want it if not in the item class? Where else would I say that?

Roboman, the method is fine in your Item class.

 

larsgerrits, 'hasEffect' is not a class field, it's a class method, otherwise you would be right, at least in the case of wanting to have a unique value for each stack, rather than per item. It sounds like the OP just wants every Item of this type to have the glow.

  • Author

No, thats not quite what I want. When the item is right click with (used, but not used up), I want that item to have the glow activated over it. Only that one, not all of that type. I understand why it shouldn't be in the item declaration class, but where should I have it is my question?

 

Also, the code I posted in the OP makes the item flicker quickly when right clicked with. Any ideas why this might happen? I think it has something to do with it being in the wrong spot.

Ah... sorry larsgerrits, I didn't see the addition of code to the OP :P

 

@OP You need to store it in the ItemStack NBT, like largerrits mentioned, and make sure you only do it once per right click, and do it on the server - NBT should sync automatically for ItemStacks.

  • Author

Sorry, I'm new to forge coding, and new to Java (But don't fear! I know how to program and have looked at many examples, I'm not clueless). I need to store it in the ItemStack NBT, thats something I need to define, isn't it. Also, doing it on the server is a simple as @SideOnly(Side.SERVER), right? If you could lead me through at least one of these things, I think I can figure out how to do it.

 

I'm doing this just to see what I CAN do and what I know I can do, this exercise is doing what its meant to do :P

No, don't use @SideOnly; in the method parameters for onItemRightClick, there is a 'World' object, named 'world' -> use that to check side:

if (world.isRemote) {
// you are on the client right now
}
// if (!world.isRemote) means you are on the server

 

For NBT tags, they are stored in the ItemStack already, not something you add to your class. Use them like this:

// 'stack' is the ItemStack from the method parameters, and this goes inside the method

// always check if the stack has a tag compound before you try to use it:
if (!stack.hasTagCompound()) {
stack.setTagCompound(new NBTTagCompound());
}
if (!world.isRemote) { // on the server
// there are lots of different 'set' methods for NBTTagCompounds
// each tag is stored with a String key, such as 'isGlowing':
boolean isGlowing = stack.getTagCompound().getBoolean("isGlowing");
// now store the opposite:
stack.getTagCompound().setBoolean("isGlowing", !isGlowing);
}
}

 

Then in your hasEffect(ItemStack, int) method, you can return 'stack.hasTagCompound() && stack.getTagCompound().getBoolean("isGlowing")'

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.