Jump to content

NBT Simulation


EducationalPurposes

Recommended Posts

Hello community,

 

I am currently making a framework for the mod called "ComputerCraft." You dont have to know what it is to answer my question, since it is NBT related.

 

So, I know how I can use NBT with the TileEntity's. That is not the issue at all, I am more interested in how the NBT gets saved. I couldnt find the source code to the classes/package(s) which actually save the NBT. Im interested in that, because I need to simulate the NBT without a TileEntity, and to do that I need the code on how to save the NBT. I am going to make my own file of course and probably remake that system to not really get copyright shizzle :P

 

So, where can I find that code?

 

Thank you in advance,

 

- EducationalPurposes

I am fairly new to Java and modding, so my answers are not always 100% correct. Sorry for that!

Link to comment
Share on other sites

Yeah I know NBT is a data format, I guess I didnt formulate it properly.

 

Since I posted this topic, I ironically found the class you mentioned. It definitely will help, but since Im getting into creating my own NBT file (I guess that is the proper way to formulate it), I also want to see what calls TileEntity.readFromNBT & TileEntity.writeToNBT. That way I can see how minecraft does it, and maybe I can add my own twist to that (though I doubt that, why wouldnt the mc class wouldnt perfect for it? I will see what Im going to do with it).

 

So, thanks Diesieben for the quick help already! :)

My other question, which is the final question in this topic for me, is: from what classes are TileEntity.readFromNBT & TileEntity.writeToNBT getting called? If I know that, then I can do it, since I can look up the imports and such etc.

 

Thank you in advance for the help (again :P)

 

- EducationalPurposes

I am fairly new to Java and modding, so my answers are not always 100% correct. Sorry for that!

Link to comment
Share on other sites

From one of my projects

 

String s="someFileName";
File rendersFolder = new File(DimensionManager.getCurrentSaveRootDirectory(), "LinkRenders");
FileInputStream fis = new FileInputStream(new File(rendersFolder, s));
DataInputStream instream = new DataInputStream(fis);
nbt = CompressedStreamTools.read(instream); //reading
CompressedStreamTools.write(nbt, new File(rendersFolder, s)); //writing
instream.close();
fis.close();

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.

Link to comment
Share on other sites

Those methods get called during chunk loading which happens in AnvilChunkLoader. Not sure if that's what you want though. You should specifically describe what you want to.

 

As I mentioned in the initial post, I am writing a framework for ComputerCraft. It basically is just passing around interfaces and some annotations and wrap around those to hook into the API of ComputerCraft. To make a long story short: ComputerCraft then uses these hooks when a block is next to the computer and checks if its an TileEntity. Then it calls the API for help so-to-say and gets my hook.

 

In fact, that system is done and the bugfixing is mostly done.

 

I am also writing a mod at the same time which is based on that framework. While writing that I discovered that having NBT data access is really handy. So I decided to try and get a system around that basically does the same as normal NBT, but not on the actual TileEntity, because that is just asking for issues.

 

In order to pass around those NBT data I was wondering how MC did it, and based on that I would write my own. Meanwhile I figured I should use the MinecraftForge events: net.minecraftforge.event.world.ChunkEvent(.load & .unload) because it makes it more easy for me to find those TileEntity's and pass them to my interfaces.

 

I think I can manage to do it, especially since Draco18s just posted an example code:

 

 

From one of my projects

 

String s="someFileName";
File rendersFolder = new File(DimensionManager.getCurrentSaveRootDirectory(), "LinkRenders");
FileInputStream fis = new FileInputStream(new File(rendersFolder, s));
DataInputStream instream = new DataInputStream(fis);
nbt = CompressedStreamTools.read(instream); //reading
CompressedStreamTools.write(nbt, new File(rendersFolder, s)); //writing
instream.close();
fis.close();

 

 

 

So, thank you for both of your time! If Im getting issues while writing that system, I will post them to this relevant post. If not, I will lock this topic on my own.

 

Thanks again :) You guys helped me out!

I am fairly new to Java and modding, so my answers are not always 100% correct. Sorry for that!

Link to comment
Share on other sites

I think I can manage to do it, especially since Draco18s just posted an example code

 

Thanks again :) You guys helped me out!

 

Veovis actually figured it out. ^..^  I just borrowed his work.

http://binarymage.com/forum/viewtopic.php?p=13045#p13045

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.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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