From 48193a70e33dadbd0bceae89f1ecd70d29edee39 Mon Sep 17 00:00:00 2001 From: whosit Date: Thu, 15 Feb 2024 17:38:57 +0300 Subject: [PATCH] make this more java enterprise edition add some useless code --- init.lua | 170 ++++++--------------------------------------------- internal.lua | 156 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 174 insertions(+), 152 deletions(-) create mode 100644 internal.lua diff --git a/init.lua b/init.lua index 6f6f459..5dcb39b 100644 --- a/init.lua +++ b/init.lua @@ -1,156 +1,22 @@ -local COOLDOWN = 1.8 -local PARTICLE_TIME = COOLDOWN - 0.2 +local modname = minetest.get_current_modname() --- can't be bothered to figure out math for this --- map from param2 rotation to the face value -local V = { - 1, 1, 1, 1, - 2, 3, 4, 5, - 4, 5, 2, 3, - 5, 2, 3, 4, - 3, 4, 5, 2, - 6, 6, 6, 6, +local mod_start_time = minetest.get_us_time() +minetest.log("action", ("[MOD] %s loading"):format(modname)) + +local modpath = minetest.get_modpath(modname) .. DIR_DELIM + +yl_dice = { + information = { + version = "1.0.1", + author = "whosit", + license = "MIT", + name = modname, + source = "https://gitea.your-land.de/your-land/" .. modname, + additional = "This mod implements a simple dice block that players can roll", + }, } -local function roll_dice(pos, node) - if not node then - node = minetest.get_node(pos) - end +dofile(modpath .. "internal.lua") - local timer = minetest.get_node_timer(pos) - if timer:is_started() then - return - end - timer:start(COOLDOWN) - - local color = math.floor(node.param2 / 32) - local facedir = math.random(0, 23) - node.param2 = color * 32 + facedir - minetest.swap_node(pos, node) - - local spawner_def = { - size = 0.6, - amount = 42, - time = 0.7, - glow = 10, - pos = { - min = vector.add(pos, vector.new(-0.5, -0.5, -0.5)), - max = vector.add(pos, vector.new(0.5, 0.5, 0.5)), - }, - vel = { - min = { x = 2, y = 3, z = 2 }, - - max = { x = -2, y = 1, z = -2 }, - }, - acc = { - min = { x = 0, y = 10, z = 0 }, - max = { x = 0, y = 10, z = 0 }, - }, - exptime = { min = 0.2, max = 0.5, }, - vertical = false, - texture = "yl_dice_6sides.png", - animation = { - type = "sheet_2d", - frames_w = 2, - frames_h = 3, - frame_length = 0.1, - } - } - - minetest.add_particlespawner(spawner_def) - - local val = V[facedir + 1] or 0 - local particle_def = { - expirationtime = PARTICLE_TIME, - pos = vector.add(pos, vector.new(0.0, 0.8, 0.0)), - velocity = { x = 0, y = 0.1, z = 0 }, - glow = 14, - texture = ("yl_dice_%d.png"):format(val), - size = 4, - } - minetest.add_particle(particle_def) - - local spec = "default_dig_cracky" --"yl_dice_roll" - local parameters = { - pos = pos, - max_hear_distance = 32, -- default - pitch = 1.0 + 0.1*math.random(), - } - minetest.sound_play(spec, parameters, true) - - return val -end - -minetest.register_node("yl_dice:dice", { - description = "Dice", - drawtype = "mesh", - paramtype = "light", - paramtype2 = "colorfacedir", - mesh = "yl_dice6.obj", - tiles = { - "yl_dice_6sides.png", - }, - drop = { - items = { - { items = { "yl_dice:dice" }, inherit_color = true }, - } - }, - inventory_image = "yl_dice_3.png", - wield_image = "yl_dice_3.png", - groups = { dig_immediate = 2 }, - palette = "yl_dice_6_palette.png", - - on_construct = function(pos) - local val = roll_dice(pos) - minetest.log("action", ("[yl_dice] placed d6 has rolled %s at %s"):format(val, minetest.pos_to_string(pos))) - end, - on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) - local val = roll_dice(pos, node) - if val then - -- `val` is nil when cooldown has not ended yet - local name = clicker and clicker:is_player() and clicker:get_player_name() or "UNKNOWN" - minetest.log("action", ("[yl_dice] %s has rolled %s by using d6 at %s"):format(name, val, minetest.pos_to_string(pos))) - end - end, -}) - -local BASE_BLOCK - -if minetest.registered_items["yl_nether:ivory_block"] then - BASE_BLOCK = "yl_nether:ivory_block" -end - -if BASE_BLOCK then - minetest.register_craft({ - type = "shaped", - output = minetest.itemstring_with_palette("yl_dice:dice", 0), - recipe = { - { BASE_BLOCK, "dye:black", "" }, - { "", "", "" }, - { "", "", "" }, - } - }) -end - -if minetest.registered_items["dye:red"] then - local colors = { - "red", - "blue", - "violet", - "orange", - "yellow", - "green", - "cyan", - } - for i, color in ipairs(colors) do - minetest.register_craft({ - type = "shaped", - output = minetest.itemstring_with_palette("yl_dice:dice", 32 * i), - recipe = { - { "yl_dice:dice", "dye:" .. color, "" }, - { "", "", "" }, - { "", "", "" }, - } - }) - end -end +local mod_end_time = (minetest.get_us_time() - mod_start_time) / 1000000 +minetest.log("action", ("[MOD] %s loaded in [%s]"):format(modname, mod_end_time)) diff --git a/internal.lua b/internal.lua new file mode 100644 index 0000000..6f6f459 --- /dev/null +++ b/internal.lua @@ -0,0 +1,156 @@ +local COOLDOWN = 1.8 +local PARTICLE_TIME = COOLDOWN - 0.2 + +-- can't be bothered to figure out math for this +-- map from param2 rotation to the face value +local V = { + 1, 1, 1, 1, + 2, 3, 4, 5, + 4, 5, 2, 3, + 5, 2, 3, 4, + 3, 4, 5, 2, + 6, 6, 6, 6, +} + +local function roll_dice(pos, node) + if not node then + node = minetest.get_node(pos) + end + + local timer = minetest.get_node_timer(pos) + if timer:is_started() then + return + end + timer:start(COOLDOWN) + + local color = math.floor(node.param2 / 32) + local facedir = math.random(0, 23) + node.param2 = color * 32 + facedir + minetest.swap_node(pos, node) + + local spawner_def = { + size = 0.6, + amount = 42, + time = 0.7, + glow = 10, + pos = { + min = vector.add(pos, vector.new(-0.5, -0.5, -0.5)), + max = vector.add(pos, vector.new(0.5, 0.5, 0.5)), + }, + vel = { + min = { x = 2, y = 3, z = 2 }, + + max = { x = -2, y = 1, z = -2 }, + }, + acc = { + min = { x = 0, y = 10, z = 0 }, + max = { x = 0, y = 10, z = 0 }, + }, + exptime = { min = 0.2, max = 0.5, }, + vertical = false, + texture = "yl_dice_6sides.png", + animation = { + type = "sheet_2d", + frames_w = 2, + frames_h = 3, + frame_length = 0.1, + } + } + + minetest.add_particlespawner(spawner_def) + + local val = V[facedir + 1] or 0 + local particle_def = { + expirationtime = PARTICLE_TIME, + pos = vector.add(pos, vector.new(0.0, 0.8, 0.0)), + velocity = { x = 0, y = 0.1, z = 0 }, + glow = 14, + texture = ("yl_dice_%d.png"):format(val), + size = 4, + } + minetest.add_particle(particle_def) + + local spec = "default_dig_cracky" --"yl_dice_roll" + local parameters = { + pos = pos, + max_hear_distance = 32, -- default + pitch = 1.0 + 0.1*math.random(), + } + minetest.sound_play(spec, parameters, true) + + return val +end + +minetest.register_node("yl_dice:dice", { + description = "Dice", + drawtype = "mesh", + paramtype = "light", + paramtype2 = "colorfacedir", + mesh = "yl_dice6.obj", + tiles = { + "yl_dice_6sides.png", + }, + drop = { + items = { + { items = { "yl_dice:dice" }, inherit_color = true }, + } + }, + inventory_image = "yl_dice_3.png", + wield_image = "yl_dice_3.png", + groups = { dig_immediate = 2 }, + palette = "yl_dice_6_palette.png", + + on_construct = function(pos) + local val = roll_dice(pos) + minetest.log("action", ("[yl_dice] placed d6 has rolled %s at %s"):format(val, minetest.pos_to_string(pos))) + end, + on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) + local val = roll_dice(pos, node) + if val then + -- `val` is nil when cooldown has not ended yet + local name = clicker and clicker:is_player() and clicker:get_player_name() or "UNKNOWN" + minetest.log("action", ("[yl_dice] %s has rolled %s by using d6 at %s"):format(name, val, minetest.pos_to_string(pos))) + end + end, +}) + +local BASE_BLOCK + +if minetest.registered_items["yl_nether:ivory_block"] then + BASE_BLOCK = "yl_nether:ivory_block" +end + +if BASE_BLOCK then + minetest.register_craft({ + type = "shaped", + output = minetest.itemstring_with_palette("yl_dice:dice", 0), + recipe = { + { BASE_BLOCK, "dye:black", "" }, + { "", "", "" }, + { "", "", "" }, + } + }) +end + +if minetest.registered_items["dye:red"] then + local colors = { + "red", + "blue", + "violet", + "orange", + "yellow", + "green", + "cyan", + } + for i, color in ipairs(colors) do + minetest.register_craft({ + type = "shaped", + output = minetest.itemstring_with_palette("yl_dice:dice", 32 * i), + recipe = { + { "yl_dice:dice", "dye:" .. color, "" }, + { "", "", "" }, + { "", "", "" }, + } + }) + end +end