From 3851b26290b880517189868b37f0eca47d553062 Mon Sep 17 00:00:00 2001 From: jordan4ibanez Date: Tue, 14 Nov 2023 07:09:15 -0500 Subject: [PATCH] I like this approach better --- minetest-api.d.ts | 12 ++++++------ mods/blocks/normal.lua | 9 ++++++++- mods/blocks/normal.ts | 17 ++++++++++++++++- mods/testing/init.lua | 3 --- mods/testing/init.ts | 16 ---------------- mods/tools/init.lua | 10 ++++++++++ mods/tools/init.ts | 30 ++++++++++++++++++++++++++++++ mods/tools/mod.conf | 4 ++++ 8 files changed, 74 insertions(+), 27 deletions(-) create mode 100644 mods/tools/init.lua create mode 100644 mods/tools/init.ts create mode 100644 mods/tools/mod.conf diff --git a/minetest-api.d.ts b/minetest-api.d.ts index 368c65d0..b2fb8ed3 100644 --- a/minetest-api.d.ts +++ b/minetest-api.d.ts @@ -557,15 +557,15 @@ declare global { } export interface ItemDropSpec { - tools: string[] - rarity: number - items: string[] - inherit_color: boolean - tool_groups: string | string[] + tools?: string[] + rarity?: number + items?: string[] + inherit_color?: boolean + tool_groups?: string[] | string[][] } export interface NodeDropSpec { - max_items: number + max_items?: number items: ItemDropSpec[] } diff --git a/mods/blocks/normal.lua b/mods/blocks/normal.lua index 6cf6f1c3..66616b6b 100644 --- a/mods/blocks/normal.lua +++ b/mods/blocks/normal.lua @@ -1,6 +1,7 @@ Blocks = Blocks or ({}) do local sounds = Sounds + local pickaxe = Tools.Pickaxe minetest.register_node( ":stone", { @@ -8,7 +9,13 @@ do tiles = {"default_stone.png"}, sounds = sounds.stone(), groups = {stone = 1}, - drop = "cobblestone" + drop = {items = {{tool_groups = { + pickaxe.A, + pickaxe.B, + pickaxe.C, + pickaxe.D, + pickaxe.E + }, items = {"stone"}}}} } ) minetest.register_node( diff --git a/mods/blocks/normal.ts b/mods/blocks/normal.ts index 3452a749..855899de 100644 --- a/mods/blocks/normal.ts +++ b/mods/blocks/normal.ts @@ -1,5 +1,6 @@ namespace Blocks { const sounds = Sounds; + const pickaxe = Tools.Pickaxe; minetest.register_node(":stone", { drawtype: Drawtype.normal, @@ -8,7 +9,21 @@ namespace Blocks { groups: { stone: 1 }, - drop: "cobblestone" + + drop: { + items: [ + { + tool_groups: [ + pickaxe.A, + pickaxe.B, + pickaxe.C, + pickaxe.D, + pickaxe.E + ], + items: ["stone"] + } + ] + } }) minetest.register_node(":cobblestone", { diff --git a/mods/testing/init.lua b/mods/testing/init.lua index ddaaf5c5..89746f11 100644 --- a/mods/testing/init.lua +++ b/mods/testing/init.lua @@ -1,4 +1 @@ Testing = Testing or ({}) -do - minetest.register_tool(":pickaxe", {inventory_image = "default_tool_stonepick.png", tool_capabilities = {full_punch_interval = 0.5, max_drop_level = 1, groupcaps = {stone = {times = {[1] = 1}, maxlevel = 1, maxdrop = 0}}}}) -end diff --git a/mods/testing/init.ts b/mods/testing/init.ts index dbbbac73..145cd1ad 100644 --- a/mods/testing/init.ts +++ b/mods/testing/init.ts @@ -2,20 +2,4 @@ namespace Testing { // minetest.register_globalstep((delta: number) => { // print(`globalstep is: ${delta}`) // }) - minetest.register_tool(":pickaxe", { - inventory_image: "default_tool_stonepick.png", - tool_capabilities: { - full_punch_interval: 0.5, - max_drop_level: 1, - groupcaps: { - stone: { - times: { - 1: 1.0 - }, - maxlevel: 1, - maxdrop: 0 - } - } - } - }) } \ No newline at end of file diff --git a/mods/tools/init.lua b/mods/tools/init.lua new file mode 100644 index 00000000..6eca5a68 --- /dev/null +++ b/mods/tools/init.lua @@ -0,0 +1,10 @@ +Tools = Tools or ({}) +do + Tools.Pickaxe = Pickaxe or ({}) + Tools.Pickaxe.A = "pickaxe_1" + Tools.Pickaxe.B = "pickaxe_2" + Tools.Pickaxe.C = "pickaxe_3" + Tools.Pickaxe.D = "pickaxe_4" + Tools.Pickaxe.E = "pickaxe_5" + minetest.register_tool(":pickaxe", {inventory_image = "default_tool_stonepick.png", tool_capabilities = {full_punch_interval = 0.5, max_drop_level = 1, groupcaps = {stone = {times = {[1] = 1}, maxlevel = 1, maxdrop = 0}}}, groups = {[Tools.Pickaxe.A] = 1}}) +end diff --git a/mods/tools/init.ts b/mods/tools/init.ts new file mode 100644 index 00000000..47c83306 --- /dev/null +++ b/mods/tools/init.ts @@ -0,0 +1,30 @@ +namespace Tools { + // Alphabetical ordering, A = 1, B = 2, etc + export enum Pickaxe { + A = "pickaxe_1", + B = "pickaxe_2", + C = "pickaxe_3", + D = "pickaxe_4", + E = "pickaxe_5" + } + + minetest.register_tool(":pickaxe", { + inventory_image: "default_tool_stonepick.png", + tool_capabilities: { + full_punch_interval: 0.5, + max_drop_level: 1, + groupcaps: { + stone: { + times: { + 1: 1.0 + }, + maxlevel: 1, + maxdrop: 0 + } + } + }, + groups: { + [Pickaxe.A]: 1 + } + }) +} \ No newline at end of file diff --git a/mods/tools/mod.conf b/mods/tools/mod.conf new file mode 100644 index 00000000..ff550e45 --- /dev/null +++ b/mods/tools/mod.conf @@ -0,0 +1,4 @@ +name = tools +description = Forgotten Lands tools library. +depends = sounds, utility +optional_depends = \ No newline at end of file