Jump to content

Recommended Posts

Posted

I am making a mod where when you kill a mob you get its hp into soulpower, and I am trying to get it to be stored in a nbt tag on the enchanted weapon, everything works except the nbt Tag.

I have tried with setTags but that gets rid of the enchantment.
 

  Reveal hidden contents
  Reveal hidden contents

 

Posted
  On 7/28/2022 at 10:24 AM, Luis_ST said:

You can not store data like this in your Enchantment and Event class.
If you want to store the data you need to use CompoundTag or a Capability (last one is recommended).

Expand  

How do I do this?, I am very new to modding in minecraft, and aren't I usign compoundTag or do I need to do it in another class?

Posted (edited)
  On 7/28/2022 at 3:23 PM, JoachimTa said:

How do I do this?, I am very new to modding in minecraft, and aren't I usign compoundTag or do I need to do it in another class?

Expand  

Yeah but not how you should do it, but i would highly recommend you to use a Capability.
CompoundTag should be used to store and load data and not on runtime.

Edited by Luis_ST
Posted
  On 7/28/2022 at 5:40 PM, Luis_ST said:

Yeah but not how you should do it, but i would highly recommend you to use a Capability.
CompoundTag should be used to store and load data and not on runtime.

Expand  

Yeah, but I am trying to make so that it saves the entitys hp on the sword, so you can see it, should I not use nbt tags for it or?

Posted (edited)
  On 7/28/2022 at 6:37 PM, Luis_ST said:

Do you want to display the tooltip for all Items or only for your Mods Items?

Expand  

So when I kill a mob, its hp becomes a value i call soulpower, and that value is gonna be displayed on the weapon I killed it with that has the soul steal enchantment. Its gonna be displayed when I hover over my mouse on the sword in my inventory. All items with the soul steal enchantment is gonna have its own separate value based on how many mobs it has killed

Edited by JoachimTa
Posted

I've split your purpose in two parts:

  1. Adding the CompoundTag
    First of all call ItemStack#getOrCreateTagElement with your Mod id, then add to the CompoundTag add data you want to add
    In your case CompoundTag#putInt the first parameter is the key the second the value
  2. Add the CompoundTag to the Tooltip of the Item
    Subscribe to ItemTooltipEvent, from the Event you can get the ItemStack,
    check if the ItemStack has your Enchantment and check if the ItemStack has your Tag using a non ull check on ItemStack#getTagElement with your Mod id.
    Then read the value from the CompoundTag via #getInt with the key you used in #putInt.
    After that create a new Component via Component#literal with your value and add this Component to the tooltip list of the Event
Posted
  Reveal hidden contents

Did you mean something like this?

Posted
  On 7/29/2022 at 4:51 AM, JoachimTa said:
  Reveal hidden contents

Did you mean something like this?

Expand  
  Reveal hidden contents

This is what I have done, I don't know if this was what you meant

Posted
  On 7/29/2022 at 4:35 AM, JoachimTa said:

Sorry I dont understand, What does # mean, and how do I call ItemStack with getOrCreateTagElement.

Expand  

The # is a sign that the following "name" is a non-static method or non-static field in the class, which you need to call.

  On 7/29/2022 at 5:20 AM, JoachimTa said:
CompoundTag tag = ItemStack.of(new CompoundTag()).getOrCreateTagElement(soulmod.MODID);
Expand  

Why did you create there a new ItemStack with an Empty CompoundTag?
You should use the ItemStack on which you checked if your enchantment is preset (level > 0).

Do you know basic java?

Posted
  On 7/29/2022 at 8:58 AM, Luis_ST said:

The # is a sign that the following "name" is a non-static method or non-static field in the class, which you need to call.

Why did you create there a new ItemStack with an Empty CompoundTag?
You should use the ItemStack on which you checked if your enchantment is preset (level > 0).

Do you know basic java?

Expand  

Yes, but I dont know how this ItemStack thing works, so i dont know what to put in the parantheses

Posted
  On 7/28/2022 at 7:34 PM, Luis_ST said:

Adding the CompoundTag
First of all call ItemStack#getOrCreateTagElement with your Mod id, then add to the CompoundTag add data you want to add
In your case CompoundTag#putFloat the first parameter is the key the second the value

Expand  

If you done step 1 you can continue with step 2:

  On 7/28/2022 at 7:34 PM, Luis_ST said:

Add the CompoundTag to the Tooltip of the Item
Subscribe to ItemTooltipEvent, from the Event you can get the ItemStack,
check if the ItemStack has your Enchantment and check if the ItemStack has your Tag using a non ull check on ItemStack#getTagElement with your Mod id.
Then read the value from the CompoundTag via #getFloat with the key you used in #putFloat.
After that create a new Component via Component#literal with your value and add this Component to the tooltip list of the Event

Expand  
Posted (edited)

this is what I understood, the Item gets checked for my enchantment before arriving so it only needs to be checked for the tag here. I dont understand the component.literal part?

  Reveal hidden contents

 

Edited by JoachimTa
Posted

Update: is this what you wanted?

  Reveal hidden contents

 

Posted
  Quote

@SubscribeEvent

public static ItemTooltipEvent tooltip(){

Expand  

This makes no sense.

Event handlers are consumers of events (in their parameters), they don't create/supply them.

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Posted
  On 7/30/2022 at 10:25 AM, diesieben07 said:

No shit... Show it. We have no idea what it does.

Expand  
  Reveal hidden contents

 

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.