本文整理汇总了C#中Chunk.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Chunk.GetType方法的具体用法?C# Chunk.GetType怎么用?C# Chunk.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Chunk
的用法示例。
在下文中一共展示了Chunk.GetType方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: Execute
public override object Execute(Script script, Scope scope, Token previousToken, object unknown)
{
// Evaluate the RHS.
object result = new Chunk(_rhs, script).Evaluate(scope);
if (result is bool)
{
return !((bool) result);
}
throw new Exception(String.Format("Expected a boolean value, not {0}", result.GetType().Name));
}
示例3: Grow
public void Grow(StructBlock block, Chunk chunk)
{
if (!CanGrow(block, chunk))
return;
UniversalCoords blockUp = UniversalCoords.FromWorld(block.Coords.WorldX, block.Coords.WorldY + 1, block.Coords.WorldZ);
if (block.World.GetEffectiveLight(blockUp) < 9)
return;
if (block.World.Server.Rand.Next(29) != 0)
return;
if ((block.MetaData & 8) == 0)
{
chunk.SetData(block.Coords, (byte)(block.MetaData | 8));
return;
}
for (int i = block.Coords.WorldY; i < block.Coords.WorldY + 4; i++)
{
chunk.SetBlockAndData(block.Coords.BlockX, i, block.Coords.BlockZ, (byte)BlockData.Blocks.Log, block.MetaData);
if(chunk.GetType(block.Coords.BlockX, i + 1, block.Coords.BlockZ) != BlockData.Blocks.Air)
break;
}
// Grow leaves
for (int i = block.Coords.WorldY + 2; i < block.Coords.WorldY + 5; i++)
for (int j = block.Coords.WorldX - 2; j <= block.Coords.WorldX + 2; j++)
for (int k = block.Coords.WorldZ - 2; k <= block.Coords.WorldZ + 2; k++)
{
Chunk nearbyChunk = block.World.GetChunkFromWorld(i, k, false, false);
if (nearbyChunk == null || (nearbyChunk.GetType(j & 0xF, i, k & 0xF) != BlockData.Blocks.Air))
continue;
nearbyChunk.SetBlockAndData(j & 0xF, i, k & 0xF, (byte)BlockData.Blocks.Leaves,
block.MetaData);
}
for (int i = block.Coords.WorldX - 1; i <= block.Coords.WorldX + 1; i++)
for (int j = block.Coords.WorldZ - 1; j <= block.Coords.WorldZ + 1; j++)
{
Chunk nearbyChunk = block.World.GetChunkFromWorld(i, j, false, false);
if (nearbyChunk == null || nearbyChunk.GetType(i & 0xF, block.Coords.WorldY + 5, j & 0xF) != BlockData.Blocks.Air)
continue;
nearbyChunk.SetBlockAndData(i & 0xF, block.Coords.WorldY + 5, j & 0xF, (byte)BlockData.Blocks.Leaves,
block.MetaData);
}
}
示例4: Grow
public void Grow(StructBlock block, Chunk chunk)
{
if (!CanGrow(block, chunk))
return;
UniversalCoords oneUp = UniversalCoords.FromWorld(block.Coords.WorldX, block.Coords.WorldY + 1, block.Coords.WorldZ);
byte blockAboveId = (byte)chunk.GetType(oneUp);
byte? blockAboveLight = chunk.World.GetEffectiveLight(oneUp);
if (blockAboveLight == null)
return;
if (blockAboveLight < 4 && BlockHelper.Instance(blockAboveId).Opacity > 2)
{
if (block.World.Server.Rand.Next(3) == 0)
{
chunk.SetBlockAndData(block.Coords, (byte)BlockData.Blocks.Dirt, 0);
}
return;
}
if (blockAboveLight >= 9)
{
int x = block.Coords.WorldX + block.World.Server.Rand.Next(2) - 1;
int y = block.Coords.WorldY + block.World.Server.Rand.Next(4) - 3;
int z = block.Coords.WorldZ + block.World.Server.Rand.Next(2) - 1;
Chunk nearbyChunk = block.World.GetChunkFromWorld(x, z);
if (nearbyChunk == null)
return;
byte newBlockId = (byte)nearbyChunk.GetType(x & 0xF, y, z & 0xF);
if (newBlockId != (byte)BlockData.Blocks.Dirt)
return;
byte? newBlockAboveLight = nearbyChunk.World.GetEffectiveLight(UniversalCoords.FromWorld(x, y + 1, z));
if (newBlockAboveLight != null && (newBlockAboveLight >= 4 && BlockHelper.Instance(newBlockId).Opacity <= 2))
nearbyChunk.SetBlockAndData(x & 0xF, y, z & 0xF, (byte)BlockData.Blocks.Grass, 0);
}
}
示例5: Execute
public override object Execute(Script script, Scope scope, Token previousToken, object unknown)
{
// Eval both sides.
object lhs = new Chunk(_lhs, script).Evaluate(scope);
object rhs = new Chunk(_rhs, script).Evaluate(scope);
if (lhs == null)
{
throw new Exception("The LHS of a in statement cannot be null!");
}
// Check the RHS.
if (rhs == null)
{
throw new Exception("The RHS of a in statement cannot be null!");
}
if (rhs is object[])
{
var items = (object[]) rhs;
for (int i = 0; i < items.Length; i++)
{
if (items[i].Equals(lhs))
{
return true;
}
}
}
else if (rhs.GetType().IsSubclassOf(typeof (IEnumerable)))
{
IEnumerable<object> enumerable = ((IEnumerable) rhs).OfType<object>();
return enumerable.Contains(lhs);
}
else
{
throw new Exception(
"The right hand side of a in statement must be an array of some sort, or implement IEnumerable");
}
return false;
}
示例6: CanGrow
public bool CanGrow(StructBlock block, Chunk chunk)
{
if (chunk == null)
return false;
bool canGrow = false;
if (block.Coords.WorldY < 127)
{
UniversalCoords oneUp = UniversalCoords.FromWorld(block.Coords.WorldX, block.Coords.WorldY + 1,
block.Coords.WorldZ);
byte blockAboveId = (byte)chunk.GetType(oneUp);
byte? blockAboveLight = chunk.World.GetEffectiveLight(oneUp);
if (blockAboveLight != null && ((blockAboveLight < 4 && BlockHelper.Instance(blockAboveId).Opacity > 2) || blockAboveLight >= 9))
canGrow = true;
}
else
{
canGrow = true;
}
return canGrow;
}
示例7: Accept
//.........这里部分代码省略.........
{
Visit((LocalVariableChunk)chunk);
}
else if (chunk is SendExpressionChunk)
{
Visit((SendExpressionChunk)chunk);
}
else if (chunk is ForEachChunk)
{
Visit((ForEachChunk)chunk);
}
else if (chunk is ScopeChunk)
{
Visit((ScopeChunk)chunk);
}
else if (chunk is GlobalVariableChunk)
{
Visit((GlobalVariableChunk)chunk);
}
else if (chunk is AssignVariableChunk)
{
Visit((AssignVariableChunk)chunk);
}
else if (chunk is ContentChunk)
{
Visit((ContentChunk)chunk);
}
else if (chunk is ContentSetChunk)
{
Visit((ContentSetChunk)chunk);
}
else if (chunk is UseContentChunk)
{
Visit((UseContentChunk)chunk);
}
else if (chunk is RenderPartialChunk)
{
Visit((RenderPartialChunk)chunk);
}
else if (chunk is RenderSectionChunk)
{
Visit((RenderSectionChunk)chunk);
}
else if (chunk is ViewDataChunk)
{
Visit((ViewDataChunk)chunk);
}
else if (chunk is ViewDataModelChunk)
{
Visit((ViewDataModelChunk)chunk);
}
else if (chunk is UseNamespaceChunk)
{
Visit((UseNamespaceChunk)chunk);
}
else if (chunk is ConditionalChunk)
{
Visit((ConditionalChunk)chunk);
}
else if (chunk is ExtensionChunk)
{
Visit((ExtensionChunk)chunk);
}
else if (chunk is CodeStatementChunk)
{
Visit((CodeStatementChunk)chunk);
}
else if (chunk is MacroChunk)
{
Visit((MacroChunk)chunk);
}
else if (chunk is UseAssemblyChunk)
{
Visit((UseAssemblyChunk)chunk);
}
else if (chunk is UseImportChunk)
{
Visit((UseImportChunk)chunk);
}
else if (chunk is DefaultVariableChunk)
{
Visit((DefaultVariableChunk)chunk);
}
else if (chunk is UseMasterChunk)
{
Visit((UseMasterChunk)chunk);
}
else if (chunk is PageBaseTypeChunk)
{
Visit((PageBaseTypeChunk)chunk);
}
else if (chunk is CacheChunk)
{
Visit((CacheChunk)chunk);
}
else
{
throw new CompilerException(string.Format("Unknown chunk type {0}", chunk.GetType().Name));
}
}
示例8: 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;
}