Ejemplo n.º 1
0
 public static void DefaultBlockMinedHandler(BlockDescriptor block, World world, Coordinates3D destroyedBlock, ItemDescriptor? tool)
 {
     var drops = Block.GetBlockDrop(block, world, destroyedBlock);
     world.SetBlockId(destroyedBlock, 0);
     world.SetMetadata(destroyedBlock, 0);
     foreach (var drop in drops)
         world.OnSpawnEntityRequested(new ItemEntity((Vector3)destroyedBlock + new Vector3(0.5), drop));
 }
Ejemplo n.º 2
0
 public static void RightClick(RemoteClient client, MinecraftServer server, IPacket _packet)
 {
     var packet = (RightClickPacket)_packet;
     var slot = client.Entity.Inventory[client.Entity.SelectedSlot];
     var position = new Coordinates3D(packet.X, packet.Y, packet.Z);
     var cursorPosition = new Coordinates3D(packet.CursorX, packet.CursorY, packet.CursorZ);
     BlockDescriptor? block = null;
     if (position != -Coordinates3D.One)
     {
         if (position.DistanceTo(client.Entity.Position) > client.Reach)
             return;
         block = client.World.GetBlock(position);
     }
     bool use = true;
     if (block != null)
         use = Block.OnBlockRightClicked(block.Value, client.World, position, AdjustByDirection(packet.Direction), cursorPosition);
     if (!slot.Empty)
     {
         var item = new ItemDescriptor(slot.Id, slot.Metadata);
         if (use)
         {
             if (block != null)
             {
                 Item.OnItemUsedOnBlock(item, client.World, position, AdjustByDirection(packet.Direction), cursorPosition);
                 if (client.GameMode != GameMode.Creative)
                 {
                     slot.Count--; // TODO: This is probably a bad place to put this code
                     if (slot.Count == 0)
                         client.Entity.Inventory[client.Entity.SelectedSlot] = ItemStack.EmptyStack;
                     else
                         client.Entity.Inventory[client.Entity.SelectedSlot] = slot;
                 }
             }
             else
                 Item.OnItemUsed(item);
         }
     }
 }
Ejemplo n.º 3
0
 public static void OnItemUsedOnBlock(ItemDescriptor item, World world, Coordinates3D clickedBlock, Coordinates3D clickedSide, Coordinates3D cursorPosition)
 {
     GetLogicDescriptor(item).ItemUsedOnBlock(item, world, clickedBlock, clickedSide, cursorPosition);
 }
Ejemplo n.º 4
0
 public static int GetMaximumStackSize(ItemDescriptor item)
 {
     return GetLogicDescriptor(item).MaximumStackSize;
 }
Ejemplo n.º 5
0
 internal static void DefaultItemUsedOnBlockHandler(ItemDescriptor item, World world, Coordinates3D clickedBlock, Coordinates3D clickedSide, Coordinates3D cursorPosition)
 {
 }
Ejemplo n.º 6
0
 public static void OnItemUsed(ItemDescriptor item)
 {
     GetLogicDescriptor(item).ItemUsed(item);
 }
Ejemplo n.º 7
0
 public static ItemLogicDescriptor GetLogicDescriptor(ItemDescriptor item)
 {
     if (!ItemLogicDescriptors.ContainsKey(item.Id))
         throw new KeyNotFoundException("The given item does not exist.");
     return ItemLogicDescriptors[item.Id];
 }
Ejemplo n.º 8
0
 internal static void DefaultItemUsedHandler(ItemDescriptor item)
 {
 }
Ejemplo n.º 9
0
 internal static bool DefaultCanHarvestHandler(ItemDescriptor item, BlockDescriptor block)
 {
     if (GetLogicDescriptor(block).Hardness == -1)
         return false;
     return true;
 }
Ejemplo n.º 10
0
 public static void OnItemUsedOnBlock(ItemDescriptor item, World world, Coordinates3D clickedBlock, Coordinates3D clickedSide, Coordinates3D cursorPosition)
 {
     if (world.GetBlockId(clickedBlock + clickedSide) == 0)
         world.SetBlockId(clickedBlock + clickedSide, CakeBlock.BlockId);
 }
Ejemplo n.º 11
0
 internal static void DefaultBlockMinedHandler(BlockDescriptor block, World world, Coordinates3D destroyedBlock, ItemDescriptor? tool)
 {
     if (GlobalDefaultBlockMinedHandler == null)
     {
         world.SetBlockId(destroyedBlock, 0);
         world.SetMetadata(destroyedBlock, 0);
     }
     else
         GlobalDefaultBlockMinedHandler(block, world, destroyedBlock, tool);
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Gets the amount of time (in milliseconds) it takes to harvest a block with the specified tool.
 /// </summary>
 public static int GetHarvestTime(ItemDescriptor item, BlockDescriptor block, out short damage)
 {
     var logic = GetLogicDescriptor(block);
     // time is in seconds until returned
     if (logic.Hardness == -1)
     {
         damage = 0;
         return -1;
     }
     double time = logic.Hardness * 1.5;
     damage = 0;
     // TODO: ToolItem class
     // Adjust for tool in use
     //if (tool != null)
     //{
     //    if (!CanHarvest(item, block))
     //        time *= 3.33;
     //    if (Tool.IsEfficient(item, block))
     //    {
     //        switch (tool.ToolMaterial)
     //        {
     //            case ToolMaterial.Wood:
     //                time /= 2;
     //                break;
     //            case ToolMaterial.Stone:
     //                time /= 4;
     //                break;
     //            case ToolMaterial.Iron:
     //                time /= 6;
     //                break;
     //            case ToolMaterial.Diamond:
     //                time /= 8;
     //                break;
     //            case ToolMaterial.Gold:
     //                time /= 12;
     //                break;
     //        }
     //    }
     //    // Do tool damage
     //    damage = 1;
     //    if (tool.ToolType == ToolType.Pick || tool.ToolType == ToolType.Axe || tool.ToolType == ToolType.Shovel)
     //        damage = (short)(Hardness != 0 ? 1 : 0);
     //    else if (tool.ToolType == ToolType.Sword)
     //    {
     //        damage = (short)(Hardness != 0 ? 2 : 0);
     //        time /= 1.5;
     //        if (block.Id == CobwebBlock.BlockId)
     //            time /= 15;
     //    }
     //    else if (tool.ToolType == ToolType.Hoe)
     //        damage = 0;
     //    else if (tool is ShearsItem)
     //    {
     //        if (this is WoolBlock)
     //            time /= 5;
     //        if (this is LeavesBlock || this is CobwebBlock)
     //            time /= 15;
     //        if (this is CobwebBlock || this is LeavesBlock || this is TallGrassBlock ||
     //            this is TripwireBlock || this is VineBlock)
     //            damage = 1;
     //        else
     //            damage = 0;
     //    }
     //    else
     //        damage = 0;
     //}
     return (int)(time * 1000);
 }
Ejemplo n.º 13
0
 public static bool CanHarvest(ItemDescriptor item, BlockDescriptor block)
 {
     return GetLogicDescriptor(block).CanHarvest(item, block);
 }
Ejemplo n.º 14
0
 public static void OnBlockMined(BlockDescriptor block, World world, Coordinates3D destroyedBlock, ItemDescriptor? tool)
 {
     if (!BlockLogicDescriptors.ContainsKey(block.Id))
         throw new KeyNotFoundException("The given block does not exist.");
     BlockLogicDescriptors[block.Id].BlockMined(block, world, destroyedBlock, tool);
 }
Ejemplo n.º 15
0
 public static void OnItemUsedOnBlock(ItemDescriptor item, World world, Coordinates3D clickedBlock, Coordinates3D clickedSide, Coordinates3D cursorPosition)
 {
     var clicked = world.GetBlock(clickedBlock);
     if (OnBlockRightClicked(clicked, world, clickedBlock, clickedSide, cursorPosition))
     {
         if ((clickedBlock + clickedSide).Y >= 0 && (clickedBlock + clickedSide).Y <= Chunk.Height)
             OnBlockPlaced(new BlockDescriptor(item.Id, (byte)item.Metadata), world, clickedBlock, clickedSide, cursorPosition);
     }
 }