mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-16 19:15:14 -04:00
move a bit of code out of inputhandler and into inventory
This commit is contained in:
parent
363f28f52b
commit
e1b2aa32ea
10
src/Core.h
10
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
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user