本文整理汇总了C#中World.GetBlockAt方法的典型用法代码示例。如果您正苦于以下问题:C# World.GetBlockAt方法的具体用法?C# World.GetBlockAt怎么用?C# World.GetBlockAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类World
的用法示例。
在下文中一共展示了World.GetBlockAt方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RecursivelyPropagateLight
void RecursivelyPropagateLight(World world, BlockPosition blockPosition, byte incomingLightValue)
{
TotalNumberOfRecursions++;
NumberOfRecursions++;
if (incomingLightValue < 1)
{
return;
}
var block = world.GetBlockAt(blockPosition);
if (block.LightLevel >= incomingLightValue)
{
return;
}
if (!block.CanPropagateLight)
{
return;
}
world.SetLightLevel(blockPosition, incomingLightValue);
//Trace.WriteLine(string.Format("Replaced light value {0} with {1} at {2}", block.LightLevel, incomingLightValue, blockPosition));
var outgoingLightLevel = (byte)(incomingLightValue - 1);
// TODO: right now this is a depth-first fill. We really need to do a breadth-first fill so that blocks gets filled
// first with the highest possible levels of light and we don't spend time overwriting lower levels from long recursion
// chains that doubled back with higher levels from shorter recursion chains.
// http://en.wikipedia.org/wiki/Iterative_deepening
// It would probably be smart to get some unit tests going before messing with this too much.
// It might also be interesting to do iterative deepening across the whole chunk so that multiple
// sunlit blocks contributing to a large dark space fill it in cooperatively rather than the first
// block flood-filling the whole space, then the second doing the same with slightly different values.
// That would probably not be a net win but it's worth thinking about. We could do a first pass on all
// sunlit blocks and make a list of just the ones that managed to propogate light somewhere, then do
// iterative deepening on just those.
if (outgoingLightLevel > 0)
{
RecursivelyPropagateLight(world, blockPosition.Left, outgoingLightLevel);
RecursivelyPropagateLight(world, blockPosition.Right, outgoingLightLevel);
RecursivelyPropagateLight(world, blockPosition.Up, outgoingLightLevel);
RecursivelyPropagateLight(world, blockPosition.Down, outgoingLightLevel);
RecursivelyPropagateLight(world, blockPosition.Front, outgoingLightLevel);
RecursivelyPropagateLight(world, blockPosition.Back, outgoingLightLevel);
}
}
示例2: PropagateLightFromBlock
public void PropagateLightFromBlock(World world, BlockPosition blockPosition)
{
NumberOfRecursions = 0;
var block = world.GetBlockAt(blockPosition);
if (!block.CanPropagateLight)
{
return;
}
var newLightValue = (byte)(block.LightLevel - 1);
RecursivelyPropagateLight(world, blockPosition.Left, newLightValue);
RecursivelyPropagateLight(world, blockPosition.Right, newLightValue);
RecursivelyPropagateLight(world, blockPosition.Up, newLightValue);
RecursivelyPropagateLight(world, blockPosition.Down, newLightValue);
RecursivelyPropagateLight(world, blockPosition.Front, newLightValue);
RecursivelyPropagateLight(world, blockPosition.Back, newLightValue);
}
示例3: Intersects
//.........这里部分代码省略.........
stepX = 0;
tDeltaX = 0;
tMaxX = float.MaxValue;
}
if (ray.Direction.Y > 0)
{
stepY = 1;
tDeltaY = 1 / ray.Direction.Y;
tMaxY = (currentBlockPosition.Y + 1 - ray.Position.Y) * tDeltaY;
}
else if (ray.Direction.Y < 0)
{
stepY = -1;
tDeltaY = 1 / -ray.Direction.Y;
tMaxY = (ray.Position.Y - currentBlockPosition.Y) * tDeltaY;
}
else
{
stepY = 0;
tDeltaY = 0;
tMaxY = float.MaxValue;
}
if (ray.Direction.Z > 0)
{
stepZ = 1;
tDeltaZ = 1 / ray.Direction.Z;
tMaxZ = (currentBlockPosition.Z + 1 - ray.Position.Z) * tDeltaZ;
}
else if (ray.Direction.Z < 0)
{
stepZ = -1;
tDeltaZ = 1 / -ray.Direction.Z;
tMaxZ = (ray.Position.Z - currentBlockPosition.Z) * tDeltaZ;
}
else
{
stepZ = 0;
tDeltaZ = 0;
tMaxZ = float.MaxValue;
}
float currentRayLength;
do
{
Face intersectedFace;
if (tMaxX < tMaxY)
{
if (tMaxX < tMaxZ)
{
currentRayLength = tMaxX;
intersectedFace = Face.X;
currentBlockPosition.X += stepX;
tMaxX = tMaxX + tDeltaX;
}
else
{
currentRayLength = tMaxZ;
intersectedFace = Face.Z;
currentBlockPosition.Z += stepZ;
tMaxZ = tMaxZ + tDeltaZ;
}
}
else
{
if (tMaxY < tMaxZ)
{
currentRayLength = tMaxY;
intersectedFace = Face.Y;
currentBlockPosition.Y += stepY;
tMaxY = tMaxY + tDeltaY;
}
else
{
currentRayLength = tMaxZ;
intersectedFace = Face.Z;
currentBlockPosition.Z += stepZ;
tMaxZ = tMaxZ + tDeltaZ;
}
}
if (currentRayLength < maximumRayLength)
{
var block = world.GetBlockAt(currentBlockPosition);
if (block.CanBeSelected)
{
var selectedFaceNormal = GetNormalForIntersectedFace(intersectedFace, stepX, stepY, stepZ);
return new IntersectionResult
{
IntersectedBlock = block,
IntersectedFaceNormal = selectedFaceNormal
};
}
}
}
while (currentRayLength < maximumRayLength);
return null;
}