From 04cab305b078284d4fc075bb1137aa4b8199acf9 Mon Sep 17 00:00:00 2001 From: jordan4ibanez Date: Thu, 18 Apr 2024 01:33:25 -0400 Subject: [PATCH] Optimize --- source/hand/init.ts | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/source/hand/init.ts b/source/hand/init.ts index f1521929..4a19e75b 100644 --- a/source/hand/init.ts +++ b/source/hand/init.ts @@ -1,4 +1,10 @@ namespace hand { + + const optionWrap = utility.optionWrap; + type Option = utility.Option; + let warning = utility.warning; + + utility.registerNode("hand", { tiles: ["character.png"], visual_scale: 1, @@ -9,15 +15,17 @@ namespace hand { }) minetest.register_on_joinplayer((player: ObjectRef, _: string) => { - // If the player's inventory disappears, uh oh. - utility.optionWrap(player.get_inventory()) - .someFunction((inv: InvRef) => { + let result: Option = optionWrap(player.get_inventory()); + switch (result.is_some()) { + case true: { + const inv = result.unwrap(); inv.set_size("hand", 1); inv.set_stack("hand", 1, "hand"); - }) - .noneFunction(() => { - utility.warning("Player inventory disappeared when creating the 3D hand!"); - }) - }); + } + case false: { + warning("Player inventory disappeared when creating the 3D hand!"); + } + } + }) } \ No newline at end of file