diff --git a/src/Core.h b/src/Core.h index 9d5a773d5..b7be97811 100644 --- a/src/Core.h +++ b/src/Core.h @@ -60,15 +60,15 @@ typedef unsigned __INTPTR_TYPE__ cc_uintptr; #endif #elif __MWERKS__ typedef signed char cc_int8; -typedef signed short cc_int16; -typedef signed int cc_int32; +typedef signed short int cc_int16; +typedef signed long int cc_int32; typedef signed long long cc_int64; typedef unsigned char cc_uint8; -typedef unsigned short cc_uint16; -typedef unsigned int cc_uint32; +typedef unsigned short int cc_uint16; +typedef unsigned long int cc_uint32; typedef unsigned long long cc_uint64; -typedef unsigned int cc_uintptr; +typedef unsigned long int cc_uintptr; /* TODO: Is there actual attribute support for these somewhere? */ #define CC_INLINE inline #define CC_NOINLINE diff --git a/src/InputHandler.c b/src/InputHandler.c index 2b5161bba..11eb8d660 100644 --- a/src/InputHandler.c +++ b/src/InputHandler.c @@ -366,28 +366,7 @@ void InputHandler_PickBlocks(bool cooldown, bool left, bool middle, bool right) cur = World_GetBlock(pos.X, pos.Y, pos.Z); if (Blocks.Draw[cur] == DRAW_GAS) return; if (!(Blocks.CanPlace[cur] || Blocks.CanDelete[cur])) return; - if (!Inventory_CheckChangeSelected() || Inventory_SelectedBlock == cur) return; - - /* Is the currently selected block an empty slot? */ - if (Inventory_SelectedBlock == BLOCK_AIR) { - Inventory_SetSelectedBlock(cur); return; - } - - /* Try to replace same block */ - for (i = 0; i < INVENTORY_BLOCKS_PER_HOTBAR; i++) { - if (Inventory_Get(i) != cur) continue; - Inventory_SetSelectedIndex(i); return; - } - - /* Try to replace empty slots */ - for (i = 0; i < INVENTORY_BLOCKS_PER_HOTBAR; i++) { - if (Inventory_Get(i) != BLOCK_AIR) continue; - Inventory_Set(i, cur); - Inventory_SetSelectedIndex(i); return; - } - - /* Finally, replace the currently selected block */ - Inventory_SetSelectedBlock(cur); + Inventory_PickBlock(cur); } } diff --git a/src/Inventory.c b/src/Inventory.c index 2af450290..79220b006 100644 --- a/src/Inventory.c +++ b/src/Inventory.c @@ -43,6 +43,32 @@ void Inventory_SetSelectedBlock(BlockID block) { Event_RaiseVoid(&UserEvents.HeldBlockChanged); } +void Inventory_PickBlock(BlockID block) { + int i; + if (!Inventory_CheckChangeSelected() || Inventory_SelectedBlock == block) return; + + /* Is the currently selected block an empty slot? */ + if (Inventory_SelectedBlock == BLOCK_AIR) { + Inventory_SetSelectedBlock(block); return; + } + + /* Try to replace same block */ + for (i = 0; i < INVENTORY_BLOCKS_PER_HOTBAR; i++) { + if (Inventory_Get(i) != block) continue; + Inventory_SetSelectedIndex(i); return; + } + + /* Try to replace empty slots */ + for (i = 0; i < INVENTORY_BLOCKS_PER_HOTBAR; i++) { + if (Inventory_Get(i) != BLOCK_AIR) continue; + Inventory_Set(i, block); + Inventory_SetSelectedIndex(i); return; + } + + /* Finally, replace the currently selected block */ + Inventory_SetSelectedBlock(block); +} + static const cc_uint8 classicInventory[42] = { BLOCK_STONE, BLOCK_COBBLE, BLOCK_BRICK, BLOCK_DIRT, BLOCK_WOOD, BLOCK_LOG, BLOCK_LEAVES, BLOCK_GLASS, BLOCK_SLAB, BLOCK_MOSSY_ROCKS, BLOCK_SAPLING, BLOCK_DANDELION, BLOCK_ROSE, BLOCK_BROWN_SHROOM, BLOCK_RED_SHROOM, BLOCK_SAND, BLOCK_GRAVEL, BLOCK_SPONGE, diff --git a/src/Inventory.h b/src/Inventory.h index 8c621a43d..d49290fbf 100644 --- a/src/Inventory.h +++ b/src/Inventory.h @@ -44,6 +44,9 @@ void Inventory_SetHotbarIndex(int index); /* Attempts to set the block for the selected index in the current hotbar. */ /* NOTE: If another slot is already this block, the selected index is instead changed. */ void Inventory_SetSelectedBlock(BlockID block); +/* Attempts to set the selected block in a user-friendly manner. */ +/* e.g. this method tries to replace empty slots before other blocks */ +void Inventory_PickBlock(BlockID block); /* Sets all slots to contain their default associated block. */ /* NOTE: The order of default blocks may not be in order of ID. */ void Inventory_ApplyDefaultMapping(void); diff --git a/src/Program.c b/src/Program.c index 0d41b6870..c02089e19 100644 --- a/src/Program.c +++ b/src/Program.c @@ -106,9 +106,9 @@ static int Program_Run(int argc, char** argv) { int argsCount = Platform_GetCommandLineArgs(argc, argv, args); #ifdef _MSC_VER /* NOTE: Make sure to comment this out before pushing a commit */ - String rawArgs = String_FromConst("UnknownShadow200 fffff 127.0.0.1 25565"); + //String rawArgs = String_FromConst("UnknownShadow200 fffff 127.0.0.1 25565"); //String rawArgs = String_FromConst("UnknownShadow200"); - argsCount = String_UNSAFE_Split(&rawArgs, ' ', args, 4); + //argsCount = String_UNSAFE_Split(&rawArgs, ' ', args, 4); #endif if (argsCount == 0) {