Source shouldn't be null if the Level object had data loaded into it. The entries you're trying to access might not be present, but that should throw a different exception.
seem reasonable that it doesn't know about those keyvalues.
and sorry for bugging you again, how do I add custom keyvalues then? says the man who didn't look in the documentation before asking
My documentation's been going increasingly out of date anyway.
Assuming that "Source" itself is not null (and it shouldn't be .. but if it legitimately is, post some sample code), you should check to see if the key exists before trying to use it. If it doesn't exist, you could then create it:
anvilWorld.Level.Source["generatorName"] = new TagNodeString("flat");
So a more complete example:
TagNode source = anvilWorld.Level.Source;
if (source == null)
throw new Exception("Hey, this shouldn't happen");
if (!source.ContainsKey("generatorName"))
source["generatorName"] = new TagNodeString("flat");
else
source["generatorName"].ToTagString().Data = "flat";
Although for simple data like strings and numerical values, it's easier to just create a new tag always, and then you don't need to check.
TagNode source = anvilWorld.Level.Source;
if (source == null)
throw new Exception("Hey, this shouldn't happen");
source["generatorName"] = new TagNodeString("flat");
If you're not building Substrate from source, check out the latest version, build it, and see if you still get a null Source value with it. If you are, then I will investigate when I get home from work.
I see the problem now. You're creating a new world, not loading an existing one. The Source property was only being initialized when data was loaded.
I've pushed some changes to github, so grab the latest version of the source and give it a shot. It would have also been possible to work around this problem by calling BuildNbtTree to get a TagNode, and then calling LoadNbtTree with that result. But that's a lot of work for nothing.
Hello! I am looking for a way to replace a block ID of 220 and metadata 0 with ID 221 and metadata 4 for my mod Galacticraft.
This is what I have:
using System;
using Substrate;
using Substrate.Core;
// This example replaces all instances of one block ID with another in a world.
// Substrate will handle all of the lower-level headaches that can pop up, such
// as maintaining correct lighting or replacing TileEntity records for blocks
// that need them.
// For a more advanced Block Replace example, see replace.cs in NBToolkit.
namespace BlockReplace
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter destination world (eg 'New World' without quotes): ");
string dest = Console.ReadLine();
Console.WriteLine("Enter dimension ID (default -28): ");
int dimID = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter block ID to replace: ");
int before = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter block metadata to replace: ");
int after = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter block ID to replace with: ");
int beforemeta = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter block metadata to replace with: ");
int aftermeta = Convert.ToInt32(Console.ReadLine());
// Open our world
NbtWorld world = NbtWorld.Open(dest);
// The chunk manager is more efficient than the block manager for
// this purpose, since we'll inspect every block
IChunkManager cm = world.GetChunkManager(dimID);
foreach (ChunkRef chunk in cm)
{
// You could hardcode your dimensions, but maybe some day they
// won't always be 16. Also the CLR is a bit stupid and has
// trouble optimizing repeated calls to Chunk.Blocks.xx, so we
// cache them in locals
int xdim = chunk.Blocks.XDim;
int ydim = chunk.Blocks.YDim;
int zdim = chunk.Blocks.ZDim;
// x, z, y is the most efficient order to scan blocks (not that
// you should care about internal detail)
for (int x = 0; x < xdim; x++)
{
for (int z = 0; z < zdim; z++)
{
for (int y = 0; y < ydim; y++)
{
// Replace the block with after if it matches before
if (chunk.Blocks.GetID(x, y, z) == before && chunk.Blocks.GetData(x, y, z) == beforemeta)
{
chunk.Blocks.SetID(x, y, z, after);
chunk.Blocks.SetData(x, y, z, aftermeta);
}
}
}
}
// Save the chunk
cm.Save();
Console.WriteLine("Processed Chunk {0},{1}", chunk.X, chunk.Z);
}
}
}
}
(of course, most of it is the example code)
1. This doesn't seem to be working, I placed it in my saves folder and used: "New World", -28, 220, 0, 221, 4... It lists all the chunks as if it successfully changed the blocks but nothing is different in-game. Is the something else I need to do for modded blocks or custom chunkmanagers? Wow, complete and utter derpage. I was setting the wrong variable.
2. Is there a way to detect save folders in .minecraft without putting it in the saves folder?
DirectoryInfo saves = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.ApplicatonData) + "\\.minecraft\\saves");
foreach(DirectoryInfo dir in saves.GetDirectories())
{
foreach(FileInfo file in dir.GetFiles())
{
if(file.Name == "level.dat")
{
//it is a save, do whatever you want
}
}
}
Rollback Post to RevisionRollBack
Join this Hamachi server! ID: aweshiz's server PASS: 9999 IP: 5.163.103.189 Awesome staff, friendly community, no lag! | I'M 12. GET OVER IT.
The Meaning of Life, the Universe, and Everything.
Join Date:
1/19/2013
Posts:
59
Member Details
Hello
jaquadro,
It's bwhodle.
Your SDK seems interesting to me, as I have made several games in C# myself.
I would like to download it.
However, I seem to have a major issue: When I go to the downloads page of your google code page, and then I click on the download button, it begins to download but it never actually finishes downloading. And with all the computer knowledge I have I for some reason, can't figure out why.
What should I do???
Also, my Posts box is acting really weird, and it's randomly erasing stuff I write and changing the allignment, so I'm if something sorry doesn't correct seem.
^My post editor epically messed up while I was typing that.
So for some reason, the whole thing is blue, centered, and highlighted white, and the last sentence ironically was the only part with the words switched around.
Last sentence: Also, my posts box is acting really weird, and it's randomly erasing stuff I write and changing the allignment, so I'm sorry if something doesn't seem correct.
I recommend going to the GitHub project instead and cloning or downloading the source zip. The VS project that comes with it should build without any fuss. It's also usually a fix or two ahead of the zip that's up on Google Code.
The Meaning of Life, the Universe, and Everything.
Join Date:
1/19/2013
Posts:
59
Member Details
Yeah... Sorry... It was a google chrome issue. It worked fine on FireFox. Also, you rule at offering help within 5 minutes of me posting it.
Okay, now I actually have the original thing, and it shows a .NET DLL with other stuff. I do know how to use c# so I added the reference, however I've never had to deal with a DLL with documentation before. And this one has documentation and I need it... So how do you add the DLL as a reference and make visual studio include the documentation.
Info:
Windows Vista something
Visual Studio 2010 Ultimate
--------------------------- Or... could you offer direct help? I can't figure out how to add an item to the player's inventory and then edit the NBT tag for it's name. I managed to add the item to the inventory by looking at the example, however I have absolutely no clue about how to edit the NBT tags. I looked at the source code for NBTExplorer which was fully not helpful at all. Now for some reason, the chm file says "navigation to the webpage was cancelled", and I don't know how to load documentaiton into VS, and the XML file is a pain in the neck to manually read, and the wiki thing has barely any info at all, and I can't find anything through google, and the code isn't as self explanatory as it looks. So how do I change NBT Tags??
Just make sure the .xml file is in the same directly as the .dll file you're referencing. I think that should be enough for VS to pick it up. However it will probably only provide contextual information. Actually integrating proper API documentation into VS requires a different set of files and I'm not sure it would work with Express. The CHM is probably failing because of Internet security issues. Make sure the CHM is in a local folder on your computer. If it still doesn't work, a Google search might be helpful.
Since the MineCraft data is changing so quickly, I have not updated the Item objects with convenience fields in a while, so as you inferred it has to be done directly with NBT tags.
Most objects that implement INbtObject have a "Source" property that is a TagNodeCompound. A TagNodeCompound is very similar to a .NET Dictionary object, and holds a collection of other NBT tags, including possibly other compound tags or lists. The Source property represents the root tag for that object's data hierarchy. For an Item object, the tag returned by Source would be expected to have tags for "id", "Damage", and "Count" at minimum.
The Item compound tags might also have a "tag" entry, which is itself another compound tag containing lots of other item metadata (though a particular tag will only exist if it's relevent). And any piece of metadata that is currently "default" won't have a tag either. That's the case for your item name.
seem reasonable that it doesn't know about those keyvalues.
and sorry for bugging you again, how do I add custom keyvalues then?
says the man who didn't look in the documentation before asking
Assuming that "Source" itself is not null (and it shouldn't be .. but if it legitimately is, post some sample code), you should check to see if the key exists before trying to use it. If it doesn't exist, you could then create it:
So a more complete example:
Although for simple data like strings and numerical values, it's easier to just create a new tag always, and then you don't need to check.
Mods I Develop: Garden Stuff -- Storage Drawers -- Hunger Strike
Tools I Develop: NBTExplorer -- Substrate
I'm becoming such a bother...
Mods I Develop: Garden Stuff -- Storage Drawers -- Hunger Strike
Tools I Develop: NBTExplorer -- Substrate
Source still null.
I've pushed some changes to github, so grab the latest version of the source and give it a shot. It would have also been possible to work around this problem by calling BuildNbtTree to get a TagNode, and then calling LoadNbtTree with that result. But that's a lot of work for nothing.
Mods I Develop: Garden Stuff -- Storage Drawers -- Hunger Strike
Tools I Develop: NBTExplorer -- Substrate
Mods I Develop: Garden Stuff -- Storage Drawers -- Hunger Strike
Tools I Develop: NBTExplorer -- Substrate
Side-note: Can you import buildcraft Blueprint files?
Mods I Develop: Garden Stuff -- Storage Drawers -- Hunger Strike
Tools I Develop: NBTExplorer -- Substrate
This is what I have:
(of course, most of it is the example code)
1. This doesn't seem to be working, I placed it in my saves folder and used: "New World", -28, 220, 0, 221, 4... It lists all the chunks as if it successfully changed the blocks but nothing is different in-game. Is the something else I need to do for modded blocks or custom chunkmanagers?Wow, complete and utter derpage. I was setting the wrong variable.2. Is there a way to detect save folders in .minecraft without putting it in the saves folder?
Thanks, and great job on this btw
This is the code I use in NBTExplorer to try and guess at the Minecraft save path.
Mods I Develop: Garden Stuff -- Storage Drawers -- Hunger Strike
Tools I Develop: NBTExplorer -- Substrate
So for some reason, the whole thing is blue, centered, and highlighted white, and the last sentence ironically was the only part with the words switched around.
Last sentence: Also, my posts box is acting really weird, and it's randomly erasing stuff I write and changing the allignment, so I'm sorry if something doesn't seem correct.
https://github.com/jaquadro/Substrate
Mods I Develop: Garden Stuff -- Storage Drawers -- Hunger Strike
Tools I Develop: NBTExplorer -- Substrate
Okay, now I actually have the original thing, and it shows a .NET DLL with other stuff. I do know how to use c# so I added the reference, however I've never had to deal with a DLL with documentation before. And this one has documentation and I need it... So how do you add the DLL as a reference and make visual studio include the documentation.
Info:
Windows Vista something
Visual Studio 2010 Ultimate
---------------------------
Or... could you offer direct help?
I can't figure out how to add an item to the player's inventory and then edit the NBT tag for it's name.
I managed to add the item to the inventory by looking at the example, however I have absolutely no clue about how to edit the NBT tags. I looked at the source code for NBTExplorer which was fully not helpful at all. Now for some reason, the chm file says "navigation to the webpage was cancelled", and I don't know how to load documentaiton into VS, and the XML file is a pain in the neck to manually read, and the wiki thing has barely any info at all, and I can't find anything through google, and the code isn't as self explanatory as it looks. So how do I change NBT Tags??
Since the MineCraft data is changing so quickly, I have not updated the Item objects with convenience fields in a while, so as you inferred it has to be done directly with NBT tags.
Most objects that implement INbtObject have a "Source" property that is a TagNodeCompound. A TagNodeCompound is very similar to a .NET Dictionary object, and holds a collection of other NBT tags, including possibly other compound tags or lists. The Source property represents the root tag for that object's data hierarchy. For an Item object, the tag returned by Source would be expected to have tags for "id", "Damage", and "Count" at minimum.
The Item compound tags might also have a "tag" entry, which is itself another compound tag containing lots of other item metadata (though a particular tag will only exist if it's relevent). And any piece of metadata that is currently "default" won't have a tag either. That's the case for your item name.
All the information you need to know on NBT structure for items is available on the wiki: http://www.minecraftwiki.net/wiki/Player.dat_format
As for actually reading and manipulating the NBT values, all the API that you need to worry about is in the .Nbt namespace: https://github.com/jaquadro/Substrate/tree/master/SubstrateCS/Source/Nbt
And setting the data value could be as simple as:
Except that you should check that the particular entries exist before actually trying to access them like I did. "tag" or "display" might not exist.
Mods I Develop: Garden Stuff -- Storage Drawers -- Hunger Strike
Tools I Develop: NBTExplorer -- Substrate