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


C# IWorld.GetMetadata方法代码示例

本文整理汇总了C#中IWorld.GetMetadata方法的典型用法代码示例。如果您正苦于以下问题:C# IWorld.GetMetadata方法的具体用法?C# IWorld.GetMetadata怎么用?C# IWorld.GetMetadata使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IWorld的用法示例。


在下文中一共展示了IWorld.GetMetadata方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

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

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

示例3: BlockRightClicked

 public override bool BlockRightClicked(BlockDescriptor descriptor, BlockFace face, IWorld world, IRemoteClient user)
 {
     bool upper = ((DoorItem.DoorFlags)descriptor.Metadata & DoorItem.DoorFlags.Upper) == DoorItem.DoorFlags.Upper;
     var other = upper ? Coordinates3D.Down : Coordinates3D.Up;
     var otherMeta = world.GetMetadata(descriptor.Coordinates + other);
     world.SetMetadata(descriptor.Coordinates, (byte)(descriptor.Metadata ^ (byte)DoorItem.DoorFlags.Open));
     world.SetMetadata(descriptor.Coordinates + other, (byte)(otherMeta ^ (byte)DoorItem.DoorFlags.Open));
     return false;
 }
开发者ID:Zoxive,项目名称:TrueCraft,代码行数:9,代码来源:DoorBlock.cs

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

示例5: GrowBlock

 private void GrowBlock(IMultiplayerServer server, IWorld world, Coordinates3D coords)
 {
     if (world.GetBlockID(coords) != BlockID)
         return;
     var meta = world.GetMetadata(coords);
     meta++;
     world.SetMetadata(coords, meta);
     if (meta < 7)
     {
         var chunk = world.FindChunk(coords);
         server.Scheduler.ScheduleEvent("crops",
             chunk, TimeSpan.FromSeconds(MathHelper.Random.Next(30, 60)),
            (_server) => GrowBlock(_server, world, coords));
     }
 }
开发者ID:Zoxive,项目名称:TrueCraft,代码行数:15,代码来源:CropsBlock.cs

示例6: DoUpdate

        public void DoUpdate(IMultiplayerServer server, IWorld world, BlockDescriptor descriptor)
        {
            var down = descriptor.Coordinates + Coordinates3D.Down;

            var current = world.GetBlockID(descriptor.Coordinates);
            if (current != FireBlock.BlockID && current != LavaBlock.BlockID && current != StationaryLavaBlock.BlockID)
                return;

            // Decay
            var meta = world.GetMetadata(descriptor.Coordinates);
            meta++;
            if (meta == 0xE)
            {
                if (!world.IsValidPosition(down) || world.GetBlockID(down) != NetherrackBlock.BlockID)
                {
                    world.SetBlockID(descriptor.Coordinates, AirBlock.BlockID);
                    return;
                }
            }
            world.SetMetadata(descriptor.Coordinates, meta);

            if (meta > 9)
            {
                var pick = AdjacentBlocks[meta % AdjacentBlocks.Length];
                var provider = BlockRepository
                    .GetBlockProvider(world.GetBlockID(pick + descriptor.Coordinates));
                if (provider.Flammable)
                    world.SetBlockID(pick + descriptor.Coordinates, AirBlock.BlockID);
            }

            // Spread
            DoSpread(server, world, descriptor);

            // Schedule next event
            ScheduleUpdate(server, world, descriptor);
        }
开发者ID:Zoxive,项目名称:TrueCraft,代码行数:36,代码来源:FireBlock.cs

示例7: 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);
     }
     server.Scheduler.ScheduleEvent(DateTime.Now.AddSeconds(UpdateIntervalSeconds), (_server) => HydrationCheckEvent(_server, coords, world));
 }
开发者ID:Luigifan,项目名称:TrueCraft,代码行数:22,代码来源:FarmlandBlock.cs

示例8: 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 = -3; y <= 3; y++)
     {
         if (world.GetBlockID(coords + (Coordinates3D.Down * y)) == BlockID)
             height++;
     }
     if (height < 3)
     {
         var meta = world.GetMetadata(coords);
         meta++;
         world.SetMetadata(coords, meta);
         if (meta == 15)
         {
             world.SetBlockID(coords + Coordinates3D.Up, BlockID);
             server.Scheduler.ScheduleEvent(DateTime.Now.AddSeconds(MathHelper.Random.Next(MinGrowthSeconds, MaxGrowthSeconds)),
                 (_server) => TryGrowth(_server, coords + Coordinates3D.Up, world));
         }
         else
         {
             server.Scheduler.ScheduleEvent(DateTime.Now.AddSeconds(MathHelper.Random.Next(MinGrowthSeconds, MaxGrowthSeconds)),
                 (_server) => TryGrowth(_server, coords, world));
         }
     }
 }
开发者ID:Luigifan,项目名称:TrueCraft,代码行数:29,代码来源:SugarcaneBlock.cs

示例9: GrowBlock

 private void GrowBlock(IMultiplayerServer server, IWorld world, Coordinates3D coords)
 {
     if (world.GetBlockID(coords) != BlockID)
         return;
     var meta = world.GetMetadata(coords);
     meta++;
     world.SetMetadata(coords, meta);
     if (meta < 7)
     {
         server.Scheduler.ScheduleEvent(DateTime.Now.AddSeconds(MathHelper.Random.Next(30, 60)),
            (_server) => GrowBlock(_server, world, coords));
     }
 }
开发者ID:Luigifan,项目名称:TrueCraft,代码行数:13,代码来源:CropsBlock.cs

示例10: DetermineOutwardFlow

        /// <summary>
        /// Produces a list of outward flow targets that this block may flow towards.
        /// </summary>
        protected LiquidFlow[] DetermineOutwardFlow(IWorld world, Coordinates3D coords)
        {
            // The maximum distance we will search for lower ground to flow towards
            const int dropCheckDistance = 5;

            var outwardFlow = new List<LiquidFlow>(5);

            var currentLevel = world.GetMetadata(coords);
            var blockBelow = world.BlockRepository.GetBlockProvider(world.GetBlockID(coords + Coordinates3D.Down));
            if (blockBelow.Hardness == 0 && blockBelow.ID != FlowingID && blockBelow.ID != StillID)
            {
                outwardFlow.Add(new LiquidFlow(coords + Coordinates3D.Down, 1));
                if (currentLevel != 0)
                    return outwardFlow.ToArray();
            }

            if (currentLevel < MaximumFluidDepletion)
            {
                // This code is responsible for seeking out candidates for flowing towards.
                // Fluid in Minecraft will flow in the direction of the nearest drop-off where
                // there is at least one block removed on the Y axis.
                // It will flow towards several equally strong candidates at once.

                var candidateFlowPoints = new List<Coordinates3D>(4);
                var furthestPossibleCandidate = new Coordinates3D(x: dropCheckDistance + 1, z: dropCheckDistance + 1) + Coordinates3D.Down;

                var nearestCandidate = furthestPossibleCandidate;
                for (int x = -dropCheckDistance; x < dropCheckDistance; x++)
                {
                    for (int z = -dropCheckDistance; z < dropCheckDistance; z++)
                    {
                        if (Math.Abs(z) + Math.Abs(x) > dropCheckDistance)
                            continue;
                        var check = new Coordinates3D(x: x, z: z) + Coordinates3D.Down;
                        var c = world.BlockRepository.GetBlockProvider(world.GetBlockID(check + coords));
                        if (c.Hardness == 0)
                        {
                            if (!LineOfSight(world, check + coords, coords))
                                continue;
                            if (coords.DistanceTo(check + coords) == coords.DistanceTo(nearestCandidate + coords))
                                candidateFlowPoints.Add(check);
                            if (coords.DistanceTo(check + coords) < coords.DistanceTo(nearestCandidate + coords))
                            {
                                candidateFlowPoints.Clear();
                                nearestCandidate = check;
                            }
                        }
                    }
                }
                if (nearestCandidate == furthestPossibleCandidate)
                {
                    candidateFlowPoints.Add(new Coordinates3D(x: -dropCheckDistance - 1, z: dropCheckDistance + 1) + Coordinates3D.Down);
                    candidateFlowPoints.Add(new Coordinates3D(x: dropCheckDistance + 1, z: -dropCheckDistance - 1) + Coordinates3D.Down);
                    candidateFlowPoints.Add(new Coordinates3D(x: -dropCheckDistance - 1, z: -dropCheckDistance - 1) + Coordinates3D.Down);
                }
                candidateFlowPoints.Add(nearestCandidate);

                // For each candidate, determine if we are actually capable of flowing towards it.
                // We are able to flow through blocks with a hardness of zero, but no others. We are
                // not able to flow through established fluid blocks.
                for (int i = 0; i < candidateFlowPoints.Count; i++)
                {
                    var location = candidateFlowPoints[i];
                    location.Clamp(1);

                    var xCoordinateCheck = new Coordinates3D(x: location.X) + coords;
                    var zCoordinateCheck = new Coordinates3D(z: location.Z) + coords;

                    var xID = world.BlockRepository.GetBlockProvider(world.GetBlockID(xCoordinateCheck));
                    var zID = world.BlockRepository.GetBlockProvider(world.GetBlockID(zCoordinateCheck));

                    if (xID.Hardness == 0 && xID.ID != FlowingID && xID.ID != StillID)
                    {
                        if (outwardFlow.All(f => f.TargetBlock != xCoordinateCheck))
                            outwardFlow.Add(new LiquidFlow(xCoordinateCheck, (byte)(currentLevel + 1)));
                    }

                    if (zID.Hardness == 0 && zID.ID != FlowingID && zID.ID != StillID)
                    {
                        if (outwardFlow.All(f => f.TargetBlock != zCoordinateCheck))
                            outwardFlow.Add(new LiquidFlow(zCoordinateCheck, (byte)(currentLevel + 1)));
                    }
                }

                // Occasionally, there are scenarios where the nearest candidate hole is not acceptable, but
                // there is space immediately next to the block. We should fill that space.
                if (outwardFlow.Count == 0 && blockBelow.ID != FlowingID && blockBelow.ID != StillID)
                {
                    for (int i = 0; i < Neighbors.Length; i++)
                    {
                        var b = world.BlockRepository.GetBlockProvider(world.GetBlockID(coords + Neighbors[i]));
                        if (b.Hardness == 0 && b.ID != StillID && b.ID != FlowingID)
                            outwardFlow.Add(new LiquidFlow(Neighbors[i] + coords, (byte)(currentLevel + 1)));
                    }
                }
            }
            return outwardFlow.ToArray();
//.........这里部分代码省略.........
开发者ID:Zoxive,项目名称:TrueCraft,代码行数:101,代码来源:FluidBlock.cs

示例11: DetermineInwardFlow

 /// <summary>
 /// Examines neighboring blocks and determines the new fluid level that this block should adopt.
 /// </summary>
 protected byte DetermineInwardFlow(IWorld world, Coordinates3D coords)
 {
     var currentLevel = world.GetMetadata(coords);
     var up = world.GetBlockID(coords + Coordinates3D.Up);
     if (up == FlowingID || up == StillID) // Check for fluid above us
         return currentLevel;
     else
     {
         if (currentLevel != 0)
         {
             byte highestNeighboringFluid = 15;
             int neighboringSourceBlocks = 0;
             for (int i = 0; i < Neighbors.Length; i++)
             {
                 var nId = world.GetBlockID(coords + Neighbors[i]);
                 if (nId == FlowingID || nId == StillID)
                 {
                     var neighborLevel = world.GetMetadata(coords + Neighbors[i]);
                     if (neighborLevel < highestNeighboringFluid)
                         highestNeighboringFluid = neighborLevel;
                     if (neighborLevel == 0)
                         neighboringSourceBlocks++;
                 }
             }
             if (neighboringSourceBlocks >= 2 && AllowSourceCreation)
                 currentLevel = 0;
             if (highestNeighboringFluid > 0)
                 currentLevel = (byte)(highestNeighboringFluid + 1);
         }
     }
     return currentLevel;
 }
开发者ID:Zoxive,项目名称:TrueCraft,代码行数:35,代码来源:FluidBlock.cs

示例12: DoAutomata

        public bool DoAutomata(IMultiplayerServer server, IWorld world, Coordinates3D coords)
        {
            var previousLevel = world.GetMetadata(coords);

            var inward = DetermineInwardFlow(world, coords);
            var outward = DetermineOutwardFlow(world, coords);

            if (outward.Length == 1 && outward[0].TargetBlock == coords + Coordinates3D.Down)
            {
                // Exit early if we have placed a fluid block beneath us (and we aren't a source block)
                FlowOutward(world, outward[0], server);
                if (previousLevel != 0)
                    return true;
            }

            // Process inward flow
            if (inward > MaximumFluidDepletion)
            {
                world.SetBlockID(coords, 0);
                return true;
            }
            world.SetMetadata(coords, inward);
            if (inward == 0 && previousLevel != 0)
            {
                // Exit early if we have become a source block
                return true;
            }

            // Process outward flow
            for (int i = 0; i < outward.Length; i++)
                FlowOutward(world, outward[i], server);
            // Set our block to still fluid if we are done spreading.
            if (outward.Length == 0 && inward == previousLevel)
            {
                world.SetBlockID(coords, StillID);
                return false;
            }
            return true;
        }
开发者ID:Zoxive,项目名称:TrueCraft,代码行数:39,代码来源:FluidBlock.cs


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