本文整理汇总了C#中Chraft.World.WorldManager.GetChunk方法的典型用法代码示例。如果您正苦于以下问题:C# WorldManager.GetChunk方法的具体用法?C# WorldManager.GetChunk怎么用?C# WorldManager.GetChunk使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Chraft.World.WorldManager
的用法示例。
在下文中一共展示了WorldManager.GetChunk方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Instance
public static PersistentContainer Instance(WorldManager world, UniversalCoords coords)
{
PersistentContainer container;
Chunk chunk = world.GetChunk(coords) as Chunk;
if (chunk == null)
return null;
BlockData.Blocks block = chunk.GetType(coords);
if (!chunk.Containers.ContainsKey(coords.BlockPackedCoords))
{
switch (block)
{
case BlockData.Blocks.Furnace:
case BlockData.Blocks.Burning_Furnace:
container = new FurnaceContainer();
container.Initialize(world, coords);
(container as FurnaceContainer).StartBurning();
break;
case BlockData.Blocks.Dispenser:
container = new DispenserContainer();
container.Initialize(world, coords);
break;
case BlockData.Blocks.Chest:
// Double chest?
if (IsDoubleChest(chunk, coords))
{
UniversalCoords[] doubleChestCoords = GetDoubleChestCoords(world, coords);
if (doubleChestCoords == null)
return null;
chunk.Containers.TryRemove(doubleChestCoords[0].BlockPackedCoords, out container);
chunk.Containers.TryRemove(doubleChestCoords[1].BlockPackedCoords, out container);
container = new LargeChestContainer(doubleChestCoords[1]);
container.Initialize(world, doubleChestCoords[0]);
chunk.Containers.TryAdd(doubleChestCoords[0].BlockPackedCoords, container);
chunk.Containers.TryAdd(doubleChestCoords[1].BlockPackedCoords, container);
}
else
{
container = new SmallChestContainer();
container.Initialize(world, coords);
}
break;
default:
return null;
}
chunk.Containers.TryAdd(coords.BlockPackedCoords, container);
}
else
{
chunk.Containers.TryGetValue(coords.BlockPackedCoords, out container);
}
return container;
}
示例2: Destroy
public static void Destroy(WorldManager world, UniversalCoords coords)
{
PersistentContainer container = Instance(world, coords);
if (container == null)
return;
Chunk chunk = world.GetChunk(coords);
if (chunk == null)
return;
PersistentContainer unused;
container.Destroy();
chunk.Containers.TryRemove(container.Coords.BlockPackedCoords, out unused);
if (container is LargeChestContainer)
chunk.Containers.TryRemove((container as LargeChestContainer).SecondCoords.BlockPackedCoords, out unused);
}
示例3: GetDoubleChestCoords
public static UniversalCoords[] GetDoubleChestCoords(WorldManager world, UniversalCoords coords)
{
Chunk chunk = world.GetChunk(coords);
if (chunk == null || !IsDoubleChest(chunk, coords))
return null;
// Is this chest the "North or East", or the "South or West"
BlockData.Blocks[] nsewBlocks = new BlockData.Blocks[4];
UniversalCoords[] nsewBlockPositions = new UniversalCoords[4];
int nsewCount = 0;
byte? blockId;
chunk.ForNSEW(coords, uc =>
{
blockId = world.GetBlockId(uc) ?? 0;
nsewBlocks[nsewCount] = (BlockData.Blocks)blockId;
nsewBlockPositions[nsewCount] = uc;
nsewCount++;
});
UniversalCoords firstCoords;
UniversalCoords secondCoords;
if ((byte)nsewBlocks[0] == (byte)BlockData.Blocks.Chest) // North
{
firstCoords = nsewBlockPositions[0];
secondCoords = coords;
}
else if ((byte)nsewBlocks[2] == (byte)BlockData.Blocks.Chest) // East
{
firstCoords = nsewBlockPositions[2];
secondCoords = coords;
}
else if ((byte)nsewBlocks[1] == (byte)BlockData.Blocks.Chest) // South
{
firstCoords = coords;
secondCoords = nsewBlockPositions[1];
}
else// if ((byte)nsewBlocks[3] == (byte)BlockData.Blocks.Chest) // West
{
firstCoords = coords;
secondCoords = nsewBlockPositions[3];
}
return new UniversalCoords[] { firstCoords, secondCoords };
}