本文整理汇总了C#中Substrate.ChunkRef类的典型用法代码示例。如果您正苦于以下问题:C# ChunkRef类的具体用法?C# ChunkRef怎么用?C# ChunkRef使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ChunkRef类属于Substrate命名空间,在下文中一共展示了ChunkRef类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FlatChunk
private static void FlatChunk(ChunkRef chunk, int height)
{
// Create bedrock
for (int y = 0; y < 2; y++)
{
for (int x = 0; x < 16; x++)
{
for (int z = 0; z < 16; z++)
{
chunk.Blocks.SetID(x, y, z, (int)BlockType.BEDROCK);
}
}
}
for (int x = 0; x < 16; x++)
{
for (int z = 0; z < 16; z++)
{
chunk.Biomes.SetBiome(x,z, BiomeType.Plains);
}
}
// Create stone
for (int y = 2; y < height - 5; y++)
{
for (int x = 0; x < 16; x++)
{
for (int z = 0; z < 16; z++)
{
chunk.Blocks.SetID(x, y, z, (int)BlockType.STONE);
}
}
}
// Create dirt
for (int y = height - 5; y < height - 1; y++)
{
for (int x = 0; x < 16; x++)
{
for (int z = 0; z < 16; z++)
{
chunk.Blocks.SetID(x, y, z, (int)BlockType.DIRT);
}
}
}
// Create grass
for (int y = height - 1; y < height; y++)
{
for (int x = 0; x < 16; x++)
{
for (int z = 0; z < 16; z++)
{
chunk.Blocks.SetID(x, y, z, (int)BlockType.GRASS);
}
}
}
}
示例2: CreateFlatChunk
private static void CreateFlatChunk(ChunkRef chunk, int[, ,] intUndergroundTerrain)
{
for (int x = 0; x < 16; x++)
{
for (int z = 0; z < 16; z++)
{
for (int y = 0; y < 2; y++)
{
chunk.Blocks.SetID(x, y, z, BlockType.BEDROCK);
}
for (int y = 2; y < 63; y++)
{
chunk.Blocks.SetID(x, y, z, intUndergroundTerrain[(chunk.X * 16) + x, y, (chunk.Z * 16) + z]);
}
for (int y = 63; y < 64; y++)
{
chunk.Blocks.SetID(x, y, z, BlockType.GRASS);
}
}
}
}
示例3: ApplyChunk
public void ApplyChunk(NbtWorld world, ChunkRef chunk)
{
IBlockFilter opt_b = opt.GetBlockFilter();
int xBase = chunk.X * chunk.Blocks.XDim;
int zBase = chunk.Z * chunk.Blocks.ZDim;
// Determine X range
int xmin = 0;
int xmax = 15;
if (opt_b.XAboveEq != null) {
xmin = (int)opt_b.XAboveEq - xBase;
}
if (opt_b.XBelowEq != null) {
xmax = (int)opt_b.XBelowEq - xBase;
}
xmin = (xmin < 0) ? 0 : xmin;
xmax = (xmax > 15) ? 15 : xmax;
if (xmin > 15 || xmax < 0 || xmin > xmax) {
return;
}
// Determine Y range
int ymin = 0;
int ymax = 127;
if (opt_b.YAboveEq != null) {
ymin = (int)opt_b.YAboveEq;
}
if (opt_b.YBelowEq != null) {
ymax = (int)opt_b.YBelowEq;
}
if (ymin > ymax) {
return;
}
// Determine X range
int zmin = 0;
int zmax = 15;
if (opt_b.ZAboveEq != null) {
zmin = (int)opt_b.ZAboveEq - zBase;
}
if (opt_b.ZBelowEq != null) {
zmax = (int)opt_b.ZBelowEq - zBase;
}
zmin = (zmin < 0) ? 0 : zmin;
zmax = (zmax > 15) ? 15 : zmax;
if (zmin > 15 || zmax < 0 || zmin > zmax) {
return;
}
int xdim = chunk.Blocks.XDim;
int ydim = chunk.Blocks.YDim;
int zdim = chunk.Blocks.ZDim;
// Bin blocks
for (int y = ymin; y <= ymax; y++) {
for (int x = xmin; x <= xmax; x++) {
for (int z = zmin; z <= zmax; z++) {
int id = chunk.Blocks.GetID(x, y, z);
_sort[id].Add(new BlockKey(x, y, z));
}
}
}
// Process bins
for (int i = 0; i < 256; i++) {
if (_sort[i].Count == 0) {
continue;
}
if (opt_b.IncludedBlockCount > 0 & !opt_b.IncludedBlocksContains(i)) {
continue;
}
if (opt_b.ExcludedBlockCount > 0 & opt_b.ExcludedBlocksContains(i)) {
continue;
}
foreach (BlockKey key in _sort[i]) {
chunk.Blocks.SetID(key.x, key.y, key.z, (int)opt.OPT_AFTER);
if (opt.OPT_VV) {
int gx = chunk.X * xdim + key.x;
int gz = chunk.Z * zdim + key.z;
Console.WriteLine("Replaced block {0} at {1},{2},{3}", i, gx, key.y, gz);
}
if (opt.OPT_DATA != null) {
chunk.Blocks.SetData(key.x, key.y, key.z, (int)opt.OPT_DATA);
}
}
}
//.........这里部分代码省略.........
示例4: FindFreeAir
public int[] FindFreeAir(ChunkRef chunk, RegionChunkManager chunkMan, int x, int y, int z)
{
int cx = chunk.X;
int cz = chunk.Z;
int[] position = { -9999, -9999, cx, cz };
int xdim = chunk.Blocks.XDim;
int zdim = chunk.Blocks.ZDim;
int xt;
int zt;
int cxt;
int czt;
for (int a = 0; a <= 8; a++)
{
xt = x + (-fallSpread + rand.Next(((1 + fallSpread) * 2)));
zt = z + (-fallSpread + rand.Next(((1 + fallSpread) * 2)));
cxt = cx;
czt = cz;
// Jump into neighboring chunks if needed
if (xt < 0)
{
cxt--;
xt = xt + xdim;
}
else if (xt >= xdim)
{
cxt++;
xt = xt - xdim;
}
if (zt < 0)
{
czt--;
zt = zt + zdim;
}
else if (zt >= zdim)
{
czt++;
zt = zt - zdim;
}
ChunkRef tchunk = chunkMan.GetChunkRef(cxt, czt);
if (tchunk == null)
continue;
int resBlock = tchunk.Blocks.GetID(xt, y, zt);
if (resBlock == 0 || smashBlock.Contains(resBlock))
{
position[0] = xt;
position[1] = zt;
position[2] = cxt;
position[3] = czt;
break;
}
}
return position;
}
示例5: FindFreeLight
public int[] FindFreeLight(ChunkRef chunk, RegionChunkManager chunkMan, int x, int y, int z)
{
int[] position = { -9999, -9999, -9999, -999, -999 };
int cx = chunk.X;
int cz = chunk.Z;
int xdim = chunk.Blocks.XDim;
int zdim = chunk.Blocks.ZDim;
int xt = x;
int zt = z;
int chance = rand.Next(4);
if (chance == 0)
xt = x + 1;
else if (chance == 1)
xt = x - 1;
else if (chance == 2)
zt = z + 1;
else
zt = z - 1;
int xtt = xt;
int ztt = zt;
int cxt = cx;
int czt = cz;
for (int a = 0; a <= 4; a++)
{
xt = x;
zt = z;
cxt = cx;
czt = cz;
if (a == 4)
{
y--;
}
else if ((xtt == x + 1) && (ztt == z))
{
xt = x;
zt = z + 1;
}
else if ((xtt == x) && (ztt == z + 1))
{
xt = x - 1;
zt = z;
}
else if ((xtt == x - 1) && (ztt == z))
{
xt = x;
zt = z - 1;
}
else if ((xtt == x) && (ztt == z - 1))
{
xt = x + 1;
zt = z;
}
xtt = xt;
ztt = zt;
// Jump into neighboring chunks if needed
if (xt < 0)
{
cxt--;
xt = xt + xdim;
}
else if (xt >= xdim)
{
cxt++;
xt = xt - xdim;
}
if (zt < 0)
{
czt--;
zt = zt + zdim;
}
else if (zt >= zdim)
{
czt++;
zt = zt - zdim;
}
ChunkRef tchunk = chunkMan.GetChunkRef(cxt, czt);
if (tchunk == null)
{ continue; }
int resBlock = tchunk.Blocks.GetID(xt, y, zt);
if (resBlock == 0 || smashBlock.Contains(resBlock))
{
position[0] = xt;
position[1] = zt;
position[2] = y;
position[3] = cxt;
//.........这里部分代码省略.........
示例6: CleanChunk
// Function for cleaning clutter left by AgeChunk
public void CleanChunk(ChunkRef chunk, RegionChunkManager chunkMan, Bitmap perlinMask, int perlinResolution, int[] minXZ)
{
int xdim = chunk.Blocks.XDim;
int ydim = chunk.Blocks.YDim;
int zdim = chunk.Blocks.ZDim;
int checkx = 0;
int checky = 0;
int checkz = 0;
int oldBlock;
float natureKillChanceMin = (float)natureKillChance[0] / 100f;
float natureKillChanceMax = (float)natureKillChance[1] / 100f - natureKillChanceMin;
// Check all blocks in the chunk
for (int x = 0; x < xdim; x++)
{
for (int z = 0; z < zdim; z++)
{
int px = Math.Abs(minXZ[0]) + (chunk.X * 16) + (x / perlinResolution);
int py = Math.Abs(minXZ[1]) + (chunk.Z * 16) + (z / perlinResolution);
px = Math.Min(Math.Max(px, 0), perlinMask.Width - 1);
py = Math.Min(Math.Max(py, 0), perlinMask.Height - 1);
Color perlinCol = perlinMask.GetPixel(px, py);
double perlinMulti = (double)perlinCol.R / 255f;
bool eroded = false;
bool foundLeaves = false;
for (int y = ydim - 2; y > 1; y--)
{
checkx = x;
checky = y;
checkz = z;
// Attempt to replace block
oldBlock = chunk.Blocks.GetID(x, y, z);
int oldData = chunk.Blocks.GetData(x, y, z);
// Destroy old trees
if (natureRepopulation)
{
if (oldBlock == 18)
{
foundLeaves = true;
}
if (foundLeaves && oldBlock == 17)
{
chunk.Blocks.SetID(x, y, z, 0);
}
}
if (oldBlock != 0 && !eroded && natureKillBlock.Length != 0)
{
foreach (int i in natureKillBlock)
{
if (oldBlock == i)
{
double c = rand.NextDouble();
if (c < natureKillChanceMin + (natureKillChanceMax * perlinMulti))
{
chunk.Blocks.SetID(x, y, z, natureKillTo);
}
eroded = true;
break;
}
}
}
// Check signs, ladders
if (oldBlock == 65 || oldBlock == 68)
{
if (oldData == 2)
{
checkz = z + 1;
}
else if (oldData == 3)
{
checkz = z - 1;
}
else if (oldData == 4)
{
checkx = x + 1;
}
else if (oldData == 5)
{
checkx = x - 1;
}
int airCheck = CheckAir(chunk, chunkMan, checkx, checky, checkz);
if (airCheck == 0)
{
chunk.Blocks.SetID(x, y, z, 0);
continue;
}
}
//.........这里部分代码省略.........
示例7: CheckAir
public int CheckAir(ChunkRef chunk, RegionChunkManager chunkMan, int x, int y, int z)
{
int cx = chunk.X;
int cz = chunk.Z;
int xdim = chunk.Blocks.XDim;
int zdim = chunk.Blocks.ZDim;
int result = 0;
if (x < 0)
{
cx--;
x = x + xdim;
}
else if (x >= xdim)
{
cx++;
x = x - xdim;
}
if (z < 0)
{
cz--;
z = z + zdim;
}
else if (z >= zdim)
{
cz++;
z = z - zdim;
}
ChunkRef tchunk = chunkMan.GetChunkRef(cx, cz);
if (tchunk != null)
{
int resBlock = tchunk.Blocks.GetID(x, y, z);
if (resBlock != 0)
{
result = resBlock;
}
}
return result;
}
示例8: AgeChunk
// Function for falling and toppling blocks
public void AgeChunk(ChunkRef chunk, RegionChunkManager chunkMan, Bitmap perlinMask, int perlinResolution, int[] minXZ)
{
int xdim = chunk.Blocks.XDim;
int ydim = chunk.Blocks.YDim;
int zdim = chunk.Blocks.ZDim;
double c = 0;
int xp;
int yp;
int zp;
float fallChanceMin = (float)fallChance[0] / 100f; // Some lazy coding on my side
float fallChanceMax = (float)fallChance[1] / 100f - fallChanceMin;
float fallKillChanceMin = (float)fallKillChance[0] / 100f;
float fallKillChanceMax = (float)fallKillChance[1] / 100f - fallKillChanceMin;
float sidewaysFallChanceMin = (float)sidewaysFallChance[0] / 100f;
float sidewaysFallChanceMax = (float)sidewaysFallChance[1] / 100f - sidewaysFallChanceMin;
float stoneFallChanceMin = (float)stoneFallChance[0] / 100f;
float stoneFallChanceMax = (float)stoneFallChance[1] / 100f - stoneFallChanceMin;
float stoneFallKillChanceMin = (float)stoneFallKillChance[0] / 100f;
float stoneFallKillChanceMax = (float)stoneFallKillChance[1] / 100f - stoneFallKillChanceMin;
float stoneSidewaysFallChanceMin = (float)stoneSidewaysFallChance[0] / 100f;
float stoneSidewaysFallChanceMax = (float)stoneSidewaysFallChance[1] / 100f - stoneSidewaysFallChanceMin;
int[] airPos = { -9999, -9999, -999, -999 };
for (int pass = 1; pass <= passN; pass++)
{
// Check all blocks in the chunk
for (int x = 0; x < xdim; x++)
{
for (int z = 0; z < zdim; z++)
{
if (chunk.Blocks.GetHeight(x, z) > 0 && chunk.Blocks.GetHeight(x, z) < 256)
{
// Reset the algorithm limiter
int bottomY = ydim - 2;
// Get the perlin mask multiplier
int px = Math.Abs(minXZ[0] / perlinResolution) + (chunk.X * 16 / perlinResolution) + (x / perlinResolution);
int py = Math.Abs(minXZ[1] / perlinResolution) + (chunk.Z * 16 / perlinResolution) + (z / perlinResolution);
px = Math.Min(Math.Max(px, 0), perlinMask.Width - 1);
py = Math.Min(Math.Max(py, 0), perlinMask.Height - 1);
Color perlinCol = perlinMask.GetPixel(px, py);
double perlinMulti = (double)perlinCol.R / 255f;
int oldBlock;
if (stoneAdvanced && pass <= stonePassN) // Stone displacement - advanced method
{
for (int y = chunk.Blocks.GetHeight(x, z); y > 1; y--)
{
bottomY = y;
// Get the checked block's ID
oldBlock = chunk.Blocks.GetID(x, y, z);
if (oldBlock == 2 || oldBlock == 3 || oldBlock == 12 || oldBlock == 13) // Stop if encountered grass or dirt, should stop random underground space
break;
if (oldBlock == 1)
{
airPos = FindFreeLight(chunk, chunkMan, x, y, z);
// Set the most bottom stone to be eroded, stop on grass
if (((airPos[0] == -9999) && (airPos[1] == -9999)))
{
break;
}
}
}
for (int y = bottomY; y < ydim - 2; y++)
{
// Don't even try if out of limits
if (y >= ydim - 2 || y <= 1)
{
continue;
}
// Get the checked block's ID
oldBlock = chunk.Blocks.GetID(x, y, z);
// Probability test
c = rand.NextDouble();
if (c < stoneFallChanceMin + (stoneFallChanceMax * perlinMulti))
{
if (oldBlock == 1)
{
// Random chance to destroy the block in fall
c = rand.NextDouble();
if ((c < fallKillChanceMin + (fallKillChanceMax * perlinMulti)) && pass == 1)
{
// Kill the initial block
chunk.Blocks.SetID(x, y, z, 0);
continue;
}
//.........这里部分代码省略.........
示例9: ApplyChunk
public void ApplyChunk (NbtWorld world, ChunkRef chunk)
{
if (opt.OPT_V) {
Console.WriteLine("Generating {0} size {1} deposits of {2} between {3} and {4}",
opt.OPT_ROUNDS, opt.OPT_SIZE, opt.OPT_ID, opt.OPT_MIN, opt.OPT_MAX);
}
IGenerator generator;
if (opt.OPT_DATA == null) {
generator = new NativeGenOre((int)opt.OPT_ID, (int)opt.OPT_SIZE);
((NativeGenOre)generator).MathFix = opt.OPT_MATHFIX;
}
else {
generator = new NativeGenOre((int)opt.OPT_ID, (int)opt.OPT_DATA, (int)opt.OPT_SIZE);
((NativeGenOre)generator).MathFix = opt.OPT_MATHFIX;
}
IChunkManager cm = world.GetChunkManager(opt.OPT_DIM);
IBlockManager bm = new GenOreBlockManager(cm, opt);
for (int i = 0; i < opt.OPT_ROUNDS; i++) {
if (opt.OPT_VV) {
Console.WriteLine("Generating round {0}...", i);
}
int x = chunk.X * chunk.Blocks.XDim + rand.Next(chunk.Blocks.XDim);
int y = (int)opt.OPT_MIN + rand.Next((int)opt.OPT_MAX - (int)opt.OPT_MIN);
int z = chunk.Z * chunk.Blocks.ZDim + rand.Next(chunk.Blocks.ZDim);
generator.Generate(bm, rand, x, y, z);
}
}
示例10: GetNeighborBlock
private AlphaBlockRef GetNeighborBlock(ChunkRef chunk, int x, int y, int z)
{
if (chunk == null)
return new AlphaBlockRef();
ChunkRef target = chunk;
if (x < 0) {
target = chunk.GetNorthNeighbor();
x += chunk.Blocks.XDim;
}
else if (x >= chunk.Blocks.XDim) {
target = chunk.GetSouthNeighbor();
x -= chunk.Blocks.XDim;
}
else if (z < 0) {
target = chunk.GetEastNeighbor();
z += chunk.Blocks.ZDim;
}
else if (z >= chunk.Blocks.ZDim) {
target = chunk.GetWestNeighbor();
z -= chunk.Blocks.ZDim;
}
else
return target.Blocks.GetBlockRef(x, y, z);
return GetNeighborBlock(target, x, y, z);
}
示例11: ApplyChunk
public void ApplyChunk(NbtWorld world, ChunkRef chunk)
{
IBlockFilter opt_b = opt.GetBlockFilter();
//chunk.Blocks.AutoLight = false;
//chunk.Blocks.AutoTileTick = false;
int xBase = chunk.X * chunk.Blocks.XDim;
int zBase = chunk.Z * chunk.Blocks.ZDim;
// Determine X range
int xmin = 0;
int xmax = 15;
if (opt_b.XAboveEq != null) {
xmin = (int)opt_b.XAboveEq - xBase;
}
if (opt_b.XBelowEq != null) {
xmax = (int)opt_b.XBelowEq - xBase;
}
xmin = (xmin < 0) ? 0 : xmin;
xmax = (xmax > 15) ? 15 : xmax;
if (xmin > 15 || xmax < 0 || xmin > xmax) {
return;
}
// Determine Y range
int ymin = 0;
int ymax = 127;
if (opt_b.YAboveEq != null) {
ymin = (int)opt_b.YAboveEq;
}
if (opt_b.YBelowEq != null) {
ymax = (int)opt_b.YBelowEq;
}
if (ymin > ymax) {
return;
}
// Determine X range
int zmin = 0;
int zmax = 15;
if (opt_b.ZAboveEq != null) {
zmin = (int)opt_b.ZAboveEq - zBase;
}
if (opt_b.ZBelowEq != null) {
zmax = (int)opt_b.ZBelowEq - zBase;
}
zmin = (zmin < 0) ? 0 : zmin;
zmax = (zmax > 15) ? 15 : zmax;
if (zmin > 15 || zmax < 0 || zmin > zmax) {
return;
}
int xdim = chunk.Blocks.XDim;
int ydim = chunk.Blocks.YDim;
int zdim = chunk.Blocks.ZDim;
// Bin blocks
for (int y = ymin; y <= ymax; y++) {
for (int x = xmin; x <= xmax; x++) {
for (int z = zmin; z <= zmax; z++) {
int id = chunk.Blocks.GetID(x, y, z);
if (!_sort.ContainsKey(id))
_sort[id] = new List<BlockKey>();
_sort[id].Add(new BlockKey(x, y, z));
}
}
}
// Process bins
//for (int i = 0; i < maxBin; i++) {
foreach (var kv in _sort) {
if (kv.Value.Count == 0) {
continue;
}
if (opt_b.IncludedBlockCount > 0 & !opt_b.IncludedBlocksContains(kv.Key)) {
continue;
}
if (opt_b.ExcludedBlockCount > 0 & opt_b.ExcludedBlocksContains(kv.Key)) {
continue;
}
foreach (BlockKey key in kv.Value) {
// Probability test
if (opt_b.ProbMatch != null) {
double c = rand.NextDouble();
if (c > opt_b.ProbMatch)
continue;
}
//.........这里部分代码省略.........
示例12: SetSkyLight
/// <inheritdoc/>
public void SetSkyLight(int x, int y, int z, int light)
{
cache = GetChunk(x, y, z);
if (cache == null || !Check(x, y, z)) {
return;
}
cache.Blocks.SetSkyLight(x & chunkXMask, y & chunkYMask, z & chunkZMask, light);
}
示例13: SetTileTickValue
/// <inheritdoc/>
public void SetTileTickValue(int x, int y, int z, int tickValue)
{
cache = GetChunk(x, y, z);
if (cache == null || !Check(x, y, z)) {
return;
}
cache.Blocks.SetTileTickValue(x & chunkXMask, y & chunkYMask, z & chunkZMask, tickValue);
}
示例14: SetBlock
/// <inheritdoc/>
public void SetBlock(int x, int y, int z, IActiveBlock block)
{
cache = GetChunk(x, y, z);
if (cache == null || !Check(x, y, z)) {
return;
}
cache.Blocks.SetBlock(x, y, z, block);
}
示例15: SetHeight
/// <inheritdoc/>
public void SetHeight(int x, int z, int height)
{
cache = GetChunk(x, 0, z);
if (cache == null || !Check(x, 0, z)) {
return;
}
cache.Blocks.SetHeight(x & chunkXMask, z & chunkZMask, height);
}