예제 #1
0
파일: Block.cs 프로젝트: pdelvo/Craft.Net
 public override void OnItemUsed(World world, Vector3 clickedBlock, Vector3 clickedSide, Vector3 cursorPosition, Entity usedBy)
 {
     var clicked = world.GetBlock(clickedBlock);
     if (clicked.OnBlockRightClicked(clickedBlock, clickedSide, cursorPosition, world, usedBy))
     {
         if (OnBlockPlaced(world, clickedBlock + clickedSide, clickedBlock, clickedSide, cursorPosition, usedBy))
         {
             if ((clickedBlock + clickedSide).Y >= 0 && (clickedBlock + clickedSide).Y <= Chunk.Height)
                 world.SetBlock(clickedBlock + clickedSide, this);
         }
     }
 }
예제 #2
0
        /// <summary>
        /// Spawns a bolt of lightning in the given world
        /// at the given position.
        /// </summary>
        public void SpawnLightning(World world, Vector3 position)
        {
            var chunk = world.GetChunk(World.WorldToChunkCoordinates(position));
            var block = World.FindBlockPosition(position);
            int y = chunk.GetHeight((byte)block.X, (byte)block.Z) + 1;

            var strike = new Vector3(position.X, y, position.Z);
            if (world.GetBlock(strike + Vector3.Down).Transparency == Transparency.Opaque)
                world.SetBlock(strike, new FireBlock());

            var clients = Server.EntityManager.GetClientsInWorld(world);
            foreach (var minecraftClient in clients)
                minecraftClient.SendPacket(new SpawnGlobalEntityPacket(EntityManager.nextEntityId++, 1,
                    (int)strike.X, (int)strike.Y, (int)strike.Z));
        }
예제 #3
0
파일: Block.cs 프로젝트: cpancake/Craft.Net
 public override void OnItemUsedOnBlock(World world, Vector3 clickedBlock, Vector3 clickedSide,
                                        Vector3 cursorPosition, Entity usedBy)
 {
     var clicked = world.GetBlock(clickedBlock);
     var player = usedBy as PlayerEntity;
     if (player.GameMode != GameMode.Creative)
     {
         var item = player.Inventory[player.SelectedSlot];
         player.Inventory[player.SelectedSlot] = new ItemStack(item.Id,
             (sbyte)(item.Count - 1), item.Metadata, item.Nbt);
     }
     if (clicked.OnBlockRightClicked(clickedBlock, clickedSide, cursorPosition, world, usedBy))
     {
         if (OnBlockPlaced(world, clickedBlock + clickedSide, clickedBlock, clickedSide, cursorPosition, usedBy))
         {
             if ((clickedBlock + clickedSide).Y >= 0 && (clickedBlock + clickedSide).Y <= Chunk.Height)
                 world.SetBlock(clickedBlock + clickedSide, this);
         }
     }
 }
예제 #4
0
 /// <summary>
 /// Called when a block update occurs. Default handler will handle
 /// common activities such as destroying blocks that lose support -
 /// make sure you call it if you don't want to lose this functionality.
 /// </summary>
 public virtual void BlockUpdate(World world, Vector3 updatedBlock, Vector3 modifiedBlock)
 {
     if (RequiresSupport)
     {
         // Ensure that it hasn't lost support
         var block = world.GetBlock(updatedBlock + SupportDirection);
         if (block is AirBlock)
         {
             world.SetBlock(updatedBlock, new AirBlock());
             ItemStack[] drops;
             bool        spawnEntity = GetDrop(null, out drops);
             if (spawnEntity)
             {
                 foreach (var drop in drops)
                 {
                     world.OnSpawnEntity(new ItemEntity(updatedBlock + new Vector3(0.5), drop));
                 }
             }
         }
     }
 }
예제 #5
0
 public virtual void OnBlockMined(World world, Vector3 destroyedBlock, PlayerEntity player)
 {
     if (Hardness != -1)
     {
         var slot = player.Inventory[player.SelectedSlot];
         world.SetBlock(destroyedBlock, new AirBlock());
         if (CanHarvest(slot.AsItem() as ToolItem) && player.GameMode != GameMode.Creative)
         {
             ItemStack[] drops;
             bool        spawnEntity = GetDrop(slot.AsItem() as ToolItem, out drops);
             if (spawnEntity)
             {
                 foreach (var drop in drops)
                 {
                     var entity = new ItemEntity(destroyedBlock + new Vector3(0.5), drop);
                     entity.ApplyRandomVelocity();
                     world.OnSpawnEntity(entity);
                 }
             }
         }
     }
 }
예제 #6
0
        public override void OnItemUsedOnBlock(World world, Vector3 clickedBlock, Vector3 clickedSide,
                                               Vector3 cursorPosition, Entity usedBy)
        {
            var clicked = world.GetBlock(clickedBlock);
            var player  = usedBy as PlayerEntity;

            if (player.GameMode != GameMode.Creative)
            {
                var item = player.Inventory[player.SelectedSlot];
                player.Inventory[player.SelectedSlot] = new ItemStack(item.Id,
                                                                      (sbyte)(item.Count - 1), item.Metadata, item.Nbt);
            }
            if (clicked.OnBlockRightClicked(clickedBlock, clickedSide, cursorPosition, world, usedBy))
            {
                if (OnBlockPlaced(world, clickedBlock + clickedSide, clickedBlock, clickedSide, cursorPosition, usedBy))
                {
                    if ((clickedBlock + clickedSide).Y >= 0 && (clickedBlock + clickedSide).Y <= Chunk.Height)
                    {
                        world.SetBlock(clickedBlock + clickedSide, this);
                    }
                }
            }
        }
예제 #7
0
        /// <summary>
        /// Spawns a bolt of lightning in the given world
        /// at the given position.
        /// </summary>
        public void SpawnLightning(World world, Vector3 position)
        {
            var chunk = world.GetChunk(World.WorldToChunkCoordinates(position));
            var block = World.FindBlockPosition(position);
            byte y = (byte)(chunk.GetHeight((byte)block.X, (byte)block.Z) + 1);

            var strike = new Vector3(position.X, y, position.Z);
            if (world.GetBlock(strike + Vector3.Down).Transparency == Transparency.Opaque)
                world.SetBlock(strike, new FireBlock());

            var clients = GetClientsInWorld(world);
            foreach (var minecraftClient in clients)
                minecraftClient.SendPacket(new SpawnLightningPacket(EntityManager.nextEntityId++, strike));

            ProcessSendQueue();
        }
예제 #8
0
파일: Block.cs 프로젝트: cpancake/Craft.Net
 /// <summary>
 /// Called when a block update occurs. Default handler will handle
 /// common activities such as destroying blocks that lose support -
 /// make sure you call it if you don't want to lose this functionality.
 /// </summary>
 public virtual void BlockUpdate(World world, Vector3 updatedBlock, Vector3 modifiedBlock)
 {
     if (RequiresSupport)
     {
         // Ensure that it hasn't lost support
         var block = world.GetBlock(updatedBlock + SupportDirection);
         if (block is AirBlock)
         {
             world.SetBlock(updatedBlock, new AirBlock());
             ItemStack[] drops;
             bool spawnEntity = GetDrop(null, out drops);
             if (spawnEntity)
             {
                 foreach (var drop in drops)
                     world.OnSpawnEntity(new ItemEntity(updatedBlock + new Vector3(0.5), drop));
             }
         }
     }
 }
예제 #9
0
파일: Block.cs 프로젝트: cpancake/Craft.Net
 public virtual void OnBlockMined(World world, Vector3 destroyedBlock, PlayerEntity player)
 {
     if (Hardness != -1)
     {
         var slot = player.Inventory[player.SelectedSlot];
         world.SetBlock(destroyedBlock, new AirBlock());
         if (CanHarvest(slot.AsItem() as ToolItem) && player.GameMode != GameMode.Creative)
         {
             ItemStack[] drops;
             bool spawnEntity = GetDrop(slot.AsItem() as ToolItem, out drops);
             if (spawnEntity)
             {
                 foreach (var drop in drops)
                 {
                     var entity = new ItemEntity(destroyedBlock + new Vector3(0.5), drop);
                     entity.ApplyRandomVelocity();
                     world.OnSpawnEntity(entity);
                 }
             }
         }
     }
 }