本文整理汇总了C#中Box.CheckSuffocation方法的典型用法代码示例。如果您正苦于以下问题:C# Box.CheckSuffocation方法的具体用法?C# Box.CheckSuffocation怎么用?C# Box.CheckSuffocation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Box
的用法示例。
在下文中一共展示了Box.CheckSuffocation方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PlaceOrRemoveBlock
//.........这里部分代码省略.........
return false;
}
// adjust the reverse shift by accounting for reverse number truncating
// when below 0
if (closest.IntersectionPoint.X < 0 && closest.IntersectionPoint.X % 1 != 0)
{
reverseShiftX--;
}
if (closest.IntersectionPoint.Z < 0 && closest.IntersectionPoint.Z % 1 != 0)
{
reverseShiftZ--;
}
// calculate cube location without the shift
x = Convert.ToInt32(Math.Truncate(closest.IntersectionPoint.X)) + reverseShiftX;
y = Convert.ToInt32(Math.Truncate(closest.IntersectionPoint.Y));
z = Convert.ToInt32(Math.Truncate(closest.IntersectionPoint.Z)) + reverseShiftZ;
if (place)
{
// correct the location based on intersection side
switch (closest.Side)
{
case Sides.FrontX:
x--;
break;
case Sides.FrontY:
y--;
break;
case Sides.FrontZ:
z--;
break;
}
}
else
{
// correct the location based on intersection side
switch (closest.Side)
{
case Sides.BackX:
x--;
break;
case Sides.BackY:
y--;
break;
case Sides.BackZ:
z--;
break;
}
}
// check for floor/ceiling limits
if (y < 0 || y > byte.MaxValue)
{
return false;
}
// adjust possible shift over the edge of the world after correction
if (x < 0)
{
x += WorldHelper.SizeX;
}
else if (x >= WorldHelper.SizeX)
{
x -= WorldHelper.SizeX;
}
if (z < 0)
{
z += WorldHelper.SizeZ;
}
else if (z >= WorldHelper.SizeZ)
{
z -= WorldHelper.SizeZ;
}
// check if placing the block will clip into an entity
if (place)
{
Box box = new Box(new Cube(x, y, z, 0), null);
List<Entity> entities = WorldHelper.GetEntities(box.CenterPoint, BlockEntityCollisionSelectRange);
bool collides = false;
foreach (Entity entity in entities)
{
box.CheckSuffocation(entity.Location, ref entity._HalfSizeX, ref entity._HalfSizeY, ref collides);
if (collides)
{
// at least one entity collides with the newly placed box
return false;
}
}
}
// retrieve the destination segment and place or remove the block
Segment destinationSegment = WorldHelper.GetSegment(x, y, z);
version = destinationSegment.PlaceOrRemoveBlockAndUpdateVersion(place, x, y, z, GetSelectedMaterial());
return true;
}