本文整理汇总了C#中Chunk.ForNSEW方法的典型用法代码示例。如果您正苦于以下问题:C# Chunk.ForNSEW方法的具体用法?C# Chunk.ForNSEW怎么用?C# Chunk.ForNSEW使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Chunk
的用法示例。
在下文中一共展示了Chunk.ForNSEW方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanGrow
public bool CanGrow(StructBlock block, Chunk chunk)
{
if (chunk == null)
return false;
// BlockMeta = 0x0 is a freshly planted cactus.
// The data value is incremented at random intervals.
// When it becomes 15, a new cactus block is created on top as long as the total height does not exceed 3.
int maxHeight = 3;
if (block.Coords.WorldY == 127)
return false;
UniversalCoords oneUp = UniversalCoords.FromWorld(block.Coords.WorldX, block.Coords.WorldY + 1, block.Coords.WorldZ);
BlockData.Blocks blockId = chunk.GetType(oneUp);
if (blockId != BlockData.Blocks.Air)
return false;
// Calculating the cactus length below this block
int cactusHeightBelow = 0;
for (int i = block.Coords.WorldY - 1; i >= 0; i--)
{
blockId = chunk.GetType(UniversalCoords.FromWorld(block.Coords.WorldX, i, block.Coords.WorldZ));
if (blockId != BlockData.Blocks.Cactus)
break;
cactusHeightBelow++;
}
if ((cactusHeightBelow + 1) >= maxHeight)
return false;
bool isAir = true;
chunk.ForNSEW(oneUp,
delegate(UniversalCoords uc)
{
byte? nearbyBlockId = block.World.GetBlockId(uc);
if (nearbyBlockId == null || nearbyBlockId != (byte)BlockData.Blocks.Air)
isAir = false;
});
if (!isAir)
return false;
return true;
}
示例2: CanGrow
public bool CanGrow(StructBlock block, Chunk chunk)
{
if (chunk == null)
return false;
// Can't grow above the sky
if (block.Coords.WorldY == 127)
return false;
// Can grow only if the block above is free
byte blockId = (byte)chunk.GetType(UniversalCoords.FromWorld(block.Coords.WorldX, block.Coords.WorldY + 1, block.Coords.WorldZ));
if (blockId != (byte)BlockData.Blocks.Air)
return false;
// MetaData = 0x0 is a freshly planted reed (sugar cane).
// The data value is incremented randomly.
// When it becomes 15, a new reed block is created on top as long as the total height does not exceed 3.
// Calculating the reed length below this block
int reedHeightBelow = 0;
for (int i = block.Coords.WorldY - 1; i >= 0; i--)
{
if (chunk.GetType(block.Coords.BlockX, i, block.Coords.BlockZ) != BlockData.Blocks.Reed)
break;
reedHeightBelow++;
}
// If the total reed height is bigger than the maximal height - it'll not grow
if ((reedHeightBelow + 1) >= MaxHeight)
return false;
// Checking if there are water next to the basement block
bool isWater = false;
chunk.ForNSEW(UniversalCoords.FromWorld(block.Coords.WorldX, block.Coords.WorldY - reedHeightBelow - 1, block.Coords.WorldZ),
delegate(UniversalCoords uc)
{
byte? blockIdBelow = block.World.GetBlockId(uc);
if (blockIdBelow != null && (blockIdBelow == (byte)BlockData.Blocks.Water || blockIdBelow == (byte)BlockData.Blocks.Still_Water))
{
isWater = true;
}
});
if (!isWater && reedHeightBelow < MaxHeight)
{
UniversalCoords baseBlock = UniversalCoords.FromWorld(block.Coords.WorldX,
block.Coords.WorldY - reedHeightBelow,
block.Coords.WorldZ);
BlockHelper.Instance(block.Type).Destroy(new StructBlock(baseBlock, block.Type, block.MetaData, block.World));
return false;
}
return true;
}