I took a look at your code. It's clear to me that the code is not doing what you thought it should be doing. When you do operations on individual region objects, then all of the chunk coordinates you use must be local to those region files -- that is, you should never be feeding chunk coordinates outside the range of [0-31] to region objects. If you do feed coordinates out of range, then the region file will attempt to delegate your action to another region file, using the coordinates as a relative offset from itself to find the correct region. If it can't find a region (because it doesn't exist), then it silently fails, which in the case of CreateChunk, returns a null chunk object.
In the code you posted, it looks like you were trying to calculate global coordinates and then feed them to individual regions, which should result in you trying to create a scatterplot of chunks over a very large area. I'm going to argue that your empty 0,0 chunk is actually the only chunk that you successfully created. Substrate does not have a default terrain generator, so any chunk you create is filled with air blocks. All the surrounding generated chunks you saw were generated by minecraft upon loading up your world, because no chunk was actually created in those locations.
The code you were actually looking for:
foreach (Substrate.Region region in rm) {
for (int x = 0; x < 32; x++) {
for (int z = 0; z < 32; z++) {
if (!region.ChunkExists(x, z)) {
region.CreateChunk(x, z);
}
world.Save();
}
}
}
However, that could would actually give you 4 regions worth of totally empty chunks. You either need to write your own terrain generator to actually build those chunks, or don't create them at all, and let Minecraft do it for you (or search for one of the Java tools that automatically invokes the Minecraft server on your world to generate chunks without exploring).
On another note about your code, I think you're making your job harder than it needs to be by working directly with regions. Like I mentioned previously, you could use the ChunkManager, and work entirely in global chunk coordinates without worrying about having to create region files or translate, it's all done in the background for you.
For an ETA, I'll probably have an Anvil-only release available this week. By that, I mean that Alpha and Beta map support will be completely replaced by Anvil support, in a somewhat gross and hacky way. This is intended to get you far enough to release an Anvil-compatible version of your tools without really needing to make any changes. You'll just be stuck with two releases.
In the next 2-3 weeks following the anvil-only release, I'm hoping to have a release that re-unifies all of the map support. The changes are far-reaching, so it's likely that the existing API will break in at least a few small ways. It's still too early for me to estimate how badly.
This is a horrible release, but at least for some of you, it is better than waiting another month for proper unified Anvil support. Alpha and Beta map support is disabled in this build. Anvil maps should be interacted with as if they were beta maps (use BetaWorldManager, BetaChunkManager, etc.) Underneath, I have simply replaced the Chunk class with an Anvil adapter class, which will expose Anvil chunks as 256-block-high AlphaBlockCollections. This means your existing code should not need any changes to operate with Anvil maps. If you wish to continue supporting older maps, plan on releasing two copies of your program until a proper Anvil release is available, one built against 1.2.0, and one built against 1.1.1.
Please go ahead and test this with your tools and let me know what problems you encounter. I will continue to fix bugs on this branch while I work on a unified release separately.
At first look, i saw ChunkRef.StitchBlockLight and ChunkRef.StitchSkyLight methods. Are these new features or was it something i didn't notice? Also, things i noticed:
ChunkRef.StitchBlockLight
ChunkRef.StitchSkyLight
Substrate.Core.IBoundedPropertyBlockCollection
Substrate.Core.IBoundedLitBlockCollection
Substrate.Core.IBoundedDataBlockCollection
Substrate.Core.IBoundedBlockCollection
Substrate.Core.IBoundedAlphaBlockCollection
Substrate.Core.IBoundedActiveBlockCollection
(i'm not sure about Substrate.Core.IBounded interfaces. Are those new?)
Are those a sign of a new update or am i being overexcited/not noticing features that was been there? Also, i'm running a test of speed on a sample Anvil world. Will update soon!
EDIT: Is there a problem or my computer is horrible?
Output from my program:
Speed test...
Placed 6553600 blocks in 149,7119949 seconds!
Source:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Substrate;
namespace substratetest
{
class Program
{
static void Main(string[] args)
{
System.IO.Directory.CreateDirectory("./test");
BetaWorld anvil = BetaWorld.Create("./test");
BetaChunkManager cm = anvil.GetChunkManager();
Console.WriteLine("Speed test...");
System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew();
for (int cx = 0; cx < 10; cx++)
{
for (int cz = 0; cz < 10; cz++)
{
ChunkRef chunk = cm.CreateChunk(cx, cz);
for (int x = 0; x < chunk.Blocks.XDim; x++)
{
for (int y = 0; y < chunk.Blocks.YDim; y++)
{
for (int z = 0; z < chunk.Blocks.ZDim; z++)
{
chunk.Blocks.SetBlock(x,y,z,new AlphaBlock(1));
}
}
}
}
}
anvil.Save();
sw.Stop();
Console.WriteLine("Placed " + (10 * 10) * (16*16*256) + " blocks in " + sw.Elapsed.TotalSeconds + " seconds!");
Console.ReadLine();
}
}
}
I have a SSD so saving shall not be a problem(1.1 was saving a 50*50 chunk flatmap in 0.68 seconds on my computer.).
Without a comparison against version 1.1.1, I can't really say anything about your speed test results. For what your test is doing though, you're pretty much getting the worst performance that you possibly could. Almost every block you place is incurring an expensive relighting calculation, and you're processing the data in suboptimal order (optimal order is now YZX). Newing up an entirely new AlphaBlock object for every block you set instead of using SetBlockID is also absolutely destroying you.
That aside, you should expect Anvil support to be somewhat slower, because the Anvil adapter class is doing additional work on top of the existing block container infrastructure with extra translation involved. When I ran my lighting and chunk generation tests, the impact was not terrible enough to prevent release.
Sorry about my bad code, i wrote it 5 minutes after i woke up. Well, it now makes a really fast test with 3 seconds. I think this version is pretty fast! When i run the code with 1.1, i get 1.6 seconds(half the time, half the blocks) so i don't think there is a much difference with performance. Well, it also seems like methods already exist in older versions. Thanks!
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.
- AnvilSections trees were not built correctly, causing chunk copying to fail
- Biome data was not marked optional, causing fresh-converted worlds to not process. Unitialized biome data is now created if it is missing.
Help, this dosn't seem to add a huge block of Obsidian, it runs for a few moments but seems to do nothing to the specified world?
using System;
using Substrate;
namespace BlockReplace
{
static class Program
{
static void Main()
{
BetaWorld world = BetaWorld.Open(
"C:\\Users\\Alan\\AppData\\Roaming\\.minecraft\\saves\\alan");
var blocks = world.GetBlockManager();
for (Int16 x = -100; x < 100; x++)
for (Int16 y = 1; y < 200; y++)
for (Int16 z = -100; z < 100; z++)
blocks.SetID(x, y, z, BlockType.OBSIDIAN);
world.Save();
}
}
}
Does this world exist?
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.
I've tried running your example on an Anvil World, and opening the results in MCEdit, it looks like it did the expected thing and created a very large block of obsidian.
It did run for 5-10 minutes on my machine, before completing. From your post, I suspect you were stopping your program before it was allowed to finish. The code is taking a long time to run because it is not efficient for what you are trying to do. Filling the map with a giant chunk of blocks seems like it should be simple, and the code to do it is simple, but it is a deceptive task. You should be able to speed it up by working with the ChunkManager instead of the BlockManager, reordering your indices, and turning off AutoLight on each chunk before you work on it (then patching up the lighting at the very end of everything). Look a few posts up for a discussion on this.
If your program is actually running to completion and you still see no results, please send me a sample world.
I could not reproduce your crash when I ran your code on an Anvil world. Please send me a world that crashes when you run your code, along with a full code snippet that I can compile and run, and the input you are supplying to it.
Note: For both you and the above, I will not be able to look at anything until Sunday.
I see now, you're not using the Anvil-compatible version of Substrate. You need to download from the "anvil beta" link in the first post. Anvil support is not yet unified back into the main distribution.
Yes Anvil was the new map format introduced in Minecraft 1.2.
You can recalculate light on a per-chunk basis if you're using the ChunkManager.
There's a set of functions exposed by the Blocks property of a Chunk or ChunkRef such as RebuildHeightMap, RebuildBlockLight, RebuildSkyLight, ResetBlockLight, and ResetSkyLight.
To have correct lighting, you really need to do a full reset on every chunk that could have had its lighting affected by your changes (so any chunk you modified, and any of their immediate neighbors), and then rebuild the height map and rebuild the lighting. See the relight example that's included.
If you're touching a relatively small number of blocks, it will be faster to let the SDK recalculate local lighting on each change, as it does by default.
The most efficient way is to loop over all the Regions in the RegionManager and call Count() on each one. Otherwise you need to loop over all the chunks in the ChunkManager.
In the code you posted, it looks like you were trying to calculate global coordinates and then feed them to individual regions, which should result in you trying to create a scatterplot of chunks over a very large area. I'm going to argue that your empty 0,0 chunk is actually the only chunk that you successfully created. Substrate does not have a default terrain generator, so any chunk you create is filled with air blocks. All the surrounding generated chunks you saw were generated by minecraft upon loading up your world, because no chunk was actually created in those locations.
The code you were actually looking for:
However, that could would actually give you 4 regions worth of totally empty chunks. You either need to write your own terrain generator to actually build those chunks, or don't create them at all, and let Minecraft do it for you (or search for one of the Java tools that automatically invokes the Minecraft server on your world to generate chunks without exploring).
On another note about your code, I think you're making your job harder than it needs to be by working directly with regions. Like I mentioned previously, you could use the ChunkManager, and work entirely in global chunk coordinates without worrying about having to create region files or translate, it's all done in the background for you.
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
In the next 2-3 weeks following the anvil-only release, I'm hoping to have a release that re-unifies all of the map support. The changes are far-reaching, so it's likely that the existing API will break in at least a few small ways. It's still too early for me to estimate how badly.
Mods I Develop: Garden Stuff -- Storage Drawers -- Hunger Strike
Tools I Develop: NBTExplorer -- Substrate
http://hocuspocus.taloncrossing.com/rii/Substrate-1.2.1-anvil.zip
This is a horrible release, but at least for some of you, it is better than waiting another month for proper unified Anvil support. Alpha and Beta map support is disabled in this build. Anvil maps should be interacted with as if they were beta maps (use BetaWorldManager, BetaChunkManager, etc.) Underneath, I have simply replaced the Chunk class with an Anvil adapter class, which will expose Anvil chunks as 256-block-high AlphaBlockCollections. This means your existing code should not need any changes to operate with Anvil maps. If you wish to continue supporting older maps, plan on releasing two copies of your program until a proper Anvil release is available, one built against 1.2.0, and one built against 1.1.1.
Please go ahead and test this with your tools and let me know what problems you encounter. I will continue to fix bugs on this branch while I work on a unified release separately.
Mods I Develop: Garden Stuff -- Storage Drawers -- Hunger Strike
Tools I Develop: NBTExplorer -- Substrate
At first look, i saw ChunkRef.StitchBlockLight and ChunkRef.StitchSkyLight methods. Are these new features or was it something i didn't notice? Also, things i noticed:
ChunkRef.StitchBlockLight
ChunkRef.StitchSkyLight
Substrate.Core.IBoundedPropertyBlockCollection
Substrate.Core.IBoundedLitBlockCollection
Substrate.Core.IBoundedDataBlockCollection
Substrate.Core.IBoundedBlockCollection
Substrate.Core.IBoundedAlphaBlockCollection
Substrate.Core.IBoundedActiveBlockCollection
(i'm not sure about Substrate.Core.IBounded interfaces. Are those new?)
Are those a sign of a new update or am i being overexcited/not noticing features that was been there? Also, i'm running a test of speed on a sample Anvil world. Will update soon!
EDIT: Is there a problem or my computer is horrible?
Output from my program:
Source:
I have a SSD so saving shall not be a problem(1.1 was saving a 50*50 chunk flatmap in 0.68 seconds on my computer.).
Without a comparison against version 1.1.1, I can't really say anything about your speed test results. For what your test is doing though, you're pretty much getting the worst performance that you possibly could. Almost every block you place is incurring an expensive relighting calculation, and you're processing the data in suboptimal order (optimal order is now YZX). Newing up an entirely new AlphaBlock object for every block you set instead of using SetBlockID is also absolutely destroying you.
That aside, you should expect Anvil support to be somewhat slower, because the Anvil adapter class is doing additional work on top of the existing block container infrastructure with extra translation involved. When I ran my lighting and chunk generation tests, the impact was not terrible enough to prevent release.
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
Mods I Develop: Garden Stuff -- Storage Drawers -- Hunger Strike
Tools I Develop: NBTExplorer -- Substrate
http://hocuspocus.taloncrossing.com/rii/Substrate-1.2.1-anvil.zip
- AnvilSections trees were not built correctly, causing chunk copying to fail
- Biome data was not marked optional, causing fresh-converted worlds to not process. Unitialized biome data is now created if it is missing.
Mods I Develop: Garden Stuff -- Storage Drawers -- Hunger Strike
Tools I Develop: NBTExplorer -- Substrate
Does this world exist?
I've tried running your example on an Anvil World, and opening the results in MCEdit, it looks like it did the expected thing and created a very large block of obsidian.
It did run for 5-10 minutes on my machine, before completing. From your post, I suspect you were stopping your program before it was allowed to finish. The code is taking a long time to run because it is not efficient for what you are trying to do. Filling the map with a giant chunk of blocks seems like it should be simple, and the code to do it is simple, but it is a deceptive task. You should be able to speed it up by working with the ChunkManager instead of the BlockManager, reordering your indices, and turning off AutoLight on each chunk before you work on it (then patching up the lighting at the very end of everything). Look a few posts up for a discussion on this.
If your program is actually running to completion and you still see no results, please send me a sample world.
Mods I Develop: Garden Stuff -- Storage Drawers -- Hunger Strike
Tools I Develop: NBTExplorer -- Substrate
I could not reproduce your crash when I ran your code on an Anvil world. Please send me a world that crashes when you run your code, along with a full code snippet that I can compile and run, and the input you are supplying to it.
Note: For both you and the above, I will not be able to look at anything until Sunday.
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
You can recalculate light on a per-chunk basis if you're using the ChunkManager.
There's a set of functions exposed by the Blocks property of a Chunk or ChunkRef such as RebuildHeightMap, RebuildBlockLight, RebuildSkyLight, ResetBlockLight, and ResetSkyLight.
To have correct lighting, you really need to do a full reset on every chunk that could have had its lighting affected by your changes (so any chunk you modified, and any of their immediate neighbors), and then rebuild the height map and rebuild the lighting. See the relight example that's included.
If you're touching a relatively small number of blocks, it will be faster to let the SDK recalculate local lighting on each change, as it does by default.
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