Looks like a string tag has a null string data value. You should see if your code could be setting a null string, but for my part I should patch up the NBT writer to handle null strings as empty strings instead.
I do
cm = world.GetChunkManager( dim );
ChunkRef cr = cm.CreateChunk(cx, cz);
generateChunk( cr, dim );
cm.Save(); //crashes on this line
in generate chunk these are the only stuffs besides SetID, SetData.
Would you mind giving me a sample project? And if you're running this on an existing world, and it doesn't reproduce on every other world you've tried, please also provide a sample world.
string player = textBox1.Text;
int itemid = Convert.ToInt32(textBox2.Text);
int count = Convert.ToInt32(textBox3.Text);
string worldPath = ((KeyValuePair<string, string>)worldBox.SelectedItem).Value;
string worldName = ((KeyValuePair<string, string>)worldBox.SelectedItem).Key;
NbtWorld world = NbtWorld.Open(worldPath);
IPlayerManager pm = world.GetPlayerManager();
if (!pm.PlayerExists(player))
{
MessageBox.Show("No such player {0}!", player);
return;
}
Player p = pm.GetPlayer(player);
for (int i = 0; i < p.Items.Capacity; i++)
{
if (!p.Items.ItemExists(i))
{
// Create the item and set its stack count
Item item = new Item(itemid);
item.Count = count;
p.Items[i] = item;
// Don't keep adding items
break;
}
}
pm.SetPlayer(player, p);
Define "nothing happens". That could mean "the contents of the player file were not updated", or it could mean "I didn't see the changes I expected in Minecraft."
Now ask yourself whether you're editing a player for an SSP or SMP world. If it's an SSP world, you should not be using the PlayerManager. You should be getting the Player object from the world's Level instead. If it's an SMP world, then you need to figure out why the data you wrote is being rejected by Minecraft. The item structure has changed quite a lot since Substrate was first published, so maybe you're missing an important tag for the particular item you're writing. Minecraft wipes out changes that it thinks are invalid or incomplete.
But did you verify whether the contents of the player.dat file were modified by your code before trying to load minecraft? That's our starting point for finding the problem.
Have you tried different items? Simple items that require no additional tags? Have you looked at items you already had in your inventory to see what might be different about them?
Okay so I rewrote the whole program and it still crashes. Works only if I set the blocks to stone and nothing else.
I can send you all that code to see for yourself if you want to.
Player has a GameType (of type PlayerGameType), not a GameMode.
That aside, it could be that SSP only respects the GameType setting on the level, rather than the player. In SMP, the server respects the GameType of each individual player, stored in their player.dat file.
I took a closer look and discovered a case error in the playerGameType property (I had the leading P capitalized. My fault, but it wouldn't hurt of Mojang was more consistent with their naming conventions).
I've pushed a fix to source control, so you could download the project and build a local copy.
Alternatively, if you don't want to build your own copy or wait for an official release, you can use the player's "Source" property to get direct access to the NBT Tree representing the player, and set the "playerGameType" to the correct value.
When you specify a spawn point I think Minecraft reserves the right to pick another point near it that it deems more "suitable". Try another point and see if you get more consistent results.
For flatmap preset I assume you mean configuring the generator in the level.dat so it continues generating new chunks during play.
I haven't exposed anything specifically for it in level.dat, so you should work with the Level object's NBT tree directly via the Source property. Use the Minecraft wiki page on level.dat format as your guide: http://www.minecraftwiki.net/wiki/Level_format
You'll want to set generatorName, generatorVersion, and generatorOptions, and you'll need to look up the format for specifying the flatmap generator string.
When you specify a spawn point I think Minecraft reserves the right to pick another point near it that it deems more "suitable". Try another point and see if you get more consistent results.
For flatmap preset I assume you mean configuring the generator in the level.dat so it continues generating new chunks during play.
I haven't exposed anything specifically for it in level.dat, so you should work with the Level object's NBT tree directly via the Source property. Use the Minecraft wiki page on level.dat format as your guide: http://www.minecraft...ki/Level_format
You'll want to set generatorName, generatorVersion, and generatorOptions, and you'll need to look up the format for specifying the flatmap generator string.
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.
You were probably opening a single player world. If so, use world.Level.Player.
I do
in generate chunk these are the only stuffs besides SetID, SetData.
And calling the world.Save() before editing any chunks saves the map data successfully. Calling again after editing fails too.
Mods I Develop: Garden Stuff -- Storage Drawers -- Hunger Strike
Tools I Develop: NBTExplorer -- Substrate
Use NBTExplorer http://www.minecraftforum.net/topic/840677-nbtexplorer-nbt-editor-for-windows-and-mac/ to verify that your changes are actually being made to the player file. If the changes are there, your code is doing its job.
Now ask yourself whether you're editing a player for an SSP or SMP world. If it's an SSP world, you should not be using the PlayerManager. You should be getting the Player object from the world's Level instead. If it's an SMP world, then you need to figure out why the data you wrote is being rejected by Minecraft. The item structure has changed quite a lot since Substrate was first published, so maybe you're missing an important tag for the particular item you're writing. Minecraft wipes out changes that it thinks are invalid or incomplete.
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
Mods I Develop: Garden Stuff -- Storage Drawers -- Hunger Strike
Tools I Develop: NBTExplorer -- Substrate
I can send you all that code to see for yourself if you want to.
Mods I Develop: Garden Stuff -- Storage Drawers -- Hunger Strike
Tools I Develop: NBTExplorer -- Substrate
Other than that I need more information.
Mods I Develop: Garden Stuff -- Storage Drawers -- Hunger Strike
Tools I Develop: NBTExplorer -- Substrate
or
instead of
because the latter one does not work, do not ask me why.
That aside, it could be that SSP only respects the GameType setting on the level, rather than the player. In SMP, the server respects the GameType of each individual player, stored in their player.dat file.
Mods I Develop: Garden Stuff -- Storage Drawers -- Hunger Strike
Tools I Develop: NBTExplorer -- Substrate
I've pushed a fix to source control, so you could download the project and build a local copy.
Alternatively, if you don't want to build your own copy or wait for an official release, you can use the player's "Source" property to get direct access to the NBT Tree representing the player, and set the "playerGameType" to the correct value.
player.Source["playerGameType"].ToTagInt().Data = (int)PlayerGameType.Creative;
Mods I Develop: Garden Stuff -- Storage Drawers -- Hunger Strike
Tools I Develop: NBTExplorer -- Substrate
Also how to spawn the player in a single spot or is it the Minecraft's way of throwing him out in a radius around it?
For flatmap preset I assume you mean configuring the generator in the level.dat so it continues generating new chunks during play.
I haven't exposed anything specifically for it in level.dat, so you should work with the Level object's NBT tree directly via the Source property. Use the Minecraft wiki page on level.dat format as your guide: http://www.minecraftwiki.net/wiki/Level_format
You'll want to set generatorName, generatorVersion, and generatorOptions, and you'll need to look up the format for specifying the flatmap generator string.
Mods I Develop: Garden Stuff -- Storage Drawers -- Hunger Strike
Tools I Develop: NBTExplorer -- Substrate
Okay so I try to do this
anvilWorld.Level.Source["generatorName"].ToTagString().Data = "flat";
anvilWorld.Level.Source["generatorOptions"].ToTagString().Data = "0x1";
says Source is null
Mods I Develop: Garden Stuff -- Storage Drawers -- Hunger Strike
Tools I Develop: NBTExplorer -- Substrate