Posted August 24, 201411 yr 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?
August 24, 201411 yr If you looked in Item, you'd see it: "public boolean hasEffect(ItemStack par1ItemStack, int pass)" http://i.imgur.com/NdrFdld.png[/img]
August 24, 201411 yr 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/
August 24, 201411 yr 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?
August 24, 201411 yr You can store it in the ItemStacks stackTagCompound. 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/
August 24, 201411 yr 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. http://i.imgur.com/NdrFdld.png[/img]
August 24, 201411 yr 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.
August 24, 201411 yr Ah... sorry larsgerrits, I didn't see the addition of code to the OP @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. http://i.imgur.com/NdrFdld.png[/img]
August 24, 201411 yr 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
August 24, 201411 yr 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")' http://i.imgur.com/NdrFdld.png[/img]
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.