Jump to content

[1.7.10] NBT persistent saving issue - adding additional player data


Recommended Posts

Posted

What we are trying to get at is 'Why save the entity twice?' Either tie the entity to the ItemStack, or tie it to the player, but not both.

 

Example A: Tied to ItemStack

- Save the entity into the ItemStack NBT

- When the player uses the item or whatever and you spawn the entity, pass the player as an argument much like setting the 'owner' of the entity, and use whatever fields from player / your player's IEEP that you need within the entity class to determine its abilities.

- Example: each player has a power level that increases as they gain experience; this is stored in the player's IEEP, and the entity uses the player's power level to modify its attack damage.

 

Example B: Tied to Player

- ItemStack is subtyped by ID, where each ID is mapped to an entity type

- E.g. 1 = Pikachu, 2 = Charzard, etc.

- The actual entity data is stored in the player's IEEP, probably as an NBTTagCompound until you actually summon it, at which point you should convert it into a real entity

- When the player right clicks with whatever egg, it uses the item's damage value (the stack subtype) to fetch the correct entity data from the player, which then creates the entity

 

There are advantages and disadvantages to each design, but you MUST figure out your design and explain EXACTLY what you are trying to do in plain English (i.e. no code). If you can't explain it in simple terms, you are going to have a very difficult time implementing anything that does what you want.

Posted

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

The reason why I need the entity tied to both the itemstack and upon item pick up the entity gets tied to the player and the itemstack NBT is cleaned up is because the eggs can be stolen by other players. if an egg is stolen then this initiates a quest that is unique to the player that originally caught the entity. In order to get my quest to work properly, in the way that I want it to, I have to know how to tie the entity to both the player and the itemstack. The design I want is clear, all I had issues with is getting the entity to save to the player persistently. I mean currently it does "save" as long as the player doesnt log off or die haha but i am trying out a few things to fix this issue, thanks a lot for the suggestions, ill post if and when i get a solution or if i run into more issues.

Posted

IEEP is by its very nature persistent for each player - it automatically calls your save and load NBT data methods for the correct player each time they log in.

 

However, if you do not implement those two methods correctly, then you cannot expect your data to be correct - your save NBT code:

for(int i=0; i < NUM_SLOTS; i++){
                System.out.println("test equals " + test);
         if(partyNbt != null){
            properties.setTag("Slot"+i, partyNbt); // <-- isn't partyNbt an array?
         }
      }

Looks like you simply made a mistake there - your 'partyNbt' field is an array, but you try to save the array reference rather than the actual element. Needs to be 'partyNbt'. Might want to double-check everywhere else that you access this field, such as the load method.

Posted

Ya I saw that and fixed it but the NBt data still isnt persistent not sure why. I also tried passing in the player as a parameter

 

[but doing this presented a problem] when I pass the player as a Parameter I get Null for all slots of my party. Below is my tryToAddMobToParty method with the player passed in as a parameter and my getPartyMember method that is located inside the IEEP class.

 

I tried to outprint both the Minecraft.getMinecraft.thePlayer and the passed in player and I get the following outprints to consol. What is werid is that if I use Minecraft.getMinecraft.thePlayer the slots are not null when the getPartyMember(); method is called and they contain the NBT data of each unique instance of my entity. if |I used the passed in player the getPartyMember(); outprints null for all slots.

 

Player is EntityPlayerMP['Player845'/247, l='New World', x=1109.00, y=4.00, z=392.58]

Minecraft.getMinecraft.thePlayer is EntityClientPlayerMP['Player845'/247, l='MpServer', x=1109.00, y=5.62, z=392.58]

 

public void tryToAddMobToParty(EntityPlayer player){
                System.out.println("Player is " + player);
                System.out.println("Minecraft.getMinecraft.thePlayer is " + Minecraft.getMinecraft.thePlayer);

	PlayerParty pp = PlayerParty.get(player);// instead of PlayerParty pp = PlayerParty.get(Minecraft.getMinecraft.thePlayer);
	System.out.println("free slot? " + pp.hasFreeSlot());
	if(pp.hasFreeSlot() == true){
	pp.setPartyMember(pp.getNextFreeSlot(), this.hitEntity);	
	System.out.println(this.hitEntity + " saved to slot " + pp.getNextFreeSlot());
	}else{
		this.displayChatMessage(EnumChatFormatting.RED + "Your Party Is Currently Full!");
		System.out.println("next free slot " + pp.getNextFreeSlot());//should return -1 at this point because party is full [works]
		pp.getPartyMember(0);
		System.out.println("first in party " + pp.getPartyMember(0));
		pp.getPartyMember(1);
		System.out.println("second in party " + pp.getPartyMember(1));
		pp.getPartyMember(2);
		System.out.println("thirdt in party " + pp.getPartyMember(2));
		pp.getPartyMember(3);
		System.out.println("fourth in party " + pp.getPartyMember(3));
		pp.getPartyMember(4);
		System.out.println("fifth in party " + pp.getPartyMember(4));
		pp.getPartyMember(5);
		System.out.println("sixth in party " + pp.getPartyMember(5));
	}
}

 

Whats weird is if the party is full and if i pass in the player rather than using Minecraft.getMinecraft.thePlayer then the getPartyMember method doesnt return null and then immediately the next tick it is null again... but what is weird also is that if i try to add another party member the NBT data is still there I know this because the UUID's that get printed dont change...

 

get member in slot0null

get member in slot1null

get member in slot2null

get member in slot3null

get member in slot4null

get member in slot5null

next free slot -1

first mob in party {DropChances:[...

second mob in party {DropChances:[...

thirdt mob in party {DropChances:[...

fourth mob in party {DropChances:[...

sixth mob in party {DropChances:[...

get member in slot1null

get member in slot2null

get member in slot3null

get member in slot4null

get member in slot5null

 

public NBTTagCompound getPartyMember(int slot){
System.out.println("get member in slot" + slot + partyNbt[slot]);
	return partyNbt[slot];
}

I get Null for all slots all the time if I pass in the player but if I use Minecraft.getMinecraft then all is fine and dandy

Posted

Scrap all of your IEEP code right now and go back to saving something simple, like an integer or a string.

 

Figure out how it works first, doing one simple piece, then expand to encompass all the data you actually want.  That way when you go from "well it saved a string" to "but it didn't save an array of strings" you can puzzle out why, rather than going, "fuck this doesn't work."

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

I also fixed the getting client player on server by passing it as a parameter

... I really don't understand what your obsession is with using the client-side version of the player. That makes absolutely no sense, and is very likely part of your problem.

 

There is a server-side version of every entity, including each player, and that is the one you want; the client side is purely for rendering and that kind of stuff - it is NOT where you want to manipulate / store data.

Posted

By fixing it, I THINK he ment that he followed my post and actually made it work on server side. Just a thought.

 

Thornack, hint for you - NBT can be printed using Syso (System.out.println). Put Syso on start and end of write and read NBT. Basically - debug as long as you understand it (Draco's right).

If you won't find it on your own - does your readNBT actually have some NBT (in Syso)?

1.7.10 is no longer supported by forge, you are on your own.

Posted

I do understand it and I already have an IEEP class that adds a stamina bar already and that is persistent and the NBT saves and I am actually using that as a gude to try and get this working. What I am trying to do is waaaay more complicated than a simple stamina bar and hence why I am debugging rather than going backwards.

 

I made my player server side like you suggested and I pass the player in. I put the client and server side player in my debug message to see what the differences were and if you read my last post you can see them. I put what the consol outprints when I try the client player and I also put what it outprints when I try the passed in player (This is the server player I believe that is obtained using the getThrower method inside my class that extends EntityThrowable)

 

I will try the outprints inside the save and load NBT that you suggested and see what I get.

Posted

Where is this tryToAddMobToParty method located at, and where are you calling it from?

 

If it is in your IEEP class, then you should already have a reference to the correct player needed as a class field; if it is in your Item class, you need to make sure you are calling the method on the server only (i.e. when the world is NOT remote), otherwise your method gets called both on the client and the server, and any information you print out on the client is likely to be all null.

 

The point being that we need as much context as you can give us if you want to solve your issue anytime soon.

Posted

Before catching 1 entity all my slots are null which is expected

 

 

[16:44:45] [server thread/INFO]  Before setting tag 0{}

[16:44:45] [server thread/INFO]  PROP 0{}

[16:44:45] [server thread/INFO]  Before setting tag 1{}

[16:44:45] [server thread/INFO]  PROP 1{}

[16:44:45] [server thread/INFO]  Before setting tag 2{}

[16:44:45] [server thread/INFO]  PROP 2{}

[16:44:45] [server thread/INFO]  Before setting tag 3{}

[16:44:45] [server thread/INFO]  PROP 3{}

[16:44:45] [server thread/INFO]  Before setting tag 4{}

[16:44:45] [server thread/INFO]  PROP 4{}

[16:44:45] [server thread/INFO]  Before setting tag 5{}

[16:44:45] [server thread/INFO]  PROP 5{}

[16:44:45] [server thread/INFO]  Before setting tag 0{}

[16:44:45] [server thread/INFO]  PROP 0{}

[16:44:45] [server thread/INFO]  Before setting tag 1{}

[16:44:45] [server thread/INFO]  PROP 1{}

[16:44:45] [server thread/INFO]  Before setting tag 2{}

[16:44:45] [server thread/INFO]  PROP 2{}

[16:44:45] [server thread/INFO]  Before setting tag 3{}

[16:44:45] [server thread/INFO]  PROP 3{}

[16:44:45] [server thread/INFO]  Before setting tag 4{}

[16:44:45] [server thread/INFO]  PROP 4{}

[16:44:45] [server thread/INFO]  Before setting tag 5{}

[16:44:45] [server thread/INFO]  PROP 5{}

 

 

 

After catching 1 entity all slots seem to be given data which is weird Id expect only slot 0 to get data and the rest to be null

 

 

[16:45:10] [server thread/INFO] Before setting tag 0{}

[16:45:10] [server thread/INFO] After setting tag 0{Slot 0:{

[16:45:10] [server thread/INFO] PROP 0{Slot 0:{.....NBT Data......

[16:45:10] [server thread/INFO] Before setting tag 1{Slot 0:{.....NBT Data (same as above)......

[16:45:10] [server thread/INFO] PROP 1{Slot 0:{.....NBT Data (same as above)......

[16:45:10] [server thread/INFO] Before setting tag 2{Slot 0:{.....NBT Data (same as above)......

[16:45:10] [server thread/INFO] PROP 2{Slot 0:{.....NBT Data (same as above)......

[16:45:10] [server thread/INFO] Before setting tag 3{Slot 0:{.....NBT Data (same as above)......

[16:45:10] [server thread/INFO] PROP 3{Slot 0:{.....NBT Data (same as above)......

[16:45:10] [server thread/INFO] Before setting tag 4{Slot 0:{.....NBT Data (same as above)......

[16:45:10] [server thread/INFO] PROP 4{Slot 0:{.....NBT Data (same as above)......

[16:45:10] [server thread/INFO] Before setting tag 5{Slot 0:{.....NBT Data (same as above)......

[16:45:10] [server thread/INFO] PROP 5{Slot 0:{.....NBT Data (same as above)......

[16:45:10] [server thread/INFO] Before setting tag 0{}

[16:45:10] [server thread/INFO] After setting tag 0{Slot 0:{

[16:45:10] [server thread/INFO] PROP 0{Slot 0:{.....NBT Data(same as above)......

[16:45:10] [server thread/INFO] Before setting tag 1{Slot 0:{.....NBT Data (same as above)......

[16:45:10] [server thread/INFO] PROP 1{Slot 0:{.....NBT Data (same as above)......

[16:45:10] [server thread/INFO] Before setting tag 2{Slot 0:{.....NBT Data (same as above)......

[16:45:10] [server thread/INFO] PROP 2{Slot 0:{.....NBT Data (same as above)......

[16:45:10] [server thread/INFO] Before setting tag 3{Slot 0:{.....NBT Data (same as above)......

[16:45:10] [server thread/INFO] PROP 3{Slot 0:{.....NBT Data (same as above)......

[16:45:10] [server thread/INFO] Before setting tag 4{Slot 0:{.....NBT Data (same as above)......

[16:45:10] [server thread/INFO] PROP 4{Slot 0:{.....NBT Data (same as above)......

[16:45:10] [server thread/INFO] Before setting tag 5{Slot 0:{.....NBT Data (same as above)......

[16:45:10] [server thread/INFO] PROP 5{Slot 0:{.....NBT Data (same as above)......

 

 

After catching second entity all slots are again given data but why does it outprint {Slot 0:{.....NBT Data...... shouldnt this be {Slot 1:{.....NBT Data...... since at this point we should be filling slot 1 and not slot 0

 

 

[16:55:42] [server thread/INFO] Before setting tag 0{}

[16:55:42] [server thread/INFO] After setting tag 0{Slot 0:{

[16:55:42] [server thread/INFO] PROP 0{Slot 0:{.....NBT Data......

[16:55:42]  [server thread/INFO] Before setting tag 1{Slot 0:{.....NBT Data (same as above)......

[16:55:42]  [server thread/INFO] PROP 1{Slot 0:{.....NBT Data (same as above)......

[16:55:42]  [server thread/INFO] Before setting tag 2{Slot 0:{.....NBT Data (same as above)......

[16:55:42]  [server thread/INFO] PROP 2{Slot 0:{.....NBT Data (same as above)......

[16:55:42]  [server thread/INFO] Before setting tag 3{Slot 0:{.....NBT Data (same as above)......

[16:55:42]  [server thread/INFO] PROP 3{Slot 0:{.....NBT Data (same as above)......

[16:55:42]  [server thread/INFO] Before setting tag 4{Slot 0:{.....NBT Data (same as above)......

[16:55:42]  [server thread/INFO] PROP 4{Slot 0:{.....NBT Data (same as above)......

[16:55:42]  [server thread/INFO] Before setting tag 5{Slot 0:{.....NBT Data (same as above)......

[16:55:42]  [server thread/INFO] PROP 5{Slot 0:{.....NBT Data (same as above)......

[16:55:42]  [server thread/INFO] Before setting tag 0{}

[16:55:42]  [server thread/INFO] After setting tag 0{Slot 0:{

[16:55:42]  [server thread/INFO] PROP 0{Slot 0:{.....NBT Data(same as above)......

[16:55:42]  [server thread/INFO] Before setting tag 1{Slot 0:{.....NBT Data (same as above)......

[16:55:42]  [server thread/INFO] PROP 1{Slot 0:{.....NBT Data (same as above)......

[16:55:42]  [server thread/INFO] Before setting tag 2{Slot 0:{.....NBT Data (same as above)......

[16:55:42]  [server thread/INFO] PROP 2{Slot 0:{.....NBT Data (same as above)......

[16:55:42]  [server thread/INFO] Before setting tag 3{Slot 0:{.....NBT Data (same as above)......

[16:55:42]  [server thread/INFO] PROP 3{Slot 0:{.....NBT Data (same as above)......

[16:55:42]  [server thread/INFO] Before setting tag 4{Slot 0:{.....NBT Data (same as above)......

[16:55:42]  [server thread/INFO] PROP 4{Slot 0:{.....NBT Data (same as above)......

[16:55:42]  [server thread/INFO] Before setting tag 5{Slot 0:{.....NBT Data (same as above)......

[16:55:42]  [server thread/INFO] PROP 5{Slot 0:{.....NBT Data (same as above)......

 

 

If I catch a third entity then the following weirdness happens. next to PROP 0 this gets printed {Slot 0:..., next to PROP 1 this gets printed {Slot 0:... but PROP 2,3,4, and 5 get {Slot 2:...

 

if I catch a fourth entity then next to PROP 0 there is a {Slot 0:..., next to PROP 1 there is a {Slot 0:...  next to PROP 2 this gets printed {Slot 2:... but next to PROP 3,4, and 5 {Slot 3:... gets printed. Its unexpected I would think that the data would only get placed into the first slot and the rest be null but apparently the entire array is populated each time starting at whichever slot was not populated last. Now for the loadNBTData stuff...

 

After I relog then log back on after having caught 1 entity the consol shows the following

 

 

[17:07:08] [server thread/INFO] [FML]: [server thread] Server side modded connection established

[17:07:08] [server thread/INFO] [sTDOUT]: PROPERTIES before {Slot 0: same as the first entity I caught the UUID's batch

[17:07:08] [server thread/INFO] [sTDOUT]: PROPERTIES slot 0{Slot 0:  same as the first entity I caught the UUID's batch

[17:07:08] [server thread/INFO] [sTDOUT]: PROPERTIES slot 1{Slot 0:  same as the first entity I caught the UUID's batch

[17:07:08] [server thread/INFO] [sTDOUT]: PROPERTIES slot 2{Slot 0:  same as the first entity I caught the UUID's batch

[17:07:08] [server thread/INFO] [sTDOUT]: PROPERTIES slot 3{Slot 0:  same as the first entity I caught the UUID's batch

[17:07:08] [server thread/INFO] [sTDOUT]: PROPERTIES slot 4{Slot 0:  same as the first entity I caught the UUID's batch

[17:07:08] [server thread/INFO] [sTDOUT]: PROPERTIES slot 5{Slot 0:  same as the first entity I caught the UUID's batch

 

 

but at this point when I hit escape to save again then everything becomes Null again and my entity is lost... even though my entity loaded it doesnt seem to get resaved...

 

This is the code that was responsible for the outprints up top

 

@Override
public void saveNBTData(NBTTagCompound compound) {
	NBTTagCompound properties = new NBTTagCompound();
	for(int i=0; i < NUM_SLOTS; i++){
		System.out.println("Before setting tag "+ i + properties);		
		if(partyNbt[i] != null){
			properties.setTag("Slot "+ i, partyNbt[i]);
			System.out.println("After setting tag "+ i + properties);
			}
		     System.out.println("PROP "+ i + properties);
			}
	compound.setTag(EXTENDED_ENTITY_PROPERTIES_TAGNAME, properties);



}

@Override
public void loadNBTData(NBTTagCompound compound) {

	NBTTagCompound properties = (NBTTagCompound) compound.getTag(EXTENDED_ENTITY_PROPERTIES_TAGNAME);
	if(properties != null){
		System.out.println("PROPERTIES before "  + properties);
		for(int i=0; i < NUM_SLOTS; i++){
			System.out.println("PROPERTIES slot " + i + properties);
			if(properties.hasKey("Slot"+i)){
				partyNbt[i] = properties.getCompoundTag("Slot"+i);
				System.out.println("PROPERTIES after " + i + properties); // doesnt seem to be called not sure why
				}
		}
	}


}

 

Posted

The  tryToAddMobToParty is being called inside my holder entity class (this class has access to the player as it is passed the thrower that threw the previous entity) and I make sure to call tryToAddMobToParty on Server only and when I outprint it it only outprints on Server thread

Posted

From write code:

properties.setTag("Slot "+ i, partyNbt);

 

From load code:

partyNbt = properties.getCompoundTag("Slot"+i);

 

Notice SPACE (" ")

 

:P

1.7.10 is no longer supported by forge, you are on your own.

Posted

Figured it out :) Thanks everybody that space was one issue and I had a type also and the client player being called on server was the main issue i think other than that it works beautifully now :)

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

×
×
  • Create New...

Important Information

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