Jump to content

Recommended Posts

Posted (edited)

Quick question and it is simply just because I can't find it. I am fairly certain it exists becasue I thought I saw a thread about it on here, or at least saw it being discussed. I have a few Constants that I utilize to identify some ints. I want to store them in a player's capability under one tag, namely IntList. So the key "intList" will contain, 1, 2, 3, 4, etc. etc. etc. So essentially it is a NBTKey that contains a list of ints. And if memory serves I thought it was called NBTList or TagList or something like that. I am fairliy certain it is within the NBT methods (the writing and reading of the list) but I can't seem to find it or how to properly execute it and am not in front of my code atm to search. Any help?

 

Also, secondary question. Does this really need a Capability? All I am essentially doing is storing a list under one key on the player. Or is there an alternative way to do it? Perhaps simply just writing NBT data onto the player?

Edited by HalestormXV
Posted (edited)
9 hours ago, diesieben07 said:

There is NBTTagList for storing an array of any type of NBT tag (such as an array of NBTTagString or an array of NBTTagInt). There is also NBTTagIntArray which is a bit more efficient at storing an int array.

 

Yes, it does. NBT is for saving to disk, not runtime storage. 

 

So I am guessing it would work something like this? (Never used the NBTTagIntArray before)

I need a function in my capability functions that takes the int and passes it to a writeNBT and in that writeNBT it adds it to an NBTTagIntArray? And then the serilize returns the writeNBT(spellID)?

If you have or anyone has or knows of any examples showing how the NBTTagIntArray works I'd appreciate it. This is something totally new to me.

 

I mean the concept is so simple. Pass an int into a function. Call a method that uses that int to write data into the writeNBT. Check if the key exists, if not create it, otherwise find the key that has the NBTTagIntArray and add the id to that array. I just think since I havent worked with this before it is giving me a block.

 

Edited by HalestormXV
Posted (edited)
2 hours ago, diesieben07 said:

Sorry, I am not sure I follow you. Please post your capability and how you are currently trying to save it.

Sorry. Here is how I did this capability in particular. My other ones are slightly different, but I decided to try this one with a different approach. So here is the class: https://pastebin.com/PNXtRZX7

All I need to do is essentially have: 

public void learnedSpell(int spellLearned)
{
    this.SPELL_ID = spellLearned;
    //writeNBT(this.SPELL_ID);
}

place the spellID in. All the spells are integers so they would all go into a key "SpellsLearned" and then the values would be [1, 3, 4, 5, etc. etc. etc.]. I just made the capability a little while ago so as it stands this is simply just the skeleton.

Edited by HalestormXV
Posted

private List<int> knownSpells = new List<int>();

 

this.knownSpells.add(spellLearned)

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
1 hour ago, Draco18s said:

private List<int> knownSpells = new List<int>();

 

this.knownSpells.add(spellLearned)

And then the writeNBT would write an NBTTagArray rather than an NBTCompound?

Posted (edited)

How about an NBTTagIntArray?

Edited by Draco18s

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted (edited)
24 minutes ago, Draco18s said:

How about an NBTTagIntArray?

Yeah that is what I meant sorry.

So it would look something like this?

public class LearnedSpellsFunctions implements ILearnedSpells
{
    private int  SPELL_ID = 0;
    private List<Integer> knownSpells = new ArrayList<>();

    public void learnedSpell(int spellLearned)
    {
        this.SPELL_ID = spellLearned;
        this.knownSpells.add(SPELL_ID);
        writeNBT();
    }

    private NBTTagCompound writeNBT(NBTTagIntArray listSpells)
    {
        NBTTagCompound nbt = new NBTTagCompound();
        return null;
    }

 Since an Interger list is primative you need to ArrayList it right? But would the writeNBT be a NBTTagCompoud that writes the NBTTagIntArray? or do you need some type of getter to get the list and pass it in? That is where I am getting hung up I think, becasue I can't figure how to pass the list that is created and added to, into the writeNBT

Edited by HalestormXV
Posted
public void learnedSpell(int spellLearned)
        writeNBT();
    }

Why are you calling writeNBT here?

    private NBTTagCompound writeNBT(NBTTagIntArray listSpells)
    {
        NBTTagCompound nbt = new NBTTagCompound();
        return null;
    }

You aren't writing anything at all

And returning null.

Why?

 

Why do you make coding puppy sad?

tips-for-dealing-with-puppy-crying-5305c

  • Sad 1

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted (edited)

I know I'm not writing anything at all. I am actually doing this at the same time as I am posting and just posting the bits as I go. I didn't get down to that segment yet. This is literally the skeleton of the code. I am filling it in as I watch for the responses.

public class LearnedSpellsFunctions implements ILearnedSpells
{
    private int  SPELL_ID = 0;
    private List<Integer> knownSpells = new ArrayList<>();

    public void learnedSpell(int spellLearned)
    {
        this.SPELL_ID = spellLearned;
        this.knownSpells.add(SPELL_ID);
        writeNBT(this.knownSpells);
    }

    private NBTTagIntArray writeNBT(List<Integer> knownSpells )
    {
        NBTTagCompound nbt = new NBTTagCompound();
        if (nbt.hasKey("LearnedSpells"))
        {
            nbt.getIntArray("LearnedSpells");
        }else{
            nbt.setIntArray("LearnedSpells", knownSpells);
        }


        return null;
    }

Coding Cat is trying but getting stuck since I never used an NBTIntArray let alone knew it existed. 

193b5kh29skggjpg.jpg

Edited by HalestormXV
Posted (edited)
12 minutes ago, Draco18s said:

public void learnedSpell(int spellLearned)
        writeNBT();
    }

Why are you calling writeNBT here?

This is still true. Why are you doing this? You would be writing data into an NBT tag which you then immediately chuck in the trash.

 

        NBTTagCompound nbt = new NBTTagCompound();
        if (nbt.hasKey("LearnedSpells"))

This if-statement will never evaluate to true, you just created that NBTTag, it has no keys yet.

Edited by Draco18s

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted (edited)

Right I know that, like I said I am writing it as I respond and read this thread, writing in the checks thats fine.

if (nbt.hasKey("LearnedSpells")) //ENTER CODE HERE

 

}else{
    nbt.setIntArray("LearnedSpells", knownSpells);}

create the tag and set it. That part I know. I've worked with the NBT before, but what I am struggling with is how to actually take that list created above in the learnSpell and store it into the NBTTagIntArray. trying to setIntArray like that throws and error.

Edited by HalestormXV
Posted

The if-statement will never be true. Remove it. Just write the array.

Except you have a List<int> which is not an int[], you need to convert. There is a method to do this for you already.

  • Like 1

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted (edited)
5 minutes ago, Draco18s said:

The if-statement will never be true. Remove it. Just write the array.

Except you have a List<int> which is not an int[], you need to convert. There is a method to do this for you already.

I didn't realize there was a method to do it for you already so I just made one, but I'd be happy to sub it out. But this is what I have done so far. Like I said, I am doing this as I go and read these responses and do some searching. And I do appreciate the responses. I am getting an understanding so far.

https://pastebin.com/3FGJuz6X (since the code is getting larger now)

 

Edited by HalestormXV
Posted

List<T>#toArray()

And again:

        public void learnedSpell(int spellLearned)
        {
            this.SPELL_ID = spellLearned;
            this.knownSpells.add(SPELL_ID);
            serializeNBT();
        }
 
Why are you calling serializeNBT here? You're telling it to create an NBTcompound and then throwing the result away.  Commenting that line out would have the same result.
  • Like 1

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted (edited)

Alright so in other words you dont need to ever call that, becasue it does it on its own correct? If you call it, then it will over-write the one that has already been setup within the capability right?

Edited by HalestormXV
Posted
5 minutes ago, HalestormXV said:

Alright so in other words you dont need to ever call that, becasue it does it on its own correct?

Yes

 

5 minutes ago, HalestormXV said:

If you call it, then it will over-write the one that has already been setup within the capability right?

No

  • Like 1

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted (edited)
18 minutes ago, Draco18s said:

Yes

 

No

Okay so now that, that is all set up here is what happens in game:

https://hastebin.com/pinajapohi.css

 

I know that is happening because it is attempting to save the data likely to a tag that is non-existant? Correct? Which I expect with the way the code is now. So now the next step is to properly write the array to a tagCompound utilizing the writeNBT correctly? Is leaving serilizeNBT the way it is fine? 

@Override
public NBTTagCompound serializeNBT()
{
    return writeNBT(this.knownSpells);
}

Because from what I am gathering this writeNBT

private NBTTagCompound writeNBT(List<Integer> knownSpells )
{
    NBTTagCompound nbt = new NBTTagCompound();
    nbt.setIntArray("LearnedSpells", convert2Primative(knownSpells));
    return nbt;
}

currently is just taking a non-existant tagCompound and trying to set an intArray (which is the coverted knownSpells) to a tag that does not yet exist correct?

Edited by HalestormXV
Posted

The crash report does not contain enough information to tell me what is wrong.

9 minutes ago, HalestormXV said:

currently is just taking a non-existant tagCompound and trying to set an intArray (which is the coverted knownSpells) to a tag that does not yet exist correct?

That is not how that code works.

For one, you are creating a new tagCompound, not using a non-existent one.

Second, setting values creates them if they don't exist.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

It wasn't a crash. It was just what spit out when it attempted to save the player. No crash.

 

Alright so the setIntArray also sets up the tag if it doesn't exist yet. I knew the setTag did that, I didn't realize the setIntArray did that also. I am guessing all the setters in the NBT do the same?

 

Secondly, you have to first create the tagCompound before you can manipulate it, just like an item right? Or do i have to do something like get the storage of this capability?

Posted
1 minute ago, HalestormXV said:

I am guessing all the setters in the NBT do the same?

Yes. Otherwise they're useless.

 

2 minutes ago, HalestormXV said:

Secondly, you have to first create the tagCompound before you can manipulate it, just like an item right?

Yes. You can't manipulate null.

2 minutes ago, HalestormXV said:

Or do i have to do something like get the storage of this capability?

You probably have to do this too, but now I am unsure what you are asking.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Well there has to be more to it then this:

https://hastebin.com/livubofure.java

Surely there needs to be more work done on the writeNBT right. I am guessing I can't jump right to the 

deserializeNBT

just yet. I mean 

        private NBTTagCompound writeNBT(List<Integer> knownSpells )
        {
            NBTTagCompound nbt = new NBTTagCompound();
            nbt.setIntArray("LearnedSpells", convert2Primative(knownSpells));
            return nbt;
        }

cant be correct

Posted
12 minutes ago, HalestormXV said:

Surely there needs to be more work done on the writeNBT right.

Why do you think there's more? The only other property your class has is a SPELL_ID field which is literally useless.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted (edited)
10 minutes ago, Draco18s said:

Why do you think there's more? The only other property your class has is a SPELL_ID field which is literally useless.

Because even with the entire capability:

https://hastebin.com/olohifagap.java

 

Having zero errors in the compiler at least. This is still occuring when the game attemptes to save the data (pause menu or whatever)

https://hastebin.com/etikawuqad.css

 

So something is casuing null somwhere. Also, this entire capability class was recycled from another one of my capabilities that simply stores a single integer under a single key that changes throughout the game. Having a Capability that stores an array of integers under one key must require some additional modifications somewhere else within the capability I would think?

Edited by HalestormXV
Posted

Christ, I think you've seriously fucked up somewhere. Hell if I know where though.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted (edited)
25 minutes ago, Draco18s said:

Christ, I think you've seriously fucked up somewhere. Hell if I know where though.

Maybe in the povider? Since that is the only place i see returning a null? Although having it in the override in the functions class should stop that right?

https://hastebin.com/ututihoyeq.java or line 96 of the whole class pasted on this page https://hastebin.com/olohifagap.java

Edited by HalestormXV

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

    • When I first heard about Bitcoin back in 2018, I was skeptical. The idea of a decentralized, digital currency seemed too good to be true. But I was intrigued as I learned more about the technology behind it and its potential. I started small, investing just a few hundred dollars, dipping my toes into the cryptocurrency waters. At first, it was exhilarating to watch the value of my investment grow exponentially. I felt like I was part of the future, an early adopter of this revolutionary new asset. But that euphoria was short-lived. One day, I logged into my digital wallet only to find it empty - my Bitcoin had vanished without a trace. It turned out that the online exchange I had trusted had been hacked, and my funds were stolen. I was devastated, both financially and emotionally. All the potential I had seen in Bitcoin was tainted by the harsh reality that with decentralization came a lack of regulation and oversight. My hard-earned money was gone, lost to the ether of the digital world. This experience taught me a painful lesson about the price of trust in the uncharted territory of cryptocurrency. While the technology holds incredible promise, the risks can be catastrophic if you don't approach it with extreme caution. My Bitcoin investment gamble had failed, and I was left to pick up the pieces, wiser but poorer for having placed my faith in the wrong hands. My sincere appreciation goes to MUYERN TRUST HACKER. You are my hero in recovering my lost funds. Send a direct m a i l ( muyerntrusted ( @ ) mail-me ( . )c o m ) or message on whats app : + 1 ( 4-4-0 ) ( 3 -3 -5 ) ( 0-2-0-5 )
    • You could try posting a log (if there is no log at all, it may be the launcher you are using, the FAQ may have info on how to enable the log) as described in the FAQ, however this will probably need to be reported to/remedied by the mod author.
    • So me and a couple of friends are playing with a shitpost mod pack and one of the mods in the pack is corail tombstone and for some reason there is a problem with it, where on death to fire the player will get kicked out of the server and the tombstone will not spawn basically deleting an entire inventory, it doesn't matter what type of fire it is, whether it's from vanilla fire/lava, or from modded fire like ice&fire/lycanites and it's common enough to where everyone on the server has experienced at least once or twice and it doesn't give any crash log. a solution to this would be much appreciated thank you!
    • It is 1.12.2 - I have no idea if there is a 1.12 pack
  • Topics

  • Who's Online (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

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