Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added assets/textures/tools/diamond_axe.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/tools/diamond_shovel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/tools/gold_axe.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/tools/gold_shovel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/tools/iron_axe.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/tools/iron_shovel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/tools/stone_axe.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/tools/stone_shovel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/tools/wood_axe.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/tools/wood_shovel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/weapons/diamond_sword.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/weapons/gold_sword.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/weapons/iron_sword.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/weapons/stone_sword.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/weapons/wood_sword.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 6 additions & 6 deletions imgui.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ Pos=38,36
Size=253,111

[Window][##MainMenu]
Pos=1030,513
Pos=710,320
Size=499,350

[Window][##WorldSelect]
Pos=1030,438
Pos=710,245
Size=500,500

[Window][Debug]
Expand All @@ -23,7 +23,7 @@ Pos=587,46
Size=192,167

[Window][##PauseMenu]
Pos=1105,538
Pos=785,345
Size=350,300

[Window][Chat]
Expand All @@ -35,10 +35,10 @@ Pos=1030,438
Size=500,500

[Window][##Inventory]
Pos=1016,546
Pos=696,353
Size=528,284

[Window][##CreativeInventory]
Pos=1016,564
Size=528,248
Pos=696,315
Size=528,360

19 changes: 19 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,25 @@ embed_asset(embed_stone_pickaxe_png "${_TEX}/tools/stone_pickaxe.png")
embed_asset(embed_gold_pickaxe_png "${_TEX}/tools/gold_pickaxe.png")
embed_asset(embed_iron_pickaxe_png "${_TEX}/tools/iron_pickaxe.png")

embed_asset(embed_diamond_axe_png "${_TEX}/tools/diamond_axe.png")
embed_asset(embed_wood_axe_png "${_TEX}/tools/wood_axe.png")
embed_asset(embed_stone_axe_png "${_TEX}/tools/stone_axe.png")
embed_asset(embed_gold_axe_png "${_TEX}/tools/gold_axe.png")
embed_asset(embed_iron_axe_png "${_TEX}/tools/iron_axe.png")

embed_asset(embed_diamond_shovel_png "${_TEX}/tools/diamond_shovel.png")
embed_asset(embed_wood_shovel_png "${_TEX}/tools/wood_shovel.png")
embed_asset(embed_stone_shovel_png "${_TEX}/tools/stone_shovel.png")
embed_asset(embed_gold_shovel_png "${_TEX}/tools/gold_shovel.png")
embed_asset(embed_iron_shovel_png "${_TEX}/tools/iron_shovel.png")

# weapons
embed_asset(embed_diamond_sword_png "${_TEX}/weapons/diamond_sword.png")
embed_asset(embed_wood_sword_png "${_TEX}/weapons/wood_sword.png")
embed_asset(embed_stone_sword_png "${_TEX}/weapons/stone_sword.png")
embed_asset(embed_gold_sword_png "${_TEX}/weapons/gold_sword.png")
embed_asset(embed_iron_sword_png "${_TEX}/weapons/iron_sword.png")


# blocks
embed_asset(embed_dirt_png "${_TEX}/dirt.png")
Expand Down
5 changes: 4 additions & 1 deletion src/core/main.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <cstdint>
#ifdef _WIN32
#define NOMINMAX
#define WIN32_LEAN_AND_MEAN
Expand Down Expand Up @@ -678,7 +679,9 @@ int main(int argc, char* argv[])
else
{
float hardness = getBlockHardness(player.breakingBlockId);
player.breakProgress += deltaTime / hardness;
uint8_t heldId = player.inventory.selectedItem().blockId;
float speedMult = getToolSpeedMultiplier(heldId, player.breakingBlockId);
player.breakProgress += (deltaTime / hardness) * speedMult;
if (player.breakProgress >= 1.0f)
{
setBlockAtWorld(hit->blockPos.x, hit->blockPos.y, hit->blockPos.z, 0, *chunkManager);
Expand Down
15 changes: 15 additions & 0 deletions src/gameplay/Inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@ const std::vector<CreativeItem>& getCreativeItems()
{TOOL_STONE_PICKAXE, "Stone Pickaxe"},
{TOOL_GOLD_PICKAXE, "Gold Pickaxe"},
{TOOL_IRON_PICKAXE, "Iron Pickaxe"},
{TOOL_DIAMOND_AXE, "Diamond Axe"},
{TOOL_WOOD_AXE, "Wood Axe"},
{TOOL_STONE_AXE, "Stone Axe"},
{TOOL_GOLD_AXE, "Gold Axe"},
{TOOL_IRON_AXE, "Iron Axe"},
{TOOL_DIAMOND_SHOVEL, "Diamond Shovel"},
{TOOL_WOOD_SHOVEL, "Wood Shovel"},
{TOOL_STONE_SHOVEL, "Stone Shovel"},
{TOOL_GOLD_SHOVEL, "Gold Shovel"},
{TOOL_IRON_SHOVEL, "Iron Shovel"},
{TOOL_DIAMOND_SWORD, "Diamond Sword"},
{TOOL_WOOD_SWORD, "Wood Sword"},
{TOOL_STONE_SWORD, "Stone Sword"},
{TOOL_GOLD_SWORD, "Gold Sword"},
{TOOL_IRON_SWORD, "Iron Sword"},
};
return items;
}
Expand Down
18 changes: 18 additions & 0 deletions src/rendering/ToolModelGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,24 @@ void loadToolModels()
{TOOL_STONE_PICKAXE, embed_stone_pickaxe_png_data, embed_stone_pickaxe_png_size},
{TOOL_GOLD_PICKAXE, embed_gold_pickaxe_png_data, embed_gold_pickaxe_png_size},
{TOOL_IRON_PICKAXE, embed_iron_pickaxe_png_data, embed_iron_pickaxe_png_size},

{TOOL_DIAMOND_AXE, embed_diamond_axe_png_data, embed_diamond_axe_png_size},
{TOOL_WOOD_AXE, embed_wood_axe_png_data, embed_wood_axe_png_size},
{TOOL_STONE_AXE, embed_stone_axe_png_data, embed_stone_axe_png_size},
{TOOL_GOLD_AXE, embed_gold_axe_png_data, embed_gold_axe_png_size},
{TOOL_IRON_AXE, embed_iron_axe_png_data, embed_iron_axe_png_size},

{TOOL_DIAMOND_SHOVEL, embed_diamond_shovel_png_data, embed_diamond_shovel_png_size},
{TOOL_WOOD_SHOVEL, embed_wood_shovel_png_data, embed_wood_shovel_png_size},
{TOOL_STONE_SHOVEL, embed_stone_shovel_png_data, embed_stone_shovel_png_size},
{TOOL_GOLD_SHOVEL, embed_gold_shovel_png_data, embed_gold_shovel_png_size},
{TOOL_IRON_SHOVEL, embed_iron_shovel_png_data, embed_iron_shovel_png_size},

{TOOL_DIAMOND_SWORD, embed_diamond_sword_png_data, embed_diamond_sword_png_size},
{TOOL_WOOD_SWORD, embed_wood_sword_png_data, embed_wood_sword_png_size},
{TOOL_STONE_SWORD, embed_stone_sword_png_data, embed_stone_sword_png_size},
{TOOL_GOLD_SWORD, embed_gold_sword_png_data, embed_gold_sword_png_size},
{TOOL_IRON_SWORD, embed_iron_sword_png_data, embed_iron_sword_png_size},
};

for (const auto &tool : tools)
Expand Down
21 changes: 21 additions & 0 deletions src/rendering/ToolModelGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,27 @@ constexpr uint8_t TOOL_STONE_PICKAXE = 130;
constexpr uint8_t TOOL_GOLD_PICKAXE = 131;
constexpr uint8_t TOOL_IRON_PICKAXE = 132;

// axes
constexpr uint8_t TOOL_DIAMOND_AXE = 133;
constexpr uint8_t TOOL_WOOD_AXE = 134;
constexpr uint8_t TOOL_STONE_AXE = 135;
constexpr uint8_t TOOL_GOLD_AXE = 136;
constexpr uint8_t TOOL_IRON_AXE = 137;

// shovels
constexpr uint8_t TOOL_DIAMOND_SHOVEL = 138;
constexpr uint8_t TOOL_WOOD_SHOVEL = 139;
constexpr uint8_t TOOL_STONE_SHOVEL = 140;
constexpr uint8_t TOOL_GOLD_SHOVEL = 141;
constexpr uint8_t TOOL_IRON_SHOVEL = 142;

// swords
constexpr uint8_t TOOL_DIAMOND_SWORD = 143;
constexpr uint8_t TOOL_WOOD_SWORD = 144;
constexpr uint8_t TOOL_STONE_SWORD = 145;
constexpr uint8_t TOOL_GOLD_SWORD = 146;
constexpr uint8_t TOOL_IRON_SWORD = 147;

inline bool isToolItem(uint8_t id) { return id >= TOOL_ID_START; }

class ToolModelGenerator {
Expand Down
61 changes: 61 additions & 0 deletions src/utils/BlockTypes.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "BlockTypes.h"
#include "../rendering/ToolModelGenerator.h"

std::array<BlockType, 256> g_blockTypes;
std::array<BlockType, 256> g_defaultBlockTypes;
Expand Down Expand Up @@ -210,3 +211,63 @@ float getBlockHardness(uint8_t blockId)
default: return 1.0f;
}
}

ToolType getBlockPreferredTool(uint8_t blockId)
{
switch (blockId)
{
case 3: //stone
case 22: //cobblestone
return ToolType::Pickaxe;
case 4: //log
case 5: //planks
return ToolType::Axe;
case 1: //dirt
case 2: //grass
case 6: //sand
case 21: //snow
return ToolType::Shovel;
default:
return ToolType::None;
}
}

float getToolSpeedMultiplier(uint8_t toolItemId, uint8_t blockId)
{
ToolType preferred = getBlockPreferredTool(blockId);
if (preferred == ToolType::None)
return 1.0f;

if (preferred == ToolType::Pickaxe) {
switch (toolItemId)
{
case TOOL_WOOD_PICKAXE: return 1.0f;
case TOOL_STONE_PICKAXE: return 1.5f;
case TOOL_IRON_PICKAXE: return 1.9f;
case TOOL_GOLD_PICKAXE: return 2.2f;
case TOOL_DIAMOND_PICKAXE: return 3.0f;
default: return 0.3f;
}
} else if (preferred == ToolType::Axe) {
switch (toolItemId)
{
case TOOL_WOOD_AXE: return 1.0f;
case TOOL_STONE_AXE: return 1.5f;
case TOOL_IRON_AXE: return 1.9f;
case TOOL_GOLD_AXE: return 2.2f;
case TOOL_DIAMOND_AXE: return 3.0f;
default: return 0.3f;
}
} else if (preferred == ToolType::Shovel) {
switch (toolItemId)
{
case TOOL_WOOD_SHOVEL: return 1.0f;
case TOOL_STONE_SHOVEL: return 1.5f;
case TOOL_IRON_SHOVEL: return 1.9f;
case TOOL_GOLD_SHOVEL: return 2.2f;
case TOOL_DIAMOND_SHOVEL: return 3.0f;
default: return 0.3f;
}
}
return 0.3f;
}
3 changes: 3 additions & 0 deletions src/utils/BlockTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ enum BlockTex : int
};

float getBlockHardness(uint8_t blockId);
enum class ToolType { None, Pickaxe, Axe, Shovel, Sword };
ToolType getBlockPreferredTool(uint8_t blockId);
float getToolSpeedMultiplier(uint8_t toolItemId, uint8_t blockId);

struct BlockType
{
Expand Down