Jump to content

[1.7.10]hasEffect() Deprecated


Roboman

Recommended Posts

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?

Link to comment
Share on other sites

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/

Link to comment
Share on other sites

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/

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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")'

Link to comment
Share on other sites

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I am not using hardcoded recipes, I'm using Vanilla's already existing code for leather armor dying. (via extending and implementing DyeableArmorItem / DyeableLeatherItem respectively) I have actually figured out that it's something to do with registering item colors to the ItemColors instance, but I'm trying to figure out where exactly in my mod's code I would be placing a call to the required event handler. Unfortunately the tutorial is criminally undescriptive. The most I've found is that it has to be done during client initialization. I'm currently trying to do the necessary setup via hijacking the item registry since trying to modify the item classes directly (via using SubscribeEvent in the item's constructor didn't work. Class so far: // mrrp mrow - mcmod item painter v1.0 - catzrule ch package catzadvitems.init; import net.minecraft.client.color.item.ItemColors; import net.minecraft.world.item.Item; import net.minecraftforge.registries.ObjectHolder; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.client.event.ColorHandlerEvent; import catzadvitems.item.DyeableWoolArmorItem; @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD) public class Painter { @ObjectHolder("cai:dyeable_wool_chestplate") public static final Item W_CHEST = null; @ObjectHolder("cai:dyeable_wool_leggings") public static final Item W_LEGS = null; @ObjectHolder("cai:dyeable_wool_boots") public static final Item W_SOCKS = null; public Painter() { // left blank, idk if forge throws a fit if constructors are missing, not taking the chance of it happening. } @SubscribeEvent public static void init(FMLClientSetupEvent event) { new Painter(); } @Mod.EventBusSubscriber private static class ForgeBusEvents { @SubscribeEvent public static void registerItemColors(ColorHandlerEvent.Item event) { ItemColors col = event.getItemColors(); col.register(DyeableUnderArmorItem::getItemDyedColor, W_CHEST, W_LEGS, W_SOCKS); //placeholder for other dye-able items here later.. } } } (for those wondering, i couldn't think of a creative wool helmet name)
    • nvm found out it was because i had create h and not f
    • Maybe there's something happening in the 'leather armor + dye' recipe itself that would be updating the held item texture?
    • @SubscribeEvent public static void onRenderPlayer(RenderPlayerEvent.Pre e) { e.setCanceled(true); model.renderToBuffer(e.getPoseStack(), pBuffer, e.getPackedLight(), 0f, 0f, 0f, 0f, 0f); //ToaPlayerRenderer.render(); } Since getting the render method from a separate class is proving to be bit of a brick wall for me (but seems to be the solution in older versions of minecraft/forge) I've decided to try and pursue using the renderToBuffer method directly from the model itself. I've tried this route before but can't figure out what variables to feed it for the vertexConsumer and still can't seem to figure it out; if this is even a path to pursue.  The vanilla model files do not include any form of render methods, and seem to be fully constructed from their layer definitions? Their renderer files seem to take their layers which are used by the render method in the vanilla MobRenderer class. But for modded entities we @Override this function and don't have to feed the method variables because of that? I assume that the render method in the extended renderer takes the layer definitions from the renderer classes which take those from the model files. Or maybe instead of trying to use a render method I should be calling the super from the renderer like   new ToaPlayerRenderer(context, false); Except I'm not sure what I would provide for context? There's a context method in the vanilla EntityRendererProvider class which doesn't look especially helpful. I've been trying something like <e.getEntity(), model<e.getEntity()>> since that generally seems to be what is provided to the renderers for context, but I don't know if it's THE context I'm looking for? Especially since the method being called doesn't want to take this or variations of this.   In short; I feel like I'm super super close but I have to be missing something obvious? Maybe this insane inane ramble post will provide some insight into this puzzle?
  • Topics

×
×
  • Create New...

Important Information

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