本文整理汇总了C#中IWorld.SetBlockData方法的典型用法代码示例。如果您正苦于以下问题:C# IWorld.SetBlockData方法的具体用法?C# IWorld.SetBlockData怎么用?C# IWorld.SetBlockData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IWorld
的用法示例。
在下文中一共展示了IWorld.SetBlockData方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ItemUsedOnBlock
public override void ItemUsedOnBlock(Coordinates3D coordinates, ItemStack item, BlockFace face, IWorld world, IRemoteClient user)
{
coordinates += MathHelper.BlockFaceToCoordinates(face);
var head = coordinates;
var foot = coordinates;
BedBlock.BedDirection direction = BedBlock.BedDirection.North;
switch (MathHelper.DirectionByRotationFlat(user.Entity.Yaw))
{
case Direction.North:
head += Coordinates3D.North;
direction = BedBlock.BedDirection.North;
break;
case Direction.South:
head += Coordinates3D.South;
direction = BedBlock.BedDirection.South;
break;
case Direction.East:
head += Coordinates3D.East;
direction = BedBlock.BedDirection.East;
break;
case Direction.West:
head += Coordinates3D.West;
direction = BedBlock.BedDirection.West;
break;
}
var bedProvider = (BedBlock)user.Server.BlockRepository.GetBlockProvider(BedBlock.BlockID);
if (!bedProvider.ValidBedPosition(new BlockDescriptor { Coordinates = head },
user.Server.BlockRepository, user.World, false, true) ||
!bedProvider.ValidBedPosition(new BlockDescriptor { Coordinates = foot },
user.Server.BlockRepository, user.World, false, true))
{
return;
}
user.Server.BlockUpdatesEnabled = false;
world.SetBlockData(head, new BlockDescriptor
{ ID = BedBlock.BlockID, Metadata = (byte)((byte)direction | (byte)BedBlock.BedType.Head) });
world.SetBlockData(foot, new BlockDescriptor
{ ID = BedBlock.BlockID, Metadata = (byte)((byte)direction | (byte)BedBlock.BedType.Foot) });
user.Server.BlockUpdatesEnabled = true;
item.Count--;
user.Inventory[user.SelectedSlot] = item;
}
示例2: ItemUsedOnBlock
public override void ItemUsedOnBlock(Coordinates3D coordinates, ItemStack item, BlockFace face, IWorld world, IRemoteClient user)
{
coordinates += MathHelper.BlockFaceToCoordinates(face);
var old = world.GetBlockData(coordinates);
byte[] overwritable =
{
AirBlock.BlockID,
WaterBlock.BlockID,
StationaryWaterBlock.BlockID,
LavaBlock.BlockID,
StationaryLavaBlock.BlockID
};
if (overwritable.Any(b => b == old.ID))
{
var data = world.GetBlockData(coordinates);
data.ID = ID;
data.Metadata = (byte)item.Metadata;
BlockPlaced(data, face, world, user);
if (!IsSupported(world.GetBlockData(coordinates), user.Server, world))
world.SetBlockData(coordinates, old);
else
{
item.Count--;
user.Inventory[user.SelectedSlot] = item;
}
}
}
示例3: BlockPlaced
public override void BlockPlaced(BlockDescriptor descriptor, BlockFace face, IWorld world, IRemoteClient user)
{
TorchDirection[] preferredDirections =
{
TorchDirection.West, TorchDirection.East,
TorchDirection.North, TorchDirection.South,
TorchDirection.Ground
};
TorchDirection direction;
switch (face)
{
case BlockFace.PositiveZ:
direction = TorchDirection.South;
break;
case BlockFace.NegativeZ:
direction = TorchDirection.North;
break;
case BlockFace.PositiveX:
direction = TorchDirection.East;
break;
case BlockFace.NegativeX:
direction = TorchDirection.West;
break;
default:
direction = TorchDirection.Ground;
break;
}
int i = 0;
descriptor.Metadata = (byte)direction;
while (!IsSupported(descriptor, user.Server, world) && i < preferredDirections.Length)
{
direction = preferredDirections[i++];
descriptor.Metadata = (byte)direction;
}
world.SetBlockData(descriptor.Coordinates, descriptor);
}
示例4: ItemUsedOnBlock
public virtual void ItemUsedOnBlock(Coordinates3D coordinates, ItemStack item, BlockFace face, IWorld world, IRemoteClient user)
{
coordinates += MathHelper.BlockFaceToCoordinates(face);
var old = world.GetBlockData(coordinates);
byte[] overwritable =
{
AirBlock.BlockID,
WaterBlock.BlockID,
StationaryWaterBlock.BlockID,
LavaBlock.BlockID,
StationaryLavaBlock.BlockID
};
if (overwritable.Any(b => b == old.ID))
{
// Test for entities
var em = user.Server.GetEntityManagerForWorld(world);
var entities = em.EntitiesInRange(coordinates, 2);
var box = new BoundingBox(coordinates, coordinates + Vector3.One);
foreach (var entity in entities)
{
var aabb = entity as IAABBEntity;
if (aabb != null && !(entity is ItemEntity))
{
if (aabb.BoundingBox.Intersects(box) && false) // TODO: Figure out
return;
}
var player = entity as PlayerEntity; // Players do not implement IAABBEntity
if (player != null)
{
if (new BoundingBox(player.Position, player.Position + player.Size)
.Intersects(box) && false)
return;
}
}
// Place block
world.SetBlockID(coordinates, ID);
world.SetMetadata(coordinates, (byte)item.Metadata);
BlockPlaced(world.GetBlockData(coordinates), face, world, user);
if (!IsSupported(world.GetBlockData(coordinates), user.Server, world))
world.SetBlockData(coordinates, old);
else
{
item.Count--;
user.Inventory[user.SelectedSlot] = item;
}
}
}
示例5: ItemUsedOnBlock
public virtual void ItemUsedOnBlock(Coordinates3D coordinates, ItemStack item, BlockFace face, IWorld world, IRemoteClient user)
{
var old = world.GetBlockData(coordinates);
if (!Overwritable.Any(b => b == old.ID))
{
coordinates += MathHelper.BlockFaceToCoordinates(face);
old = world.GetBlockData(coordinates);
if (!Overwritable.Any(b => b == old.ID))
return;
}
// Test for entities
if (BoundingBox.HasValue)
{
var em = user.Server.GetEntityManagerForWorld(world);
var entities = em.EntitiesInRange(coordinates, 3);
var box = new BoundingBox(BoundingBox.Value.Min + (Vector3)coordinates,
BoundingBox.Value.Max + (Vector3)coordinates);
foreach (var entity in entities)
{
var aabb = entity as IAABBEntity;
if (aabb != null && !(entity is ItemEntity))
{
if (aabb.BoundingBox.Intersects(box))
return;
}
var player = entity as PlayerEntity; // Players do not implement IAABBEntity
if (player != null)
{
if (new BoundingBox(player.Position, player.Position + player.Size)
.Intersects(box))
return;
}
}
}
// Place block
world.SetBlockID(coordinates, ID);
world.SetMetadata(coordinates, (byte)item.Metadata);
BlockPlaced(world.GetBlockData(coordinates), face, world, user);
if (!IsSupported(world.GetBlockData(coordinates), user.Server, world))
world.SetBlockData(coordinates, old);
else
{
item.Count--;
user.Inventory[user.SelectedSlot] = item;
}
}