Wood pickaxe

This commit is contained in:
2026-04-08 15:30:18 -03:00
parent 436adf9647
commit 2568694ada
4 changed files with 61 additions and 8 deletions
+45 -4
View File
@@ -53,6 +53,31 @@ const recipes: CraftingRecipe[] = [
], ],
result: new ItemStack("bworld:planks", 2), 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; const PADDING = 10;
@@ -73,7 +98,7 @@ export class GuiPlayerInventory extends GuiInventoryScreen {
for (let i = 0; i < 3; i += 1) { for (let i = 0; i < 3; i += 1) {
for (let j = 0; j < 3; j += 1) { for (let j = 0; j < 3; j += 1) {
this.slots.push( 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,17 +163,33 @@ export class GuiPlayerInventory extends GuiInventoryScreen {
for (let x = 0; x <= 3 - recipe.width; x++) { for (let x = 0; x <= 3 - recipe.width; x++) {
let match = true; let match = true;
for (let ry = 0; ry < recipe.height; ry++) { for (let gy = 0; gy < 3; gy++) {
for (let rx = 0; rx < recipe.width; rx++) { for (let gx = 0; gx < 3; gx++) {
const grid_index = (y + ry) * 3 + (x + rx); const grid_index = gy * 3 + gx;
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; const recipe_index = ry * recipe.width + rx;
if (grid[grid_index] !== recipe.pattern[recipe_index]) { if (grid[grid_index] !== recipe.pattern[recipe_index]) {
match = false; match = false;
break; break;
} }
} else {
if (grid[grid_index] !== undefined) {
match = false;
break;
} }
} }
}
if (!match) break;
}
if (match) return true; if (match) return true;
} }
+2
View File
@@ -7,3 +7,5 @@ import "./tin_ingot.ts";
import "./iron_ingot.ts"; import "./iron_ingot.ts";
import "./copper_ingot.ts"; import "./copper_ingot.ts";
import "./gold_ingot.ts"; import "./gold_ingot.ts";
import "./stick.ts";
import "./wood_pickaxe.ts";
+5
View File
@@ -0,0 +1,5 @@
import { EverythingRegistry, ItemRegistry } from "$/common/everything_registry.ts";
EverythingRegistry.register<ItemRegistry>("items", "bworld:stick", {
texture_id: "bworld:stick",
});
+5
View File
@@ -0,0 +1,5 @@
import { EverythingRegistry, ItemRegistry } from "$/common/everything_registry.ts";
EverythingRegistry.register<ItemRegistry>("items", "bworld:wood_pickaxe", {
texture_id: "bworld:wood_pickaxe",
});