Jump to content

Recommended Posts

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?

Posted

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/

Posted

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?

Posted

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.

Posted

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

Posted

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

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

Announcements



×
×
  • Create New...

Important Information

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