当前位置: 首页>>代码示例>>C#>>正文


C# IWorld.SetBlockData方法代码示例

本文整理汇总了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;
 }
开发者ID:Zoxive,项目名称:TrueCraft,代码行数:42,代码来源:BedItem.cs

示例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;
                }
            }
        }
开发者ID:Luigifan,项目名称:TrueCraft,代码行数:29,代码来源:TorchBlock.cs

示例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);
 }
开发者ID:Luigifan,项目名称:TrueCraft,代码行数:36,代码来源:TorchBlock.cs

示例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;
                }
            }
        }
开发者ID:zevipa,项目名称:TrueCraft,代码行数:50,代码来源:BlockProvider.cs

示例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;
            }
        }
开发者ID:Zoxive,项目名称:TrueCraft,代码行数:50,代码来源:BlockProvider.cs


注:本文中的IWorld.SetBlockData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。