Jump to content

[1.20.4] way to directly acces the nbt database and manually save or retrive the nbt data for blockEntities ?


Recommended Posts

Posted

 

I have problems whit mi blockEntities they just save data only when it feels like 

stonehead.png

I just retake he topic after several weeks i know it not the menu nor the packages system 

was thinking something xtreame like make the block entities to read write the data as .nbt text files just coze i can but think don't worts the effort 

#################

???

mi question is if theres a way to espose and  directly messup whit the minecraft nbt database system ??

like 

SELECT nbt FROM miwarudo WHERE x='127' and y='80' and z='-3627'

or something whit

CompoundTag worldnbt = warudo.getLevelData().something; ??

CompoundTag blockentitynbt = worldnbt.getDataAt(x,y,z) ??

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Posted (edited)

I'm struggling to guess what on earth are you trying to achieve, or what do you want cause your post is a lil bit wonky,  but the BlockEntity class has methods like SaveAdditional(CompoundTag) and load(CompoundTag) that should manage serialization and deserialization of your block entity NBT data for most cases and that you can override.

If you mean reading NBT data of things "Inside" your BE, (in a slot) I'm pretty sure you can get an ItemStack out of any slot inside your BE from which to acess NBT data of the item in the slot.

If you need the NBT data of a specific block entity you can call ServerLevel.getBlockEntity()

Blocks don't have NBT data iirc.

It would help to get an explanation on what is that your BE does and whats the current look of your BE class.

Edited by chxr
Typos
Posted

well

The problem is the data in mi blockentity, its not being saved when i close the game

i put items on it i retrive items from it all just seems good, the problem cames until i close minecraft then when i reload the word i have an older version of the items saved or just an empty briefcase

 

normally when you declare an entity or a block entity or an item capability, forge automatically keeps track of changes and save the data in nbt format all of this by itself 
in this moments i have some items whit capabilities, those work right 
i have entities , those also works right 

but all of mi blockentities all of them are storages briefcase and all of them fails, save the data sometimes most of the time don't 

well i have only like 3 blockentities up now 

 

 



 

Posted (edited)

I'm sure load and SaveAdditional are what you are looking for, probably. Mind sharing your BE class code?

You also need to override onLoad method if you haven't

Edited by chxr
Posted (edited)

 hola thanks for answering 

i set some system outs to test and see whats going on 

	    @Override
    protected void saveAdditional( CompoundTag nbt ){
        
        nbt.put("itemhandler", itemhandler.serializeNBT() );
        nbt.putInt("progress", this.progress );
	        System.out.println("saveAdditional(nbt)");        
        System.out.println(NbtUtils.prettyPrint(nbt)); //<-- this is whats getting saved
        super.saveAdditional( nbt );
    }
    @Override
    public void load( CompoundTag nbt ){
	        itemhandler.deserializeNBT( nbt.getCompound("itemhandler") );
        this.progress = nbt.getInt("progress" );
	        System.out.println(NbtUtils.prettyPrint(nbt)); //<-- this is whats minecraft is giving back to the entity 
        System.out.println("load(nbt)");
        super.load( nbt );
    }
	

 

This dead adventurer body  has two parts a block and a block Item  both has their own item-handlers and their own menus all of that seems fine 

Testing remarks :
*when i change some element inside the gui  it triggers the saveAdditional(nbt) system out and shows a pretty print of the data being saved 

*when the world map loads it triggers the load(nbt) system out and shows a pretty print of the data minecraft is giving to this Block Entity

For the testing i gonna set mi BlockEntityBodyBlock, save something in it, close minecraft, fireup the game again and check if the items remain 

 

 

################

first try set the block entity (dead adventurer body like shaped) and left only a weath seed  in the slot 10
the console says its all right 

  Reveal hidden contents

 

close minecraft, launch it again
i see the system out whit the data returned to the entity and its look good theres is only a weed seed 

  Reveal hidden contents

################

Second try,
now i gonna change the seed for two arrows 

the console says its all right the two arrows are being saved 
 

  Reveal hidden contents

#########

Now close and run again

bam Error  minecraft returns the original data whit only a wheat seed
the two arrows has been loss

  Reveal hidden contents

 

##########

try again now i gonna put 3 wheat seeds

Console system out says it gets it and is saving the data

  Reveal hidden contents

 

##############

but after close fire again 

  Reveal hidden contents

wheat seed,  data losed once more time  and it just throw the original  

#######################################################################################

sorry for the long post and the crappy video 

this is the reason why i say its saving the Block Entity data only when it feels like 
coze its saves data when it feels like 

¿ its something wrong whit mi BlockEntity.saveAdditional() 

if  i keep trying eventually it updates and the data chages 

 

 

i alredy try to 
level.removeBlockEntity(pos);

level.setBlockEntity(pos, bebb);

 

 

BlockEntityBodyBlock.class

  Reveal hidden contents

 

BlockEntityInit.class

  Reveal hidden contents

 

 

body_blockitem.class

  Reveal hidden contents

 

 

 

 

 

 

 

 

 

Edited by perromercenary00
Gramar missmatch
Posted

WIthout entering on menu class and capability shenanigans, in the load method try calling the super.load(nbt) before doing anything else. It might not be it, but that's really the only difference i can see with the very basic be i have. If you have a repo i can make a clone of to take a quick look at the whole thing on I'll maybe help you out quicker

Posted

i has that 
anyway i test it at the beginning and the end of the function just to be sure 

	@Override
public void load( CompoundTag nbt ){
super.load( nbt );

Level warudo = this.getLevel();
itemhandler.deserializeNBT( nbt.getCompound("itemhandler") );
this.progress = nbt.getInt("progress" );

System.out.println("load(nbt)");
System.out.println(NbtUtils.prettyPrint(nbt));
	//super.load( nbt );
}
	

but it does the same 

 

looking at it a second time
it seems like it only store the nbt data when the entity is created and set into the world 
then never update values

 

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

    • Hello All,  Relatively new to this and after playing for a few hours whenever someone enters the nether the entire server will crash and my friend and I are at a bit of a loss. Deleting player data solves the issues but it still persists whenever someone enters even after deleting the DIM-1 folder. Paste: https://pastebin.com/REbpJVqe Thanks!   -Mitchell
    • Add the crash-report or latest.log (logs-folder) with sites like https://mclo.gs/ and paste the link to it here  
    • Cracked Launchers are not supported
    • Hi, I have a problem in minecraft java (only in forge 1.20.1), When I start the game after a moment the game crashed with code 1 this only in forge 1.20.1 , I tried to reinstall java, Upgrade java to 17, update the drivers to the latest version, downgrade the drivers to the pervious version, deleting .minecraft and reinstall it , but none of these ways working.   here is the log:   [Launcher] Launching Minecraft... I'm hiding! mods after C:\Users\Windows\AppData\Roaming\.minecraft\mods\tl_skin_cape_forge_1.20_1.20.1-1.32.jar [InnerMinecraftServersImpl]  search changers of the servers read servers from servers.dat [] [InnerMinecraftServersImpl]  prepare inner servers save servers to servers.dat [Launcher] Game skin type: TLAUNCHER [Launcher] Starting Minecraft Forge 1.20.1... [Launcher] Launching in: C:\Users\Windows\AppData\Roaming\.minecraft Starting garbage collector: 96 / 227 MB Garbage collector completed: 60 / 214 MB [Launcher] Processing post-launch actions. Assist launch: true =============================================================================================== [05:29:03] [main/INFO]: ModLauncher running: args [--username, *********, --version, Forge 1.20.1, --gameDir, C:\Users\Windows\AppData\Roaming\.minecraft, --assetsDir, C:\Users\Windows\AppData\Roaming\.minecraft\assets, --assetIndex, 5, --uuid, *************************************, --accessToken, вќ„вќ„вќ„вќ„вќ„вќ„вќ„вќ„, --clientId, null, --xuid, null, --userType, mojang, --versionType, modified, --width, 925, --height, 530, --launchTarget, forgeclient, --fml.forgeVersion, 47.3.22, --fml.mcVersion, 1.20.1, --fml.forgeGroup, net.minecraftforge, --fml.mcpVersion, 20230612.114412] [05:29:04] [main/INFO]: ModLauncher 10.0.9+10.0.9+main.dcd20f30 starting: java version 17.0.12 by Oracle Corporation; OS Windows 10 arch amd64 version 10.0 [05:29:15] [main/INFO]: Loading ImmediateWindowProvider fmlearlywindow [05:29:24] [main/INFO]: Trying GL version 4.6 [05:29:60] [main/INFO]: Requested GL version 4.6 got version 4.6 [05:29:67] [main/INFO]: SpongePowered MIXIN Subsystem Version=0.8.5 Source=union:/C:/Users/Windows/AppData/Roaming/.minecraft/libraries/org/spongepowered/mixin/0.8.5/mixin-0.8.5.jar%23100!/ Service=ModLauncher Env=CLIENT FATAL ERROR in native method: Thread[pool-2-thread-1,5,main]: No context is current or a function that is not available in the current context was called. The JVM will abort execution.     at org.lwjgl.opengl.GL11C.nglGetString(org.lwjgl.opengl@3.3.1+7/Native Method)     at org.lwjgl.opengl.GL11C.glGetString(org.lwjgl.opengl@3.3.1+7/GL11C.java:978)     at net.minecraftforge.fml.earlydisplay.DisplayWindow.initRender(fmlearlydisplay@1.20.1-47.3.22/DisplayWindow.java:209)     at net.minecraftforge.fml.earlydisplay.DisplayWindow.lambda$start$5(fmlearlydisplay@1.20.1-47.3.22/DisplayWindow.java:292)     at net.minecraftforge.fml.earlydisplay.DisplayWindow$$Lambda$437/0x000001fab120a618.run(fmlearlydisplay@1.20.1-47.3.22/Unknown Source)     at java.util.concurrent.Executors$RunnableAdapter.call(java.base@17.0.12/Executors.java:539)     at java.util.concurrent.FutureTask.run(java.base@17.0.12/FutureTask.java:264)     at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(java.base@17.0.12/ScheduledThreadPoolExecutor.java:304)     at java.util.concurrent.ThreadPoolExecutor.runWorker(java.base@17.0.12/ThreadPoolExecutor.java:1136)     at java.util.concurrent.ThreadPoolExecutor$Worker.run(java.base@17.0.12/ThreadPoolExecutor.java:635)     at java.lang.Thread.run(java.base@17.0.12/Thread.java:842) Here I am! [VersionManager] Refreshing versions locally... [VersionManager] Versions has been refreshed (6 ms) [Launcher] Launcher exited. [Launcher] Minecraft closed with exit code: 1 flush now [Launcher] [Crash] Signature "Bad video drivers" matches! [Crash] Signature "Bad video drivers" matches! [Launcher] [Crash] Crash has been recognized! [Crash] Crash has been recognized! flush now
  • Topics

×
×
  • Create New...

Important Information

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