1
0
mirror of https://github.com/p2r3/bareiron.git synced 2025-10-02 07:35:08 +02:00

implement basic crafting

This commit is contained in:
p2r3
2025-08-12 17:08:17 +03:00
parent 0404fa2cbb
commit 1fc0f75ed7
5 changed files with 116 additions and 4 deletions

84
src/crafting.c Normal file
View File

@@ -0,0 +1,84 @@
#include <stdlib.h>
#include <string.h>
#include "globals.h"
#include "registries.h"
#include "crafting.h"
void getCraftingOutput (PlayerData *player, uint8_t *count, uint16_t *item) {
uint8_t i, filled = 0, first = 10;
for (i = 0; i < 9; i ++) {
if (player->craft_items[i]) {
filled ++;
if (first == 10) first = i;
}
}
uint8_t first_col = first % 3, first_row = first / 3;
switch (filled) {
case 0:
*item = 0;
*count = 0;
return;
case 1:
switch (player->craft_items[first]) {
case I_oak_log:
*item = I_oak_planks;
*count = 4;
return;
case I_oak_planks:
*item = 715; // oak_button
*count = 1;
return;
default: break;
}
break;
case 2:
switch (player->craft_items[first]) {
case I_oak_planks:
if (first_col != 2 && player->craft_items[first + 1] == I_oak_planks) {
*item = 731; // oak_pressure_plate
*count = 1;
return;
} else if (first_row != 2 && player->craft_items[first + 3] == I_oak_planks) {
*item = I_stick;
*count = 4;
return;
}
break;
default: break;
}
case 4:
switch (player->craft_items[first]) {
case I_oak_planks:
if (
first_col != 2 && first_row != 2 &&
player->craft_items[first + 1] == I_oak_planks &&
player->craft_items[first + 3] == I_oak_planks &&
player->craft_items[first + 4] == I_oak_planks
) {
*item = 320; // crafting_table
*count = 1;
return;
}
break;
default: break;
}
default: break;
}
*count = 0;
*item = 0;
}