Posted May 2, 20223 yr I want to save some data on the EntityBlock using saveAdditional() and then load using load(). No problem saving basic stuff obv.. but what if I want to save a BlockPos(prob save x,y and z Ig) but what about a Level? How can I properly save a world? Ik you obviously wouldn't save the world but rather some ID you can retreive it with later, but I just can't seem to find some unique variable for each Level ot have... People would say DimensionType but it is absolutely possible to have servers with multiple Overworlds and etc, so idk how good this will hold in that case if at all... My question is: is there some sort of a unique ID for a world I can save and later use to retreive it? Why I need it? I want to save a location but it doesn't only matter to me where it was(BlockPos), but rather in what world too, if I only save the BlockPos I cannot know what Level it came from if I can't save the Level or some unique representation of it...
May 2, 20223 yr For a BlockPos you can use NbtUtils#readBlockPos and NbtUtils#writeBlockPos. There's also BlockEntity#getPosFromTag and BlockEntity has a BlockPos field with getter and setter. For the world I'm not sure either with tags, however BlockEntity has a protected Level field with setter and getter, maybe it can be of use (?).
May 2, 20223 yr Author I meant I am saving a BlockPos that is NOT the BlockEntity's own pos(also even without NBTUtils it's quite easy to save the pos, but it's handy to know it exists) same goes for the Level of the BlockEntity, I save something else, not this one I have a block that is meant to "target" another block, for that I use a BlockPos and a Level(in case it is in another world) so I need to be able to save and load that target Edited May 2, 20223 yr by 1Mangomaster1
May 2, 20223 yr Author There's a plugin Ik that let's you add new worlds of different types. When I check the files later I see two folders that represent overworld levels(they are named differently obviously but it is the same dimension...) EDIT: wait I didn't see you said dimension key, alright, Imma check that out, thank you! AND, ok. Assuming I use that to save, how do I use that key to get that world back??? Do I store the registery path? name?? or the entire key somehow tho Idek how you'd do that Edited May 2, 20223 yr by 1Mangomaster1
May 3, 20223 yr Author I don't know how to get the instance of MinecraftServer... ik Level has one(but looking at the code it reutns null... also at this point I have no access to a world because I am trying to use the MinecraftServer to get one), but other than that.. no idea I saw on the Internet people saying something about FMLCommonHandler but it isn't a thing(at least not on 1.18 Forge) Edited May 3, 20223 yr by 1Mangomaster1
May 3, 20223 yr Author Ooh I mean I CTRL+Clicked on the Level#getServer method and saw its content... Ik it is a .class file but for some reason I can still see the entire thing, on all files Regardless, this is not the point, because even if Level#getServer does actually work, I do not have access to the world at this specific point. I am talking about me trying to LOAD a world from its resource location, something you told me is possible, so if I am trying to load a world, clearly I do not have one... I am trying to find it, so I don't have an instance to call level#getServer on anyways Edited May 3, 20223 yr by 1Mangomaster1
May 3, 20223 yr Author I mean I see it structred like a .java file I see all the code and everything, the name just says .class after it but it is decompiled
May 3, 20223 yr Author And yeah, I know, this is how I store it: public static void saveNBT(CompoundTag nbt, Location location, String name) { String worldString = location.getWorld().dimension().location().toString(); BlockPos pos = location.getPos(); nbt.putString(name + ".world", worldString); nbt.putInt(name + ".pos.x", pos.getX()); nbt.putInt(name + ".pos.y", pos.getY()); nbt.putInt(name + ".pos.z", pos.getZ()); } Location is literally just a class with a Level and a BlockPos, that's all it has, nothing special Is that a proper way to save it? Also I know NBTUtils has a BlockPos write and read but it RETURNS a CompoundTag and I am not sure what I need to do with that(since I already have an existing instnace of it) I assume CompoundTag#put has someting to do with it because it can receive a tag but idrk and what I did here is not too difficault either so no biggy ig Edited May 3, 20223 yr by 1Mangomaster1
May 3, 20223 yr Author So... you're saying I can make another CompoundTag, and place them in it... and place that tag in the given tag? How do I rectreive that tag back then?
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.