本文整理汇总了C#中UniversalCoords类的典型用法代码示例。如果您正苦于以下问题:C# UniversalCoords类的具体用法?C# UniversalCoords怎么用?C# UniversalCoords使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UniversalCoords类属于命名空间,在下文中一共展示了UniversalCoords类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StructBlock
public StructBlock(int worldX, int worldY, int worldZ, byte type, byte metaData, WorldManager world)
{
Type = type;
Coords = UniversalCoords.FromWorld(worldX, worldY, worldZ);
MetaData = metaData;
World = world;
}
示例2: fixed
internal unsafe byte this[UniversalCoords coords]
{
get
{
fixed (byte* types = Types)
return types[coords.SectionPackedCoords];
}
set
{
fixed (byte* types = Types)
{
byte oldValue = types[coords.SectionPackedCoords];
if (oldValue != value)
{
//if (value != (byte)BlockData.Blocks.Air)
types[coords.SectionPackedCoords] = value;
if (value == (byte)BlockData.Blocks.Air)
{
if (_NonAirBlocks > 0)
--_NonAirBlocks;
}
else
++_NonAirBlocks;
}
}
}
}
示例3: Open
/// <summary>
/// Opens the Workbench and specifies where items should be dropped if exiting the workbench with items still in it.
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="z"></param>
public virtual void Open(UniversalCoords coords)
{
_useProvidedDropCoordinates = true;
_DropCoords = coords;
this.Open();
}
示例4: Interact
public void Interact(EntityBase entity, StructBlock block)
{
Player player = entity as Player;
if (player == null)
return;
if (player.CurrentInterface != null)
return;
byte? blockId = block.World.GetBlockId(block.Coords);
if (blockId == null || !BlockHelper.Instance((byte)blockId).IsAir)
{
// Cannot open a chest if no space is above it
return;
}
Chunk chunk = GetBlockChunk(block);
// Double chest?
if (chunk.IsNSEWTo(block.Coords, block.Type))
{
// 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;
chunk.ForNSEW(block.Coords, (uc) =>
{
nsewBlocks[nsewCount] = (BlockData.Blocks)block.World.GetBlockId(uc);
nsewBlockPositions[nsewCount] = uc;
nsewCount++;
});
if ((byte)nsewBlocks[0] == block.Type) // North
{
player.CurrentInterface = new LargeChestInterface(block.World, nsewBlockPositions[0], block.Coords);
}
else if ((byte)nsewBlocks[2] == block.Type) // East
{
player.CurrentInterface = new LargeChestInterface(block.World, nsewBlockPositions[2], block.Coords);
}
else if ((byte)nsewBlocks[1] == block.Type) // South
{
player.CurrentInterface = new LargeChestInterface(block.World, block.Coords, nsewBlockPositions[1]);
}
else if ((byte)nsewBlocks[3] == block.Type) // West
{
player.CurrentInterface = new LargeChestInterface(block.World, block.Coords, nsewBlockPositions[3]);
}
}
else
{
player.CurrentInterface = new SmallChestInterface(block.World, block.Coords);
}
player.CurrentInterface.Associate(player);
player.CurrentInterface.Open();
}
示例5: BlockPathWeight
protected override double BlockPathWeight(UniversalCoords coords)
{
if (this.World.GetBlockId(coords.WorldX, coords.WorldY - 1, coords.WorldZ) == (byte)BlockData.Blocks.Grass)
{
return 10.0;
}
else
{
return this.World.GetBlockLightBrightness(coords) - 0.5; // stay out of lower half of brightness spectrum
}
}
示例6: Remove
public bool Remove(UniversalCoords coords)
{
Chunk chunk;
Interlocked.Increment(ref Changes);
bool result = Chunks.TryRemove(coords.ChunkPackedCoords, out chunk);
if(result)
chunk.Dispose();
return result;
}
示例7: 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;
}
示例8:
public Chunk this[UniversalCoords coords]
{
get
{
Chunk chunk;
Chunks.TryGetValue(coords.ChunkPackedCoords, out chunk);
return chunk;
}
private set
{
Chunks.AddOrUpdate(coords.ChunkPackedCoords, value, (key, oldValue) => value);
}
}
示例9: Initialize
public virtual void Initialize(WorldManager world, UniversalCoords coords)
{
World = world;
Coords = coords;
Slots = new ItemInventory[SlotsCount];
DataFile = string.Format("x{0}y{1}z{2}.dat", Coords.WorldX, Coords.WorldY, Coords.WorldZ);
string chunkFolder = string.Format("x{0}z{1}", Coords.ChunkX, Coords.ChunkZ);
ContainerFolder = Path.Combine(DataPath, chunkFolder);
if (!Directory.Exists(ContainerFolder))
{
Directory.CreateDirectory(ContainerFolder);
}
Load();
}
示例10: CheckOffset
private int CheckOffset(UniversalCoords start, Size size)
{
for (int x = start.WorldX; x < start.WorldX + size.Width; x++)
{
for (int y = start.WorldY; y < start.WorldY + size.Height; y++)
{
for (int z = start.WorldZ; z < start.WorldZ + size.Width; z++)
{
StructBlock block = World.GetBlock(x, y, z);
if (block.Type <= 0)
continue;
BlockBase blockClass = BlockHelper.Instance(block.Type);
if (blockClass is BlockBaseDoor)
{
if (!((BlockBaseDoor)blockClass).IsOpen(block))
{
return 0;
}
continue;
}
if (blockClass.IsSolid)
{
return 0;
}
if (blockClass.IsLiquid)
{
if (!blockClass.IsOpaque) // Water
{
return -1;
}
else // Lava
{
return -2;
}
}
}
}
}
return 1;
}
示例11: DropItem
/// <summary>
/// Drops an item at the given location.
/// </summary>
/// <param name="world">The world in which the coordinates reside.</param>
/// <param name="coords">The target coordinate</param>
/// <param name="stack">The stack to be dropped</param>
/// <param name="velocity">An optional velocity (the velocity will be clamped to -0.4 and 0.4 on each axis)</param>
/// <returns>The entity ID of the item drop.</returns>
public int DropItem(IWorldManager world, UniversalCoords coords, IItemInventory stack, Vector3 velocity = new Vector3())
{
if (ItemHelper.IsVoid(stack))
return -1;
int entityId = AllocateEntity();
bool sendVelocity = false;
if (velocity != Vector3.Origin)
{
velocity = new Vector3(velocity.X.Clamp(-0.4, 0.4), velocity.Y.Clamp(-0.4, 0.4), velocity.Z.Clamp(-0.4, 0.4));
sendVelocity = true;
}
AddEntity(new ItemEntity(this, entityId)
{
World = world as WorldManager,
Position = new AbsWorldCoords(new Vector3(coords.WorldX + 0.5, coords.WorldY, coords.WorldZ + 0.5)), // Put in the middle of the block (ignoring Y)
ItemId = stack.Type,
Count = stack.Count,
Velocity = velocity,
Durability = stack.Durability
});
if (sendVelocity)
SendPacketToNearbyPlayers(world as WorldManager, coords, new EntityVelocityPacket { EntityId = entityId, VelocityX = (short)(velocity.X * 8000), VelocityY = (short)(velocity.Y * 8000), VelocityZ = (short)(velocity.Z * 8000) });
return entityId;
}
示例12: GetNearbyLivings
public IEnumerable<ILivingEntity> GetNearbyLivings(IWorldManager world, UniversalCoords coords)
{
return GetNearbyLivingsInternal(world as WorldManager, coords);
}
示例13: foreach
/*public IEnumerable<IEntityBase> GetNearbyLivings(IWorldManager world, AbsWorldCoords coords)
{
int radius = ChraftConfig.SightRadius << 4;
foreach (EntityBase entity in GetEntities())
{
if (!(entity is LivingEntity))
continue;
if (entity.World == world && Math.Abs(coords.X - entity.Position.X) <= radius && Math.Abs(coords.Y - entity.Position.Y) <= radius && Math.Abs(coords.Z - entity.Position.Z) <= radius)
yield return (entity as LivingEntity);
}
}*/
internal IEnumerable<LivingEntity> GetNearbyLivingsInternal(WorldManager world, UniversalCoords coords)
{
int radius = ChraftConfig.MaxSightRadius;
foreach (EntityBase entity in GetEntities())
{
if (!(entity is LivingEntity))
continue;
int entityChunkX = (int)Math.Floor(entity.Position.X) >> 4;
int entityChunkZ = (int)Math.Floor(entity.Position.Z) >> 4;
if (entity.World == world && Math.Abs(coords.ChunkX - entityChunkX) <= radius && Math.Abs(coords.ChunkZ - entityChunkZ) <= radius)
yield return (entity as LivingEntity);
}
}
示例14: GetNearbyEntitiesDict
/// <summary>
/// Yields an enumerable of nearby entities, including players. Thread-safe.
/// </summary>
/// <param name="world">The world containing the coordinates.</param>
/// <param name="x">The center X coordinate.</param>
/// <param name="y">The center Y coordinate.</param>
/// <param name="z">The center Z coordinate.</param>
/// <returns>A lazy enumerable of nearby entities.</returns>
public Dictionary<int, IEntityBase> GetNearbyEntitiesDict(IWorldManager world, UniversalCoords coords)
{
int radius = ChraftConfig.MaxSightRadius;
Dictionary<int, IEntityBase> dict = new Dictionary<int, IEntityBase>();
foreach (EntityBase e in GetEntities())
{
int entityChunkX = (int)Math.Floor(e.Position.X) >> 4;
int entityChunkZ = (int)Math.Floor(e.Position.Z) >> 4;
if (e.World == world && Math.Abs(coords.ChunkX - entityChunkX) <= radius && Math.Abs(coords.ChunkZ - entityChunkZ) <= radius)
{
dict.Add(e.EntityId, e);
}
}
return dict;
}
示例15: SetSkyLight
public void SetSkyLight(UniversalCoords coords, byte value)
{
SkyLight.setNibble(coords.BlockPackedCoords, value);
}