diff --git a/client/gui/gui_player_inventory.ts b/client/gui/gui_player_inventory.ts index 5490f42..ffc39aa 100644 --- a/client/gui/gui_player_inventory.ts +++ b/client/gui/gui_player_inventory.ts @@ -53,6 +53,31 @@ const recipes: CraftingRecipe[] = [ ], result: new ItemStack("bworld:planks", 2), }, + { + width: 1, + height: 2, + pattern: [ + "bworld:planks", + "bworld:planks", + ], + result: new ItemStack("bworld:stick", 2), + }, + { + width: 3, + height: 3, + pattern: [ + "bworld:planks", + "bworld:planks", + "bworld:planks", + undefined, + "bworld:stick", + undefined, + undefined, + "bworld:stick", + undefined, + ], + result: new ItemStack("bworld:wood_pickaxe", 1), + }, ]; const PADDING = 10; @@ -73,7 +98,7 @@ export class GuiPlayerInventory extends GuiInventoryScreen { for (let i = 0; i < 3; i += 1) { for (let j = 0; j < 3; j += 1) { this.slots.push( - new Slot(this.inventory, i * 3 + j, crafting_x + i * SLOT_SIZE, crafting_y + j * SLOT_SIZE), + new Slot(this.inventory, j * 3 + i, crafting_x + i * SLOT_SIZE, crafting_y + j * SLOT_SIZE), ); } } @@ -138,16 +163,32 @@ export class GuiPlayerInventory extends GuiInventoryScreen { for (let x = 0; x <= 3 - recipe.width; x++) { let match = true; - for (let ry = 0; ry < recipe.height; ry++) { - for (let rx = 0; rx < recipe.width; rx++) { - const grid_index = (y + ry) * 3 + (x + rx); - const recipe_index = ry * recipe.width + rx; + for (let gy = 0; gy < 3; gy++) { + for (let gx = 0; gx < 3; gx++) { + const grid_index = gy * 3 + gx; - if (grid[grid_index] !== recipe.pattern[recipe_index]) { - match = false; - break; + if ( + gx >= x && + gx < x + recipe.width && + gy >= y && + gy < y + recipe.height + ) { + const rx = gx - x; + const ry = gy - y; + const recipe_index = ry * recipe.width + rx; + + if (grid[grid_index] !== recipe.pattern[recipe_index]) { + match = false; + break; + } + } else { + if (grid[grid_index] !== undefined) { + match = false; + break; + } } } + if (!match) break; } if (match) return true; diff --git a/client/items/mod.ts b/client/items/mod.ts index fa632e3..b3aa64b 100644 --- a/client/items/mod.ts +++ b/client/items/mod.ts @@ -7,3 +7,5 @@ import "./tin_ingot.ts"; import "./iron_ingot.ts"; import "./copper_ingot.ts"; import "./gold_ingot.ts"; +import "./stick.ts"; +import "./wood_pickaxe.ts"; diff --git a/client/items/stick.ts b/client/items/stick.ts new file mode 100644 index 0000000..3ff679d --- /dev/null +++ b/client/items/stick.ts @@ -0,0 +1,5 @@ +import { EverythingRegistry, ItemRegistry } from "$/common/everything_registry.ts"; + +EverythingRegistry.register("items", "bworld:stick", { + texture_id: "bworld:stick", +}); diff --git a/client/items/wood_pickaxe.ts b/client/items/wood_pickaxe.ts new file mode 100644 index 0000000..67a0ed0 --- /dev/null +++ b/client/items/wood_pickaxe.ts @@ -0,0 +1,5 @@ +import { EverythingRegistry, ItemRegistry } from "$/common/everything_registry.ts"; + +EverythingRegistry.register("items", "bworld:wood_pickaxe", { + texture_id: "bworld:wood_pickaxe", +});