本文整理汇总了C#中IWorld.GetBlockID方法的典型用法代码示例。如果您正苦于以下问题:C# IWorld.GetBlockID方法的具体用法?C# IWorld.GetBlockID怎么用?C# IWorld.GetBlockID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IWorld
的用法示例。
在下文中一共展示了IWorld.GetBlockID方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryGrowth
private void TryGrowth(IMultiplayerServer server, Coordinates3D coords, IWorld world)
{
if (world.GetBlockID(coords) != BlockID)
return;
// Find current height of stalk
int height = 0;
for (int y = -MaxGrowHeight; y <= MaxGrowHeight; y++)
{
if (world.GetBlockID(coords + (Coordinates3D.Down * y)) == BlockID)
height++;
}
if (height < MaxGrowHeight)
{
var meta = world.GetMetadata(coords);
meta++;
world.SetMetadata(coords, meta);
var chunk = world.FindChunk(coords);
if (meta == 15)
{
if (world.GetBlockID(coords + Coordinates3D.Up) == 0)
{
world.SetBlockID(coords + Coordinates3D.Up, BlockID);
server.Scheduler.ScheduleEvent("cactus", chunk,
TimeSpan.FromSeconds(MathHelper.Random.Next(MinGrowthSeconds, MaxGrowthSeconds)),
(_server) => TryGrowth(_server, coords + Coordinates3D.Up, world));
}
}
else
{
server.Scheduler.ScheduleEvent("cactus", chunk,
TimeSpan.FromSeconds(MathHelper.Random.Next(MinGrowthSeconds, MaxGrowthSeconds)),
(_server) => TryGrowth(_server, coords, world));
}
}
}
示例2: ValidCactusPosition
public bool ValidCactusPosition(BlockDescriptor descriptor, IBlockRepository repository, IWorld world, bool checkNeighbor = true, bool checkSupport = true)
{
if (checkNeighbor)
{
var adjacent = new Coordinates3D[]
{
descriptor.Coordinates + Coordinates3D.North,
descriptor.Coordinates + Coordinates3D.East,
descriptor.Coordinates + Coordinates3D.South,
descriptor.Coordinates + Coordinates3D.West,
};
foreach (var coords in adjacent)
if (world.GetBlockID(coords) != AirBlock.BlockID)
return false;
}
if (checkSupport)
{
var supportingBlock = repository.GetBlockProvider(world.GetBlockID(descriptor.Coordinates + Coordinates3D.Down));
if ((supportingBlock.ID != CactusBlock.BlockID) && (supportingBlock.ID != SandBlock.BlockID))
return false;
}
return true;
}
示例3: ItemUsedOnBlock
public override void ItemUsedOnBlock(Coordinates3D coordinates, ItemStack item, BlockFace face, IWorld world, IRemoteClient user)
{
var bottom = coordinates + MathHelper.BlockFaceToCoordinates(face);
var top = bottom + Coordinates3D.Up;
if (world.GetBlockID(top) != 0 || world.GetBlockID(bottom) != 0)
return;
DoorFlags direction;
switch (MathHelper.DirectionByRotationFlat(user.Entity.Yaw))
{
case Direction.North:
direction = DoorFlags.Northwest;
break;
case Direction.South:
direction = DoorFlags.Southeast;
break;
case Direction.East:
direction = DoorFlags.Northeast;
break;
default: // Direction.West:
direction = DoorFlags.Southwest;
break;
}
user.Server.BlockUpdatesEnabled = false;
world.SetBlockID(bottom, BlockID);
world.SetMetadata(bottom, (byte)direction);
world.SetBlockID(top, BlockID);
world.SetMetadata(top, (byte)(direction | DoorFlags.Upper));
user.Server.BlockUpdatesEnabled = true;
item.Count--;
user.Inventory[user.SelectedSlot] = item;
}
示例4: ValidPlacement
public static bool ValidPlacement(BlockDescriptor descriptor, IWorld world)
{
var below = world.GetBlockID(descriptor.Coordinates + Coordinates3D.Down);
if (below != SugarcaneBlock.BlockID && below != GrassBlock.BlockID && below != DirtBlock.BlockID)
return false;
var toCheck = new[]
{
Coordinates3D.Down + Coordinates3D.Left,
Coordinates3D.Down + Coordinates3D.Right,
Coordinates3D.Down + Coordinates3D.Backwards,
Coordinates3D.Down + Coordinates3D.Forwards
};
if (below != BlockID)
{
bool foundWater = false;
for (int i = 0; i < toCheck.Length; i++)
{
var id = world.GetBlockID(descriptor.Coordinates + toCheck[i]);
if (id == WaterBlock.BlockID || id == StationaryWaterBlock.BlockID)
{
foundWater = true;
break;
}
}
return foundWater;
}
return true;
}
示例5: HydrationCheckEvent
void HydrationCheckEvent(IMultiplayerServer server, Coordinates3D coords, IWorld world)
{
if (world.GetBlockID(coords) != BlockID)
return;
if (MathHelper.Random.Next(3) == 0)
{
var meta = world.GetMetadata(coords);
if (IsHydrated(coords, world) && meta != 15)
meta++;
else
{
meta--;
if (meta == 0)
{
world.SetBlockID(coords, BlockID);
return;
}
}
world.SetMetadata(coords, meta);
}
var chunk = world.FindChunk(coords);
server.Scheduler.ScheduleEvent("farmland", chunk,
TimeSpan.FromSeconds(UpdateIntervalSeconds),
_server => HydrationCheckEvent(_server, coords, world));
}
示例6: ValidBedPosition
public bool ValidBedPosition(BlockDescriptor descriptor, IBlockRepository repository, IWorld world, bool checkNeighbor = true, bool checkSupport = false)
{
if (checkNeighbor)
{
var other = Coordinates3D.Zero;
switch ((BedDirection)(descriptor.Metadata & 0x3))
{
case BedDirection.East:
other = Coordinates3D.East;
break;
case BedDirection.West:
other = Coordinates3D.West;
break;
case BedDirection.North:
other = Coordinates3D.North;
break;
case BedDirection.South:
other = Coordinates3D.South;
break;
}
if ((descriptor.Metadata & (byte)BedType.Head) == (byte)BedType.Head)
other = -other;
if (world.GetBlockID(descriptor.Coordinates + other) != BedBlock.BlockID)
return false;
}
if (checkSupport)
{
var supportingBlock = repository.GetBlockProvider(world.GetBlockID(descriptor.Coordinates + Coordinates3D.Down));
if (!supportingBlock.Opaque)
return false;
}
return true;
}
示例7: BlockUpdate
public override void BlockUpdate(BlockDescriptor descriptor, BlockDescriptor source, IMultiplayerServer server, IWorld world)
{
bool upper = ((DoorItem.DoorFlags)descriptor.Metadata & DoorItem.DoorFlags.Upper) == DoorItem.DoorFlags.Upper;
var other = upper ? Coordinates3D.Down : Coordinates3D.Up;
if (world.GetBlockID(descriptor.Coordinates + other) != ID)
world.SetBlockID(descriptor.Coordinates, 0);
}
示例8: ItemUsedOnBlock
public override void ItemUsedOnBlock(Coordinates3D coordinates, ItemStack item, BlockFace face, IWorld world, IRemoteClient user)
{
coordinates += MathHelper.BlockFaceToCoordinates(face);
if (world.GetBlockID(coordinates) == AirBlock.BlockID)
{
world.SetBlockID(coordinates, FireBlock.BlockID);
}
}
示例9: GetBoundingBox
public BoundingBox? GetBoundingBox(IWorld world, Coordinates3D coordinates)
{
// TODO: Block-specific bounding boxes
var id = world.GetBlockID(coordinates);
if (id == 0) return null;
var provider = BlockProviders[id];
return provider.BoundingBox;
}
示例10: BlockUpdate
public override void BlockUpdate(BlockDescriptor descriptor, BlockDescriptor source, IMultiplayerServer server, IWorld world)
{
if (world.GetBlockID(descriptor.Coordinates + Coordinates3D.Down) == AirBlock.BlockID)
{
world.SetBlockID(descriptor.Coordinates, AirBlock.BlockID);
server.GetEntityManagerForWorld(world).SpawnEntity(new FallingGravelEntity(descriptor.Coordinates));
}
}
示例11: BlockUpdate
public override void BlockUpdate(BlockDescriptor descriptor, BlockDescriptor source, IMultiplayerServer server, IWorld world)
{
if (world.GetBlockID(descriptor.Coordinates + Coordinates3D.Down) != FarmlandBlock.BlockID)
{
GenerateDropEntity(descriptor, world, server);
world.SetBlockID(descriptor.Coordinates, 0);
}
}
示例12: ScheduleNextEvent
public void ScheduleNextEvent(Coordinates3D coords, IWorld world, IMultiplayerServer server)
{
if (world.GetBlockID(coords) == StillID)
return;
var chunk = world.FindChunk(coords);
server.Scheduler.ScheduleEvent("fluid", chunk,
TimeSpan.FromSeconds(SecondsBetweenUpdates), (_server) =>
AutomataUpdate(_server, world, coords));
}
示例13: ItemUsedOnBlock
public override void ItemUsedOnBlock(Coordinates3D coordinates, ItemStack item, BlockFace face, IWorld world, IRemoteClient user)
{
if (world.GetBlockID(coordinates) == FarmlandBlock.BlockID)
{
world.SetBlockID(coordinates + MathHelper.BlockFaceToCoordinates(face), CropsBlock.BlockID);
world.BlockRepository.GetBlockProvider(CropsBlock.BlockID).BlockPlaced(
new BlockDescriptor { Coordinates = coordinates }, face, world, user);
}
}
示例14: ItemUsedOnBlock
public override void ItemUsedOnBlock(Coordinates3D coordinates, ItemStack item, BlockFace face, IWorld world, IRemoteClient user)
{
coordinates += MathHelper.BlockFaceToCoordinates(face);
if (item.ID == ItemID) // Empty bucket
{
var block = world.GetBlockID(coordinates);
if (block == WaterBlock.BlockID || block == StationaryWaterBlock.BlockID)
{
var meta = world.GetMetadata(coordinates);
if (meta == 0) // Is source block?
{
user.Inventory[user.SelectedSlot] = new ItemStack(WaterBucketItem.ItemID);
world.SetBlockID(coordinates, 0);
}
}
else if (block == LavaBlock.BlockID || block == StationaryLavaBlock.BlockID)
{
var meta = world.GetMetadata(coordinates);
if (meta == 0) // Is source block?
{
user.Inventory[user.SelectedSlot] = new ItemStack(LavaBucketItem.ItemID);
world.SetBlockID(coordinates, 0);
}
}
}
else
{
var provider = user.Server.BlockRepository.GetBlockProvider(world.GetBlockID(coordinates));
if (!provider.Opaque)
{
if (RelevantBlockType != null)
{
var blockType = RelevantBlockType.Value;
user.Server.BlockUpdatesEnabled = false;
world.SetBlockID(coordinates, blockType);
world.SetMetadata(coordinates, 0); // Source block
user.Server.BlockUpdatesEnabled = true;
var liquidProvider = world.BlockRepository.GetBlockProvider(blockType);
liquidProvider.BlockPlaced(new BlockDescriptor { Coordinates = coordinates }, face, world, user);
}
user.Inventory[user.SelectedSlot] = new ItemStack(BucketItem.ItemID);
}
}
}
示例15: ItemUsedOnBlock
public override void ItemUsedOnBlock(Coordinates3D coordinates, ItemStack item, BlockFace face, IWorld world, IRemoteClient user)
{
var id = world.GetBlockID(coordinates);
if (id == DirtBlock.BlockID || id == GrassBlock.BlockID)
{
world.SetBlockID(coordinates, FarmlandBlock.BlockID);
user.Server.BlockRepository.GetBlockProvider(FarmlandBlock.BlockID).BlockPlaced(
new BlockDescriptor { Coordinates = coordinates }, face, world, user);
}
}