Exemplo n.º 1
0
 public static void SetBlock(this World world, Coordinates3D coordinates, BlockDescriptor value)
 {
     world.SetBlockId(coordinates, value.Id);
     world.SetMetadata(coordinates, value.Metadata);
     world.SetSkyLight(coordinates, value.SkyLight);
     world.SetBlockLight(coordinates, value.BlockLight);
 }
Exemplo n.º 2
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));
 }
Exemplo n.º 3
0
 public static ItemStack[] DefaultGetDropHandler(BlockDescriptor block, World world, Coordinates3D minedBlock)
 {
     return new[] { new ItemStack(block.Id, 1, block.Metadata) };
 }
Exemplo n.º 4
0
 internal static SupportDirection DefaultGetSupportDirectionHandler(BlockDescriptor block, World world, Coordinates3D coordinates)
 {
     return SupportDirection.None;
 }
Exemplo n.º 5
0
 internal static void DefaultBlockUpdateHandler(BlockDescriptor block, World world, Coordinates3D updatedBlock)
 {
     var logic = GetLogicDescriptor(block);
     var support = logic.GetSupportDirection(block, world, updatedBlock);
     var supportingBlock = updatedBlock;
     switch (support)
     {
         case SupportDirection.Down:
             supportingBlock = updatedBlock + Coordinates3D.Down;
             break;
         case SupportDirection.Up:
             supportingBlock = updatedBlock + Coordinates3D.Up;
             break;
         case SupportDirection.East:
             supportingBlock = updatedBlock + Coordinates3D.East;
             break;
         case SupportDirection.West:
             supportingBlock = updatedBlock + Coordinates3D.West;
             break;
         case SupportDirection.North:
             supportingBlock = updatedBlock + Coordinates3D.North;
             break;
         case SupportDirection.South:
             supportingBlock = updatedBlock + Coordinates3D.South;
             break;
         default:
             return;
     }
     if (!World.IsValidPosition(supportingBlock))
         return;
     if (world.GetBlockId(supportingBlock) == 0) // TODO: Air isn't the only thing that can't support some blocks
         OnBlockMined(block, world, updatedBlock, null); // TODO: Consider using a seperate delegate for blocks destroyed through non-player actions
 }
Exemplo n.º 6
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);
 }
Exemplo n.º 7
0
 internal static bool DefaultCanHarvestHandler(ItemDescriptor item, BlockDescriptor block)
 {
     if (GetLogicDescriptor(block).Hardness == -1)
         return false;
     return true;
 }
Exemplo n.º 8
0
 internal static bool DefaultBlockRightClickedHandler(BlockDescriptor block, World world, Coordinates3D clickedBlock, Coordinates3D clickedSide, Coordinates3D cursorPosition)
 {
     return true;
 }
Exemplo n.º 9
0
 internal static void DefaultBlockPlacedHandler(BlockDescriptor block, World world, Coordinates3D clickedBlock, Coordinates3D clickedSide, Coordinates3D cursorPosition)
 {
     if (world.GetBlockId(clickedBlock + clickedSide) == 0) // TODO: There are more situations than just air when a block can be overwritten
     {
         world.SetBlockId(clickedBlock + clickedSide, block.Id);
         world.SetMetadata(clickedBlock + clickedSide, block.Metadata);
     }
 }
Exemplo n.º 10
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);
 }
Exemplo n.º 11
0
 public static BlockLogicDescriptor GetLogicDescriptor(BlockDescriptor block)
 {
     if (!BlockLogicDescriptors.ContainsKey(block.Id))
         throw new KeyNotFoundException("The given block does not exist.");
     return BlockLogicDescriptors[block.Id];
 }
Exemplo n.º 12
0
 public static bool CanHarvest(ItemDescriptor item, BlockDescriptor block)
 {
     return GetLogicDescriptor(block).CanHarvest(item, block);
 }
Exemplo n.º 13
0
 public static ItemStack[] GetBlockDrop (BlockDescriptor block, World world, Coordinates3D minedBlock)
 {
     if (!BlockLogicDescriptors.ContainsKey(block.Id))
         throw new KeyNotFoundException("The given block does not exist.");
     return BlockLogicDescriptors[block.Id].GetDrop(block, world, minedBlock);
 }
Exemplo n.º 14
0
 public static void OnBlockUpdate(BlockDescriptor block, World world, Coordinates3D updatedBlock)
 {
     if (!BlockLogicDescriptors.ContainsKey(block.Id))
         throw new KeyNotFoundException("The given block does not exist.");
     BlockLogicDescriptors[block.Id].BlockUpdated(block, world, updatedBlock);
 }
Exemplo n.º 15
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);
 }
Exemplo n.º 16
0
 public static void OnBlockPlaced(BlockDescriptor block, World world, Coordinates3D clickedBlock, Coordinates3D clickedSide, Coordinates3D cursorPosition)
 {
     if (!BlockLogicDescriptors.ContainsKey(block.Id))
         throw new KeyNotFoundException("The given block does not exist.");
     BlockLogicDescriptors[block.Id].BlockPlaced(block, world, clickedBlock, clickedSide, cursorPosition);
 }