From e0f0c3c4d576f43c67817cb9551dc293a98df849 Mon Sep 17 00:00:00 2001 From: paulaboks Date: Fri, 27 Mar 2026 17:16:12 -0300 Subject: [PATCH] Fire and arrow on furnace --- assets/sprites/textures/arrow_empty.png | Bin 0 -> 130 bytes assets/sprites/textures/arrow_full.png | Bin 0 -> 128 bytes assets/sprites/textures/fire_empty.png | Bin 0 -> 157 bytes assets/sprites/textures/fire_full.png | Bin 0 -> 156 bytes client/blocks/furnace.ts | 6 ++ client/gui/gui_furnace.ts | 120 ++++++++++++++++++++---- 6 files changed, 107 insertions(+), 19 deletions(-) create mode 100644 assets/sprites/textures/arrow_empty.png create mode 100644 assets/sprites/textures/arrow_full.png create mode 100644 assets/sprites/textures/fire_empty.png create mode 100644 assets/sprites/textures/fire_full.png diff --git a/assets/sprites/textures/arrow_empty.png b/assets/sprites/textures/arrow_empty.png new file mode 100644 index 0000000000000000000000000000000000000000..ad9155d2e7267eaa3f8c75550f7390f440524e2e GIT binary patch literal 130 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`o}Mm_Ar`&K2@;kImahA2Z&s-0 z#jALdA*XFZ4#O_Ro*i@CcvfVtN>Mq@dZJ-sMC*%nYk<6z1O;QBgjpwz7$S{58}2m7 bF)=VS+KMkfJGs&pXefiHtDnm{r-UW|JtipW literal 0 HcmV?d00001 diff --git a/assets/sprites/textures/arrow_full.png b/assets/sprites/textures/arrow_full.png new file mode 100644 index 0000000000000000000000000000000000000000..ddd0955a0348c65a8764af72f02b53946a1704b3 GIT binary patch literal 128 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`?w&4=Ar`$)CpdC3DDWH>`~UxW zrBI1a!B>@M7S{r@zVW|%cXRJuFRvz_ATbxt-C61k9=u{FUnb{pCaC2Z9GaBCH$9-e bu7Pi2jSMsYSGj3GBN;qh{an^LB{Ts5XBjEF literal 0 HcmV?d00001 diff --git a/assets/sprites/textures/fire_empty.png b/assets/sprites/textures/fire_empty.png new file mode 100644 index 0000000000000000000000000000000000000000..6bed32092007c934bc79d79d0851051b18d089b4 GIT binary patch literal 157 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`DV{ElAr`&K2@+ctEM524-tg6o z6^R^g9lT?I*E_8{@R~KHx!|OslJ<(sRVhc7OU||t-o>(stz`Dboh<8nZ#eh{t0se# z&RF`vK*8+Pg{y`SC#$dth;o}4GCYe?OW})+WngAtFE%RO^T47QXdi>8tDnm{r-UW| Dv&uGW literal 0 HcmV?d00001 diff --git a/assets/sprites/textures/fire_full.png b/assets/sprites/textures/fire_full.png new file mode 100644 index 0000000000000000000000000000000000000000..bc1ef7e4bac086a977372fb4d0b91b7e12342890 GIT binary patch literal 156 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`$(}BbAr`%712^&>FyP>x^CY@R zZTknIxhn*`IGuy9MyDjtHaM2A*ic&Xr|qOAN5XEgr(73bbS~DIu_}ajeZ@H!nG+{h ztEE2T3ZBYhz`ytZg6d6c9(TQ2P}-`@c5m9_$CugqxS40_oD>%70NKyr>FVdQ&MBb@ E0Ckc%pa1{> literal 0 HcmV?d00001 diff --git a/client/blocks/furnace.ts b/client/blocks/furnace.ts index 8e6840e..062974c 100644 --- a/client/blocks/furnace.ts +++ b/client/blocks/furnace.ts @@ -113,7 +113,9 @@ function craft(container: Container, recipe: FurnaceRecipe) { interface TileChestData { inventory: Inventory; progress: number; + progress_max: number; fuel: number; + fuel_max: number; } const block = EverythingRegistry.register("blocks", "bworld:furnace", { @@ -142,7 +144,9 @@ const block = EverythingRegistry.register("blocks", "bworld:furna data: { inventory: new Inventory(new Container(3)), progress: 0, + progress_max: 0, fuel: 0, + fuel_max: 0, }, }); }, @@ -174,10 +178,12 @@ const block = EverythingRegistry.register("blocks", "bworld:furna // refuel if (data.fuel === 0 && has_fuel(container)) { data.fuel = consume_fuel(container); + data.fuel_max = data.fuel; } // cook if (data.fuel > 0 && recipe) { + data.progress_max = recipe.cook_time; data.progress += 1; if (data.progress >= recipe.cook_time) { diff --git a/client/gui/gui_furnace.ts b/client/gui/gui_furnace.ts index 1a53bab..b52bf99 100644 --- a/client/gui/gui_furnace.ts +++ b/client/gui/gui_furnace.ts @@ -1,20 +1,30 @@ import { Inventory, PlayerInventory } from "../inventory.ts"; import { add_player_hotbar, add_player_inventory, GuiInventoryScreen, Slot } from "./gui_screen.ts"; -import { canvas, draw_rect, draw_text, Texture } from "$/client/renderer/mod.ts"; +import { canvas, draw_rect, draw_texture_region, Texture } from "$/client/renderer/mod.ts"; import { AssetManager } from "../assets.ts"; -import { SLOT_SIZE } from "../../common/constants.ts"; +import { SLOT_SIZE, TEXTURE_SIZE } from "$/common/constants.ts"; import { draw_nine_slice } from "../systems/rendering/render_utils.ts"; +import { get_sprite_region } from "$/common/utils.ts"; const PADDING = 10; -export class GuiFurnace extends GuiInventoryScreen { +// crazy this is how i found out interface X {} is diffrent then type X = {} +type TileChestData = { + inventory: Inventory; + progress: number; + progress_max: number; + fuel: number; + fuel_max: number; +}; + +export class GuiFurnace extends GuiInventoryScreen { override inventory_width = PADDING * 2 + SLOT_SIZE * 9; override inventory_height = PADDING * 4 + SLOT_SIZE * 7; constructor( inventory: Inventory, player_inventory: PlayerInventory, - properties: { fuel: number; progress: number }, + properties: TileChestData, ) { super(inventory, player_inventory, properties); @@ -70,21 +80,8 @@ export class GuiFurnace extends GuiInventoryScreen("bworld:textures"); + + const fire_empty_region = get_sprite_region("bworld:fire_empty"); + const fire_full_region = get_sprite_region("bworld:fire_full"); + + const fuel_pct = Math.max(0, Math.min(1, this.properties.fuel / this.properties.fuel_max)); + const full_height = SLOT_SIZE * fuel_pct; + + const furnace_y = PADDING * 3 + SLOT_SIZE * 4; + + draw_texture_region( + atlas, + fire_empty_region.x * TEXTURE_SIZE, + fire_empty_region.y * TEXTURE_SIZE, + TEXTURE_SIZE, + TEXTURE_SIZE, + this.x + this.inventory_width / 2 - SLOT_SIZE, + this.y + furnace_y + SLOT_SIZE, + SLOT_SIZE, + SLOT_SIZE, + ); + + const fire_draw_x = this.x + this.inventory_width / 2 - SLOT_SIZE; + const fire_draw_y = this.y + furnace_y + SLOT_SIZE; + + const fire_src_height = TEXTURE_SIZE * fuel_pct; + + const fire_src_y_offset = TEXTURE_SIZE - fire_src_height; + const fire_dst_y_offset = SLOT_SIZE - full_height; + + draw_texture_region( + atlas, + fire_full_region.x * TEXTURE_SIZE, + fire_full_region.y * TEXTURE_SIZE + fire_src_y_offset, + TEXTURE_SIZE, + fire_src_height, + fire_draw_x, + fire_draw_y + fire_dst_y_offset, + SLOT_SIZE, + full_height, + ); + } + + draw_arrow() { + const atlas = AssetManager.instance.get("bworld:textures"); + + const arrow_empty_region = get_sprite_region("bworld:arrow_empty"); + const arrow_full_region = get_sprite_region("bworld:arrow_full"); + + const progress_pct = Math.max(0, Math.min(1, this.properties.progress / this.properties.progress_max)); + const full_width = SLOT_SIZE * progress_pct; + + const furnace_y = PADDING * 3 + SLOT_SIZE * 4; + + draw_texture_region( + atlas, + arrow_empty_region.x * TEXTURE_SIZE, + arrow_empty_region.y * TEXTURE_SIZE, + TEXTURE_SIZE, + TEXTURE_SIZE, + this.x + this.inventory_width / 2, + this.y + furnace_y + SLOT_SIZE, + SLOT_SIZE, + SLOT_SIZE, + ); + + const draw_x = this.x + this.inventory_width / 2; + const draw_y = this.y + furnace_y + SLOT_SIZE; + + const src_width = TEXTURE_SIZE * progress_pct; + + draw_texture_region( + atlas, + arrow_full_region.x * TEXTURE_SIZE, + arrow_full_region.y * TEXTURE_SIZE, + src_width, + TEXTURE_SIZE, + draw_x, + draw_y, + full_width, + SLOT_SIZE, + ); + } }