From 80b21759d9bed3060b6dcff49c6e3cd403f70a82 Mon Sep 17 00:00:00 2001 From: Johannes Fritz Date: Wed, 26 Jul 2023 09:56:13 -0500 Subject: [PATCH 01/82] Remove mcl_base_textures mod --- mods/HUD/mcl_base_textures/init.lua | 1 - mods/HUD/mcl_base_textures/mod.conf | 3 --- 2 files changed, 4 deletions(-) delete mode 100644 mods/HUD/mcl_base_textures/init.lua delete mode 100644 mods/HUD/mcl_base_textures/mod.conf diff --git a/mods/HUD/mcl_base_textures/init.lua b/mods/HUD/mcl_base_textures/init.lua deleted file mode 100644 index 643c51108..000000000 --- a/mods/HUD/mcl_base_textures/init.lua +++ /dev/null @@ -1 +0,0 @@ --- This mod has no code and is only a collection of textures. diff --git a/mods/HUD/mcl_base_textures/mod.conf b/mods/HUD/mcl_base_textures/mod.conf deleted file mode 100644 index b36dccfe4..000000000 --- a/mods/HUD/mcl_base_textures/mod.conf +++ /dev/null @@ -1,3 +0,0 @@ -name = mcl_base_textures -author = Wuzzy -description = Provides core textures needed by Minetest. From a99daf429443ebfe146a9ad6dcbda2aa8a21af53 Mon Sep 17 00:00:00 2001 From: Nicu Date: Sun, 30 Jul 2023 09:16:02 +0000 Subject: [PATCH 02/82] Fixed typo in mcl_damage Fixed typo that invalidated the cached reason for damage --- mods/CORE/mcl_damage/init.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mods/CORE/mcl_damage/init.lua b/mods/CORE/mcl_damage/init.lua index 8804b8561..f6058dbaa 100644 --- a/mods/CORE/mcl_damage/init.lua +++ b/mods/CORE/mcl_damage/init.lua @@ -96,8 +96,8 @@ function mcl_damage.finish_reason(mcl_reason) end function mcl_damage.from_mt(mt_reason) - if mt_reason._mcl_chached_reason then - return mt_reason._mcl_chached_reason + if mt_reason._mcl_cached_reason then + return mt_reason._mcl_cached_reason end local mcl_reason From a3bbb3694c572786ea815289cb852a87550bcc45 Mon Sep 17 00:00:00 2001 From: codiac Date: Thu, 27 Jul 2023 21:27:51 +1000 Subject: [PATCH 03/82] Allow villager to claim filled cauldrons. Fixes #3733 --- mods/ENTITIES/mobs_mc/villager.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mods/ENTITIES/mobs_mc/villager.lua b/mods/ENTITIES/mobs_mc/villager.lua index 8fc18ccab..7db8a8306 100644 --- a/mods/ENTITIES/mobs_mc/villager.lua +++ b/mods/ENTITIES/mobs_mc/villager.lua @@ -351,7 +351,7 @@ local professions = { leatherworker = { name = N("Leatherworker"), texture = "mobs_mc_villager_leatherworker.png", - jobsite = "mcl_cauldrons:cauldron", + jobsite = "group:cauldron", trades = { { { { "mcl_mobitems:leather", 9, 12 }, E1 }, @@ -1007,8 +1007,9 @@ end ----- JOBSITE LOGIC local function get_profession_by_jobsite(js) + local is_cauldron = string.find(js, "mcl_cauldrons:cauldron") for k,v in pairs(professions) do - if v.jobsite == js then return k end + if v.jobsite == js or (is_cauldron and v.jobsite == "group:cauldron") then return k end end end From 4f2cb955b895f2e265da222986c3a5a227e76145 Mon Sep 17 00:00:00 2001 From: codiac Date: Fri, 4 Aug 2023 11:24:07 +1000 Subject: [PATCH 04/82] Use minetest.get_item_group for more flexibility --- mods/ENTITIES/mobs_mc/villager.lua | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/mods/ENTITIES/mobs_mc/villager.lua b/mods/ENTITIES/mobs_mc/villager.lua index 7db8a8306..96c5c7233 100644 --- a/mods/ENTITIES/mobs_mc/villager.lua +++ b/mods/ENTITIES/mobs_mc/villager.lua @@ -1007,9 +1007,16 @@ end ----- JOBSITE LOGIC local function get_profession_by_jobsite(js) - local is_cauldron = string.find(js, "mcl_cauldrons:cauldron") for k,v in pairs(professions) do - if v.jobsite == js or (is_cauldron and v.jobsite == "group:cauldron") then return k end + if v.jobsite == js then + return k + -- Catch Nitwit doesn't have a jobsite + elseif v.jobsite and v.jobsite:find("^group:") then + local group = v.jobsite:gsub("^group:", "") + if minetest.get_item_group(js, group) > 0 then + return k + end + end end end From a6096395855f714c696518b619213853fe89ab97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikita=20Wi=C5=9Bniewski?= Date: Wed, 9 Aug 2023 12:02:04 +0700 Subject: [PATCH 05/82] Add spaces after #, make the commands monospaced --- MODELS.md | 23 ++++++++++++++--------- RELEASE.md | 18 ++++++++++++------ 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/MODELS.md b/MODELS.md index 4b9094c33..663313f30 100644 --- a/MODELS.md +++ b/MODELS.md @@ -1,13 +1,14 @@ -#Models in Minetest/Mineclone2 +# Models in Minetest/Mineclone2 Models are an important part of all entities & unique nodes in Mineclone2. They provide a 3 dimensional map of an object for which textures are then applied to. This document is for modders, it quickly highlights some important information for the software needed to open models in Mineclone2. ## Minetest Wiki + For more detailed information on actually using blender to create and modify models for Minetest/Mineclone2, please visit the Minetest wiki's page on using Blender [Here](https://wiki.minetest.net/Using_Blender) -##Recommended software +## Recommended software -###Blender +### Blender Blender is a very popular and free modeling software supported on Windows, MacOS, and most Linux distributions. It is recommended to use Blender to create and modify 3D models within the minetest engine. @@ -19,14 +20,16 @@ Blitz 3D (.b3d) Is one of the main animated model formats used for entities in t The most up to date version of this Blender plugin can be downloaded [Here](https://github.com/GreenXenith/io_scene_b3d/releases/tag/f189786) -##Types of model formats +## Types of model formats + +### Animated, skinned models -###Animated, skinned models * Blitz 3D files (.b3d) * Microsoft DirectX (.x) (binary & text, compression is not supported) -###Static meshes +### Static meshes + * Wavefront OBJ (.obj) Note: The sometimes accompanying .mtl files are not supported and can safely be deleted. @@ -45,16 +48,18 @@ Note: Do not use .b3d and .x files for static meshes at the moment, Minetest cur Note: Any formats not mentioned above but known to work in the past were removed in 5.5.0 and aren't supported anymore. -##Pros & Cons of .b3d vs .x +## Pros & Cons of .b3d vs .x + +### B3D -###B3D * [+] Binary format means a small size * [-] Difficult to postprocess after exporting * [-] Difficult to debug problems -###X (text version) +### X (text version) + * [+] Can be parsed easily with lua scripts * [+] Can be easily generated by scripts diff --git a/RELEASE.md b/RELEASE.md index 52be92b6c..3984c4c84 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -1,10 +1,11 @@ ### Standard Release -#File to document release steps with a view to evolving into a script +# File to document release steps with a view to evolving into a script -#Update CREDITS.md -#Update version in game.conf +# Update CREDITS.md +# Update version in game.conf +``` lua tools/generate_ingame_credits.lua git add CREDITS.md @@ -18,10 +19,11 @@ git commit -m "Pre-release update credits and set version 0.83.0" git tag 0.83.0 git push origin 0.83.0 +``` -#Update version in game.conf to the next version with -SNAPSHOT suffix +# Update version in game.conf to the next version with -SNAPSHOT suffix -git commit -m "Post-release set version 0.84.0-SNAPSHOT" +`git commit -m "Post-release set version 0.84.0-SNAPSHOT"` ### Hotfix Release @@ -32,15 +34,17 @@ To mitigate this, you just release the last release, and the relevant bug fix. F * Create release branch from the last release tag, push it: +``` git checkout -b release/0.82.1 0.82.0 git push origin release/0.82.1 +``` ##### Prepare feature branch and fix * Create feature branch from that release branch (can review it to check only fix is there, nothing else, and use to also merge into master separately) -git checkout -b hotfix_bug_1_branch +`git checkout -b hotfix_bug_1_branch` * Fix crash/serious bug and commit * Push branch and create pr to the release and also the master branch (Do not rebase, to reduce merge conflict risk. Do not delete after first merge or it needs to be repushed) @@ -53,11 +57,13 @@ git checkout -b hotfix_bug_1_branch * Tag it, push tag and branch: +``` git tag 0.82.1 git push origin 0.82.1 git push origin release/0.82.1 +``` Note: If you have to do more than 1 hotfix release, can do it on the same release branch. From f884de5f87edf3351fec1bf7c8ec4651dd87a873 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikita=20Wi=C5=9Bniewski?= Date: Wed, 9 Aug 2023 12:06:50 +0700 Subject: [PATCH 06/82] Fix a link and a typo in LEGAL.md --- LEGAL.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/LEGAL.md b/LEGAL.md index aace346bf..e378c1b59 100644 --- a/LEGAL.md +++ b/LEGAL.md @@ -38,11 +38,11 @@ No non-free licenses are used anywhere. The textures, unless otherwise noted, are based on the Pixel Perfection resource pack for Minecraft 1.11, authored by XSSheep. Most textures are verbatim copies, while some textures have been changed or redone from scratch. -The glazed terracotta textures have been created by (MysticTempest)[https://github.com/MysticTempest]. +The glazed terracotta textures have been created by [MysticTempest](https://github.com/MysticTempest). Source: License: [CC BY-SA 4.0](http://creativecommons.org/licenses/by-sa/4.0/) -The main menu images are release under: [CC0](https://creativecommons.org/publicdomain/zero/1.0/) +The main menu images are released under: [CC0](https://creativecommons.org/publicdomain/zero/1.0/) All other files, unless mentioned otherwise, fall under: Creative Commons Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) From 6ae597c97fb2bfade939d80af8bab7ad337f0334 Mon Sep 17 00:00:00 2001 From: codiac Date: Sat, 12 Aug 2023 14:01:26 +1000 Subject: [PATCH 07/82] This changes mob floating so they stay inside the top water node instead of standing on it. The head of the mod should still be above water. Changes drowning so that mobs will not drown in one block of water. They will drown in 2 or more blocks of water. Does not appear to affect them getting out of deep water :( But they do seem to die somewhat faster when they stay in deep water. --- mods/ENTITIES/mcl_mobs/physics.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/physics.lua b/mods/ENTITIES/mcl_mobs/physics.lua index e1b23d78a..e49da2633 100644 --- a/mods/ENTITIES/mcl_mobs/physics.lua +++ b/mods/ENTITIES/mcl_mobs/physics.lua @@ -675,6 +675,9 @@ function mob_class:do_env_damage() self.standing_in = node_ok(pos, "air").name self.standing_on = node_ok(pos2, "air").name + local pos3 = {x=pos.x, y=pos.y+1, z=pos.z} + self.standing_under = node_ok(pos3, "air").name + -- don't fall when on ignore, just stand still if self.standing_in == "ignore" then self.object:set_velocity({x = 0, y = 0, z = 0}) @@ -682,6 +685,7 @@ function mob_class:do_env_damage() local nodef = minetest.registered_nodes[self.standing_in] local nodef2 = minetest.registered_nodes[self.standing_on] + local nodef3 = minetest.registered_nodes[self.standing_under] -- rain if self.rain_damage > 0 then @@ -761,7 +765,7 @@ function mob_class:do_env_damage() if minetest.get_item_group(self.standing_in, "water") == 0 then drowning = true end - elseif nodef.drowning > 0 then + elseif nodef.drowning > 0 and nodef3.drowning > 0 then drowning = true end @@ -939,7 +943,7 @@ function mob_class:falling(pos) -- in water then float up if registered_node.groups.water then - if acc and self.floats == 1 then + if acc and self.floats == 1 and minetest.registered_nodes[node_ok(vector.offset(pos,0,self.collisionbox[5],0)).name].groups.water then self.object:set_acceleration(vector.new(0, -self.fall_speed / (math.max(1, v.y) ^ 2), 0)) end else From 898a183ccdd7d267a93d2462f79a609180dad068 Mon Sep 17 00:00:00 2001 From: cora Date: Sat, 12 Aug 2023 08:36:24 +0200 Subject: [PATCH 08/82] Prevent floating mobs from drowning all the time Less dieing for mobs in deep water. --- mods/ENTITIES/mcl_mobs/physics.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ENTITIES/mcl_mobs/physics.lua b/mods/ENTITIES/mcl_mobs/physics.lua index e49da2633..32ebc75cd 100644 --- a/mods/ENTITIES/mcl_mobs/physics.lua +++ b/mods/ENTITIES/mcl_mobs/physics.lua @@ -943,7 +943,7 @@ function mob_class:falling(pos) -- in water then float up if registered_node.groups.water then - if acc and self.floats == 1 and minetest.registered_nodes[node_ok(vector.offset(pos,0,self.collisionbox[5],0)).name].groups.water then + if acc and minetest.registered_nodes[node_ok(vector.offset(pos,0,self.collisionbox[5] -0.25,0)).name].groups.water then self.object:set_acceleration(vector.new(0, -self.fall_speed / (math.max(1, v.y) ^ 2), 0)) end else From 034382c883690dd3c22f6869494bfcdf5c30ea6f Mon Sep 17 00:00:00 2001 From: codiac Date: Sun, 13 Aug 2023 12:14:52 +1000 Subject: [PATCH 09/82] Fix float check :( --- mods/ENTITIES/mcl_mobs/physics.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ENTITIES/mcl_mobs/physics.lua b/mods/ENTITIES/mcl_mobs/physics.lua index 32ebc75cd..0f3334367 100644 --- a/mods/ENTITIES/mcl_mobs/physics.lua +++ b/mods/ENTITIES/mcl_mobs/physics.lua @@ -943,7 +943,7 @@ function mob_class:falling(pos) -- in water then float up if registered_node.groups.water then - if acc and minetest.registered_nodes[node_ok(vector.offset(pos,0,self.collisionbox[5] -0.25,0)).name].groups.water then + if acc and self.floats == 1 minetest.registered_nodes[node_ok(vector.offset(pos,0,self.collisionbox[5] -0.25,0)).name].groups.water then self.object:set_acceleration(vector.new(0, -self.fall_speed / (math.max(1, v.y) ^ 2), 0)) end else From 8c64fdfa5db0cef33f7bf9c70444810825d9e1d0 Mon Sep 17 00:00:00 2001 From: codiac Date: Sun, 13 Aug 2023 14:02:15 +1000 Subject: [PATCH 10/82] Enable enchanting on sheers & allow enchanted shears to shear. --- mods/ENTITIES/mobs_mc/cow+mooshroom.lua | 2 +- mods/ENTITIES/mobs_mc/sheep.lua | 2 +- mods/ENTITIES/mobs_mc/snowman.lua | 2 +- mods/ITEMS/mcl_beehives/init.lua | 2 +- mods/ITEMS/mcl_tools/init.lua | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/mods/ENTITIES/mobs_mc/cow+mooshroom.lua b/mods/ENTITIES/mobs_mc/cow+mooshroom.lua index 64f74c516..9d1aa1aaa 100644 --- a/mods/ENTITIES/mobs_mc/cow+mooshroom.lua +++ b/mods/ENTITIES/mobs_mc/cow+mooshroom.lua @@ -105,7 +105,7 @@ mooshroom_def.on_rightclick = function(self, clicker) end local item = clicker:get_wielded_item() -- Use shears to get mushrooms and turn mooshroom into cow - if item:get_name() == "mcl_tools:shears" then + if minetest.get_item_group(item:get_name(), "shears") > 0 then local pos = self.object:get_pos() minetest.sound_play("mcl_tools_shears_cut", {pos = pos}, true) diff --git a/mods/ENTITIES/mobs_mc/sheep.lua b/mods/ENTITIES/mobs_mc/sheep.lua index 6eaffa611..af1222403 100644 --- a/mods/ENTITIES/mobs_mc/sheep.lua +++ b/mods/ENTITIES/mobs_mc/sheep.lua @@ -234,7 +234,7 @@ mcl_mobs.register_mob("mobs_mc:sheep", { if self:feed_tame(clicker, 1, true, false) then return end if mcl_mobs:protect(self, clicker) then return end - if item:get_name() == "mcl_tools:shears" and not self.gotten and not self.child then + if minetest.get_item_group(item:get_name(), "shears") > 0 and not self.gotten and not self.child then self.gotten = true local pos = self.object:get_pos() minetest.sound_play("mcl_tools_shears_cut", {pos = pos}, true) diff --git a/mods/ENTITIES/mobs_mc/snowman.lua b/mods/ENTITIES/mobs_mc/snowman.lua index ec2a14675..0e5bc8d4b 100644 --- a/mods/ENTITIES/mobs_mc/snowman.lua +++ b/mods/ENTITIES/mobs_mc/snowman.lua @@ -114,7 +114,7 @@ mcl_mobs.register_mob("mobs_mc:snowman", { -- Remove pumpkin if using shears on_rightclick = function(self, clicker) local item = clicker:get_wielded_item() - if self.gotten ~= true and item:get_name() == "mcl_tools:shears" then + if self.gotten ~= true and inetest.get_item_group(item:get_name(), "shears") > 0 then -- Remove pumpkin self.gotten = true self.object:set_properties({ diff --git a/mods/ITEMS/mcl_beehives/init.lua b/mods/ITEMS/mcl_beehives/init.lua index 82b3cae5f..d20370ca7 100644 --- a/mods/ITEMS/mcl_beehives/init.lua +++ b/mods/ITEMS/mcl_beehives/init.lua @@ -8,7 +8,7 @@ local S = minetest.get_translator(minetest.get_current_modname()) -- Function to allow harvesting honey and honeycomb from the beehive and bee nest. local honey_harvest = function(pos, node, player, itemstack, pointed_thing) local inv = player:get_inventory() - local shears = player:get_wielded_item():get_name() == "mcl_tools:shears" + local shears = minetest.get_item_group(player:get_wielded_item():get_name(), "shears") > 0 local bottle = player:get_wielded_item():get_name() == "mcl_potions:glass_bottle" local beehive = "mcl_beehives:beehive" local is_creative = minetest.is_creative_enabled(player:get_player_name()) diff --git a/mods/ITEMS/mcl_tools/init.lua b/mods/ITEMS/mcl_tools/init.lua index 5f96fa3fa..2c17aa135 100644 --- a/mods/ITEMS/mcl_tools/init.lua +++ b/mods/ITEMS/mcl_tools/init.lua @@ -661,7 +661,7 @@ minetest.register_tool("mcl_tools:shears", { inventory_image = "default_tool_shears.png", wield_image = "default_tool_shears.png", stack_max = 1, - groups = { tool=1, shears=1, dig_speed_class=4, }, + groups = { tool=1, shears=1, dig_speed_class=4, enchantability=14, }, tool_capabilities = { full_punch_interval = 0.5, max_drop_level=1, From 246a95f9731b1d98a9270540217d399dbce21526 Mon Sep 17 00:00:00 2001 From: codiac Date: Mon, 14 Aug 2023 10:39:31 +1000 Subject: [PATCH 11/82] Fix typo --- mods/ENTITIES/mobs_mc/snowman.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ENTITIES/mobs_mc/snowman.lua b/mods/ENTITIES/mobs_mc/snowman.lua index 0e5bc8d4b..62b988b9a 100644 --- a/mods/ENTITIES/mobs_mc/snowman.lua +++ b/mods/ENTITIES/mobs_mc/snowman.lua @@ -114,7 +114,7 @@ mcl_mobs.register_mob("mobs_mc:snowman", { -- Remove pumpkin if using shears on_rightclick = function(self, clicker) local item = clicker:get_wielded_item() - if self.gotten ~= true and inetest.get_item_group(item:get_name(), "shears") > 0 then + if self.gotten ~= true and minetest.get_item_group(item:get_name(), "shears") > 0 then -- Remove pumpkin self.gotten = true self.object:set_properties({ From 0d16acdd423776deb955beb21e904e267f9611bf Mon Sep 17 00:00:00 2001 From: codiac Date: Mon, 14 Aug 2023 10:48:27 +1000 Subject: [PATCH 12/82] Use a vector and fix the merge fail >_< --- mods/ENTITIES/mcl_mobs/physics.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/physics.lua b/mods/ENTITIES/mcl_mobs/physics.lua index 0f3334367..341e28984 100644 --- a/mods/ENTITIES/mcl_mobs/physics.lua +++ b/mods/ENTITIES/mcl_mobs/physics.lua @@ -675,7 +675,7 @@ function mob_class:do_env_damage() self.standing_in = node_ok(pos, "air").name self.standing_on = node_ok(pos2, "air").name - local pos3 = {x=pos.x, y=pos.y+1, z=pos.z} + local pos3 = vector.offset(pos, 0, 1, 0) self.standing_under = node_ok(pos3, "air").name -- don't fall when on ignore, just stand still @@ -943,7 +943,7 @@ function mob_class:falling(pos) -- in water then float up if registered_node.groups.water then - if acc and self.floats == 1 minetest.registered_nodes[node_ok(vector.offset(pos,0,self.collisionbox[5] -0.25,0)).name].groups.water then + if acc and self.floats == 1 and minetest.registered_nodes[node_ok(vector.offset(pos,0,self.collisionbox[5] -0.25,0)).name].groups.water then self.object:set_acceleration(vector.new(0, -self.fall_speed / (math.max(1, v.y) ^ 2), 0)) end else From d7ea628270e27d687b54f3c9289dfdc387e6cd6c Mon Sep 17 00:00:00 2001 From: Sebastian Riedel Date: Mon, 14 Aug 2023 11:27:36 +0200 Subject: [PATCH 13/82] Revert reversion of 822071c66b30d9a1da3ae810d038bebdb65e101c --- mods/ENTITIES/mobs_mc/LICENSE-media.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mods/ENTITIES/mobs_mc/LICENSE-media.md b/mods/ENTITIES/mobs_mc/LICENSE-media.md index 4e3de49f1..c937097c9 100644 --- a/mods/ENTITIES/mobs_mc/LICENSE-media.md +++ b/mods/ENTITIES/mobs_mc/LICENSE-media.md @@ -191,9 +191,10 @@ Origin of those models: * [Spennnyyy](https://freesound.org/people/Spennnyyy/) (CC0) * `mcl_totems_totem.ogg` * Source: -* [Baŝto](https://opengameart.org/users/ba%C5%9Dto) +* [Baŝto](https://opengameart.org/users/ba%C5%9Dto) (remixer) and [kantouth](https://freesound.org/people/kantouth/) (original author) * `mobs_mc_skeleton_random.*.ogg` (CC BY 3.0) * Source: + * Based on: * [spookymodem](https://freesound.org/people/spookymodem/) * `mobs_mc_skeleton_death.ogg` (CC0) * @@ -307,4 +308,4 @@ Origin of those models: Note: Many of these sounds have been more or less modified to fit the game. -Sounds not mentioned hre are licensed under CC0. +Sounds not mentioned here are licensed under CC0. From 11d275a471c11ffeb13a363fe64ef1637e2aa5d8 Mon Sep 17 00:00:00 2001 From: Sebastian Riedel Date: Mon, 14 Aug 2023 12:57:36 +0200 Subject: [PATCH 14/82] Increase copper needed for blocks from 4 to 9 --- mods/ITEMS/mcl_copper/crafting.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mods/ITEMS/mcl_copper/crafting.lua b/mods/ITEMS/mcl_copper/crafting.lua index ce280fcdf..41084afb3 100644 --- a/mods/ITEMS/mcl_copper/crafting.lua +++ b/mods/ITEMS/mcl_copper/crafting.lua @@ -10,8 +10,9 @@ minetest.register_craft({ minetest.register_craft({ output = "mcl_copper:block", recipe = { - { "mcl_copper:copper_ingot", "mcl_copper:copper_ingot" }, - { "mcl_copper:copper_ingot", "mcl_copper:copper_ingot" }, + { "mcl_copper:copper_ingot", "mcl_copper:copper_ingot", "mcl_copper:copper_ingot" }, + { "mcl_copper:copper_ingot", "mcl_copper:copper_ingot", "mcl_copper:copper_ingot" }, + { "mcl_copper:copper_ingot", "mcl_copper:copper_ingot", "mcl_copper:copper_ingot" }, }, }) @@ -59,7 +60,7 @@ for _, w in ipairs(waxable_blocks) do end minetest.register_craft({ - output = "mcl_copper:copper_ingot 4", + output = "mcl_copper:copper_ingot 9", recipe = { { "mcl_copper:block" }, }, From dd96af15c44fe63cbb5eccfecd119434be237962 Mon Sep 17 00:00:00 2001 From: cora Date: Tue, 15 Aug 2023 04:09:02 +0200 Subject: [PATCH 15/82] Shears are not enchantable on enchanting table --- mods/ITEMS/mcl_tools/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_tools/init.lua b/mods/ITEMS/mcl_tools/init.lua index 2c17aa135..49863268e 100644 --- a/mods/ITEMS/mcl_tools/init.lua +++ b/mods/ITEMS/mcl_tools/init.lua @@ -661,7 +661,7 @@ minetest.register_tool("mcl_tools:shears", { inventory_image = "default_tool_shears.png", wield_image = "default_tool_shears.png", stack_max = 1, - groups = { tool=1, shears=1, dig_speed_class=4, enchantability=14, }, + groups = { tool=1, shears=1, dig_speed_class=4, enchantability=-1, }, tool_capabilities = { full_punch_interval = 0.5, max_drop_level=1, From 6756358307a6ba744677ed0b1cbcb6caf285fcf1 Mon Sep 17 00:00:00 2001 From: Johannes Fritz Date: Mon, 31 Jul 2023 10:04:41 -0500 Subject: [PATCH 16/82] Fix meshhand with mcl_skins disabled --- mods/PLAYER/mcl_meshhand/init.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mods/PLAYER/mcl_meshhand/init.lua b/mods/PLAYER/mcl_meshhand/init.lua index a28efd502..6d1177b18 100644 --- a/mods/PLAYER/mcl_meshhand/init.lua +++ b/mods/PLAYER/mcl_meshhand/init.lua @@ -85,16 +85,16 @@ function mcl_meshhand.update_player(player) end end +minetest.register_on_joinplayer(function(player) + player:get_inventory():set_size("hand", 1) +end) + if mcl_skins_enabled then mcl_player.register_on_visual_change(mcl_meshhand.update_player) else minetest.register_on_joinplayer(mcl_meshhand.update_player) end -minetest.register_on_joinplayer(function(player) - player:get_inventory():set_size("hand", 1) -end) - -- This is needed to deal damage when punching mobs -- with random items in hand in survival mode minetest.override_item("", { From ac4db102b2d99ce38c947a9f251e2a625330527f Mon Sep 17 00:00:00 2001 From: AFCMS Date: Sun, 25 Apr 2021 23:35:27 +0200 Subject: [PATCH 17/82] add basic temp function to get v4 itemslots --- mods/HUD/mcl_formspec/init.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/mods/HUD/mcl_formspec/init.lua b/mods/HUD/mcl_formspec/init.lua index 7013fc0ee..6418a23fd 100644 --- a/mods/HUD/mcl_formspec/init.lua +++ b/mods/HUD/mcl_formspec/init.lua @@ -9,3 +9,15 @@ function mcl_formspec.get_itemslot_bg(x, y, w, h) end return out end + +--This function will replace mcl_formspec.get_itemslot_bg then every formspec will be upgrade to version 4 +function mcl_formspec.get_itemslot_bg_v4(x, y, w, h) + local out = "" + for i = 0, w - 1, 1 do + for j = 0, h - 1, 1 do + out = out .."image["..x+i+(i*0.25)..","..y+j+(j*0.25)..";1,1;mcl_formspec_itemslot.png]" + end + end + return out +end + From 767c904258239c68b5602d4a820f721f5bbfdbac Mon Sep 17 00:00:00 2001 From: AFCMS Date: Fri, 17 Sep 2021 20:00:25 +0200 Subject: [PATCH 18/82] create some files --- mods/HUD/mcl_formspec/API.md | 0 mods/HUD/mcl_formspec/FORMSPEC_GUIDE.md | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 mods/HUD/mcl_formspec/API.md create mode 100644 mods/HUD/mcl_formspec/FORMSPEC_GUIDE.md diff --git a/mods/HUD/mcl_formspec/API.md b/mods/HUD/mcl_formspec/API.md new file mode 100644 index 000000000..e69de29bb diff --git a/mods/HUD/mcl_formspec/FORMSPEC_GUIDE.md b/mods/HUD/mcl_formspec/FORMSPEC_GUIDE.md new file mode 100644 index 000000000..e69de29bb From f20fbfb95af50cd794a92c03589a647f4be9b307 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Fri, 17 Sep 2021 23:58:58 +0200 Subject: [PATCH 19/82] ender chest formspec v4 --- mods/HUD/mcl_formspec/FORMSPEC_GUIDE.md | 20 ++++++++++ mods/HUD/mcl_formspec/init.lua | 24 ++++++++++-- mods/ITEMS/mcl_chests/init.lua | 50 +++++++++++++++---------- 3 files changed, 71 insertions(+), 23 deletions(-) diff --git a/mods/HUD/mcl_formspec/FORMSPEC_GUIDE.md b/mods/HUD/mcl_formspec/FORMSPEC_GUIDE.md index e69de29bb..337d203ea 100644 --- a/mods/HUD/mcl_formspec/FORMSPEC_GUIDE.md +++ b/mods/HUD/mcl_formspec/FORMSPEC_GUIDE.md @@ -0,0 +1,20 @@ +Formspecs are an important part of game and mod development. + +This guide will learn you rules about creation of formspecs for the MineClone2 game. + +First of all, MineClone2 aims to support ONLY last formspec version. Many utility functions will not work with formspec v1 or v2. + +Label font size should be 25 to be minecraft like. We arent modifying formspec prepend in order to not break existing mods. + +Just use this code to apply it to your formspec: +```lua +"style_type[label;font_size=25]", +``` + +The typical width of an inventory formspec is `0.375 + 9 + (9 * 0.25) + 0.375 = 12` + +Margins is 0.375 +Space between 1st inventory line and the rest of inventory is 0.4 + +Labels should have 0.375 space above if there is no other stuff above and 0.45 between content ++ 0.375 under \ No newline at end of file diff --git a/mods/HUD/mcl_formspec/init.lua b/mods/HUD/mcl_formspec/init.lua index 6418a23fd..1acf8b372 100644 --- a/mods/HUD/mcl_formspec/init.lua +++ b/mods/HUD/mcl_formspec/init.lua @@ -1,5 +1,12 @@ +local string = string +local table = table + +local sf = string.format + mcl_formspec = {} +mcl_formspec.label_color = "#313131" + function mcl_formspec.get_itemslot_bg(x, y, w, h) local out = "" for i = 0, w - 1, 1 do @@ -11,13 +18,22 @@ function mcl_formspec.get_itemslot_bg(x, y, w, h) end --This function will replace mcl_formspec.get_itemslot_bg then every formspec will be upgrade to version 4 -function mcl_formspec.get_itemslot_bg_v4(x, y, w, h) +local function get_slot(x, y, size) + local t = "image["..x-size..","..y-size..";".. 1+(size*2)..",".. 1+(size*2)..";mcl_formspec_itemslot.png]" + return t +end + +mcl_formspec.itemslot_border_size = 0.05 + +function mcl_formspec.get_itemslot_bg_v4(x, y, w, h, size) + if not size then + size = mcl_formspec.itemslot_border_size + end local out = "" for i = 0, w - 1, 1 do for j = 0, h - 1, 1 do - out = out .."image["..x+i+(i*0.25)..","..y+j+(j*0.25)..";1,1;mcl_formspec_itemslot.png]" + out = out .. get_slot(x+i+(i*0.25), y+j+(j*0.25), size) end end return out -end - +end \ No newline at end of file diff --git a/mods/ITEMS/mcl_chests/init.lua b/mods/ITEMS/mcl_chests/init.lua index 38437c73f..2169f488f 100644 --- a/mods/ITEMS/mcl_chests/init.lua +++ b/mods/ITEMS/mcl_chests/init.lua @@ -1,4 +1,6 @@ local S = minetest.get_translator(minetest.get_current_modname()) +local F = minetest.formspec_escape +local C = minetest.colorize local mod_doc = minetest.get_modpath("doc") -- Christmas chest setup @@ -492,10 +494,10 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile minetest.show_formspec(clicker:get_player_name(), "mcl_chests:"..canonical_basename.."_"..pos.x.."_"..pos.y.."_"..pos.z, "size[9,8.75]".. - "label[0,0;"..minetest.formspec_escape(minetest.colorize("#313131", name)).."]".. + "label[0,0;"..F(minetest.colorize("#313131", name)).."]".. "list[nodemeta:"..pos.x..","..pos.y..","..pos.z..";main;0,0.5;9,3;]".. mcl_formspec.get_itemslot_bg(0,0.5,9,3).. - "label[0,4.0;"..minetest.formspec_escape(minetest.colorize("#313131", S("Inventory"))).."]".. + "label[0,4.0;"..F(minetest.colorize("#313131", S("Inventory"))).."]".. "list[current_player;main;0,4.5;9,3;9]".. mcl_formspec.get_itemslot_bg(0,4.5,9,3).. "list[current_player;main;0,7.74;9,1;]".. @@ -643,12 +645,12 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile minetest.show_formspec(clicker:get_player_name(), "mcl_chests:"..canonical_basename.."_"..pos.x.."_"..pos.y.."_"..pos.z, "size[9,11.5]".. - "label[0,0;"..minetest.formspec_escape(minetest.colorize("#313131", name)).."]".. + "label[0,0;"..F(minetest.colorize("#313131", name)).."]".. "list[nodemeta:"..pos.x..","..pos.y..","..pos.z..";main;0,0.5;9,3;]".. mcl_formspec.get_itemslot_bg(0,0.5,9,3).. "list[nodemeta:"..pos_other.x..","..pos_other.y..","..pos_other.z..";main;0,3.5;9,3;]".. mcl_formspec.get_itemslot_bg(0,3.5,9,3).. - "label[0,7;"..minetest.formspec_escape(minetest.colorize("#313131", S("Inventory"))).."]".. + "label[0,7;"..F(minetest.colorize("#313131", S("Inventory"))).."]".. "list[current_player;main;0,7.5;9,3;9]".. mcl_formspec.get_itemslot_bg(0,7.5,9,3).. "list[current_player;main;0,10.75;9,1;]".. @@ -791,12 +793,12 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile "mcl_chests:"..canonical_basename.."_"..pos.x.."_"..pos.y.."_"..pos.z, "size[9,11.5]".. - "label[0,0;"..minetest.formspec_escape(minetest.colorize("#313131", name)).."]".. + "label[0,0;"..F(minetest.colorize("#313131", name)).."]".. "list[nodemeta:"..pos_other.x..","..pos_other.y..","..pos_other.z..";main;0,0.5;9,3;]".. mcl_formspec.get_itemslot_bg(0,0.5,9,3).. "list[nodemeta:"..pos.x..","..pos.y..","..pos.z..";main;0,3.5;9,3;]".. mcl_formspec.get_itemslot_bg(0,3.5,9,3).. - "label[0,7;"..minetest.formspec_escape(minetest.colorize("#313131", S("Inventory"))).."]".. + "label[0,7;"..F(minetest.colorize("#313131", S("Inventory"))).."]".. "list[current_player;main;0,7.5;9,3;9]".. mcl_formspec.get_itemslot_bg(0,7.5,9,3).. "list[current_player;main;0,10.75;9,1;]".. @@ -985,17 +987,27 @@ minetest.register_node("mcl_chests:ender_chest", { end, }) -local formspec_ender_chest = "size[9,8.75]".. - "label[0,0;"..minetest.formspec_escape(minetest.colorize("#313131", S("Ender Chest"))).."]".. - "list[current_player;enderchest;0,0.5;9,3;]".. - mcl_formspec.get_itemslot_bg(0,0.5,9,3).. - "label[0,4.0;"..minetest.formspec_escape(minetest.colorize("#313131", S("Inventory"))).."]".. - "list[current_player;main;0,4.5;9,3;9]".. - mcl_formspec.get_itemslot_bg(0,4.5,9,3).. - "list[current_player;main;0,7.74;9,1;]".. - mcl_formspec.get_itemslot_bg(0,7.74,9,1).. - "listring[current_player;enderchest]".. - "listring[current_player;main]" +local formspec_ender_chest = table.concat({ + "formspec_version[4]", + "size[12,10.375]", + "style_type[label;font_size=25]", + + "label[0.375,0.375;"..F(C(mcl_formspec.label_color, S("Ender Chest"))).."]", + + mcl_formspec.get_itemslot_bg_v4(0.375, 0.75, 9, 3), + "list[current_player;enderchest;0.375,0.75;9,3;]", + + "label[0.375,4.7;"..F(C(mcl_formspec.label_color, S("Inventory"))).."]", + + mcl_formspec.get_itemslot_bg_v4(0.375, 5.1, 9, 3), + "list[current_player;main;0.375,5.1;9,3;9]", + + mcl_formspec.get_itemslot_bg_v4(0.375, 9, 9, 1), + "list[current_player;main;0.375,9;9,1;]", + + "listring[current_player;enderchest]", + "listring[current_player;main]", +}) minetest.register_node("mcl_chests:ender_chest_small", { @@ -1118,10 +1130,10 @@ local function formspec_shulker_box(name) name = S("Shulker Box") end return "size[9,8.75]".. - "label[0,0;"..minetest.formspec_escape(minetest.colorize("#313131", name)).."]".. + "label[0,0;"..F(minetest.colorize("#313131", name)).."]".. "list[context;main;0,0.5;9,3;]".. mcl_formspec.get_itemslot_bg(0,0.5,9,3).. - "label[0,4.0;"..minetest.formspec_escape(minetest.colorize("#313131", S("Inventory"))).."]".. + "label[0,4.0;"..F(minetest.colorize("#313131", S("Inventory"))).."]".. "list[current_player;main;0,4.5;9,3;9]".. mcl_formspec.get_itemslot_bg(0,4.5,9,3).. "list[current_player;main;0,7.74;9,1;]".. From cf01c0630c9d798c32c049551f37bb1f205663a0 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Sat, 18 Sep 2021 00:36:33 +0200 Subject: [PATCH 20/82] chest + shulkerbox formspec --- mods/HUD/mcl_formspec/FORMSPEC_GUIDE.md | 6 +- mods/ITEMS/mcl_chests/init.lua | 132 +++++++++++++++--------- 2 files changed, 87 insertions(+), 51 deletions(-) diff --git a/mods/HUD/mcl_formspec/FORMSPEC_GUIDE.md b/mods/HUD/mcl_formspec/FORMSPEC_GUIDE.md index 337d203ea..6bb2e1424 100644 --- a/mods/HUD/mcl_formspec/FORMSPEC_GUIDE.md +++ b/mods/HUD/mcl_formspec/FORMSPEC_GUIDE.md @@ -11,10 +11,12 @@ Just use this code to apply it to your formspec: "style_type[label;font_size=25]", ``` -The typical width of an inventory formspec is `0.375 + 9 + (9 * 0.25) + 0.375 = 12` +The typical width of an inventory formspec is `0.375 + 9 + ((9-1) * 0.25) + 0.375 = 11.75` Margins is 0.375 Space between 1st inventory line and the rest of inventory is 0.4 Labels should have 0.375 space above if there is no other stuff above and 0.45 between content -+ 0.375 under \ No newline at end of file ++ 0.375 under + +According to minetest modding book, table.concat is faster than string concatenation, so this method should be prefered (the code is also more clear) \ No newline at end of file diff --git a/mods/ITEMS/mcl_chests/init.lua b/mods/ITEMS/mcl_chests/init.lua index 2169f488f..ad3db56ee 100644 --- a/mods/ITEMS/mcl_chests/init.lua +++ b/mods/ITEMS/mcl_chests/init.lua @@ -1,6 +1,13 @@ local S = minetest.get_translator(minetest.get_current_modname()) local F = minetest.formspec_escape local C = minetest.colorize + +local string = string +local table = table +local math = math + +local sf = string.format + local mod_doc = minetest.get_modpath("doc") -- Christmas chest setup @@ -52,7 +59,7 @@ local entity_animations = { speed = 25, open = {x = 0, y = 7}, close = {x = 13, y = 20}, - } + }, } minetest.register_entity("mcl_chests:chest", { @@ -240,7 +247,7 @@ local function chest_update_after_close(pos) local node = minetest.get_node(pos) if node.name == "mcl_chests:trapped_chest_on_small" then - minetest.swap_node(pos, {name="mcl_chests:trapped_chest_small", param2 = node.param2}) + minetest.swap_node(pos, {name = "mcl_chests:trapped_chest_small", param2 = node.param2}) find_or_create_entity(pos, "mcl_chests:trapped_chest_small", {"mcl_chests_trapped.png"}, node.param2, false, "default_chest", "mcl_chests_chest", "chest"):reinitialize("mcl_chests:trapped_chest_small") mesecon.receptor_off(pos, trapped_chest_mesecons_rules) elseif node.name == "mcl_chests:trapped_chest_on_left" then @@ -249,10 +256,10 @@ local function chest_update_after_close(pos) mesecon.receptor_off(pos, trapped_chest_mesecons_rules) local pos_other = mcl_util.get_double_container_neighbor_pos(pos, node.param2, "left") - minetest.swap_node(pos_other, {name="mcl_chests:trapped_chest_right", param2 = node.param2}) + minetest.swap_node(pos_other, {name = "mcl_chests:trapped_chest_right", param2 = node.param2}) mesecon.receptor_off(pos_other, trapped_chest_mesecons_rules) elseif node.name == "mcl_chests:trapped_chest_on_right" then - minetest.swap_node(pos, {name="mcl_chests:trapped_chest_right", param2 = node.param2}) + minetest.swap_node(pos, {name = "mcl_chests:trapped_chest_right", param2 = node.param2}) mesecon.receptor_off(pos, trapped_chest_mesecons_rules) local pos_other = mcl_util.get_double_container_neighbor_pos(pos, node.param2, "right") @@ -492,18 +499,29 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile end minetest.show_formspec(clicker:get_player_name(), - "mcl_chests:"..canonical_basename.."_"..pos.x.."_"..pos.y.."_"..pos.z, - "size[9,8.75]".. - "label[0,0;"..F(minetest.colorize("#313131", name)).."]".. - "list[nodemeta:"..pos.x..","..pos.y..","..pos.z..";main;0,0.5;9,3;]".. - mcl_formspec.get_itemslot_bg(0,0.5,9,3).. - "label[0,4.0;"..F(minetest.colorize("#313131", S("Inventory"))).."]".. - "list[current_player;main;0,4.5;9,3;9]".. - mcl_formspec.get_itemslot_bg(0,4.5,9,3).. - "list[current_player;main;0,7.74;9,1;]".. - mcl_formspec.get_itemslot_bg(0,7.74,9,1).. - "listring[nodemeta:"..pos.x..","..pos.y..","..pos.z..";main]".. - "listring[current_player;main]") + sf("mcl_chests:%s_%s_%s_%s", canonical_basename, pos.x, pos.y, pos.z), + table.concat({ + "formspec_version[4]", + "size[11.75,10.375]", + "style_type[label;font_size=25]", + + "label[0.375,0.375;"..F(C(mcl_formspec.label_color, name)).."]", + + mcl_formspec.get_itemslot_bg_v4(0.375, 0.75, 9, 3), + sf("list[nodemeta:%s,%s,%s;main;0.375,0.75;9,3;]", pos.x, pos.y, pos.z), + + "label[0.375,4.7;"..F(C(mcl_formspec.label_color, S("Inventory"))).."]", + + mcl_formspec.get_itemslot_bg_v4(0.375, 5.1, 9, 3), + "list[current_player;main;0.375,5.1;9,3;9]", + + mcl_formspec.get_itemslot_bg_v4(0.375, 9, 9, 1), + "list[current_player;main;0.375,9;9,1;]", + + sf("listring[nodemeta:%s,%s,%s;main]", pos.x, pos.y, pos.z), + "listring[current_player;main]", + }) + ) if on_rightclick_addendum then on_rightclick_addendum(pos, node, clicker) @@ -856,10 +874,12 @@ register_chest("trapped_chest", S("27 inventory slots") .. "\n" .. S("Can be combined to a large chest") .. "\n" .. S("Emits a redstone signal when opened"), traptiles, nil, - {receptor = { - state = mesecon.state.off, - rules = trapped_chest_mesecons_rules, - }}, + { + receptor = { + state = mesecon.state.off, + rules = trapped_chest_mesecons_rules, + }, + }, function(pos, node, clicker) minetest.swap_node(pos, {name="mcl_chests:trapped_chest_on_small", param2 = node.param2}) find_or_create_entity(pos, "mcl_chests:trapped_chest_on_small", {"mcl_chests_trapped.png"}, node.param2, false, "default_chest", "mcl_chests_chest", "chest"):reinitialize("mcl_chests:trapped_chest_on_small") @@ -891,10 +911,12 @@ register_chest("trapped_chest", register_chest("trapped_chest_on", nil, nil, nil, nil, traptiles, true, - {receptor = { - state = mesecon.state.on, - rules = trapped_chest_mesecons_rules, - }}, + { + receptor = { + state = mesecon.state.on, + rules = trapped_chest_mesecons_rules, + }, + }, nil, nil, nil, "trapped_chest", "trapped_chest" @@ -951,19 +973,19 @@ minetest.register_craft({ {"group:wood", "group:wood", "group:wood"}, {"group:wood", "", "group:wood"}, {"group:wood", "group:wood", "group:wood"}, - } + }, }) minetest.register_craft({ type = "fuel", recipe = "mcl_chests:chest", - burntime = 15 + burntime = 15, }) minetest.register_craft({ type = "fuel", recipe = "mcl_chests:trapped_chest", - burntime = 15 + burntime = 15, }) minetest.register_node("mcl_chests:ender_chest", { @@ -989,7 +1011,7 @@ minetest.register_node("mcl_chests:ender_chest", { local formspec_ender_chest = table.concat({ "formspec_version[4]", - "size[12,10.375]", + "size[11.75,10.375]", "style_type[label;font_size=25]", "label[0.375,0.375;"..F(C(mcl_formspec.label_color, S("Ender Chest"))).."]", @@ -1082,7 +1104,7 @@ minetest.register_craft({ {"mcl_core:obsidian", "mcl_core:obsidian", "mcl_core:obsidian"}, {"mcl_core:obsidian", "mcl_end:ender_eye", "mcl_core:obsidian"}, {"mcl_core:obsidian", "mcl_core:obsidian", "mcl_core:obsidian"}, - } + }, }) -- Shulker boxes @@ -1125,21 +1147,33 @@ local shulker_mob_textures = { } local canonical_shulker_color = "violet" +--WARNING: after formspec v4 update, old shulker boxes will need to be placed again to get the new formspec local function formspec_shulker_box(name) - if name == "" then + if not name or name == "" then name = S("Shulker Box") end - return "size[9,8.75]".. - "label[0,0;"..F(minetest.colorize("#313131", name)).."]".. - "list[context;main;0,0.5;9,3;]".. - mcl_formspec.get_itemslot_bg(0,0.5,9,3).. - "label[0,4.0;"..F(minetest.colorize("#313131", S("Inventory"))).."]".. - "list[current_player;main;0,4.5;9,3;9]".. - mcl_formspec.get_itemslot_bg(0,4.5,9,3).. - "list[current_player;main;0,7.74;9,1;]".. - mcl_formspec.get_itemslot_bg(0,7.74,9,1).. - "listring[context;main]".. - "listring[current_player;main]" + + return table.concat({ + "formspec_version[4]", + "size[11.75,10.375]", + "style_type[label;font_size=25]", + + "label[0.375,0.375;"..F(C(mcl_formspec.label_color, name)).."]", + + mcl_formspec.get_itemslot_bg_v4(0.375, 0.75, 9, 3), + "list[context;main;0.375,0.75;9,3;]", + + "label[0.375,4.7;"..F(C(mcl_formspec.label_color, S("Inventory"))).."]", + + mcl_formspec.get_itemslot_bg_v4(0.375, 5.1, 9, 3), + "list[current_player;main;0.375,5.1;9,3;9]", + + mcl_formspec.get_itemslot_bg_v4(0.375, 9, 9, 1), + "list[current_player;main;0.375,9;9,1;]", + + "listring[context;main]", + "listring[current_player;main]", + }) end local function set_shulkerbox_meta(nmeta, imeta) @@ -1248,9 +1282,9 @@ for color, desc in pairs(boxtypes) do drop = "", paramtype = "light", paramtype2 = "facedir", --- TODO: Make shulker boxes rotatable --- This doesn't work, it just destroys the inventory: --- on_place = minetest.rotate_node, + -- TODO: Make shulker boxes rotatable + -- This doesn't work, it just destroys the inventory: + -- on_place = minetest.rotate_node, on_construct = function(pos) local meta = minetest.get_meta(pos) meta:set_string("formspec", formspec_shulker_box(nil)) @@ -1336,7 +1370,7 @@ for color, desc in pairs(boxtypes) do minetest.register_craft({ type = "shapeless", output = "mcl_chests:"..color.."_shulker_box", - recipe = { "group:shulker_box", "mcl_dye:"..color } + recipe = {"group:shulker_box", "mcl_dye:"..color}, }) end @@ -1346,7 +1380,7 @@ minetest.register_craft({ {"mcl_mobitems:shulker_shell"}, {"mcl_chests:chest"}, {"mcl_mobitems:shulker_shell"}, - } + }, }) -- Save metadata of shulker box when used in crafting @@ -1420,13 +1454,13 @@ minetest.register_lbm({ }) minetest.register_lbm({ - label = "Update shulker box formspecs (0.60.0)", - name = "mcl_chests:update_shulker_box_formspecs_0_60_0", + label = "Update shulker box formspecs (0.72.0)", + name = "mcl_chests:update_shulker_box_formspecs_0_72_0", nodenames = { "group:shulker_box" }, run_at_every_load = false, action = function(pos, node) local meta = minetest.get_meta(pos) - meta:set_string("formspec", formspec_shulker_box) + meta:set_string("formspec", formspec_shulker_box(meta:get_string("name"))) end, }) From 558df5e4bd4d65b68241360c54b031b34c845ee0 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Sat, 18 Sep 2021 09:53:45 +0200 Subject: [PATCH 21/82] fix all chest formspecs --- mods/HUD/mcl_formspec/FORMSPEC_GUIDE.md | 2 +- mods/HUD/mcl_formspec/init.lua | 4 + mods/ITEMS/mcl_chests/init.lua | 127 ++++++++++++++---------- settingtypes.txt | 5 + 4 files changed, 85 insertions(+), 53 deletions(-) diff --git a/mods/HUD/mcl_formspec/FORMSPEC_GUIDE.md b/mods/HUD/mcl_formspec/FORMSPEC_GUIDE.md index 6bb2e1424..20673a682 100644 --- a/mods/HUD/mcl_formspec/FORMSPEC_GUIDE.md +++ b/mods/HUD/mcl_formspec/FORMSPEC_GUIDE.md @@ -14,7 +14,7 @@ Just use this code to apply it to your formspec: The typical width of an inventory formspec is `0.375 + 9 + ((9-1) * 0.25) + 0.375 = 11.75` Margins is 0.375 -Space between 1st inventory line and the rest of inventory is 0.4 +Space between 1st inventory line and the rest of inventory is 0.45 Labels should have 0.375 space above if there is no other stuff above and 0.45 between content + 0.375 under diff --git a/mods/HUD/mcl_formspec/init.lua b/mods/HUD/mcl_formspec/init.lua index 1acf8b372..8ddc90c1d 100644 --- a/mods/HUD/mcl_formspec/init.lua +++ b/mods/HUD/mcl_formspec/init.lua @@ -7,6 +7,10 @@ mcl_formspec = {} mcl_formspec.label_color = "#313131" +mcl_formspec.label_size = tonumber(minetest.settings:get("mcl_label_font_size")) or 24 + +mcl_formspec.apply_label_size = sf("style_type[label;font_size=%s]", mcl_formspec.label_size) + function mcl_formspec.get_itemslot_bg(x, y, w, h) local out = "" for i = 0, w - 1, 1 do diff --git a/mods/ITEMS/mcl_chests/init.lua b/mods/ITEMS/mcl_chests/init.lua index ad3db56ee..b870fc362 100644 --- a/mods/ITEMS/mcl_chests/init.lua +++ b/mods/ITEMS/mcl_chests/init.lua @@ -502,8 +502,8 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile sf("mcl_chests:%s_%s_%s_%s", canonical_basename, pos.x, pos.y, pos.z), table.concat({ "formspec_version[4]", - "size[11.75,10.375]", - "style_type[label;font_size=25]", + "size[11.75,10.425]", + mcl_formspec.apply_label_size, "label[0.375,0.375;"..F(C(mcl_formspec.label_color, name)).."]", @@ -515,8 +515,8 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile mcl_formspec.get_itemslot_bg_v4(0.375, 5.1, 9, 3), "list[current_player;main;0.375,5.1;9,3;9]", - mcl_formspec.get_itemslot_bg_v4(0.375, 9, 9, 1), - "list[current_player;main;0.375,9;9,1;]", + mcl_formspec.get_itemslot_bg_v4(0.375, 9.05, 9, 1), + "list[current_player;main;0.375,9.05;9,1;]", sf("listring[nodemeta:%s,%s,%s;main]", pos.x, pos.y, pos.z), "listring[current_player;main]", @@ -661,26 +661,38 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile end minetest.show_formspec(clicker:get_player_name(), - "mcl_chests:"..canonical_basename.."_"..pos.x.."_"..pos.y.."_"..pos.z, - "size[9,11.5]".. - "label[0,0;"..F(minetest.colorize("#313131", name)).."]".. - "list[nodemeta:"..pos.x..","..pos.y..","..pos.z..";main;0,0.5;9,3;]".. - mcl_formspec.get_itemslot_bg(0,0.5,9,3).. - "list[nodemeta:"..pos_other.x..","..pos_other.y..","..pos_other.z..";main;0,3.5;9,3;]".. - mcl_formspec.get_itemslot_bg(0,3.5,9,3).. - "label[0,7;"..F(minetest.colorize("#313131", S("Inventory"))).."]".. - "list[current_player;main;0,7.5;9,3;9]".. - mcl_formspec.get_itemslot_bg(0,7.5,9,3).. - "list[current_player;main;0,10.75;9,1;]".. - mcl_formspec.get_itemslot_bg(0,10.75,9,1).. - -- BEGIN OF LISTRING WORKAROUND - "listring[current_player;main]".. - "listring[nodemeta:"..pos.x..","..pos.y..","..pos.z..";input]".. - -- END OF LISTRING WORKAROUND - "listring[current_player;main]".. - "listring[nodemeta:"..pos.x..","..pos.y..","..pos.z..";main]".. - "listring[current_player;main]".. - "listring[nodemeta:"..pos_other.x..","..pos_other.y..","..pos_other.z..";main]") + sf("mcl_chests:%s_%s_%s_%s", canonical_basename, pos.x, pos.y, pos.z), + table.concat({ + "formspec_version[4]", + "size[11.75,14.15]", + mcl_formspec.apply_label_size, + + "label[0.375,0.375;"..F(C(mcl_formspec.label_color, name)).."]", + + mcl_formspec.get_itemslot_bg_v4(0.375, 0.75, 9, 3), + sf("list[nodemeta:%s,%s,%s;main;0.375,0.75;9,3;]", pos.x, pos.y, pos.z), + + mcl_formspec.get_itemslot_bg_v4(0.375, 4.5, 9, 3), + sf("list[nodemeta:%s,%s,%s;main;0.375,4.5;9,3;]", pos_other.x, pos_other.y, pos_other.z), + + "label[0.375,8.45;"..F(C(mcl_formspec.label_color, S("Inventory"))).."]", + + mcl_formspec.get_itemslot_bg_v4(0.375, 8.825, 9, 3), + "list[current_player;main;0.375,8.825;9,3;9]", + + mcl_formspec.get_itemslot_bg_v4(0.375, 12.775, 9, 1), + "list[current_player;main;0.375,12.775;9,1;]", + + --BEGIN OF LISTRING WORKAROUND + "listring[current_player;main]", + sf("listring[nodemeta:%s,%s,%s;input]", pos.x, pos.y, pos.z), + --END OF LISTRING WORKAROUND + "listring[current_player;main]".. + sf("listring[nodemeta:%s,%s,%s;main]", pos.x, pos.y, pos.z), + "listring[current_player;main]", + sf("listring[nodemeta:%s,%s,%s;main]", pos_other.x, pos_other.y, pos_other.z), + }) + ) if on_rightclick_addendum_left then on_rightclick_addendum_left(pos, node, clicker) @@ -808,27 +820,38 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile end minetest.show_formspec(clicker:get_player_name(), - "mcl_chests:"..canonical_basename.."_"..pos.x.."_"..pos.y.."_"..pos.z, + sf("mcl_chests:%s_%s_%s_%s", canonical_basename, pos.x, pos.y, pos.z), + table.concat({ + "formspec_version[4]", + "size[11.75,14.15]", + mcl_formspec.apply_label_size, - "size[9,11.5]".. - "label[0,0;"..F(minetest.colorize("#313131", name)).."]".. - "list[nodemeta:"..pos_other.x..","..pos_other.y..","..pos_other.z..";main;0,0.5;9,3;]".. - mcl_formspec.get_itemslot_bg(0,0.5,9,3).. - "list[nodemeta:"..pos.x..","..pos.y..","..pos.z..";main;0,3.5;9,3;]".. - mcl_formspec.get_itemslot_bg(0,3.5,9,3).. - "label[0,7;"..F(minetest.colorize("#313131", S("Inventory"))).."]".. - "list[current_player;main;0,7.5;9,3;9]".. - mcl_formspec.get_itemslot_bg(0,7.5,9,3).. - "list[current_player;main;0,10.75;9,1;]".. - mcl_formspec.get_itemslot_bg(0,10.75,9,1).. - -- BEGIN OF LISTRING WORKAROUND - "listring[current_player;main]".. - "listring[nodemeta:"..pos.x..","..pos.y..","..pos.z..";input]".. - -- END OF LISTRING WORKAROUND - "listring[current_player;main]".. - "listring[nodemeta:"..pos_other.x..","..pos_other.y..","..pos_other.z..";main]".. - "listring[current_player;main]".. - "listring[nodemeta:"..pos.x..","..pos.y..","..pos.z..";main]") + "label[0.375,0.375;"..F(C(mcl_formspec.label_color, name)).."]", + + mcl_formspec.get_itemslot_bg_v4(0.375, 0.75, 9, 3), + sf("list[nodemeta:%s,%s,%s;main;0.375,0.75;9,3;]", pos_other.x, pos_other.y, pos_other.z), + + mcl_formspec.get_itemslot_bg_v4(0.375, 4.5, 9, 3), + sf("list[nodemeta:%s,%s,%s;main;0.375,4.5;9,3;]", pos.x, pos.y, pos.z), + + "label[0.375,8.45;"..F(C(mcl_formspec.label_color, S("Inventory"))).."]", + + mcl_formspec.get_itemslot_bg_v4(0.375, 8.825, 9, 3), + "list[current_player;main;0.375,8.825;9,3;9]", + + mcl_formspec.get_itemslot_bg_v4(0.375, 12.775, 9, 1), + "list[current_player;main;0.375,12.775;9,1;]", + + --BEGIN OF LISTRING WORKAROUND + "listring[current_player;main]", + sf("listring[nodemeta:%s,%s,%s;input]", pos.x, pos.y, pos.z), + --END OF LISTRING WORKAROUND + "listring[current_player;main]".. + sf("listring[nodemeta:%s,%s,%s;main]", pos_other.x, pos_other.y, pos_other.z), + "listring[current_player;main]", + sf("listring[nodemeta:%s,%s,%s;main]", pos.x, pos.y, pos.z), + }) + ) if on_rightclick_addendum_right then on_rightclick_addendum_right(pos, node, clicker) @@ -1011,8 +1034,8 @@ minetest.register_node("mcl_chests:ender_chest", { local formspec_ender_chest = table.concat({ "formspec_version[4]", - "size[11.75,10.375]", - "style_type[label;font_size=25]", + "size[11.75,10.425]", + mcl_formspec.apply_label_size, "label[0.375,0.375;"..F(C(mcl_formspec.label_color, S("Ender Chest"))).."]", @@ -1024,8 +1047,8 @@ local formspec_ender_chest = table.concat({ mcl_formspec.get_itemslot_bg_v4(0.375, 5.1, 9, 3), "list[current_player;main;0.375,5.1;9,3;9]", - mcl_formspec.get_itemslot_bg_v4(0.375, 9, 9, 1), - "list[current_player;main;0.375,9;9,1;]", + mcl_formspec.get_itemslot_bg_v4(0.375, 9.05, 9, 1), + "list[current_player;main;0.375,9.05;9,1;]", "listring[current_player;enderchest]", "listring[current_player;main]", @@ -1155,8 +1178,8 @@ local function formspec_shulker_box(name) return table.concat({ "formspec_version[4]", - "size[11.75,10.375]", - "style_type[label;font_size=25]", + "size[11.75,10.425]", + mcl_formspec.apply_label_size, "label[0.375,0.375;"..F(C(mcl_formspec.label_color, name)).."]", @@ -1168,8 +1191,8 @@ local function formspec_shulker_box(name) mcl_formspec.get_itemslot_bg_v4(0.375, 5.1, 9, 3), "list[current_player;main;0.375,5.1;9,3;9]", - mcl_formspec.get_itemslot_bg_v4(0.375, 9, 9, 1), - "list[current_player;main;0.375,9;9,1;]", + mcl_formspec.get_itemslot_bg_v4(0.375, 9.05, 9, 1), + "list[current_player;main;0.375,9.05;9,1;]", "listring[context;main]", "listring[current_player;main]", diff --git a/settingtypes.txt b/settingtypes.txt index c5d5d32c1..1f1e31dbb 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -192,6 +192,11 @@ animated_chests (Animated chests) bool true # The maximum number of boss bars to simultaniously display on the screen max_bossbars (Maximum Boss bars) int 5 +# Define how wide font will be displayed in mineclone2 formspecs +# This allow MineClone2 to have a label size similar to minecraft, but allowing at least singleplayer to use his own font with custom size +# (some fonts may be bigger than the default one and break formspecs) +mcl_label_font_size (Label Font Size) int 24 + # Default intensity of shadows (default: 0.33) mcl_default_shadow_intensity (Default shadow intensity) float 0.33 0.0 1.0 From 54b119cffacf79cee11ac8b108204e4aa6cbb08a Mon Sep 17 00:00:00 2001 From: AFCMS Date: Sat, 18 Sep 2021 11:05:17 +0200 Subject: [PATCH 22/82] some things --- mods/HUD/mcl_formspec/FORMSPEC_GUIDE.md | 13 ++++++++----- mods/ITEMS/mcl_hoppers/init.lua | 12 ++++++------ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/mods/HUD/mcl_formspec/FORMSPEC_GUIDE.md b/mods/HUD/mcl_formspec/FORMSPEC_GUIDE.md index 20673a682..838e5cbdd 100644 --- a/mods/HUD/mcl_formspec/FORMSPEC_GUIDE.md +++ b/mods/HUD/mcl_formspec/FORMSPEC_GUIDE.md @@ -1,19 +1,22 @@ -Formspecs are an important part of game and mod development. +# MineClone2 Formspec Guide -This guide will learn you rules about creation of formspecs for the MineClone2 game. +***This guide will learn you rules about creation of formspecs for the MineClone2 game.*** + +Formspecs are an important part of game and mod development. First of all, MineClone2 aims to support ONLY last formspec version. Many utility functions will not work with formspec v1 or v2. Label font size should be 25 to be minecraft like. We arent modifying formspec prepend in order to not break existing mods. -Just use this code to apply it to your formspec: +Just add this code to apply it to your formspec: ```lua -"style_type[label;font_size=25]", +mcl_formspec.apply_label_size ``` -The typical width of an inventory formspec is `0.375 + 9 + ((9-1) * 0.25) + 0.375 = 11.75` +The typical width of an 9 slots width inventory formspec is `0.375 + 9 + ((9-1) * 0.25) + 0.375 = 11.75` Margins is 0.375 + Space between 1st inventory line and the rest of inventory is 0.45 Labels should have 0.375 space above if there is no other stuff above and 0.45 between content diff --git a/mods/ITEMS/mcl_hoppers/init.lua b/mods/ITEMS/mcl_hoppers/init.lua index 15bc922ff..62b358c64 100644 --- a/mods/ITEMS/mcl_hoppers/init.lua +++ b/mods/ITEMS/mcl_hoppers/init.lua @@ -13,16 +13,16 @@ end local mcl_hoppers_formspec = table.concat({ "size[9,7]", - "label[2,0;" .. F(C("#313131", S("Hopper"))) .. "]", + "label[2,0;"..F(C(mcl_formspec.label_color, S("Hopper"))).."]", "list[context;main;2,0.5;5,1;]", - mcl_formspec.get_itemslot_bg(2, 0.5, 5, 1), - "label[0,2;" .. F(C("#313131", S("Inventory"))) .. "]", + mcl_formspec.get_itemslot_bg(2,0.5,5,1), + "label[0,2;"..F(C(mcl_formspec.label_color, S("Inventory"))).."]", "list[current_player;main;0,2.5;9,3;9]", - mcl_formspec.get_itemslot_bg(0, 2.5, 9, 3), + mcl_formspec.get_itemslot_bg(0,2.5,9,3), "list[current_player;main;0,5.74;9,1;]", - mcl_formspec.get_itemslot_bg(0, 5.74, 9, 1), + mcl_formspec.get_itemslot_bg(0,5.74,9,1), "listring[context;main]", - "listring[current_player;main]", + "listring[current_player;main]" }) -- Downwards hopper (base definition) From 4ee6a67516376fc8935aa7ccfb4562e65f1c27f3 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Mon, 20 Sep 2021 09:22:13 +0200 Subject: [PATCH 23/82] survival inventory --- mods/HUD/mcl_inventory/init.lua | 91 ++++++++++++++++----------- textures/crafting_formspec_arrow.png | Bin 0 -> 5362 bytes 2 files changed, 55 insertions(+), 36 deletions(-) create mode 100644 textures/crafting_formspec_arrow.png diff --git a/mods/HUD/mcl_inventory/init.lua b/mods/HUD/mcl_inventory/init.lua index 4ca0f2a73..a83425388 100644 --- a/mods/HUD/mcl_inventory/init.lua +++ b/mods/HUD/mcl_inventory/init.lua @@ -15,14 +15,14 @@ function return_item(itemstack, dropper, pos, inv) else -- Drop item on the ground local v = dropper:get_look_dir() - local p = {x=pos.x, y=pos.y+1.2, z=pos.z} - p.x = p.x+(math.random(1,3)*0.2) - p.z = p.z+(math.random(1,3)*0.2) + local p = { x = pos.x, y = pos.y + 1.2, z = pos.z } + p.x = p.x + (math.random(1, 3) * 0.2) + p.z = p.z + (math.random(1, 3) * 0.2) local obj = minetest.add_item(p, itemstack) if obj then - v.x = v.x*4 - v.y = v.y*4 + 2 - v.z = v.z*4 + v.x = v.x * 4 + v.y = v.y * 4 + 2 + v.z = v.z * 4 obj:set_velocity(v) obj:get_luaentity()._insta_collect = false end @@ -39,7 +39,7 @@ function return_fields(player, name) local inv = player:get_inventory() local list = inv:get_list(name) if not list then return end - for i,stack in ipairs(list) do + for i, stack in ipairs(list) do return_item(stack, player, player:get_pos(), inv) stack:clear() inv:set_stack(name, i, stack) @@ -55,11 +55,12 @@ local function set_inventory(player) inv:set_width("craft", 2) inv:set_size("craft", 4) - local armor_slots = {"helmet", "chestplate", "leggings", "boots"} + local armor_slots = { "helmet", "chestplate", "leggings", "boots" } local armor_slot_imgs = "" - for a=1,4 do - if inv:get_stack("armor", a+1):is_empty() then - armor_slot_imgs = armor_slot_imgs .. "image[0,"..(a-1)..";1,1;mcl_inventory_empty_armor_slot_"..armor_slots[a]..".png]" + for a = 1, 4 do + if inv:get_stack("armor", a + 1):is_empty() then + armor_slot_imgs = armor_slot_imgs .. + "image[0," .. (a - 1) .. ";1,1;mcl_inventory_empty_armor_slot_" .. armor_slots[a] .. ".png]" end end @@ -76,29 +77,29 @@ local function set_inventory(player) "list[current_player;armor;0,1;1,1;2]" .. "list[current_player;armor;0,2;1,1;3]" .. "list[current_player;armor;0,3;1,1;4]" .. - mcl_formspec.get_itemslot_bg(0,0,1,1) .. - mcl_formspec.get_itemslot_bg(0,1,1,1) .. - mcl_formspec.get_itemslot_bg(0,2,1,1) .. - mcl_formspec.get_itemslot_bg(0,3,1,1) .. + mcl_formspec.get_itemslot_bg(0, 0, 1, 1) .. + mcl_formspec.get_itemslot_bg(0, 1, 1, 1) .. + mcl_formspec.get_itemslot_bg(0, 2, 1, 1) .. + mcl_formspec.get_itemslot_bg(0, 3, 1, 1) .. "list[current_player;offhand;3,2;1,1]" .. - mcl_formspec.get_itemslot_bg(3,2,1,1) .. + mcl_formspec.get_itemslot_bg(3, 2, 1, 1) .. armor_slot_imgs .. -- Craft and inventory - "label[0,4;"..F(minetest.colorize("#313131", S("Inventory"))) .. "]" .. + "label[0,4;" .. F(minetest.colorize("#313131", S("Inventory"))) .. "]" .. "list[current_player;main;0,4.5;9,3;9]" .. "list[current_player;main;0,7.74;9,1;]" .. - "label[4,0.5;"..F(minetest.colorize("#313131", S("Crafting"))) .. "]" .. + "label[4,0.5;" .. F(minetest.colorize("#313131", S("Crafting"))) .. "]" .. "list[current_player;craft;4,1;2,2]" .. "list[current_player;craftpreview;7,1.5;1,1;]" .. mcl_formspec.get_itemslot_bg(0, 4.5, 9, 3) .. mcl_formspec.get_itemslot_bg(0, 7.74, 9, 1) .. - mcl_formspec.get_itemslot_bg(4, 1,2, 2) .. + mcl_formspec.get_itemslot_bg(4, 1, 2, 2) .. mcl_formspec.get_itemslot_bg(7, 1.5, 1, 1) .. -- Crafting guide button "image_button[4.5,3;1,1;craftguide_book.png;__mcl_craftguide;]" .. - "tooltip[__mcl_craftguide;"..F(S("Recipe book")) .. "]" .. + "tooltip[__mcl_craftguide;" .. F(S("Recipe book")) .. "]" .. -- Help button "image_button[8,3;1,1;doc_button_icon_lores.png;__mcl_doc;]" .. @@ -129,9 +130,9 @@ end -- Drop items in craft grid and reset inventory on closing minetest.register_on_player_receive_fields(function(player, formname, fields) if fields.quit then - return_fields(player,"craft") - return_fields(player,"enchanting_lapis") - return_fields(player,"enchanting_item") + return_fields(player, "craft") + return_fields(player, "enchanting_lapis") + return_fields(player, "enchanting_item") if not minetest.is_creative_enabled(player:get_player_name()) and (formname == "" or formname == "main") then set_inventory(player) end @@ -174,7 +175,7 @@ minetest.register_on_joinplayer(function(player) return_fields(player, "enchanting_lapis") end) -dofile(minetest.get_modpath(minetest.get_current_modname()).."/creative.lua") +dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/creative.lua") mcl_player.register_on_visual_change(mcl_inventory.update_inventory_formspec) @@ -190,8 +191,26 @@ function minetest.is_creative_enabled(name) return false end -local function in_table(n,h) - for k,v in pairs(h) do +--Insta "digging" nodes in gamemode-creative +minetest.register_on_punchnode(function(pos, node, puncher, pointed_thing) + if not puncher or not puncher:is_player() then return end + local name = puncher:get_player_name() + if not minetest.is_creative_enabled(name) then return end + if pointed_thing.type ~= "node" then return end + local def = minetest.registered_nodes[node.name] + if def then + minetest.node_dig(pos, node, puncher) + return true + end +end) + +--Don't subtract from inv when placing in gamemode-creative +minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack, pointed_thing) + if placer and placer:is_player() and minetest.is_creative_enabled(placer:get_player_name()) then return true end +end) + +local function in_table(n, h) + for k, v in pairs(h) do if v == n then return true end end return false @@ -202,24 +221,24 @@ local gamemodes = { "creative" } -function mcl_inventory.player_set_gamemode(p,g) +function mcl_inventory.player_set_gamemode(p, g) local m = p:get_meta() - m:set_string("gamemode",g) + m:set_string("gamemode", g) if g == "survival" then - mcl_experience.setup_hud(p) - mcl_experience.update(p) + mcl_experience.setup_hud(p) + mcl_experience.update(p) elseif g == "creative" then - mcl_experience.remove_hud(p) + mcl_experience.remove_hud(p) end mcl_meshhand.update_player(p) set_inventory(p) end -minetest.register_chatcommand("gamemode",{ +minetest.register_chatcommand("gamemode", { params = S("[] []"), description = S("Change gamemode (survival/creative) for yourself or player"), privs = { server = true }, - func = function(n,param) + func = function(n, param) -- Full input validation ( just for @erlehmann <3 ) local p local args = param:split(" ") @@ -232,15 +251,15 @@ minetest.register_chatcommand("gamemode",{ if not p then return false, S("Player not online") end - if args[1] ~= nil and not in_table(args[1],gamemodes) then + if args[1] ~= nil and not in_table(args[1], gamemodes) then return false, S("Gamemode " .. args[1] .. " does not exist.") elseif args[1] ~= nil then - mcl_inventory.player_set_gamemode(p,args[1]) + mcl_inventory.player_set_gamemode(p, args[1]) end --Result message - show effective game mode local gm = p:get_meta():get_string("gamemode") if gm == "" then gm = gamemodes[1] end - return true, S("Gamemode for player ")..n..S(": "..gm) + return true, S("Gamemode for player ") .. n .. S(": " .. gm) end }) diff --git a/textures/crafting_formspec_arrow.png b/textures/crafting_formspec_arrow.png new file mode 100644 index 0000000000000000000000000000000000000000..12b9c197041202eb4aaa6517d9794a5c329d43ce GIT binary patch literal 5362 zcmeHLX;c&05)MwlVG#rYMbL@Cd9s+Kvq6#}$PQ5ghzueq(n&h8g)Alk0*VW+ETV{m zqk^J1xS+V9g2DizQ5aM}RFqZr5pfg|84-A$fZKWV$8+BNGv{>r-dj~)ReiU*dP(r} z@tmSFQwN1YO<{St`6Fj1)q(yF`494p=tH42e~JwVlKX?v7>QKOha(`2JVpXxAO*}v zp%hOpEnSwLOVb;9WD~1>JMDR=qO`kc)PwcMj^*f(H?4QMRu6h60VV|*9 z?p!lzD93A#_fSE{o(fvR{r-yV&WfE;>l$OVOAagHYheJdrlC`y*ZaPKCe}#Dw^uDd zCq@?g9U>fy)SMQ*>EYJXSP~5m&&t=jz%MKf-&jqyn27Lj*b|Bu4c$@L+- zN5u2|&c^5kbNPQnxrCn%K?RMF9w(=5Nf+L5Q)ZI(X3@Z zr<~+7Lt#pe77hiDa_({N0Ty z4U_cC9NY`P0Cy#irT(^6T6tN_wuvc?q|Qk{tFde~xfexn|~xXm(7OwJ2C)UyYll zUZhV*Rs5VraZJbd(ktAt#Vc_Z1Fl`)$H&+#+R+ws2Y1Kvr{v4O_S6s>;(t4%fiZkI zh$=VL_uh1-yEJWvWmPrt`r%|J!-GoWpwi}pT6>kt%)|7f^d2gi*SUGG_+}n=;tiX% zY|m*m=!Vjb?K*Z9?69b8j_ocs2wgW&(H*u~*KrHRIccS-txpl!Fk#PJPxBQ6M7M-g zP9l9jZ?Q$34$I%$x-;3Gj1@Fy66bVt5^;G$Mu~fa{3}fUT(aT~HQ;3G>QjaL`R32u zblJfXCp-5Gj@3TrFWA1Ui*}qIeJuD&Q)G+lzS(P^#mIKT=ihV|yqMXtoLp|5X>~BX z;O7q0_)8gzH+m^%wA&=Q`qzwYl`24~VoLzTNMyyPBE` z=e67}JiCr;-|cl~*!*s4aCBQ^u6S}DHSS4WMXki^%8^9IvWSwZyY2VfTkj6t7c>kX z8vG8`tlOZEzHB*vsjxe~J4hltO=OQ=I(||2@Zh{n==2A5)pX;h2i`5u#QtHFnm{_& z^&)L+j$^Ao#5kHtL3w1`nzI{ke9!2&!lkVi8j&8gX>0QI z&5c{z=NAtb{<<-_LV#WoXf&W}x}6!fan$hroqapemA6}oL8W=jU1gI_<~oSx>$9ru z{Y%jA%tmyRTy1*v5}%A&3Pz)Yc~Wm+^~vd0q0Hy@yP0`(*`A6l$ zTv(I&Aj#FBC~L&_kf+Ey$z^TmtySx7E)P`L4Z+i^nVa&R!W|Yo@IB-j?t8fTW!(ar z_pXGf4OSM3y-(`_Oxsw(J==~)zdg)-0Ue7!c&X3Q*>g4TSg`FvmZ?W}-C(06?T^=# zj@b=Iz-jd)>3Z7z)N-$bfQM1uYV087s|djgR+kk10xe#2Gc>hk$`hxYpH5AIsW~2X zvWOEgwR@ZDZI<4-P%~JzH+Y$mH>FIe$!=qa2v>7`fW9}`lQn*MR%tx=!<>+UloJKv z9qU)_ueE$IohLorbm(N;(YH$cv%dP@v#?u6JLX7j>}RC~PYc%$8@g_5UcCS1`)7O~ zyC);=y~p(mxBc4K5@T+1RcnOFc^BA`%UNmMG!Gg08m`ERnlus{Tzv&Qmi|Ql?_y5P z@Se!CdWzPgtIjMQd-SM%pTph0AkJ3#n+3PCXSDULlkqZ5D-cSfG%A+;B*a;Xndd#Kit}tptmKc}(n5DjQ%+T%lF4SF99T z66+JdjSc70dDsPxIt~g30w9FsAVwjK5Xl${CRUBhK*p+N0v4lIk%u#}L2N&at5^zQ zD0m7Uz_}~nC=%9D2jd{+@frSZ9upAAjEP+(mrED~LUeRAKAMadO9ccXolYkJBm#+q zLo{%*7?B)Q;6yS@6~s7(8zkdOVTl|Ti!drokRy(iGqG4ij`nfincO`J0htKsA1!17$lZwG56Q%lQZD2k1&QRApF{AtAMGWP(g<}r zJT3u>fP{#u4Dm|*!lfsR?f20_MS%boO4L>e*OD1fkEMSR$Dm6mcOH6atQi5gaNHIIz<4~>qssPS1AO_#nJ$= zID&~)g@jRAs>>VWFuo~Xunf_NQC0jz&AWht@!9w#5CN-27>v4X86bDui42T_cxp$8 z-MEOm3KR(-19t}z%X91Eak_}Qo>TEDpYAUV2j3s&%q~Zx65pe(=N2CQ1NeqC>AOp4lG61lI ziG&HNtNKI64ut>V#6hj_SsOs?#@CScf^;jw$96TrnTp1L@i(y-|Dp#3`kRxl;`bX} z-{|@(2EI!9TXlV->#G>}D&=q0^?##F=hF)hBto8oqLJ4bTI|vdD3rz)*wxjK7@X4AEs^h5yrBqCTr?!jE}gSFbR$X3I}u#Q07|WQ{uzR z%68p6wK?fxo_=0DW=Ny0tLs<~_Qz3zb^eYwtpz{)^@91LS;M8cied}suevJCF=$8hC>l2pi6fO+w z2y)V#$$MllI=ST9rT(;Oq5d>|^h%3vF1qK5=1l6Xza678l-jKuwDJbhOZ+GE9a(2D z<@Xp?UzxIe`4tLeP|&EMby)B5-W3(TOKx{>dP{znGar!XZh2VLd|;RshpMgnxnGM$ zLwo4%EpC3=)YMlzvNq>&i$TjPX~gu6@&tP8ghT1B`Bw^dgOy3N`te=(+#ylbCwq}(Uy2Elc7+$(^Q8B>OjT}WO1^b z#de?EscodAIs5H}R5Y>_$Z~TI@Va&LLD>`(=6kgB!N$>$^WV9WX2#qr$5@2Nov`S@ zOs3y<)|c+yY|)Wr))Sx_&3I{EV31w%GDbm9E1F((FvB2YaYkCkgLQ-<{;Q^+1y`2PaEx Date: Fri, 9 Sep 2022 18:59:12 +0200 Subject: [PATCH 24/82] Modern Survival Inventory (9 slice images, formspec v6) --- mods/HUD/mcl_formspec/init.lua | 21 +++- mods/HUD/mcl_inventory/init.lua | 143 +++++++++++++++---------- mods/PLAYER/mcl_player/init.lua | 35 ++++-- textures/mcl_inventory_background9.png | Bin 0 -> 5324 bytes 4 files changed, 126 insertions(+), 73 deletions(-) create mode 100644 textures/mcl_inventory_background9.png diff --git a/mods/HUD/mcl_formspec/init.lua b/mods/HUD/mcl_formspec/init.lua index 8ddc90c1d..e7817e639 100644 --- a/mods/HUD/mcl_formspec/init.lua +++ b/mods/HUD/mcl_formspec/init.lua @@ -15,20 +15,31 @@ function mcl_formspec.get_itemslot_bg(x, y, w, h) local out = "" for i = 0, w - 1, 1 do for j = 0, h - 1, 1 do - out = out .."image["..x+i..","..y+j..";1,1;mcl_formspec_itemslot.png]" + out = out .. "image[" .. x + i .. "," .. y + j .. ";1,1;mcl_formspec_itemslot.png]" end end return out end ---This function will replace mcl_formspec.get_itemslot_bg then every formspec will be upgrade to version 4 +---This function will replace mcl_formspec.get_itemslot_bg then every formspec will be upgrade to version 4 +---@param x number +---@param y number +---@param size number +---@return string local function get_slot(x, y, size) - local t = "image["..x-size..","..y-size..";".. 1+(size*2)..",".. 1+(size*2)..";mcl_formspec_itemslot.png]" + local t = "image[" .. x - size .. "," .. y - size .. ";" .. 1 + (size * 2) .. + "," .. 1 + (size * 2) .. ";mcl_formspec_itemslot.png]" return t end mcl_formspec.itemslot_border_size = 0.05 +---@param x number +---@param y number +---@param w integer +---@param h integer +---@param size? number +---@return string function mcl_formspec.get_itemslot_bg_v4(x, y, w, h, size) if not size then size = mcl_formspec.itemslot_border_size @@ -36,8 +47,8 @@ function mcl_formspec.get_itemslot_bg_v4(x, y, w, h, size) local out = "" for i = 0, w - 1, 1 do for j = 0, h - 1, 1 do - out = out .. get_slot(x+i+(i*0.25), y+j+(j*0.25), size) + out = out .. get_slot(x + i + (i * 0.25), y + j + (j * 0.25), size) end end return out -end \ No newline at end of file +end diff --git a/mods/HUD/mcl_inventory/init.lua b/mods/HUD/mcl_inventory/init.lua index a83425388..a46f2669f 100644 --- a/mods/HUD/mcl_inventory/init.lua +++ b/mods/HUD/mcl_inventory/init.lua @@ -6,8 +6,12 @@ mcl_inventory = {} --local mod_player = minetest.get_modpath("mcl_player") --local mod_craftguide = minetest.get_modpath("mcl_craftguide") --- Returns a single itemstack in the given inventory to the main inventory, or drop it when there's no space left -function return_item(itemstack, dropper, pos, inv) +---Returns a single itemstack in the given inventory to the main inventory, or drop it when there's no space left. +---@param itemstack ItemStack +---@param dropper ObjectRef +---@param pos Vector +---@param inv InvRef +local function return_item(itemstack, dropper, pos, inv) if dropper:is_player() then -- Return to main inventory if inv:room_for_item("main", itemstack) then @@ -15,7 +19,7 @@ function return_item(itemstack, dropper, pos, inv) else -- Drop item on the ground local v = dropper:get_look_dir() - local p = { x = pos.x, y = pos.y + 1.2, z = pos.z } + local p = vector.offset(pos, 0, 1.2, 0) p.x = p.x + (math.random(1, 3) * 0.2) p.z = p.z + (math.random(1, 3) * 0.2) local obj = minetest.add_item(p, itemstack) @@ -34,9 +38,14 @@ function return_item(itemstack, dropper, pos, inv) return itemstack end --- Return items in the given inventory list (name) to the main inventory, or drop them if there is no space left -function return_fields(player, name) +---Return items in the given inventory list (name) to the main inventory, or drop them if there is no space left. +---@param player ObjectRef +---@param name string +local function return_fields(player, name) local inv = player:get_inventory() + + ---@diagnostic disable need-check-nil + local list = inv:get_list(name) if not list then return end for i, stack in ipairs(list) do @@ -44,85 +53,102 @@ function return_fields(player, name) stack:clear() inv:set_stack(name, i, stack) end + + ---@diagnostic enable need-check-nil end +---@param player ObjectRef local function set_inventory(player) if minetest.is_creative_enabled(player:get_player_name()) then mcl_inventory.set_creative_formspec(player) return end + local inv = player:get_inventory() + + ---@diagnostic disable need-check-nil inv:set_width("craft", 2) inv:set_size("craft", 4) local armor_slots = { "helmet", "chestplate", "leggings", "boots" } local armor_slot_imgs = "" + for a = 1, 4 do if inv:get_stack("armor", a + 1):is_empty() then armor_slot_imgs = armor_slot_imgs .. - "image[0," .. (a - 1) .. ";1,1;mcl_inventory_empty_armor_slot_" .. armor_slots[a] .. ".png]" + "image[0.375," .. + (0.375 + (a - 1) * 1.25) .. ";1,1;mcl_inventory_empty_armor_slot_" .. armor_slots[a] .. ".png]" end end if inv:get_stack("offhand", 1):is_empty() then - armor_slot_imgs = armor_slot_imgs .. "image[3,2;1,1;mcl_inventory_empty_armor_slot_shield.png]" + armor_slot_imgs = armor_slot_imgs .. "image[5.375,4.125;1,1;mcl_inventory_empty_armor_slot_shield.png]" end - local form = "size[9,8.75]" .. - "background[-0.19,-0.25;9.41,9.49;crafting_formspec_bg.png]" .. - mcl_player.get_player_formspec_model(player, 1.0, 0.0, 2.25, 4.5, "") .. + ---@diagnostic enable need-check-nil - -- Armor - "list[current_player;armor;0,0;1,1;1]" .. - "list[current_player;armor;0,1;1,1;2]" .. - "list[current_player;armor;0,2;1,1;3]" .. - "list[current_player;armor;0,3;1,1;4]" .. - mcl_formspec.get_itemslot_bg(0, 0, 1, 1) .. - mcl_formspec.get_itemslot_bg(0, 1, 1, 1) .. - mcl_formspec.get_itemslot_bg(0, 2, 1, 1) .. - mcl_formspec.get_itemslot_bg(0, 3, 1, 1) .. - "list[current_player;offhand;3,2;1,1]" .. - mcl_formspec.get_itemslot_bg(3, 2, 1, 1) .. - armor_slot_imgs .. + local form = table.concat({ + "formspec_version[6]", + "size[11.75,10.9]", - -- Craft and inventory - "label[0,4;" .. F(minetest.colorize("#313131", S("Inventory"))) .. "]" .. - "list[current_player;main;0,4.5;9,3;9]" .. - "list[current_player;main;0,7.74;9,1;]" .. - "label[4,0.5;" .. F(minetest.colorize("#313131", S("Crafting"))) .. "]" .. - "list[current_player;craft;4,1;2,2]" .. - "list[current_player;craftpreview;7,1.5;1,1;]" .. - mcl_formspec.get_itemslot_bg(0, 4.5, 9, 3) .. - mcl_formspec.get_itemslot_bg(0, 7.74, 9, 1) .. - mcl_formspec.get_itemslot_bg(4, 1, 2, 2) .. - mcl_formspec.get_itemslot_bg(7, 1.5, 1, 1) .. + --Armor slots + mcl_formspec.get_itemslot_bg_v4(0.375, 0.375, 1, 4), + "list[current_player;armor;0.375,0.375;1,1;1]", + "list[current_player;armor;0.375,1.625;1,1;2]", + "list[current_player;armor;0.375,2.875;1,1;3]", + "list[current_player;armor;0.375,4.125;1,1;4]", - -- Crafting guide button - "image_button[4.5,3;1,1;craftguide_book.png;__mcl_craftguide;]" .. - "tooltip[__mcl_craftguide;" .. F(S("Recipe book")) .. "]" .. + --Main inventory + mcl_formspec.get_itemslot_bg_v4(0.375, 5.575, 9, 3), + "list[current_player;main;0.375,5.575;9,3;9]", - -- Help button - "image_button[8,3;1,1;doc_button_icon_lores.png;__mcl_doc;]" .. - "tooltip[__mcl_doc;" .. F(S("Help")) .. "]" + --Hotbar + mcl_formspec.get_itemslot_bg_v4(0.375, 9.525, 9, 1), + "list[current_player;main;0.375,9.525;9,1;]", - -- Skins button - if minetest.global_exists("mcl_skins") then - form = form .. - "image_button[3,3;1,1;mcl_skins_button.png;__mcl_skins;]" .. - "tooltip[__mcl_skins;" .. F(S("Select player skin")) .. "]" - end + --Player model + "image[1.57,0.343;3.62,4.85;mcl_inventory_background9.png;2]", + mcl_player.get_player_formspec_model(player, 1.57, 0.4, 3.62, 4.85, ""), - form = form .. - -- Achievements button - "image_button[7,3;1,1;mcl_achievements_button.png;__mcl_achievements;]" .. - "tooltip[__mcl_achievements;" .. F(S("Advancements")) .. "]" .. + --Offhand + mcl_formspec.get_itemslot_bg_v4(5.375, 4.125, 1, 1), + "list[current_player;offhand;5.375,4.125;1,1]", - -- For shortcuts - "listring[current_player;main]" .. - "listring[current_player;armor]" .. - "listring[current_player;main]" .. - "listring[current_player;craft]" .. - "listring[current_player;main]" + armor_slot_imgs, + + --Craft grid + "label[6.61,0.5;" .. F(minetest.colorize(mcl_formspec.label_color, S("Crafting"))) .. "]", + mcl_formspec.get_itemslot_bg_v4(6.625, 0.875, 2, 2), + "list[current_player;craft;6.625,0.875;2,2]", + + "image[9.125,1.5;1,1;crafting_formspec_arrow.png]", + + mcl_formspec.get_itemslot_bg_v4(10.375, 1.5, 1, 1), + "list[current_player;craftpreview;10.375,1.5;1,1;]", + + --Crafting guide button + "image_button[6.575,4.075;1.1,1.1;craftguide_book.png;__mcl_craftguide;]", + "tooltip[__mcl_craftguide;" .. F(S("Recipe book")) .. "]", + + --Help button + "image_button[7.825,4.075;1.1,1.1;doc_button_icon_lores.png;__mcl_doc;]", + "tooltip[__mcl_doc;" .. F(S("Help")) .. "]", + + --Skins button + "image_button[9.075,4.075;1.1,1.1;mcl_skins_button.png;__mcl_skins;]", + "tooltip[__mcl_skins;" .. F(S("Select player skin")) .. "]", + + --Advancements button + "image_button[10.325,4.075;1.1,1.1;mcl_achievements_button.png;__mcl_achievements;]", + "tooltip[__mcl_achievements;" .. F(S("Advancements")) .. "]", + + --Listring + "listring[current_player;main]", + "listring[current_player;armor]", + "listring[current_player;main]", + "listring[current_player;craft]", + "listring[current_player;main]", + }) player:set_inventory_formspec(form) end @@ -151,9 +177,13 @@ end) minetest.register_on_joinplayer(function(player) --init inventory local inv = player:get_inventory() + + ---get_inventory can return nil if object isn't a player, but we are sure this is one :) + ---@diagnostic disable need-check-nil inv:set_width("main", 9) inv:set_size("main", 36) inv:set_size("offhand", 1) + ---@diagnostic enable need-check-nil --set hotbar size player:hud_set_hotbar_itemcount(9) @@ -175,9 +205,8 @@ minetest.register_on_joinplayer(function(player) return_fields(player, "enchanting_lapis") end) -dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/creative.lua") -mcl_player.register_on_visual_change(mcl_inventory.update_inventory_formspec) +dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/creative.lua") local mt_is_creative_enabled = minetest.is_creative_enabled diff --git a/mods/PLAYER/mcl_player/init.lua b/mods/PLAYER/mcl_player/init.lua index 084fe48a1..520add947 100644 --- a/mods/PLAYER/mcl_player/init.lua +++ b/mods/PLAYER/mcl_player/init.lua @@ -11,15 +11,16 @@ local animation_blend = 0 local function get_mouse_button(player) local controls = player:get_player_control() local get_wielded_item_name = player:get_wielded_item():get_name() - if controls.RMB and not string.find(get_wielded_item_name, "mcl_bows:bow") and not string.find(get_wielded_item_name, "mcl_bows:crossbow") and - not mcl_shields.wielding_shield(player, 1) and not mcl_shields.wielding_shield(player, 2) or controls.LMB then + if controls.RMB and not string.find(get_wielded_item_name, "mcl_bows:bow") and + not string.find(get_wielded_item_name, "mcl_bows:crossbow") and + not mcl_shields.wielding_shield(player, 1) and not mcl_shields.wielding_shield(player, 2) or controls.LMB then return true else return false end end -mcl_player.registered_player_models = { } +mcl_player.registered_player_models = {} -- Local for speed. local models = mcl_player.registered_player_models @@ -49,7 +50,7 @@ function mcl_player.player_get_animation(player) model = player_model[name], textures = textures, animation = player_anim[name], - visibility = player_visibility[name] + visibility = player_visible[name] } end @@ -94,7 +95,7 @@ function mcl_player.player_set_model(player, model_name) player:set_properties({ mesh = model_name, visual = "mesh", - visual_size = model.visual_size or {x=1, y=1}, + visual_size = model.visual_size or { x = 1, y = 1 }, damage_texture_modifier = "^[colorize:red:130", }) update_player_textures(player) @@ -133,6 +134,14 @@ function mcl_player.player_set_armor(player, texture) update_player_textures(player) end +---comment +---@param player ObjectRef +---@param x number +---@param y number +---@param w number +---@param h number +---@param fsname string +---@return string function mcl_player.get_player_formspec_model(player, x, y, w, h, fsname) local name = player:get_player_name() local model = player_model[name] @@ -165,7 +174,8 @@ minetest.register_on_joinplayer(function(player) local name = player:get_player_name() mcl_player.player_attached[name] = false player_visible[name] = true - player_textures[name] = {"character.png", "blank.png", "blank.png"} + player_textures[name] = { "character.png", "blank.png", "blank.png" } + --player:set_local_animation({x=0, y=79}, {x=168, y=187}, {x=189, y=198}, {x=200, y=219}, 30) player:set_fov(86.1) -- see >>> end) @@ -221,11 +231,13 @@ minetest.register_globalstep(function(dtime) elseif mcl_playerplus.elytra[player] and mcl_playerplus.elytra[player].active then player_set_animation(player, "stand") elseif walking and velocity.x > 0.35 - or walking and velocity.x < -0.35 - or walking and velocity.z > 0.35 - or walking and velocity.z < -0.35 then + or walking and velocity.x < -0.35 + or walking and velocity.z > 0.35 + or walking and velocity.z < -0.35 then local wielded_itemname = player:get_wielded_item():get_name() - local no_arm_moving = string.find(wielded_itemname, "mcl_bows:bow") or mcl_shields.wielding_shield(player, 1) or mcl_shields.wielding_shield(player, 2) + local no_arm_moving = string.find(wielded_itemname, "mcl_bows:bow") or + mcl_shields.wielding_shield(player, 1) or + mcl_shields.wielding_shield(player, 2) if player_sneak[name] ~= controls.sneak then player_anim[name] = nil player_sneak[name] = controls.sneak @@ -234,7 +246,8 @@ minetest.register_globalstep(function(dtime) player_set_animation(player, "swim_walk_mine", animation_speed_mod) elseif not controls.sneak and head_in_water and is_sprinting == true then player_set_animation(player, "swim_walk", animation_speed_mod) - elseif no_arm_moving and controls.RMB and controls.sneak or string.find(wielded_itemname, "mcl_bows:crossbow_") and controls.sneak then + elseif no_arm_moving and controls.RMB and controls.sneak or + string.find(wielded_itemname, "mcl_bows:crossbow_") and controls.sneak then player_set_animation(player, "bow_sneak", animation_speed_mod) elseif no_arm_moving and controls.RMB or string.find(wielded_itemname, "mcl_bows:crossbow_") then player_set_animation(player, "bow_walk", animation_speed_mod) diff --git a/textures/mcl_inventory_background9.png b/textures/mcl_inventory_background9.png new file mode 100644 index 0000000000000000000000000000000000000000..d774fd31925f642e35f3fe4f7157bdf93dcf8bdd GIT binary patch literal 5324 zcmeHKdt6N09-pLW3`tinuQ8#Nc|V#NjY^ZLsp%zhqO@nvo|>AMnW?6fqBun&;&eNS z8mBm3M{#sKZ3oa+0N^goy*|_j8SoOuE=}wz@r}j z)O(aWtIPeNU+Nqr)FY@YUY3?Vj+bYOUsoH+|LI|^c$L^xgj72H?VpdK{ zasRXBLGyzbws>cUtT*kVLFvjI%Tvw!{F+zJx~1%Ef57bMYV6qlsuLrL(&3 z#iZK3Bq4q7-^~lv)Hlv{Mv@lM6?kek?d1(hK{;bcMf1<^T5ZJ)C z57KZq=Cf?F`FTRqHSuk2UTb4a3WW6;x9t-DeSWdj6)lh$ZF5c!vH49~U32^UCxnia zy`y?9iq5W!z+Gqwgt0C~SYupUK-tO8KWg8-v8%Mhc5L{Lw~@3ES#n%Wy~Sn`wEow-{HC;hCcH_MEhFwjKMEI=Fc6GT8MeGYS{ZdOmBi zgUy_5UA~c7)ajte^wY-6Zm_Gjw5HkcuQ0m`d;P4*Fxg=lU{Q#JrZM%QI^W(dWx<-rq*1}rZLGS zb1e6J>^C9))r-1j;W4wPfOdmw#DLRm~Gwo-*O!5&<=r(<9~B9uTI+| zn|HX^c>cEa9q#gRF2MsvE^i1b+MZKcZ9SD|79PrJ4*X~4p?OpNIhgVzc@l%t-`ST~7ZM>SA+qx~b zcJIdCmWtgnhNE-Sj)UvXUY6*%O?Q^Q-_draM_Ar-{NV~d@7cYBw|_X>KIZY5Bwyj4 zx#fwZ>Kpkv(+}`WIx%#7Ous2Dt>fBqWTx}{SwryCfr8R|}@ zNmAh#yYeH3B!kk%H4a(8tQpf?`=ZZzK=;vX2EX;LP0BD}DnoK^P+0OVKY|KiryO}~ zKwR0k)$M3Y|D}{Z`4IYGNaGXv&mH43yO_y`sA1>_){*na$IhN@eQa9d^e3t-XYOS; zQG@rMH^=Whe5fgr;EMV7er#>0bIo<7*w{SVcjW@7ikEA~=KX@x_S_&^SQL(#tL-b` z&}`I9w<}pJjIMk)+L!6K+~Lx=$>DY9(+8X%&d{FTqnn05%)gpr6*@bbx5-)E+Hk+V zDE?R_rEH}9z@%fknk89-WH0fX=&8rE(US@bBCg$RD)*?_w{LXo1JTSwj7PpHXh%U@ zo-Tu}v2uPoeQ@!B^;62B7L%x!izt-QdWolJppU2LhfNl2t%WJM9PbP6HXH7i@|QSG zdyKumwU~Vz>(m%@ATR@6yfnJ0s=d)Ix^e5?N+$ZS$(U5D0}}{WPO>Y}>;5p$)NS8h zvMKL%cv!T>gK4##)344D6Yd%<)Sagth#GZObIZ@cQph;rWE#;BK+Ry5P%5%nKKv?m z^6d+?uTI(g{`~NO8uMe~CZh$p+MTwgg3}(Z6_P21ud*&2oOPi3QFYLEg7@3HxF2d1 zg_{WDT&YrVV{bJiJbJT+Z(Xr%zeRv0FGNt5JoA=tN3T`Xpb^}-u`+@vt%3+k@kw(Upkef8HYJ|y#L06+D_xG#SuTq)6zX7PkXm?P49Wq_2kw$diVQx zs8imm>Vxy_v%%ZYP6FO~%LIOGSRo@oB83nkXk|+9Rz#s(-Ly&wjzu(BArd8#b8tPU z&f%~U5eFAa7mx%>Pb6C6ouon*C;5lKNwF|XgmYVfcGa>0fDF+UuE|hc&2ZVmY{FfvQ1FCA^mHe4Yo{u2#qlKP=D2YsIumWU%rm2yL zKaus>*z`Sya7GRUn196mO#4IZ24$cn5U{xlI8Hx2A1(){_sIjj@ki{BE&nB6{ptw+3R4OP~B>Ipe1Kv_Zr3RU($0U;o)FE8`w6H-i zfLKVMrvShJ3u0k=st`z{P=zQIQVvcJfz?|Y(i`hKG%4N^HPA@ZXZ&!^FGf}kwT6~} zRAT7DVhw4_hTtJ5YA7BN85{w-p)NQYl1Cw6eGezp2f5@gCX2-qQ6Qlh!Bat`V7_4p z4+&v0o&~v3Ad%38MibLMM^`JvngmFNctn9nK{OzN4AEd64OGtkTst8e(ep$CYn#LZ z{}3{hO`@>LF3zANk#NM}fQkB5{UKsk;{R~sYET%l4FJ0#8Q5OHZbkgKT@7=lr}1z6 z4bR2j=m9`~b@E00ex>UxU0=k&7b$lWE?dVW#x{MvX#^ zv((>4sDeTpARMFd5qOPxXl6EXlm&BDQ8f_F^x=AhIQ|X?o*$KMtIR|T*If;209R0n f*JjV7sK+HJMZ*#!csA7&D5HG5{JDo0My~r0MPwd9 literal 0 HcmV?d00001 From c2032fe4de645ab43914386635322bd1f17e65f6 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Fri, 9 Sep 2022 19:02:45 +0200 Subject: [PATCH 25/82] Fix --- mods/PLAYER/mcl_player/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/PLAYER/mcl_player/init.lua b/mods/PLAYER/mcl_player/init.lua index 520add947..757d33c0a 100644 --- a/mods/PLAYER/mcl_player/init.lua +++ b/mods/PLAYER/mcl_player/init.lua @@ -1,3 +1,4 @@ +local string = string local sf = string.format -- Minetest 0.4 mod: player @@ -134,7 +135,6 @@ function mcl_player.player_set_armor(player, texture) update_player_textures(player) end ----comment ---@param player ObjectRef ---@param x number ---@param y number From e093c693280cf0a3c0f23b4ca71c256b2b271ba1 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Fri, 9 Sep 2022 20:42:28 +0200 Subject: [PATCH 26/82] Remove the label size thing (too breaking change) --- mods/HUD/mcl_formspec/FORMSPEC_GUIDE.md | 18 +- mods/HUD/mcl_formspec/init.lua | 14 +- mods/ITEMS/mcl_chests/init.lua | 550 ++++++++++++++---------- settingtypes.txt | 5 - 4 files changed, 336 insertions(+), 251 deletions(-) diff --git a/mods/HUD/mcl_formspec/FORMSPEC_GUIDE.md b/mods/HUD/mcl_formspec/FORMSPEC_GUIDE.md index 838e5cbdd..f8576070f 100644 --- a/mods/HUD/mcl_formspec/FORMSPEC_GUIDE.md +++ b/mods/HUD/mcl_formspec/FORMSPEC_GUIDE.md @@ -1,25 +1,21 @@ # MineClone2 Formspec Guide -***This guide will learn you rules about creation of formspecs for the MineClone2 game.*** +**_This guide will learn you rules about creation of formspecs for the MineClone2 game._** Formspecs are an important part of game and mod development. First of all, MineClone2 aims to support ONLY last formspec version. Many utility functions will not work with formspec v1 or v2. -Label font size should be 25 to be minecraft like. We arent modifying formspec prepend in order to not break existing mods. - -Just add this code to apply it to your formspec: -```lua -mcl_formspec.apply_label_size -``` - The typical width of an 9 slots width inventory formspec is `0.375 + 9 + ((9-1) * 0.25) + 0.375 = 11.75` -Margins is 0.375 +Margins is 0.375. + +The labels color is `mcl_formspec.label_color` Space between 1st inventory line and the rest of inventory is 0.45 Labels should have 0.375 space above if there is no other stuff above and 0.45 between content -+ 0.375 under -According to minetest modding book, table.concat is faster than string concatenation, so this method should be prefered (the code is also more clear) \ No newline at end of file +- 0.375 under + +According to minetest modding book, table.concat is faster than string concatenation, so this method should be prefered (the code is also more clear) diff --git a/mods/HUD/mcl_formspec/init.lua b/mods/HUD/mcl_formspec/init.lua index e7817e639..00fa7560e 100644 --- a/mods/HUD/mcl_formspec/init.lua +++ b/mods/HUD/mcl_formspec/init.lua @@ -1,16 +1,12 @@ -local string = string -local table = table - -local sf = string.format - mcl_formspec = {} mcl_formspec.label_color = "#313131" -mcl_formspec.label_size = tonumber(minetest.settings:get("mcl_label_font_size")) or 24 - -mcl_formspec.apply_label_size = sf("style_type[label;font_size=%s]", mcl_formspec.label_size) - +---@param x number +---@param y number +---@param w number +---@param h number +---@return string function mcl_formspec.get_itemslot_bg(x, y, w, h) local out = "" for i = 0, w - 1, 1 do diff --git a/mods/ITEMS/mcl_chests/init.lua b/mods/ITEMS/mcl_chests/init.lua index b870fc362..fb4850759 100644 --- a/mods/ITEMS/mcl_chests/init.lua +++ b/mods/ITEMS/mcl_chests/init.lua @@ -14,37 +14,37 @@ local mod_doc = minetest.get_modpath("doc") local it_is_christmas = false local date = os.date("*t") if ( - date.month == 12 and ( - date.day == 24 or - date.day == 25 or - date.day == 26 - ) -) then + date.month == 12 and ( + date.day == 24 or + date.day == 25 or + date.day == 26 + ) + ) then it_is_christmas = true end -local tiles_chest_normal_small = {"mcl_chests_normal.png"} -local tiles_chest_normal_double = {"mcl_chests_normal_double.png"} +local tiles_chest_normal_small = { "mcl_chests_normal.png" } +local tiles_chest_normal_double = { "mcl_chests_normal_double.png" } if it_is_christmas then - tiles_chest_normal_small = {"mcl_chests_normal_present.png^mcl_chests_noise.png"} - tiles_chest_normal_double = {"mcl_chests_normal_double_present.png^mcl_chests_noise_double.png"} + tiles_chest_normal_small = { "mcl_chests_normal_present.png^mcl_chests_noise.png" } + tiles_chest_normal_double = { "mcl_chests_normal_double_present.png^mcl_chests_noise_double.png" } end -local tiles_chest_trapped_small = {"mcl_chests_trapped.png"} -local tiles_chest_trapped_double = {"mcl_chests_trapped_double.png"} +local tiles_chest_trapped_small = { "mcl_chests_trapped.png" } +local tiles_chest_trapped_double = { "mcl_chests_trapped_double.png" } if it_is_christmas then - tiles_chest_trapped_small = {"mcl_chests_trapped_present.png^mcl_chests_noise.png"} - tiles_chest_trapped_double = {"mcl_chests_trapped_double_present.png^mcl_chests_noise_double.png"} + tiles_chest_trapped_small = { "mcl_chests_trapped_present.png^mcl_chests_noise.png" } + tiles_chest_trapped_double = { "mcl_chests_trapped_double_present.png^mcl_chests_noise_double.png" } end -local tiles_chest_ender_small = {"mcl_chests_ender.png"} +local tiles_chest_ender_small = { "mcl_chests_ender.png" } -local ender_chest_texture = {"mcl_chests_ender.png"} +local ender_chest_texture = { "mcl_chests_ender.png" } if it_is_christmas then - tiles_chest_ender_small = {"mcl_chests_ender_present.png^mcl_chests_noise.png"} - ender_chest_texture = {"mcl_chests_ender_present.png"} + tiles_chest_ender_small = { "mcl_chests_ender_present.png^mcl_chests_noise.png" } + ender_chest_texture = { "mcl_chests_ender_present.png" } end -- Chest Entity @@ -52,19 +52,20 @@ local animate_chests = (minetest.settings:get_bool("animated_chests") ~= false) local entity_animations = { shulker = { speed = 50, - open = {x = 45, y = 95}, - close = {x = 95, y = 145}, + open = { x = 45, y = 95 }, + close = { x = 95, y = 145 }, }, chest = { speed = 25, - open = {x = 0, y = 7}, - close = {x = 13, y = 20}, + open = { x = 0, y = 7 }, + close = { x = 13, y = 20 }, }, } minetest.register_entity("mcl_chests:chest", { initial_properties = { visual = "mesh", + visual_size = { x = 3, y = 3 }, pointable = false, physical = false, static_save = false, @@ -81,7 +82,8 @@ minetest.register_entity("mcl_chests:chest", { self.players[playername] = true if not self.is_open then self:set_animation("open") - minetest.sound_play(self.sound_prefix .. "_open", {pos=self.node_pos, gain=0.5, max_hear_distance = 16}, true) + minetest.sound_play(self.sound_prefix .. "_open", { pos = self.node_pos, gain = 0.5, max_hear_distance = 16 }, + true) self.is_open = true end end, @@ -94,7 +96,8 @@ minetest.register_entity("mcl_chests:chest", { return end self:set_animation("close") - minetest.sound_play(self.sound_prefix .. "_close", {pos=self.node_pos, gain=0.3, max_hear_distance = 16}, true) + minetest.sound_play(self.sound_prefix .. "_close", { pos = self.node_pos, gain = 0.3, max_hear_distance = 16 }, + true) self.is_open = false end end, @@ -133,7 +136,7 @@ minetest.register_entity("mcl_chests:chest", { end, on_activate = function(self) - self.object:set_armor_groups({immortal = 1}) + self.object:set_armor_groups({ immortal = 1 }) self.players = {} end, @@ -167,7 +170,8 @@ local function get_entity_info(pos, param2, double, dir, entity_pos) return dir, get_entity_pos(pos, dir, double) end -local function create_entity(pos, node_name, textures, param2, double, sound_prefix, mesh_prefix, animation_type, dir, entity_pos) +local function create_entity(pos, node_name, textures, param2, double, sound_prefix, mesh_prefix, animation_type, dir, + entity_pos) dir, entity_pos = get_entity_info(pos, param2, double, dir, entity_pos) local obj = minetest.add_entity(entity_pos, "mcl_chests:chest") local luaentity = obj:get_luaentity() @@ -175,9 +179,12 @@ local function create_entity(pos, node_name, textures, param2, double, sound_pre return luaentity end -local function find_or_create_entity(pos, node_name, textures, param2, double, sound_prefix, mesh_prefix, animation_type, dir, entity_pos) +local function find_or_create_entity(pos, node_name, textures, param2, double, sound_prefix, mesh_prefix, animation_type + , dir, entity_pos) dir, entity_pos = get_entity_info(pos, param2, double, dir, entity_pos) - return find_entity(entity_pos) or create_entity(pos, node_name, textures, param2, double, sound_prefix, mesh_prefix, animation_type, dir, entity_pos) + return find_entity(entity_pos) or + create_entity(pos, node_name, textures, param2, double, sound_prefix, mesh_prefix, animation_type, dir, + entity_pos) end local no_rotate, simple_rotate @@ -188,7 +195,9 @@ if minetest.get_modpath("screwdriver") then local nodename = node.name local nodedef = minetest.registered_nodes[nodename] local dir = minetest.facedir_to_dir(new_param2) - find_or_create_entity(pos, nodename, nodedef._chest_entity_textures, new_param2, false, nodedef._chest_entity_sound, nodedef._chest_entity_mesh, nodedef._chest_entity_animation_type, dir):set_yaw(dir) + find_or_create_entity(pos, nodename, nodedef._chest_entity_textures, new_param2, false, + nodedef._chest_entity_sound, + nodedef._chest_entity_mesh, nodedef._chest_entity_animation_type, dir):set_yaw(dir) else return false end @@ -213,10 +222,21 @@ end]] -- To be called if a player opened a chest local function player_chest_open(player, pos, node_name, textures, param2, double, sound, mesh, shulker) local name = player:get_player_name() - open_chests[name] = {pos = pos, node_name = node_name, textures = textures, param2 = param2, double = double, sound = sound, mesh = mesh, shulker = shulker} + open_chests[name] = { + pos = pos, + node_name = node_name, + textures = textures, + param2 = param2, + double = double, + sound = sound, + mesh = mesh, + shulker = shulker + } if animate_chests then local dir = minetest.facedir_to_dir(param2) - find_or_create_entity(pos, node_name, textures, param2, double, sound, mesh, shulker and "shulker" or "chest", dir):open(name) + find_or_create_entity(pos, node_name, textures, param2, double, sound, mesh, shulker and "shulker" or "chest", + dir): + open(name) end end @@ -230,6 +250,7 @@ local function protection_check_move(pos, from_list, from_index, to_list, to_ind return count end end + local function protection_check_put_take(pos, listname, index, stack, player) local name = player:get_player_name() if minetest.is_protected(pos, name) then @@ -247,24 +268,27 @@ local function chest_update_after_close(pos) local node = minetest.get_node(pos) if node.name == "mcl_chests:trapped_chest_on_small" then - minetest.swap_node(pos, {name = "mcl_chests:trapped_chest_small", param2 = node.param2}) - find_or_create_entity(pos, "mcl_chests:trapped_chest_small", {"mcl_chests_trapped.png"}, node.param2, false, "default_chest", "mcl_chests_chest", "chest"):reinitialize("mcl_chests:trapped_chest_small") + minetest.swap_node(pos, { name = "mcl_chests:trapped_chest_small", param2 = node.param2 }) + find_or_create_entity(pos, "mcl_chests:trapped_chest_small", { "mcl_chests_trapped.png" }, node.param2, false, + "default_chest", "mcl_chests_chest", "chest"):reinitialize("mcl_chests:trapped_chest_small") mesecon.receptor_off(pos, trapped_chest_mesecons_rules) elseif node.name == "mcl_chests:trapped_chest_on_left" then - minetest.swap_node(pos, {name="mcl_chests:trapped_chest_left", param2 = node.param2}) - find_or_create_entity(pos, "mcl_chests:trapped_chest_left", tiles_chest_trapped_double, node.param2, true, "default_chest", "mcl_chests_chest", "chest"):reinitialize("mcl_chests:trapped_chest_left") + minetest.swap_node(pos, { name = "mcl_chests:trapped_chest_left", param2 = node.param2 }) + find_or_create_entity(pos, "mcl_chests:trapped_chest_left", tiles_chest_trapped_double, node.param2, true, + "default_chest", "mcl_chests_chest", "chest"):reinitialize("mcl_chests:trapped_chest_left") mesecon.receptor_off(pos, trapped_chest_mesecons_rules) local pos_other = mcl_util.get_double_container_neighbor_pos(pos, node.param2, "left") - minetest.swap_node(pos_other, {name = "mcl_chests:trapped_chest_right", param2 = node.param2}) + minetest.swap_node(pos_other, { name = "mcl_chests:trapped_chest_right", param2 = node.param2 }) mesecon.receptor_off(pos_other, trapped_chest_mesecons_rules) elseif node.name == "mcl_chests:trapped_chest_on_right" then - minetest.swap_node(pos, {name = "mcl_chests:trapped_chest_right", param2 = node.param2}) + minetest.swap_node(pos, { name = "mcl_chests:trapped_chest_right", param2 = node.param2 }) mesecon.receptor_off(pos, trapped_chest_mesecons_rules) local pos_other = mcl_util.get_double_container_neighbor_pos(pos, node.param2, "right") - minetest.swap_node(pos_other, {name="mcl_chests:trapped_chest_left", param2 = node.param2}) - find_or_create_entity(pos_other, "mcl_chests:trapped_chest_left", tiles_chest_trapped_double, node.param2, true, "default_chest", "mcl_chests_chest", "chest"):reinitialize("mcl_chests:trapped_chest_left") + minetest.swap_node(pos_other, { name = "mcl_chests:trapped_chest_left", param2 = node.param2 }) + find_or_create_entity(pos_other, "mcl_chests:trapped_chest_left", tiles_chest_trapped_double, node.param2, true, + "default_chest", "mcl_chests_chest", "chest"):reinitialize("mcl_chests:trapped_chest_left") mesecon.receptor_off(pos_other, trapped_chest_mesecons_rules) end end @@ -277,7 +301,9 @@ local function player_chest_close(player) return end if animate_chests then - find_or_create_entity(open_chest.pos, open_chest.node_name, open_chest.textures, open_chest.param2, open_chest.double, open_chest.sound, open_chest.mesh, open_chest.shulker and "shulker" or "chest"):close(name) + find_or_create_entity(open_chest.pos, open_chest.node_name, open_chest.textures, open_chest.param2, + open_chest.double, + open_chest.sound, open_chest.mesh, open_chest.shulker and "shulker" or "chest"):close(name) end chest_update_after_close(open_chest.pos) @@ -285,12 +311,14 @@ local function player_chest_close(player) end -- This is a helper function to register both chests and trapped chests. Trapped chests will make use of the additional parameters -local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tiles_table, hidden, mesecons, on_rightclick_addendum, on_rightclick_addendum_left, on_rightclick_addendum_right, drop, canonical_basename) +local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tiles_table, hidden, mesecons, + on_rightclick_addendum, on_rightclick_addendum_left, on_rightclick_addendum_right, drop, + canonical_basename) -- START OF register_chest FUNCTION BODY if not drop then - drop = "mcl_chests:"..basename + drop = "mcl_chests:" .. basename else - drop = "mcl_chests:"..drop + drop = "mcl_chests:" .. drop end -- The basename of the "canonical" version of the node, if set (e.g.: trapped_chest_on → trapped_chest). -- Used to get a shared formspec ID and to swap the node back to the canonical version in on_construct. @@ -356,12 +384,12 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile return stack:get_count() - leftover:get_count() end - local small_name = "mcl_chests:"..basename.."_small" + local small_name = "mcl_chests:" .. basename .. "_small" local small_textures = tiles_table.small - local left_name = "mcl_chests:"..basename.."_left" + local left_name = "mcl_chests:" .. basename .. "_left" local left_textures = tiles_table.double - minetest.register_node("mcl_chests:"..basename, { + minetest.register_node("mcl_chests:" .. basename, { description = desc, _tt_help = tt_help, _doc_items_longdesc = longdesc, @@ -375,7 +403,7 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile paramtype2 = "facedir", stack_max = 64, sounds = mcl_sounds.node_sound_wood_defaults(), - groups = {deco_block=1}, + groups = { deco_block = 1 }, on_construct = function(pos, node) local node = minetest.get_node(pos) node.name = small_name @@ -388,9 +416,10 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile local function close_forms(canonical_basename, pos) local players = minetest.get_connected_players() - for p=1, #players do + for p = 1, #players do if vector.distance(players[p]:get_pos(), pos) <= 30 then - minetest.close_formspec(players[p]:get_player_name(), "mcl_chests:"..canonical_basename.."_"..pos.x.."_"..pos.y.."_"..pos.z) + minetest.close_formspec(players[p]:get_player_name(), + "mcl_chests:" .. canonical_basename .. "_" .. pos.x .. "_" .. pos.y .. "_" .. pos.z) end end end @@ -404,9 +433,9 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile drawtype = "nodebox", node_box = { type = "fixed", - fixed = {-0.4375, -0.5, -0.4375, 0.4375, 0.375, 0.4375}, + fixed = { -0.4375, -0.5, -0.4375, 0.4375, 0.375, 0.4375 }, }, - tiles = {"blank.png^[resize:16x16"}, + tiles = { "blank.png^[resize:16x16" }, use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "clip" or true, _chest_entity_textures = small_textures, _chest_entity_sound = "default_chest", @@ -416,7 +445,16 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile paramtype2 = "facedir", stack_max = 64, drop = drop, - groups = {handy=1,axey=1, container=2, deco_block=1, material_wood=1,flammable=-1,chest_entity=1, not_in_creative_inventory=1}, + groups = { + handy = 1, + axey = 1, + container = 2, + deco_block = 1, + material_wood = 1, + flammable = -1, + chest_entity = 1, + not_in_creative_inventory = 1 + }, is_ground_content = false, sounds = mcl_sounds.node_sound_wood_defaults(), on_construct = function(pos) @@ -433,7 +471,7 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile meta:set_string("workaround", nil) -- Done to keep metadata clean -- END OF WORKAROUND -- local inv = meta:get_inventory() - inv:set_size("main", 9*3) + inv:set_size("main", 9 * 3) --[[ The "input" list is *another* workaround (hahahaha!) around the fact that Minetest does not support listrings to put items into an alternative list if the first one happens to be full. See . @@ -444,19 +482,26 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile -- BEGIN OF LISTRING WORKAROUND inv:set_size("input", 1) -- END OF LISTRING WORKAROUND - if minetest.get_node(mcl_util.get_double_container_neighbor_pos(pos, param2, "right")).name == "mcl_chests:"..canonical_basename.."_small" then - minetest.swap_node(pos, {name="mcl_chests:"..canonical_basename.."_right",param2=param2}) + if minetest.get_node(mcl_util.get_double_container_neighbor_pos(pos, param2, "right")).name == + "mcl_chests:" .. canonical_basename .. "_small" then + minetest.swap_node(pos, { name = "mcl_chests:" .. canonical_basename .. "_right", param2 = param2 }) local p = mcl_util.get_double_container_neighbor_pos(pos, param2, "right") - minetest.swap_node(p, { name = "mcl_chests:"..canonical_basename.."_left", param2 = param2 }) - create_entity(p, "mcl_chests:"..canonical_basename.."_left", left_textures, param2, true, "default_chest", "mcl_chests_chest", "chest") - elseif minetest.get_node(mcl_util.get_double_container_neighbor_pos(pos, param2, "left")).name == "mcl_chests:"..canonical_basename.."_small" then - minetest.swap_node(pos, {name="mcl_chests:"..canonical_basename.."_left",param2=param2}) - create_entity(pos, "mcl_chests:"..canonical_basename.."_left", left_textures, param2, true, "default_chest", "mcl_chests_chest", "chest") + minetest.swap_node(p, { name = "mcl_chests:" .. canonical_basename .. "_left", param2 = param2 }) + create_entity(p, "mcl_chests:" .. canonical_basename .. "_left", left_textures, param2, true, + "default_chest", + "mcl_chests_chest", "chest") + elseif minetest.get_node(mcl_util.get_double_container_neighbor_pos(pos, param2, "left")).name == + "mcl_chests:" .. canonical_basename .. "_small" then + minetest.swap_node(pos, { name = "mcl_chests:" .. canonical_basename .. "_left", param2 = param2 }) + create_entity(pos, "mcl_chests:" .. canonical_basename .. "_left", left_textures, param2, true, + "default_chest", + "mcl_chests_chest", "chest") local p = mcl_util.get_double_container_neighbor_pos(pos, param2, "left") - minetest.swap_node(p, { name = "mcl_chests:"..canonical_basename.."_right", param2 = param2 }) + minetest.swap_node(p, { name = "mcl_chests:" .. canonical_basename .. "_right", param2 = param2 }) else - minetest.swap_node(pos, { name = "mcl_chests:"..canonical_basename.."_small", param2 = param2 }) - create_entity(pos, small_name, small_textures, param2, false, "default_chest", "mcl_chests_chest", "chest") + minetest.swap_node(pos, { name = "mcl_chests:" .. canonical_basename .. "_small", param2 = param2 }) + create_entity(pos, small_name, small_textures, param2, false, "default_chest", "mcl_chests_chest", + "chest") end end, after_place_node = function(pos, placer, itemstack, pointed_thing) @@ -468,28 +513,28 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile allow_metadata_inventory_take = protection_check_put_take, allow_metadata_inventory_put = protection_check_put_take, on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) - minetest.log("action", player:get_player_name().. - " moves stuff in chest at "..minetest.pos_to_string(pos)) + minetest.log("action", player:get_player_name() .. + " moves stuff in chest at " .. minetest.pos_to_string(pos)) end, on_metadata_inventory_put = function(pos, listname, index, stack, player) - minetest.log("action", player:get_player_name().. - " moves stuff to chest at "..minetest.pos_to_string(pos)) + minetest.log("action", player:get_player_name() .. + " moves stuff to chest at " .. minetest.pos_to_string(pos)) -- BEGIN OF LISTRING WORKAROUND if listname == "input" then - local inv = minetest.get_inventory({type="node", pos=pos}) + local inv = minetest.get_inventory({ type = "node", pos = pos }) inv:add_item("main", stack) end -- END OF LISTRING WORKAROUND end, on_metadata_inventory_take = function(pos, listname, index, stack, player) - minetest.log("action", player:get_player_name().. - " takes stuff from chest at "..minetest.pos_to_string(pos)) + minetest.log("action", player:get_player_name() .. + " takes stuff from chest at " .. minetest.pos_to_string(pos)) end, _mcl_blast_resistance = 2.5, _mcl_hardness = 2.5, on_rightclick = function(pos, node, clicker) - if minetest.registered_nodes[minetest.get_node({x = pos.x, y = pos.y + 1, z = pos.z}).name].groups.opaque == 1 then + if minetest.registered_nodes[minetest.get_node({ x = pos.x, y = pos.y + 1, z = pos.z }).name].groups.opaque == 1 then -- won't open if there is no space from the top return false end @@ -503,21 +548,16 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile table.concat({ "formspec_version[4]", "size[11.75,10.425]", - mcl_formspec.apply_label_size, - - "label[0.375,0.375;"..F(C(mcl_formspec.label_color, name)).."]", + "label[0.375,0.375;" .. F(C(mcl_formspec.label_color, name)) .. "]", mcl_formspec.get_itemslot_bg_v4(0.375, 0.75, 9, 3), sf("list[nodemeta:%s,%s,%s;main;0.375,0.75;9,3;]", pos.x, pos.y, pos.z), - - "label[0.375,4.7;"..F(C(mcl_formspec.label_color, S("Inventory"))).."]", - + "label[0.375,4.7;" .. F(C(mcl_formspec.label_color, S("Inventory"))) .. "]", mcl_formspec.get_itemslot_bg_v4(0.375, 5.1, 9, 3), "list[current_player;main;0.375,5.1;9,3;9]", mcl_formspec.get_itemslot_bg_v4(0.375, 9.05, 9, 1), "list[current_player;main;0.375,9.05;9,1;]", - sf("listring[nodemeta:%s,%s,%s;main]", pos.x, pos.y, pos.z), "listring[current_player;main]", }) @@ -527,7 +567,8 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile on_rightclick_addendum(pos, node, clicker) end - player_chest_open(clicker, pos, small_name, small_textures, node.param2, false, "default_chest", "mcl_chests_chest") + player_chest_open(clicker, pos, small_name, small_textures, node.param2, false, "default_chest", + "mcl_chests_chest") end, on_destruct = function(pos) @@ -541,9 +582,9 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile drawtype = "nodebox", node_box = { type = "fixed", - fixed = {-0.4375, -0.5, -0.4375, 0.5, 0.375, 0.4375}, + fixed = { -0.4375, -0.5, -0.4375, 0.5, 0.375, 0.4375 }, }, - tiles = {"blank.png^[resize:16x16"}, + tiles = { "blank.png^[resize:16x16" }, use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "clip" or true, _chest_entity_textures = left_textures, _chest_entity_sound = "default_chest", @@ -551,7 +592,16 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile _chest_entity_animation_type = "chest", paramtype = "light", paramtype2 = "facedir", - groups = {handy=1,axey=1, container=5,not_in_creative_inventory=1, material_wood=1,flammable=-1,chest_entity=1,double_chest=1}, + groups = { + handy = 1, + axey = 1, + container = 5, + not_in_creative_inventory = 1, + material_wood = 1, + flammable = -1, + chest_entity = 1, + double_chest = 1 + }, drop = drop, is_ground_content = false, sounds = mcl_sounds.node_sound_wood_defaults(), @@ -559,8 +609,8 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile local n = minetest.get_node(pos) local param2 = n.param2 local p = mcl_util.get_double_container_neighbor_pos(pos, param2, "left") - if not p or minetest.get_node(p).name ~= "mcl_chests:"..canonical_basename.."_right" then - n.name = "mcl_chests:"..canonical_basename.."_small" + if not p or minetest.get_node(p).name ~= "mcl_chests:" .. canonical_basename .. "_right" then + n.name = "mcl_chests:" .. canonical_basename .. "_small" minetest.swap_node(pos, n) end create_entity(pos, left_name, left_textures, param2, true, "default_chest", "mcl_chests_chest", "chest") @@ -578,7 +628,7 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile local param2 = n.param2 local p = mcl_util.get_double_container_neighbor_pos(pos, param2, "left") - if not p or minetest.get_node(p).name ~= "mcl_chests:"..basename.."_right" then + if not p or minetest.get_node(p).name ~= "mcl_chests:" .. basename .. "_right" then return end close_forms(canonical_basename, p) @@ -595,11 +645,11 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile if minetest.is_protected(pos, name) then minetest.record_protection_violation(pos, name) return 0 - -- BEGIN OF LISTRING WORKAROUND + -- BEGIN OF LISTRING WORKAROUND elseif listname == "input" then - local inv = minetest.get_inventory({type="node", pos=pos}) + local inv = minetest.get_inventory({ type = "node", pos = pos }) local other_pos = mcl_util.get_double_container_neighbor_pos(pos, minetest.get_node(pos).param2, "left") - local other_inv = minetest.get_inventory({type="node", pos=other_pos}) + local other_inv = minetest.get_inventory({ type = "node", pos = other_pos }) return limit_put(stack, inv, other_inv) --[[if inv:room_for_item("main", stack) then return -1 @@ -610,24 +660,25 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile else return 0 end - end]]-- - -- END OF LISTRING WORKAROUND + end]] + -- + -- END OF LISTRING WORKAROUND else return stack:get_count() end end, on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) - minetest.log("action", player:get_player_name().. - " moves stuff in chest at "..minetest.pos_to_string(pos)) + minetest.log("action", player:get_player_name() .. + " moves stuff in chest at " .. minetest.pos_to_string(pos)) end, on_metadata_inventory_put = function(pos, listname, index, stack, player) - minetest.log("action", player:get_player_name().. - " moves stuff to chest at "..minetest.pos_to_string(pos)) + minetest.log("action", player:get_player_name() .. + " moves stuff to chest at " .. minetest.pos_to_string(pos)) -- BEGIN OF LISTRING WORKAROUND if listname == "input" then - local inv = minetest.get_inventory({type="node", pos=pos}) + local inv = minetest.get_inventory({ type = "node", pos = pos }) local other_pos = mcl_util.get_double_container_neighbor_pos(pos, minetest.get_node(pos).param2, "left") - local other_inv = minetest.get_inventory({type="node", pos=other_pos}) + local other_inv = minetest.get_inventory({ type = "node", pos = other_pos }) inv:set_stack("input", 1, nil) @@ -636,16 +687,17 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile -- END OF LISTRING WORKAROUND end, on_metadata_inventory_take = function(pos, listname, index, stack, player) - minetest.log("action", player:get_player_name().. - " takes stuff from chest at "..minetest.pos_to_string(pos)) + minetest.log("action", player:get_player_name() .. + " takes stuff from chest at " .. minetest.pos_to_string(pos)) end, _mcl_blast_resistance = 2.5, _mcl_hardness = 2.5, on_rightclick = function(pos, node, clicker) local pos_other = mcl_util.get_double_container_neighbor_pos(pos, node.param2, "left") - local above_def = minetest.registered_nodes[minetest.get_node({x = pos.x, y = pos.y + 1, z = pos.z}).name] - local above_def_other = minetest.registered_nodes[minetest.get_node({x = pos_other.x, y = pos_other.y + 1, z = pos_other.z}).name] + local above_def = minetest.registered_nodes[minetest.get_node({ x = pos.x, y = pos.y + 1, z = pos.z }).name] + local above_def_other = minetest.registered_nodes[ + minetest.get_node({ x = pos_other.x, y = pos_other.y + 1, z = pos_other.z }).name] if not above_def or above_def.groups.opaque == 1 or not above_def_other or above_def_other.groups.opaque == 1 then -- won't open if there is no space from the top @@ -665,18 +717,13 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile table.concat({ "formspec_version[4]", "size[11.75,14.15]", - mcl_formspec.apply_label_size, - - "label[0.375,0.375;"..F(C(mcl_formspec.label_color, name)).."]", + "label[0.375,0.375;" .. F(C(mcl_formspec.label_color, name)) .. "]", mcl_formspec.get_itemslot_bg_v4(0.375, 0.75, 9, 3), sf("list[nodemeta:%s,%s,%s;main;0.375,0.75;9,3;]", pos.x, pos.y, pos.z), - mcl_formspec.get_itemslot_bg_v4(0.375, 4.5, 9, 3), sf("list[nodemeta:%s,%s,%s;main;0.375,4.5;9,3;]", pos_other.x, pos_other.y, pos_other.z), - - "label[0.375,8.45;"..F(C(mcl_formspec.label_color, S("Inventory"))).."]", - + "label[0.375,8.45;" .. F(C(mcl_formspec.label_color, S("Inventory"))) .. "]", mcl_formspec.get_itemslot_bg_v4(0.375, 8.825, 9, 3), "list[current_player;main;0.375,8.825;9,3;9]", @@ -687,7 +734,7 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile "listring[current_player;main]", sf("listring[nodemeta:%s,%s,%s;input]", pos.x, pos.y, pos.z), --END OF LISTRING WORKAROUND - "listring[current_player;main]".. + "listring[current_player;main]" .. sf("listring[nodemeta:%s,%s,%s;main]", pos.x, pos.y, pos.z), "listring[current_player;main]", sf("listring[nodemeta:%s,%s,%s;main]", pos_other.x, pos_other.y, pos_other.z), @@ -698,23 +745,32 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile on_rightclick_addendum_left(pos, node, clicker) end - player_chest_open(clicker, pos, left_name, left_textures, node.param2, true, "default_chest", "mcl_chests_chest") + player_chest_open(clicker, pos, left_name, left_textures, node.param2, true, "default_chest", + "mcl_chests_chest") end, mesecons = mesecons, on_rotate = no_rotate, }) - minetest.register_node("mcl_chests:"..basename.."_right", { + minetest.register_node("mcl_chests:" .. basename .. "_right", { drawtype = "nodebox", paramtype = "light", paramtype2 = "facedir", node_box = { type = "fixed", - fixed = {-0.5, -0.5, -0.4375, 0.4375, 0.375, 0.4375}, + fixed = { -0.5, -0.5, -0.4375, 0.4375, 0.375, 0.4375 }, }, - tiles = {"blank.png^[resize:16x16"}, + tiles = { "blank.png^[resize:16x16" }, use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "clip" or true, - groups = {handy=1,axey=1, container=6,not_in_creative_inventory=1, material_wood=1,flammable=-1,double_chest=2}, + groups = { + handy = 1, + axey = 1, + container = 6, + not_in_creative_inventory = 1, + material_wood = 1, + flammable = -1, + double_chest = 2 + }, drop = drop, is_ground_content = false, sounds = mcl_sounds.node_sound_wood_defaults(), @@ -722,8 +778,8 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile local n = minetest.get_node(pos) local param2 = n.param2 local p = mcl_util.get_double_container_neighbor_pos(pos, param2, "right") - if not p or minetest.get_node(p).name ~= "mcl_chests:"..canonical_basename.."_left" then - n.name = "mcl_chests:"..canonical_basename.."_small" + if not p or minetest.get_node(p).name ~= "mcl_chests:" .. canonical_basename .. "_left" then + n.name = "mcl_chests:" .. canonical_basename .. "_small" minetest.swap_node(pos, n) end end, @@ -740,7 +796,7 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile local param2 = n.param2 local p = mcl_util.get_double_container_neighbor_pos(pos, param2, "right") - if not p or minetest.get_node(p).name ~= "mcl_chests:"..basename.."_left" then + if not p or minetest.get_node(p).name ~= "mcl_chests:" .. basename .. "_left" then return end close_forms(canonical_basename, p) @@ -757,11 +813,11 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile if minetest.is_protected(pos, name) then minetest.record_protection_violation(pos, name) return 0 - -- BEGIN OF LISTRING WORKAROUND + -- BEGIN OF LISTRING WORKAROUND elseif listname == "input" then local other_pos = mcl_util.get_double_container_neighbor_pos(pos, minetest.get_node(pos).param2, "right") - local other_inv = minetest.get_inventory({type="node", pos=other_pos}) - local inv = minetest.get_inventory({type="node", pos=pos}) + local other_inv = minetest.get_inventory({ type = "node", pos = other_pos }) + local inv = minetest.get_inventory({ type = "node", pos = pos }) --[[if other_inv:room_for_item("main", stack) then return -1 else @@ -772,23 +828,23 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile end end--]] return limit_put(stack, other_inv, inv) - -- END OF LISTRING WORKAROUND + -- END OF LISTRING WORKAROUND else return stack:get_count() end end, on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) - minetest.log("action", player:get_player_name().. - " moves stuff in chest at "..minetest.pos_to_string(pos)) + minetest.log("action", player:get_player_name() .. + " moves stuff in chest at " .. minetest.pos_to_string(pos)) end, on_metadata_inventory_put = function(pos, listname, index, stack, player) - minetest.log("action", player:get_player_name().. - " moves stuff to chest at "..minetest.pos_to_string(pos)) + minetest.log("action", player:get_player_name() .. + " moves stuff to chest at " .. minetest.pos_to_string(pos)) -- BEGIN OF LISTRING WORKAROUND if listname == "input" then local other_pos = mcl_util.get_double_container_neighbor_pos(pos, minetest.get_node(pos).param2, "right") - local other_inv = minetest.get_inventory({type="node", pos=other_pos}) - local inv = minetest.get_inventory({type="node", pos=pos}) + local other_inv = minetest.get_inventory({ type = "node", pos = other_pos }) + local inv = minetest.get_inventory({ type = "node", pos = pos }) inv:set_stack("input", 1, nil) @@ -797,18 +853,20 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile -- END OF LISTRING WORKAROUND end, on_metadata_inventory_take = function(pos, listname, index, stack, player) - minetest.log("action", player:get_player_name().. - " takes stuff from chest at "..minetest.pos_to_string(pos)) + minetest.log("action", player:get_player_name() .. + " takes stuff from chest at " .. minetest.pos_to_string(pos)) end, _mcl_blast_resistance = 2.5, _mcl_hardness = 2.5, on_rightclick = function(pos, node, clicker) local pos_other = mcl_util.get_double_container_neighbor_pos(pos, node.param2, "right") - if minetest.registered_nodes[minetest.get_node({x = pos.x, y = pos.y + 1, z = pos.z}).name].groups.opaque == 1 - or minetest.registered_nodes[minetest.get_node({x = pos_other.x, y = pos_other.y + 1, z = pos_other.z}).name].groups.opaque == 1 then - -- won't open if there is no space from the top - return false + if minetest.registered_nodes[minetest.get_node({ x = pos.x, y = pos.y + 1, z = pos.z }).name].groups.opaque == 1 + or + minetest.registered_nodes[minetest.get_node({ x = pos_other.x, y = pos_other.y + 1, z = pos_other.z }).name].groups.opaque + == 1 then + -- won't open if there is no space from the top + return false end local name = minetest.get_meta(pos_other):get_string("name") @@ -824,18 +882,13 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile table.concat({ "formspec_version[4]", "size[11.75,14.15]", - mcl_formspec.apply_label_size, - - "label[0.375,0.375;"..F(C(mcl_formspec.label_color, name)).."]", + "label[0.375,0.375;" .. F(C(mcl_formspec.label_color, name)) .. "]", mcl_formspec.get_itemslot_bg_v4(0.375, 0.75, 9, 3), sf("list[nodemeta:%s,%s,%s;main;0.375,0.75;9,3;]", pos_other.x, pos_other.y, pos_other.z), - mcl_formspec.get_itemslot_bg_v4(0.375, 4.5, 9, 3), sf("list[nodemeta:%s,%s,%s;main;0.375,4.5;9,3;]", pos.x, pos.y, pos.z), - - "label[0.375,8.45;"..F(C(mcl_formspec.label_color, S("Inventory"))).."]", - + "label[0.375,8.45;" .. F(C(mcl_formspec.label_color, S("Inventory"))) .. "]", mcl_formspec.get_itemslot_bg_v4(0.375, 8.825, 9, 3), "list[current_player;main;0.375,8.825;9,3;9]", @@ -846,7 +899,7 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile "listring[current_player;main]", sf("listring[nodemeta:%s,%s,%s;input]", pos.x, pos.y, pos.z), --END OF LISTRING WORKAROUND - "listring[current_player;main]".. + "listring[current_player;main]" .. sf("listring[nodemeta:%s,%s,%s;main]", pos_other.x, pos_other.y, pos_other.z), "listring[current_player;main]", sf("listring[nodemeta:%s,%s,%s;main]", pos.x, pos.y, pos.z), @@ -857,15 +910,16 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile on_rightclick_addendum_right(pos, node, clicker) end - player_chest_open(clicker, pos_other, left_name, left_textures, node.param2, true, "default_chest", "mcl_chests_chest") + player_chest_open(clicker, pos_other, left_name, left_textures, node.param2, true, "default_chest", + "mcl_chests_chest") end, mesecons = mesecons, on_rotate = no_rotate, }) if mod_doc then - doc.add_entry_alias("nodes", small_name, "nodes", "mcl_chests:"..basename.."_left") - doc.add_entry_alias("nodes", small_name, "nodes", "mcl_chests:"..basename.."_right") + doc.add_entry_alias("nodes", small_name, "nodes", "mcl_chests:" .. basename .. "_left") + doc.add_entry_alias("nodes", small_name, "nodes", "mcl_chests:" .. basename .. "_right") end -- END OF register_chest FUNCTION BODY @@ -875,12 +929,23 @@ local chestusage = S("To access its inventory, rightclick it. When broken, the i register_chest("chest", S("Chest"), - S("Chests are containers which provide 27 inventory slots. Chests can be turned into large chests with double the capacity by placing two chests next to each other."), + S( + "Chests are containers which provide 27 inventory slots. Chests can be turned into large chests with double the capacity by placing two chests next to each other.") + , chestusage, S("27 inventory slots") .. "\n" .. S("Can be combined to a large chest"), { small = tiles_chest_normal_small, double = tiles_chest_normal_double, + inv = { "default_chest_top.png", "mcl_chests_chest_bottom.png", + "mcl_chests_chest_right.png", "mcl_chests_chest_left.png", + "mcl_chests_chest_back.png", "default_chest_front.png" }, + --[[left = {"default_chest_top_big.png", "default_chest_top_big.png", + "mcl_chests_chest_right.png", "mcl_chests_chest_left.png", + "default_chest_side_big.png^[transformFX", "default_chest_front_big.png"}, + right = {"default_chest_top_big.png^[transformFX", "default_chest_top_big.png^[transformFX", + "mcl_chests_chest_right.png", "mcl_chests_chest_left.png", + "default_chest_side_big.png", "default_chest_front_big.png^[transformFX"},]] -- }, false ) @@ -892,9 +957,12 @@ local traptiles = { register_chest("trapped_chest", S("Trapped Chest"), - S("A trapped chest is a container which provides 27 inventory slots. When it is opened, it sends a redstone signal to its adjacent blocks as long it stays open. Trapped chests can be turned into large trapped chests with double the capacity by placing two trapped chests next to each other."), + S( + "A trapped chest is a container which provides 27 inventory slots. When it is opened, it sends a redstone signal to its adjacent blocks as long it stays open. Trapped chests can be turned into large trapped chests with double the capacity by placing two trapped chests next to each other.") + , chestusage, - S("27 inventory slots") .. "\n" .. S("Can be combined to a large chest") .. "\n" .. S("Emits a redstone signal when opened"), + S("27 inventory slots") .. + "\n" .. S("Can be combined to a large chest") .. "\n" .. S("Emits a redstone signal when opened"), traptiles, nil, { @@ -904,30 +972,34 @@ register_chest("trapped_chest", }, }, function(pos, node, clicker) - minetest.swap_node(pos, {name="mcl_chests:trapped_chest_on_small", param2 = node.param2}) - find_or_create_entity(pos, "mcl_chests:trapped_chest_on_small", {"mcl_chests_trapped.png"}, node.param2, false, "default_chest", "mcl_chests_chest", "chest"):reinitialize("mcl_chests:trapped_chest_on_small") + minetest.swap_node(pos, { name = "mcl_chests:trapped_chest_on_small", param2 = node.param2 }) + find_or_create_entity(pos, "mcl_chests:trapped_chest_on_small", { "mcl_chests_trapped.png" }, node.param2, false, + "default_chest", "mcl_chests_chest", "chest"):reinitialize("mcl_chests:trapped_chest_on_small") mesecon.receptor_on(pos, trapped_chest_mesecons_rules) end, function(pos, node, clicker) local meta = minetest.get_meta(pos) meta:set_int("players", 1) - minetest.swap_node(pos, {name="mcl_chests:trapped_chest_on_left", param2 = node.param2}) - find_or_create_entity(pos, "mcl_chests:trapped_chest_on_left", tiles_chest_trapped_double, node.param2, true, "default_chest", "mcl_chests_chest", "chest"):reinitialize("mcl_chests:trapped_chest_on_left") + minetest.swap_node(pos, { name = "mcl_chests:trapped_chest_on_left", param2 = node.param2 }) + find_or_create_entity(pos, "mcl_chests:trapped_chest_on_left", tiles_chest_trapped_double, node.param2, true, + "default_chest", "mcl_chests_chest", "chest"):reinitialize("mcl_chests:trapped_chest_on_left") mesecon.receptor_on(pos, trapped_chest_mesecons_rules) local pos_other = mcl_util.get_double_container_neighbor_pos(pos, node.param2, "left") - minetest.swap_node(pos_other, {name="mcl_chests:trapped_chest_on_right", param2 = node.param2}) + minetest.swap_node(pos_other, { name = "mcl_chests:trapped_chest_on_right", param2 = node.param2 }) mesecon.receptor_on(pos_other, trapped_chest_mesecons_rules) end, function(pos, node, clicker) local pos_other = mcl_util.get_double_container_neighbor_pos(pos, node.param2, "right") - minetest.swap_node(pos, {name="mcl_chests:trapped_chest_on_right", param2 = node.param2}) + minetest.swap_node(pos, { name = "mcl_chests:trapped_chest_on_right", param2 = node.param2 }) mesecon.receptor_on(pos, trapped_chest_mesecons_rules) - minetest.swap_node(pos_other, {name="mcl_chests:trapped_chest_on_left", param2 = node.param2}) - find_or_create_entity(pos_other, "mcl_chests:trapped_chest_on_left", tiles_chest_trapped_double, node.param2, true, "default_chest", "mcl_chests_chest", "chest"):reinitialize("mcl_chests:trapped_chest_on_left") + minetest.swap_node(pos_other, { name = "mcl_chests:trapped_chest_on_left", param2 = node.param2 }) + find_or_create_entity(pos_other, "mcl_chests:trapped_chest_on_left", tiles_chest_trapped_double, node.param2, + true, + "default_chest", "mcl_chests_chest", "chest"):reinitialize("mcl_chests:trapped_chest_on_left") mesecon.receptor_on(pos_other, trapped_chest_mesecons_rules) end ) @@ -993,9 +1065,9 @@ end) minetest.register_craft({ output = "mcl_chests:chest", recipe = { - {"group:wood", "group:wood", "group:wood"}, - {"group:wood", "", "group:wood"}, - {"group:wood", "group:wood", "group:wood"}, + { "group:wood", "group:wood", "group:wood" }, + { "group:wood", "", "group:wood" }, + { "group:wood", "group:wood", "group:wood" }, }, }) @@ -1013,8 +1085,10 @@ minetest.register_craft({ minetest.register_node("mcl_chests:ender_chest", { description = S("Ender Chest"), - _tt_help = S("27 interdimensional inventory slots") .. "\n" .. S("Put items inside, retrieve them from any ender chest"), - _doc_items_longdesc = S("Ender chests grant you access to a single personal interdimensional inventory with 27 slots. This inventory is the same no matter from which ender chest you access it from. If you put one item into one ender chest, you will find it in all other ender chests. Each player will only see their own items, but not the items of other players."), + _tt_help = S("27 interdimensional inventory slots") .. + "\n" .. S("Put items inside, retrieve them from any ender chest"), + _doc_items_longdesc = S( + "Ender chests grant you access to a single personal interdimensional inventory with 27 slots. This inventory is the same no matter from which ender chest you access it from. If you put one item into one ender chest, you will find it in all other ender chests. Each player will only see their own items, but not the items of other players."), _doc_items_usagehelp = S("Rightclick the ender chest to access your personal interdimensional inventory."), drawtype = "mesh", mesh = "mcl_chests_chest.b3d", @@ -1023,7 +1097,7 @@ minetest.register_node("mcl_chests:ender_chest", { paramtype = "light", paramtype2 = "facedir", stack_max = 64, - groups = {deco_block=1}, + groups = { deco_block = 1 }, sounds = mcl_sounds.node_sound_stone_defaults(), on_construct = function(pos, node) local node = minetest.get_node(pos) @@ -1035,15 +1109,11 @@ minetest.register_node("mcl_chests:ender_chest", { local formspec_ender_chest = table.concat({ "formspec_version[4]", "size[11.75,10.425]", - mcl_formspec.apply_label_size, - - "label[0.375,0.375;"..F(C(mcl_formspec.label_color, S("Ender Chest"))).."]", + "label[0.375,0.375;" .. F(C(mcl_formspec.label_color, S("Ender Chest"))) .. "]", mcl_formspec.get_itemslot_bg_v4(0.375, 0.75, 9, 3), "list[current_player;enderchest;0.375,0.75;9,3;]", - - "label[0.375,4.7;"..F(C(mcl_formspec.label_color, S("Inventory"))).."]", - + "label[0.375,4.7;" .. F(C(mcl_formspec.label_color, S("Inventory"))) .. "]", mcl_formspec.get_itemslot_bg_v4(0.375, 5.1, 9, 3), "list[current_player;main;0.375,5.1;9,3;9]", @@ -1057,23 +1127,25 @@ local formspec_ender_chest = table.concat({ minetest.register_node("mcl_chests:ender_chest_small", { description = S("Ender Chest"), - _tt_help = S("27 interdimensional inventory slots") .. "\n" .. S("Put items inside, retrieve them from any ender chest"), - _doc_items_longdesc = S("Ender chests grant you access to a single personal interdimensional inventory with 27 slots. This inventory is the same no matter from which ender chest you access it from. If you put one item into one ender chest, you will find it in all other ender chests. Each player will only see their own items, but not the items of other players."), + _tt_help = S("27 interdimensional inventory slots") .. + "\n" .. S("Put items inside, retrieve them from any ender chest"), + _doc_items_longdesc = S( + "Ender chests grant you access to a single personal interdimensional inventory with 27 slots. This inventory is the same no matter from which ender chest you access it from. If you put one item into one ender chest, you will find it in all other ender chests. Each player will only see their own items, but not the items of other players."), _doc_items_usagehelp = S("Rightclick the ender chest to access your personal interdimensional inventory."), drawtype = "nodebox", node_box = { type = "fixed", - fixed = {-0.4375, -0.5, -0.4375, 0.4375, 0.375, 0.4375}, + fixed = { -0.4375, -0.5, -0.4375, 0.4375, 0.375, 0.4375 }, }, _chest_entity_textures = ender_chest_texture, _chest_entity_sound = "mcl_chests_enderchest", _chest_entity_mesh = "mcl_chests_chest", _chest_entity_animation_type = "chest", - tiles = {"blank.png^[resize:16x16"}, + tiles = { "blank.png^[resize:16x16" }, use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "clip" or true, -- Note: The “container” group is missing here because the ender chest does not -- have an inventory on its own - groups = {pickaxey=1, deco_block=1, material_stone=1, chest_entity=1, not_in_creative_inventory=1}, + groups = { pickaxey = 1, deco_block = 1, material_stone = 1, chest_entity = 1, not_in_creative_inventory = 1 }, is_ground_content = false, paramtype = "light", light_source = 7, @@ -1081,15 +1153,18 @@ minetest.register_node("mcl_chests:ender_chest_small", { sounds = mcl_sounds.node_sound_stone_defaults(), drop = "mcl_core:obsidian 8", on_construct = function(pos) - create_entity(pos, "mcl_chests:ender_chest_small", ender_chest_texture, minetest.get_node(pos).param2, false, "mcl_chests_enderchest", "mcl_chests_chest", "chest") + create_entity(pos, "mcl_chests:ender_chest_small", ender_chest_texture, minetest.get_node(pos).param2, false, + "mcl_chests_enderchest", "mcl_chests_chest", "chest") end, on_rightclick = function(pos, node, clicker) - if minetest.registered_nodes[minetest.get_node({x = pos.x, y = pos.y + 1, z = pos.z}).name].groups.opaque == 1 then - -- won't open if there is no space from the top - return false + if minetest.registered_nodes[minetest.get_node({ x = pos.x, y = pos.y + 1, z = pos.z }).name].groups.opaque == 1 then + -- won't open if there is no space from the top + return false end - minetest.show_formspec(clicker:get_player_name(), "mcl_chests:ender_chest_"..clicker:get_player_name(), formspec_ender_chest) - player_chest_open(clicker, pos, "mcl_chests:ender_chest_small", ender_chest_texture, node.param2, false, "mcl_chests_enderchest", "mcl_chests_chest") + minetest.show_formspec(clicker:get_player_name(), "mcl_chests:ender_chest_" .. clicker:get_player_name(), + formspec_ender_chest) + player_chest_open(clicker, pos, "mcl_chests:ender_chest_small", ender_chest_texture, node.param2, false, + "mcl_chests_enderchest", "mcl_chests_chest") end, on_receive_fields = function(pos, formname, fields, sender) if fields.quit then @@ -1098,21 +1173,21 @@ minetest.register_node("mcl_chests:ender_chest_small", { end, _mcl_blast_resistance = 3000, _mcl_hardness = 22.5, - _mcl_silk_touch_drop = {"mcl_chests:ender_chest"}, + _mcl_silk_touch_drop = { "mcl_chests:ender_chest" }, on_rotate = simple_rotate, }) minetest.register_on_joinplayer(function(player) local inv = player:get_inventory() - inv:set_size("enderchest", 9*3) + inv:set_size("enderchest", 9 * 3) end) minetest.register_allow_player_inventory_action(function(player, action, inv, info) if inv:get_location().type == "player" and ( - action == "move" and (info.from_list == "enderchest" or info.to_list == "enderchest") - or action == "put" and info.listname == "enderchest" - or action == "take" and info.listname == "enderchest" - ) then + action == "move" and (info.from_list == "enderchest" or info.to_list == "enderchest") + or action == "put" and info.listname == "enderchest" + or action == "take" and info.listname == "enderchest" + ) then local def = player:get_wielded_item():get_definition() local range = (def and def.range or player:get_inventory():get_stack("hand", 1):get_definition().range) + 1 if not minetest.find_node_near(player:get_pos(), range, "mcl_chests:ender_chest_small", true) then @@ -1124,9 +1199,9 @@ end) minetest.register_craft({ output = "mcl_chests:ender_chest", recipe = { - {"mcl_core:obsidian", "mcl_core:obsidian", "mcl_core:obsidian"}, - {"mcl_core:obsidian", "mcl_end:ender_eye", "mcl_core:obsidian"}, - {"mcl_core:obsidian", "mcl_core:obsidian", "mcl_core:obsidian"}, + { "mcl_core:obsidian", "mcl_core:obsidian", "mcl_core:obsidian" }, + { "mcl_core:obsidian", "mcl_end:ender_eye", "mcl_core:obsidian" }, + { "mcl_core:obsidian", "mcl_core:obsidian", "mcl_core:obsidian" }, }, }) @@ -1179,15 +1254,11 @@ local function formspec_shulker_box(name) return table.concat({ "formspec_version[4]", "size[11.75,10.425]", - mcl_formspec.apply_label_size, - - "label[0.375,0.375;"..F(C(mcl_formspec.label_color, name)).."]", + "label[0.375,0.375;" .. F(C(mcl_formspec.label_color, name)) .. "]", mcl_formspec.get_itemslot_bg_v4(0.375, 0.75, 9, 3), "list[context;main;0.375,0.75;9,3;]", - - "label[0.375,4.7;"..F(C(mcl_formspec.label_color, S("Inventory"))).."]", - + "label[0.375,4.7;" .. F(C(mcl_formspec.label_color, S("Inventory"))) .. "]", mcl_formspec.get_itemslot_bg_v4(0.375, 5.1, 9, 3), "list[current_player;main;0.375,5.1;9,3;9]", @@ -1212,28 +1283,38 @@ for color, desc in pairs(boxtypes) do local longdesc, usagehelp, create_entry, entry_name if mod_doc then if is_canonical then - longdesc = S("A shulker box is a portable container which provides 27 inventory slots for any item except shulker boxes. Shulker boxes keep their inventory when broken, so shulker boxes as well as their contents can be taken as a single item. Shulker boxes come in many different colors.") - usagehelp = S("To access the inventory of a shulker box, place and right-click it. To take a shulker box and its contents with you, just break and collect it, the items will not fall out. Place the shulker box again to be able to retrieve its contents.") + longdesc = S( + "A shulker box is a portable container which provides 27 inventory slots for any item except shulker boxes. Shulker boxes keep their inventory when broken, so shulker boxes as well as their contents can be taken as a single item. Shulker boxes come in many different colors.") + usagehelp = S( + "To access the inventory of a shulker box, place and right-click it. To take a shulker box and its contents with you, just break and collect it, the items will not fall out. Place the shulker box again to be able to retrieve its contents.") entry_name = S("Shulker Box") else create_entry = false end end - local small_name = "mcl_chests:"..color.."_shulker_box_small" + local small_name = "mcl_chests:" .. color .. "_shulker_box_small" - minetest.register_node("mcl_chests:"..color.."_shulker_box", { + minetest.register_node("mcl_chests:" .. color .. "_shulker_box", { description = desc, _tt_help = S("27 inventory slots") .. "\n" .. S("Can be carried around with its contents"), _doc_items_create_entry = create_entry, _doc_items_entry_name = entry_name, _doc_items_longdesc = longdesc, _doc_items_usagehelp = usagehelp, - tiles = {mob_texture}, + tiles = { mob_texture }, use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "opaque" or false, drawtype = "mesh", mesh = "mcl_chests_shulker.b3d", - groups = {handy=1,pickaxey=1, container=3, deco_block=1, dig_by_piston=1, shulker_box=1, old_shulker_box_node=1}, + groups = { + handy = 1, + pickaxey = 1, + container = 3, + deco_block = 1, + dig_by_piston = 1, + shulker_box = 1, + old_shulker_box_node = 1 + }, is_ground_content = false, sounds = mcl_sounds.node_sound_stone_defaults(), stack_max = 1, @@ -1251,7 +1332,7 @@ for color, desc in pairs(boxtypes) do local iinv_main = minetest.deserialize(imetadata) local ninv = nmeta:get_inventory() ninv:set_list("main", iinv_main) - ninv:set_size("main", 9*3) + ninv:set_size("main", 9 * 3) set_shulkerbox_meta(nmeta, itemstack:get_meta()) if minetest.is_creative_enabled(placer:get_player_name()) then @@ -1267,12 +1348,12 @@ for color, desc in pairs(boxtypes) do _on_dispense = function(stack, pos, droppos, dropnode, dropdir) -- Place shulker box as node if minetest.registered_nodes[dropnode.name].buildable_to then - minetest.set_node(droppos, {name = small_name, param2 = minetest.dir_to_facedir(dropdir)}) - local ninv = minetest.get_inventory({type="node", pos=droppos}) + minetest.set_node(droppos, { name = small_name, param2 = minetest.dir_to_facedir(dropdir) }) + local ninv = minetest.get_inventory({ type = "node", pos = droppos }) local imetadata = stack:get_metadata() local iinv_main = minetest.deserialize(imetadata) ninv:set_list("main", iinv_main) - ninv:set_size("main", 9*3) + ninv:set_size("main", 9 * 3) set_shulkerbox_meta(minetest.get_meta(droppos), stack:get_meta()) stack:take_item() end @@ -1290,15 +1371,24 @@ for color, desc in pairs(boxtypes) do drawtype = "nodebox", node_box = { type = "fixed", - fixed = {-0.48, -0.5, -0.48, 0.48, 0.489, 0.48}, + fixed = { -0.48, -0.5, -0.48, 0.48, 0.489, 0.48 }, }, - tiles = {"blank.png^[resize:16x16"}, + tiles = { "blank.png^[resize:16x16" }, use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "clip" or true, - _chest_entity_textures = {mob_texture}, + _chest_entity_textures = { mob_texture }, _chest_entity_sound = "mcl_chests_shulker", _chest_entity_mesh = "mcl_chests_shulker", _chest_entity_animation_type = "shulker", - groups = {handy=1,pickaxey=1, container=3, deco_block=1, dig_by_piston=1, shulker_box=1, chest_entity=1, not_in_creative_inventory=1}, + groups = { + handy = 1, + pickaxey = 1, + container = 3, + deco_block = 1, + dig_by_piston = 1, + shulker_box = 1, + chest_entity = 1, + not_in_creative_inventory = 1 + }, is_ground_content = false, sounds = mcl_sounds.node_sound_stone_defaults(), stack_max = 1, @@ -1312,8 +1402,9 @@ for color, desc in pairs(boxtypes) do local meta = minetest.get_meta(pos) meta:set_string("formspec", formspec_shulker_box(nil)) local inv = meta:get_inventory() - inv:set_size("main", 9*3) - create_entity(pos, small_name, {mob_texture}, minetest.get_node(pos).param2, false, "mcl_chests_shulker", "mcl_chests_shulker", "shulker") + inv:set_size("main", 9 * 3) + create_entity(pos, small_name, { mob_texture }, minetest.get_node(pos).param2, false, "mcl_chests_shulker", + "mcl_chests_shulker", "shulker") end, after_place_node = function(pos, placer, itemstack, pointed_thing) local nmeta = minetest.get_meta(pos) @@ -1321,7 +1412,7 @@ for color, desc in pairs(boxtypes) do local iinv_main = minetest.deserialize(imetadata) local ninv = nmeta:get_inventory() ninv:set_list("main", iinv_main) - ninv:set_size("main", 9*3) + ninv:set_size("main", 9 * 3) set_shulkerbox_meta(nmeta, itemstack:get_meta()) if minetest.is_creative_enabled(placer:get_player_name()) then @@ -1335,7 +1426,8 @@ for color, desc in pairs(boxtypes) do end end, on_rightclick = function(pos, node, clicker) - player_chest_open(clicker, pos, small_name, {mob_texture}, node.param2, false, "mcl_chests_shulker", "mcl_chests_shulker", true) + player_chest_open(clicker, pos, small_name, { mob_texture }, node.param2, false, "mcl_chests_shulker", + "mcl_chests_shulker", true) end, on_receive_fields = function(pos, formname, fields, sender) if fields.quit then @@ -1346,12 +1438,12 @@ for color, desc in pairs(boxtypes) do local meta = minetest.get_meta(pos) local inv = meta:get_inventory() local items = {} - for i=1, inv:get_size("main") do + for i = 1, inv:get_size("main") do local stack = inv:get_stack("main", i) items[i] = stack:to_string() end local data = minetest.serialize(items) - local boxitem = ItemStack("mcl_chests:"..color.."_shulker_box") + local boxitem = ItemStack("mcl_chests:" .. color .. "_shulker_box") local boxitem_meta = boxitem:get_meta() boxitem_meta:set_string("description", meta:get_string("description")) boxitem_meta:set_string("name", meta:get_string("name")) @@ -1386,23 +1478,25 @@ for color, desc in pairs(boxtypes) do }) if mod_doc and not is_canonical then - doc.add_entry_alias("nodes", "mcl_chests:"..canonical_shulker_color.."_shulker_box", "nodes", "mcl_chests:"..color.."_shulker_box") - doc.add_entry_alias("nodes", "mcl_chests:"..canonical_shulker_color.."_shulker_box_small", "nodes", "mcl_chests:"..color.."_shulker_box_small") + doc.add_entry_alias("nodes", "mcl_chests:" .. canonical_shulker_color .. "_shulker_box", "nodes", + "mcl_chests:" .. color .. "_shulker_box") + doc.add_entry_alias("nodes", "mcl_chests:" .. canonical_shulker_color .. "_shulker_box_small", "nodes", + "mcl_chests:" .. color .. "_shulker_box_small") end minetest.register_craft({ type = "shapeless", - output = "mcl_chests:"..color.."_shulker_box", - recipe = {"group:shulker_box", "mcl_dye:"..color}, + output = "mcl_chests:" .. color .. "_shulker_box", + recipe = { "group:shulker_box", "mcl_dye:" .. color }, }) end minetest.register_craft({ output = "mcl_chests:violet_shulker_box", recipe = { - {"mcl_mobitems:shulker_shell"}, - {"mcl_chests:chest"}, - {"mcl_mobitems:shulker_shell"}, + { "mcl_mobitems:shulker_shell" }, + { "mcl_chests:chest" }, + { "mcl_mobitems:shulker_shell" }, }, }) @@ -1431,13 +1525,14 @@ local function select_and_spawn_entity(pos, node) local node_name = node.name local node_def = minetest.registered_nodes[node_name] local double_chest = minetest.get_item_group(node_name, "double_chest") > 0 - find_or_create_entity(pos, node_name, node_def._chest_entity_textures, node.param2, double_chest, node_def._chest_entity_sound, node_def._chest_entity_mesh, node_def._chest_entity_animation_type) + find_or_create_entity(pos, node_name, node_def._chest_entity_textures, node.param2, double_chest, + node_def._chest_entity_sound, node_def._chest_entity_mesh, node_def._chest_entity_animation_type) end minetest.register_lbm({ label = "Spawn Chest entities", name = "mcl_chests:spawn_chest_entities", - nodenames = {"group:chest_entity"}, + nodenames = { "group:chest_entity" }, run_at_every_load = true, action = select_and_spawn_entity, }) @@ -1445,7 +1540,9 @@ minetest.register_lbm({ minetest.register_lbm({ label = "Replace old chest nodes", name = "mcl_chests:replace_old", - nodenames = {"mcl_chests:chest", "mcl_chests:trapped_chest", "mcl_chests:trapped_chest_on", "mcl_chests:ender_chest", "group:old_shulker_box_node"}, + nodenames = { "mcl_chests:chest", "mcl_chests:trapped_chest", "mcl_chests:trapped_chest_on", + "mcl_chests:ender_chest", + "group:old_shulker_box_node" }, run_at_every_load = true, action = function(pos, node) local node_name = node.name @@ -1453,7 +1550,7 @@ minetest.register_lbm({ minetest.swap_node(pos, node) select_and_spawn_entity(pos, node) if node_name == "mcl_chests:trapped_chest_on" then - minetest.log("action", "[mcl_chests] Disabled active trapped chest on load: " ..minetest.pos_to_string(pos)) + minetest.log("action", "[mcl_chests] Disabled active trapped chest on load: " .. minetest.pos_to_string(pos)) chest_update_after_close(pos) elseif node_name == "mcl_chests:ender_chest" then local meta = minetest.get_meta(pos) @@ -1468,10 +1565,11 @@ minetest.register_lbm({ -- Fixes redstone weirdness. label = "Disable active trapped chests", name = "mcl_chests:reset_trapped_chests", - nodenames = { "mcl_chests:trapped_chest_on_small", "mcl_chests:trapped_chest_on_left", "mcl_chests:trapped_chest_on_right" }, + nodenames = { "mcl_chests:trapped_chest_on_small", "mcl_chests:trapped_chest_on_left", + "mcl_chests:trapped_chest_on_right" }, run_at_every_load = true, action = function(pos, node) - minetest.log("action", "[mcl_chests] Disabled active trapped chest on load: " ..minetest.pos_to_string(pos)) + minetest.log("action", "[mcl_chests] Disabled active trapped chest on load: " .. minetest.pos_to_string(pos)) chest_update_after_close(pos) end, }) @@ -1490,7 +1588,7 @@ minetest.register_lbm({ minetest.register_lbm({ label = "Upgrade old ender chest formspec", name = "mcl_chests:replace_old_ender_form", - nodenames = {"mcl_chests:ender_chest_small"}, + nodenames = { "mcl_chests:ender_chest_small" }, run_at_every_load = false, action = function(pos, node) minetest.get_meta(pos):set_string("formspec", "") diff --git a/settingtypes.txt b/settingtypes.txt index 1f1e31dbb..c5d5d32c1 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -192,11 +192,6 @@ animated_chests (Animated chests) bool true # The maximum number of boss bars to simultaniously display on the screen max_bossbars (Maximum Boss bars) int 5 -# Define how wide font will be displayed in mineclone2 formspecs -# This allow MineClone2 to have a label size similar to minecraft, but allowing at least singleplayer to use his own font with custom size -# (some fonts may be bigger than the default one and break formspecs) -mcl_label_font_size (Label Font Size) int 24 - # Default intensity of shadows (default: 0.33) mcl_default_shadow_intensity (Default shadow intensity) float 0.33 0.0 1.0 From fb794650526c09f65a2a74bdf4123d31699a60ef Mon Sep 17 00:00:00 2001 From: AFCMS Date: Fri, 9 Sep 2022 20:46:04 +0200 Subject: [PATCH 27/82] Fixes --- mods/HUD/mcl_inventory/init.lua | 300 ++++++++++++++++++++++++++++++++ 1 file changed, 300 insertions(+) diff --git a/mods/HUD/mcl_inventory/init.lua b/mods/HUD/mcl_inventory/init.lua index a46f2669f..b9b952e97 100644 --- a/mods/HUD/mcl_inventory/init.lua +++ b/mods/HUD/mcl_inventory/init.lua @@ -292,3 +292,303 @@ minetest.register_chatcommand("gamemode", { return true, S("Gamemode for player ") .. n .. S(": " .. gm) end }) +local S = minetest.get_translator(minetest.get_current_modname()) +local F = minetest.formspec_escape + +---get_inventory can return nil if object isn't a player, but we are sure sometimes this is one :) +---@diagnostic disable need-check-nil + +mcl_inventory = {} + +--local mod_player = minetest.get_modpath("mcl_player") +--local mod_craftguide = minetest.get_modpath("mcl_craftguide") + +---Returns a single itemstack in the given inventory to the main inventory, or drop it when there's no space left. +---@param itemstack ItemStack +---@param dropper ObjectRef +---@param pos Vector +---@param inv InvRef +local function return_item(itemstack, dropper, pos, inv) + if dropper:is_player() then + -- Return to main inventory + if inv:room_for_item("main", itemstack) then + inv:add_item("main", itemstack) + else + -- Drop item on the ground + local v = dropper:get_look_dir() + local p = vector.offset(pos, 0, 1.2, 0) + p.x = p.x + (math.random(1, 3) * 0.2) + p.z = p.z + (math.random(1, 3) * 0.2) + local obj = minetest.add_item(p, itemstack) + if obj then + v.x = v.x * 4 + v.y = v.y * 4 + 2 + v.z = v.z * 4 + obj:set_velocity(v) + obj:get_luaentity()._insta_collect = false + end + end + else + -- Fallback for unexpected cases + minetest.add_item(pos, itemstack) + end + return itemstack +end + +---Return items in the given inventory list (name) to the main inventory, or drop them if there is no space left. +---@param player ObjectRef +---@param name string +local function return_fields(player, name) + local inv = player:get_inventory() + + local list = inv:get_list(name) + if not list then return end + for i, stack in ipairs(list) do + return_item(stack, player, player:get_pos(), inv) + stack:clear() + inv:set_stack(name, i, stack) + end +end + +---@param player ObjectRef +---@param armor_change_only? boolean +local function set_inventory(player, armor_change_only) + if minetest.is_creative_enabled(player:get_player_name()) then + if armor_change_only then + -- Stay on survival inventory plage if only the armor has been changed + mcl_inventory.set_creative_formspec(player, 0, 0, nil, nil, "inv") + else + mcl_inventory.set_creative_formspec(player, 0, 1) + end + return + end + + local inv = player:get_inventory() + + inv:set_width("craft", 2) + inv:set_size("craft", 4) + + local armor_slots = { "helmet", "chestplate", "leggings", "boots" } + local armor_slot_imgs = "" + + for a = 1, 4 do + if inv:get_stack("armor", a + 1):is_empty() then + armor_slot_imgs = armor_slot_imgs .. + "image[0.375," .. (0.375 + (a - 1) * 1.25) .. ";1,1;mcl_inventory_empty_armor_slot_" .. armor_slots[a] .. ".png]" + end + end + + if inv:get_stack("offhand", 1):is_empty() then + armor_slot_imgs = armor_slot_imgs .. "image[5.375,4.125;1,1;mcl_inventory_empty_armor_slot_shield.png]" + end + + local form = table.concat({ + "formspec_version[6]", + "size[11.75,10.9]", + + --Armor slots + mcl_formspec.get_itemslot_bg_v4(0.375, 0.375, 1, 4), + "list[current_player;armor;0.375,0.375;1,1;1]", + "list[current_player;armor;0.375,1.625;1,1;2]", + "list[current_player;armor;0.375,2.875;1,1;3]", + "list[current_player;armor;0.375,4.125;1,1;4]", + + --Main inventory + mcl_formspec.get_itemslot_bg_v4(0.375, 5.575, 9, 3), + "list[current_player;main;0.375,5.575;9,3;9]", + + --Hotbar + mcl_formspec.get_itemslot_bg_v4(0.375, 9.525, 9, 1), + "list[current_player;main;0.375,9.525;9,1;]", + + --Player model + "image[1.57,0.343;3.62,4.85;mcl_inventory_background9.png;2]", + mcl_player.get_player_formspec_model(player, 1.57, 0.4, 3.62, 4.85, ""), + + --Offhand + mcl_formspec.get_itemslot_bg_v4(5.375, 4.125, 1, 1), + "list[current_player;offhand;5.375,4.125;1,1]", + + armor_slot_imgs, + + --Craft grid + "label[6.61,0.5;" .. F(minetest.colorize(mcl_formspec.label_color, S("Crafting"))) .. "]", + + mcl_formspec.get_itemslot_bg_v4(6.625, 0.875, 2, 2), + "list[current_player;craft;6.625,0.875;2,2]", + + "image[9.125,1.5;1,1;crafting_formspec_arrow.png]", + + mcl_formspec.get_itemslot_bg_v4(10.375, 1.5, 1, 1), + "list[current_player;craftpreview;10.375,1.5;1,1;]", + + --Crafting guide button + "image_button[6.575,4.075;1.1,1.1;craftguide_book.png;__mcl_craftguide;]", + "tooltip[__mcl_craftguide;" .. F(S("Recipe book")) .. "]", + + --Help button + "image_button[7.825,4.075;1.1,1.1;doc_button_icon_lores.png;__mcl_doc;]", + "tooltip[__mcl_doc;" .. F(S("Help")) .. "]", + + --Skins button + "image_button[9.075,4.075;1.1,1.1;mcl_skins_button.png;__mcl_skins;]", + "tooltip[__mcl_skins;" .. F(S("Select player skin")) .. "]", + + --Achievements button + "image_button[10.325,4.075;1.1,1.1;mcl_achievements_button.png;__mcl_achievements;]", + "tooltip[__mcl_achievements;" .. F(S("Achievements")) .. "]", + + --Listring + "listring[current_player;main]", + "listring[current_player;armor]", + "listring[current_player;main]", + "listring[current_player;craft]", + "listring[current_player;main]", + }) + + player:set_inventory_formspec(form) +end + +-- Drop items in craft grid and reset inventory on closing +minetest.register_on_player_receive_fields(function(player, formname, fields) + if fields.quit then + return_fields(player, "craft") + return_fields(player, "enchanting_lapis") + return_fields(player, "enchanting_item") + if not minetest.is_creative_enabled(player:get_player_name()) and (formname == "" or formname == "main") then + set_inventory(player) + end + end +end) + +if not minetest.is_creative_enabled("") then + function mcl_inventory.update_inventory_formspec(player) + set_inventory(player) + end +end + +-- Drop crafting grid items on leaving +minetest.register_on_leaveplayer(function(player) + return_fields(player, "craft") + return_fields(player, "enchanting_lapis") + return_fields(player, "enchanting_item") +end) + +minetest.register_on_joinplayer(function(player) + --init inventory + local inv = player:get_inventory() + + inv:set_width("main", 9) + inv:set_size("main", 36) + inv:set_size("offhand", 1) + + --set hotbar size + player:hud_set_hotbar_itemcount(9) + --add hotbar images + player:hud_set_hotbar_image("mcl_inventory_hotbar.png") + player:hud_set_hotbar_selected_image("mcl_inventory_hotbar_selected.png") + + local old_update_player = mcl_armor.update_player + function mcl_armor.update_player(player, info) + old_update_player(player, info) + set_inventory(player, true) + end + + -- In Creative Mode, the initial inventory setup is handled in creative.lua + if not minetest.is_creative_enabled(player:get_player_name()) then + set_inventory(player) + end + + --[[ Make sure the crafting grid is empty. Why? Because the player might have + items remaining in the crafting grid from the previous join; this is likely + when the server has been shutdown and the server didn't clean up the player + inventories. ]] + return_fields(player, "craft") + return_fields(player, "enchanting_item") + return_fields(player, "enchanting_lapis") +end) + + +dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/creative.lua") + +local mt_is_creative_enabled = minetest.is_creative_enabled + +function minetest.is_creative_enabled(name) + if mt_is_creative_enabled(name) then return true end + if not name then return false end + local p = minetest.get_player_by_name(name) + if p then + return p:get_meta():get_string("gamemode") == "creative" + end + return false +end + +--Insta "digging" nodes in gamemode-creative +minetest.register_on_punchnode(function(pos, node, puncher, pointed_thing) + if not puncher or not puncher:is_player() then return end + if minetest.is_creative_enabled() then return end + local name = puncher:get_player_name() + if not minetest.is_creative_enabled(name) then return end + if pointed_thing.type ~= "node" then return end + local def = minetest.registered_nodes[node.name] + if def then + if def.on_destruct then def.on_destruct(pos) end + minetest.remove_node(pos) + return true + end +end) + +--Don't subtract from inv when placing in gamemode-creative +minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack, pointed_thing) + if placer and placer:is_player() and minetest.is_creative_enabled(placer:get_player_name()) then return true end +end) + +local function in_table(n, h) + for k, v in pairs(h) do + if v == n then return true end + end + return false +end + +local gamemodes = { + "survival", + "creative" +} + +function mcl_inventory.player_set_gamemode(p, g) + local m = p:get_meta() + m:set_string("gamemode", g) + if g == "survival" then + mcl_experience.setup_hud(p) + mcl_experience.update(p) + elseif g == "creative" then + mcl_experience.remove_hud(p) + end + set_inventory(p) +end + +minetest.register_chatcommand("gamemode", { + params = S("[] []"), + description = S("Change gamemode (survival/creative) for yourself or player"), + privs = { server = true }, + func = function(n, param) + -- Full input validation ( just for @erlehmann <3 ) + local p = minetest.get_player_by_name(n) + local args = param:split(" ") + if args[2] ~= nil then + p = minetest.get_player_by_name(args[2]) + end + if not p then + return false, S("Player not online") + end + if args[1] ~= nil and not in_table(args[1], gamemodes) then + return false, S("Gamemode " .. args[1] .. " does not exist.") + elseif args[1] ~= nil then + mcl_inventory.player_set_gamemode(p, args[1]) + end + --Result message - show effective game mode + local gm = p:get_meta():get_string("gamemode") + if gm == "" then gm = gamemodes[1] end + return true, S("Gamemode for player ") .. n .. S(": " .. gm) + end +}) From fbb51835b382d8869b8e77c4be6844f46e51bfaa Mon Sep 17 00:00:00 2001 From: AFCMS Date: Sat, 10 Sep 2022 01:06:10 +0200 Subject: [PATCH 28/82] survival inventory tabs API + mcl_gamemode --- mods/HUD/mcl_experience/init.lua | 33 ++-- mods/HUD/mcl_experience/mod.conf | 1 + mods/HUD/mcl_inventory/API.md | 0 mods/HUD/mcl_inventory/creative.lua | 259 ++++++++++++++++++---------- mods/HUD/mcl_inventory/init.lua | 180 ++----------------- mods/HUD/mcl_inventory/mod.conf | 5 + mods/HUD/mcl_inventory/survival.lua | 219 +++++++++++++++++++++++ mods/PLAYER/mcl_gamemode/init.lua | 106 ++++++++++++ mods/PLAYER/mcl_gamemode/mod.conf | 1 + 9 files changed, 539 insertions(+), 265 deletions(-) create mode 100644 mods/HUD/mcl_inventory/API.md create mode 100644 mods/HUD/mcl_inventory/survival.lua create mode 100644 mods/PLAYER/mcl_gamemode/init.lua create mode 100644 mods/PLAYER/mcl_gamemode/mod.conf diff --git a/mods/HUD/mcl_experience/init.lua b/mods/HUD/mcl_experience/init.lua index 359e68918..47e48d36c 100644 --- a/mods/HUD/mcl_experience/init.lua +++ b/mods/HUD/mcl_experience/init.lua @@ -147,13 +147,13 @@ function mcl_experience.throw_xp(pos, total_xp) obj:set_velocity(vector.new( math.random(-2, 2) * math.random(), - math.random( 2, 5), + math.random(2, 5), math.random(-2, 2) * math.random() )) i = i + xp j = j + 1 - table.insert(obs,obj) + table.insert(obs, obj) end return obs end @@ -179,18 +179,18 @@ function mcl_experience.setup_hud(player) if not minetest.is_creative_enabled(player:get_player_name()) then hud_bars[player] = player:hud_add({ hud_elem_type = "image", - position = {x = 0.5, y = 1}, - offset = {x = (-9 * 28) - 3, y = -(48 + 24 + 16 - 5)}, - scale = {x = 0.35, y = 0.375}, - alignment = {x = 1, y = 1}, + position = { x = 0.5, y = 1 }, + offset = { x = (-9 * 28) - 3, y = -(48 + 24 + 16 - 5) }, + scale = { x = 0.35, y = 0.375 }, + alignment = { x = 1, y = 1 }, z_index = 11, }) hud_levels[player] = player:hud_add({ hud_elem_type = "text", - position = {x = 0.5, y = 1}, + position = { x = 0.5, y = 1 }, number = 0x80FF20, - offset = {x = 0, y = -(48 + 24 + 24)}, + offset = { x = 0, y = -(48 + 24 + 24) }, z_index = 12, }) end @@ -221,7 +221,7 @@ function mcl_experience.update(player) end function mcl_experience.register_on_add_xp(func, priority) - table.insert(mcl_experience.on_add_xp, {func = func, priority = priority or 0}) + table.insert(mcl_experience.on_add_xp, { func = func, priority = priority or 0 }) end -- callbacks @@ -232,9 +232,9 @@ minetest.register_on_joinplayer(function(player) end) minetest.register_on_leaveplayer(function(player) - hud_bars[player] = nil - hud_levels[player] = nil - caches[player] = nil + hud_bars[player] = nil + hud_levels[player] = nil + caches[player] = nil end) minetest.register_on_dieplayer(function(player) @@ -247,3 +247,12 @@ end) minetest.register_on_mods_loaded(function() table.sort(mcl_experience.on_add_xp, function(a, b) return a.priority < b.priority end) end) + +mcl_gamemode.register_on_gamemode_change(function(player, old_gamemode, new_gamemode) + if new_gamemode == "survival" then + mcl_experience.setup_hud(player) + mcl_experience.update(player) + elseif new_gamemode == "creative" then + mcl_experience.remove_hud(player) + end +end) diff --git a/mods/HUD/mcl_experience/mod.conf b/mods/HUD/mcl_experience/mod.conf index 211249b30..a8e992c06 100644 --- a/mods/HUD/mcl_experience/mod.conf +++ b/mods/HUD/mcl_experience/mod.conf @@ -1,3 +1,4 @@ name = mcl_experience author = oilboi description = eXPerience mod +depends = mcl_gamemode diff --git a/mods/HUD/mcl_inventory/API.md b/mods/HUD/mcl_inventory/API.md new file mode 100644 index 000000000..e69de29bb diff --git a/mods/HUD/mcl_inventory/creative.lua b/mods/HUD/mcl_inventory/creative.lua index 32bb226f0..c18b559b1 100644 --- a/mods/HUD/mcl_inventory/creative.lua +++ b/mods/HUD/mcl_inventory/creative.lua @@ -11,7 +11,8 @@ local inventory_lists = {} --local mod_player = minetest.get_modpath("mcl_player") -- Create tables -local builtin_filter_ids = {"blocks","deco","redstone","rail","food","tools","combat","mobs","brew","matr","misc","all"} +local builtin_filter_ids = { "blocks", "deco", "redstone", "rail", "food", "tools", "combat", "mobs", "brew", "matr", + "misc", "all" } for _, f in pairs(builtin_filter_ids) do inventory_lists[f] = {} end @@ -31,17 +32,26 @@ end --[[ Populate all the item tables. We only do this once. Note this code must be executed after loading all the other mods in order to work. ]] minetest.register_on_mods_loaded(function() - for name,def in pairs(minetest.registered_items) do - if (not def.groups.not_in_creative_inventory or def.groups.not_in_creative_inventory == 0) and def.description and def.description ~= "" then + for name, def in pairs(minetest.registered_items) do + if (not def.groups.not_in_creative_inventory or def.groups.not_in_creative_inventory == 0) and def.description and + def.description ~= "" then local function is_redstone(def) - return def.mesecons or def.groups.mesecon or def.groups.mesecon_conductor_craftable or def.groups.mesecon_effecor_off + return def.mesecons or def.groups.mesecon or def.groups.mesecon_conductor_craftable or + def.groups.mesecon_effecor_off end + local function is_tool(def) return def.groups.tool or (def.tool_capabilities and def.tool_capabilities.damage_groups == nil) end + local function is_weapon_or_armor(def) - return def.groups.weapon or def.groups.weapon_ranged or def.groups.ammo or def.groups.combat_item or ((def.groups.armor_head or def.groups.armor_torso or def.groups.armor_legs or def.groups.armor_feet or def.groups.horse_armor) and def.groups.non_combat_armor ~= 1) + return def.groups.weapon or def.groups.weapon_ranged or def.groups.ammo or def.groups.combat_item or + ( + ( + def.groups.armor_head or def.groups.armor_torso or def.groups.armor_legs or def.groups.armor_feet or + def.groups.horse_armor) and def.groups.non_combat_armor ~= 1) end + -- Is set to true if it was added in any category besides misc local nonmisc = false if def.groups.building_block then @@ -122,11 +132,12 @@ end local function set_inv_search(filter, player) local playername = player:get_player_name() - local inv = minetest.get_inventory({type="detached", name="creative_"..playername}) + local inv = minetest.get_inventory({ type = "detached", name = "creative_" .. playername }) local creative_list = {} local lang = minetest.get_player_information(playername).lang_code - for name,def in pairs(minetest.registered_items) do - if (not def.groups.not_in_creative_inventory or def.groups.not_in_creative_inventory == 0) and def.description and def.description ~= "" then + for name, def in pairs(minetest.registered_items) do + if (not def.groups.not_in_creative_inventory or def.groups.not_in_creative_inventory == 0) and def.description and + def.description ~= "" then if filter_item(string.lower(def.name), def.description, lang, filter) then table.insert(creative_list, name) end @@ -149,7 +160,7 @@ end local function set_inv_page(page, player) local playername = player:get_player_name() - local inv = minetest.get_inventory({type="detached", name="creative_"..playername}) + local inv = minetest.get_inventory({ type = "detached", name = "creative_" .. playername }) inv:set_size("main", 0) local creative_list = {} if inventory_lists[page] then -- Standard filter @@ -162,7 +173,7 @@ end local function init(player) local playername = player:get_player_name() - minetest.create_detached_inventory("creative_"..playername, { + minetest.create_detached_inventory("creative_" .. playername, { allow_move = function(inv, from_list, from_index, to_list, to_index, count, player) if minetest.is_creative_enabled(playername) then return count @@ -200,7 +211,7 @@ local trash = minetest.create_detached_inventory("trash", { trash:set_size("main", 1) local noffset = {} -- numeric tab offset -local offset = {} -- string offset: +local offset = {} -- string offset: local boffset = {} -- local hoch = {} local filtername = {} @@ -238,9 +249,9 @@ next_noffset("mobs") next_noffset("matr") next_noffset("inv", true) -for k,v in pairs(noffset) do +for k, v in pairs(noffset) do offset[k] = tostring(v[1]) .. "," .. tostring(v[2]) - boffset[k] = tostring(v[1]+0.19) .. "," .. tostring(v[2]+0.25) + boffset[k] = tostring(v[1] + 0.19) .. "," .. tostring(v[2] + 0.25) end hoch["blocks"] = "" @@ -299,7 +310,7 @@ local function set_stack_size(player, n) player:get_meta():set_int("mcl_inventory:switch_stack", n) end -minetest.register_on_joinplayer(function (player) +minetest.register_on_joinplayer(function(player) if get_stack_size(player) == 0 then set_stack_size(player, 64) end @@ -310,14 +321,26 @@ function mcl_inventory.set_creative_formspec(player) if not players[playername] then return end local start_i = players[playername].start_i - local pagenum = start_i / (9*5) + 1 + local pagenum = start_i / (9 * 5) + 1 local name = players[playername].page local inv_size = players[playername].inv_size local filter = players[playername].filter - local pagemax = math.max(1, math.floor((inv_size-1) / (9*5) + 1)) + + if not inv_size then + if page == "nix" then + local inv = minetest.get_inventory({ type = "detached", name = "creative_" .. playername }) + inv_size = inv:get_size("main") + elseif page and page ~= "inv" then + inv_size = #(inventory_lists[page]) + else + inv_size = 0 + end + end + local pagemax = math.max(1, math.floor((inv_size - 1) / (9 * 5) + 1)) + local name = "nix" local main_list - local listrings = "listring[detached:creative_"..playername..";main]".. - "listring[current_player;main]".. + local listrings = "listring[detached:creative_" .. playername .. ";main]" .. + "listring[current_player;main]" .. "listring[detached:trash;main]" local inv_bg = "crafting_inventory_creative.png" @@ -349,7 +372,7 @@ function mcl_inventory.set_creative_formspec(player) -- Survival inventory slots main_list = "list[current_player;main;0,3.75;9,3;9]" .. mcl_formspec.get_itemslot_bg(0, 3.75, 9, 3) .. - + -- Armor "list[current_player;armor;2.5,1.3;1,1;1]" .. "list[current_player;armor;2.5,2.75;1,1;2]" .. @@ -362,46 +385,46 @@ function mcl_inventory.set_creative_formspec(player) "list[current_player;offhand;1.5,2.025;1,1]" .. mcl_formspec.get_itemslot_bg(1.5, 2.025, 1, 1) .. armor_slot_imgs .. - + -- Player preview mcl_player.get_player_formspec_model(player, 3.9, 1.4, 1.2333, 2.4666, "") .. - + -- Crafting guide button "image_button[9,1;1,1;craftguide_book.png;__mcl_craftguide;]" .. - "tooltip[__mcl_craftguide;"..F(S("Recipe book")) .. "]" .. - + "tooltip[__mcl_craftguide;" .. F(S("Recipe book")) .. "]" .. + -- Help button "image_button[9,2;1,1;doc_button_icon_lores.png;__mcl_doc;]" .. "tooltip[__mcl_doc;" .. F(S("Help")) .. "]" .. - - -- Achievements button + + -- Advancements button "image_button[9,3;1,1;mcl_achievements_button.png;__mcl_achievements;]" .. --"style_type[image_button;border=;bgimg=;bgimg_pressed=]" .. - "tooltip[__mcl_achievements;"..F(S("Advancements")) .. "]" .. - + "tooltip[__mcl_achievements;" .. F(S("Advancements")) .. "]" .. + -- Switch stack size button "image_button[9,4;1,1;default_apple.png;__switch_stack;]" .. "label[9.4,4.4;" .. F(C("#FFFFFF", stack_size ~= 1 and stack_size or "")) .. "]" .. "tooltip[__switch_stack;" .. F(S("Switch stack size")) .. "]" - + -- Skins button if minetest.global_exists("mcl_skins") then main_list = main_list .. "image_button[9,5;1,1;mcl_skins_button.png;__mcl_skins;]" .. - "tooltip[__mcl_skins;"..F(S("Select player skin")) .. "]" + "tooltip[__mcl_skins;" .. F(S("Select player skin")) .. "]" end -- For shortcuts listrings = listrings .. - "listring[detached:"..playername.."_armor;armor]".. + "listring[detached:" .. playername .. "_armor;armor]" .. "listring[current_player;main]" else -- Creative inventory slots - main_list = "list[detached:creative_"..playername..";main;0,1.75;9,5;"..tostring(start_i).."]".. - mcl_formspec.get_itemslot_bg(0,1.75,9,5).. - -- Page buttons - "label[9.0,5.5;"..F(S("@1/@2", pagenum, pagemax)).."]".. - "image_button[9.0,6.0;0.7,0.7;crafting_creative_prev.png;creative_prev;]".. + main_list = "list[detached:creative_" .. playername .. ";main;0,1.75;9,5;" .. tostring(start_i) .. "]" .. + mcl_formspec.get_itemslot_bg(0, 1.75, 9, 5) .. + -- Page buttons + "label[9.0,5.5;" .. F(S("@1/@2", pagenum, pagemax)) .. "]" .. + "image_button[9.0,6.0;0.7,0.7;crafting_creative_prev.png;creative_prev;]" .. "image_button[9.5,6.0;0.7,0.7;crafting_creative_next.png;creative_next;]" end @@ -423,65 +446,65 @@ function mcl_inventory.set_creative_formspec(player) local function tab(current_tab, this_tab) local bg_img if current_tab == this_tab then - bg_img = "crafting_creative_active"..hoch[this_tab]..".png" + bg_img = "crafting_creative_active" .. hoch[this_tab] .. ".png" else - bg_img = "crafting_creative_inactive"..hoch[this_tab]..".png" + bg_img = "crafting_creative_inactive" .. hoch[this_tab] .. ".png" end - return - "style["..this_tab..";border=false;bgimg=;bgimg_pressed=]".. - "item_image_button[" .. boffset[this_tab] ..";1,1;"..tab_icon[this_tab]..";"..this_tab..";]".. + return "style[" .. this_tab .. ";border=false;bgimg=;bgimg_pressed=]" .. + "item_image_button[" .. boffset[this_tab] .. ";1,1;" .. tab_icon[this_tab] .. ";" .. this_tab .. ";]" .. "image[" .. offset[this_tab] .. ";1.5,1.44;" .. bg_img .. "]" end + local caption = "" if name ~= "inv" and filtername[name] then - caption = "label[0,1.2;"..F(minetest.colorize("#313131", filtername[name])).."]" + caption = "label[0,1.2;" .. F(minetest.colorize("#313131", filtername[name])) .. "]" end - local formspec = "size[10,9.3]".. - "no_prepend[]".. - mcl_vars.gui_nonbg..mcl_vars.gui_bg_color.. - "background[-0.19,-0.25;10.5,9.87;"..inv_bg.."]".. - "label[-5,-5;"..name.."]".. + local formspec = "size[10,9.3]" .. + "no_prepend[]" .. + mcl_vars.gui_nonbg .. mcl_vars.gui_bg_color .. + "background[-0.19,-0.25;10.5,9.87;" .. inv_bg .. "]" .. + "label[-5,-5;" .. name .. "]" .. tab(name, "blocks") .. - "tooltip[blocks;"..F(filtername["blocks"]).."]".. + "tooltip[blocks;" .. F(filtername["blocks"]) .. "]" .. tab(name, "deco") .. - "tooltip[deco;"..F(filtername["deco"]).."]".. + "tooltip[deco;" .. F(filtername["deco"]) .. "]" .. tab(name, "redstone") .. - "tooltip[redstone;"..F(filtername["redstone"]).."]".. + "tooltip[redstone;" .. F(filtername["redstone"]) .. "]" .. tab(name, "rail") .. - "tooltip[rail;"..F(filtername["rail"]).."]".. + "tooltip[rail;" .. F(filtername["rail"]) .. "]" .. tab(name, "misc") .. - "tooltip[misc;"..F(filtername["misc"]).."]".. + "tooltip[misc;" .. F(filtername["misc"]) .. "]" .. tab(name, "nix") .. - "tooltip[nix;"..F(filtername["nix"]).."]".. - caption.. - "list[current_player;main;0,7;9,1;]".. - mcl_formspec.get_itemslot_bg(0,7,9,1).. - main_list.. + "tooltip[nix;" .. F(filtername["nix"]) .. "]" .. + caption .. + "list[current_player;main;0,7;9,1;]" .. + mcl_formspec.get_itemslot_bg(0, 7, 9, 1) .. + main_list .. tab(name, "food") .. - "tooltip[food;"..F(filtername["food"]).."]".. + "tooltip[food;" .. F(filtername["food"]) .. "]" .. tab(name, "tools") .. - "tooltip[tools;"..F(filtername["tools"]).."]".. + "tooltip[tools;" .. F(filtername["tools"]) .. "]" .. tab(name, "combat") .. - "tooltip[combat;"..F(filtername["combat"]).."]".. + "tooltip[combat;" .. F(filtername["combat"]) .. "]" .. tab(name, "mobs") .. - "tooltip[mobs;"..F(filtername["mobs"]).."]".. + "tooltip[mobs;" .. F(filtername["mobs"]) .. "]" .. tab(name, "brew") .. - "tooltip[brew;"..F(filtername["brew"]).."]".. + "tooltip[brew;" .. F(filtername["brew"]) .. "]" .. tab(name, "matr") .. - "tooltip[matr;"..F(filtername["matr"]).."]".. + "tooltip[matr;" .. F(filtername["matr"]) .. "]" .. tab(name, "inv") .. - "tooltip[inv;"..F(filtername["inv"]).."]".. - "list[detached:trash;main;9,7;1,1;]".. - mcl_formspec.get_itemslot_bg(9,7,1,1).. - "image[9,7;1,1;crafting_creative_trash.png]".. + "tooltip[inv;" .. F(filtername["inv"]) .. "]" .. + "list[detached:trash;main;9,7;1,1;]" .. + mcl_formspec.get_itemslot_bg(9, 7, 1, 1) .. + "image[9,7;1,1;crafting_creative_trash.png]" .. listrings if name == "nix" then - formspec = formspec .. "field[5.3,1.34;4,0.75;search;;"..minetest.formspec_escape(filter).."]" + formspec = formspec .. "field[5.3,1.34;4,0.75;search;;" .. minetest.formspec_escape(filter) .. "]" formspec = formspec .. "field_close_on_enter[search;false]" end - if pagenum then formspec = formspec .. "p"..tostring(pagenum) end + if pagenum then formspec = formspec .. "p" .. tostring(pagenum) end player:set_inventory_formspec(formspec) end @@ -500,50 +523,50 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) if fields.blocks then if players[name].page == "blocks" then return end - set_inv_page("blocks",player) + set_inv_page("blocks", player) page = "blocks" elseif fields.deco then if players[name].page == "deco" then return end - set_inv_page("deco",player) + set_inv_page("deco", player) page = "deco" elseif fields.redstone then if players[name].page == "redstone" then return end - set_inv_page("redstone",player) + set_inv_page("redstone", player) page = "redstone" elseif fields.rail then if players[name].page == "rail" then return end - set_inv_page("rail",player) + set_inv_page("rail", player) page = "rail" elseif fields.misc then if players[name].page == "misc" then return end - set_inv_page("misc",player) + set_inv_page("misc", player) page = "misc" elseif fields.nix then - set_inv_page("all",player) + set_inv_page("all", player) page = "nix" elseif fields.food then if players[name].page == "food" then return end - set_inv_page("food",player) + set_inv_page("food", player) page = "food" elseif fields.tools then if players[name].page == "tools" then return end - set_inv_page("tools",player) + set_inv_page("tools", player) page = "tools" elseif fields.combat then if players[name].page == "combat" then return end - set_inv_page("combat",player) + set_inv_page("combat", player) page = "combat" elseif fields.mobs then if players[name].page == "mobs" then return end - set_inv_page("mobs",player) + set_inv_page("mobs", player) page = "mobs" elseif fields.brew then if players[name].page == "brew" then return end - set_inv_page("brew",player) + set_inv_page("brew", player) page = "brew" elseif fields.matr then if players[name].page == "matr" then return end - set_inv_page("matr",player) + set_inv_page("matr", player) page = "matr" elseif fields.inv then if players[name].page == "inv" then return end @@ -552,7 +575,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) set_inv_page("all", player) page = "nix" elseif fields.search and not fields.creative_next and not fields.creative_prev then - set_inv_search(string.lower(fields.search),player) + set_inv_search(string.lower(fields.search), player) page = "nix" elseif fields.__switch_stack then local switch = 1 @@ -570,20 +593,20 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) local start_i = players[name].start_i if fields.creative_prev then - start_i = start_i - 9*5 + start_i = start_i - 9 * 5 elseif fields.creative_next then - start_i = start_i + 9*5 + start_i = start_i + 9 * 5 else -- Reset scroll bar if not scrolled start_i = 0 end if start_i < 0 then - start_i = start_i + 9*5 + start_i = start_i + 9 * 5 end local inv_size if page == "nix" then - local inv = minetest.get_inventory({type="detached", name="creative_"..name}) + local inv = minetest.get_inventory({ type = "detached", name = "creative_" .. name }) inv_size = inv:get_size("main") elseif page and page ~= "inv" then inv_size = #(inventory_lists[page]) @@ -593,7 +616,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) players[name].inv_size = inv_size if start_i >= inv_size then - start_i = start_i - 9*5 + start_i = start_i - 9 * 5 end if start_i < 0 or start_i >= inv_size then start_i = 0 @@ -606,13 +629,66 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) players[name].filter = "" end - mcl_inventory.set_creative_formspec(player) + mcl_inventory.set_creative_formspec(player, start_i, start_i / (9 * 5) + 1, inv_size, false, page, filter) end) -minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack) - return placer and placer:is_player() and minetest.is_creative_enabled(placer:get_player_name()) -end) +if minetest.is_creative_enabled("") then + minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack) + -- Place infinite nodes, except for shulker boxes + local group = minetest.get_item_group(itemstack:get_name(), "shulker_box") + return group == 0 or group == nil + end) + + function minetest.handle_node_drops(pos, drops, digger) + if not digger or not digger:is_player() then + for _, item in ipairs(drops) do + minetest.add_item(pos, item) + end + end + local inv = digger:get_inventory() + if inv then + for _, item in ipairs(drops) do + if not inv:contains_item("main", item, true) then + inv:add_item("main", item) + end + end + end + end + + mcl_inventory.update_inventory_formspec = function(player) + local page + + local name = player:get_player_name() + + if players[name].page then + page = players[name].page + else + page = "nix" + end + + -- Figure out current scroll bar from formspec + --local formspec = player:get_inventory_formspec() + local start_i = players[name].start_i + + local inv_size + if page == "nix" then + local inv = minetest.get_inventory({ type = "detached", name = "creative_" .. name }) + inv_size = inv:get_size("main") + elseif page and page ~= "inv" then + inv_size = #(inventory_lists[page]) + else + inv_size = 0 + end + + local filter = players[name].filter + if filter == nil then + filter = "" + end + + mcl_inventory.set_creative_formspec(player, start_i, start_i / (9 * 5) + 1, inv_size, false, page, filter) + end +end minetest.register_on_joinplayer(function(player) -- Initialize variables and inventory @@ -629,7 +705,8 @@ minetest.register_on_joinplayer(function(player) end) minetest.register_on_player_inventory_action(function(player, action, inventory, inventory_info) - if minetest.is_creative_enabled(player:get_player_name()) and get_stack_size(player) == 64 and action == "put" and inventory_info.listname == "main" then + if minetest.is_creative_enabled(player:get_player_name()) and get_stack_size(player) == 64 and action == "put" and + inventory_info.listname == "main" then local stack = inventory_info.stack stack:set_count(stack:get_stack_max()) player:get_inventory():set_stack("main", inventory_info.index, stack) diff --git a/mods/HUD/mcl_inventory/init.lua b/mods/HUD/mcl_inventory/init.lua index b9b952e97..ca019fae8 100644 --- a/mods/HUD/mcl_inventory/init.lua +++ b/mods/HUD/mcl_inventory/init.lua @@ -300,6 +300,9 @@ local F = minetest.formspec_escape mcl_inventory = {} +dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/creative.lua") +dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/survival.lua") + --local mod_player = minetest.get_modpath("mcl_player") --local mod_craftguide = minetest.get_modpath("mcl_craftguide") @@ -363,90 +366,9 @@ local function set_inventory(player, armor_change_only) return end - local inv = player:get_inventory() - inv:set_width("craft", 2) - inv:set_size("craft", 4) - local armor_slots = { "helmet", "chestplate", "leggings", "boots" } - local armor_slot_imgs = "" - - for a = 1, 4 do - if inv:get_stack("armor", a + 1):is_empty() then - armor_slot_imgs = armor_slot_imgs .. - "image[0.375," .. (0.375 + (a - 1) * 1.25) .. ";1,1;mcl_inventory_empty_armor_slot_" .. armor_slots[a] .. ".png]" - end - end - - if inv:get_stack("offhand", 1):is_empty() then - armor_slot_imgs = armor_slot_imgs .. "image[5.375,4.125;1,1;mcl_inventory_empty_armor_slot_shield.png]" - end - - local form = table.concat({ - "formspec_version[6]", - "size[11.75,10.9]", - - --Armor slots - mcl_formspec.get_itemslot_bg_v4(0.375, 0.375, 1, 4), - "list[current_player;armor;0.375,0.375;1,1;1]", - "list[current_player;armor;0.375,1.625;1,1;2]", - "list[current_player;armor;0.375,2.875;1,1;3]", - "list[current_player;armor;0.375,4.125;1,1;4]", - - --Main inventory - mcl_formspec.get_itemslot_bg_v4(0.375, 5.575, 9, 3), - "list[current_player;main;0.375,5.575;9,3;9]", - - --Hotbar - mcl_formspec.get_itemslot_bg_v4(0.375, 9.525, 9, 1), - "list[current_player;main;0.375,9.525;9,1;]", - - --Player model - "image[1.57,0.343;3.62,4.85;mcl_inventory_background9.png;2]", - mcl_player.get_player_formspec_model(player, 1.57, 0.4, 3.62, 4.85, ""), - - --Offhand - mcl_formspec.get_itemslot_bg_v4(5.375, 4.125, 1, 1), - "list[current_player;offhand;5.375,4.125;1,1]", - - armor_slot_imgs, - - --Craft grid - "label[6.61,0.5;" .. F(minetest.colorize(mcl_formspec.label_color, S("Crafting"))) .. "]", - - mcl_formspec.get_itemslot_bg_v4(6.625, 0.875, 2, 2), - "list[current_player;craft;6.625,0.875;2,2]", - - "image[9.125,1.5;1,1;crafting_formspec_arrow.png]", - - mcl_formspec.get_itemslot_bg_v4(10.375, 1.5, 1, 1), - "list[current_player;craftpreview;10.375,1.5;1,1;]", - - --Crafting guide button - "image_button[6.575,4.075;1.1,1.1;craftguide_book.png;__mcl_craftguide;]", - "tooltip[__mcl_craftguide;" .. F(S("Recipe book")) .. "]", - - --Help button - "image_button[7.825,4.075;1.1,1.1;doc_button_icon_lores.png;__mcl_doc;]", - "tooltip[__mcl_doc;" .. F(S("Help")) .. "]", - - --Skins button - "image_button[9.075,4.075;1.1,1.1;mcl_skins_button.png;__mcl_skins;]", - "tooltip[__mcl_skins;" .. F(S("Select player skin")) .. "]", - - --Achievements button - "image_button[10.325,4.075;1.1,1.1;mcl_achievements_button.png;__mcl_achievements;]", - "tooltip[__mcl_achievements;" .. F(S("Achievements")) .. "]", - - --Listring - "listring[current_player;main]", - "listring[current_player;armor]", - "listring[current_player;main]", - "listring[current_player;craft]", - "listring[current_player;main]", - }) - - player:set_inventory_formspec(form) + player:set_inventory_formspec(mcl_inventory.build_survival_formspec(player)) end -- Drop items in craft grid and reset inventory on closing @@ -508,87 +430,21 @@ minetest.register_on_joinplayer(function(player) return_fields(player, "enchanting_lapis") end) - -dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/creative.lua") - -local mt_is_creative_enabled = minetest.is_creative_enabled - -function minetest.is_creative_enabled(name) - if mt_is_creative_enabled(name) then return true end - if not name then return false end - local p = minetest.get_player_by_name(name) - if p then - return p:get_meta():get_string("gamemode") == "creative" +---@param player ObjectRef +function mcl_inventory.update_inventory(player) + local player_gamemode = mcl_gamemode.get_gamemode(player) + if player_gamemode == "creative" then + --if armor_change_only then + -- Stay on survival inventory plage if only the armor has been changed + -- mcl_inventory.set_creative_formspec(player, 0, 0, nil, nil, "inv") + --else + mcl_inventory.set_creative_formspec(player, 0, 1) + --end + elseif player_gamemode == "survival" then + player:set_inventory_formspec(mcl_inventory.build_survival_formspec(player)) end - return false end ---Insta "digging" nodes in gamemode-creative -minetest.register_on_punchnode(function(pos, node, puncher, pointed_thing) - if not puncher or not puncher:is_player() then return end - if minetest.is_creative_enabled() then return end - local name = puncher:get_player_name() - if not minetest.is_creative_enabled(name) then return end - if pointed_thing.type ~= "node" then return end - local def = minetest.registered_nodes[node.name] - if def then - if def.on_destruct then def.on_destruct(pos) end - minetest.remove_node(pos) - return true - end +mcl_gamemode.register_on_gamemode_change(function(player, old_gamemode, new_gamemode) + set_inventory(player) end) - ---Don't subtract from inv when placing in gamemode-creative -minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack, pointed_thing) - if placer and placer:is_player() and minetest.is_creative_enabled(placer:get_player_name()) then return true end -end) - -local function in_table(n, h) - for k, v in pairs(h) do - if v == n then return true end - end - return false -end - -local gamemodes = { - "survival", - "creative" -} - -function mcl_inventory.player_set_gamemode(p, g) - local m = p:get_meta() - m:set_string("gamemode", g) - if g == "survival" then - mcl_experience.setup_hud(p) - mcl_experience.update(p) - elseif g == "creative" then - mcl_experience.remove_hud(p) - end - set_inventory(p) -end - -minetest.register_chatcommand("gamemode", { - params = S("[] []"), - description = S("Change gamemode (survival/creative) for yourself or player"), - privs = { server = true }, - func = function(n, param) - -- Full input validation ( just for @erlehmann <3 ) - local p = minetest.get_player_by_name(n) - local args = param:split(" ") - if args[2] ~= nil then - p = minetest.get_player_by_name(args[2]) - end - if not p then - return false, S("Player not online") - end - if args[1] ~= nil and not in_table(args[1], gamemodes) then - return false, S("Gamemode " .. args[1] .. " does not exist.") - elseif args[1] ~= nil then - mcl_inventory.player_set_gamemode(p, args[1]) - end - --Result message - show effective game mode - local gm = p:get_meta():get_string("gamemode") - if gm == "" then gm = gamemodes[1] end - return true, S("Gamemode for player ") .. n .. S(": " .. gm) - end -}) diff --git a/mods/HUD/mcl_inventory/mod.conf b/mods/HUD/mcl_inventory/mod.conf index e42213d4f..80aab2ab1 100644 --- a/mods/HUD/mcl_inventory/mod.conf +++ b/mods/HUD/mcl_inventory/mod.conf @@ -1,5 +1,10 @@ name = mcl_inventory author = BlockMen description = Adds the player inventory and creative inventory. +<<<<<<< HEAD depends = mcl_init, mcl_formspec, mcl_enchanting, mcl_player optional_depends = mcl_armor, mcl_brewing, mcl_potions, mcl_enchanting, mcl_craftguide +======= +depends = mcl_init, mcl_formspec, mcl_enchanting, mcl_gamemode +optional_depends = mcl_armor, mcl_brewing, mcl_potions, mcl_enchanting, mcl_craftguide, mcl_player +>>>>>>> a2429154d (survival inventory tabs API + mcl_gamemode) diff --git a/mods/HUD/mcl_inventory/survival.lua b/mods/HUD/mcl_inventory/survival.lua new file mode 100644 index 000000000..99c8cf839 --- /dev/null +++ b/mods/HUD/mcl_inventory/survival.lua @@ -0,0 +1,219 @@ +---@diagnostic disable need-check-nil + +local table = table +local ipairs = ipairs + +local S = minetest.get_translator("mcl_inventory") +local F = minetest.formspec_escape + +---@type {id: string, description: string, item_icon: string, build: (fun(player: ObjectRef): string), handle: fun(player: ObjectRef, fields: table), access: (fun(player): boolean), show_inventory: boolean}[] +mcl_inventory.registered_survival_inventory_tabs = {} + +---@param def {id: string, description: string, item_icon: string, build: (fun(player: ObjectRef): string), handle: fun(player: ObjectRef, fields: table), access: (fun(player): boolean), show_inventory: boolean} +function mcl_inventory.register_survival_inventory_tab(def) + if #mcl_inventory.registered_survival_inventory_tabs == 7 then + error("Too much tabs registered!") + end + + assert(def.id) + assert(def.description) + assert(def.item_icon) + assert(def.build) + assert(def.handle) + + if not def.access then + function def.access(player) + return true + end + end + + if def.show_inventory == nil then + def.show_inventory = true + end + + table.insert(mcl_inventory.registered_survival_inventory_tabs, def) +end + +local player_current_tab = {} + +minetest.register_on_joinplayer(function(player, last_login) + player_current_tab[player] = "main" +end) + +minetest.register_on_leaveplayer(function(player, timed_out) + player_current_tab[player] = nil +end) + +---@param player ObjectRef +---@param content string +---@param inventory boolean +---@param tabname string +function build_page(player, content, inventory, tabname) + local tab_buttons = "style_type[image;noclip=true]" + + if #mcl_inventory.registered_survival_inventory_tabs ~= 1 then + for i, d in ipairs(mcl_inventory.registered_survival_inventory_tabs) do + local btn_name = "tab_" .. d.id + + tab_buttons = tab_buttons .. table.concat({ + "style[" .. btn_name .. ";border=false;bgimg=;bgimg_pressed=;noclip=true]", + "image[" .. + (0.2 + (i - 1) * 1.6) .. + ",-1.34;1.5,1.44;" .. (tabname == d.id and "crafting_creative_active.png" or "crafting_creative_inactive.png") .. + "]", + "item_image_button[" .. (0.44 + (i - 1) * 1.6) .. ",-1.1;1,1;" .. d.item_icon .. ";" .. btn_name .. ";]", + }) + end + end + + return table.concat({ + "formspec_version[6]", + "size[11.75,10.9]", + + inventory and table.concat({ + --Main inventory + mcl_formspec.get_itemslot_bg_v4(0.375, 5.575, 9, 3), + "list[current_player;main;0.375,5.575;9,3;9]", + + --Hotbar + mcl_formspec.get_itemslot_bg_v4(0.375, 9.525, 9, 1), + "list[current_player;main;0.375,9.525;9,1;]" + }) or "", + + content, + tab_buttons, + }) +end + +local main_page_static = table.concat({ + --Armor slots + mcl_formspec.get_itemslot_bg_v4(0.375, 0.375, 1, 4), + "list[current_player;armor;0.375,0.375;1,1;1]", + "list[current_player;armor;0.375,1.625;1,1;2]", + "list[current_player;armor;0.375,2.875;1,1;3]", + "list[current_player;armor;0.375,4.125;1,1;4]", + + --Player model background + "image[1.57,0.343;3.62,4.85;mcl_inventory_background9.png;2]", + + --Offhand + mcl_formspec.get_itemslot_bg_v4(5.375, 4.125, 1, 1), + "list[current_player;offhand;5.375,4.125;1,1]", + + --Craft grid + "label[6.61,0.5;" .. F(minetest.colorize(mcl_formspec.label_color, S("Crafting"))) .. "]", + + mcl_formspec.get_itemslot_bg_v4(6.625, 0.875, 2, 2), + "list[current_player;craft;6.625,0.875;2,2]", + + "image[9.125,1.5;1,1;crafting_formspec_arrow.png]", + + mcl_formspec.get_itemslot_bg_v4(10.375, 1.5, 1, 1), + "list[current_player;craftpreview;10.375,1.5;1,1;]", + + --Crafting guide button + "image_button[6.575,4.075;1.1,1.1;craftguide_book.png;__mcl_craftguide;]", + "tooltip[__mcl_craftguide;" .. F(S("Recipe book")) .. "]", + + --Help button + "image_button[7.825,4.075;1.1,1.1;doc_button_icon_lores.png;__mcl_doc;]", + "tooltip[__mcl_doc;" .. F(S("Help")) .. "]", + + --Skins button + "image_button[9.075,4.075;1.1,1.1;mcl_skins_button.png;__mcl_skins;]", + "tooltip[__mcl_skins;" .. F(S("Select player skin")) .. "]", + + --Achievements button + "image_button[10.325,4.075;1.1,1.1;mcl_achievements_button.png;__mcl_achievements;]", + "tooltip[__mcl_achievements;" .. F(S("Achievements")) .. "]", + + --Listring + "listring[current_player;main]", + "listring[current_player;armor]", + "listring[current_player;main]", + "listring[current_player;craft]", + "listring[current_player;main]", +}) + +mcl_inventory.register_survival_inventory_tab({ + id = "main", + description = "Main Inventory", + item_icon = "mcl_crafting_table:crafting_table", + show_inventory = true, + build = function(player) + local inv = player:get_inventory() + + local armor_slots = { "helmet", "chestplate", "leggings", "boots" } + local armor_slot_imgs = "" + + for a = 1, 4 do + if inv:get_stack("armor", a + 1):is_empty() then + armor_slot_imgs = armor_slot_imgs .. + "image[0.375," .. (0.375 + (a - 1) * 1.25) .. ";1,1;mcl_inventory_empty_armor_slot_" .. armor_slots[a] .. ".png]" + end + end + + if inv:get_stack("offhand", 1):is_empty() then + armor_slot_imgs = armor_slot_imgs .. "image[5.375,4.125;1,1;mcl_inventory_empty_armor_slot_shield.png]" + end + return main_page_static .. armor_slot_imgs .. mcl_player.get_player_formspec_model(player, 1.57, 0.4, 3.62, 4.85, "") + end, + handle = function() end, +}) + +-- +mcl_inventory.register_survival_inventory_tab({ + id = "test", + description = "Test", + item_icon = "mcl_core:stone", + show_inventory = true, + build = function(player) + return "label[1,1;Hello hello]button[2,2;2,2;Hello;hey]" + end, + handle = function(player, fields) + print(dump(fields)) + end, +}) + +---@param player ObjectRef +function mcl_inventory.build_survival_formspec(player) + local inv = player:get_inventory() + + inv:set_width("craft", 2) + inv:set_size("craft", 4) + + local tab = player_current_tab[player] + + local tab_def = nil + + for _, d in ipairs(mcl_inventory.registered_survival_inventory_tabs) do + if tab == d.id then + tab_def = d + break + end + end + + local form = build_page(player, tab_def.build(player), tab_def.show_inventory, tab) + + return form +end + +minetest.register_on_player_receive_fields(function(player, formname, fields) + if formname == "" and #mcl_inventory.registered_survival_inventory_tabs ~= 1 and + mcl_gamemode.get_gamemode(player) == "survival" then + for _, d in ipairs(mcl_inventory.registered_survival_inventory_tabs) do + if fields["tab_" .. d.id] and d.access(player) then + player_current_tab[player] = d.id + mcl_inventory.update_inventory(player) + return + end + end + + for _, d in ipairs(mcl_inventory.registered_survival_inventory_tabs) do + if player_current_tab[player] == d.id and d.access(player) then + d.handle(player, fields) + return + end + end + end +end) diff --git a/mods/PLAYER/mcl_gamemode/init.lua b/mods/PLAYER/mcl_gamemode/init.lua new file mode 100644 index 000000000..7ac814073 --- /dev/null +++ b/mods/PLAYER/mcl_gamemode/init.lua @@ -0,0 +1,106 @@ +---@diagnostic disable lowercase-global + +local S = minetest.get_translator("mcl_gamemode") + +mcl_gamemode = {} + +mcl_gamemode.gamemodes = { + "survival", + "creative", +} + +---@param n any +---@param h table +---@return boolean +local function in_table(n, h) + for k, v in pairs(h) do + if v == n then return true end + end + return false +end + +---@type fun(player: ObjectRef, old_gamemode: '"survival"'|'"creative"', new_gamemode: '"survival"'|'"creative"')[] +mcl_gamemode.registered_on_gamemode_change = {} + +---@param func fun(player: ObjectRef, old_gamemode: '"survival"'|'"creative"', new_gamemode: '"survival"'|'"creative"') +function mcl_gamemode.register_on_gamemode_change(func) + table.insert(mcl_gamemode.registered_on_gamemode_change, func) +end + +---@param player ObjectRef +---@param gamemode '"survival"'|'"creative"' +function mcl_gamemode.set_gamemode(player, gamemode) + local meta = player:get_meta() + local old_gamemode = meta:get_string("gamemode") + meta:set_string("gamemode", gamemode) + for _, f in ipairs(mcl_gamemode.registered_on_gamemode_change) do + f(player, old_gamemode, gamemode) + end +end + +local mt_is_creative_enabled = minetest.is_creative_enabled + +---@param player ObjectRef +---@return '"survival"'|'"creative"' +function mcl_gamemode.get_gamemode(player) + if mt_is_creative_enabled(player:get_player_name()) then + return "creative" + end + return player:get_meta():get_string("gamemode") +end + +function minetest.is_creative_enabled(name) + if mt_is_creative_enabled(name) then return true end + if not name then return false end + local p = minetest.get_player_by_name(name) + if p then + return p:get_meta():get_string("gamemode") == "creative" + end + return false +end + +-- Insta "digging" nodes in gamemode-creative +minetest.register_on_punchnode(function(pos, node, puncher, pointed_thing) + if not puncher or not puncher:is_player() then return end + if minetest.is_creative_enabled() then return end + local name = puncher:get_player_name() + if not minetest.is_creative_enabled(name) then return end + if pointed_thing.type ~= "node" then return end + local def = minetest.registered_nodes[node.name] + if def then + if def.on_destruct then def.on_destruct(pos) end + minetest.remove_node(pos) + return true + end +end) + +-- Don't subtract from inv when placing in gamemode-creative +minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack, pointed_thing) + if placer and placer:is_player() and minetest.is_creative_enabled(placer:get_player_name()) then return true end +end) + +minetest.register_chatcommand("gamemode", { + params = S("[] []"), + description = S("Change gamemode (survival/creative) for yourself or player"), + privs = { server = true }, + func = function(n, param) + -- Full input validation ( just for @erlehmann <3 ) + local p = minetest.get_player_by_name(n) + local args = param:split(" ") + if args[2] ~= nil then + p = minetest.get_player_by_name(args[2]) + end + if not p then + return false, S("Player not online") + end + if args[1] ~= nil and not in_table(args[1], gamemodes) then + return false, S("Gamemode " .. args[1] .. " does not exist.") + elseif args[1] ~= nil then + mcl_inventory.player_set_gamemode(p, args[1]) + end + --Result message - show effective game mode + local gm = p:get_meta():get_string("gamemode") + if gm == "" then gm = gamemodes[1] end + return true, S("Gamemode for player ") .. n .. S(": " .. gm) + end +}) diff --git a/mods/PLAYER/mcl_gamemode/mod.conf b/mods/PLAYER/mcl_gamemode/mod.conf new file mode 100644 index 000000000..03eade707 --- /dev/null +++ b/mods/PLAYER/mcl_gamemode/mod.conf @@ -0,0 +1 @@ +name = mcl_gamemode \ No newline at end of file From 04a58ddd24ce01f1f106fad8284ff17c8b0e9cfc Mon Sep 17 00:00:00 2001 From: AFCMS Date: Sat, 10 Sep 2022 01:06:53 +0200 Subject: [PATCH 29/82] Disable test tab --- mods/HUD/mcl_inventory/survival.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mods/HUD/mcl_inventory/survival.lua b/mods/HUD/mcl_inventory/survival.lua index 99c8cf839..5f213ad2b 100644 --- a/mods/HUD/mcl_inventory/survival.lua +++ b/mods/HUD/mcl_inventory/survival.lua @@ -161,7 +161,7 @@ mcl_inventory.register_survival_inventory_tab({ handle = function() end, }) --- +--[[ mcl_inventory.register_survival_inventory_tab({ id = "test", description = "Test", @@ -173,7 +173,7 @@ mcl_inventory.register_survival_inventory_tab({ handle = function(player, fields) print(dump(fields)) end, -}) +})]] ---@param player ObjectRef function mcl_inventory.build_survival_formspec(player) From 9e83e531bdea548d2b2db6193e4412b93dfcd845 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Sat, 10 Sep 2022 11:03:28 +0200 Subject: [PATCH 30/82] Make function local --- mods/HUD/mcl_inventory/survival.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/HUD/mcl_inventory/survival.lua b/mods/HUD/mcl_inventory/survival.lua index 5f213ad2b..0ca22d119 100644 --- a/mods/HUD/mcl_inventory/survival.lua +++ b/mods/HUD/mcl_inventory/survival.lua @@ -48,7 +48,7 @@ end) ---@param content string ---@param inventory boolean ---@param tabname string -function build_page(player, content, inventory, tabname) +local function build_page(player, content, inventory, tabname) local tab_buttons = "style_type[image;noclip=true]" if #mcl_inventory.registered_survival_inventory_tabs ~= 1 then From 452cd2655816b54ef8750d8d0a68a16994223bec Mon Sep 17 00:00:00 2001 From: AFCMS Date: Sat, 10 Sep 2022 11:05:59 +0200 Subject: [PATCH 31/82] Reenable creative formspec armor update --- mods/HUD/mcl_inventory/init.lua | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/mods/HUD/mcl_inventory/init.lua b/mods/HUD/mcl_inventory/init.lua index ca019fae8..2f954c070 100644 --- a/mods/HUD/mcl_inventory/init.lua +++ b/mods/HUD/mcl_inventory/init.lua @@ -431,15 +431,16 @@ minetest.register_on_joinplayer(function(player) end) ---@param player ObjectRef -function mcl_inventory.update_inventory(player) +---@param armor_change_only? boolean +function mcl_inventory.update_inventory(player, armor_change_only) local player_gamemode = mcl_gamemode.get_gamemode(player) if player_gamemode == "creative" then - --if armor_change_only then - -- Stay on survival inventory plage if only the armor has been changed - -- mcl_inventory.set_creative_formspec(player, 0, 0, nil, nil, "inv") - --else - mcl_inventory.set_creative_formspec(player, 0, 1) - --end + if armor_change_only then + -- Stay on survival inventory plage if only the armor has been changed + mcl_inventory.set_creative_formspec(player, 0, 0, nil, nil, "inv") + else + mcl_inventory.set_creative_formspec(player, 0, 1) + end elseif player_gamemode == "survival" then player:set_inventory_formspec(mcl_inventory.build_survival_formspec(player)) end From 1065eb4d8c74c4aa4d4af7ffcb5ecbb98a366951 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Sat, 10 Sep 2022 11:20:48 +0200 Subject: [PATCH 32/82] Hooper formspec --- mods/HUD/mcl_inventory/init.lua | 4 +- mods/ITEMS/mcl_hoppers/init.lua | 77 ++++++++++++++++++--------------- 2 files changed, 43 insertions(+), 38 deletions(-) diff --git a/mods/HUD/mcl_inventory/init.lua b/mods/HUD/mcl_inventory/init.lua index 2f954c070..6edfc3d78 100644 --- a/mods/HUD/mcl_inventory/init.lua +++ b/mods/HUD/mcl_inventory/init.lua @@ -366,8 +366,6 @@ local function set_inventory(player, armor_change_only) return end - - player:set_inventory_formspec(mcl_inventory.build_survival_formspec(player)) end @@ -436,7 +434,7 @@ function mcl_inventory.update_inventory(player, armor_change_only) local player_gamemode = mcl_gamemode.get_gamemode(player) if player_gamemode == "creative" then if armor_change_only then - -- Stay on survival inventory plage if only the armor has been changed + -- Stay on survival inventory page if only the armor has been changed mcl_inventory.set_creative_formspec(player, 0, 0, nil, nil, "inv") else mcl_inventory.set_creative_formspec(player, 0, 1) diff --git a/mods/ITEMS/mcl_hoppers/init.lua b/mods/ITEMS/mcl_hoppers/init.lua index 62b358c64..b4378b21b 100644 --- a/mods/ITEMS/mcl_hoppers/init.lua +++ b/mods/ITEMS/mcl_hoppers/init.lua @@ -12,17 +12,24 @@ end --[[ BEGIN OF NODE DEFINITIONS ]] local mcl_hoppers_formspec = table.concat({ - "size[9,7]", - "label[2,0;"..F(C(mcl_formspec.label_color, S("Hopper"))).."]", - "list[context;main;2,0.5;5,1;]", - mcl_formspec.get_itemslot_bg(2,0.5,5,1), - "label[0,2;"..F(C(mcl_formspec.label_color, S("Inventory"))).."]", - "list[current_player;main;0,2.5;9,3;9]", - mcl_formspec.get_itemslot_bg(0,2.5,9,3), - "list[current_player;main;0,5.74;9,1;]", - mcl_formspec.get_itemslot_bg(0,5.74,9,1), + "formspec_version[4]", + "size[11.75,8.175]", + + "label[0.375,0.375;" .. F(C(mcl_formspec.label_color, S("Hopper"))) .. "]", + + mcl_formspec.get_itemslot_bg_v4(2.875, 0.75, 5, 1), + "list[context;main;2.875,0.75;5,1;]", + + "label[0.375,2.45;" .. F(C(mcl_formspec.label_color, S("Inventory"))) .. "]", + + mcl_formspec.get_itemslot_bg_v4(0.375, 2.85, 9, 3), + "list[current_player;main;0.375,2.85;9,3;9]", + + mcl_formspec.get_itemslot_bg_v4(0.375, 6.8, 9, 1), + "list[current_player;main;0.375,6.8;9,1;]", + "listring[context;main]", - "listring[current_player;main]" + "listring[current_player;main]", }) -- Downwards hopper (base definition) @@ -31,7 +38,7 @@ local mcl_hoppers_formspec = table.concat({ local def_hopper = { inventory_image = "mcl_hoppers_item.png", wield_image = "mcl_hoppers_item.png", - groups = {pickaxey = 1, container = 2, deco_block = 1, hopper = 1}, + groups = { pickaxey = 1, container = 2, deco_block = 1, hopper = 1 }, drawtype = "nodebox", paramtype = "light", -- FIXME: mcl_hoppers_hopper_inside.png is unused by hoppers. @@ -47,25 +54,25 @@ local def_hopper = { type = "fixed", fixed = { --funnel walls - {-0.5, 0.0, 0.4, 0.5, 0.5, 0.5}, - {0.4, 0.0, -0.5, 0.5, 0.5, 0.5}, - {-0.5, 0.0, -0.5, -0.4, 0.5, 0.5}, - {-0.5, 0.0, -0.5, 0.5, 0.5, -0.4}, + { -0.5, 0.0, 0.4, 0.5, 0.5, 0.5 }, + { 0.4, 0.0, -0.5, 0.5, 0.5, 0.5 }, + { -0.5, 0.0, -0.5, -0.4, 0.5, 0.5 }, + { -0.5, 0.0, -0.5, 0.5, 0.5, -0.4 }, --funnel base - {-0.5, 0.0, -0.5, 0.5, 0.1, 0.5}, + { -0.5, 0.0, -0.5, 0.5, 0.1, 0.5 }, --spout - {-0.3, -0.3, -0.3, 0.3, 0.0, 0.3}, - {-0.1, -0.3, -0.1, 0.1, -0.5, 0.1}, + { -0.3, -0.3, -0.3, 0.3, 0.0, 0.3 }, + { -0.1, -0.3, -0.1, 0.1, -0.5, 0.1 }, }, }, selection_box = { type = "fixed", fixed = { --funnel - {-0.5, 0.0, -0.5, 0.5, 0.5, 0.5}, + { -0.5, 0.0, -0.5, 0.5, 0.5, 0.5 }, --spout - {-0.3, -0.3, -0.3, 0.3, 0.0, 0.3}, - {-0.1, -0.3, -0.1, 0.1, -0.5, 0.1}, + { -0.3, -0.3, -0.3, 0.3, 0.0, 0.3 }, + { -0.1, -0.3, -0.1, 0.1, -0.5, 0.1 }, }, }, is_ground_content = false, @@ -248,25 +255,25 @@ local def_hopper_side = { type = "fixed", fixed = { --funnel walls - {-0.5, 0.0, 0.4, 0.5, 0.5, 0.5}, - {0.4, 0.0, -0.5, 0.5, 0.5, 0.5}, - {-0.5, 0.0, -0.5, -0.4, 0.5, 0.5}, - {-0.5, 0.0, -0.5, 0.5, 0.5, -0.4}, + { -0.5, 0.0, 0.4, 0.5, 0.5, 0.5 }, + { 0.4, 0.0, -0.5, 0.5, 0.5, 0.5 }, + { -0.5, 0.0, -0.5, -0.4, 0.5, 0.5 }, + { -0.5, 0.0, -0.5, 0.5, 0.5, -0.4 }, --funnel base - {-0.5, 0.0, -0.5, 0.5, 0.1, 0.5}, + { -0.5, 0.0, -0.5, 0.5, 0.1, 0.5 }, --spout - {-0.3, -0.3, -0.3, 0.3, 0.0, 0.3}, - {-0.5, -0.3, -0.1, 0.1, -0.1, 0.1}, + { -0.3, -0.3, -0.3, 0.3, 0.0, 0.3 }, + { -0.5, -0.3, -0.1, 0.1, -0.1, 0.1 }, }, }, selection_box = { type = "fixed", fixed = { --funnel - {-0.5, 0.0, -0.5, 0.5, 0.5, 0.5}, + { -0.5, 0.0, -0.5, 0.5, 0.5, 0.5 }, --spout - {-0.3, -0.3, -0.3, 0.3, 0.0, 0.3}, - {-0.5, -0.3, -0.1, 0.1, -0.1, 0.1}, + { -0.3, -0.3, -0.3, 0.3, 0.0, 0.3 }, + { -0.5, -0.3, -0.1, 0.1, -0.1, 0.1 }, }, }, is_ground_content = false, @@ -559,8 +566,8 @@ end minetest.register_abm({ label = "Hopper/container item exchange", - nodenames = {"mcl_hoppers:hopper"}, - neighbors = {"group:container"}, + nodenames = { "mcl_hoppers:hopper" }, + neighbors = { "group:container" }, interval = 1.0, chance = 1, action = function(pos, node, active_object_count, active_object_count_wider) @@ -591,8 +598,8 @@ minetest.register_abm({ minetest.register_abm({ label = "Side-hopper/container item exchange", - nodenames = {"mcl_hoppers:hopper_side"}, - neighbors = {"group:container"}, + nodenames = { "mcl_hoppers:hopper_side" }, + neighbors = { "group:container" }, interval = 1.0, chance = 1, action = function(pos, node, active_object_count, active_object_count_wider) From 37176976b66b418887e5c7e856945fe580398322 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Sat, 10 Sep 2022 11:39:10 +0200 Subject: [PATCH 33/82] Dropper + Dispenser inventory --- mods/ITEMS/REDSTONE/mcl_dispensers/init.lua | 127 +++++++++++--------- mods/ITEMS/REDSTONE/mcl_droppers/init.lua | 78 +++++++----- 2 files changed, 117 insertions(+), 88 deletions(-) diff --git a/mods/ITEMS/REDSTONE/mcl_dispensers/init.lua b/mods/ITEMS/REDSTONE/mcl_dispensers/init.lua index 17d9385a2..fa8ecc779 100644 --- a/mods/ITEMS/REDSTONE/mcl_dispensers/init.lua +++ b/mods/ITEMS/REDSTONE/mcl_dispensers/init.lua @@ -8,23 +8,36 @@ All node definitions share a lot of code, so this is the reason why there are so many weird tables below. ]] local S = minetest.get_translator(minetest.get_current_modname()) +local C = minetest.colorize +local F = minetest.formspec_escape --- For after_place_node +local dispenser_formspec = table.concat({ + "formspec_version[4]", + "size[11.75,10.425]", + + "label[4.125,0.375;" .. F(C(mcl_formspec.label_color, S("Dispenser"))) .. "]", + + mcl_formspec.get_itemslot_bg_v4(4.125, 0.75, 3, 3), + "list[context;main;4.125,0.75;3,3;]", + + "label[0.375,4.7;" .. F(C(mcl_formspec.label_color, S("Inventory"))) .. "]", + + mcl_formspec.get_itemslot_bg_v4(0.375, 5.1, 9, 3), + "list[current_player;main;0.375,5.1;9,3;9]", + + mcl_formspec.get_itemslot_bg_v4(0.375, 9.05, 9, 1), + "list[current_player;main;0.375,9.05;9,1;]", + + "listring[context;main]", + "listring[current_player;main]", +}) + +---For after_place_node +---@param pos Vector local function setup_dispenser(pos) -- Set formspec and inventory - local form = "size[9,8.75]".. - "label[0,4.0;"..minetest.formspec_escape(minetest.colorize("#313131", S("Inventory"))).."]".. - "list[current_player;main;0,4.5;9,3;9]".. - mcl_formspec.get_itemslot_bg(0,4.5,9,3).. - "list[current_player;main;0,7.74;9,1;]".. - mcl_formspec.get_itemslot_bg(0,7.74,9,1).. - "label[3,0;"..minetest.formspec_escape(minetest.colorize("#313131", S("Dispenser"))).."]".. - "list[context;main;3,0.5;3,3;]".. - mcl_formspec.get_itemslot_bg(3,0.5,3,3).. - "listring[context;main]".. - "listring[current_player;main]" local meta = minetest.get_meta(pos) - meta:set_string("formspec", form) + meta:set_string("formspec", dispenser_formspec) local inv = meta:get_inventory() inv:set_size("main", 9) end @@ -38,9 +51,9 @@ local function orientate_dispenser(pos, placer) local node = minetest.get_node(pos) if pitch > 55 then - minetest.swap_node(pos, {name="mcl_dispensers:dispenser_up", param2 = node.param2}) + minetest.swap_node(pos, { name = "mcl_dispensers:dispenser_up", param2 = node.param2 }) elseif pitch < -55 then - minetest.swap_node(pos, {name="mcl_dispensers:dispenser_down", param2 = node.param2}) + minetest.swap_node(pos, { name = "mcl_dispensers:dispenser_down", param2 = node.param2 }) end end @@ -85,10 +98,10 @@ local dispenserdef = { local meta2 = meta:to_table() meta:from_table(oldmetadata) local inv = meta:get_inventory() - for i=1, inv:get_size("main") do + for i = 1, inv:get_size("main") do local stack = inv:get_stack("main", i) if not stack:is_empty() then - local p = {x=pos.x+math.random(0, 10)/10-0.5, y=pos.y, z=pos.z+math.random(0, 10)/10-0.5} + local p = { x = pos.x + math.random(0, 10) / 10 - 0.5, y = pos.y, z = pos.z + math.random(0, 10) / 10 - 0.5 } minetest.add_item(p, stack) end end @@ -107,19 +120,19 @@ local dispenserdef = { dropdir = vector.multiply(minetest.facedir_to_dir(node.param2), -1) droppos = vector.add(pos, dropdir) elseif node.name == "mcl_dispensers:dispenser_up" then - dropdir = {x=0, y=1, z=0} - droppos = {x=pos.x, y=pos.y+1, z=pos.z} + dropdir = { x = 0, y = 1, z = 0 } + droppos = { x = pos.x, y = pos.y + 1, z = pos.z } elseif node.name == "mcl_dispensers:dispenser_down" then - dropdir = {x=0, y=-1, z=0} - droppos = {x=pos.x, y=pos.y-1, z=pos.z} + dropdir = { x = 0, y = -1, z = 0 } + droppos = { x = pos.x, y = pos.y - 1, z = pos.z } end local dropnode = minetest.get_node(droppos) local dropnodedef = minetest.registered_nodes[dropnode.name] local stacks = {} - for i=1,inv:get_size("main") do + for i = 1, inv:get_size("main") do local stack = inv:get_stack("main", i) if not stack:is_empty() then - table.insert(stacks, {stack = stack, stackpos = i}) + table.insert(stacks, { stack = stack, stackpos = i }) end end if #stacks >= 1 then @@ -143,9 +156,10 @@ local dispenserdef = { -- Armor, mob heads and pumpkins if igroups.armor then - local droppos_below = {x = droppos.x, y = droppos.y - 1, z = droppos.z} + local droppos_below = { x = droppos.x, y = droppos.y - 1, z = droppos.z } - for _, objs in ipairs({minetest.get_objects_inside_radius(droppos, 1), minetest.get_objects_inside_radius(droppos_below, 1)}) do + for _, objs in ipairs({ minetest.get_objects_inside_radius(droppos, 1), + minetest.get_objects_inside_radius(droppos_below, 1) }) do for _, obj in ipairs(objs) do stack = mcl_armor.equip(stack, obj) if stack:is_empty() then @@ -157,11 +171,11 @@ local dispenserdef = { end end - -- Place head or pumpkin as node, if equipping it as armor has failed + -- Place head or pumpkin as node, if equipping it as armor has failed if not stack:is_empty() then if igroups.head or iname == "mcl_farming:pumpkin_face" then if dropnodedef.buildable_to then - minetest.set_node(droppos, {name = iname, param2 = node.param2}) + minetest.set_node(droppos, { name = iname, param2 = node.param2 }) stack:take_item() end end @@ -169,7 +183,7 @@ local dispenserdef = { inv:set_stack("main", stack_id, stack) - -- Use shears on sheeps + -- Use shears on sheeps elseif igroups.shears then for _, obj in pairs(minetest.get_objects_inside_radius(droppos, 1)) do local entity = obj:get_luaentity() @@ -220,7 +234,7 @@ local dispenserdef = { end end - -- Spawn Egg + -- Spawn Egg elseif igroups.spawn_egg then -- Spawn mob if not dropnodedef.walkable then @@ -231,7 +245,7 @@ local dispenserdef = { inv:set_stack("main", stack_id, stack) end - -- Generalized dispension + -- Generalized dispension elseif (not dropnodedef.walkable or stackdef._dispense_into_walkable) then --[[ _on_dispense(stack, pos, droppos, dropnode, dropdir) * stack: Itemstack which is dispense @@ -263,7 +277,7 @@ local dispenserdef = { local item_entity = minetest.add_item(droppos, dropitem) local drop_vel = vector.subtract(droppos, pos) local speed = 3 - item_entity:set_velocity(vector.multiply(drop_vel,speed)) + item_entity:set_velocity(vector.multiply(drop_vel, speed)) end else stack:take_item() @@ -280,7 +294,7 @@ local dispenserdef = { local item_entity = minetest.add_item(droppos, dropitem) local drop_vel = vector.subtract(droppos, pos) local speed = 3 - item_entity:set_velocity(vector.multiply(drop_vel,speed)) + item_entity:set_velocity(vector.multiply(drop_vel, speed)) stack:take_item() inv:set_stack("main", stack_id, stack) end @@ -299,27 +313,28 @@ local dispenserdef = { local horizontal_def = table.copy(dispenserdef) horizontal_def.description = S("Dispenser") -horizontal_def._tt_help = S("9 inventory slots").."\n"..S("Launches item when powered by redstone power") +horizontal_def._tt_help = S("9 inventory slots") .. "\n" .. S("Launches item when powered by redstone power") horizontal_def._doc_items_longdesc = S("A dispenser is a block which acts as a redstone component which, when powered with redstone power, dispenses an item. It has a container with 9 inventory slots.") -horizontal_def._doc_items_usagehelp = S("Place the dispenser in one of 6 possible directions. The “hole” is where items will fly out of the dispenser. Use the dispenser to access its inventory. Insert the items you wish to dispense. Supply the dispenser with redstone energy once to dispense a random item.").."\n\n".. +horizontal_def._doc_items_usagehelp = S("Place the dispenser in one of 6 possible directions. The “hole” is where items will fly out of the dispenser. Use the dispenser to access its inventory. Insert the items you wish to dispense. Supply the dispenser with redstone energy once to dispense a random item.") + .. "\n\n" .. -S("The dispenser will do different things, depending on the dispensed item:").."\n\n".. + S("The dispenser will do different things, depending on the dispensed item:") .. "\n\n" .. -S("• Arrows: Are launched").."\n".. -S("• Eggs and snowballs: Are thrown").."\n".. -S("• Fire charges: Are fired in a straight line").."\n".. -S("• Armor: Will be equipped to players and armor stands").."\n".. -S("• Boats: Are placed on water or are dropped").."\n".. -S("• Minecart: Are placed on rails or are dropped").."\n".. -S("• Bone meal: Is applied on the block it is facing").."\n".. -S("• Empty buckets: Are used to collect a liquid source").."\n".. -S("• Filled buckets: Are used to place a liquid source").."\n".. -S("• Heads, pumpkins: Equipped to players and armor stands, or placed as a block").."\n".. -S("• Shulker boxes: Are placed as a block").."\n".. -S("• TNT: Is placed and ignited").."\n".. -S("• Flint and steel: Is used to ignite a fire in air and to ignite TNT").."\n".. -S("• Spawn eggs: Will summon the mob they contain").."\n".. -S("• Other items: Are simply dropped") + S("• Arrows: Are launched") .. "\n" .. + S("• Eggs and snowballs: Are thrown") .. "\n" .. + S("• Fire charges: Are fired in a straight line") .. "\n" .. + S("• Armor: Will be equipped to players and armor stands") .. "\n" .. + S("• Boats: Are placed on water or are dropped") .. "\n" .. + S("• Minecart: Are placed on rails or are dropped") .. "\n" .. + S("• Bone meal: Is applied on the block it is facing") .. "\n" .. + S("• Empty buckets: Are used to collect a liquid source") .. "\n" .. + S("• Filled buckets: Are used to place a liquid source") .. "\n" .. + S("• Heads, pumpkins: Equipped to players and armor stands, or placed as a block") .. "\n" .. + S("• Shulker boxes: Are placed as a block") .. "\n" .. + S("• TNT: Is placed and ignited") .. "\n" .. + S("• Flint and steel: Is used to ignite a fire in air and to ignite TNT") .. "\n" .. + S("• Spawn eggs: Will summon the mob they contain") .. "\n" .. + S("• Other items: Are simply dropped") function horizontal_def.after_place_node(pos, placer, itemstack, pointed_thing) setup_dispenser(pos) @@ -332,7 +347,7 @@ horizontal_def.tiles = { "default_furnace_side.png", "mcl_dispensers_dispenser_front_horizontal.png" } horizontal_def.paramtype2 = "facedir" -horizontal_def.groups = {pickaxey=1, container=2, material_stone=1} +horizontal_def.groups = { pickaxey = 1, container = 2, material_stone = 1 } minetest.register_node("mcl_dispensers:dispenser", horizontal_def) @@ -345,7 +360,7 @@ down_def.tiles = { "default_furnace_side.png", "default_furnace_side.png", "default_furnace_side.png", "default_furnace_side.png" } -down_def.groups = {pickaxey=1, container=2,not_in_creative_inventory=1, material_stone=1} +down_def.groups = { pickaxey = 1, container = 2, not_in_creative_inventory = 1, material_stone = 1 } down_def._doc_items_create_entry = false down_def.drop = "mcl_dispensers:dispenser" minetest.register_node("mcl_dispensers:dispenser_down", down_def) @@ -365,9 +380,9 @@ minetest.register_node("mcl_dispensers:dispenser_up", up_def) minetest.register_craft({ output = "mcl_dispensers:dispenser", recipe = { - {"mcl_core:cobble", "mcl_core:cobble", "mcl_core:cobble",}, - {"mcl_core:cobble", "mcl_bows:bow", "mcl_core:cobble",}, - {"mcl_core:cobble", "mesecons:redstone", "mcl_core:cobble",}, + { "mcl_core:cobble", "mcl_core:cobble", "mcl_core:cobble", }, + { "mcl_core:cobble", "mcl_bows:bow", "mcl_core:cobble", }, + { "mcl_core:cobble", "mesecons:redstone", "mcl_core:cobble", }, } }) @@ -384,6 +399,6 @@ minetest.register_lbm({ nodenames = { "mcl_dispensers:dispenser", "mcl_dispensers:dispenser_down", "mcl_dispensers:dispenser_up" }, action = function(pos, node) setup_dispenser(pos) - minetest.log("action", "[mcl_dispenser] Node formspec updated at "..minetest.pos_to_string(pos)) + minetest.log("action", "[mcl_dispenser] Node formspec updated at " .. minetest.pos_to_string(pos)) end, }) diff --git a/mods/ITEMS/REDSTONE/mcl_droppers/init.lua b/mods/ITEMS/REDSTONE/mcl_droppers/init.lua index 5f8f94d84..78a9a773b 100644 --- a/mods/ITEMS/REDSTONE/mcl_droppers/init.lua +++ b/mods/ITEMS/REDSTONE/mcl_droppers/init.lua @@ -9,23 +9,36 @@ are so many weird tables below. ]] local S = minetest.get_translator(minetest.get_current_modname()) +local C = minetest.colorize +local F = minetest.formspec_escape --- For after_place_node +local dropper_formspec = table.concat({ + "formspec_version[4]", + "size[11.75,10.425]", + + "label[4.125,0.375;" .. F(C(mcl_formspec.label_color, S("Dropper"))) .. "]", + + mcl_formspec.get_itemslot_bg_v4(4.125, 0.75, 3, 3), + "list[context;main;4.125,0.75;3,3;]", + + "label[0.375,4.7;" .. F(C(mcl_formspec.label_color, S("Inventory"))) .. "]", + + mcl_formspec.get_itemslot_bg_v4(0.375, 5.1, 9, 3), + "list[current_player;main;0.375,5.1;9,3;9]", + + mcl_formspec.get_itemslot_bg_v4(0.375, 9.05, 9, 1), + "list[current_player;main;0.375,9.05;9,1;]", + + "listring[context;main]", + "listring[current_player;main]", +}) + +---For after_place_node +---@param pos Vector local function setup_dropper(pos) -- Set formspec and inventory - local form = "size[9,8.75]".. - "label[0,4.0;"..minetest.formspec_escape(minetest.colorize("#313131", S("Inventory"))).."]".. - "list[current_player;main;0,4.5;9,3;9]".. - mcl_formspec.get_itemslot_bg(0,4.5,9,3).. - "list[current_player;main;0,7.74;9,1;]".. - mcl_formspec.get_itemslot_bg(0,7.74,9,1).. - "label[3,0;"..minetest.formspec_escape(minetest.colorize("#313131", S("Dropper"))).."]".. - "list[context;main;3,0.5;3,3;]".. - mcl_formspec.get_itemslot_bg(3,0.5,3,3).. - "listring[context;main]".. - "listring[current_player;main]" local meta = minetest.get_meta(pos) - meta:set_string("formspec", form) + meta:set_string("formspec", dropper_formspec) local inv = meta:get_inventory() inv:set_size("main", 9) end @@ -38,9 +51,9 @@ local function orientate_dropper(pos, placer) local pitch = placer:get_look_vertical() * (180 / math.pi) if pitch > 55 then - minetest.swap_node(pos, {name="mcl_droppers:dropper_up"}) + minetest.swap_node(pos, { name = "mcl_droppers:dropper_up" }) elseif pitch < -55 then - minetest.swap_node(pos, {name="mcl_droppers:dropper_down"}) + minetest.swap_node(pos, { name = "mcl_droppers:dropper_down" }) end end @@ -58,10 +71,10 @@ local dropperdef = { local meta2 = meta:to_table() meta:from_table(oldmetadata) local inv = meta:get_inventory() - for i=1, inv:get_size("main") do + for i = 1, inv:get_size("main") do local stack = inv:get_stack("main", i) if not stack:is_empty() then - local p = {x=pos.x+math.random(0, 10)/10-0.5, y=pos.y, z=pos.z+math.random(0, 10)/10-0.5} + local p = { x = pos.x + math.random(0, 10) / 10 - 0.5, y = pos.y, z = pos.z + math.random(0, 10) / 10 - 0.5 } minetest.add_item(p, stack) end end @@ -96,7 +109,7 @@ local dropperdef = { end, _mcl_blast_resistance = 3.5, _mcl_hardness = 3.5, - mesecons = {effector = { + mesecons = { effector = { -- Drop random item when triggered action_on = function(pos, node) if not pos then return end @@ -104,11 +117,11 @@ local dropperdef = { local inv = meta:get_inventory() local droppos if node.name == "mcl_droppers:dropper" then - droppos = vector.subtract(pos, minetest.facedir_to_dir(node.param2)) + droppos = vector.subtract(pos, minetest.facedir_to_dir(node.param2)) elseif node.name == "mcl_droppers:dropper_up" then - droppos = {x=pos.x, y=pos.y+1, z=pos.z} + droppos = { x = pos.x, y = pos.y + 1, z = pos.z } elseif node.name == "mcl_droppers:dropper_down" then - droppos = {x=pos.x, y=pos.y-1, z=pos.z} + droppos = { x = pos.x, y = pos.y - 1, z = pos.z } end local dropnode = minetest.get_node(droppos) -- Do not drop into solid nodes, unless they are containers @@ -117,10 +130,10 @@ local dropperdef = { return end local stacks = {} - for i=1,inv:get_size("main") do + for i = 1, inv:get_size("main") do local stack = inv:get_stack("main", i) if not stack:is_empty() then - table.insert(stacks, {stack = stack, stackpos = i}) + table.insert(stacks, { stack = stack, stackpos = i }) end end if #stacks >= 1 then @@ -144,14 +157,14 @@ local dropperdef = { local item_entity = minetest.add_item(droppos, dropitem) local drop_vel = vector.subtract(droppos, pos) local speed = 3 - item_entity:set_velocity(vector.multiply(drop_vel,speed)) + item_entity:set_velocity(vector.multiply(drop_vel, speed)) stack:take_item() inv:set_stack("main", stack_id, stack) end end end, rules = mesecon.rules.alldirs, - }}, + } }, on_rotate = on_rotate, } @@ -159,20 +172,21 @@ local dropperdef = { local horizontal_def = table.copy(dropperdef) horizontal_def.description = S("Dropper") -horizontal_def._tt_help = S("9 inventory slots").."\n"..S("Drops item when powered by redstone power") +horizontal_def._tt_help = S("9 inventory slots") .. "\n" .. S("Drops item when powered by redstone power") horizontal_def._doc_items_longdesc = S("A dropper is a redstone component and a container with 9 inventory slots which, when supplied with redstone power, drops an item or puts it into a container in front of it.") horizontal_def._doc_items_usagehelp = S("Droppers can be placed in 6 possible directions, items will be dropped out of the hole. Use the dropper to access its inventory. Supply it with redstone energy once to make the dropper drop or transfer a random item.") function horizontal_def.after_place_node(pos, placer, itemstack, pointed_thing) setup_dropper(pos) orientate_dropper(pos, placer) end + horizontal_def.tiles = { "default_furnace_top.png", "default_furnace_bottom.png", "default_furnace_side.png", "default_furnace_side.png", "default_furnace_side.png", "mcl_droppers_dropper_front_horizontal.png" } horizontal_def.paramtype2 = "facedir" -horizontal_def.groups = {pickaxey=1, container=2, material_stone=1} +horizontal_def.groups = { pickaxey = 1, container = 2, material_stone = 1 } minetest.register_node("mcl_droppers:dropper", horizontal_def) @@ -185,7 +199,7 @@ down_def.tiles = { "default_furnace_side.png", "default_furnace_side.png", "default_furnace_side.png", "default_furnace_side.png" } -down_def.groups = {pickaxey=1, container=2,not_in_creative_inventory=1, material_stone=1} +down_def.groups = { pickaxey = 1, container = 2, not_in_creative_inventory = 1, material_stone = 1 } down_def._doc_items_create_entry = false down_def.drop = "mcl_droppers:dropper" minetest.register_node("mcl_droppers:dropper_down", down_def) @@ -207,9 +221,9 @@ minetest.register_node("mcl_droppers:dropper_up", up_def) minetest.register_craft({ output = "mcl_droppers:dropper", recipe = { - {"mcl_core:cobble", "mcl_core:cobble", "mcl_core:cobble",}, - {"mcl_core:cobble", "", "mcl_core:cobble",}, - {"mcl_core:cobble", "mesecons:redstone", "mcl_core:cobble",}, + { "mcl_core:cobble", "mcl_core:cobble", "mcl_core:cobble", }, + { "mcl_core:cobble", "", "mcl_core:cobble", }, + { "mcl_core:cobble", "mesecons:redstone", "mcl_core:cobble", }, } }) @@ -226,6 +240,6 @@ minetest.register_lbm({ nodenames = { "mcl_droppers:dropper", "mcl_droppers:dropper_down", "mcl_droppers:dropper_up" }, action = function(pos, node) setup_dropper(pos) - minetest.log("action", "[mcl_droppers] Node formspec updated at "..minetest.pos_to_string(pos)) + minetest.log("action", "[mcl_droppers] Node formspec updated at " .. minetest.pos_to_string(pos)) end, }) From 842363464d77b5f8b13bfc637250a112cce9fb91 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Sat, 10 Sep 2022 13:44:12 +0200 Subject: [PATCH 34/82] Enchanting table formspec redo --- mods/ITEMS/mcl_enchanting/engine.lua | 158 ++++++++++++++++++--------- 1 file changed, 105 insertions(+), 53 deletions(-) diff --git a/mods/ITEMS/mcl_enchanting/engine.lua b/mods/ITEMS/mcl_enchanting/engine.lua index fa6dea353..57fde4dd5 100644 --- a/mods/ITEMS/mcl_enchanting/engine.lua +++ b/mods/ITEMS/mcl_enchanting/engine.lua @@ -2,7 +2,8 @@ local S = minetest.get_translator(minetest.get_current_modname()) local F = minetest.formspec_escape function mcl_enchanting.is_book(itemname) - return itemname == "mcl_books:book" or itemname == "mcl_enchanting:book_enchanted" or itemname == "mcl_books:book_enchanted" + return itemname == "mcl_books:book" or itemname == "mcl_enchanting:book_enchanted" or + itemname == "mcl_books:book_enchanted" end function mcl_enchanting.get_enchantments(itemstack) @@ -54,11 +55,13 @@ end function mcl_enchanting.get_enchantment_description(enchantment, level) local enchantment_def = mcl_enchanting.enchantments[enchantment] - return enchantment_def.name .. (enchantment_def.max_level == 1 and "" or " " .. mcl_enchanting.roman_numerals.toRoman(level)) + return enchantment_def.name .. + (enchantment_def.max_level == 1 and "" or " " .. mcl_enchanting.roman_numerals.toRoman(level)) end function mcl_enchanting.get_colorized_enchantment_description(enchantment, level) - return minetest.colorize(mcl_enchanting.enchantments[enchantment].curse and mcl_colors.RED or mcl_colors.GRAY, mcl_enchanting.get_enchantment_description(enchantment, level)) + return minetest.colorize(mcl_enchanting.enchantments[enchantment].curse and mcl_colors.RED or mcl_colors.GRAY, + mcl_enchanting.get_enchantment_description(enchantment, level)) end function mcl_enchanting.get_enchanted_itemstring(itemname) @@ -169,7 +172,9 @@ function mcl_enchanting.combine(itemstack, combine_with) local itemname = itemstack:get_name() local combine_name = combine_with:get_name() local enchanted_itemname = mcl_enchanting.get_enchanted_itemstring(itemname) - if not enchanted_itemname or enchanted_itemname ~= mcl_enchanting.get_enchanted_itemstring(combine_name) and not mcl_enchanting.is_book(combine_name) then + if not enchanted_itemname or + enchanted_itemname ~= mcl_enchanting.get_enchanted_itemstring(combine_name) and + not mcl_enchanting.is_book(combine_name) then return false end local enchantments = mcl_enchanting.get_enchantments(itemstack) @@ -219,7 +224,7 @@ function mcl_enchanting.enchantments_snippet(_, _, itemstack) local enchantments = mcl_enchanting.get_enchantments(itemstack) local text = "" for enchantment, level in pairs(enchantments) do - text = text .. mcl_enchanting.get_colorized_enchantment_description(enchantment, level) .. "\n" + text = text .. mcl_enchanting.get_colorized_enchantment_description(enchantment, level) .. "\n" end if text ~= "" then if not itemstack:get_definition()._tt_original_description then @@ -267,7 +272,7 @@ function mcl_enchanting.initialize() for itemname, itemdef in pairs(minetest.registered_items) do if mcl_enchanting.can_enchant_freshly(itemname) and not mcl_enchanting.is_book(itemname) then local new_name = itemname .. "_enchanted" - minetest.override_item(itemname, {_mcl_enchanting_enchanted_tool = new_name}) + minetest.override_item(itemname, { _mcl_enchanting_enchanted_tool = new_name }) local new_def = table.copy(itemdef) new_def.inventory_image = itemdef.inventory_image .. mcl_enchanting.overlay if new_def.wield_image then @@ -303,7 +308,7 @@ end function mcl_enchanting.random(pr, ...) local r = pr and pr:next(...) or math.random(...) - if pr and not ({...})[1] then + if pr and not ({ ... })[1] then r = r / 32767 end @@ -328,20 +333,24 @@ function mcl_enchanting.get_random_enchantment(itemstack, treasure, weighted, ex return #possible > 0 and possible[mcl_enchanting.random(pr, 1, #possible)] end -function mcl_enchanting.generate_random_enchantments(itemstack, enchantment_level, treasure, no_reduced_bonus_chance, ignore_already_enchanted, pr) +function mcl_enchanting.generate_random_enchantments(itemstack, enchantment_level, treasure, no_reduced_bonus_chance, + ignore_already_enchanted, pr) local itemname = itemstack:get_name() - if (not mcl_enchanting.can_enchant_freshly(itemname) and not ignore_already_enchanted) or mcl_enchanting.not_enchantable_on_enchanting_table(itemname) then + if (not mcl_enchanting.can_enchant_freshly(itemname) and not ignore_already_enchanted) or + mcl_enchanting.not_enchantable_on_enchanting_table(itemname) then return end itemstack = ItemStack(itemstack) local enchantability = minetest.get_item_group(itemname, "enchantability") - enchantability = 1 + mcl_enchanting.random(pr, 0, math.floor(enchantability / 4)) + mcl_enchanting.random(pr, 0, math.floor(enchantability / 4)) + enchantability = 1 + mcl_enchanting.random(pr, 0, math.floor(enchantability / 4)) + + mcl_enchanting.random(pr, 0, math.floor(enchantability / 4)) enchantment_level = enchantment_level + enchantability - enchantment_level = enchantment_level + enchantment_level * (mcl_enchanting.random(pr) + mcl_enchanting.random(pr) - 1) * 0.15 + enchantment_level = enchantment_level + + enchantment_level * (mcl_enchanting.random(pr) + mcl_enchanting.random(pr) - 1) * 0.15 enchantment_level = math.max(math.floor(enchantment_level + 0.5), 1) local enchantments = {} @@ -393,18 +402,22 @@ function mcl_enchanting.generate_random_enchantments(itemstack, enchantment_leve return enchantments, description end -function mcl_enchanting.generate_random_enchantments_reliable(itemstack, enchantment_level, treasure, no_reduced_bonus_chance, ignore_already_enchanted, pr) +function mcl_enchanting.generate_random_enchantments_reliable(itemstack, enchantment_level, treasure, + no_reduced_bonus_chance, ignore_already_enchanted, pr) local enchantments repeat - enchantments = mcl_enchanting.generate_random_enchantments(itemstack, enchantment_level, treasure, no_reduced_bonus_chance, ignore_already_enchanted, pr) + enchantments = mcl_enchanting.generate_random_enchantments(itemstack, enchantment_level, treasure, + no_reduced_bonus_chance, ignore_already_enchanted, pr) until enchantments return enchantments end -function mcl_enchanting.enchant_randomly(itemstack, enchantment_level, treasure, no_reduced_bonus_chance, ignore_already_enchanted, pr) - local enchantments = mcl_enchanting.generate_random_enchantments_reliable(itemstack, enchantment_level, treasure, no_reduced_bonus_chance, ignore_already_enchanted, pr) +function mcl_enchanting.enchant_randomly(itemstack, enchantment_level, treasure, no_reduced_bonus_chance, + ignore_already_enchanted, pr) + local enchantments = mcl_enchanting.generate_random_enchantments_reliable(itemstack, enchantment_level, treasure, + no_reduced_bonus_chance, ignore_already_enchanted, pr) mcl_enchanting.set_enchanted_itemstring(itemstack) mcl_enchanting.set_enchantments(itemstack, enchantments) @@ -416,7 +429,8 @@ function mcl_enchanting.enchant_uniform_randomly(stack, exclude, pr) local enchantment = mcl_enchanting.get_random_enchantment(stack, true, false, exclude, pr) if enchantment then - mcl_enchanting.enchant(stack, enchantment, mcl_enchanting.random(pr, 1, mcl_enchanting.enchantments[enchantment].max_level)) + mcl_enchanting.enchant(stack, enchantment, + mcl_enchanting.random(pr, 1, mcl_enchanting.enchantments[enchantment].max_level)) end return stack @@ -426,7 +440,8 @@ function mcl_enchanting.get_random_glyph_row() local glyphs = "" local x = 1.3 for i = 1, 9 do - glyphs = glyphs .. "image[".. x .. ",0.1;0.5,0.5;mcl_enchanting_glyph_" .. math.random(18) .. ".png^[colorize:#675D49:255]" + glyphs = glyphs .. + "image[" .. x .. ",0.1;0.5,0.5;mcl_enchanting_glyph_" .. math.random(18) .. ".png^[colorize:#675D49:255]" x = x + 0.6 end return glyphs @@ -459,7 +474,7 @@ end function mcl_enchanting.get_table_slots(player, itemstack, num_bookshelves) local itemname = itemstack:get_name() if (not mcl_enchanting.can_enchant_freshly(itemname)) or mcl_enchanting.not_enchantable_on_enchanting_table(itemname) then - return {false, false, false} + return { false, false, false } end local meta = player:get_meta() local player_slots = minetest.deserialize(meta:get_string("mcl_enchanting:slots")) or {} @@ -475,7 +490,7 @@ function mcl_enchanting.get_table_slots(player, itemstack, num_bookshelves) meta:set_string("mcl_enchanting:slots", minetest.serialize(player_slots)) return player_bookshelves_item_slots else - return {false, false, false} + return { false, false, false } end end end @@ -491,28 +506,37 @@ function mcl_enchanting.show_enchanting_formspec(player) local inv = player:get_inventory() local num_bookshelves = meta:get_int("mcl_enchanting:num_bookshelves") local table_name = meta:get_string("mcl_enchanting:table_name") - local formspec = "" - .. "size[9.07,8.6;]" - .. "formspec_version[3]" - .. "label[0,0;" .. C("#313131") .. F(table_name) .. "]" - .. mcl_formspec.get_itemslot_bg(0.2, 2.4, 1, 1) - .. "list[current_player;enchanting_item;0.2,2.4;1,1]" - .. mcl_formspec.get_itemslot_bg(1.1, 2.4, 1, 1) - .. "image[1.1,2.4;1,1;mcl_enchanting_lapis_background.png]" - .. "list[current_player;enchanting_lapis;1.1,2.4;1,1]" - .. "label[0,4;" .. C("#313131") .. F(S("Inventory")).."]" - .. mcl_formspec.get_itemslot_bg(0, 4.5, 9, 3) - .. mcl_formspec.get_itemslot_bg(0, 7.74, 9, 1) - .. "list[current_player;main;0,4.5;9,3;9]" - .. "listring[current_player;enchanting_item]" - .. "listring[current_player;main]" - .. "listring[current_player;enchanting]" - .. "listring[current_player;main]" - .. "listring[current_player;enchanting_lapis]" - .. "listring[current_player;main]" - .. "list[current_player;main;0,7.74;9,1;]" - .. "real_coordinates[true]" - .. "image[3.15,0.6;7.6,4.1;mcl_enchanting_button_background.png]" + + local formspec = table.concat({ + "formspec_version[4]", + "size[11.75,10.425]", + + "label[0.375,0.375;" .. F(C(mcl_formspec.label_color) .. table_name) .. "]", + + mcl_formspec.get_itemslot_bg_v4(1, 3.25, 1, 1), + "list[current_player;enchanting_item;1,3.25;1,1]", + mcl_formspec.get_itemslot_bg_v4(2.25, 3.25, 1, 1), + "list[current_player;enchanting_lapis;2.25,3.25;1,1]", + "image[2.25,2.4;1,1;mcl_enchanting_lapis_background.png]", + + "image[4.125,0.375;7.25,4.1;mcl_enchanting_button_background.png]", + + "label[0.375,4.7;" .. F(C(mcl_formspec.label_color) .. S("Inventory")) .. "]", + + mcl_formspec.get_itemslot_bg_v4(0.375, 5.1, 9, 3), + "list[current_player;main;0.375,5.1;9,3;9]", + + mcl_formspec.get_itemslot_bg_v4(0.375, 9.05, 9, 1), + "list[current_player;main;0.375,9.05;9,1;]", + + "listring[current_player;enchanting_item]", + "listring[current_player;main]", + "listring[current_player;enchanting]", + "listring[current_player;main]", + "listring[current_player;enchanting_lapis]", + "listring[current_player;main]", + }) + local itemstack = inv:get_stack("enchanting_item", 1) local player_levels = mcl_experience.get_level(player) local y = 0.65 @@ -526,18 +550,43 @@ function mcl_enchanting.show_enchanting_formspec(player) local ending = (can_enchant and "" or "_off") local hover_ending = (can_enchant and "_hovered" or "_off") formspec = formspec - .. "container[3.2," .. y .. "]" - .. (slot and "tooltip[button_" .. i .. ";" .. C("#818181") .. ((slot.description and F(slot.description)) or "") .. " " .. C("#FFFFFF") .. " . . . ?\n\n" .. (enough_levels and C(enough_lapis and "#818181" or "#FC5454") .. F(S("@1 Lapis Lazuli", i)) .. "\n" .. C("#818181") .. F(S("@1 Enchantment Levels", i)) or C("#FC5454") .. F(S("Level requirement: @1", slot.level_requirement))) .. "]" or "") - .. "style[button_" .. i .. ";bgimg=mcl_enchanting_button" .. ending .. ".png;bgimg_hovered=mcl_enchanting_button" .. hover_ending .. ".png;bgimg_pressed=mcl_enchanting_button" .. hover_ending .. ".png]" + .. "container[4.125," .. y .. "]" + .. + ( + slot and + "tooltip[button_" .. + i .. + ";" .. + C("#818181") .. + ((slot.description and F(slot.description)) or "") .. + " " .. + C("#FFFFFF") .. + " . . . ?\n\n" .. + ( + enough_levels and + C(enough_lapis and "#818181" or "#FC5454") .. + F(S("@1 Lapis Lazuli", i)) .. "\n" .. C("#818181") .. F(S("@1 Enchantment Levels", i)) or + C("#FC5454") .. F(S("Level requirement: @1", slot.level_requirement))) .. "]" or "") + .. + "style[button_" .. + i .. + ";bgimg=mcl_enchanting_button" .. + ending .. + ".png;bgimg_hovered=mcl_enchanting_button" .. + hover_ending .. ".png;bgimg_pressed=mcl_enchanting_button" .. hover_ending .. ".png]" .. "button[0,0;7.5,1.3;button_" .. i .. ";]" .. (slot and "image[0,0;1.3,1.3;mcl_enchanting_number_" .. i .. ending .. ".png]" or "") - .. (slot and "label[7.2,1.1;" .. C(can_enchant and "#80FF20" or "#407F10") .. slot.level_requirement .. "]" or "") + .. (slot and "label[6.8,1;" .. C(can_enchant and "#80FF20" or "#407F10") .. slot.level_requirement .. "]" or "") .. (slot and slot.glyphs or "") .. "container_end[]" - y = y + 1.35 + y = y + 1.3 end formspec = formspec - .. "image[" .. (any_enchantment and 0.58 or 1.15) .. ",1.2;" .. (any_enchantment and 2 or 0.87) .. ",1.43;mcl_enchanting_book_" .. (any_enchantment and "open" or "closed") .. ".png]" + .. + "image[" .. + (any_enchantment and 1.1 or 1.67) .. + ",1.2;" .. + (any_enchantment and 2 or 0.87) .. ",1.43;mcl_enchanting_book_" .. (any_enchantment and "open" or "closed") .. ".png]" minetest.show_formspec(name, "mcl_enchanting:table", formspec) end @@ -573,7 +622,7 @@ function mcl_enchanting.handle_formspec_fields(player, formname, fields) mcl_enchanting.set_enchanted_itemstring(itemstack) mcl_enchanting.set_enchantments(itemstack, slot.enchantments) inv:set_stack("enchanting_item", 1, itemstack) - minetest.sound_play("mcl_enchanting_enchant", {to_player = name, gain = 5.0}) + minetest.sound_play("mcl_enchanting_enchant", { to_player = name, gain = 5.0 }) mcl_enchanting.reset_table_slots(player) mcl_enchanting.show_enchanting_formspec(player) awards.unlock(player:get_player_name(), "mcl:enchanter") @@ -645,13 +694,16 @@ function mcl_enchanting.on_inventory_action(player, action, inventory, inventory end function mcl_enchanting.schedule_book_animation(self, anim) - self.scheduled_anim = {timer = self.anim_length, anim = anim} + self.scheduled_anim = { timer = self.anim_length, anim = anim } end function mcl_enchanting.set_book_animation(self, anim) local anim_index = mcl_enchanting.book_animations[anim] - local start, stop = mcl_enchanting.book_animation_steps[anim_index], mcl_enchanting.book_animation_steps[anim_index + 1] - self.object:set_animation({x = start, y = stop}, mcl_enchanting.book_animation_speed, 0, mcl_enchanting.book_animation_loop[anim] or false) + local start, stop = mcl_enchanting.book_animation_steps[anim_index], + mcl_enchanting.book_animation_steps[anim_index + 1 + ] + self.object:set_animation({ x = start, y = stop }, mcl_enchanting.book_animation_speed, 0, + mcl_enchanting.book_animation_loop[anim] or false) self.scheduled_anim = nil self.anim_length = (stop - start) / 40 end @@ -661,7 +713,7 @@ function mcl_enchanting.check_animation_schedule(self, dtime) if schedanim then schedanim.timer = schedanim.timer - dtime if schedanim.timer <= 0 then - mcl_enchanting.set_book_animation(self, schedanim.anim) + mcl_enchanting.set_book_animation(self, schedanim.anim) end end end @@ -669,7 +721,7 @@ end function mcl_enchanting.look_at(self, pos2) local pos1 = self.object:get_pos() local vec = vector.subtract(pos1, pos2) - local yaw = math.atan(vec.z / vec.x) - math.pi/2 + local yaw = math.atan(vec.z / vec.x) - math.pi / 2 yaw = yaw + (pos1.x >= pos2.x and math.pi or 0) self.object:set_yaw(yaw + math.pi) end From e5ee0c4afc618c4989e2d86a3aa7bd51acef6714 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Sat, 10 Sep 2022 14:14:12 +0200 Subject: [PATCH 35/82] Crafting table formspec redo --- mods/ITEMS/mcl_crafting_table/init.lua | 79 ++++++++++++++++---------- 1 file changed, 48 insertions(+), 31 deletions(-) diff --git a/mods/ITEMS/mcl_crafting_table/init.lua b/mods/ITEMS/mcl_crafting_table/init.lua index 7f6b9ccc5..2f114362d 100644 --- a/mods/ITEMS/mcl_crafting_table/init.lua +++ b/mods/ITEMS/mcl_crafting_table/init.lua @@ -1,34 +1,51 @@ +---@diagnostic disable lowercase-global + local S = minetest.get_translator(minetest.get_current_modname()) -local formspec_escape = minetest.formspec_escape -local show_formspec = minetest.show_formspec +local F = minetest.formspec_escape local C = minetest.colorize -local text_color = "#313131" -local itemslot_bg = mcl_formspec.get_itemslot_bg +local show_formspec = minetest.show_formspec mcl_crafting_table = {} -function mcl_crafting_table.show_crafting_form(player) - player:get_inventory():set_width("craft", 3) - player:get_inventory():set_size("craft", 9) +mcl_crafting_table.formspec = table.concat({ + "formspec_version[4]", + "size[11.75,10.425]", - show_formspec(player:get_player_name(), "main", - "size[9,8.75]".. - "image[4.7,1.5;1.5,1;gui_crafting_arrow.png]".. - "label[0,4;"..formspec_escape(C(text_color, S("Inventory"))).."]".. - "list[current_player;main;0,4.5;9,3;9]".. - itemslot_bg(0,4.5,9,3).. - "list[current_player;main;0,7.74;9,1;]".. - itemslot_bg(0,7.74,9,1).. - "label[1.75,0;"..formspec_escape(C(text_color, S("Crafting"))).."]".. - "list[current_player;craft;1.75,0.5;3,3;]".. - itemslot_bg(1.75,0.5,3,3).. - "list[current_player;craftpreview;6.1,1.5;1,1;]".. - itemslot_bg(6.1,1.5,1,1).. - "image_button[0.75,1.5;1,1;craftguide_book.png;__mcl_craftguide;]".. - "tooltip[__mcl_craftguide;"..formspec_escape(S("Recipe book")).."]".. - "listring[current_player;main]".. - "listring[current_player;craft]" - ) + "label[2.25,0.375;" .. F(C(mcl_formspec.label_color, S("Crafting"))) .. "]", + + mcl_formspec.get_itemslot_bg_v4(2.25, 0.75, 3, 3), + "list[current_player;craft;2.25,0.75;3,3;]", + + "image[6.125,2;1.5,1;gui_crafting_arrow.png]", + + mcl_formspec.get_itemslot_bg_v4(8.2, 2, 1, 1, 0.2), + "list[current_player;craftpreview;8.2,2;1,1;]", + + "label[0.375,4.7;" .. F(C(mcl_formspec.label_color, S("Inventory"))) .. "]", + + mcl_formspec.get_itemslot_bg_v4(0.375, 5.1, 9, 3), + "list[current_player;main;0.375,5.1;9,3;9]", + + mcl_formspec.get_itemslot_bg_v4(0.375, 9.05, 9, 1), + "list[current_player;main;0.375,9.05;9,1;]", + + "listring[current_player;craft]", + "listring[current_player;main]", + + --Crafting guide button + "image_button[0.325,1.95;1.1,1.1;craftguide_book.png;__mcl_craftguide;]", + "tooltip[__mcl_craftguide;" .. F(S("Recipe book")) .. "]", +}) + +---@param player ObjectRef +function mcl_crafting_table.show_crafting_form(player) + local inv = player:get_inventory() + if inv then + inv:set_width("craft", 3) + inv:set_size("craft", 9) + end + + show_formspec(player:get_player_name(), "main", mcl_crafting_table.formspec) end minetest.register_node("mcl_crafting_table:crafting_table", { @@ -38,10 +55,10 @@ minetest.register_node("mcl_crafting_table:crafting_table", { _doc_items_usagehelp = S("Rightclick the crafting table to access the 3×3 crafting grid."), _doc_items_hidden = false, is_ground_content = false, - tiles = {"crafting_workbench_top.png", "default_wood.png", "crafting_workbench_side.png", - "crafting_workbench_side.png", "crafting_workbench_front.png", "crafting_workbench_front.png"}, + tiles = { "crafting_workbench_top.png", "default_wood.png", "crafting_workbench_side.png", + "crafting_workbench_side.png", "crafting_workbench_front.png", "crafting_workbench_front.png" }, paramtype2 = "facedir", - groups = {handy=1,axey=1, deco_block=1, material_wood=1,flammable=-1}, + groups = { handy = 1, axey = 1, deco_block = 1, material_wood = 1, flammable = -1 }, on_rightclick = function(pos, node, player, itemstack) if not player:get_player_control().sneak then mcl_crafting_table.show_crafting_form(player) @@ -55,9 +72,9 @@ minetest.register_node("mcl_crafting_table:crafting_table", { minetest.register_craft({ output = "mcl_crafting_table:crafting_table", recipe = { - {"group:wood", "group:wood"}, - {"group:wood", "group:wood"} - } + { "group:wood", "group:wood" }, + { "group:wood", "group:wood" } + }, }) minetest.register_craft({ From 0ae76776b1e6b20b8b6bb523ef8d50fff053cc3e Mon Sep 17 00:00:00 2001 From: AFCMS Date: Sat, 10 Sep 2022 14:28:26 +0200 Subject: [PATCH 36/82] Bookshelf menu redo --- mods/ITEMS/mcl_books/init.lua | 142 ++++++++++++++++++---------------- 1 file changed, 77 insertions(+), 65 deletions(-) diff --git a/mods/ITEMS/mcl_books/init.lua b/mods/ITEMS/mcl_books/init.lua index af84feb66..e8c53ed8a 100644 --- a/mods/ITEMS/mcl_books/init.lua +++ b/mods/ITEMS/mcl_books/init.lua @@ -5,7 +5,7 @@ local C = minetest.colorize local max_text_length = 4500 -- TODO: Increase to 12800 when scroll bar was added to written book local max_title_length = 64 -local bookshelf_inv = minetest.settings:get_bool("mcl_bookshelf_inventories",true) +local bookshelf_inv = minetest.settings:get_bool("mcl_bookshelf_inventories", true) local header = "" if minetest.get_modpath("mcl_init") then @@ -19,7 +19,7 @@ minetest.register_craftitem("mcl_books:book", { _doc_items_longdesc = S("Books are used to make bookshelves and book and quills."), inventory_image = "default_book.png", stack_max = 64, - groups = { book=1, craftitem = 1, enchantability = 1 }, + groups = { book = 1, craftitem = 1, enchantability = 1 }, _mcl_enchanting_enchanted_tool = "mcl_enchanting:book_enchanted", }) @@ -91,12 +91,12 @@ local function write(itemstack, user, pointed_thing) end local text = get_text(itemstack) - local formspec = "size[8,9]".. - header.. - "background[-0.5,-0.5;9,10;mcl_books_book_bg.png]".. - "textarea[0.75,0.1;7.25,9;text;;"..minetest.formspec_escape(text).."]".. - "button[0.75,7.95;3,1;sign;"..minetest.formspec_escape(S("Sign")).."]".. - "button_exit[4.25,7.95;3,1;ok;"..minetest.formspec_escape(S("Done")).."]" + local formspec = "size[8,9]" .. + header .. + "background[-0.5,-0.5;9,10;mcl_books_book_bg.png]" .. + "textarea[0.75,0.1;7.25,9;text;;" .. minetest.formspec_escape(text) .. "]" .. + "button[0.75,7.95;3,1;sign;" .. minetest.formspec_escape(S("Sign")) .. "]" .. + "button_exit[4.25,7.95;3,1;ok;" .. minetest.formspec_escape(S("Done")) .. "]" minetest.show_formspec(user:get_player_name(), "mcl_books:writable_book", formspec) end @@ -112,11 +112,11 @@ local function read(itemstack, user, pointed_thing) end local text = get_text(itemstack) - local formspec = "size[8,9]".. - header.. - "background[-0.5,-0.5;9,10;mcl_books_book_bg.png]".. - "textarea[0.75,0.1;7.25,9;;"..minetest.formspec_escape(text)..";]".. - "button_exit[2.25,7.95;3,1;ok;"..minetest.formspec_escape(S("Done")).."]" + local formspec = "size[8,9]" .. + header .. + "background[-0.5,-0.5;9,10;mcl_books_book_bg.png]" .. + "textarea[0.75,0.1;7.25,9;;" .. minetest.formspec_escape(text) .. ";]" .. + "button_exit[2.25,7.95;3,1;ok;" .. minetest.formspec_escape(S("Done")) .. "]" minetest.show_formspec(user:get_player_name(), "mcl_books:written_book", formspec) end @@ -125,16 +125,17 @@ minetest.register_craftitem("mcl_books:writable_book", { description = S("Book and Quill"), _tt_help = S("Write down some notes"), _doc_items_longdesc = S("This item can be used to write down some notes."), - _doc_items_usagehelp = S("Hold it in the hand, then rightclick to read the current notes and edit then. You can edit the text as often as you like. You can also sign the book which turns it into a written book which you can stack, but it can't be edited anymore.").."\n".. - S("A book can hold up to 4500 characters. The title length is limited to 64 characters."), + _doc_items_usagehelp = S("Hold it in the hand, then rightclick to read the current notes and edit then. You can edit the text as often as you like. You can also sign the book which turns it into a written book which you can stack, but it can't be edited anymore.") + .. "\n" .. + S("A book can hold up to 4500 characters. The title length is limited to 64 characters."), inventory_image = "mcl_books_book_writable.png", - groups = { book=1 }, + groups = { book = 1 }, stack_max = 1, on_place = write, on_secondary_use = write, }) -minetest.register_on_player_receive_fields(function ( player, formname, fields ) +minetest.register_on_player_receive_fields(function(player, formname, fields) if ((formname == "mcl_books:writable_book") and fields and fields.text) then local stack = player:get_wielded_item() if (stack:get_name() and (stack:get_name() == "mcl_books:writable_book")) then @@ -148,14 +149,16 @@ minetest.register_on_player_receive_fields(function ( player, formname, fields ) player:set_wielded_item(stack) local name = player:get_player_name() - local formspec = "size[8,9]".. - header.. - "background[-0.5,-0.5;9,10;mcl_books_book_bg.png]".. - "field[0.75,1;7.25,1;title;"..minetest.formspec_escape(minetest.colorize("#000000", S("Enter book title:")))..";]".. - "label[0.75,1.5;"..minetest.formspec_escape(minetest.colorize("#404040", S("by @1", name))).."]".. - "button_exit[0.75,7.95;3,1;sign;"..minetest.formspec_escape(S("Sign and Close")).."]".. - "tooltip[sign;"..minetest.formspec_escape(S("Note: The book will no longer be editable after signing")).."]".. - "button[4.25,7.95;3,1;cancel;"..minetest.formspec_escape(S("Cancel")).."]" + local formspec = "size[8,9]" .. + header .. + "background[-0.5,-0.5;9,10;mcl_books_book_bg.png]" .. + "field[0.75,1;7.25,1;title;" .. + minetest.formspec_escape(minetest.colorize("#000000", S("Enter book title:"))) .. ";]" .. + "label[0.75,1.5;" .. minetest.formspec_escape(minetest.colorize("#404040", S("by @1", name))) .. "]" .. + "button_exit[0.75,7.95;3,1;sign;" .. minetest.formspec_escape(S("Sign and Close")) .. "]" .. + "tooltip[sign;" .. + minetest.formspec_escape(S("Note: The book will no longer be editable after signing")) .. "]" .. + "button[4.25,7.95;3,1;cancel;" .. minetest.formspec_escape(S("Cancel")) .. "]" minetest.show_formspec(player:get_player_name(), "mcl_books:signing", formspec) end end @@ -181,7 +184,7 @@ minetest.register_on_player_receive_fields(function ( player, formname, fields ) player:set_wielded_item(newbook) else - minetest.log("error", "[mcl_books] "..name.." failed to sign a book!") + minetest.log("error", "[mcl_books] " .. name .. " failed to sign a book!") end elseif ((formname == "mcl_books:signing") and fields and fields.cancel) then local book = player:get_wielded_item() @@ -203,11 +206,11 @@ end minetest.register_craftitem("mcl_books:written_book", { description = S("Written Book"), _doc_items_longdesc = S("Written books contain some text written by someone. They can be read and copied, but not edited."), - _doc_items_usagehelp = S("Hold it in your hand, then rightclick to read the book.").."\n\n".. + _doc_items_usagehelp = S("Hold it in your hand, then rightclick to read the book.") .. "\n\n" .. -S("To copy the text of the written book, place it into the crafting grid together with a book and quill (or multiple of those) and craft. The written book will not be consumed. Copies of copies can not be copied."), + S("To copy the text of the written book, place it into the crafting grid together with a book and quill (or multiple of those) and craft. The written book will not be consumed. Copies of copies can not be copied."), inventory_image = "mcl_books_book_written.png", - groups = { not_in_creative_inventory=1, book=1, no_rename=1 }, + groups = { not_in_creative_inventory = 1, book = 1, no_rename = 1 }, stack_max = 16, on_place = read, on_secondary_use = read @@ -219,19 +222,19 @@ S("To copy the text of the written book, place it into the crafting grid togethe local baq = "mcl_books:writable_book" local wb = "mcl_books:written_book" local recipes = { - {wb, baq}, - {baq, baq, wb}, - {baq, baq, wb, baq}, - {baq, baq, baq, baq, wb}, - {baq, baq, baq, baq, wb, baq}, - {baq, baq, baq, baq, wb, baq, baq}, - {baq, baq, baq, baq, wb, baq, baq, baq}, - {baq, baq, baq, baq, wb, baq, baq, baq, baq}, + { wb, baq }, + { baq, baq, wb }, + { baq, baq, wb, baq }, + { baq, baq, baq, baq, wb }, + { baq, baq, baq, baq, wb, baq }, + { baq, baq, baq, baq, wb, baq, baq }, + { baq, baq, baq, baq, wb, baq, baq, baq }, + { baq, baq, baq, baq, wb, baq, baq, baq, baq }, } -for r=#recipes, 1, -1 do +for r = #recipes, 1, -1 do minetest.register_craft({ type = "shapeless", - output = "mcl_books:written_book "..r, + output = "mcl_books:written_book " .. r, recipe = recipes[r], }) end @@ -367,6 +370,9 @@ local function protection_check_put_take(pos, listname, index, stack, player) end end +---@param pos Vector +---@param node node +---@param clicker ObjectRef local function bookshelf_gui(pos, node, clicker) if not bookshelf_inv then return end local name = minetest.get_meta(pos):get_string("name") @@ -378,18 +384,25 @@ local function bookshelf_gui(pos, node, clicker) local playername = clicker:get_player_name() minetest.show_formspec(playername, - "mcl_books:bookshelf_"..pos.x.."_"..pos.y.."_"..pos.z, + "mcl_books:bookshelf_" .. pos.x .. "_" .. pos.y .. "_" .. pos.z, table.concat({ - "size[9,8.75]", - "label[0,0;"..F(C("#313131", name)).."]", - "list[nodemeta:"..pos.x..","..pos.y..","..pos.z..";main;0,0.5;9,3;]", - mcl_formspec.get_itemslot_bg(0, 0.5, 9, 3), - "label[0,4.0;"..F(C("#313131", S("Inventory"))).."]", - "list[current_player;main;0,4.5;9,3;9]", - mcl_formspec.get_itemslot_bg(0, 4.5, 9, 3), - "list[current_player;main;0,7.74;9,1;]", - mcl_formspec.get_itemslot_bg(0, 7.74, 9, 1), - "listring[nodemeta:"..pos.x..","..pos.y..","..pos.z..";main]", + "formspec_version[4]", + "size[11.75,10.425]", + + "label[0.375,0.375;" .. F(C(mcl_formspec.label_color, name)) .. "]", + + mcl_formspec.get_itemslot_bg_v4(0.375, 0.75, 9, 3), + "list[nodemeta:" .. pos.x .. "," .. pos.y .. "," .. pos.z .. ";main;0.375,0.75;9,3;]", + + "label[0.375,4.7;" .. F(C(mcl_formspec.label_color, S("Inventory"))) .. "]", + + mcl_formspec.get_itemslot_bg_v4(0.375, 5.1, 9, 3), + "list[current_player;main;0.375,5.1;9,3;9]", + + mcl_formspec.get_itemslot_bg_v4(0.375, 9.05, 9, 1), + "list[current_player;main;0.375,9.05;9,1;]", + + "listring[nodemeta:" .. pos.x .. "," .. pos.y .. "," .. pos.z .. ";main]", "listring[current_player;main]", }) ) @@ -397,7 +410,7 @@ end local function close_forms(pos) local players = minetest.get_connected_players() - local formname = "mcl_books:bookshelf_"..pos.x.."_"..pos.y.."_"..pos.z + local formname = "mcl_books:bookshelf_" .. pos.x .. "_" .. pos.y .. "_" .. pos.z for p = 1, #players do if vector.distance(players[p]:get_pos(), pos) <= 30 then minetest.close_formspec(players[p]:get_player_name(), formname) @@ -409,12 +422,12 @@ end minetest.register_node("mcl_books:bookshelf", { description = S("Bookshelf"), _doc_items_longdesc = S("Bookshelves are used for decoration."), - tiles = {"mcl_books_bookshelf_top.png", "mcl_books_bookshelf_top.png", "default_bookshelf.png"}, + tiles = { "mcl_books_bookshelf_top.png", "mcl_books_bookshelf_top.png", "default_bookshelf.png" }, stack_max = 64, is_ground_content = false, groups = { - handy=1, axey=1, deco_block=1, material_wood=1, - flammable=3, fire_encouragement=30, fire_flammability=20, container=1 + handy = 1, axey = 1, deco_block = 1, material_wood = 1, + flammable = 3, fire_encouragement = 30, fire_flammability = 20, container = 1 }, drop = "mcl_books:book 3", sounds = wood_sound, @@ -424,7 +437,7 @@ minetest.register_node("mcl_books:bookshelf", { on_construct = function(pos) local meta = minetest.get_meta(pos) local inv = meta:get_inventory() - inv:set_size("main", 9*3) + inv:set_size("main", 9 * 3) end, after_place_node = function(pos, placer, itemstack, pointed_thing) minetest.get_meta(pos):set_string("name", itemstack:get_meta():get_string("name")) @@ -433,16 +446,16 @@ minetest.register_node("mcl_books:bookshelf", { allow_metadata_inventory_take = protection_check_put_take, allow_metadata_inventory_put = protection_check_put_take, on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) - minetest.log("action", player:get_player_name().. - " moves stuff in bookshelf at "..minetest.pos_to_string(pos)) + minetest.log("action", player:get_player_name() .. + " moves stuff in bookshelf at " .. minetest.pos_to_string(pos)) end, on_metadata_inventory_put = function(pos, listname, index, stack, player) - minetest.log("action", player:get_player_name().. - " moves stuff to bookshelf at "..minetest.pos_to_string(pos)) + minetest.log("action", player:get_player_name() .. + " moves stuff to bookshelf at " .. minetest.pos_to_string(pos)) end, on_metadata_inventory_take = function(pos, listname, index, stack, player) - minetest.log("action", player:get_player_name().. - " takes stuff from bookshelf at "..minetest.pos_to_string(pos)) + minetest.log("action", player:get_player_name() .. + " takes stuff from bookshelf at " .. minetest.pos_to_string(pos)) end, after_dig_node = drop_content, on_blast = on_blast, @@ -453,9 +466,9 @@ minetest.register_node("mcl_books:bookshelf", { minetest.register_craft({ output = "mcl_books:bookshelf", recipe = { - {"group:wood", "group:wood", "group:wood"}, - {"mcl_books:book", "mcl_books:book", "mcl_books:book"}, - {"group:wood", "group:wood", "group:wood"}, + { "group:wood", "group:wood", "group:wood" }, + { "mcl_books:book", "mcl_books:book", "mcl_books:book" }, + { "group:wood", "group:wood", "group:wood" }, } }) @@ -464,4 +477,3 @@ minetest.register_craft({ recipe = "mcl_books:bookshelf", burntime = 15, }) - From 0da1822d26c209ed57b3145f18e0320ae8b7315f Mon Sep 17 00:00:00 2001 From: AFCMS Date: Sat, 10 Sep 2022 18:32:37 +0200 Subject: [PATCH 37/82] Code style fixes in mcl_chests --- mods/ITEMS/mcl_chests/init.lua | 45 +++++++++++++++++----------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/mods/ITEMS/mcl_chests/init.lua b/mods/ITEMS/mcl_chests/init.lua index fb4850759..8158b0a32 100644 --- a/mods/ITEMS/mcl_chests/init.lua +++ b/mods/ITEMS/mcl_chests/init.lua @@ -96,7 +96,8 @@ minetest.register_entity("mcl_chests:chest", { return end self:set_animation("close") - minetest.sound_play(self.sound_prefix .. "_close", { pos = self.node_pos, gain = 0.3, max_hear_distance = 16 }, + minetest.sound_play(self.sound_prefix .. "_close", + { pos = self.node_pos, gain = 0.3, max_hear_distance = 16 }, true) self.is_open = false end @@ -148,7 +149,8 @@ minetest.register_entity("mcl_chests:chest", { }) local function get_entity_pos(pos, dir, double) - pos = vector.new(pos) + pos = vector.copy(pos) + pos.y = pos.y - 0.49 if double then local add, mul, vec, cross = vector.add, vector.multiply, vector.new, vector.cross pos = add(pos, mul(cross(dir, vec(0, 1, 0)), -0.5)) @@ -398,10 +400,9 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile drawtype = "mesh", mesh = "mcl_chests_chest.b3d", tiles = small_textures, - use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "opaque" or false, + use_texture_alpha = "opaque", paramtype = "light", paramtype2 = "facedir", - stack_max = 64, sounds = mcl_sounds.node_sound_wood_defaults(), groups = { deco_block = 1 }, on_construct = function(pos, node) @@ -436,14 +437,13 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile fixed = { -0.4375, -0.5, -0.4375, 0.4375, 0.375, 0.4375 }, }, tiles = { "blank.png^[resize:16x16" }, - use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "clip" or true, + use_texture_alpha = "clip", _chest_entity_textures = small_textures, _chest_entity_sound = "default_chest", _chest_entity_mesh = "mcl_chests_chest", _chest_entity_animation_type = "chest", paramtype = "light", paramtype2 = "facedir", - stack_max = 64, drop = drop, groups = { handy = 1, @@ -585,7 +585,7 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile fixed = { -0.4375, -0.5, -0.4375, 0.5, 0.375, 0.4375 }, }, tiles = { "blank.png^[resize:16x16" }, - use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "clip" or true, + use_texture_alpha = "clip", _chest_entity_textures = left_textures, _chest_entity_sound = "default_chest", _chest_entity_mesh = "mcl_chests_chest", @@ -761,7 +761,7 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile fixed = { -0.5, -0.5, -0.4375, 0.4375, 0.375, 0.4375 }, }, tiles = { "blank.png^[resize:16x16" }, - use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "clip" or true, + use_texture_alpha = "clip", groups = { handy = 1, axey = 1, @@ -930,7 +930,7 @@ local chestusage = S("To access its inventory, rightclick it. When broken, the i register_chest("chest", S("Chest"), S( - "Chests are containers which provide 27 inventory slots. Chests can be turned into large chests with double the capacity by placing two chests next to each other.") + "Chests are containers which provide 27 inventory slots. Chests can be turned into large chests with double the capacity by placing two chests next to each other.") , chestusage, S("27 inventory slots") .. "\n" .. S("Can be combined to a large chest"), @@ -958,7 +958,7 @@ local traptiles = { register_chest("trapped_chest", S("Trapped Chest"), S( - "A trapped chest is a container which provides 27 inventory slots. When it is opened, it sends a redstone signal to its adjacent blocks as long it stays open. Trapped chests can be turned into large trapped chests with double the capacity by placing two trapped chests next to each other.") + "A trapped chest is a container which provides 27 inventory slots. When it is opened, it sends a redstone signal to its adjacent blocks as long it stays open. Trapped chests can be turned into large trapped chests with double the capacity by placing two trapped chests next to each other.") , chestusage, S("27 inventory slots") .. @@ -1086,20 +1086,19 @@ minetest.register_craft({ minetest.register_node("mcl_chests:ender_chest", { description = S("Ender Chest"), _tt_help = S("27 interdimensional inventory slots") .. - "\n" .. S("Put items inside, retrieve them from any ender chest"), + "\n" .. S("Put items inside, retrieve them from any ender chest"), _doc_items_longdesc = S( - "Ender chests grant you access to a single personal interdimensional inventory with 27 slots. This inventory is the same no matter from which ender chest you access it from. If you put one item into one ender chest, you will find it in all other ender chests. Each player will only see their own items, but not the items of other players."), + "Ender chests grant you access to a single personal interdimensional inventory with 27 slots. This inventory is the same no matter from which ender chest you access it from. If you put one item into one ender chest, you will find it in all other ender chests. Each player will only see their own items, but not the items of other players."), _doc_items_usagehelp = S("Rightclick the ender chest to access your personal interdimensional inventory."), drawtype = "mesh", mesh = "mcl_chests_chest.b3d", tiles = tiles_chest_ender_small, - use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "opaque" or false, + use_texture_alpha = "opaque", paramtype = "light", paramtype2 = "facedir", - stack_max = 64, groups = { deco_block = 1 }, sounds = mcl_sounds.node_sound_stone_defaults(), - on_construct = function(pos, node) + on_construct = function(pos) local node = minetest.get_node(pos) node.name = "mcl_chests:ender_chest_small" minetest.set_node(pos, node) @@ -1128,9 +1127,9 @@ local formspec_ender_chest = table.concat({ minetest.register_node("mcl_chests:ender_chest_small", { description = S("Ender Chest"), _tt_help = S("27 interdimensional inventory slots") .. - "\n" .. S("Put items inside, retrieve them from any ender chest"), + "\n" .. S("Put items inside, retrieve them from any ender chest"), _doc_items_longdesc = S( - "Ender chests grant you access to a single personal interdimensional inventory with 27 slots. This inventory is the same no matter from which ender chest you access it from. If you put one item into one ender chest, you will find it in all other ender chests. Each player will only see their own items, but not the items of other players."), + "Ender chests grant you access to a single personal interdimensional inventory with 27 slots. This inventory is the same no matter from which ender chest you access it from. If you put one item into one ender chest, you will find it in all other ender chests. Each player will only see their own items, but not the items of other players."), _doc_items_usagehelp = S("Rightclick the ender chest to access your personal interdimensional inventory."), drawtype = "nodebox", node_box = { @@ -1142,7 +1141,7 @@ minetest.register_node("mcl_chests:ender_chest_small", { _chest_entity_mesh = "mcl_chests_chest", _chest_entity_animation_type = "chest", tiles = { "blank.png^[resize:16x16" }, - use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "clip" or true, + use_texture_alpha = "clip", -- Note: The “container” group is missing here because the ender chest does not -- have an inventory on its own groups = { pickaxey = 1, deco_block = 1, material_stone = 1, chest_entity = 1, not_in_creative_inventory = 1 }, @@ -1157,7 +1156,7 @@ minetest.register_node("mcl_chests:ender_chest_small", { "mcl_chests_enderchest", "mcl_chests_chest", "chest") end, on_rightclick = function(pos, node, clicker) - if minetest.registered_nodes[minetest.get_node({ x = pos.x, y = pos.y + 1, z = pos.z }).name].groups.opaque == 1 then + if minetest.registered_nodes[minetest.get_node(vector.offset(pos, 0, 1, 0)).name].groups.opaque == 1 then -- won't open if there is no space from the top return false end @@ -1284,9 +1283,9 @@ for color, desc in pairs(boxtypes) do if mod_doc then if is_canonical then longdesc = S( - "A shulker box is a portable container which provides 27 inventory slots for any item except shulker boxes. Shulker boxes keep their inventory when broken, so shulker boxes as well as their contents can be taken as a single item. Shulker boxes come in many different colors.") + "A shulker box is a portable container which provides 27 inventory slots for any item except shulker boxes. Shulker boxes keep their inventory when broken, so shulker boxes as well as their contents can be taken as a single item. Shulker boxes come in many different colors.") usagehelp = S( - "To access the inventory of a shulker box, place and right-click it. To take a shulker box and its contents with you, just break and collect it, the items will not fall out. Place the shulker box again to be able to retrieve its contents.") + "To access the inventory of a shulker box, place and right-click it. To take a shulker box and its contents with you, just break and collect it, the items will not fall out. Place the shulker box again to be able to retrieve its contents.") entry_name = S("Shulker Box") else create_entry = false @@ -1303,7 +1302,7 @@ for color, desc in pairs(boxtypes) do _doc_items_longdesc = longdesc, _doc_items_usagehelp = usagehelp, tiles = { mob_texture }, - use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "opaque" or false, + use_texture_alpha = "opaque", drawtype = "mesh", mesh = "mcl_chests_shulker.b3d", groups = { @@ -1374,7 +1373,7 @@ for color, desc in pairs(boxtypes) do fixed = { -0.48, -0.5, -0.48, 0.48, 0.489, 0.48 }, }, tiles = { "blank.png^[resize:16x16" }, - use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "clip" or true, + use_texture_alpha = "clip", _chest_entity_textures = { mob_texture }, _chest_entity_sound = "mcl_chests_shulker", _chest_entity_mesh = "mcl_chests_shulker", From 093d55861ca47410b8c73419b6a49a46086f6720 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Sat, 10 Sep 2022 18:38:46 +0200 Subject: [PATCH 38/82] Basic mcl_gamemode documentation --- mods/PLAYER/mcl_gamemode/API.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 mods/PLAYER/mcl_gamemode/API.md diff --git a/mods/PLAYER/mcl_gamemode/API.md b/mods/PLAYER/mcl_gamemode/API.md new file mode 100644 index 000000000..24651301e --- /dev/null +++ b/mods/PLAYER/mcl_gamemode/API.md @@ -0,0 +1,27 @@ +# `mcl_gamemode` + +## `mcl_gamemode.gamemodes` + +List of availlable gamemodes. + +Currently `{"survival", "creative"}` + +## `mcl_gamemode.get_gamemode(player)` + +Get the player's gamemode. + +Returns "survival" or "creative". + +## `mcl_gamemode.set_gamemode(player, gamemode)` + +Set the player's gamemode. + +gamemode: "survival" or "creative" + +## `mcl_gamemode.register_on_gamemode_change(function(player, old_gamemode, new_gamemode))` + +Register a function that will be called when `mcl_gamemode.set_gamemode` is called. + +## `mcl_gamemode.registered_on_gamemode_change` + +Map of registered on_gamemode_change. From bf57cf3aa34a50554a90aa298dcc4fb522a30c91 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Sat, 10 Sep 2022 21:51:40 +0200 Subject: [PATCH 39/82] Barrel formspec --- mods/ITEMS/mcl_barrels/init.lua | 94 ++++++++++++++++++++------------- 1 file changed, 56 insertions(+), 38 deletions(-) diff --git a/mods/ITEMS/mcl_barrels/init.lua b/mods/ITEMS/mcl_barrels/init.lua index 714a80f09..e2f46be28 100644 --- a/mods/ITEMS/mcl_barrels/init.lua +++ b/mods/ITEMS/mcl_barrels/init.lua @@ -8,6 +8,7 @@ local open_barrels = {} local drop_content = mcl_util.drop_items_from_meta_container("main") +---@param pos Vector local function on_blast(pos) local node = minetest.get_node(pos) drop_content(pos, node) @@ -45,30 +46,34 @@ local function barrel_open(pos, node, clicker) local playername = clicker:get_player_name() minetest.show_formspec(playername, - "mcl_barrels:barrel_"..pos.x.."_"..pos.y.."_"..pos.z, + "mcl_barrels:barrel_" .. pos.x .. "_" .. pos.y .. "_" .. pos.z, table.concat({ - "size[9,8.75]", - "label[0,0;"..F(C("#313131", name)).."]", - "list[nodemeta:"..pos.x..","..pos.y..","..pos.z..";main;0,0.5;9,3;]", - mcl_formspec.get_itemslot_bg(0, 0.5, 9, 3), - "label[0,4.0;"..F(C("#313131", S("Inventory"))).."]", - "list[current_player;main;0,4.5;9,3;9]", - mcl_formspec.get_itemslot_bg(0, 4.5, 9, 3), - "list[current_player;main;0,7.74;9,1;]", - mcl_formspec.get_itemslot_bg(0, 7.74, 9, 1), - "listring[nodemeta:"..pos.x..","..pos.y..","..pos.z..";main]", + "formspec_version[4]", + "size[11.75,10.425]", + + "label[0.375,0.375;" .. F(C(mcl_formspec.label_color, name)) .. "]", + mcl_formspec.get_itemslot_bg_v4(0.375, 0.75, 9, 3), + "list[nodemeta:" .. pos.x .. "," .. pos.y .. "," .. pos.z .. ";main;0.375,0.75;9,3;]", + "label[0.375,4.7;" .. F(C(mcl_formspec.label_color, S("Inventory"))) .. "]", + mcl_formspec.get_itemslot_bg_v4(0.375, 5.1, 9, 3), + "list[current_player;main;0.375,5.1;9,3;9]", + + mcl_formspec.get_itemslot_bg_v4(0.375, 9.05, 9, 1), + "list[current_player;main;0.375,9.05;9,1;]", + "listring[nodemeta:" .. pos.x .. "," .. pos.y .. "," .. pos.z .. ";main]", "listring[current_player;main]", }) ) - minetest.swap_node(pos, { name = "mcl_barrels:barrel_open", param2 = node.param2 }) + minetest.swap_node(pos, { name = "mcl_barrels:barrel_open", param2 = node.param2 }) open_barrels[playername] = pos - minetest.sound_play({name="mcl_barrels_default_barrel_open", pos=pos, gain=0.5, max_hear_distance=16}, true) + minetest.sound_play({ name = "mcl_barrels_default_barrel_open", pos = pos, gain = 0.5, max_hear_distance = 16 }, true) end +---@param pos Vector local function close_forms(pos) local players = minetest.get_connected_players() - local formname = "mcl_barrels:barrel_"..pos.x.."_"..pos.y.."_"..pos.z + local formname = "mcl_barrels:barrel_" .. pos.x .. "_" .. pos.y .. "_" .. pos.z for p = 1, #players do if vector.distance(players[p]:get_pos(), pos) <= 30 then minetest.close_formspec(players[p]:get_player_name(), formname) @@ -76,15 +81,18 @@ local function close_forms(pos) end end +---@param pos Vector local function update_after_close(pos) local node = minetest.get_node_or_nil(pos) if not node then return end if node.name == "mcl_barrels:barrel_open" then - minetest.swap_node(pos, {name = "mcl_barrels:barrel_closed", param2 = node.param2}) - minetest.sound_play({name="mcl_barrels_default_barrel_close", pos=pos, gain=0.5, max_hear_distance=16}, true) + minetest.swap_node(pos, { name = "mcl_barrels:barrel_closed", param2 = node.param2 }) + minetest.sound_play({ name = "mcl_barrels_default_barrel_close", pos = pos, gain = 0.5, max_hear_distance = 16 }, + true) end end +---@param player ObjectRef local function close_barrel(player) local name = player:get_player_name() local open = open_barrels[name] @@ -102,20 +110,22 @@ minetest.register_node("mcl_barrels:barrel_closed", { _tt_help = S("27 inventory slots"), _doc_items_longdesc = S("Barrels are containers which provide 27 inventory slots."), _doc_items_usagehelp = S("To access its inventory, rightclick it. When broken, the items will drop out."), - tiles = {"mcl_barrels_barrel_top.png^[transformR270", "mcl_barrels_barrel_bottom.png", "mcl_barrels_barrel_side.png"}, + tiles = { "mcl_barrels_barrel_top.png^[transformR270", "mcl_barrels_barrel_bottom.png", "mcl_barrels_barrel_side.png" }, paramtype = "light", paramtype2 = "facedir", on_place = function(itemstack, placer, pointed_thing) - minetest.rotate_and_place(itemstack, placer, pointed_thing, minetest.is_creative_enabled(placer:get_player_name()), {}, false) + minetest.rotate_and_place(itemstack, placer, pointed_thing, + minetest.is_creative_enabled(placer:get_player_name()), {} + , false) return itemstack end, stack_max = 64, sounds = mcl_sounds.node_sound_wood_defaults(), - groups = {handy = 1, axey = 1, container = 2, material_wood = 1, flammable = -1, deco_block = 1}, + groups = { handy = 1, axey = 1, container = 2, material_wood = 1, flammable = -1, deco_block = 1 }, on_construct = function(pos) local meta = minetest.get_meta(pos) local inv = meta:get_inventory() - inv:set_size("main", 9*3) + inv:set_size("main", 9 * 3) end, after_place_node = function(pos, placer, itemstack, pointed_thing) minetest.get_meta(pos):set_string("name", itemstack:get_meta():get_string("name")) @@ -124,16 +134,16 @@ minetest.register_node("mcl_barrels:barrel_closed", { allow_metadata_inventory_take = protection_check_put_take, allow_metadata_inventory_put = protection_check_put_take, on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) - minetest.log("action", player:get_player_name().. - " moves stuff in barrel at "..minetest.pos_to_string(pos)) + minetest.log("action", player:get_player_name() .. + " moves stuff in barrel at " .. minetest.pos_to_string(pos)) end, on_metadata_inventory_put = function(pos, listname, index, stack, player) - minetest.log("action", player:get_player_name().. - " moves stuff to barrel at "..minetest.pos_to_string(pos)) + minetest.log("action", player:get_player_name() .. + " moves stuff to barrel at " .. minetest.pos_to_string(pos)) end, on_metadata_inventory_take = function(pos, listname, index, stack, player) - minetest.log("action", player:get_player_name().. - " takes stuff from barrel at "..minetest.pos_to_string(pos)) + minetest.log("action", player:get_player_name() .. + " takes stuff from barrel at " .. minetest.pos_to_string(pos)) end, after_dig_node = drop_content, on_blast = on_blast, @@ -149,27 +159,35 @@ minetest.register_node("mcl_barrels:barrel_open", { _doc_items_longdesc = S("Barrels are containers which provide 27 inventory slots."), _doc_items_usagehelp = S("To access its inventory, rightclick it. When broken, the items will drop out."), _doc_items_create_entry = false, - tiles = {"mcl_barrels_barrel_top_open.png", "mcl_barrels_barrel_bottom.png", "mcl_barrels_barrel_side.png"}, + tiles = { "mcl_barrels_barrel_top_open.png", "mcl_barrels_barrel_bottom.png", "mcl_barrels_barrel_side.png" }, paramtype = "light", paramtype2 = "facedir", drop = "mcl_barrels:barrel_closed", stack_max = 64, sounds = mcl_sounds.node_sound_wood_defaults(), - groups = {handy = 1, axey = 1, container = 2, material_wood = 1, flammable = -1, deco_block = 1, not_in_creative_inventory = 1}, + groups = { + handy = 1, + axey = 1, + container = 2, + material_wood = 1, + flammable = -1, + deco_block = 1, + not_in_creative_inventory = 1 + }, allow_metadata_inventory_move = protection_check_move, allow_metadata_inventory_take = protection_check_put_take, allow_metadata_inventory_put = protection_check_put_take, on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) - minetest.log("action", player:get_player_name().. - " moves stuff in barrel at "..minetest.pos_to_string(pos)) + minetest.log("action", player:get_player_name() .. + " moves stuff in barrel at " .. minetest.pos_to_string(pos)) end, on_metadata_inventory_put = function(pos, listname, index, stack, player) - minetest.log("action", player:get_player_name().. - " moves stuff to barrel at "..minetest.pos_to_string(pos)) + minetest.log("action", player:get_player_name() .. + " moves stuff to barrel at " .. minetest.pos_to_string(pos)) end, on_metadata_inventory_take = function(pos, listname, index, stack, player) - minetest.log("action", player:get_player_name().. - " takes stuff from barrel at "..minetest.pos_to_string(pos)) + minetest.log("action", player:get_player_name() .. + " takes stuff from barrel at " .. minetest.pos_to_string(pos)) end, after_dig_node = drop_content, on_blast = on_blast, @@ -193,10 +211,10 @@ end) minetest.register_craft({ output = "mcl_barrels:barrel_closed", recipe = { - {"group:wood", "group:wood_slab", "group:wood"}, - {"group:wood", "", "group:wood"}, - {"group:wood", "group:wood_slab", "group:wood"}, - } + { "group:wood", "group:wood_slab", "group:wood" }, + { "group:wood", "", "group:wood" }, + { "group:wood", "group:wood_slab", "group:wood" }, + }, }) minetest.register_craft({ From f6804600ba24965d7598f4c86559fea2438d49b5 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Sat, 10 Sep 2022 22:34:31 +0200 Subject: [PATCH 40/82] Grindstone menu --- .luacheckrc | 24 ++++--- mods/ITEMS/mcl_grindstone/init.lua | 110 +++++++++++++++++------------ textures/grindstone_gui_9.png | Bin 0 -> 100 bytes 3 files changed, 76 insertions(+), 58 deletions(-) create mode 100644 textures/grindstone_gui_9.png diff --git a/.luacheckrc b/.luacheckrc index 9d0b8cb2a..69c015665 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -1,10 +1,12 @@ +---@diagnostic disable + unused_args = false allow_defined_top = true max_line_length = false redefined = false globals = { - "minetest", "core", + "minetest", "core", } read_globals = { @@ -40,16 +42,16 @@ read_globals = { "factorial" } }, - ------ - --MODS - ------ + ------ + --MODS + ------ - --GENERAL - "default", + --GENERAL + "default", - --ENTITIES - "cmi", + --ENTITIES + "cmi", - --HUD - "sfinv", "sfinv_buttons", "unified_inventory", "cmsg", "inventory_plus", -} \ No newline at end of file + --HUD + "sfinv", "sfinv_buttons", "unified_inventory", "cmsg", "inventory_plus", +} diff --git a/mods/ITEMS/mcl_grindstone/init.lua b/mods/ITEMS/mcl_grindstone/init.lua index 00c373536..ddd1e8812 100644 --- a/mods/ITEMS/mcl_grindstone/init.lua +++ b/mods/ITEMS/mcl_grindstone/init.lua @@ -1,37 +1,52 @@ -- Code based from mcl_anvils local S = minetest.get_translator(minetest.get_current_modname()) +local F = minetest.formspec_escape +local C = minetest.colorize local MAX_WEAR = 65535 --- formspecs -local function get_grindstone_formspec() - return "size[9,8.75]".. - "image[3,1.5;1.5,1;gui_crafting_arrow.png]".. - "label[0,4.0;"..minetest.formspec_escape(minetest.colorize("#313131", S("Inventory"))).."]".. - "label[1,0.1;"..minetest.formspec_escape(minetest.colorize("#313131", S("Repair & Disenchant"))).."]".. - "list[context;main;0,0;8,4;]".. - "list[current_player;main;0,4.5;9,3;9]".. - mcl_formspec.get_itemslot_bg(0,4.5,9,3).. - "list[current_player;main;0,7.74;9,1;]".. - mcl_formspec.get_itemslot_bg(0,7.74,9,1).. - "list[context;input;1,1;1,1;]".. - mcl_formspec.get_itemslot_bg(1,1,1,1).. - "list[context;input;1,2;1,1;1]".. - mcl_formspec.get_itemslot_bg(1,2,1,1).. - "list[context;output;6,1.5;1,1;]".. - mcl_formspec.get_itemslot_bg(6,1.5,1,1).. - "listring[context;output]".. - "listring[current_player;main]".. - "listring[context;input]".. - "listring[current_player;main]" -end +local grindstone_formspec = table.concat({ + "formspec_version[6]", + "size[11.75,10.425]", + + "label[0.375,0.375;" .. F(C(mcl_formspec.label_color, S("Repair & Disenchant"))) .. "]", + + mcl_formspec.get_itemslot_bg_v4(2.875, 1.25, 1, 1), + "list[context;input;2.875,1.25;1,1;]", + + mcl_formspec.get_itemslot_bg_v4(2.875, 2.625, 1, 1), + "list[context;input;2.875,2.625;1,1;1]", + + "image[2.375,1;2,2.875;grindstone_gui_9.png;2]", + + "image[1.875,1.5;0.5,2.875;grindstone_gui_9.png;2]", + "image[4.375,1.5;0.5,2.875;grindstone_gui_9.png;2]", + + "image[5.5,1.95;1.5,1;gui_crafting_arrow.png]", + + mcl_formspec.get_itemslot_bg_v4(7.875, 1.9375, 1, 1), + "list[context;output;7.875,1.9375;1,1;]", + + "label[0.375,4.7;" .. F(C(mcl_formspec.label_color, S("Inventory"))) .. "]", + + mcl_formspec.get_itemslot_bg_v4(0.375, 5.1, 9, 3), + "list[current_player;main;0.375,5.1;9,3;9]", + + mcl_formspec.get_itemslot_bg_v4(0.375, 9.05, 9, 1), + "list[current_player;main;0.375,9.05;9,1;]", + + "listring[context;output]", + "listring[current_player;main]", + "listring[context;input]", + "listring[current_player;main]", +}) -- Creates a new item with the wear of the items and custom name local function create_new_item(name_item, meta, wear) local new_item = ItemStack(name_item) if wear ~= nil then - new_item:set_wear(wear) + new_item:set_wear(wear) end local new_meta = new_item:get_meta() new_meta:set_string("name", meta:get_string("name")) @@ -86,7 +101,6 @@ local function fix_stack_size(stack) return count end - -- Update the inventory slots of an grindstone node. -- meta: Metadata of grindstone node local function update_grindstone_slots(meta) @@ -122,8 +136,8 @@ local function update_grindstone_slots(meta) else new_output = "" end - -- Check if at least one input has an item - -- Check if the item is's an enchanted book or tool + -- Check if at least one input has an item + -- Check if the item is's an enchanted book or tool elseif (not input1:is_empty() and input2:is_empty()) or (input1:is_empty() and not input2:is_empty()) then if input2:is_empty() then local def1 = input1:get_definition() @@ -168,10 +182,10 @@ end -- Drop any items inside the grindstone if destroyed local function drop_grindstone_items(pos, meta) local inv = meta:get_inventory() - for i=1, inv:get_size("input") do + for i = 1, inv:get_size("input") do local stack = inv:get_stack("input", i) if not stack:is_empty() then - local p = {x=pos.x+math.random(0, 10)/10-0.5, y=pos.y, z=pos.z+math.random(0, 10)/10-0.5} + local p = { x = pos.x + math.random(0, 10) / 10 - 0.5, y = pos.y, z = pos.z + math.random(0, 10) / 10 - 0.5 } minetest.add_item(p, stack) end end @@ -181,11 +195,11 @@ local node_box = { type = "fixed", -- created with nodebox editor fixed = { - {-0.25, -0.25, -0.375, 0.25, 0.5, 0.375}, - {-0.375, -0.0625, -0.1875, -0.25, 0.3125, 0.1875}, - {0.25, -0.0625, -0.1875, 0.375, 0.3125, 0.1875}, - {0.25, -0.5, -0.125, 0.375, -0.0625, 0.125}, - {-0.375, -0.5, -0.125, -0.25, -0.0625, 0.125}, + { -0.25, -0.25, -0.375, 0.25, 0.5, 0.375 }, + { -0.375, -0.0625, -0.1875, -0.25, 0.3125, 0.1875 }, + { 0.25, -0.0625, -0.1875, 0.375, 0.3125, 0.1875 }, + { 0.25, -0.5, -0.125, 0.375, -0.0625, 0.125 }, + { -0.375, -0.5, -0.125, -0.25, -0.0625, 0.125 }, } } @@ -193,11 +207,14 @@ minetest.register_node("mcl_grindstone:grindstone", { description = S("Grindstone"), _tt_help = S("Used to disenchant/fix tools"), _doc_items_longdesc = S("Grindstone disenchants tools and armour except for curses, and repairs two items of the same type it is also the weapon smith's work station."), - _doc_items_usagehelp = S("To use the grindstone, rightclick it, Two input slots (on the left) and a single output slot.").."\n".. - S("To disenchant an item place enchanted item in one of the input slots and take the disenchanted item from the output.").."\n".. - S("To repair a tool you need a tool of the same type and material, put both items in the input slot and the output slot will combine two items durabilities with 5% bonus.").."\n".. - S("If both items have enchantments the player will get xp from both items from the disenchant.").."\n".. - S("Curses cannot be removed and will be transfered to the new repaired item, if both items have a different curse the curses will be combined."), + _doc_items_usagehelp = S("To use the grindstone, rightclick it, Two input slots (on the left) and a single output slot.") + .. "\n" .. + S("To disenchant an item place enchanted item in one of the input slots and take the disenchanted item from the output.") + .. "\n" .. + S("To repair a tool you need a tool of the same type and material, put both items in the input slot and the output slot will combine two items durabilities with 5% bonus.") + .. "\n" .. + S("If both items have enchantments the player will get xp from both items from the disenchant.") .. "\n" .. + S("Curses cannot be removed and will be transfered to the new repaired item, if both items have a different curse the curses will be combined."), tiles = { "grindstone_top.png", "grindstone_top.png", @@ -212,7 +229,7 @@ minetest.register_node("mcl_grindstone:grindstone", { selection_box = node_box, collision_box = node_box, sounds = mcl_sounds.node_sound_stone_defaults(), - groups = {pickaxey = 1, deco_block = 1}, + groups = { pickaxey = 1, deco_block = 1 }, after_dig_node = function(pos, oldnode, oldmetadata, digger) local meta = minetest.get_meta(pos) @@ -268,7 +285,7 @@ minetest.register_node("mcl_grindstone:grindstone", { local meta = minetest.get_meta(pos) if from_list == "output" and to_list == "input" then local inv = meta:get_inventory() - for i=1, inv:get_size("input") do + for i = 1, inv:get_size("input") do if i ~= to_index then local istack = inv:get_stack("input", i) istack:set_count(math.max(0, istack:get_count() - count)) @@ -289,8 +306,8 @@ minetest.register_node("mcl_grindstone:grindstone", { if not input1:is_empty() and not input2:is_empty() then -- Get xp earnt from the enchanted items xp_earnt = calculate_xp(input1) + calculate_xp(input1) - input1:take_item() - input2:take_item() + input1:take_item(1) + input2:take_item(1) inv:set_stack("input", 1, input1) inv:set_stack("input", 2, input2) else @@ -320,14 +337,13 @@ minetest.register_node("mcl_grindstone:grindstone", { local inv = meta:get_inventory() inv:set_size("input", 2) inv:set_size("output", 1) - local form = get_grindstone_formspec() - meta:set_string("formspec", form) + meta:set_string("formspec", grindstone_formspec) end, on_rightclick = function(pos, node, player, itemstack) if not player:get_player_control().sneak then local meta = minetest.get_meta(pos) update_grindstone_slots(meta) - meta:set_string("formspec", get_grindstone_formspec()) + meta:set_string("formspec", grindstone_formspec) end end, _mcl_blast_resistance = 6, @@ -337,7 +353,7 @@ minetest.register_node("mcl_grindstone:grindstone", { minetest.register_craft({ output = "mcl_grindstone:grindstone", recipe = { - { "mcl_core:stick", "mcl_stairs:slab_stone_rough", "mcl_core:stick"}, - { "group:wood", "", "group:wood"}, + { "mcl_core:stick", "mcl_stairs:slab_stone_rough", "mcl_core:stick" }, + { "group:wood", "", "group:wood" }, } }) diff --git a/textures/grindstone_gui_9.png b/textures/grindstone_gui_9.png new file mode 100644 index 0000000000000000000000000000000000000000..b2fffcb56dde72da4bd92a0c432c7df377a91611 GIT binary patch literal 100 zcmeAS@N?(olHy`uVBq!ia0vp^AT}2V8<6ZZI=>f4X?wajhDd}bCnO~N@K;Iu@&4Vr xK4Ja1Jrbdc%zPi@Iog&x1qeJ~E@(ZHzz~^JYWtJ-#%`cC22WQ%mvv4FO#tBC9g6?} literal 0 HcmV?d00001 From 5011e1220909155693de7bf5daeb871059fcd36d Mon Sep 17 00:00:00 2001 From: AFCMS Date: Sat, 10 Sep 2022 23:33:16 +0200 Subject: [PATCH 41/82] mcl_inventory API documentation + fix --- mods/HUD/mcl_inventory/API.md | 35 +++++++++++++++++++++++++++++ mods/HUD/mcl_inventory/survival.lua | 5 +++++ 2 files changed, 40 insertions(+) diff --git a/mods/HUD/mcl_inventory/API.md b/mods/HUD/mcl_inventory/API.md index e69de29bb..5fc5a8d6e 100644 --- a/mods/HUD/mcl_inventory/API.md +++ b/mods/HUD/mcl_inventory/API.md @@ -0,0 +1,35 @@ +# `mcl_inventory` + +## `mcl_inventory.register_survival_inventory_tab(def)` + +```lua +mcl_inventory.register_survival_inventory_tab({ + -- Page identifier + -- Used to uniquely identify the tab + id = "test", + + -- The tab description, can be translated + description = "Test", + + -- The name of the item that will be used as icon + item_icon = "mcl_core:stone", + + -- If true, the main inventory will be shown at the bottom of the tab + -- Listrings need to be added by hand + show_inventory = true, + + -- This function must return the tab's formspec for the player + build = function(player) + return "label[1,1;Hello hello]button[2,2;2,2;Hello;hey]" + end, + + -- This function will be called in the on_player_receive_fields callback if the tab is currently open + handle = function(player, fields) + print(dump(fields)) + end, + + -- This function will be called to know if a player can see the tab + -- Returns true by default + access = function(player) + end, +``` diff --git a/mods/HUD/mcl_inventory/survival.lua b/mods/HUD/mcl_inventory/survival.lua index 0ca22d119..5b5c6032c 100644 --- a/mods/HUD/mcl_inventory/survival.lua +++ b/mods/HUD/mcl_inventory/survival.lua @@ -21,6 +21,10 @@ function mcl_inventory.register_survival_inventory_tab(def) assert(def.build) assert(def.handle) + for _, d in ipairs(mcl_inventory.registered_survival_inventory_tabs) do + assert(d.id ~= def.id, "Another tab exists with the same name!") + end + if not def.access then function def.access(player) return true @@ -62,6 +66,7 @@ local function build_page(player, content, inventory, tabname) ",-1.34;1.5,1.44;" .. (tabname == d.id and "crafting_creative_active.png" or "crafting_creative_inactive.png") .. "]", "item_image_button[" .. (0.44 + (i - 1) * 1.6) .. ",-1.1;1,1;" .. d.item_icon .. ";" .. btn_name .. ";]", + "tooltip[" .. btn_name .. ";" .. F(d.description) .. "]" }) end end From 7c15fe6ac956a392987deb3e14902f1d281a3468 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Sun, 18 Sep 2022 16:56:26 +0200 Subject: [PATCH 42/82] Furnaces formspec redo --- mods/ITEMS/mcl_blast_furnace/init.lua | 181 +++++++++++++++----------- mods/ITEMS/mcl_furnaces/init.lua | 165 +++++++++++++---------- mods/ITEMS/mcl_smoker/init.lua | 180 ++++++++++++++----------- 3 files changed, 309 insertions(+), 217 deletions(-) diff --git a/mods/ITEMS/mcl_blast_furnace/init.lua b/mods/ITEMS/mcl_blast_furnace/init.lua index e8e6e81c8..7e625989f 100644 --- a/mods/ITEMS/mcl_blast_furnace/init.lua +++ b/mods/ITEMS/mcl_blast_furnace/init.lua @@ -1,5 +1,6 @@ - local S = minetest.get_translator(minetest.get_current_modname()) +local C = minetest.colorize +local F = minetest.formspec_escape local LIGHT_ACTIVE_FURNACE = 13 @@ -8,60 +9,82 @@ local LIGHT_ACTIVE_FURNACE = 13 -- local function active_formspec(fuel_percent, item_percent) - return "size[9,8.75]".. - "label[0,4;"..minetest.formspec_escape(minetest.colorize("#313131", S("Inventory"))).."]".. - "list[current_player;main;0,4.5;9,3;9]".. - mcl_formspec.get_itemslot_bg(0,4.5,9,3).. - "list[current_player;main;0,7.74;9,1;]".. - mcl_formspec.get_itemslot_bg(0,7.74,9,1).. - "label[2.75,0;"..minetest.formspec_escape(minetest.colorize("#313131", S("Blast Furnace"))).."]".. - "list[context;src;2.75,0.5;1,1;]".. - mcl_formspec.get_itemslot_bg(2.75,0.5,1,1).. - "list[context;fuel;2.75,2.5;1,1;]".. - mcl_formspec.get_itemslot_bg(2.75,2.5,1,1).. - "list[context;dst;5.75,1.5;1,1;]".. - mcl_formspec.get_itemslot_bg(5.75,1.5,1,1).. - "image[2.75,1.5;1,1;default_furnace_fire_bg.png^[lowpart:".. - (100-fuel_percent)..":default_furnace_fire_fg.png]".. - "image[4.1,1.5;1.5,1;gui_furnace_arrow_bg.png^[lowpart:".. - (item_percent)..":gui_furnace_arrow_fg.png^[transformR270]".. - -- Craft guide button temporarily removed due to Minetest bug. - -- TODO: Add it back when the Minetest bug is fixed. - --"image_button[8,0;1,1;craftguide_book.png;craftguide;]".. - --"tooltip[craftguide;"..minetest.formspec_escape(S("Recipe book")).."]".. - "listring[context;dst]".. - "listring[current_player;main]".. - "listring[context;src]".. - "listring[current_player;main]".. - "listring[context;fuel]".. - "listring[current_player;main]" + return table.concat({ + "formspec_version[4]", + "size[11.75,10.425]", + "label[0.375,0.375;" .. F(C(mcl_formspec.label_color, S("Blast Furnace"))) .. "]", + mcl_formspec.get_itemslot_bg_v4(3.5, 0.75, 1, 1), + "list[context;src;3.5,0.75;1,1;]", + + "image[3.5,2;1,1;default_furnace_fire_bg.png^[lowpart:" .. + (100 - fuel_percent) .. ":default_furnace_fire_fg.png]", + + mcl_formspec.get_itemslot_bg_v4(3.5, 3.25, 1, 1), + "list[context;fuel;3.5,3.25;1,1;]", + + "image[5.25,2;1.5,1;gui_furnace_arrow_bg.png^[lowpart:" .. + (item_percent) .. ":gui_furnace_arrow_fg.png^[transformR270]", + mcl_formspec.get_itemslot_bg_v4(7.875, 2, 1, 1, 0.2), + "list[context;dst;7.875,2;1,1;]", + + "label[0.375,4.7;" .. F(C(mcl_formspec.label_color, S("Inventory"))) .. "]", + mcl_formspec.get_itemslot_bg_v4(0.375, 5.1, 9, 3), + "list[current_player;main;0.375,5.1;9,3;9]", + + mcl_formspec.get_itemslot_bg_v4(0.375, 9.05, 9, 1), + "list[current_player;main;0.375,9.05;9,1;]", + + -- Craft guide button temporarily removed due to Minetest bug. + -- TODO: Add it back when the Minetest bug is fixed. + --"image_button[8,0;1,1;craftguide_book.png;craftguide;]".. + --"tooltip[craftguide;"..minetest.formspec_escape(S("Recipe book")).."]".. + + "listring[context;dst]", + "listring[current_player;main]", + "listring[context;src]", + "listring[current_player;main]", + "listring[context;fuel]", + "listring[current_player;main]", + }) end -local inactive_formspec = "size[9,8.75]".. - "label[0,4;"..minetest.formspec_escape(minetest.colorize("#313131", S("Inventory"))).."]".. - "list[current_player;main;0,4.5;9,3;9]".. - mcl_formspec.get_itemslot_bg(0,4.5,9,3).. - "list[current_player;main;0,7.74;9,1;]".. - mcl_formspec.get_itemslot_bg(0,7.74,9,1).. - "label[2.75,0;"..minetest.formspec_escape(minetest.colorize("#313131", S("Blast Furnace"))).."]".. - "list[context;src;2.75,0.5;1,1;]".. - mcl_formspec.get_itemslot_bg(2.75,0.5,1,1).. - "list[context;fuel;2.75,2.5;1,1;]".. - mcl_formspec.get_itemslot_bg(2.75,2.5,1,1).. - "list[context;dst;5.75,1.5;1,1;]".. - mcl_formspec.get_itemslot_bg(5.75,1.5,1,1).. - "image[2.75,1.5;1,1;default_furnace_fire_bg.png]".. - "image[4.1,1.5;1.5,1;gui_furnace_arrow_bg.png^[transformR270]".. +local inactive_formspec = table.concat({ + "formspec_version[4]", + "size[11.75,10.425]", + "label[0.375,0.375;" .. F(C(mcl_formspec.label_color, S("Blast Furnace"))) .. "]", + mcl_formspec.get_itemslot_bg_v4(3.5, 0.75, 1, 1), + "list[context;src;3.5,0.75;1,1;]", + + "image[3.5,2;1,1;default_furnace_fire_bg.png]", + + mcl_formspec.get_itemslot_bg_v4(3.5, 3.25, 1, 1), + "list[context;fuel;3.5,3.25;1,1;]", + + "image[5.25,2;1.5,1;gui_furnace_arrow_bg.png^[transformR270]", + + mcl_formspec.get_itemslot_bg_v4(7.875, 2, 1, 1, 0.2), + "list[context;dst;7.875,2;1,1;]", + + "label[0.375,4.7;" .. F(C(mcl_formspec.label_color, S("Inventory"))) .. "]", + mcl_formspec.get_itemslot_bg_v4(0.375, 5.1, 9, 3), + "list[current_player;main;0.375,5.1;9,3;9]", + + mcl_formspec.get_itemslot_bg_v4(0.375, 9.05, 9, 1), + "list[current_player;main;0.375,9.05;9,1;]", + -- Craft guide button temporarily removed due to Minetest bug. -- TODO: Add it back when the Minetest bug is fixed. --"image_button[8,0;1,1;craftguide_book.png;craftguide;]".. --"tooltip[craftguide;"..minetest.formspec_escape(S("Recipe book")).."]".. - "listring[context;dst]".. - "listring[current_player;main]".. - "listring[context;src]".. - "listring[current_player;main]".. - "listring[context;fuel]".. - "listring[current_player;main]" + + "listring[context;dst]", + "listring[current_player;main]", + "listring[context;src]", + "listring[current_player;main]", + "listring[context;fuel]", + "listring[current_player;main]", +}) + local receive_fields = function(pos, formname, fields, sender) if fields.craftguide then @@ -71,7 +94,7 @@ end local function give_xp(pos, player) local meta = minetest.get_meta(pos) - local dir = vector.divide(minetest.facedir_to_dir(minetest.get_node(pos).param2),-1.95) + local dir = vector.divide(minetest.facedir_to_dir(minetest.get_node(pos).param2), -1.95) local xp = meta:get_int("xp") if xp > 0 then if player then @@ -99,7 +122,7 @@ local function allow_metadata_inventory_put(pos, listname, index, stack, player) -- Test stack with size 1 because we burn one fuel at a time local teststack = ItemStack(stack) teststack:set_count(1) - local output, decremented_input = minetest.get_craft_result({method="fuel", width=1, items={teststack}}) + local output, decremented_input = minetest.get_craft_result({ method = "fuel", width = 1, items = { teststack } }) if output.time ~= 0 then -- Only allow to place 1 item if fuel get replaced by recipe. -- This is the case for lava buckets. @@ -293,7 +316,7 @@ local function blast_furnace_node_timer(pos, elapsed) -- Check if we have cookable content: cookable local aftercooked - cooked, aftercooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist}) + cooked, aftercooked = minetest.get_craft_result({ method = "cooking", width = 1, items = srclist }) cookable = minetest.get_item_group(inv:get_stack("src", 1):get_name(), "blast_furnace_smeltable") == 1 if cookable then -- Successful cooking requires space in dst slot and time @@ -311,7 +334,7 @@ local function blast_furnace_node_timer(pos, elapsed) if cookable and not active then -- We need to get new fuel local afterfuel - fuel, afterfuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist}) + fuel, afterfuel = minetest.get_craft_result({ method = "fuel", width = 1, items = fuellist }) if fuel.time == 0 then -- No valid fuel in fuel list -- stop @@ -343,7 +366,7 @@ local function blast_furnace_node_timer(pos, elapsed) srclist = inv:get_list("src") src_time = 0 - meta:set_int("xp", meta:get_int("xp") + 1) -- ToDo give each recipe an idividial XP count + meta:set_int("xp", meta:get_int("xp") + 1) -- ToDo give each recipe an idividial XP count end end @@ -390,9 +413,9 @@ local function blast_furnace_node_timer(pos, elapsed) meta:set_float("fuel_time", fuel_time) meta:set_float("src_time", src_time) if srclist then - meta:set_string("src_item", src_item) + meta:set_string("src_item", src_item) else - meta:set_string("src_item", "") + meta:set_string("src_item", "") end meta:set_string("formspec", formspec) @@ -415,13 +438,14 @@ end minetest.register_node("mcl_blast_furnace:blast_furnace", { description = S("Blast Furnace"), _tt_help = S("Smelts ores faster than furnace"), - _doc_items_longdesc = S("Blast Furnaces smelt several items, mainly ores and armor, using a furnace fuel, but twice as fast as a normal furnace."), + _doc_items_longdesc = S( + "Blast Furnaces smelt several items, mainly ores and armor, using a furnace fuel, but twice as fast as a normal furnace."), _doc_items_usagehelp = - S("Use the blast furnace to open the furnace menu.").."\n".. - S("Place a furnace fuel in the lower slot and the source material in the upper slot.").."\n".. - S("The blast furnace will slowly use its fuel to smelt the item.").."\n".. - S("The result will be placed into the output slot at the right side.").."\n".. - S("Use the recipe book to see what ores you can smelt, what you can use as fuel and how long it will burn."), + S("Use the blast furnace to open the furnace menu.") .. "\n" .. + S("Place a furnace fuel in the lower slot and the source material in the upper slot.") .. "\n" .. + S("The blast furnace will slowly use its fuel to smelt the item.") .. "\n" .. + S("The result will be placed into the output slot at the right side.") .. "\n" .. + S("Use the recipe book to see what ores you can smelt, what you can use as fuel and how long it will burn."), _doc_items_hidden = false, tiles = { "blast_furnace_top.png", "blast_furnace_top.png", @@ -429,7 +453,7 @@ minetest.register_node("mcl_blast_furnace:blast_furnace", { "blast_furnace_side.png", "blast_furnace_front.png" }, paramtype2 = "facedir", - groups = {pickaxey=1, container=4, deco_block=1, material_stone=1}, + groups = { pickaxey = 1, container = 4, deco_block = 1, material_stone = 1 }, is_ground_content = false, sounds = mcl_sounds.node_sound_stone_defaults(), @@ -439,10 +463,14 @@ minetest.register_node("mcl_blast_furnace:blast_furnace", { local meta2 = meta:to_table() meta:from_table(oldmetadata) local inv = meta:get_inventory() - for _, listname in ipairs({"src", "dst", "fuel"}) do + for _, listname in ipairs({ "src", "dst", "fuel" }) do local stack = inv:get_stack(listname, 1) if not stack:is_empty() then - local p = {x=pos.x+math.random(0, 10)/10-0.5, y=pos.y, z=pos.z+math.random(0, 10)/10-0.5} + local p = { + x = pos.x + math.random(0, 10) / 10 - 0.5, + y = pos.y, + z = pos.z + math.random(0, 10) / 10 - 0.5 + } minetest.add_item(p, stack) end end @@ -499,14 +527,16 @@ minetest.register_node("mcl_blast_furnace:blast_furnace_active", { tiles = { "blast_furnace_top.png", "blast_furnace_top.png", "blast_furnace_side.png", "blast_furnace_side.png", - "blast_furnace_side.png", {name = "blast_furnace_front_on.png", - animation = {type = "vertical_frames", aspect_w = 16, aspect_h = 16, length = 48}}, + "blast_furnace_side.png", { + name = "blast_furnace_front_on.png", + animation = { type = "vertical_frames", aspect_w = 16, aspect_h = 16, length = 48 } + }, }, paramtype2 = "facedir", paramtype = "light", light_source = LIGHT_ACTIVE_FURNACE, drop = "mcl_blast_furnace:blast_furnace", - groups = {pickaxey=1, container=4, deco_block=1, not_in_creative_inventory=1, material_stone=1}, + groups = { pickaxey = 1, container = 4, deco_block = 1, not_in_creative_inventory = 1, material_stone = 1 }, is_ground_content = false, sounds = mcl_sounds.node_sound_stone_defaults(), on_timer = blast_furnace_node_timer, @@ -516,10 +546,14 @@ minetest.register_node("mcl_blast_furnace:blast_furnace_active", { local meta2 = meta meta:from_table(oldmetadata) local inv = meta:get_inventory() - for _, listname in ipairs({"src", "dst", "fuel"}) do + for _, listname in ipairs({ "src", "dst", "fuel" }) do local stack = inv:get_stack(listname, 1) if not stack:is_empty() then - local p = {x=pos.x+math.random(0, 10)/10-0.5, y=pos.y, z=pos.z+math.random(0, 10)/10-0.5} + local p = { + x = pos.x + math.random(0, 10) / 10 - 0.5, + y = pos.y, + z = pos.z + math.random(0, 10) / 10 - 0.5 + } minetest.add_item(p, stack) end end @@ -550,8 +584,8 @@ minetest.register_node("mcl_blast_furnace:blast_furnace_active", { minetest.register_craft({ output = "mcl_blast_furnace:blast_furnace", recipe = { - { "mcl_core:iron_ingot", "mcl_core:iron_ingot", "mcl_core:iron_ingot" }, - { "mcl_core:iron_ingot", "mcl_furnaces:furnace", "mcl_core:iron_ingot" }, + { "mcl_core:iron_ingot", "mcl_core:iron_ingot", "mcl_core:iron_ingot" }, + { "mcl_core:iron_ingot", "mcl_furnaces:furnace", "mcl_core:iron_ingot" }, { "mcl_core:stone_smooth", "mcl_core:stone_smooth", "mcl_core:stone_smooth" }, } }) @@ -564,10 +598,9 @@ end minetest.register_lbm({ label = "Active blast_furnace flame particles", name = "mcl_blast_furnace:flames", - nodenames = {"mcl_blast_furnace:blast_furnace_active"}, + nodenames = { "mcl_blast_furnace:blast_furnace_active" }, run_at_every_load = true, action = function(pos, node) spawn_flames(pos, node.param2) end, }) - diff --git a/mods/ITEMS/mcl_furnaces/init.lua b/mods/ITEMS/mcl_furnaces/init.lua index 8cb8ad5a0..9cb8ffb16 100644 --- a/mods/ITEMS/mcl_furnaces/init.lua +++ b/mods/ITEMS/mcl_furnaces/init.lua @@ -1,5 +1,6 @@ - local S = minetest.get_translator(minetest.get_current_modname()) +local C = minetest.colorize +local F = minetest.formspec_escape local LIGHT_ACTIVE_FURNACE = 13 @@ -8,60 +9,82 @@ local LIGHT_ACTIVE_FURNACE = 13 -- local function active_formspec(fuel_percent, item_percent) - return "size[9,8.75]".. - "label[0,4;"..minetest.formspec_escape(minetest.colorize("#313131", S("Inventory"))).."]".. - "list[current_player;main;0,4.5;9,3;9]".. - mcl_formspec.get_itemslot_bg(0,4.5,9,3).. - "list[current_player;main;0,7.74;9,1;]".. - mcl_formspec.get_itemslot_bg(0,7.74,9,1).. - "label[2.75,0;"..minetest.formspec_escape(minetest.colorize("#313131", S("Furnace"))).."]".. - "list[context;src;2.75,0.5;1,1;]".. - mcl_formspec.get_itemslot_bg(2.75,0.5,1,1).. - "list[context;fuel;2.75,2.5;1,1;]".. - mcl_formspec.get_itemslot_bg(2.75,2.5,1,1).. - "list[context;dst;5.75,1.5;1,1;]".. - mcl_formspec.get_itemslot_bg(5.75,1.5,1,1).. - "image[2.75,1.5;1,1;default_furnace_fire_bg.png^[lowpart:".. - (100-fuel_percent)..":default_furnace_fire_fg.png]".. - "image[4.1,1.5;1.5,1;gui_furnace_arrow_bg.png^[lowpart:".. - (item_percent)..":gui_furnace_arrow_fg.png^[transformR270]".. - -- Craft guide button temporarily removed due to Minetest bug. - -- TODO: Add it back when the Minetest bug is fixed. - --"image_button[8,0;1,1;craftguide_book.png;craftguide;]".. - --"tooltip[craftguide;"..minetest.formspec_escape(S("Recipe book")).."]".. - "listring[context;dst]".. - "listring[current_player;main]".. - "listring[context;src]".. - "listring[current_player;main]".. - "listring[context;fuel]".. - "listring[current_player;main]" + return table.concat({ + "formspec_version[4]", + "size[11.75,10.425]", + "label[0.375,0.375;" .. F(C(mcl_formspec.label_color, S("Furnace"))) .. "]", + mcl_formspec.get_itemslot_bg_v4(3.5, 0.75, 1, 1), + "list[context;src;3.5,0.75;1,1;]", + + "image[3.5,2;1,1;default_furnace_fire_bg.png^[lowpart:" .. + (100 - fuel_percent) .. ":default_furnace_fire_fg.png]", + + mcl_formspec.get_itemslot_bg_v4(3.5, 3.25, 1, 1), + "list[context;fuel;3.5,3.25;1,1;]", + + "image[5.25,2;1.5,1;gui_furnace_arrow_bg.png^[lowpart:" .. + (item_percent) .. ":gui_furnace_arrow_fg.png^[transformR270]", + mcl_formspec.get_itemslot_bg_v4(7.875, 2, 1, 1, 0.2), + "list[context;dst;7.875,2;1,1;]", + + "label[0.375,4.7;" .. F(C(mcl_formspec.label_color, S("Inventory"))) .. "]", + mcl_formspec.get_itemslot_bg_v4(0.375, 5.1, 9, 3), + "list[current_player;main;0.375,5.1;9,3;9]", + + mcl_formspec.get_itemslot_bg_v4(0.375, 9.05, 9, 1), + "list[current_player;main;0.375,9.05;9,1;]", + + -- Craft guide button temporarily removed due to Minetest bug. + -- TODO: Add it back when the Minetest bug is fixed. + --"image_button[8,0;1,1;craftguide_book.png;craftguide;]".. + --"tooltip[craftguide;"..minetest.formspec_escape(S("Recipe book")).."]".. + + "listring[context;dst]", + "listring[current_player;main]", + "listring[context;src]", + "listring[current_player;main]", + "listring[context;fuel]", + "listring[current_player;main]", + }) end -local inactive_formspec = "size[9,8.75]".. - "label[0,4;"..minetest.formspec_escape(minetest.colorize("#313131", S("Inventory"))).."]".. - "list[current_player;main;0,4.5;9,3;9]".. - mcl_formspec.get_itemslot_bg(0,4.5,9,3).. - "list[current_player;main;0,7.74;9,1;]".. - mcl_formspec.get_itemslot_bg(0,7.74,9,1).. - "label[2.75,0;"..minetest.formspec_escape(minetest.colorize("#313131", S("Furnace"))).."]".. - "list[context;src;2.75,0.5;1,1;]".. - mcl_formspec.get_itemslot_bg(2.75,0.5,1,1).. - "list[context;fuel;2.75,2.5;1,1;]".. - mcl_formspec.get_itemslot_bg(2.75,2.5,1,1).. - "list[context;dst;5.75,1.5;1,1;]".. - mcl_formspec.get_itemslot_bg(5.75,1.5,1,1).. - "image[2.75,1.5;1,1;default_furnace_fire_bg.png]".. - "image[4.1,1.5;1.5,1;gui_furnace_arrow_bg.png^[transformR270]".. +local inactive_formspec = table.concat({ + "formspec_version[4]", + "size[11.75,10.425]", + "label[0.375,0.375;" .. F(C(mcl_formspec.label_color, S("Furnace"))) .. "]", + mcl_formspec.get_itemslot_bg_v4(3.5, 0.75, 1, 1), + "list[context;src;3.5,0.75;1,1;]", + + "image[3.5,2;1,1;default_furnace_fire_bg.png]", + + mcl_formspec.get_itemslot_bg_v4(3.5, 3.25, 1, 1), + "list[context;fuel;3.5,3.25;1,1;]", + + "image[5.25,2;1.5,1;gui_furnace_arrow_bg.png^[transformR270]", + + mcl_formspec.get_itemslot_bg_v4(7.875, 2, 1, 1, 0.2), + "list[context;dst;7.875,2;1,1;]", + + "label[0.375,4.7;" .. F(C(mcl_formspec.label_color, S("Inventory"))) .. "]", + mcl_formspec.get_itemslot_bg_v4(0.375, 5.1, 9, 3), + "list[current_player;main;0.375,5.1;9,3;9]", + + mcl_formspec.get_itemslot_bg_v4(0.375, 9.05, 9, 1), + "list[current_player;main;0.375,9.05;9,1;]", + -- Craft guide button temporarily removed due to Minetest bug. -- TODO: Add it back when the Minetest bug is fixed. --"image_button[8,0;1,1;craftguide_book.png;craftguide;]".. --"tooltip[craftguide;"..minetest.formspec_escape(S("Recipe book")).."]".. - "listring[context;dst]".. - "listring[current_player;main]".. - "listring[context;src]".. - "listring[current_player;main]".. - "listring[context;fuel]".. - "listring[current_player;main]" + + "listring[context;dst]", + "listring[current_player;main]", + "listring[context;src]", + "listring[current_player;main]", + "listring[context;fuel]", + "listring[current_player;main]", +}) + local receive_fields = function(pos, formname, fields, sender) if fields.craftguide then @@ -71,7 +94,7 @@ end local function give_xp(pos, player) local meta = minetest.get_meta(pos) - local dir = vector.divide(minetest.facedir_to_dir(minetest.get_node(pos).param2),-1.95) + local dir = vector.divide(minetest.facedir_to_dir(minetest.get_node(pos).param2), -1.95) local xp = meta:get_int("xp") if xp > 0 then if player then @@ -108,7 +131,7 @@ local function allow_metadata_inventory_put(pos, listname, index, stack, player) -- Test stack with size 1 because we burn one fuel at a time local teststack = ItemStack(stack) teststack:set_count(1) - local output, decremented_input = minetest.get_craft_result({method="fuel", width=1, items={teststack}}) + local output, decremented_input = minetest.get_craft_result({ method = "fuel", width = 1, items = { teststack } }) if output.time ~= 0 then -- Only allow to place 1 item if fuel get replaced by recipe. -- This is the case for lava buckets. @@ -303,7 +326,7 @@ local function furnace_node_timer(pos, elapsed) -- Check if we have cookable content: cookable local aftercooked - cooked, aftercooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist}) + cooked, aftercooked = minetest.get_craft_result({ method = "cooking", width = 1, items = srclist }) cookable = cooked.time ~= 0 if cookable then -- Successful cooking requires space in dst slot and time @@ -321,7 +344,7 @@ local function furnace_node_timer(pos, elapsed) if cookable and not active then -- We need to get new fuel local afterfuel - fuel, afterfuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist}) + fuel, afterfuel = minetest.get_craft_result({ method = "fuel", width = 1, items = fuellist }) if fuel.time == 0 then -- No valid fuel in fuel list -- stop @@ -356,7 +379,7 @@ local function furnace_node_timer(pos, elapsed) if srclist[1]:get_name() == "mcl_sponges:sponge_wet" then inv:set_stack("fuel", 1, "mcl_buckets:bucket_water") fuellist = inv:get_list("fuel") - -- Also for river water + -- Also for river water elseif srclist[1]:get_name() == "mcl_sponges:sponge_wet_river_water" then inv:set_stack("fuel", 1, "mcl_buckets:bucket_river_water") fuellist = inv:get_list("fuel") @@ -366,7 +389,7 @@ local function furnace_node_timer(pos, elapsed) srclist = inv:get_list("src") src_time = 0 - meta:set_int("xp", meta:get_int("xp") + 1) -- ToDo give each recipe an idividial XP count + meta:set_int("xp", meta:get_int("xp") + 1) -- ToDo give each recipe an idividial XP count end end @@ -413,9 +436,9 @@ local function furnace_node_timer(pos, elapsed) meta:set_float("fuel_time", fuel_time) meta:set_float("src_time", src_time) if srclist then - meta:set_string("src_item", src_item) + meta:set_string("src_item", src_item) else - meta:set_string("src_item", "") + meta:set_string("src_item", "") end meta:set_string("formspec", formspec) @@ -440,11 +463,11 @@ minetest.register_node("mcl_furnaces:furnace", { _tt_help = S("Uses fuel to smelt or cook items"), _doc_items_longdesc = S("Furnaces cook or smelt several items, using a furnace fuel, into something else."), _doc_items_usagehelp = - S("Use the furnace to open the furnace menu.").."\n".. - S("Place a furnace fuel in the lower slot and the source material in the upper slot.").."\n".. - S("The furnace will slowly use its fuel to smelt the item.").."\n".. - S("The result will be placed into the output slot at the right side.").."\n".. - S("Use the recipe book to see what you can smelt, what you can use as fuel and how long it will burn."), + S("Use the furnace to open the furnace menu.") .. "\n" .. + S("Place a furnace fuel in the lower slot and the source material in the upper slot.") .. "\n" .. + S("The furnace will slowly use its fuel to smelt the item.") .. "\n" .. + S("The result will be placed into the output slot at the right side.") .. "\n" .. + S("Use the recipe book to see what you can smelt, what you can use as fuel and how long it will burn."), _doc_items_hidden = false, tiles = { "default_furnace_top.png", "default_furnace_bottom.png", @@ -452,7 +475,7 @@ minetest.register_node("mcl_furnaces:furnace", { "default_furnace_side.png", "default_furnace_front.png" }, paramtype2 = "facedir", - groups = {pickaxey=1, container=4, deco_block=1, material_stone=1}, + groups = { pickaxey = 1, container = 4, deco_block = 1, material_stone = 1 }, is_ground_content = false, sounds = mcl_sounds.node_sound_stone_defaults(), @@ -462,10 +485,11 @@ minetest.register_node("mcl_furnaces:furnace", { local meta2 = meta:to_table() meta:from_table(oldmetadata) local inv = meta:get_inventory() - for _, listname in ipairs({"src", "dst", "fuel"}) do + for _, listname in ipairs({ "src", "dst", "fuel" }) do local stack = inv:get_stack(listname, 1) if not stack:is_empty() then - local p = {x=pos.x+math.random(0, 10)/10-0.5, y=pos.y, z=pos.z+math.random(0, 10)/10-0.5} + local p = { x = pos.x + math.random(0, 10) / 10 - 0.5, y = pos.y, + z = pos.z + math.random(0, 10) / 10 - 0.5 } minetest.add_item(p, stack) end end @@ -528,7 +552,7 @@ minetest.register_node("mcl_furnaces:furnace_active", { paramtype = "light", light_source = LIGHT_ACTIVE_FURNACE, drop = "mcl_furnaces:furnace", - groups = {pickaxey=1, container=4, deco_block=1, not_in_creative_inventory=1, material_stone=1}, + groups = { pickaxey = 1, container = 4, deco_block = 1, not_in_creative_inventory = 1, material_stone = 1 }, is_ground_content = false, sounds = mcl_sounds.node_sound_stone_defaults(), on_timer = furnace_node_timer, @@ -538,10 +562,11 @@ minetest.register_node("mcl_furnaces:furnace_active", { local meta2 = meta meta:from_table(oldmetadata) local inv = meta:get_inventory() - for _, listname in ipairs({"src", "dst", "fuel"}) do + for _, listname in ipairs({ "src", "dst", "fuel" }) do local stack = inv:get_stack(listname, 1) if not stack:is_empty() then - local p = {x=pos.x+math.random(0, 10)/10-0.5, y=pos.y, z=pos.z+math.random(0, 10)/10-0.5} + local p = { x = pos.x + math.random(0, 10) / 10 - 0.5, y = pos.y, + z = pos.z + math.random(0, 10) / 10 - 0.5 } minetest.add_item(p, stack) end end @@ -573,7 +598,7 @@ minetest.register_craft({ output = "mcl_furnaces:furnace", recipe = { { "group:cobble", "group:cobble", "group:cobble" }, - { "group:cobble", "", "group:cobble" }, + { "group:cobble", "", "group:cobble" }, { "group:cobble", "group:cobble", "group:cobble" }, } }) @@ -586,7 +611,7 @@ end minetest.register_lbm({ label = "Active furnace flame particles", name = "mcl_furnaces:flames", - nodenames = {"mcl_furnaces:furnace_active"}, + nodenames = { "mcl_furnaces:furnace_active" }, run_at_every_load = true, action = function(pos, node) spawn_flames(pos, node.param2) diff --git a/mods/ITEMS/mcl_smoker/init.lua b/mods/ITEMS/mcl_smoker/init.lua index 4a4cfca15..757f13054 100644 --- a/mods/ITEMS/mcl_smoker/init.lua +++ b/mods/ITEMS/mcl_smoker/init.lua @@ -1,5 +1,6 @@ - local S = minetest.get_translator(minetest.get_current_modname()) +local C = minetest.colorize +local F = minetest.formspec_escape local LIGHT_ACTIVE_FURNACE = 13 @@ -8,60 +9,82 @@ local LIGHT_ACTIVE_FURNACE = 13 -- local function active_formspec(fuel_percent, item_percent) - return "size[9,8.75]".. - "label[0,4;"..minetest.formspec_escape(minetest.colorize("#313131", S("Inventory"))).."]".. - "list[current_player;main;0,4.5;9,3;9]".. - mcl_formspec.get_itemslot_bg(0,4.5,9,3).. - "list[current_player;main;0,7.74;9,1;]".. - mcl_formspec.get_itemslot_bg(0,7.74,9,1).. - "label[2.75,0;"..minetest.formspec_escape(minetest.colorize("#313131", S("Smoker"))).."]".. - "list[context;src;2.75,0.5;1,1;]".. - mcl_formspec.get_itemslot_bg(2.75,0.5,1,1).. - "list[context;fuel;2.75,2.5;1,1;]".. - mcl_formspec.get_itemslot_bg(2.75,2.5,1,1).. - "list[context;dst;5.75,1.5;1,1;]".. - mcl_formspec.get_itemslot_bg(5.75,1.5,1,1).. - "image[2.75,1.5;1,1;default_furnace_fire_bg.png^[lowpart:".. - (100-fuel_percent)..":default_furnace_fire_fg.png]".. - "image[4.1,1.5;1.5,1;gui_furnace_arrow_bg.png^[lowpart:".. - (item_percent)..":gui_furnace_arrow_fg.png^[transformR270]".. - -- Craft guide button temporarily removed due to Minetest bug. - -- TODO: Add it back when the Minetest bug is fixed. - --"image_button[8,0;1,1;craftguide_book.png;craftguide;]".. - --"tooltip[craftguide;"..minetest.formspec_escape(S("Recipe book")).."]".. - "listring[context;dst]".. - "listring[current_player;main]".. - "listring[context;src]".. - "listring[current_player;main]".. - "listring[context;fuel]".. - "listring[current_player;main]" + return table.concat({ + "formspec_version[4]", + "size[11.75,10.425]", + "label[0.375,0.375;" .. F(C(mcl_formspec.label_color, S("Smoker"))) .. "]", + mcl_formspec.get_itemslot_bg_v4(3.5, 0.75, 1, 1), + "list[context;src;3.5,0.75;1,1;]", + + "image[3.5,2;1,1;default_furnace_fire_bg.png^[lowpart:" .. + (100 - fuel_percent) .. ":default_furnace_fire_fg.png]", + + mcl_formspec.get_itemslot_bg_v4(3.5, 3.25, 1, 1), + "list[context;fuel;3.5,3.25;1,1;]", + + "image[5.25,2;1.5,1;gui_furnace_arrow_bg.png^[lowpart:" .. + (item_percent) .. ":gui_furnace_arrow_fg.png^[transformR270]", + mcl_formspec.get_itemslot_bg_v4(7.875, 2, 1, 1, 0.2), + "list[context;dst;7.875,2;1,1;]", + + "label[0.375,4.7;" .. F(C(mcl_formspec.label_color, S("Inventory"))) .. "]", + mcl_formspec.get_itemslot_bg_v4(0.375, 5.1, 9, 3), + "list[current_player;main;0.375,5.1;9,3;9]", + + mcl_formspec.get_itemslot_bg_v4(0.375, 9.05, 9, 1), + "list[current_player;main;0.375,9.05;9,1;]", + + -- Craft guide button temporarily removed due to Minetest bug. + -- TODO: Add it back when the Minetest bug is fixed. + --"image_button[8,0;1,1;craftguide_book.png;craftguide;]".. + --"tooltip[craftguide;"..minetest.formspec_escape(S("Recipe book")).."]".. + + "listring[context;dst]", + "listring[current_player;main]", + "listring[context;src]", + "listring[current_player;main]", + "listring[context;fuel]", + "listring[current_player;main]", + }) end -local inactive_formspec = "size[9,8.75]".. - "label[0,4;"..minetest.formspec_escape(minetest.colorize("#313131", S("Inventory"))).."]".. - "list[current_player;main;0,4.5;9,3;9]".. - mcl_formspec.get_itemslot_bg(0,4.5,9,3).. - "list[current_player;main;0,7.74;9,1;]".. - mcl_formspec.get_itemslot_bg(0,7.74,9,1).. - "label[2.75,0;"..minetest.formspec_escape(minetest.colorize("#313131", S("Smoker"))).."]".. - "list[context;src;2.75,0.5;1,1;]".. - mcl_formspec.get_itemslot_bg(2.75,0.5,1,1).. - "list[context;fuel;2.75,2.5;1,1;]".. - mcl_formspec.get_itemslot_bg(2.75,2.5,1,1).. - "list[context;dst;5.75,1.5;1,1;]".. - mcl_formspec.get_itemslot_bg(5.75,1.5,1,1).. - "image[2.75,1.5;1,1;default_furnace_fire_bg.png]".. - "image[4.1,1.5;1.5,1;gui_furnace_arrow_bg.png^[transformR270]".. +local inactive_formspec = table.concat({ + "formspec_version[4]", + "size[11.75,10.425]", + "label[0.375,0.375;" .. F(C(mcl_formspec.label_color, S("Smoker"))) .. "]", + mcl_formspec.get_itemslot_bg_v4(3.5, 0.75, 1, 1), + "list[context;src;3.5,0.75;1,1;]", + + "image[3.5,2;1,1;default_furnace_fire_bg.png]", + + mcl_formspec.get_itemslot_bg_v4(3.5, 3.25, 1, 1), + "list[context;fuel;3.5,3.25;1,1;]", + + "image[5.25,2;1.5,1;gui_furnace_arrow_bg.png^[transformR270]", + + mcl_formspec.get_itemslot_bg_v4(7.875, 2, 1, 1, 0.2), + "list[context;dst;7.875,2;1,1;]", + + "label[0.375,4.7;" .. F(C(mcl_formspec.label_color, S("Inventory"))) .. "]", + mcl_formspec.get_itemslot_bg_v4(0.375, 5.1, 9, 3), + "list[current_player;main;0.375,5.1;9,3;9]", + + mcl_formspec.get_itemslot_bg_v4(0.375, 9.05, 9, 1), + "list[current_player;main;0.375,9.05;9,1;]", + -- Craft guide button temporarily removed due to Minetest bug. -- TODO: Add it back when the Minetest bug is fixed. --"image_button[8,0;1,1;craftguide_book.png;craftguide;]".. --"tooltip[craftguide;"..minetest.formspec_escape(S("Recipe book")).."]".. - "listring[context;dst]".. - "listring[current_player;main]".. - "listring[context;src]".. - "listring[current_player;main]".. - "listring[context;fuel]".. - "listring[current_player;main]" + + "listring[context;dst]", + "listring[current_player;main]", + "listring[context;src]", + "listring[current_player;main]", + "listring[context;fuel]", + "listring[current_player;main]", +}) + local receive_fields = function(pos, formname, fields, sender) if fields.craftguide then @@ -71,7 +94,7 @@ end local function give_xp(pos, player) local meta = minetest.get_meta(pos) - local dir = vector.divide(minetest.facedir_to_dir(minetest.get_node(pos).param2),-1.95) + local dir = vector.divide(minetest.facedir_to_dir(minetest.get_node(pos).param2), -1.95) local xp = meta:get_int("xp") if xp > 0 then if player then @@ -98,7 +121,7 @@ local function allow_metadata_inventory_put(pos, listname, index, stack, player) -- Test stack with size 1 because we burn one fuel at a time local teststack = ItemStack(stack) teststack:set_count(1) - local output, decremented_input = minetest.get_craft_result({method="fuel", width=1, items={teststack}}) + local output, decremented_input = minetest.get_craft_result({ method = "fuel", width = 1, items = { teststack } }) if output.time ~= 0 then -- Only allow to place 1 item if fuel get replaced by recipe. -- This is the case for lava buckets. @@ -292,7 +315,7 @@ local function smoker_node_timer(pos, elapsed) -- Check if we have cookable content: cookable local aftercooked - cooked, aftercooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist}) + cooked, aftercooked = minetest.get_craft_result({ method = "cooking", width = 1, items = srclist }) cookable = minetest.get_item_group(inv:get_stack("src", 1):get_name(), "smoker_cookable") == 1 if cookable then -- Successful cooking requires space in dst slot and time @@ -310,7 +333,7 @@ local function smoker_node_timer(pos, elapsed) if cookable and not active then -- We need to get new fuel local afterfuel - fuel, afterfuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist}) + fuel, afterfuel = minetest.get_craft_result({ method = "fuel", width = 1, items = fuellist }) if fuel.time == 0 then -- No valid fuel in fuel list -- stop @@ -343,7 +366,7 @@ local function smoker_node_timer(pos, elapsed) srclist = inv:get_list("src") src_time = 0 - meta:set_int("xp", meta:get_int("xp") + 1) -- ToDo give each recipe an idividial XP count + meta:set_int("xp", meta:get_int("xp") + 1) -- ToDo give each recipe an idividial XP count end end @@ -390,9 +413,9 @@ local function smoker_node_timer(pos, elapsed) meta:set_float("fuel_time", fuel_time) meta:set_float("src_time", src_time) if srclist then - meta:set_string("src_item", src_item) + meta:set_string("src_item", src_item) else - meta:set_string("src_item", "") + meta:set_string("src_item", "") end meta:set_string("formspec", formspec) @@ -415,13 +438,14 @@ end minetest.register_node("mcl_smoker:smoker", { description = S("Smoker"), _tt_help = S("Cooks food faster than furnace"), - _doc_items_longdesc = S("Smokers cook several items, mainly raw foods, into cooked foods, but twice as fast as a normal furnace."), + _doc_items_longdesc = S( + "Smokers cook several items, mainly raw foods, into cooked foods, but twice as fast as a normal furnace."), _doc_items_usagehelp = - S("Use the smoker to open the furnace menu.").."\n".. - S("Place a furnace fuel in the lower slot and the source material in the upper slot.").."\n".. - S("The smoker will slowly use its fuel to smelt the item.").."\n".. - S("The result will be placed into the output slot at the right side.").."\n".. - S("Use the recipe book to see what foods you can smelt, what you can use as fuel and how long it will burn."), + S("Use the smoker to open the furnace menu.") .. "\n" .. + S("Place a furnace fuel in the lower slot and the source material in the upper slot.") .. "\n" .. + S("The smoker will slowly use its fuel to smelt the item.") .. "\n" .. + S("The result will be placed into the output slot at the right side.") .. "\n" .. + S("Use the recipe book to see what foods you can smelt, what you can use as fuel and how long it will burn."), _doc_items_hidden = false, tiles = { "smoker_top.png", "smoker_bottom.png", @@ -429,7 +453,7 @@ minetest.register_node("mcl_smoker:smoker", { "smoker_side.png", "smoker_front.png" }, paramtype2 = "facedir", - groups = {pickaxey=1, container=4, deco_block=1, material_stone=1}, + groups = { pickaxey = 1, container = 4, deco_block = 1, material_stone = 1 }, is_ground_content = false, sounds = mcl_sounds.node_sound_stone_defaults(), @@ -439,10 +463,14 @@ minetest.register_node("mcl_smoker:smoker", { local meta2 = meta:to_table() meta:from_table(oldmetadata) local inv = meta:get_inventory() - for _, listname in ipairs({"src", "dst", "fuel"}) do + for _, listname in ipairs({ "src", "dst", "fuel" }) do local stack = inv:get_stack(listname, 1) if not stack:is_empty() then - local p = {x=pos.x+math.random(0, 10)/10-0.5, y=pos.y, z=pos.z+math.random(0, 10)/10-0.5} + local p = { + x = pos.x + math.random(0, 10) / 10 - 0.5, + y = pos.y, + z = pos.z + math.random(0, 10) / 10 - 0.5 + } minetest.add_item(p, stack) end end @@ -499,14 +527,16 @@ minetest.register_node("mcl_smoker:smoker_active", { tiles = { "smoker_top.png", "smoker_bottom.png", "smoker_side.png", "smoker_side.png", - "smoker_side.png", {name = "smoker_front_on.png", - animation = {type = "vertical_frames", aspect_w = 16, aspect_h = 16, length = 48}}, + "smoker_side.png", { + name = "smoker_front_on.png", + animation = { type = "vertical_frames", aspect_w = 16, aspect_h = 16, length = 48 } + }, }, paramtype2 = "facedir", paramtype = "light", light_source = LIGHT_ACTIVE_FURNACE, drop = "mcl_smoker:smoker", - groups = {pickaxey=1, container=4, deco_block=1, not_in_creative_inventory=1, material_stone=1}, + groups = { pickaxey = 1, container = 4, deco_block = 1, not_in_creative_inventory = 1, material_stone = 1 }, is_ground_content = false, sounds = mcl_sounds.node_sound_stone_defaults(), on_timer = smoker_node_timer, @@ -516,10 +546,14 @@ minetest.register_node("mcl_smoker:smoker_active", { local meta2 = meta meta:from_table(oldmetadata) local inv = meta:get_inventory() - for _, listname in ipairs({"src", "dst", "fuel"}) do + for _, listname in ipairs({ "src", "dst", "fuel" }) do local stack = inv:get_stack(listname, 1) if not stack:is_empty() then - local p = {x=pos.x+math.random(0, 10)/10-0.5, y=pos.y, z=pos.z+math.random(0, 10)/10-0.5} + local p = { + x = pos.x + math.random(0, 10) / 10 - 0.5, + y = pos.y, + z = pos.z + math.random(0, 10) / 10 - 0.5 + } minetest.add_item(p, stack) end end @@ -550,9 +584,9 @@ minetest.register_node("mcl_smoker:smoker_active", { minetest.register_craft({ output = "mcl_smoker:smoker", recipe = { - { "", "group:tree", "" }, + { "", "group:tree", "" }, { "group:tree", "mcl_furnaces:furnace", "group:tree" }, - { "", "group:tree", "" }, + { "", "group:tree", "" }, } }) @@ -564,7 +598,7 @@ end minetest.register_lbm({ label = "Active smoker flame particles", name = "mcl_smoker:flames", - nodenames = {"mcl_smoker:smoker_active"}, + nodenames = { "mcl_smoker:smoker_active" }, run_at_every_load = true, action = function(pos, node) spawn_flames(pos, node.param2) From 4055555ec18de5edec3fba44ed98b14ee84743b4 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Sat, 8 Oct 2022 00:02:35 +0200 Subject: [PATCH 43/82] Redo Creative Inventory --- mods/HUD/mcl_formspec/init.lua | 14 +- mods/HUD/mcl_inventory/creative.lua | 282 ++++++++++++++-------------- 2 files changed, 145 insertions(+), 151 deletions(-) diff --git a/mods/HUD/mcl_formspec/init.lua b/mods/HUD/mcl_formspec/init.lua index 00fa7560e..69ef23e08 100644 --- a/mods/HUD/mcl_formspec/init.lua +++ b/mods/HUD/mcl_formspec/init.lua @@ -21,10 +21,12 @@ end ---@param x number ---@param y number ---@param size number +---@param texture? string ---@return string -local function get_slot(x, y, size) +---@nodiscard +local function get_slot(x, y, size, texture) local t = "image[" .. x - size .. "," .. y - size .. ";" .. 1 + (size * 2) .. - "," .. 1 + (size * 2) .. ";mcl_formspec_itemslot.png]" + "," .. 1 + (size * 2) .. ";" .. (texture and texture or "mcl_formspec_itemslot.png") .. "]" return t end @@ -34,16 +36,18 @@ mcl_formspec.itemslot_border_size = 0.05 ---@param y number ---@param w integer ---@param h integer ----@param size? number +---@param size? number Optional size of the slot border (default: 0.05) +---@param texture? string Optional texture to replace the default one ---@return string -function mcl_formspec.get_itemslot_bg_v4(x, y, w, h, size) +---@nodiscard +function mcl_formspec.get_itemslot_bg_v4(x, y, w, h, size, texture) if not size then size = mcl_formspec.itemslot_border_size end local out = "" for i = 0, w - 1, 1 do for j = 0, h - 1, 1 do - out = out .. get_slot(x + i + (i * 0.25), y + j + (j * 0.25), size) + out = out .. get_slot(x + i + (i * 0.25), y + j + (j * 0.25), size, texture) end end return out diff --git a/mods/HUD/mcl_inventory/creative.lua b/mods/HUD/mcl_inventory/creative.lua index c18b559b1..1e0b493e3 100644 --- a/mods/HUD/mcl_inventory/creative.lua +++ b/mods/HUD/mcl_inventory/creative.lua @@ -37,7 +37,7 @@ minetest.register_on_mods_loaded(function() def.description ~= "" then local function is_redstone(def) return def.mesecons or def.groups.mesecon or def.groups.mesecon_conductor_craftable or - def.groups.mesecon_effecor_off + def.groups.mesecon_effecor_off end local function is_tool(def) @@ -217,15 +217,15 @@ local hoch = {} local filtername = {} --local bg = {} -local noffset_x_start = -0.24 +local noffset_x_start = 0.2 local noffset_x = noffset_x_start -local noffset_y = -0.25 +local noffset_y = -1.34 local function next_noffset(id, right) if right then - noffset[id] = { 8.94, noffset_y } + noffset[id] = { 11.3, noffset_y } else noffset[id] = { noffset_x, noffset_y } - noffset_x = noffset_x + 1.25 + noffset_x = noffset_x + 1.6 end end @@ -239,7 +239,7 @@ next_noffset("misc") next_noffset("nix", true) noffset_x = noffset_x_start -noffset_y = 8.12 +noffset_y = 8.64 -- Lower row next_noffset("food") @@ -251,7 +251,7 @@ next_noffset("inv", true) for k, v in pairs(noffset) do offset[k] = tostring(v[1]) .. "," .. tostring(v[2]) - boffset[k] = tostring(v[1] + 0.19) .. "," .. tostring(v[2] + 0.25) + boffset[k] = tostring(v[1] + 0.24) .. "," .. tostring(v[2] + 0.25) end hoch["blocks"] = "" @@ -302,10 +302,30 @@ filtername["inv"] = S("Survival Inventory") bg["default"] = dark_bg end]] +local tab_icon = { + blocks = "mcl_core:brick_block", + deco = "mcl_flowers:peony", + redstone = "mesecons:redstone", + rail = "mcl_minecarts:golden_rail", + misc = "mcl_buckets:bucket_lava", + nix = "mcl_compass:compass", + food = "mcl_core:apple", + tools = "mcl_core:axe_iron", + combat = "mcl_core:sword_gold", + mobs = "mobs_mc:cow", + brew = "mcl_potions:dragon_breath", + matr = "mcl_core:stick", + inv = "mcl_chests:chest", +} + +---@param player ObjectRef +---@return integer local function get_stack_size(player) return player:get_meta():get_int("mcl_inventory:switch_stack") end +---@param player ObjectRef +---@param n integer local function set_stack_size(player, n) player:get_meta():set_int("mcl_inventory:switch_stack", n) end @@ -322,7 +342,7 @@ function mcl_inventory.set_creative_formspec(player) local start_i = players[playername].start_i local pagenum = start_i / (9 * 5) + 1 - local name = players[playername].page + local page = players[playername].page local inv_size = players[playername].inv_size local filter = players[playername].filter @@ -339,80 +359,89 @@ function mcl_inventory.set_creative_formspec(player) local pagemax = math.max(1, math.floor((inv_size - 1) / (9 * 5) + 1)) local name = "nix" local main_list - local listrings = "listring[detached:creative_" .. playername .. ";main]" .. - "listring[current_player;main]" .. - "listring[detached:trash;main]" + local listrings = table.concat({ + "listring[detached:creative_" .. playername .. ";main]", + "listring[current_player;main]", + "listring[detached:trash;main]", + }) + + if page then + name = page + if players[playername] then + players[playername].page = page + end + end - local inv_bg = "crafting_inventory_creative.png" if name == "inv" then - inv_bg = "crafting_inventory_creative_survival.png" - -- Background images for armor slots (hide if occupied) local armor_slot_imgs = "" local inv = player:get_inventory() if inv:get_stack("armor", 2):is_empty() then - armor_slot_imgs = armor_slot_imgs .. "image[2.5,1.3;1,1;mcl_inventory_empty_armor_slot_helmet.png]" + armor_slot_imgs = armor_slot_imgs .. "image[3.5,0.375;1,1;mcl_inventory_empty_armor_slot_helmet.png]" end if inv:get_stack("armor", 3):is_empty() then - armor_slot_imgs = armor_slot_imgs .. "image[2.5,2.75;1,1;mcl_inventory_empty_armor_slot_chestplate.png]" + armor_slot_imgs = armor_slot_imgs .. "image[3.5,2.125;1,1;mcl_inventory_empty_armor_slot_chestplate.png]" end if inv:get_stack("armor", 4):is_empty() then - armor_slot_imgs = armor_slot_imgs .. "image[5.5,1.3;1,1;mcl_inventory_empty_armor_slot_leggings.png]" + armor_slot_imgs = armor_slot_imgs .. "image[7.25,0.375;1,1;mcl_inventory_empty_armor_slot_leggings.png]" end if inv:get_stack("armor", 5):is_empty() then - armor_slot_imgs = armor_slot_imgs .. "image[5.5,2.75;1,1;mcl_inventory_empty_armor_slot_boots.png]" + armor_slot_imgs = armor_slot_imgs .. "image[7.25,2.125;1,1;mcl_inventory_empty_armor_slot_boots.png]" end if inv:get_stack("offhand", 1):is_empty() then - armor_slot_imgs = armor_slot_imgs .. "image[1.5,2.025;1,1;mcl_inventory_empty_armor_slot_shield.png]" + armor_slot_imgs = armor_slot_imgs .. "image[2.25,1.25;1,1;mcl_inventory_empty_armor_slot_shield.png]" end local stack_size = get_stack_size(player) -- Survival inventory slots - main_list = "list[current_player;main;0,3.75;9,3;9]" .. - mcl_formspec.get_itemslot_bg(0, 3.75, 9, 3) .. + main_list = table.concat({ + mcl_formspec.get_itemslot_bg_v4(0.375, 3.375, 9, 3), + "list[current_player;main;0.375,3.375;9,3;9]", -- Armor - "list[current_player;armor;2.5,1.3;1,1;1]" .. - "list[current_player;armor;2.5,2.75;1,1;2]" .. - "list[current_player;armor;5.5,1.3;1,1;3]" .. - "list[current_player;armor;5.5,2.75;1,1;4]" .. - mcl_formspec.get_itemslot_bg(2.5, 1.3, 1, 1) .. - mcl_formspec.get_itemslot_bg(2.5, 2.75, 1, 1) .. - mcl_formspec.get_itemslot_bg(5.5, 1.3, 1, 1) .. - mcl_formspec.get_itemslot_bg(5.5, 2.75, 1, 1) .. - "list[current_player;offhand;1.5,2.025;1,1]" .. - mcl_formspec.get_itemslot_bg(1.5, 2.025, 1, 1) .. - armor_slot_imgs .. + mcl_formspec.get_itemslot_bg_v4(3.5, 0.375, 1, 1), + mcl_formspec.get_itemslot_bg_v4(3.5, 2.125, 1, 1), + mcl_formspec.get_itemslot_bg_v4(7.25, 0.375, 1, 1), + mcl_formspec.get_itemslot_bg_v4(7.25, 2.125, 1, 1), + "list[current_player;armor;3.5,0.375;1,1;1]", + "list[current_player;armor;3.5,2.125;1,1;2]", + "list[current_player;armor;7.25,0.375;1,1;3]", + "list[current_player;armor;7.25,2.125;1,1;4]", + + -- Offhand + mcl_formspec.get_itemslot_bg_v4(2.25, 1.25, 1, 1), + "list[current_player;offhand;2.25,1.25;1,1]", + + armor_slot_imgs, -- Player preview - mcl_player.get_player_formspec_model(player, 3.9, 1.4, 1.2333, 2.4666, "") .. + "image[4.75,0.33;2.25,2.83;mcl_inventory_background9.png;2]", + mcl_player.get_player_formspec_model(player, 4.75, 0.45, 2.25, 2.75, ""), -- Crafting guide button - "image_button[9,1;1,1;craftguide_book.png;__mcl_craftguide;]" .. - "tooltip[__mcl_craftguide;" .. F(S("Recipe book")) .. "]" .. + "image_button[11.575,0.825;1.1,1.1;craftguide_book.png;__mcl_craftguide;]", + "tooltip[__mcl_craftguide;" .. F(S("Recipe book")) .. "]", -- Help button - "image_button[9,2;1,1;doc_button_icon_lores.png;__mcl_doc;]" .. - "tooltip[__mcl_doc;" .. F(S("Help")) .. "]" .. + "image_button[11.575,2.075;1.1,1.1;doc_button_icon_lores.png;__mcl_doc;]", + "tooltip[__mcl_doc;" .. F(S("Help")) .. "]", -- Advancements button - "image_button[9,3;1,1;mcl_achievements_button.png;__mcl_achievements;]" .. + "image_button[11.575,3.3;1.1,1.1;mcl_achievements_button.png;__mcl_achievements;]" .. --"style_type[image_button;border=;bgimg=;bgimg_pressed=]" .. "tooltip[__mcl_achievements;" .. F(S("Advancements")) .. "]" .. -- Switch stack size button - "image_button[9,4;1,1;default_apple.png;__switch_stack;]" .. - "label[9.4,4.4;" .. F(C("#FFFFFF", stack_size ~= 1 and stack_size or "")) .. "]" .. - "tooltip[__switch_stack;" .. F(S("Switch stack size")) .. "]" + "image_button[11.575,4.575;1.1,1.1;default_apple.png;__switch_stack;]", + "label[12.275,5.28;" .. F(C("#FFFFFF", tostring(stack_size ~= 1 and stack_size or ""))) .. "]", + "tooltip[__switch_stack;" .. F(S("Switch stack size")) .. "]", - -- Skins button - if minetest.global_exists("mcl_skins") then - main_list = main_list .. - "image_button[9,5;1,1;mcl_skins_button.png;__mcl_skins;]" .. - "tooltip[__mcl_skins;" .. F(S("Select player skin")) .. "]" - end + -- Skins button + "image_button[11.575,5.825;1.1,1.1;mcl_skins_button.png;__mcl_skins;]", + "tooltip[__mcl_skins;" .. F(S("Select player skin")) .. "]", + }) -- For shortcuts listrings = listrings .. @@ -420,29 +449,16 @@ function mcl_inventory.set_creative_formspec(player) "listring[current_player;main]" else -- Creative inventory slots - main_list = "list[detached:creative_" .. playername .. ";main;0,1.75;9,5;" .. tostring(start_i) .. "]" .. - mcl_formspec.get_itemslot_bg(0, 1.75, 9, 5) .. + main_list = table.concat({ + mcl_formspec.get_itemslot_bg_v4(0.375, 0.875, 9, 5), + "list[detached:creative_" .. playername .. ";main;0.375,0.875;9,5;" .. tostring(start_i) .. "]", -- Page buttons - "label[9.0,5.5;" .. F(S("@1/@2", pagenum, pagemax)) .. "]" .. - "image_button[9.0,6.0;0.7,0.7;crafting_creative_prev.png;creative_prev;]" .. - "image_button[9.5,6.0;0.7,0.7;crafting_creative_next.png;creative_next;]" + "label[11.65,5.6;" .. F(S("@1 / @2", pagenum, pagemax)) .. "]", + "image_button[11.575,5.83;0.55,1.1;crafting_creative_prev.png;creative_prev;]", + "image_button[12.075,5.83;0.55,1.1;crafting_creative_next.png;creative_next;]", + }) end - local tab_icon = { - blocks = "mcl_core:brick_block", - deco = "mcl_flowers:peony", - redstone = "mesecons:redstone", - rail = "mcl_minecarts:golden_rail", - misc = "mcl_buckets:bucket_lava", - nix = "mcl_compass:compass", - food = "mcl_core:apple", - tools = "mcl_core:axe_iron", - combat = "mcl_core:sword_gold", - mobs = "mobs_mc:cow", - brew = "mcl_potions:dragon_breath", - matr = "mcl_core:stick", - inv = "mcl_chests:chest", - } local function tab(current_tab, this_tab) local bg_img if current_tab == this_tab then @@ -450,59 +466,66 @@ function mcl_inventory.set_creative_formspec(player) else bg_img = "crafting_creative_inactive" .. hoch[this_tab] .. ".png" end - return "style[" .. this_tab .. ";border=false;bgimg=;bgimg_pressed=]" .. - "item_image_button[" .. boffset[this_tab] .. ";1,1;" .. tab_icon[this_tab] .. ";" .. this_tab .. ";]" .. - "image[" .. offset[this_tab] .. ";1.5,1.44;" .. bg_img .. "]" + return table.concat({ + "style[" .. this_tab .. ";border=false;bgimg=;bgimg_pressed=;noclip=true]", + "image[" .. offset[this_tab] .. ";1.5,1.44;" .. bg_img .. "]", + "item_image_button[" .. boffset[this_tab] .. ";1,1;" .. tab_icon[this_tab] .. ";" .. this_tab .. ";]", + "tooltip[blocks;" .. F(filtername[this_tab]) .. "]" + }) end local caption = "" if name ~= "inv" and filtername[name] then - caption = "label[0,1.2;" .. F(minetest.colorize("#313131", filtername[name])) .. "]" + caption = "label[0.375,0.375;" .. F(minetest.colorize("#313131", filtername[name])) .. "]" end - local formspec = "size[10,9.3]" .. - "no_prepend[]" .. - mcl_vars.gui_nonbg .. mcl_vars.gui_bg_color .. - "background[-0.19,-0.25;10.5,9.87;" .. inv_bg .. "]" .. - "label[-5,-5;" .. name .. "]" .. - tab(name, "blocks") .. - "tooltip[blocks;" .. F(filtername["blocks"]) .. "]" .. - tab(name, "deco") .. - "tooltip[deco;" .. F(filtername["deco"]) .. "]" .. - tab(name, "redstone") .. - "tooltip[redstone;" .. F(filtername["redstone"]) .. "]" .. - tab(name, "rail") .. - "tooltip[rail;" .. F(filtername["rail"]) .. "]" .. - tab(name, "misc") .. - "tooltip[misc;" .. F(filtername["misc"]) .. "]" .. - tab(name, "nix") .. - "tooltip[nix;" .. F(filtername["nix"]) .. "]" .. - caption .. - "list[current_player;main;0,7;9,1;]" .. - mcl_formspec.get_itemslot_bg(0, 7, 9, 1) .. - main_list .. - tab(name, "food") .. - "tooltip[food;" .. F(filtername["food"]) .. "]" .. - tab(name, "tools") .. - "tooltip[tools;" .. F(filtername["tools"]) .. "]" .. - tab(name, "combat") .. - "tooltip[combat;" .. F(filtername["combat"]) .. "]" .. - tab(name, "mobs") .. - "tooltip[mobs;" .. F(filtername["mobs"]) .. "]" .. - tab(name, "brew") .. - "tooltip[brew;" .. F(filtername["brew"]) .. "]" .. - tab(name, "matr") .. - "tooltip[matr;" .. F(filtername["matr"]) .. "]" .. - tab(name, "inv") .. - "tooltip[inv;" .. F(filtername["inv"]) .. "]" .. - "list[detached:trash;main;9,7;1,1;]" .. - mcl_formspec.get_itemslot_bg(9, 7, 1, 1) .. - "image[9,7;1,1;crafting_creative_trash.png]" .. - listrings + local formspec = table.concat({ + "formspec_version[6]", + "size[13,8.75]", + + "style_type[image;noclip=true]", + + -- Hotbar + mcl_formspec.get_itemslot_bg_v4(0.375, 7.375, 9, 1), + "list[current_player;main;0.375,7.375;9,1;]", + + -- Trash + mcl_formspec.get_itemslot_bg_v4(11.625, 7.375, 1, 1, mcl_formspec.itemslot_border_size, + "crafting_creative_trash.png"), + "list[detached:trash;main;11.625,7.375;1,1;]", + + main_list, + + caption, + + listrings, + + tab(name, "blocks"), + tab(name, "deco"), + tab(name, "redstone"), + tab(name, "rail"), + tab(name, "misc"), + tab(name, "nix"), + + tab(name, "food"), + tab(name, "tools"), + tab(name, "combat"), + tab(name, "mobs"), + tab(name, "brew"), + tab(name, "matr"), + tab(name, "inv"), + }) if name == "nix" then - formspec = formspec .. "field[5.3,1.34;4,0.75;search;;" .. minetest.formspec_escape(filter) .. "]" - formspec = formspec .. "field_close_on_enter[search;false]" + if filter == nil then + filter = "" + end + + formspec = formspec .. table.concat({ + "field[5.325,0.15;6.1,0.6;search;;" .. minetest.formspec_escape(filter) .. "]", + "field_close_on_enter[search;false]", + "set_focus[search;true]", + }) end if pagenum then formspec = formspec .. "p" .. tostring(pagenum) end player:set_inventory_formspec(formspec) @@ -629,7 +652,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) players[name].filter = "" end - mcl_inventory.set_creative_formspec(player, start_i, start_i / (9 * 5) + 1, inv_size, false, page, filter) + mcl_inventory.set_creative_formspec(player) end) @@ -655,39 +678,6 @@ if minetest.is_creative_enabled("") then end end end - - mcl_inventory.update_inventory_formspec = function(player) - local page - - local name = player:get_player_name() - - if players[name].page then - page = players[name].page - else - page = "nix" - end - - -- Figure out current scroll bar from formspec - --local formspec = player:get_inventory_formspec() - local start_i = players[name].start_i - - local inv_size - if page == "nix" then - local inv = minetest.get_inventory({ type = "detached", name = "creative_" .. name }) - inv_size = inv:get_size("main") - elseif page and page ~= "inv" then - inv_size = #(inventory_lists[page]) - else - inv_size = 0 - end - - local filter = players[name].filter - if filter == nil then - filter = "" - end - - mcl_inventory.set_creative_formspec(player, start_i, start_i / (9 * 5) + 1, inv_size, false, page, filter) - end end minetest.register_on_joinplayer(function(player) From 9831f2c25be98dfa5cf371a14c9c25d671ca703a Mon Sep 17 00:00:00 2001 From: AFCMS Date: Sat, 8 Oct 2022 00:15:38 +0200 Subject: [PATCH 44/82] Document `mcl_formspec` API --- mods/HUD/mcl_formspec/API.md | 40 ++++++++++++++++++++++++++++++++++ mods/HUD/mcl_formspec/init.lua | 2 ++ 2 files changed, 42 insertions(+) diff --git a/mods/HUD/mcl_formspec/API.md b/mods/HUD/mcl_formspec/API.md index e69de29bb..64795f8c3 100644 --- a/mods/HUD/mcl_formspec/API.md +++ b/mods/HUD/mcl_formspec/API.md @@ -0,0 +1,40 @@ +# MineClone2 Formspec API + +## `mcl_formspec.label_color` + +Contains the color used for formspec labels, currently `#313131`. + +## `mcl_formspec.get_itemslot_bg(x, y, w, h)` + +Get the background of inventory slots (formspec version = 1) + +ex: + +```lua +local formspec = table.concat({ + mcl_formspec.get_itemslot_bg(0, 0, 5, 2), + "list[current_player;super_inventory;0,0;5,2;]", +}) +``` + +## `mcl_formspec.get_itemslot_bg_v4(x, y, w, h, size, texture)` + +Get the background of inventory slots (formspec version > 1) + +Works basically the same as `mcl_formspec.get_itemslot_bg(x, y, w, h)` but have more customisation options: + +- `size`: allow you to customize the size of the slot borders, default is 0.05 +- `texture`: allow you to specify a custom texture tu use instead of the default one + +ex: + +```lua +local formspec = table.concat({ + mcl_formspec.get_itemslot_bg_v4(0.375, 0.375, 5, 2, 0.1, "super_slot_background.png"), + "list[current_player;super_inventory;0.375,0.375;5,2;]", +}) +``` + +## `mcl_formspec.itemslot_border_size` + +Contains the default item slot border size used by `mcl_formspec.get_itemslot_bg_v4`, currently 0.05 diff --git a/mods/HUD/mcl_formspec/init.lua b/mods/HUD/mcl_formspec/init.lua index 69ef23e08..d449e937f 100644 --- a/mods/HUD/mcl_formspec/init.lua +++ b/mods/HUD/mcl_formspec/init.lua @@ -2,6 +2,7 @@ mcl_formspec = {} mcl_formspec.label_color = "#313131" +---Get the background of inventory slots (formspec version = 1) ---@param x number ---@param y number ---@param w number @@ -32,6 +33,7 @@ end mcl_formspec.itemslot_border_size = 0.05 +---Get the background of inventory slots (formspec version > 1) ---@param x number ---@param y number ---@param w integer From ecb4c82600d153acb47d0d346d0d3dbbcc7d22a6 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Sat, 15 Oct 2022 12:37:00 +0200 Subject: [PATCH 45/82] Anvil Formspec - anvil formspec - hammer icon - use new vectors - add some type annotations - optimize textures (some of them by 95%) --- mods/ITEMS/mcl_anvils/init.lua | 188 ++++++++++++++--------- textures/mcl_anvils_inventory_arrow.png | Bin 0 -> 238 bytes textures/mcl_anvils_inventory_cross.png | Bin 0 -> 133 bytes textures/mcl_anvils_inventory_hammer.png | Bin 0 -> 177 bytes 4 files changed, 117 insertions(+), 71 deletions(-) create mode 100644 textures/mcl_anvils_inventory_arrow.png create mode 100644 textures/mcl_anvils_inventory_cross.png create mode 100644 textures/mcl_anvils_inventory_hammer.png diff --git a/mods/ITEMS/mcl_anvils/init.lua b/mods/ITEMS/mcl_anvils/init.lua index a56299cd9..9ff9f7750 100644 --- a/mods/ITEMS/mcl_anvils/init.lua +++ b/mods/ITEMS/mcl_anvils/init.lua @@ -1,4 +1,6 @@ local S = minetest.get_translator(minetest.get_current_modname()) +local F = minetest.formspec_escape +local C = minetest.colorize local MAX_NAME_LENGTH = 35 local MAX_WEAR = 65535 @@ -10,41 +12,65 @@ local MATERIAL_TOOL_REPAIR_BOOST = { MAX_WEAR, -- 100% } +---@param set_name? string local function get_anvil_formspec(set_name) if not set_name then set_name = "" end - return "size[9,8.75]".. - "background[-0.19,-0.25;9.41,9.49;mcl_anvils_inventory.png]".. - "label[0,4.0;"..minetest.formspec_escape(minetest.colorize("#313131", S("Inventory"))).."]".. - "list[current_player;main;0,4.5;9,3;9]".. - mcl_formspec.get_itemslot_bg(0,4.5,9,3).. - "list[current_player;main;0,7.74;9,1;]".. - mcl_formspec.get_itemslot_bg(0,7.74,9,1).. - "list[context;input;1,2.5;1,1;]".. - mcl_formspec.get_itemslot_bg(1,2.5,1,1).. - "list[context;input;4,2.5;1,1;1]".. - mcl_formspec.get_itemslot_bg(4,2.5,1,1).. - "list[context;output;8,2.5;1,1;]".. - mcl_formspec.get_itemslot_bg(8,2.5,1,1).. - "label[3,0.1;"..minetest.formspec_escape(minetest.colorize("#313131", S("Repair and Name"))).."]".. - "field[3.25,1;4,1;name;;"..minetest.formspec_escape(set_name).."]".. - "field_close_on_enter[name;false]".. - "button[7,0.7;2,1;name_button;"..minetest.formspec_escape(S("Set Name")).."]".. - "listring[context;output]".. - "listring[current_player;main]".. - "listring[context;input]".. - "listring[current_player;main]" + + return table.concat({ + "formspec_version[4]", + "size[11.75,10.425]", + + "label[4.125,0.375;" .. F(C(mcl_formspec.label_color, S("Repair and Name"))) .. "]", + + "image[0.875,0.375;1.75,1.75;mcl_anvils_inventory_hammer.png]", + + "field[4.125,0.75;7.25,1;name;;" .. F(set_name) .. "]", + "field_close_on_enter[name;false]", + "set_focus[name;true]", + + mcl_formspec.get_itemslot_bg_v4(1.625, 2.6, 1, 1), + "list[context;input;1.625,2.6;1,1;]", + + "image[3.5,2.6;1,1;mcl_anvils_inventory_cross.png]", + + mcl_formspec.get_itemslot_bg_v4(5.375, 2.6, 1, 1), + "list[context;input;5.375,2.6;1,1;1]", + + "image[6.75,2.6;2,1;mcl_anvils_inventory_arrow.png]", + + mcl_formspec.get_itemslot_bg_v4(9.125, 2.6, 1, 1), + "list[context;output;9.125,2.6;1,1;]", + + -- Player Inventory + + mcl_formspec.get_itemslot_bg_v4(0.375, 5.1, 9, 3), + "list[current_player;main;0.375,5.1;9,3;9]", + + mcl_formspec.get_itemslot_bg_v4(0.375, 9.05, 9, 1), + "list[current_player;main;0.375,9.05;9,1;]", + + -- Listrings + + "listring[context;output]", + "listring[current_player;main]", + "listring[context;input]", + "listring[current_player;main]", + }) end -- Given a tool and material stack, returns how many items of the material stack -- needs to be used up to repair the tool. +---@param tool ItemStack +---@param material ItemStack +---@return integer local function get_consumed_materials(tool, material) local wear = tool:get_wear() --local health = (MAX_WEAR - wear) local matsize = material:get_count() local materials_used = 0 - for m=1, math.min(4, matsize) do + for m = 1, math.min(4, matsize) do materials_used = materials_used + 1 if (wear - MATERIAL_TOOL_REPAIR_BOOST[m]) <= 0 then break @@ -53,6 +79,9 @@ local function get_consumed_materials(tool, material) return materials_used end +---@param table table +---@param value any +---@return boolean local function contains(table, value) for _, i in pairs(table) do if i == value then @@ -66,6 +95,8 @@ end -- Returns ("tool", input1, input2) if input1 is tool and input2 is material. -- Returns ("material", input2, input1) if input1 is material and input2 is tool. -- Returns nil otherwise. +---@param input1 ItemStack +---@param input2 ItemStack local function distinguish_tool_and_material(input1, input2) local def1 = input1:get_definition() local def2 = input2:get_definition() @@ -84,7 +115,8 @@ local function distinguish_tool_and_material(input1, input2) end end --- Helper function to make sure update_anvil_slots NEVER overstacks the output slot +---Helper function to make sure update_anvil_slots NEVER overstacks the output slot +---@param stack ItemStack local function fix_stack_size(stack) if not stack or stack == "" then return "" end local count = stack:get_count() @@ -99,6 +131,7 @@ end -- Update the inventory slots of an anvil node. -- meta: Metadata of anvil node +---@param meta NodeMetaRef local function update_anvil_slots(meta) local inv = meta:get_inventory() local new_name = meta:get_string("set_name") @@ -137,7 +170,7 @@ local function update_anvil_slots(meta) name_item = input1 new_output = name_item - -- Tool + repair item + -- Tool + repair item else -- Any tool can have a repair item. This may be defined in the tool's item definition -- as an itemstring in the field `_repair_material`. Only if this field is set, the @@ -185,7 +218,7 @@ local function update_anvil_slots(meta) new_output = "" end end - -- Exactly 1 input slot occupied + -- Exactly 1 input slot occupied elseif (not input1:is_empty() and input2:is_empty()) or (input1:is_empty() and not input2:is_empty()) then -- Just rename item if input1:is_empty() then @@ -231,28 +264,32 @@ local function update_anvil_slots(meta) end end --- Drop input items of anvil at pos with metadata meta +---Drop input items of anvil at pos with metadata meta +---@param pos Vector +---@param meta NodeMetaRef local function drop_anvil_items(pos, meta) local inv = meta:get_inventory() - for i=1, inv:get_size("input") do + for i = 1, inv:get_size("input") do local stack = inv:get_stack("input", i) if not stack:is_empty() then - local p = {x=pos.x+math.random(0, 10)/10-0.5, y=pos.y, z=pos.z+math.random(0, 10)/10-0.5} + local p = vector.offset(pos, math.random(0, 10) / 10 - 0.5, 0, math.random(0, 10) / 10 - 0.5) minetest.add_item(p, stack) end end end +---@param pos Vector +---@param node node local function damage_particles(pos, node) minetest.add_particlespawner({ amount = 30, time = 0.1, - minpos = vector.add(pos, {x=-0.5, y=-0.5, z=-0.5}), - maxpos = vector.add(pos, {x=0.5, y=-0.25, z=0.5}), - minvel = {x=-0.5, y=0.05, z=-0.5}, - maxvel = {x=0.5, y=0.3, z=0.5}, - minacc = {x=0, y=-9.81, z=0}, - maxacc = {x=0, y=-9.81, z=0}, + minpos = vector.offset(pos, -0.5, -0.5, -0.5), + maxpos = vector.offset(pos, 0.5, -0.25, 0.5), + minvel = vector.new(-0.5, 0.05, -0.5), + maxvel = vector.new(0.5, 0.3, 0.5), + minacc = vector.new(0, -9.81, 0), + maxacc = vector.new(0, -9.81, 0), minexptime = 0.1, maxexptime = 0.5, minsize = 0.4, @@ -267,12 +304,12 @@ local function destroy_particles(pos, node) minetest.add_particlespawner({ amount = math.random(20, 30), time = 0.1, - minpos = vector.add(pos, {x=-0.4, y=-0.4, z=-0.4}), - maxpos = vector.add(pos, {x=0.4, y=0.4, z=0.4}), - minvel = {x=-0.5, y=-0.1, z=-0.5}, - maxvel = {x=0.5, y=0.2, z=0.5}, - minacc = {x=0, y=-9.81, z=0}, - maxacc = {x=0, y=-9.81, z=0}, + minpos = vector.offset(pos, -0.4, -0.4, -0.4), + maxpos = vector.offset(pos, 0.4, 0.4, 0.4), + minvel = vector.new(-0.5, -0.1, -0.5), + maxvel = vector.new(0.5, 0.2, 0.5), + minacc = vector.new(0, -9.81, 0), + maxacc = vector.new(0, -9.81, 0), minexptime = 0.2, maxexptime = 0.65, minsize = 0.8, @@ -289,28 +326,29 @@ end local function damage_anvil(pos) local node = minetest.get_node(pos) if node.name == "mcl_anvils:anvil" then - minetest.swap_node(pos, {name="mcl_anvils:anvil_damage_1", param2=node.param2}) + minetest.swap_node(pos, { name = "mcl_anvils:anvil_damage_1", param2 = node.param2 }) damage_particles(pos, node) - minetest.sound_play(mcl_sounds.node_sound_metal_defaults().dig, {pos=pos, max_hear_distance=16}, true) + minetest.sound_play(mcl_sounds.node_sound_metal_defaults().dig, { pos = pos, max_hear_distance = 16 }, true) return false elseif node.name == "mcl_anvils:anvil_damage_1" then - minetest.swap_node(pos, {name="mcl_anvils:anvil_damage_2", param2=node.param2}) + minetest.swap_node(pos, { name = "mcl_anvils:anvil_damage_2", param2 = node.param2 }) damage_particles(pos, node) - minetest.sound_play(mcl_sounds.node_sound_metal_defaults().dig, {pos=pos, max_hear_distance=16}, true) + minetest.sound_play(mcl_sounds.node_sound_metal_defaults().dig, { pos = pos, max_hear_distance = 16 }, true) return false elseif node.name == "mcl_anvils:anvil_damage_2" then -- Destroy anvil local meta = minetest.get_meta(pos) drop_anvil_items(pos, meta) - minetest.sound_play(mcl_sounds.node_sound_metal_defaults().dug, {pos=pos, max_hear_distance=16}, true) + minetest.sound_play(mcl_sounds.node_sound_metal_defaults().dug, { pos = pos, max_hear_distance = 16 }, true) minetest.remove_node(pos) destroy_particles(pos, node) - minetest.check_single_for_falling({x=pos.x, y=pos.y+1, z=pos.z}) + minetest.check_single_for_falling(vector.offset(pos, 0, 1, 0)) return true end end --- Roll a virtual dice and damage anvil at a low chance. +---Roll a virtual dice and damage anvil at a low chance. +---@param pos Vector local function damage_anvil_by_using(pos) local r = math.random(1, 100) -- 12% chance @@ -321,25 +359,30 @@ local function damage_anvil_by_using(pos) end end +---@param pos Vector +---@param distance number local function damage_anvil_by_falling(pos, distance) local r = math.random(1, 100) if distance > 1 then - if r <= (5*distance) then + if r <= (5 * distance) then damage_anvil(pos) end end end +---@type nodebox local anvilbox = { type = "fixed", fixed = { { -8 / 16, -8 / 16, -6 / 16, 8 / 16, 8 / 16, 6 / 16 }, }, } + +---@type node_definition local anvildef = { - groups = {pickaxey=1, falling_node=1, falling_node_damage=1, crush_after_fall=1, deco_block=1, anvil=1}, - tiles = {"mcl_anvils_anvil_top_damaged_0.png^[transformR90", "mcl_anvils_anvil_base.png", "mcl_anvils_anvil_side.png"}, - use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "opaque" or false, + groups = { pickaxey = 1, falling_node = 1, falling_node_damage = 1, crush_after_fall = 1, deco_block = 1, anvil = 1 }, + tiles = { "mcl_anvils_anvil_top_damaged_0.png^[transformR90", "mcl_anvils_anvil_base.png", "mcl_anvils_anvil_side.png" }, + use_texture_alpha = "opaque", _tt_help = S("Repair and rename items"), paramtype = "light", sunlight_propagates = true, @@ -353,7 +396,7 @@ local anvildef = { { -5 / 16, -4 / 16, -4 / 16, 5 / 16, -3 / 16, 4 / 16 }, { -4 / 16, -3 / 16, -2 / 16, 4 / 16, 2 / 16, 2 / 16 }, { -8 / 16, 2 / 16, -5 / 16, 8 / 16, 8 / 16, 5 / 16 }, - } + }, }, selection_box = anvilbox, collision_box = anvilbox, @@ -416,7 +459,7 @@ local anvildef = { local meta = minetest.get_meta(pos) if from_list == "output" and to_list == "input" then local inv = meta:get_inventory() - for i=1, inv:get_size("input") do + for i = 1, inv:get_size("input") do if i ~= to_index then local istack = inv:get_stack("input", i) istack:set_count(math.max(0, istack:get_count() - count)) @@ -504,22 +547,20 @@ local anvildef = { minetest.record_protection_violation(pos, sender_name) return end - if fields.name_button or fields.name then - local set_name - if fields.name == nil then - set_name = "" - else - set_name = fields.name - end + + if fields.name then local meta = minetest.get_meta(pos) + -- Limit name length - set_name = string.sub(set_name, 1, MAX_NAME_LENGTH) + local set_name = string.sub(fields.name, 1, MAX_NAME_LENGTH) + meta:set_string("set_name", set_name) update_anvil_slots(meta) meta:set_string("formspec", get_anvil_formspec(set_name)) end end, } + if minetest.get_modpath("screwdriver") then anvildef.on_rotate = screwdriver.rotate_simple end @@ -529,27 +570,32 @@ anvildef0.description = S("Anvil") anvildef0._doc_items_longdesc = S("The anvil allows you to repair tools and armor, and to give names to items. It has a limited durability, however. Don't let it fall on your head, it could be quite painful!") anvildef0._doc_items_usagehelp = -S("To use an anvil, rightclick it. An anvil has 2 input slots (on the left) and one output slot.").."\n".. -S("To rename items, put an item stack in one of the item slots while keeping the other input slot empty. Type in a name, hit enter or “Set Name”, then take the renamed item from the output slot.").."\n".. -S("There are two possibilities to repair tools (and armor):").."\n".. -S("• Tool + Tool: Place two tools of the same type in the input slots. The “health” of the repaired tool is the sum of the “health” of both input tools, plus a 12% bonus.").."\n".. -S("• Tool + Material: Some tools can also be repaired by combining them with an item that it's made of. For example, iron pickaxes can be repaired with iron ingots. This repairs the tool by 25%.").."\n".. -S("Armor counts as a tool. It is possible to repair and rename a tool in a single step.").."\n\n".. -S("The anvil has limited durability and 3 damage levels: undamaged, slightly damaged and very damaged. Each time you repair or rename something, there is a 12% chance the anvil gets damaged. Anvils also have a chance of being damaged when they fall by more than 1 block. If a very damaged anvil is damaged again, it is destroyed.") +S("To use an anvil, rightclick it. An anvil has 2 input slots (on the left) and one output slot.") .. "\n" .. + S("To rename items, put an item stack in one of the item slots while keeping the other input slot empty. Type in a name, hit enter or “Set Name”, then take the renamed item from the output slot.") + .. "\n" .. + S("There are two possibilities to repair tools (and armor):") .. "\n" .. + S("• Tool + Tool: Place two tools of the same type in the input slots. The “health” of the repaired tool is the sum of the “health” of both input tools, plus a 12% bonus.") + .. "\n" .. + S("• Tool + Material: Some tools can also be repaired by combining them with an item that it's made of. For example, iron pickaxes can be repaired with iron ingots. This repairs the tool by 25%.") + .. "\n" .. + S("Armor counts as a tool. It is possible to repair and rename a tool in a single step.") .. "\n\n" .. + S("The anvil has limited durability and 3 damage levels: undamaged, slightly damaged and very damaged. Each time you repair or rename something, there is a 12% chance the anvil gets damaged. Anvils also have a chance of being damaged when they fall by more than 1 block. If a very damaged anvil is damaged again, it is destroyed.") local anvildef1 = table.copy(anvildef) anvildef1.description = S("Slightly Damaged Anvil") anvildef1._doc_items_create_entry = false anvildef1.groups.anvil = 2 anvildef1._doc_items_create_entry = false -anvildef1.tiles = {"mcl_anvils_anvil_top_damaged_1.png^[transformR90", "mcl_anvils_anvil_base.png", "mcl_anvils_anvil_side.png"} +anvildef1.tiles = { "mcl_anvils_anvil_top_damaged_1.png^[transformR90", "mcl_anvils_anvil_base.png", + "mcl_anvils_anvil_side.png" } local anvildef2 = table.copy(anvildef) anvildef2.description = S("Very Damaged Anvil") anvildef2._doc_items_create_entry = false anvildef2.groups.anvil = 3 anvildef2._doc_items_create_entry = false -anvildef2.tiles = {"mcl_anvils_anvil_top_damaged_2.png^[transformR90", "mcl_anvils_anvil_base.png", "mcl_anvils_anvil_side.png"} +anvildef2.tiles = { "mcl_anvils_anvil_top_damaged_2.png^[transformR90", "mcl_anvils_anvil_base.png", + "mcl_anvils_anvil_side.png" } minetest.register_node("mcl_anvils:anvil", anvildef0) minetest.register_node("mcl_anvils:anvil_damage_1", anvildef1) @@ -562,7 +608,7 @@ if minetest.get_modpath("mcl_core") then { "mcl_core:ironblock", "mcl_core:ironblock", "mcl_core:ironblock" }, { "", "mcl_core:iron_ingot", "" }, { "mcl_core:iron_ingot", "mcl_core:iron_ingot", "mcl_core:iron_ingot" }, - } + }, }) end diff --git a/textures/mcl_anvils_inventory_arrow.png b/textures/mcl_anvils_inventory_arrow.png new file mode 100644 index 0000000000000000000000000000000000000000..722d6f636d97361752db430b0273faaeb298d183 GIT binary patch literal 238 zcmeAS@N?(olHy`uVBq!ia0vp^EkNwV!VDx+ZYSFUDWL$L5ZC;oT!#D{AkW?1eevSO zbLY;@4+vTg~xS9->MWKHV~Ye8cRrGAA? jl1j^!jDFw!-_5(@h?COJbP0l+XkK?t@pv literal 0 HcmV?d00001 diff --git a/textures/mcl_anvils_inventory_cross.png b/textures/mcl_anvils_inventory_cross.png new file mode 100644 index 0000000000000000000000000000000000000000..ec13632caa7499717fb7ee1b6460672fe86c03fe GIT binary patch literal 133 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDB3?!H8JlO)IgaUj*T=R=^8S-<0Ja>2Z#fulu zojW%_AZR&|&sY-V7tG-B>_!@pqv+}47-DfcIiaC3z#!oO%VMGCXeAMLiKz#sNch@0 b$1pJjzE~c)yqBj3sF=ai)z4*}Q$iB}g&ZXD literal 0 HcmV?d00001 diff --git a/textures/mcl_anvils_inventory_hammer.png b/textures/mcl_anvils_inventory_hammer.png new file mode 100644 index 0000000000000000000000000000000000000000..66c1f5f918a13a368deaa98c5062e6f4c8ae07a8 GIT binary patch literal 177 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`6`n4RAr_~T6BHPnnEw7Zp1|!e z%f9Z%hxt0r39}q49Wg(sOzo}%Y4%VCzR@7Dj5=NNHj9s`=|*yvV&c7ua*wDD2~ ZhRUgDYq(n``~kXw!PC{xWt~$(699$=J)Qsn literal 0 HcmV?d00001 From 7d8a1e1e5f322af2eb199c3199d76715d31f4a1d Mon Sep 17 00:00:00 2001 From: AFCMS Date: Sun, 16 Oct 2022 20:27:51 +0200 Subject: [PATCH 46/82] Fix some merging stuff --- mods/HUD/mcl_inventory/creative.lua | 6 +++--- mods/PLAYER/mcl_gamemode/init.lua | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/mods/HUD/mcl_inventory/creative.lua b/mods/HUD/mcl_inventory/creative.lua index 1e0b493e3..f5e52c443 100644 --- a/mods/HUD/mcl_inventory/creative.lua +++ b/mods/HUD/mcl_inventory/creative.lua @@ -429,9 +429,9 @@ function mcl_inventory.set_creative_formspec(player) "tooltip[__mcl_doc;" .. F(S("Help")) .. "]", -- Advancements button - "image_button[11.575,3.3;1.1,1.1;mcl_achievements_button.png;__mcl_achievements;]" .. - --"style_type[image_button;border=;bgimg=;bgimg_pressed=]" .. - "tooltip[__mcl_achievements;" .. F(S("Advancements")) .. "]" .. + "image_button[11.575,3.325;1.1,1.1;mcl_achievements_button.png;__mcl_achievements;]", + --"style_type[image_button;border=;bgimg=;bgimg_pressed=]", + "tooltip[__mcl_achievements;" .. F(S("Advancements")) .. "]", -- Switch stack size button "image_button[11.575,4.575;1.1,1.1;default_apple.png;__switch_stack;]", diff --git a/mods/PLAYER/mcl_gamemode/init.lua b/mods/PLAYER/mcl_gamemode/init.lua index 7ac814073..5d9267a8c 100644 --- a/mods/PLAYER/mcl_gamemode/init.lua +++ b/mods/PLAYER/mcl_gamemode/init.lua @@ -93,14 +93,14 @@ minetest.register_chatcommand("gamemode", { if not p then return false, S("Player not online") end - if args[1] ~= nil and not in_table(args[1], gamemodes) then + if args[1] ~= nil and not in_table(args[1], mcl_gamemode.gamemodes) then return false, S("Gamemode " .. args[1] .. " does not exist.") elseif args[1] ~= nil then - mcl_inventory.player_set_gamemode(p, args[1]) + mcl_gamemode.set_gamemode(p, args[1]) end --Result message - show effective game mode local gm = p:get_meta():get_string("gamemode") - if gm == "" then gm = gamemodes[1] end + if gm == "" then gm = mcl_gamemode.gamemodes[1] end return true, S("Gamemode for player ") .. n .. S(": " .. gm) end }) From 6a2ad4e6182401c6931b6f0f26e07fd46d7a51ed Mon Sep 17 00:00:00 2001 From: AFCMS Date: Sun, 16 Oct 2022 20:41:35 +0200 Subject: [PATCH 47/82] Materialize the fact that bookshelves only store books --- mods/ITEMS/mcl_books/init.lua | 1 + textures/mcl_book_book_empty_slot.png | Bin 0 -> 115 bytes 2 files changed, 1 insertion(+) create mode 100644 textures/mcl_book_book_empty_slot.png diff --git a/mods/ITEMS/mcl_books/init.lua b/mods/ITEMS/mcl_books/init.lua index e8c53ed8a..7c223030c 100644 --- a/mods/ITEMS/mcl_books/init.lua +++ b/mods/ITEMS/mcl_books/init.lua @@ -392,6 +392,7 @@ local function bookshelf_gui(pos, node, clicker) "label[0.375,0.375;" .. F(C(mcl_formspec.label_color, name)) .. "]", mcl_formspec.get_itemslot_bg_v4(0.375, 0.75, 9, 3), + mcl_formspec.get_itemslot_bg_v4(0.375, 0.75, 9, 3, 0, "mcl_book_book_empty_slot.png"), "list[nodemeta:" .. pos.x .. "," .. pos.y .. "," .. pos.z .. ";main;0.375,0.75;9,3;]", "label[0.375,4.7;" .. F(C(mcl_formspec.label_color, S("Inventory"))) .. "]", diff --git a/textures/mcl_book_book_empty_slot.png b/textures/mcl_book_book_empty_slot.png new file mode 100644 index 0000000000000000000000000000000000000000..e6a50bd9e63f4781283fca8eed19641e3a384734 GIT binary patch literal 115 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`R-P`7Ar`&K2@-Qj;=31C1C&n literal 0 HcmV?d00001 From c8620685c0d94ae0f34cab26948d3fc853d72a23 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Sun, 16 Oct 2022 20:53:25 +0200 Subject: [PATCH 48/82] Move stack size button label lower --- mods/HUD/mcl_inventory/creative.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/HUD/mcl_inventory/creative.lua b/mods/HUD/mcl_inventory/creative.lua index f5e52c443..c7567189d 100644 --- a/mods/HUD/mcl_inventory/creative.lua +++ b/mods/HUD/mcl_inventory/creative.lua @@ -435,7 +435,7 @@ function mcl_inventory.set_creative_formspec(player) -- Switch stack size button "image_button[11.575,4.575;1.1,1.1;default_apple.png;__switch_stack;]", - "label[12.275,5.28;" .. F(C("#FFFFFF", tostring(stack_size ~= 1 and stack_size or ""))) .. "]", + "label[12.275,5.35;" .. F(C("#FFFFFF", tostring(stack_size ~= 1 and stack_size or ""))) .. "]", "tooltip[__switch_stack;" .. F(S("Switch stack size")) .. "]", -- Skins button From 7cf91c79cb1813089874460b821176eaea83d7a8 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Tue, 18 Oct 2022 14:49:21 +0200 Subject: [PATCH 49/82] Smithing Table --- .luarc.json | 22 +++++ mods/ITEMS/mcl_smithing_table/init.lua | 86 +++++++++++------- mods/ITEMS/mcl_smithing_table/mod.conf | 2 +- textures/mcl_smithing_table_bottom.png | Bin 240 -> 284 bytes textures/mcl_smithing_table_front.png | Bin 263 -> 298 bytes .../mcl_smithing_table_inventory_hammer.png | Bin 0 -> 178 bytes textures/mcl_smithing_table_side.png | Bin 241 -> 283 bytes textures/mcl_smithing_table_top.png | Bin 283 -> 320 bytes 8 files changed, 77 insertions(+), 33 deletions(-) create mode 100644 .luarc.json create mode 100644 textures/mcl_smithing_table_inventory_hammer.png diff --git a/.luarc.json b/.luarc.json new file mode 100644 index 000000000..7e9e92042 --- /dev/null +++ b/.luarc.json @@ -0,0 +1,22 @@ +{ + "runtime.version": "LuaJIT", + "diagnostics": { "disable": ["lowercase-global"] }, + "diagnostics.globals": [ + "minetest", + "dump", + "dump2", + "Raycast", + "Settings", + "PseudoRandom", + "PerlinNoise", + "VoxelManip", + "SecureRandom", + "VoxelArea", + "PerlinNoiseMap", + "PcgRandom", + "ItemStack", + "AreaStore", + "vector" + ], + "workspace.ignoreDir": [".luacheckrc"] +} diff --git a/mods/ITEMS/mcl_smithing_table/init.lua b/mods/ITEMS/mcl_smithing_table/init.lua index dbb6c620f..5d0becad7 100644 --- a/mods/ITEMS/mcl_smithing_table/init.lua +++ b/mods/ITEMS/mcl_smithing_table/init.lua @@ -1,11 +1,13 @@ ---[[ -By EliasFleckenstein03 and Code-Sploit -]] +-- By EliasFleckenstein03 and Code-Sploit local S = minetest.get_translator("mcl_smithing_table") +local F = minetest.formspec_escape +local C = minetest.colorize + mcl_smithing_table = {} --- Function to upgrade diamond tool/armor to netherite tool/armor +---Function to upgrade diamond tool/armor to netherite tool/armor +---@param itemstack ItemStack function mcl_smithing_table.upgrade_item(itemstack) local def = itemstack:get_definition() @@ -29,28 +31,48 @@ function mcl_smithing_table.upgrade_item(itemstack) return itemstack end --- Badly copied over from mcl_anvils --- ToDo: Make better formspec +local formspec = table.concat({ + "formspec_version[4]", + "size[11.75,10.425]", -local formspec = "size[9,9]" .. - "background[-0.19,-0.25;9.41,9.49;mcl_smithing_table_inventory.png]".. - "label[0,4.0;" .. minetest.formspec_escape(minetest.colorize(mcl_colors.DARK_GRAY, S("Inventory"))) .. "]" .. - "list[current_player;main;0,4.5;9,3;9]" .. - mcl_formspec.get_itemslot_bg(0,4.5,9,3) .. - "list[current_player;main;0,7.74;9,1;]" .. - mcl_formspec.get_itemslot_bg(0,7.74,9,1) .. - "list[context;diamond_item;1,2.5;1,1;]" .. - mcl_formspec.get_itemslot_bg(1,2.5,1,1) .. - "list[context;netherite;4,2.5;1,1;]" .. - mcl_formspec.get_itemslot_bg(4,2.5,1,1) .. - "list[context;upgraded_item;8,2.5;1,1;]" .. - mcl_formspec.get_itemslot_bg(8,2.5,1,1) .. - "label[3,0.1;" .. minetest.formspec_escape(minetest.colorize(mcl_colors.DARK_GRAY, S("Upgrade Gear"))) .. "]" .. - "listring[context;output]".. - "listring[current_player;main]".. - "listring[context;input]".. - "listring[current_player;main]" + "label[4.125,0.375;" .. F(C(mcl_formspec.label_color, S("Upgrade Gear"))) .. "]", + "image[0.875,0.375;1.75,1.75;mcl_smithing_table_inventory_hammer.png]", + + mcl_formspec.get_itemslot_bg_v4(1.625, 2.6, 1, 1), + "list[context;diamond_item;1.625,2.6;1,1;]", + + "image[3.5,2.6;1,1;mcl_anvils_inventory_cross.png]", + + mcl_formspec.get_itemslot_bg_v4(5.375, 2.6, 1, 1), + "list[context;netherite;5.375,2.6;1,1;]", + + "image[6.75,2.6;2,1;mcl_anvils_inventory_arrow.png]", + + mcl_formspec.get_itemslot_bg_v4(9.125, 2.6, 1, 1), + "list[context;upgraded_item;9.125,2.6;1,1;]", + + -- Player Inventory + + mcl_formspec.get_itemslot_bg_v4(0.375, 5.1, 9, 3), + "list[current_player;main;0.375,5.1;9,3;9]", + + mcl_formspec.get_itemslot_bg_v4(0.375, 9.05, 9, 1), + "list[current_player;main;0.375,9.05;9,1;]", + + -- Listrings + + "listring[context;diamond_item]", + "listring[current_player;main]", + "listring[context;netherite]", + "listring[current_player;main]", + "listring[context;upgraded_item]", + "listring[current_player;main]", + "listring[current_player;main]", + "listring[context;diamond_item]", +}) + +---@param pos Vector local function reset_upgraded_item(pos) local inv = minetest.get_meta(pos):get_inventory() local upgraded_item @@ -66,8 +88,7 @@ minetest.register_node("mcl_smithing_table:table", { description = S("Smithing table"), -- ToDo: Add _doc_items_longdesc and _doc_items_usagehelp - stack_max = 64, - groups = {pickaxey = 2, deco_block = 1}, + groups = { pickaxey = 2, deco_block = 1 }, tiles = { "mcl_smithing_table_top.png", @@ -92,7 +113,8 @@ minetest.register_node("mcl_smithing_table:table", { end, allow_metadata_inventory_put = function(pos, listname, index, stack, player) - if listname == "diamond_item" and mcl_smithing_table.upgrade_item(stack) or listname == "netherite" and stack:get_name() == "mcl_nether:netherite_ingot" then + if listname == "diamond_item" and mcl_smithing_table.upgrade_item(stack) or + listname == "netherite" and stack:get_name() == "mcl_nether:netherite_ingot" then return stack:get_count() end @@ -119,7 +141,7 @@ minetest.register_node("mcl_smithing_table:table", { take_item("netherite") -- ToDo: make epic sound - minetest.sound_play("mcl_smithing_table_upgrade", {pos = pos, max_hear_distance = 16}) + minetest.sound_play("mcl_smithing_table_upgrade", { pos = pos, max_hear_distance = 16 }) end if listname == "upgraded_item" then if stack:get_name() == "mcl_farming:hoe_netherite" then @@ -138,8 +160,8 @@ minetest.register_node("mcl_smithing_table:table", { minetest.register_craft({ output = "mcl_smithing_table:table", recipe = { - {"mcl_core:iron_ingot", "mcl_core:iron_ingot", ""}, - {"group:wood", "group:wood", ""}, - {"group:wood", "group:wood", ""} - } + { "mcl_core:iron_ingot", "mcl_core:iron_ingot", "" }, + { "group:wood", "group:wood", "" }, + { "group:wood", "group:wood", "" } + }, }) diff --git a/mods/ITEMS/mcl_smithing_table/mod.conf b/mods/ITEMS/mcl_smithing_table/mod.conf index aee93fa65..1c12cb483 100644 --- a/mods/ITEMS/mcl_smithing_table/mod.conf +++ b/mods/ITEMS/mcl_smithing_table/mod.conf @@ -1,2 +1,2 @@ name = mcl_smithing_table -depends = mcl_colors, mcl_formspec +depends = mcl_colors, mcl_formspec, mcl_anvils diff --git a/textures/mcl_smithing_table_bottom.png b/textures/mcl_smithing_table_bottom.png index d44c0773ea51d8f2b95c5cfa02d5f54ba6ca1e34..cca0ebf1428aea62b5de7844d76df482482ead40 100644 GIT binary patch delta 269 zcmV+o0rLLv0h|Jm7=H)?0001xk!Usm0084jL_t(2Q+<-L3IZ_@MDqzD<^6%3gtr`4kT*Jw$r;?h zsMT)a9%h_Cp{GfY8z3`UllSx{&-Y0?vq)VYSQH`9SfSJTCRvd`JFRsOj_9}^`e2+? zp5**UR*(=6mesG3OO*;G0Pxm+ON3X{@?IqZSvli=LzLCT#ORc+9q=F0B(kR*)R$iq a8;^gOpes$)gLioV0000(V2XOTbd`kb`f6ZO51%Eu$C85T6hh_gO*zJ zrVw!p1yT%Wr~T@0fjrN%EE{W$vwZsKVpp7@0{BPB3|xF?OBR5~kPOgn3_j{wz#BleBp;hwvVgZ% g7|Y}7ZVA8-;1k#23E5OqA^-pY07*qoM6N<$f^D9B0RR91 delta 246 zcmV%CMPE+C@3f? zDJd!{DlRTAFE1}NG&DFF7eGKjLn0tfJ}^&DPgX4}Sw=T;Rz!SXOp4^0)!m~`z+V5@y<**%XLA(y7vNa6#e5J4^*PhCjzV+_0i};>m9hP`B0a% wQ_43Of1;;Wm!eC!=rx|=5>8=0)sM0K16gc3WlB;-mjD0&07*qoM6N<$f@QZ_0ssI2 diff --git a/textures/mcl_smithing_table_inventory_hammer.png b/textures/mcl_smithing_table_inventory_hammer.png new file mode 100644 index 0000000000000000000000000000000000000000..48a21e97dbb3f3ed76930150de82b93bd2ff227a GIT binary patch literal 178 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`m7Xq+Ar_~T6BHO!RFC{Op1|!e z%eR;3-{e#dA7hT!S(y#IonN>7^xu?L;(Vz&ro)_N3FmA@m7Ofp64sjF(t0y~$Yhcm9(po*u?=43~JgOnzmzu}a;X brOC>0sGz1VDWvBa&=Cxtu6{1-oD!M<5duKG literal 0 HcmV?d00001 diff --git a/textures/mcl_smithing_table_side.png b/textures/mcl_smithing_table_side.png index fbc1a9a23610d4afd2a51f565058a50f74f24e40..d93a7906ce77f831ff3509f956e2114a141308fb 100644 GIT binary patch delta 267 zcmV+m0rdXy0hMA%%S6zJoSKq*=^lNjC>3PKvN-oKlKbquu?wsp4(rYB}xLSB7Y9XUq25rG( z3nf~NSg{yyrbGJ`6-LAZWD~gVW>HnfchKzHX&qH%z5oL#fPW`22$4V<+g3|kfTYWI zE_oQj`~k{hDF8+QR3iZ}oB${;yRJS-kiC5ec6!~9s_)17R{^pt^Btb$K2Xbxhq`H+ zwg6fmRudfqgQt$<0r?|zhv-?+79dyBm|WA|R{-k90Xe81w-f04k?dIkKE;jKtGmh> R+yDRo07*qoL>-||3@o88ogw8JZ5N;woH^!2I4dkX|0KgVGhO01z9+CI^vO)fIjm|0-KGP zl?(R8wLt<&g1ZE522EsC<|hL9{V(w`n827Wxcl$v=PTXRcr7IA>08Gix*005AYXf^-<0S8G$K~yMHb&|^tf-n$8`4SQlS@^2b5DbPy zUAS`N!j&6${{J6%+Dpa?@unribk01WnR9L#HTxBwMbtd1EK6+s83(WXnWx{aFGr94 zyq#?EijyOvv5TU}K$Xl*QeyXg z9~$amXsj1|Tc|Y=#q{GXt!3^aH5EG|04!eSU%W<7ySA!p}$q&*bl3QlP4}hx(TB9G> Ro&W#<07*qoL Date: Sun, 23 Oct 2022 01:03:51 +0200 Subject: [PATCH 50/82] Fix rebase breaking creative digging --- mods/PLAYER/mcl_gamemode/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/PLAYER/mcl_gamemode/init.lua b/mods/PLAYER/mcl_gamemode/init.lua index 5d9267a8c..baee7ca45 100644 --- a/mods/PLAYER/mcl_gamemode/init.lua +++ b/mods/PLAYER/mcl_gamemode/init.lua @@ -69,7 +69,7 @@ minetest.register_on_punchnode(function(pos, node, puncher, pointed_thing) local def = minetest.registered_nodes[node.name] if def then if def.on_destruct then def.on_destruct(pos) end - minetest.remove_node(pos) + minetest.dig_node(pos) return true end end) From 3bbae86bafd476dc4838987381dc7dcb91ae130d Mon Sep 17 00:00:00 2001 From: AFCMS Date: Wed, 9 Nov 2022 20:48:51 +0100 Subject: [PATCH 51/82] Fix this stupid merge conflict --- mods/HUD/mcl_inventory/init.lua | 301 +----------------------------- mods/PLAYER/mcl_gamemode/init.lua | 2 +- 2 files changed, 4 insertions(+), 299 deletions(-) diff --git a/mods/HUD/mcl_inventory/init.lua b/mods/HUD/mcl_inventory/init.lua index 6edfc3d78..52fbd268b 100644 --- a/mods/HUD/mcl_inventory/init.lua +++ b/mods/HUD/mcl_inventory/init.lua @@ -1,300 +1,6 @@ local S = minetest.get_translator(minetest.get_current_modname()) local F = minetest.formspec_escape -mcl_inventory = {} - ---local mod_player = minetest.get_modpath("mcl_player") ---local mod_craftguide = minetest.get_modpath("mcl_craftguide") - ----Returns a single itemstack in the given inventory to the main inventory, or drop it when there's no space left. ----@param itemstack ItemStack ----@param dropper ObjectRef ----@param pos Vector ----@param inv InvRef -local function return_item(itemstack, dropper, pos, inv) - if dropper:is_player() then - -- Return to main inventory - if inv:room_for_item("main", itemstack) then - inv:add_item("main", itemstack) - else - -- Drop item on the ground - local v = dropper:get_look_dir() - local p = vector.offset(pos, 0, 1.2, 0) - p.x = p.x + (math.random(1, 3) * 0.2) - p.z = p.z + (math.random(1, 3) * 0.2) - local obj = minetest.add_item(p, itemstack) - if obj then - v.x = v.x * 4 - v.y = v.y * 4 + 2 - v.z = v.z * 4 - obj:set_velocity(v) - obj:get_luaentity()._insta_collect = false - end - end - else - -- Fallback for unexpected cases - minetest.add_item(pos, itemstack) - end - return itemstack -end - ----Return items in the given inventory list (name) to the main inventory, or drop them if there is no space left. ----@param player ObjectRef ----@param name string -local function return_fields(player, name) - local inv = player:get_inventory() - - ---@diagnostic disable need-check-nil - - local list = inv:get_list(name) - if not list then return end - for i, stack in ipairs(list) do - return_item(stack, player, player:get_pos(), inv) - stack:clear() - inv:set_stack(name, i, stack) - end - - ---@diagnostic enable need-check-nil -end - ----@param player ObjectRef -local function set_inventory(player) - if minetest.is_creative_enabled(player:get_player_name()) then - mcl_inventory.set_creative_formspec(player) - return - end - - local inv = player:get_inventory() - - ---@diagnostic disable need-check-nil - inv:set_width("craft", 2) - inv:set_size("craft", 4) - - local armor_slots = { "helmet", "chestplate", "leggings", "boots" } - local armor_slot_imgs = "" - - for a = 1, 4 do - if inv:get_stack("armor", a + 1):is_empty() then - armor_slot_imgs = armor_slot_imgs .. - "image[0.375," .. - (0.375 + (a - 1) * 1.25) .. ";1,1;mcl_inventory_empty_armor_slot_" .. armor_slots[a] .. ".png]" - end - end - - if inv:get_stack("offhand", 1):is_empty() then - armor_slot_imgs = armor_slot_imgs .. "image[5.375,4.125;1,1;mcl_inventory_empty_armor_slot_shield.png]" - end - - ---@diagnostic enable need-check-nil - - local form = table.concat({ - "formspec_version[6]", - "size[11.75,10.9]", - - --Armor slots - mcl_formspec.get_itemslot_bg_v4(0.375, 0.375, 1, 4), - "list[current_player;armor;0.375,0.375;1,1;1]", - "list[current_player;armor;0.375,1.625;1,1;2]", - "list[current_player;armor;0.375,2.875;1,1;3]", - "list[current_player;armor;0.375,4.125;1,1;4]", - - --Main inventory - mcl_formspec.get_itemslot_bg_v4(0.375, 5.575, 9, 3), - "list[current_player;main;0.375,5.575;9,3;9]", - - --Hotbar - mcl_formspec.get_itemslot_bg_v4(0.375, 9.525, 9, 1), - "list[current_player;main;0.375,9.525;9,1;]", - - --Player model - "image[1.57,0.343;3.62,4.85;mcl_inventory_background9.png;2]", - mcl_player.get_player_formspec_model(player, 1.57, 0.4, 3.62, 4.85, ""), - - --Offhand - mcl_formspec.get_itemslot_bg_v4(5.375, 4.125, 1, 1), - "list[current_player;offhand;5.375,4.125;1,1]", - - armor_slot_imgs, - - --Craft grid - "label[6.61,0.5;" .. F(minetest.colorize(mcl_formspec.label_color, S("Crafting"))) .. "]", - mcl_formspec.get_itemslot_bg_v4(6.625, 0.875, 2, 2), - "list[current_player;craft;6.625,0.875;2,2]", - - "image[9.125,1.5;1,1;crafting_formspec_arrow.png]", - - mcl_formspec.get_itemslot_bg_v4(10.375, 1.5, 1, 1), - "list[current_player;craftpreview;10.375,1.5;1,1;]", - - --Crafting guide button - "image_button[6.575,4.075;1.1,1.1;craftguide_book.png;__mcl_craftguide;]", - "tooltip[__mcl_craftguide;" .. F(S("Recipe book")) .. "]", - - --Help button - "image_button[7.825,4.075;1.1,1.1;doc_button_icon_lores.png;__mcl_doc;]", - "tooltip[__mcl_doc;" .. F(S("Help")) .. "]", - - --Skins button - "image_button[9.075,4.075;1.1,1.1;mcl_skins_button.png;__mcl_skins;]", - "tooltip[__mcl_skins;" .. F(S("Select player skin")) .. "]", - - --Advancements button - "image_button[10.325,4.075;1.1,1.1;mcl_achievements_button.png;__mcl_achievements;]", - "tooltip[__mcl_achievements;" .. F(S("Advancements")) .. "]", - - --Listring - "listring[current_player;main]", - "listring[current_player;armor]", - "listring[current_player;main]", - "listring[current_player;craft]", - "listring[current_player;main]", - }) - - player:set_inventory_formspec(form) -end - --- Drop items in craft grid and reset inventory on closing -minetest.register_on_player_receive_fields(function(player, formname, fields) - if fields.quit then - return_fields(player, "craft") - return_fields(player, "enchanting_lapis") - return_fields(player, "enchanting_item") - if not minetest.is_creative_enabled(player:get_player_name()) and (formname == "" or formname == "main") then - set_inventory(player) - end - end -end) - -mcl_inventory.update_inventory_formspec = set_inventory - --- Drop crafting grid items on leaving -minetest.register_on_leaveplayer(function(player) - return_fields(player, "craft") - return_fields(player, "enchanting_lapis") - return_fields(player, "enchanting_item") -end) - -minetest.register_on_joinplayer(function(player) - --init inventory - local inv = player:get_inventory() - - ---get_inventory can return nil if object isn't a player, but we are sure this is one :) - ---@diagnostic disable need-check-nil - inv:set_width("main", 9) - inv:set_size("main", 36) - inv:set_size("offhand", 1) - ---@diagnostic enable need-check-nil - - --set hotbar size - player:hud_set_hotbar_itemcount(9) - --add hotbar images - player:hud_set_hotbar_image("mcl_inventory_hotbar.png") - player:hud_set_hotbar_selected_image("mcl_inventory_hotbar_selected.png") - - -- In Creative Mode, the initial inventory setup is handled in creative.lua - if not minetest.is_creative_enabled(player:get_player_name()) then - set_inventory(player) - end - - --[[ Make sure the crafting grid is empty. Why? Because the player might have - items remaining in the crafting grid from the previous join; this is likely - when the server has been shutdown and the server didn't clean up the player - inventories. ]] - return_fields(player, "craft") - return_fields(player, "enchanting_item") - return_fields(player, "enchanting_lapis") -end) - - -dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/creative.lua") - -local mt_is_creative_enabled = minetest.is_creative_enabled - -function minetest.is_creative_enabled(name) - if mt_is_creative_enabled(name) then return true end - if not name then return false end - local p = minetest.get_player_by_name(name) - if p then - return p:get_meta():get_string("gamemode") == "creative" - end - return false -end - ---Insta "digging" nodes in gamemode-creative -minetest.register_on_punchnode(function(pos, node, puncher, pointed_thing) - if not puncher or not puncher:is_player() then return end - local name = puncher:get_player_name() - if not minetest.is_creative_enabled(name) then return end - if pointed_thing.type ~= "node" then return end - local def = minetest.registered_nodes[node.name] - if def then - minetest.node_dig(pos, node, puncher) - return true - end -end) - ---Don't subtract from inv when placing in gamemode-creative -minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack, pointed_thing) - if placer and placer:is_player() and minetest.is_creative_enabled(placer:get_player_name()) then return true end -end) - -local function in_table(n, h) - for k, v in pairs(h) do - if v == n then return true end - end - return false -end - -local gamemodes = { - "survival", - "creative" -} - -function mcl_inventory.player_set_gamemode(p, g) - local m = p:get_meta() - m:set_string("gamemode", g) - if g == "survival" then - mcl_experience.setup_hud(p) - mcl_experience.update(p) - elseif g == "creative" then - mcl_experience.remove_hud(p) - end - mcl_meshhand.update_player(p) - set_inventory(p) -end - -minetest.register_chatcommand("gamemode", { - params = S("[] []"), - description = S("Change gamemode (survival/creative) for yourself or player"), - privs = { server = true }, - func = function(n, param) - -- Full input validation ( just for @erlehmann <3 ) - local p - local args = param:split(" ") - if args[2] ~= nil then - p = minetest.get_player_by_name(args[2]) - n = args[2] - else - p = minetest.get_player_by_name(n) - end - if not p then - return false, S("Player not online") - end - if args[1] ~= nil and not in_table(args[1], gamemodes) then - return false, S("Gamemode " .. args[1] .. " does not exist.") - elseif args[1] ~= nil then - mcl_inventory.player_set_gamemode(p, args[1]) - end - - --Result message - show effective game mode - local gm = p:get_meta():get_string("gamemode") - if gm == "" then gm = gamemodes[1] end - return true, S("Gamemode for player ") .. n .. S(": " .. gm) - end -}) -local S = minetest.get_translator(minetest.get_current_modname()) -local F = minetest.formspec_escape - ---get_inventory can return nil if object isn't a player, but we are sure sometimes this is one :) ---@diagnostic disable need-check-nil @@ -381,10 +87,9 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) end end) -if not minetest.is_creative_enabled("") then - function mcl_inventory.update_inventory_formspec(player) - set_inventory(player) - end + +function mcl_inventory.update_inventory_formspec(player) + set_inventory(player) end -- Drop crafting grid items on leaving diff --git a/mods/PLAYER/mcl_gamemode/init.lua b/mods/PLAYER/mcl_gamemode/init.lua index baee7ca45..9b23922a4 100644 --- a/mods/PLAYER/mcl_gamemode/init.lua +++ b/mods/PLAYER/mcl_gamemode/init.lua @@ -69,7 +69,7 @@ minetest.register_on_punchnode(function(pos, node, puncher, pointed_thing) local def = minetest.registered_nodes[node.name] if def then if def.on_destruct then def.on_destruct(pos) end - minetest.dig_node(pos) + minetest.node_dig(pos, node, puncher) return true end end) From 653f82198ee88253e13a6cf77a723e6f51d7702d Mon Sep 17 00:00:00 2001 From: AFCMS Date: Tue, 15 Nov 2022 22:06:53 +0100 Subject: [PATCH 52/82] Apply MysticTempest fixes to enchanting table --- mods/ITEMS/mcl_enchanting/engine.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mods/ITEMS/mcl_enchanting/engine.lua b/mods/ITEMS/mcl_enchanting/engine.lua index 57fde4dd5..01ef51a54 100644 --- a/mods/ITEMS/mcl_enchanting/engine.lua +++ b/mods/ITEMS/mcl_enchanting/engine.lua @@ -516,10 +516,10 @@ function mcl_enchanting.show_enchanting_formspec(player) mcl_formspec.get_itemslot_bg_v4(1, 3.25, 1, 1), "list[current_player;enchanting_item;1,3.25;1,1]", mcl_formspec.get_itemslot_bg_v4(2.25, 3.25, 1, 1), + "image[2.25,3.25;1,1;mcl_enchanting_lapis_background.png]", "list[current_player;enchanting_lapis;2.25,3.25;1,1]", - "image[2.25,2.4;1,1;mcl_enchanting_lapis_background.png]", - "image[4.125,0.375;7.25,4.1;mcl_enchanting_button_background.png]", + "image[4.125,0.56;7.25,4.1;mcl_enchanting_button_background.png]", "label[0.375,4.7;" .. F(C(mcl_formspec.label_color) .. S("Inventory")) .. "]", @@ -574,7 +574,7 @@ function mcl_enchanting.show_enchanting_formspec(player) ending .. ".png;bgimg_hovered=mcl_enchanting_button" .. hover_ending .. ".png;bgimg_pressed=mcl_enchanting_button" .. hover_ending .. ".png]" - .. "button[0,0;7.5,1.3;button_" .. i .. ";]" + .. "button[0,0;7.25,1.3;button_" .. i .. ";]" .. (slot and "image[0,0;1.3,1.3;mcl_enchanting_number_" .. i .. ending .. ".png]" or "") .. (slot and "label[6.8,1;" .. C(can_enchant and "#80FF20" or "#407F10") .. slot.level_requirement .. "]" or "") .. (slot and slot.glyphs or "") From cd6dd4d851e5be504adc0f2c852e939cf9070565 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Wed, 28 Jun 2023 16:16:26 +0200 Subject: [PATCH 53/82] Fix merge conflict (huge chests) --- mods/ITEMS/mcl_chests/init.lua | 2 -- 1 file changed, 2 deletions(-) diff --git a/mods/ITEMS/mcl_chests/init.lua b/mods/ITEMS/mcl_chests/init.lua index 8158b0a32..9e058af2d 100644 --- a/mods/ITEMS/mcl_chests/init.lua +++ b/mods/ITEMS/mcl_chests/init.lua @@ -65,7 +65,6 @@ local entity_animations = { minetest.register_entity("mcl_chests:chest", { initial_properties = { visual = "mesh", - visual_size = { x = 3, y = 3 }, pointable = false, physical = false, static_save = false, @@ -150,7 +149,6 @@ minetest.register_entity("mcl_chests:chest", { local function get_entity_pos(pos, dir, double) pos = vector.copy(pos) - pos.y = pos.y - 0.49 if double then local add, mul, vec, cross = vector.add, vector.multiply, vector.new, vector.cross pos = add(pos, mul(cross(dir, vec(0, 1, 0)), -0.5)) From 0e13190ea48656a3d30e2c75796a1f8a4e3ebbfe Mon Sep 17 00:00:00 2001 From: AFCMS Date: Thu, 29 Jun 2023 08:23:44 +0200 Subject: [PATCH 54/82] Fix reabse problem with `mcl_inventory` --- mods/HUD/mcl_inventory/mod.conf | 5 ----- 1 file changed, 5 deletions(-) diff --git a/mods/HUD/mcl_inventory/mod.conf b/mods/HUD/mcl_inventory/mod.conf index 80aab2ab1..66f175c3b 100644 --- a/mods/HUD/mcl_inventory/mod.conf +++ b/mods/HUD/mcl_inventory/mod.conf @@ -1,10 +1,5 @@ name = mcl_inventory author = BlockMen description = Adds the player inventory and creative inventory. -<<<<<<< HEAD -depends = mcl_init, mcl_formspec, mcl_enchanting, mcl_player -optional_depends = mcl_armor, mcl_brewing, mcl_potions, mcl_enchanting, mcl_craftguide -======= depends = mcl_init, mcl_formspec, mcl_enchanting, mcl_gamemode optional_depends = mcl_armor, mcl_brewing, mcl_potions, mcl_enchanting, mcl_craftguide, mcl_player ->>>>>>> a2429154d (survival inventory tabs API + mcl_gamemode) From 4db0631133f32a7d46fe1604037dfaa2aa2b8a4c Mon Sep 17 00:00:00 2001 From: AFCMS Date: Thu, 29 Jun 2023 08:39:58 +0200 Subject: [PATCH 55/82] `mcl_inventory` creative fixes - Add many comments (I had a really hard time understanding the code) - Add some more type annotations (https://github.com/minetest-toolkit/minetest-lsp-api) - Rename non english variable --- mods/HUD/mcl_inventory/creative.lua | 121 ++++++++++++++++++++-------- mods/PLAYER/mcl_player/init.lua | 2 +- 2 files changed, 90 insertions(+), 33 deletions(-) diff --git a/mods/HUD/mcl_inventory/creative.lua b/mods/HUD/mcl_inventory/creative.lua index c7567189d..a896fa0de 100644 --- a/mods/HUD/mcl_inventory/creative.lua +++ b/mods/HUD/mcl_inventory/creative.lua @@ -3,20 +3,35 @@ local F = minetest.formspec_escape local C = minetest.colorize -- Prepare player info table +---@type table local players = {} -- Containing all the items for each Creative Mode tab +---@type table local inventory_lists = {} ---local mod_player = minetest.get_modpath("mcl_player") - -- Create tables -local builtin_filter_ids = { "blocks", "deco", "redstone", "rail", "food", "tools", "combat", "mobs", "brew", "matr", - "misc", "all" } +---@type string[] +local builtin_filter_ids = { + "blocks", + "deco", + "redstone", + "rail", + "food", + "tools", + "combat", + "mobs", + "brew", + "matr", + "misc", + "all" +} + for _, f in pairs(builtin_filter_ids) do inventory_lists[f] = {} end +---@param tbl string[] local function replace_enchanted_books(tbl) for k, item in ipairs(tbl) do if item:find("mcl_enchanting:book_enchanted") == 1 then @@ -29,21 +44,24 @@ local function replace_enchanted_books(tbl) end end ---[[ Populate all the item tables. We only do this once. Note this code must be -executed after loading all the other mods in order to work. ]] +-- Populate all the item tables. We only do this once. +-- Note this code must be executed after loading all the other mods in order to work. minetest.register_on_mods_loaded(function() for name, def in pairs(minetest.registered_items) do if (not def.groups.not_in_creative_inventory or def.groups.not_in_creative_inventory == 0) and def.description and def.description ~= "" then + ---@param def mt.ItemDef|mt.NodeDef local function is_redstone(def) return def.mesecons or def.groups.mesecon or def.groups.mesecon_conductor_craftable or def.groups.mesecon_effecor_off end + ---@param def mt.ItemDef|mt.NodeDef local function is_tool(def) return def.groups.tool or (def.tool_capabilities and def.tool_capabilities.damage_groups == nil) end + ---@param def mt.ItemDef|mt.NodeDef local function is_weapon_or_armor(def) return def.groups.weapon or def.groups.weapon_ranged or def.groups.ammo or def.groups.combat_item or ( @@ -120,6 +138,11 @@ minetest.register_on_mods_loaded(function() end end) +---@param name string +---@param description string +---@param lang mt.LangCode +---@param filter string +---@return integer local function filter_item(name, description, lang, filter) local desc if not lang then @@ -130,6 +153,8 @@ local function filter_item(name, description, lang, filter) return string.find(name, filter, nil, true) or string.find(desc, filter, nil, true) end +---@param filter string +---@param player mt.PlayerObjectRef local function set_inv_search(filter, player) local playername = player:get_player_name() local inv = minetest.get_inventory({ type = "detached", name = "creative_" .. playername }) @@ -158,6 +183,8 @@ local function set_inv_search(filter, player) inv:set_list("main", creative_list) end +---@param page string +---@param player mt.PlayerObjectRef local function set_inv_page(page, player) local playername = player:get_player_name() local inv = minetest.get_inventory({ type = "detached", name = "creative_" .. playername }) @@ -171,6 +198,8 @@ local function set_inv_page(page, player) inv:set_list("main", creative_list) end + +---@param player mt.PlayerObjectRef local function init(player) local playername = player:get_player_name() minetest.create_detached_inventory("creative_" .. playername, { @@ -208,18 +237,39 @@ local trash = minetest.create_detached_inventory("trash", { inv:set_stack(listname, index, "") end, }) + trash:set_size("main", 1) -local noffset = {} -- numeric tab offset -local offset = {} -- string offset: -local boffset = {} -- -local hoch = {} +------------------------------ +-- Formspec Precalculations -- +------------------------------ + +-- Numeric position of tab background image, indexed by tab name +---@type table +local noffset = {} + +-- String position of tab button background image, indexed by tab name +---@type table +local offset = {} + +-- String position of tab button, indexed by tab name +---@type table +local boffset = {} + +-- Used to determine the tab button background image +---@type table +local button_bg_postfix = {} + +-- Tab caption/tooltip translated string, indexed by tab name +---@type table local filtername = {} ---local bg = {} local noffset_x_start = 0.2 local noffset_x = noffset_x_start local noffset_y = -1.34 + +---@param id string +---@param right? boolean local function next_noffset(id, right) if right then noffset[id] = { 11.3, noffset_y } @@ -254,20 +304,20 @@ for k, v in pairs(noffset) do boffset[k] = tostring(v[1] + 0.24) .. "," .. tostring(v[2] + 0.25) end -hoch["blocks"] = "" -hoch["deco"] = "" -hoch["redstone"] = "" -hoch["rail"] = "" -hoch["brew"] = "" -hoch["misc"] = "" -hoch["nix"] = "" -hoch["default"] = "" -hoch["food"] = "_down" -hoch["tools"] = "_down" -hoch["combat"] = "_down" -hoch["mobs"] = "_down" -hoch["matr"] = "_down" -hoch["inv"] = "_down" +button_bg_postfix["blocks"] = "" +button_bg_postfix["deco"] = "" +button_bg_postfix["redstone"] = "" +button_bg_postfix["rail"] = "" +button_bg_postfix["brew"] = "" +button_bg_postfix["misc"] = "" +button_bg_postfix["nix"] = "" +button_bg_postfix["default"] = "" +button_bg_postfix["food"] = "_down" +button_bg_postfix["tools"] = "_down" +button_bg_postfix["combat"] = "_down" +button_bg_postfix["mobs"] = "_down" +button_bg_postfix["matr"] = "_down" +button_bg_postfix["inv"] = "_down" filtername["blocks"] = S("Building Blocks") filtername["deco"] = S("Decoration Blocks") @@ -302,6 +352,8 @@ filtername["inv"] = S("Survival Inventory") bg["default"] = dark_bg end]] +-- Item name representing a tab, indexed by tab name +---@type table local tab_icon = { blocks = "mcl_core:brick_block", deco = "mcl_flowers:peony", @@ -318,13 +370,15 @@ local tab_icon = { inv = "mcl_chests:chest", } ----@param player ObjectRef +-- Get the player configured stack size when taking items from creative inventory +---@param player mt.PlayerObjectRef ---@return integer local function get_stack_size(player) return player:get_meta():get_int("mcl_inventory:switch_stack") end ----@param player ObjectRef +-- Set the player configured stack size when taking items from creative inventory +---@param player mt.PlayerObjectRef ---@param n integer local function set_stack_size(player, n) player:get_meta():set_int("mcl_inventory:switch_stack", n) @@ -336,6 +390,7 @@ minetest.register_on_joinplayer(function(player) end end) +---@param player mt.PlayerObjectRef function mcl_inventory.set_creative_formspec(player) local playername = player:get_player_name() if not players[playername] then return end @@ -459,12 +514,15 @@ function mcl_inventory.set_creative_formspec(player) }) end + ---@param current_tab string + ---@param this_tab string + ---@return string local function tab(current_tab, this_tab) local bg_img if current_tab == this_tab then - bg_img = "crafting_creative_active" .. hoch[this_tab] .. ".png" + bg_img = "crafting_creative_active" .. button_bg_postfix[this_tab] .. ".png" else - bg_img = "crafting_creative_inactive" .. hoch[this_tab] .. ".png" + bg_img = "crafting_creative_inactive" .. button_bg_postfix[this_tab] .. ".png" end return table.concat({ "style[" .. this_tab .. ";border=false;bgimg=;bgimg_pressed=;noclip=true]", @@ -476,7 +534,7 @@ function mcl_inventory.set_creative_formspec(player) local caption = "" if name ~= "inv" and filtername[name] then - caption = "label[0.375,0.375;" .. F(minetest.colorize("#313131", filtername[name])) .. "]" + caption = "label[0.375,0.375;" .. F(C(mcl_formspec.label_color, filtername[name])) .. "]" end local formspec = table.concat({ @@ -490,8 +548,7 @@ function mcl_inventory.set_creative_formspec(player) "list[current_player;main;0.375,7.375;9,1;]", -- Trash - mcl_formspec.get_itemslot_bg_v4(11.625, 7.375, 1, 1, mcl_formspec.itemslot_border_size, - "crafting_creative_trash.png"), + mcl_formspec.get_itemslot_bg_v4(11.625, 7.375, 1, 1, nil, "crafting_creative_trash.png"), "list[detached:trash;main;11.625,7.375;1,1;]", main_list, diff --git a/mods/PLAYER/mcl_player/init.lua b/mods/PLAYER/mcl_player/init.lua index 757d33c0a..288b697e1 100644 --- a/mods/PLAYER/mcl_player/init.lua +++ b/mods/PLAYER/mcl_player/init.lua @@ -135,7 +135,7 @@ function mcl_player.player_set_armor(player, texture) update_player_textures(player) end ----@param player ObjectRef +---@param player mt.PlayerObjectRef ---@param x number ---@param y number ---@param w number From ae632fe773df6f27191999c4ef4dfef637fbe839 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Thu, 29 Jun 2023 09:03:48 +0200 Subject: [PATCH 56/82] Fixes in `mcl_inventory` - Fix (yet another) rebase conflict - Remove unused code and annotations - Fix annotations in `mcl_gamemode` to https://github.com/minetest-toolkit/minetest-lsp-api --- mods/HUD/mcl_inventory/init.lua | 30 +++++++++--------------------- mods/PLAYER/mcl_gamemode/init.lua | 10 ++++------ 2 files changed, 13 insertions(+), 27 deletions(-) diff --git a/mods/HUD/mcl_inventory/init.lua b/mods/HUD/mcl_inventory/init.lua index 52fbd268b..c99f8c386 100644 --- a/mods/HUD/mcl_inventory/init.lua +++ b/mods/HUD/mcl_inventory/init.lua @@ -1,9 +1,3 @@ -local S = minetest.get_translator(minetest.get_current_modname()) -local F = minetest.formspec_escape - ----get_inventory can return nil if object isn't a player, but we are sure sometimes this is one :) ----@diagnostic disable need-check-nil - mcl_inventory = {} dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/creative.lua") @@ -13,10 +7,10 @@ dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/survival.lua") --local mod_craftguide = minetest.get_modpath("mcl_craftguide") ---Returns a single itemstack in the given inventory to the main inventory, or drop it when there's no space left. ----@param itemstack ItemStack ----@param dropper ObjectRef ----@param pos Vector ----@param inv InvRef +---@param itemstack mt.ItemStack +---@param dropper mt.ObjectRef +---@param pos mt.Vector +---@param inv mt.InvRef local function return_item(itemstack, dropper, pos, inv) if dropper:is_player() then -- Return to main inventory @@ -45,7 +39,7 @@ local function return_item(itemstack, dropper, pos, inv) end ---Return items in the given inventory list (name) to the main inventory, or drop them if there is no space left. ----@param player ObjectRef +---@param player mt.PlayerObjectRef ---@param name string local function return_fields(player, name) local inv = player:get_inventory() @@ -59,7 +53,7 @@ local function return_fields(player, name) end end ----@param player ObjectRef +---@param player mt.PlayerObjectRef ---@param armor_change_only? boolean local function set_inventory(player, armor_change_only) if minetest.is_creative_enabled(player:get_player_name()) then @@ -133,17 +127,11 @@ minetest.register_on_joinplayer(function(player) return_fields(player, "enchanting_lapis") end) ----@param player ObjectRef ----@param armor_change_only? boolean -function mcl_inventory.update_inventory(player, armor_change_only) +---@param player mt.PlayerObjectRef +function mcl_inventory.update_inventory(player) local player_gamemode = mcl_gamemode.get_gamemode(player) if player_gamemode == "creative" then - if armor_change_only then - -- Stay on survival inventory page if only the armor has been changed - mcl_inventory.set_creative_formspec(player, 0, 0, nil, nil, "inv") - else - mcl_inventory.set_creative_formspec(player, 0, 1) - end + mcl_inventory.set_creative_formspec(player) elseif player_gamemode == "survival" then player:set_inventory_formspec(mcl_inventory.build_survival_formspec(player)) end diff --git a/mods/PLAYER/mcl_gamemode/init.lua b/mods/PLAYER/mcl_gamemode/init.lua index 9b23922a4..aa2c2ba0c 100644 --- a/mods/PLAYER/mcl_gamemode/init.lua +++ b/mods/PLAYER/mcl_gamemode/init.lua @@ -1,5 +1,3 @@ ----@diagnostic disable lowercase-global - local S = minetest.get_translator("mcl_gamemode") mcl_gamemode = {} @@ -19,15 +17,15 @@ local function in_table(n, h) return false end ----@type fun(player: ObjectRef, old_gamemode: '"survival"'|'"creative"', new_gamemode: '"survival"'|'"creative"')[] +---@type fun(player: mt.PlayerObjectRef, old_gamemode: '"survival"'|'"creative"', new_gamemode: '"survival"'|'"creative"')[] mcl_gamemode.registered_on_gamemode_change = {} ----@param func fun(player: ObjectRef, old_gamemode: '"survival"'|'"creative"', new_gamemode: '"survival"'|'"creative"') +---@param func fun(player: mt.PlayerObjectRef, old_gamemode: '"survival"'|'"creative"', new_gamemode: '"survival"'|'"creative"') function mcl_gamemode.register_on_gamemode_change(func) table.insert(mcl_gamemode.registered_on_gamemode_change, func) end ----@param player ObjectRef +---@param player mt.PlayerObjectRef ---@param gamemode '"survival"'|'"creative"' function mcl_gamemode.set_gamemode(player, gamemode) local meta = player:get_meta() @@ -40,7 +38,7 @@ end local mt_is_creative_enabled = minetest.is_creative_enabled ----@param player ObjectRef +---@param player mt.PlayerObjectRef ---@return '"survival"'|'"creative"' function mcl_gamemode.get_gamemode(player) if mt_is_creative_enabled(player:get_player_name()) then From 2cb9eca8e165084445d4d478d3f42e4aaac300cf Mon Sep 17 00:00:00 2001 From: AFCMS Date: Thu, 29 Jun 2023 21:10:31 +0200 Subject: [PATCH 57/82] Use new vectors in `mcl_blast_furnace` --- mods/ITEMS/mcl_blast_furnace/init.lua | 30 +++++++++++++-------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/mods/ITEMS/mcl_blast_furnace/init.lua b/mods/ITEMS/mcl_blast_furnace/init.lua index 7e625989f..108411083 100644 --- a/mods/ITEMS/mcl_blast_furnace/init.lua +++ b/mods/ITEMS/mcl_blast_furnace/init.lua @@ -183,17 +183,17 @@ local function spawn_flames(pos, param2) local minrelpos, maxrelpos local dir = minetest.facedir_to_dir(param2) if dir.x > 0 then - minrelpos = { x = -0.6, y = -0.05, z = -0.25 } - maxrelpos = { x = -0.55, y = -0.45, z = 0.25 } + minrelpos = vector.new(-0.6, -0.05, -0.25) + maxrelpos = vector.new(-0.55, -0.45, 0.25) elseif dir.x < 0 then - minrelpos = { x = 0.55, y = -0.05, z = -0.25 } - maxrelpos = { x = 0.6, y = -0.45, z = 0.25 } + minrelpos = vector.new(0.55, -0.05, -0.25) + maxrelpos = vector.new(0.6, -0.45, 0.25) elseif dir.z > 0 then - minrelpos = { x = -0.25, y = -0.05, z = -0.6 } - maxrelpos = { x = 0.25, y = -0.45, z = -0.55 } + minrelpos = vector.new(-0.25, -0.05, -0.6) + maxrelpos = vector.new(0.25, 0.45, -0.55) elseif dir.z < 0 then - minrelpos = { x = -0.25, y = -0.05, z = 0.55 } - maxrelpos = { x = 0.25, y = -0.45, z = 0.6 } + minrelpos = vector.new(-0.25, -0.05, 0.55) + maxrelpos = vector.new(0.25, -0.45, 0.6) else return end @@ -202,8 +202,8 @@ local function spawn_flames(pos, param2) time = 0, minpos = vector.add(pos, minrelpos), maxpos = vector.add(pos, maxrelpos), - minvel = { x = -0.01, y = 0, z = -0.01 }, - maxvel = { x = 0.01, y = 0.1, z = 0.01 }, + minvel = vector.new(-0.01, 0, -0.01), + maxvel = vector.new(0.01, 0.1, 0.01), minexptime = 0.3, maxexptime = 0.6, minsize = 0.4, @@ -549,11 +549,11 @@ minetest.register_node("mcl_blast_furnace:blast_furnace_active", { for _, listname in ipairs({ "src", "dst", "fuel" }) do local stack = inv:get_stack(listname, 1) if not stack:is_empty() then - local p = { - x = pos.x + math.random(0, 10) / 10 - 0.5, - y = pos.y, - z = pos.z + math.random(0, 10) / 10 - 0.5 - } + local p = vector.new( + pos.x + math.random(0, 10) / 10 - 0.5, + pos.y, + pos.z + math.random(0, 10) / 10 - 0.5 + ) minetest.add_item(p, stack) end end From 06e2022c6da0c32ae5df710ffd10f3dd67c58bee Mon Sep 17 00:00:00 2001 From: AFCMS Date: Thu, 29 Jun 2023 21:11:58 +0200 Subject: [PATCH 58/82] Fix `mcl_enchanting` formating --- mods/ITEMS/mcl_enchanting/engine.lua | 34 +++++++++++++--------------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/mods/ITEMS/mcl_enchanting/engine.lua b/mods/ITEMS/mcl_enchanting/engine.lua index 01ef51a54..ec168b87f 100644 --- a/mods/ITEMS/mcl_enchanting/engine.lua +++ b/mods/ITEMS/mcl_enchanting/engine.lua @@ -82,7 +82,8 @@ function mcl_enchanting.not_enchantable_on_enchanting_table(itemname) end function mcl_enchanting.is_enchantable(itemname) - return mcl_enchanting.get_enchantability(itemname) > 0 or mcl_enchanting.not_enchantable_on_enchanting_table(itemname) + return mcl_enchanting.get_enchantability(itemname) > 0 or + mcl_enchanting.not_enchantable_on_enchanting_table(itemname) end function mcl_enchanting.can_enchant_freshly(itemname) @@ -153,7 +154,8 @@ function mcl_enchanting.can_enchant(itemstack, enchantment, level) for incompatible in pairs(enchantment_def.incompatible) do local incompatible_level = item_enchantments[incompatible] if incompatible_level then - return false, "incompatible", mcl_enchanting.get_enchantment_description(incompatible, incompatible_level) + return false, "incompatible", + mcl_enchanting.get_enchantment_description(incompatible, incompatible_level) end end end @@ -334,7 +336,7 @@ function mcl_enchanting.get_random_enchantment(itemstack, treasure, weighted, ex end function mcl_enchanting.generate_random_enchantments(itemstack, enchantment_level, treasure, no_reduced_bonus_chance, - ignore_already_enchanted, pr) + ignore_already_enchanted, pr) local itemname = itemstack:get_name() if (not mcl_enchanting.can_enchant_freshly(itemname) and not ignore_already_enchanted) or @@ -396,14 +398,13 @@ function mcl_enchanting.generate_random_enchantments(itemstack, enchantment_leve enchantments[selected_enchantment] = enchantment_power mcl_enchanting.enchant(itemstack, selected_enchantment, enchantment_power) end - until not no_reduced_bonus_chance and mcl_enchanting.random(pr) >= (enchantment_level + 1) / 50 return enchantments, description end function mcl_enchanting.generate_random_enchantments_reliable(itemstack, enchantment_level, treasure, - no_reduced_bonus_chance, ignore_already_enchanted, pr) + no_reduced_bonus_chance, ignore_already_enchanted, pr) local enchantments repeat @@ -415,7 +416,7 @@ function mcl_enchanting.generate_random_enchantments_reliable(itemstack, enchant end function mcl_enchanting.enchant_randomly(itemstack, enchantment_level, treasure, no_reduced_bonus_chance, - ignore_already_enchanted, pr) + ignore_already_enchanted, pr) local enchantments = mcl_enchanting.generate_random_enchantments_reliable(itemstack, enchantment_level, treasure, no_reduced_bonus_chance, ignore_already_enchanted, pr) @@ -512,17 +513,13 @@ function mcl_enchanting.show_enchanting_formspec(player) "size[11.75,10.425]", "label[0.375,0.375;" .. F(C(mcl_formspec.label_color) .. table_name) .. "]", - mcl_formspec.get_itemslot_bg_v4(1, 3.25, 1, 1), "list[current_player;enchanting_item;1,3.25;1,1]", mcl_formspec.get_itemslot_bg_v4(2.25, 3.25, 1, 1), "image[2.25,3.25;1,1;mcl_enchanting_lapis_background.png]", "list[current_player;enchanting_lapis;2.25,3.25;1,1]", - "image[4.125,0.56;7.25,4.1;mcl_enchanting_button_background.png]", - "label[0.375,4.7;" .. F(C(mcl_formspec.label_color) .. S("Inventory")) .. "]", - mcl_formspec.get_itemslot_bg_v4(0.375, 5.1, 9, 3), "list[current_player;main;0.375,5.1;9,3;9]", @@ -544,7 +541,7 @@ function mcl_enchanting.show_enchanting_formspec(player) local table_slots = mcl_enchanting.get_table_slots(player, itemstack, num_bookshelves) for i, slot in ipairs(table_slots) do any_enchantment = any_enchantment or slot - local enough_lapis = inv:contains_item("enchanting_lapis", ItemStack({name = "mcl_core:lapis", count = i})) + local enough_lapis = inv:contains_item("enchanting_lapis", ItemStack({ name = "mcl_core:lapis", count = i })) local enough_levels = slot and slot.level_requirement <= player_levels local can_enchant = (slot and enough_lapis and enough_levels) local ending = (can_enchant and "" or "_off") @@ -553,7 +550,7 @@ function mcl_enchanting.show_enchanting_formspec(player) .. "container[4.125," .. y .. "]" .. ( - slot and + slot and "tooltip[button_" .. i .. ";" .. @@ -563,7 +560,7 @@ function mcl_enchanting.show_enchanting_formspec(player) C("#FFFFFF") .. " . . . ?\n\n" .. ( - enough_levels and + enough_levels and C(enough_lapis and "#818181" or "#FC5454") .. F(S("@1 Lapis Lazuli", i)) .. "\n" .. C("#818181") .. F(S("@1 Enchantment Levels", i)) or C("#FC5454") .. F(S("Level requirement: @1", slot.level_requirement))) .. "]" or "") @@ -586,7 +583,8 @@ function mcl_enchanting.show_enchanting_formspec(player) "image[" .. (any_enchantment and 1.1 or 1.67) .. ",1.2;" .. - (any_enchantment and 2 or 0.87) .. ",1.43;mcl_enchanting_book_" .. (any_enchantment and "open" or "closed") .. ".png]" + (any_enchantment and 2 or 0.87) .. + ",1.43;mcl_enchanting_book_" .. (any_enchantment and "open" or "closed") .. ".png]" minetest.show_formspec(name, "mcl_enchanting:table", formspec) end @@ -604,7 +602,7 @@ function mcl_enchanting.handle_formspec_fields(player, formname, fields) local meta = player:get_meta() local num_bookshelfes = meta:get_int("mcl_enchanting:num_bookshelves") local itemstack = inv:get_stack("enchanting_item", 1) - local cost = ItemStack({name = "mcl_core:lapis", count = button_pressed}) + local cost = ItemStack({ name = "mcl_core:lapis", count = button_pressed }) if not inv:contains_item("enchanting_lapis", cost) then return end @@ -652,7 +650,8 @@ function mcl_enchanting.is_enchanting_inventory_action(action, inventory, invent end function mcl_enchanting.allow_inventory_action(player, action, inventory, inventory_info) - local is_enchanting_action, do_limit = mcl_enchanting.is_enchanting_inventory_action(action, inventory, inventory_info) + local is_enchanting_action, do_limit = mcl_enchanting.is_enchanting_inventory_action(action, inventory, + inventory_info) if is_enchanting_action and do_limit then if action == "move" then local listname = inventory_info.to_list @@ -700,8 +699,7 @@ end function mcl_enchanting.set_book_animation(self, anim) local anim_index = mcl_enchanting.book_animations[anim] local start, stop = mcl_enchanting.book_animation_steps[anim_index], - mcl_enchanting.book_animation_steps[anim_index + 1 - ] + mcl_enchanting.book_animation_steps[anim_index + 1] self.object:set_animation({ x = start, y = stop }, mcl_enchanting.book_animation_speed, 0, mcl_enchanting.book_animation_loop[anim] or false) self.scheduled_anim = nil From 054dc22432327776a96a08d62e3d1b1885c1c0f9 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Thu, 29 Jun 2023 21:14:47 +0200 Subject: [PATCH 59/82] Use new vectors in `mcl_chests` --- mods/ITEMS/mcl_chests/init.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mods/ITEMS/mcl_chests/init.lua b/mods/ITEMS/mcl_chests/init.lua index 9e058af2d..a9011a805 100644 --- a/mods/ITEMS/mcl_chests/init.lua +++ b/mods/ITEMS/mcl_chests/init.lua @@ -859,9 +859,9 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile on_rightclick = function(pos, node, clicker) local pos_other = mcl_util.get_double_container_neighbor_pos(pos, node.param2, "right") - if minetest.registered_nodes[minetest.get_node({ x = pos.x, y = pos.y + 1, z = pos.z }).name].groups.opaque == 1 + if minetest.registered_nodes[minetest.get_node(vector.offset(pos, 0, 1, 0)).name].groups.opaque == 1 or - minetest.registered_nodes[minetest.get_node({ x = pos_other.x, y = pos_other.y + 1, z = pos_other.z }).name].groups.opaque + minetest.registered_nodes[minetest.get_node(vector.offset(pos_other, 0, 1, 0)).name].groups.opaque == 1 then -- won't open if there is no space from the top return false From 40bc219a86ff2f48ee419c82aef62c0ee000c429 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Thu, 29 Jun 2023 21:18:26 +0200 Subject: [PATCH 60/82] Fix `mcl_books` formating? --- mods/ITEMS/mcl_books/init.lua | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/mods/ITEMS/mcl_books/init.lua b/mods/ITEMS/mcl_books/init.lua index 7c223030c..8fbd6aad2 100644 --- a/mods/ITEMS/mcl_books/init.lua +++ b/mods/ITEMS/mcl_books/init.lua @@ -205,10 +205,14 @@ end -- Written Book minetest.register_craftitem("mcl_books:written_book", { description = S("Written Book"), - _doc_items_longdesc = S("Written books contain some text written by someone. They can be read and copied, but not edited."), - _doc_items_usagehelp = S("Hold it in your hand, then rightclick to read the book.") .. "\n\n" .. - - S("To copy the text of the written book, place it into the crafting grid together with a book and quill (or multiple of those) and craft. The written book will not be consumed. Copies of copies can not be copied."), + _doc_items_longdesc = S( + "Written books contain some text written by someone. They can be read and copied, but not edited." + ), + _doc_items_usagehelp = S("Hold it in your hand, then rightclick to read the book.") .. + "\n\n" .. + S( + "To copy the text of the written book, place it into the crafting grid together with a book and quill (or multiple of those) and craft. The written book will not be consumed. Copies of copies can not be copied." + ), inventory_image = "mcl_books_book_written.png", groups = { not_in_creative_inventory = 1, book = 1, no_rename = 1 }, stack_max = 16, From bb3771c0d24c70d78f9d224f03d37e8de913ad5b Mon Sep 17 00:00:00 2001 From: AFCMS Date: Thu, 29 Jun 2023 21:20:42 +0200 Subject: [PATCH 61/82] Fix formating in `mcl_anvils` --- mods/ITEMS/mcl_anvils/init.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mods/ITEMS/mcl_anvils/init.lua b/mods/ITEMS/mcl_anvils/init.lua index 9ff9f7750..9c2e25371 100644 --- a/mods/ITEMS/mcl_anvils/init.lua +++ b/mods/ITEMS/mcl_anvils/init.lua @@ -568,9 +568,9 @@ end local anvildef0 = table.copy(anvildef) anvildef0.description = S("Anvil") anvildef0._doc_items_longdesc = -S("The anvil allows you to repair tools and armor, and to give names to items. It has a limited durability, however. Don't let it fall on your head, it could be quite painful!") + S("The anvil allows you to repair tools and armor, and to give names to items. It has a limited durability, however. Don't let it fall on your head, it could be quite painful!") anvildef0._doc_items_usagehelp = -S("To use an anvil, rightclick it. An anvil has 2 input slots (on the left) and one output slot.") .. "\n" .. + S("To use an anvil, rightclick it. An anvil has 2 input slots (on the left) and one output slot.") .. "\n" .. S("To rename items, put an item stack in one of the item slots while keeping the other input slot empty. Type in a name, hit enter or “Set Name”, then take the renamed item from the output slot.") .. "\n" .. S("There are two possibilities to repair tools (and armor):") .. "\n" .. From a77930d4a1feae28f98f3ed72d2c1dd894c96a92 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Thu, 13 Jul 2023 23:40:07 +0200 Subject: [PATCH 62/82] Fix `mcl_chests` auto formating --- mods/ITEMS/mcl_chests/init.lua | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/mods/ITEMS/mcl_chests/init.lua b/mods/ITEMS/mcl_chests/init.lua index a9011a805..59ed2ba09 100644 --- a/mods/ITEMS/mcl_chests/init.lua +++ b/mods/ITEMS/mcl_chests/init.lua @@ -927,9 +927,7 @@ local chestusage = S("To access its inventory, rightclick it. When broken, the i register_chest("chest", S("Chest"), - S( - "Chests are containers which provide 27 inventory slots. Chests can be turned into large chests with double the capacity by placing two chests next to each other.") - , + S("Chests are containers which provide 27 inventory slots. Chests can be turned into large chests with double the capacity by placing two chests next to each other."), chestusage, S("27 inventory slots") .. "\n" .. S("Can be combined to a large chest"), { @@ -955,9 +953,7 @@ local traptiles = { register_chest("trapped_chest", S("Trapped Chest"), - S( - "A trapped chest is a container which provides 27 inventory slots. When it is opened, it sends a redstone signal to its adjacent blocks as long it stays open. Trapped chests can be turned into large trapped chests with double the capacity by placing two trapped chests next to each other.") - , + S("A trapped chest is a container which provides 27 inventory slots. When it is opened, it sends a redstone signal to its adjacent blocks as long it stays open. Trapped chests can be turned into large trapped chests with double the capacity by placing two trapped chests next to each other."), chestusage, S("27 inventory slots") .. "\n" .. S("Can be combined to a large chest") .. "\n" .. S("Emits a redstone signal when opened"), From 1bdbdc365d83db713912a429fac59336c514c795 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Thu, 13 Jul 2023 23:41:51 +0200 Subject: [PATCH 63/82] Fix `mcl_enchanting` auto formating --- mods/ITEMS/mcl_enchanting/engine.lua | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/mods/ITEMS/mcl_enchanting/engine.lua b/mods/ITEMS/mcl_enchanting/engine.lua index ec168b87f..b5766dd28 100644 --- a/mods/ITEMS/mcl_enchanting/engine.lua +++ b/mods/ITEMS/mcl_enchanting/engine.lua @@ -403,8 +403,7 @@ function mcl_enchanting.generate_random_enchantments(itemstack, enchantment_leve return enchantments, description end -function mcl_enchanting.generate_random_enchantments_reliable(itemstack, enchantment_level, treasure, - no_reduced_bonus_chance, ignore_already_enchanted, pr) +function mcl_enchanting.generate_random_enchantments_reliable(itemstack, enchantment_level, treasure, no_reduced_bonus_chance, ignore_already_enchanted, pr) local enchantments repeat @@ -417,8 +416,7 @@ end function mcl_enchanting.enchant_randomly(itemstack, enchantment_level, treasure, no_reduced_bonus_chance, ignore_already_enchanted, pr) - local enchantments = mcl_enchanting.generate_random_enchantments_reliable(itemstack, enchantment_level, treasure, - no_reduced_bonus_chance, ignore_already_enchanted, pr) + local enchantments = mcl_enchanting.generate_random_enchantments_reliable(itemstack, enchantment_level, treasure, no_reduced_bonus_chance, ignore_already_enchanted, pr) mcl_enchanting.set_enchanted_itemstring(itemstack) mcl_enchanting.set_enchantments(itemstack, enchantments) From f7c251e7f214e5b2e59b82e5d2714cdb8bc350c3 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Thu, 13 Jul 2023 23:43:39 +0200 Subject: [PATCH 64/82] Fix `mcl_grindstone` auto formating --- mods/ITEMS/mcl_grindstone/init.lua | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/mods/ITEMS/mcl_grindstone/init.lua b/mods/ITEMS/mcl_grindstone/init.lua index ddd1e8812..e0137dcd1 100644 --- a/mods/ITEMS/mcl_grindstone/init.lua +++ b/mods/ITEMS/mcl_grindstone/init.lua @@ -207,12 +207,9 @@ minetest.register_node("mcl_grindstone:grindstone", { description = S("Grindstone"), _tt_help = S("Used to disenchant/fix tools"), _doc_items_longdesc = S("Grindstone disenchants tools and armour except for curses, and repairs two items of the same type it is also the weapon smith's work station."), - _doc_items_usagehelp = S("To use the grindstone, rightclick it, Two input slots (on the left) and a single output slot.") - .. "\n" .. - S("To disenchant an item place enchanted item in one of the input slots and take the disenchanted item from the output.") - .. "\n" .. - S("To repair a tool you need a tool of the same type and material, put both items in the input slot and the output slot will combine two items durabilities with 5% bonus.") - .. "\n" .. + _doc_items_usagehelp = S("To use the grindstone, rightclick it, Two input slots (on the left) and a single output slot.") .. "\n" .. + S("To disenchant an item place enchanted item in one of the input slots and take the disenchanted item from the output.") .. "\n" .. + S("To repair a tool you need a tool of the same type and material, put both items in the input slot and the output slot will combine two items durabilities with 5% bonus.") .. "\n" .. S("If both items have enchantments the player will get xp from both items from the disenchant.") .. "\n" .. S("Curses cannot be removed and will be transfered to the new repaired item, if both items have a different curse the curses will be combined."), tiles = { From bf28bab427afb5f5167ebf62ae7afa977e13698a Mon Sep 17 00:00:00 2001 From: AFCMS Date: Thu, 13 Jul 2023 23:52:36 +0200 Subject: [PATCH 65/82] Remove duplicated creacode --- mods/PLAYER/mcl_gamemode/init.lua | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/mods/PLAYER/mcl_gamemode/init.lua b/mods/PLAYER/mcl_gamemode/init.lua index aa2c2ba0c..cce6c0b46 100644 --- a/mods/PLAYER/mcl_gamemode/init.lua +++ b/mods/PLAYER/mcl_gamemode/init.lua @@ -57,21 +57,6 @@ function minetest.is_creative_enabled(name) return false end --- Insta "digging" nodes in gamemode-creative -minetest.register_on_punchnode(function(pos, node, puncher, pointed_thing) - if not puncher or not puncher:is_player() then return end - if minetest.is_creative_enabled() then return end - local name = puncher:get_player_name() - if not minetest.is_creative_enabled(name) then return end - if pointed_thing.type ~= "node" then return end - local def = minetest.registered_nodes[node.name] - if def then - if def.on_destruct then def.on_destruct(pos) end - minetest.node_dig(pos, node, puncher) - return true - end -end) - -- Don't subtract from inv when placing in gamemode-creative minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack, pointed_thing) if placer and placer:is_player() and minetest.is_creative_enabled(placer:get_player_name()) then return true end From 3fe3153a408bab6fa0bf5aa29aac2a1ebbdac290 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Thu, 13 Jul 2023 23:52:57 +0200 Subject: [PATCH 66/82] Remove duplicated creative digging code --- mods/ITEMS/mcl_books/init.lua | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/mods/ITEMS/mcl_books/init.lua b/mods/ITEMS/mcl_books/init.lua index 8fbd6aad2..e2f391b17 100644 --- a/mods/ITEMS/mcl_books/init.lua +++ b/mods/ITEMS/mcl_books/init.lua @@ -85,7 +85,8 @@ local function write(itemstack, user, pointed_thing) local node = minetest.get_node(pointed_thing.under) if user and not user:get_player_control().sneak then if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].on_rightclick then - return minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, user, itemstack) or itemstack + return minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, user, itemstack) or + itemstack end end end @@ -106,7 +107,8 @@ local function read(itemstack, user, pointed_thing) local node = minetest.get_node(pointed_thing.under) if user and not user:get_player_control().sneak then if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].on_rightclick then - return minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, user, itemstack) or itemstack + return minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, user, itemstack) or + itemstack end end end @@ -125,7 +127,8 @@ minetest.register_craftitem("mcl_books:writable_book", { description = S("Book and Quill"), _tt_help = S("Write down some notes"), _doc_items_longdesc = S("This item can be used to write down some notes."), - _doc_items_usagehelp = S("Hold it in the hand, then rightclick to read the current notes and edit then. You can edit the text as often as you like. You can also sign the book which turns it into a written book which you can stack, but it can't be edited anymore.") + _doc_items_usagehelp = S( + "Hold it in the hand, then rightclick to read the current notes and edit then. You can edit the text as often as you like. You can also sign the book which turns it into a written book which you can stack, but it can't be edited anymore.") .. "\n" .. S("A book can hold up to 4500 characters. The title length is limited to 64 characters."), inventory_image = "mcl_books_book_writable.png", @@ -154,7 +157,8 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) "background[-0.5,-0.5;9,10;mcl_books_book_bg.png]" .. "field[0.75,1;7.25,1;title;" .. minetest.formspec_escape(minetest.colorize("#000000", S("Enter book title:"))) .. ";]" .. - "label[0.75,1.5;" .. minetest.formspec_escape(minetest.colorize("#404040", S("by @1", name))) .. "]" .. + "label[0.75,1.5;" .. + minetest.formspec_escape(minetest.colorize("#404040", S("by @1", name))) .. "]" .. "button_exit[0.75,7.95;3,1;sign;" .. minetest.formspec_escape(S("Sign and Close")) .. "]" .. "tooltip[sign;" .. minetest.formspec_escape(S("Note: The book will no longer be editable after signing")) .. "]" .. @@ -226,9 +230,9 @@ minetest.register_craftitem("mcl_books:written_book", { local baq = "mcl_books:writable_book" local wb = "mcl_books:written_book" local recipes = { - { wb, baq }, + { wb, baq }, { baq, baq, wb }, - { baq, baq, wb, baq }, + { baq, baq, wb, baq }, { baq, baq, baq, baq, wb }, { baq, baq, baq, baq, wb, baq }, { baq, baq, baq, baq, wb, baq, baq }, @@ -394,19 +398,15 @@ local function bookshelf_gui(pos, node, clicker) "size[11.75,10.425]", "label[0.375,0.375;" .. F(C(mcl_formspec.label_color, name)) .. "]", - mcl_formspec.get_itemslot_bg_v4(0.375, 0.75, 9, 3), mcl_formspec.get_itemslot_bg_v4(0.375, 0.75, 9, 3, 0, "mcl_book_book_empty_slot.png"), "list[nodemeta:" .. pos.x .. "," .. pos.y .. "," .. pos.z .. ";main;0.375,0.75;9,3;]", - "label[0.375,4.7;" .. F(C(mcl_formspec.label_color, S("Inventory"))) .. "]", - mcl_formspec.get_itemslot_bg_v4(0.375, 5.1, 9, 3), "list[current_player;main;0.375,5.1;9,3;9]", mcl_formspec.get_itemslot_bg_v4(0.375, 9.05, 9, 1), "list[current_player;main;0.375,9.05;9,1;]", - "listring[nodemeta:" .. pos.x .. "," .. pos.y .. "," .. pos.z .. ";main]", "listring[current_player;main]", }) @@ -431,8 +431,14 @@ minetest.register_node("mcl_books:bookshelf", { stack_max = 64, is_ground_content = false, groups = { - handy = 1, axey = 1, deco_block = 1, material_wood = 1, - flammable = 3, fire_encouragement = 30, fire_flammability = 20, container = 1 + handy = 1, + axey = 1, + deco_block = 1, + material_wood = 1, + flammable = 3, + fire_encouragement = 30, + fire_flammability = 20, + container = 1 }, drop = "mcl_books:book 3", sounds = wood_sound, @@ -471,9 +477,9 @@ minetest.register_node("mcl_books:bookshelf", { minetest.register_craft({ output = "mcl_books:bookshelf", recipe = { - { "group:wood", "group:wood", "group:wood" }, + { "group:wood", "group:wood", "group:wood" }, { "mcl_books:book", "mcl_books:book", "mcl_books:book" }, - { "group:wood", "group:wood", "group:wood" }, + { "group:wood", "group:wood", "group:wood" }, } }) From 9d184e98977ce05b4023b45fbf0068c5d1cb44ba Mon Sep 17 00:00:00 2001 From: AFCMS Date: Thu, 13 Jul 2023 23:57:18 +0200 Subject: [PATCH 67/82] Remove duplicated creative inventory code --- mods/PLAYER/mcl_gamemode/init.lua | 5 ----- 1 file changed, 5 deletions(-) diff --git a/mods/PLAYER/mcl_gamemode/init.lua b/mods/PLAYER/mcl_gamemode/init.lua index cce6c0b46..a43a9c1ff 100644 --- a/mods/PLAYER/mcl_gamemode/init.lua +++ b/mods/PLAYER/mcl_gamemode/init.lua @@ -57,11 +57,6 @@ function minetest.is_creative_enabled(name) return false end --- Don't subtract from inv when placing in gamemode-creative -minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack, pointed_thing) - if placer and placer:is_player() and minetest.is_creative_enabled(placer:get_player_name()) then return true end -end) - minetest.register_chatcommand("gamemode", { params = S("[] []"), description = S("Change gamemode (survival/creative) for yourself or player"), From dc20267b4fa10c0584e450743cbff11cb2e5c310 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Fri, 14 Jul 2023 00:05:01 +0200 Subject: [PATCH 68/82] Update inventory when player visuals change --- mods/HUD/mcl_inventory/init.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mods/HUD/mcl_inventory/init.lua b/mods/HUD/mcl_inventory/init.lua index c99f8c386..4bb3ea0a9 100644 --- a/mods/HUD/mcl_inventory/init.lua +++ b/mods/HUD/mcl_inventory/init.lua @@ -140,3 +140,5 @@ end mcl_gamemode.register_on_gamemode_change(function(player, old_gamemode, new_gamemode) set_inventory(player) end) + +mcl_player.register_on_visual_change(mcl_inventory.update_inventory_formspec) From df2ab1fd8cc8130fc7646a047d9e2415e82688b1 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Fri, 14 Jul 2023 00:12:47 +0200 Subject: [PATCH 69/82] Remove duplicated armor update code --- mods/HUD/mcl_inventory/init.lua | 6 ------ 1 file changed, 6 deletions(-) diff --git a/mods/HUD/mcl_inventory/init.lua b/mods/HUD/mcl_inventory/init.lua index 4bb3ea0a9..cf484101c 100644 --- a/mods/HUD/mcl_inventory/init.lua +++ b/mods/HUD/mcl_inventory/init.lua @@ -107,12 +107,6 @@ minetest.register_on_joinplayer(function(player) player:hud_set_hotbar_image("mcl_inventory_hotbar.png") player:hud_set_hotbar_selected_image("mcl_inventory_hotbar_selected.png") - local old_update_player = mcl_armor.update_player - function mcl_armor.update_player(player, info) - old_update_player(player, info) - set_inventory(player, true) - end - -- In Creative Mode, the initial inventory setup is handled in creative.lua if not minetest.is_creative_enabled(player:get_player_name()) then set_inventory(player) From e936cede037d6d1befdf12ab58c444e35c22f0ff Mon Sep 17 00:00:00 2001 From: AFCMS Date: Fri, 14 Jul 2023 00:17:51 +0200 Subject: [PATCH 70/82] Update meshhand --- mods/HUD/mcl_inventory/init.lua | 1 + mods/HUD/mcl_inventory/mod.conf | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/mods/HUD/mcl_inventory/init.lua b/mods/HUD/mcl_inventory/init.lua index cf484101c..8762213c8 100644 --- a/mods/HUD/mcl_inventory/init.lua +++ b/mods/HUD/mcl_inventory/init.lua @@ -129,6 +129,7 @@ function mcl_inventory.update_inventory(player) elseif player_gamemode == "survival" then player:set_inventory_formspec(mcl_inventory.build_survival_formspec(player)) end + mcl_meshhand.update_player(player) end mcl_gamemode.register_on_gamemode_change(function(player, old_gamemode, new_gamemode) diff --git a/mods/HUD/mcl_inventory/mod.conf b/mods/HUD/mcl_inventory/mod.conf index 66f175c3b..d37a3e372 100644 --- a/mods/HUD/mcl_inventory/mod.conf +++ b/mods/HUD/mcl_inventory/mod.conf @@ -1,5 +1,5 @@ name = mcl_inventory author = BlockMen description = Adds the player inventory and creative inventory. -depends = mcl_init, mcl_formspec, mcl_enchanting, mcl_gamemode +depends = mcl_init, mcl_formspec, mcl_enchanting, mcl_gamemode, mcl_meshhand optional_depends = mcl_armor, mcl_brewing, mcl_potions, mcl_enchanting, mcl_craftguide, mcl_player From 158ff8e8601b6ada23a9a978a5120a8082686682 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Fri, 28 Jul 2023 16:39:57 +0200 Subject: [PATCH 71/82] Add commented basic scrollbar support to replace pages system --- mods/HUD/mcl_inventory/creative.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/mods/HUD/mcl_inventory/creative.lua b/mods/HUD/mcl_inventory/creative.lua index a896fa0de..02e0d99ec 100644 --- a/mods/HUD/mcl_inventory/creative.lua +++ b/mods/HUD/mcl_inventory/creative.lua @@ -503,10 +503,23 @@ function mcl_inventory.set_creative_formspec(player) "listring[detached:" .. playername .. "_armor;armor]" .. "listring[current_player;main]" else + + --local nb_lines = math.ceil(inv_size / 9) -- Creative inventory slots main_list = table.concat({ mcl_formspec.get_itemslot_bg_v4(0.375, 0.875, 9, 5), + + -- Basic code to replace buttons by scrollbar + -- Require Minetest 5.8 + -- + --"scroll_container[0.375,0.875;11.575,6;scroll;vertical;1.25]", + --"list[detached:creative_" .. playername .. ";main;0,0;9," .. nb_lines .. ";]", + --"scroll_container_end[]", + --"scrollbaroptions[min=0;max=" .. math.max(nb_lines - 5, 0) .. ";smallstep=1;largesteps=1;arrows=hide]", + --"scrollbar[11.75,0.825;0.75,6.1;vertical;scroll;0]", + "list[detached:creative_" .. playername .. ";main;0.375,0.875;9,5;" .. tostring(start_i) .. "]", + -- Page buttons "label[11.65,5.6;" .. F(S("@1 / @2", pagenum, pagemax)) .. "]", "image_button[11.575,5.83;0.55,1.1;crafting_creative_prev.png;creative_prev;]", From 4efb5bf8b9afc367abb0a80b7c57efb49994c8b4 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Fri, 28 Jul 2023 16:49:56 +0200 Subject: [PATCH 72/82] Make creative inventory page buttons vertical --- mods/HUD/mcl_inventory/creative.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mods/HUD/mcl_inventory/creative.lua b/mods/HUD/mcl_inventory/creative.lua index 02e0d99ec..3e4c3d4d6 100644 --- a/mods/HUD/mcl_inventory/creative.lua +++ b/mods/HUD/mcl_inventory/creative.lua @@ -521,9 +521,9 @@ function mcl_inventory.set_creative_formspec(player) "list[detached:creative_" .. playername .. ";main;0.375,0.875;9,5;" .. tostring(start_i) .. "]", -- Page buttons - "label[11.65,5.6;" .. F(S("@1 / @2", pagenum, pagemax)) .. "]", - "image_button[11.575,5.83;0.55,1.1;crafting_creative_prev.png;creative_prev;]", - "image_button[12.075,5.83;0.55,1.1;crafting_creative_next.png;creative_next;]", + "label[11.65,4.33;" .. F(S("@1 / @2", pagenum, pagemax)) .. "]", + "image_button[11.575,4.58;1.1,1.1;crafting_creative_prev.png^[transformR270;creative_prev;]", + "image_button[11.575,5.83;1.1,1.1;crafting_creative_next.png^[transformR270;creative_next;]", }) end From 4f0620c7c1d8ea7b253b40f42dd34efd06610549 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Fri, 28 Jul 2023 17:15:41 +0200 Subject: [PATCH 73/82] Fix meshhand not updating correctly --- mods/HUD/mcl_inventory/init.lua | 1 - mods/HUD/mcl_inventory/mod.conf | 2 +- mods/PLAYER/mcl_meshhand/init.lua | 4 ++++ mods/PLAYER/mcl_meshhand/mod.conf | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/mods/HUD/mcl_inventory/init.lua b/mods/HUD/mcl_inventory/init.lua index 8762213c8..cf484101c 100644 --- a/mods/HUD/mcl_inventory/init.lua +++ b/mods/HUD/mcl_inventory/init.lua @@ -129,7 +129,6 @@ function mcl_inventory.update_inventory(player) elseif player_gamemode == "survival" then player:set_inventory_formspec(mcl_inventory.build_survival_formspec(player)) end - mcl_meshhand.update_player(player) end mcl_gamemode.register_on_gamemode_change(function(player, old_gamemode, new_gamemode) diff --git a/mods/HUD/mcl_inventory/mod.conf b/mods/HUD/mcl_inventory/mod.conf index d37a3e372..66f175c3b 100644 --- a/mods/HUD/mcl_inventory/mod.conf +++ b/mods/HUD/mcl_inventory/mod.conf @@ -1,5 +1,5 @@ name = mcl_inventory author = BlockMen description = Adds the player inventory and creative inventory. -depends = mcl_init, mcl_formspec, mcl_enchanting, mcl_gamemode, mcl_meshhand +depends = mcl_init, mcl_formspec, mcl_enchanting, mcl_gamemode optional_depends = mcl_armor, mcl_brewing, mcl_potions, mcl_enchanting, mcl_craftguide, mcl_player diff --git a/mods/PLAYER/mcl_meshhand/init.lua b/mods/PLAYER/mcl_meshhand/init.lua index 6d1177b18..c42ff8081 100644 --- a/mods/PLAYER/mcl_meshhand/init.lua +++ b/mods/PLAYER/mcl_meshhand/init.lua @@ -89,6 +89,10 @@ minetest.register_on_joinplayer(function(player) player:get_inventory():set_size("hand", 1) end) +mcl_gamemode.register_on_gamemode_change(function(player) + mcl_meshhand.update_player(player) +end) + if mcl_skins_enabled then mcl_player.register_on_visual_change(mcl_meshhand.update_player) else diff --git a/mods/PLAYER/mcl_meshhand/mod.conf b/mods/PLAYER/mcl_meshhand/mod.conf index 687932514..fd10c259c 100644 --- a/mods/PLAYER/mcl_meshhand/mod.conf +++ b/mods/PLAYER/mcl_meshhand/mod.conf @@ -1,5 +1,5 @@ name = mcl_meshhand author = jordan4ibanez description = Applies the player skin texture to the hand. -depends = mcl_tools, mcl_player +depends = mcl_tools, mcl_player, mcl_gamemode optional_depends = mcl_skins, mcl_custom_skins From 438998de6ae44f7cf9c9858ca173a8a155b5cd3e Mon Sep 17 00:00:00 2001 From: AFCMS Date: Tue, 1 Aug 2023 16:37:04 +0200 Subject: [PATCH 74/82] Remove unused files --- textures/crafting_inventory_creative.png | Bin 1180 -> 0 bytes .../crafting_inventory_creative_survival.png | Bin 1236 -> 0 bytes 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 textures/crafting_inventory_creative.png delete mode 100644 textures/crafting_inventory_creative_survival.png diff --git a/textures/crafting_inventory_creative.png b/textures/crafting_inventory_creative.png deleted file mode 100644 index 43664452b34a9cf748974be42ce8f33ecfec0f5a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1180 zcmeAS@N?(olHy`uVBq!ia0y~yVBQGCMl8%g5l_u%86YJT;1lAS2xNf4|Ns9lT)2>t zk-;!6-v%hcSQ6wH%;50sMj8VHi-o6)V@SoVx0f9SnHU9_4|?2;ayY2?a6-YqwI3Xq z^qsc1_^2{M4I+-JyAhN=No9Mp*<_W~IrC+wzb)xIJ#E_ElW#5Nsi&^p%8tN8qeM;j!>G=Q!j z^*-r|1|F~@GWLHjPn@c&xBL5b*ST|DZn{lQkuO`ZCudR4^VG>p&n?#>E@LC9IxziS X!J_jXOJ66w1c`dO`njxgN@xNA%W@VN diff --git a/textures/crafting_inventory_creative_survival.png b/textures/crafting_inventory_creative_survival.png deleted file mode 100644 index ad53b5f4f275476241a05d7dbc98a18cf52cc30d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1236 zcmeAS@N?(olHy`uVBq!ia0y~yVBQGCMl8%g5l_u%86YJQ;1lAS2xNf4|Ns9lT)2>t zk>T#{zIgHCbz3EF0>v3ig8YIR9G=}sV_;y(@^o~!eTK_C9aWpoQqQz+(&_=*ag=GckvWV zA*geHUM*TsK39Bi&NSuRZ^^GxH*2icIkgCkw7NHGfDx3xXbqH)M~TiUa&*BB?%qU# zU2t7+7Zc+`OkHpn Date: Sat, 19 Aug 2023 18:18:27 +0200 Subject: [PATCH 75/82] Use `table.indexof` in `mcl_anvils` --- mods/ITEMS/mcl_anvils/init.lua | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/mods/ITEMS/mcl_anvils/init.lua b/mods/ITEMS/mcl_anvils/init.lua index 9c2e25371..b41411f15 100644 --- a/mods/ITEMS/mcl_anvils/init.lua +++ b/mods/ITEMS/mcl_anvils/init.lua @@ -79,18 +79,6 @@ local function get_consumed_materials(tool, material) return materials_used end ----@param table table ----@param value any ----@return boolean -local function contains(table, value) - for _, i in pairs(table) do - if i == value then - return true - end - end - return false -end - -- Given 2 input stacks, tells you which is the tool and which is the material. -- Returns ("tool", input1, input2) if input1 is tool and input2 is material. -- Returns ("material", input2, input1) if input1 is material and input2 is tool. @@ -102,9 +90,9 @@ local function distinguish_tool_and_material(input1, input2) local def2 = input2:get_definition() local r1 = def1._repair_material local r2 = def2._repair_material - if def1.type == "tool" and r1 and type(r1) == "table" and contains(r1, input2) then + if def1.type == "tool" and r1 and type(r1) == "table" and table.indexof(r1, input2) ~= -1 then return "tool", input1, input2 - elseif def2.type == "tool" and r2 and type(r2) == "table" and contains(r2, input1) then + elseif def2.type == "tool" and r2 and type(r2) == "table" and table.indexof(r1, input1) ~= -1 then return "material", input2, input1 elseif def1.type == "tool" and r1 then return "tool", input1, input2 @@ -192,7 +180,7 @@ local function update_anvil_slots(meta) has_correct_material = true end else - if contains(repair, material_name) then + if table.indexof(repair, material_name) ~= -1 then has_correct_material = true else for _, r in pairs(repair) do From 1b5b2e4dc7fc2660f6858f2df92543ed9fa00367 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Sat, 19 Aug 2023 18:27:00 +0200 Subject: [PATCH 76/82] Use new vectors in several places --- mods/ITEMS/REDSTONE/mcl_dispensers/init.lua | 13 ++++++------- mods/ITEMS/REDSTONE/mcl_droppers/init.lua | 17 ++++++++--------- mods/ITEMS/mcl_blast_furnace/init.lua | 7 +------ 3 files changed, 15 insertions(+), 22 deletions(-) diff --git a/mods/ITEMS/REDSTONE/mcl_dispensers/init.lua b/mods/ITEMS/REDSTONE/mcl_dispensers/init.lua index fa8ecc779..ae419a512 100644 --- a/mods/ITEMS/REDSTONE/mcl_dispensers/init.lua +++ b/mods/ITEMS/REDSTONE/mcl_dispensers/init.lua @@ -101,8 +101,7 @@ local dispenserdef = { for i = 1, inv:get_size("main") do local stack = inv:get_stack("main", i) if not stack:is_empty() then - local p = { x = pos.x + math.random(0, 10) / 10 - 0.5, y = pos.y, z = pos.z + math.random(0, 10) / 10 - 0.5 } - minetest.add_item(p, stack) + minetest.add_item(vector.offset(pos, math.random(0, 10) / 10 - 0.5, 0, math.random(0, 10) / 10 - 0.5), stack) end end meta:from_table(meta2) @@ -120,11 +119,11 @@ local dispenserdef = { dropdir = vector.multiply(minetest.facedir_to_dir(node.param2), -1) droppos = vector.add(pos, dropdir) elseif node.name == "mcl_dispensers:dispenser_up" then - dropdir = { x = 0, y = 1, z = 0 } - droppos = { x = pos.x, y = pos.y + 1, z = pos.z } + dropdir = vector.new(0, 1, 0) + droppos = vector.offset(pos, 0, 1, 0) elseif node.name == "mcl_dispensers:dispenser_down" then - dropdir = { x = 0, y = -1, z = 0 } - droppos = { x = pos.x, y = pos.y - 1, z = pos.z } + dropdir = vector.new(0, -1, 0) + droppos = vector.offset(pos, 0, -1, 0) end local dropnode = minetest.get_node(droppos) local dropnodedef = minetest.registered_nodes[dropnode.name] @@ -156,7 +155,7 @@ local dispenserdef = { -- Armor, mob heads and pumpkins if igroups.armor then - local droppos_below = { x = droppos.x, y = droppos.y - 1, z = droppos.z } + local droppos_below = vector.offset(droppos, 0, -1, 0) for _, objs in ipairs({ minetest.get_objects_inside_radius(droppos, 1), minetest.get_objects_inside_radius(droppos_below, 1) }) do diff --git a/mods/ITEMS/REDSTONE/mcl_droppers/init.lua b/mods/ITEMS/REDSTONE/mcl_droppers/init.lua index 78a9a773b..09e221a4d 100644 --- a/mods/ITEMS/REDSTONE/mcl_droppers/init.lua +++ b/mods/ITEMS/REDSTONE/mcl_droppers/init.lua @@ -74,8 +74,7 @@ local dropperdef = { for i = 1, inv:get_size("main") do local stack = inv:get_stack("main", i) if not stack:is_empty() then - local p = { x = pos.x + math.random(0, 10) / 10 - 0.5, y = pos.y, z = pos.z + math.random(0, 10) / 10 - 0.5 } - minetest.add_item(p, stack) + minetest.add_item(vector.offset(pos, math.random(0, 10) / 10 - 0.5, 0, math.random(0, 10) / 10 - 0.5), stack) end end meta:from_table(meta2) @@ -119,9 +118,9 @@ local dropperdef = { if node.name == "mcl_droppers:dropper" then droppos = vector.subtract(pos, minetest.facedir_to_dir(node.param2)) elseif node.name == "mcl_droppers:dropper_up" then - droppos = { x = pos.x, y = pos.y + 1, z = pos.z } + droppos = vector.offset(pos, 0, 1, 0) elseif node.name == "mcl_droppers:dropper_down" then - droppos = { x = pos.x, y = pos.y - 1, z = pos.z } + droppos = vector.offset(pos, 0, -1, 0) end local dropnode = minetest.get_node(droppos) -- Do not drop into solid nodes, unless they are containers @@ -149,11 +148,11 @@ local dropperdef = { if not dropped and not dropnodedef.groups.container then -- Drop item normally local pos_variation = 100 - droppos = { - x = droppos.x + math.random(-pos_variation, pos_variation) / 1000, - y = droppos.y + math.random(-pos_variation, pos_variation) / 1000, - z = droppos.z + math.random(-pos_variation, pos_variation) / 1000, - } + droppos = vector.offset(droppos, + math.random(-pos_variation, pos_variation) / 1000, + math.random(-pos_variation, pos_variation) / 1000, + math.random(-pos_variation, pos_variation) / 1000 + ) local item_entity = minetest.add_item(droppos, dropitem) local drop_vel = vector.subtract(droppos, pos) local speed = 3 diff --git a/mods/ITEMS/mcl_blast_furnace/init.lua b/mods/ITEMS/mcl_blast_furnace/init.lua index 108411083..51a8f193a 100644 --- a/mods/ITEMS/mcl_blast_furnace/init.lua +++ b/mods/ITEMS/mcl_blast_furnace/init.lua @@ -466,12 +466,7 @@ minetest.register_node("mcl_blast_furnace:blast_furnace", { for _, listname in ipairs({ "src", "dst", "fuel" }) do local stack = inv:get_stack(listname, 1) if not stack:is_empty() then - local p = { - x = pos.x + math.random(0, 10) / 10 - 0.5, - y = pos.y, - z = pos.z + math.random(0, 10) / 10 - 0.5 - } - minetest.add_item(p, stack) + minetest.add_item(vector.offset(pos, math.random(0, 10) / 10 - 0.5, 0, math.random(0, 10) / 10 - 0.5), stack) end end meta:from_table(meta2) From 149cb5d17c64703441727220d596ec060c5fd38f Mon Sep 17 00:00:00 2001 From: AFCMS Date: Sat, 19 Aug 2023 18:30:03 +0200 Subject: [PATCH 77/82] Fix gramar mistakes --- mods/HUD/mcl_formspec/FORMSPEC_GUIDE.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mods/HUD/mcl_formspec/FORMSPEC_GUIDE.md b/mods/HUD/mcl_formspec/FORMSPEC_GUIDE.md index f8576070f..a5f3d4745 100644 --- a/mods/HUD/mcl_formspec/FORMSPEC_GUIDE.md +++ b/mods/HUD/mcl_formspec/FORMSPEC_GUIDE.md @@ -1,6 +1,6 @@ # MineClone2 Formspec Guide -**_This guide will learn you rules about creation of formspecs for the MineClone2 game._** +**_This guide will teach you the rules for creating formspecs for the MineClone2 game._** Formspecs are an important part of game and mod development. @@ -8,7 +8,7 @@ First of all, MineClone2 aims to support ONLY last formspec version. Many utilit The typical width of an 9 slots width inventory formspec is `0.375 + 9 + ((9-1) * 0.25) + 0.375 = 11.75` -Margins is 0.375. +Margins are 0.375. The labels color is `mcl_formspec.label_color` From 28d77a3e5beec9bb3eb747f48b4e39e874033a42 Mon Sep 17 00:00:00 2001 From: Sebastian Riedel Date: Sun, 20 Aug 2023 03:19:17 +0200 Subject: [PATCH 78/82] Replace spaces in itemstrings with underscore --- mods/ITEMS/mcl_crimson/alias.lua | 4 ++++ mods/ITEMS/mcl_crimson/init.lua | 10 ++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 mods/ITEMS/mcl_crimson/alias.lua diff --git a/mods/ITEMS/mcl_crimson/alias.lua b/mods/ITEMS/mcl_crimson/alias.lua new file mode 100644 index 000000000..cbc76ef2e --- /dev/null +++ b/mods/ITEMS/mcl_crimson/alias.lua @@ -0,0 +1,4 @@ +minetest.register_alias("mcl_flowerpots:flower_pot_crimson fungus", "mcl_flowerpots:flower_pot_crimson_fungus") +minetest.register_alias("mcl_flowerpots:flower_pot_crimson roots", "mcl_flowerpots:flower_pot_crimson_roots") +minetest.register_alias("mcl_flowerpots:flower_pot_warped fungus", "mcl_flowerpots:flower_pot_warped_fungus") +minetest.register_alias("mcl_flowerpots:flower_pot_warped roots", "mcl_flowerpots:flower_pot_warped_roots") diff --git a/mods/ITEMS/mcl_crimson/init.lua b/mods/ITEMS/mcl_crimson/init.lua index 3ec6d60e4..cd9c9354c 100644 --- a/mods/ITEMS/mcl_crimson/init.lua +++ b/mods/ITEMS/mcl_crimson/init.lua @@ -99,7 +99,7 @@ minetest.register_node("mcl_crimson:warped_fungus", { }) mcl_flowerpots.register_potted_flower("mcl_crimson:warped_fungus", { - name = "warped fungus", + name = "warped_fungus", desc = S("Warped Fungus"), image = "mcl_crimson_warped_fungus.png", }) @@ -297,7 +297,7 @@ minetest.register_node("mcl_crimson:warped_roots", { }) mcl_flowerpots.register_potted_flower("mcl_crimson:warped_roots", { - name = "warped roots", + name = "warped_roots", desc = S("Warped Roots"), image = "mcl_crimson_warped_roots.png", }) @@ -490,7 +490,7 @@ minetest.register_node("mcl_crimson:crimson_fungus", { }) mcl_flowerpots.register_potted_flower("mcl_crimson:crimson_fungus", { - name = "crimson fungus", + name = "crimson_fungus", desc = S("Crimson Fungus"), image = "mcl_crimson_crimson_fungus.png", }) @@ -516,7 +516,7 @@ minetest.register_node("mcl_crimson:crimson_roots", { }) mcl_flowerpots.register_potted_flower("mcl_crimson:crimson_roots", { - name = "crimson roots", + name = "crimson_roots", desc = S("Crimson Roots"), image = "mcl_crimson_crimson_roots.png", }) @@ -807,3 +807,5 @@ minetest.register_craft({ {"mcl_core:stick", warped_wood, "mcl_core:stick"}, } }) + +dofile(modpath.."/alias.lua") \ No newline at end of file From 2eabeb119a73c8b69cdc19af7be1e9eee35cc08c Mon Sep 17 00:00:00 2001 From: AFCMS Date: Wed, 23 Aug 2023 21:48:49 +0200 Subject: [PATCH 79/82] Fix creative node placement --- mods/HUD/mcl_inventory/creative.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mods/HUD/mcl_inventory/creative.lua b/mods/HUD/mcl_inventory/creative.lua index 3e4c3d4d6..bb2f226a2 100644 --- a/mods/HUD/mcl_inventory/creative.lua +++ b/mods/HUD/mcl_inventory/creative.lua @@ -725,6 +725,9 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) mcl_inventory.set_creative_formspec(player) end) +minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack) + return placer and placer:is_player() and minetest.is_creative_enabled(placer:get_player_name()) +end) if minetest.is_creative_enabled("") then minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack) From 7b764adbc0c90a8909d2132379ceb352b620e24c Mon Sep 17 00:00:00 2001 From: Van Date: Thu, 31 Aug 2023 22:27:08 +0000 Subject: [PATCH 80/82] Banners color editing (#3868) ### Changing banner colors Reason: I think the current colors of the banners do not match the palette of the surrounding world. Solution: Muting Banner Tones ### Testing Check out the new colors on 12 color banners. ### Attachments Changed banner colors/Current banner appearance UPDATE: Adjusted colors, see the third attachment UPDATE: Changed the color of the white flag. Fixed a bug with different colors of patterns and banners, increased the contrast of folds. The last four attachments display all. Reviewed-on: https://git.minetest.land/MineClone2/MineClone2/pulls/3868 Reviewed-by: chmodsayshello Co-authored-by: Van Co-committed-by: Van --- mods/ITEMS/mcl_banners/init.lua | 32 +++++++++++++-------------- textures/mcl_banners_banner_base.png | Bin 791 -> 1126 bytes 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/mods/ITEMS/mcl_banners/init.lua b/mods/ITEMS/mcl_banners/init.lua index 18b50928a..8c2c1298c 100644 --- a/mods/ITEMS/mcl_banners/init.lua +++ b/mods/ITEMS/mcl_banners/init.lua @@ -22,22 +22,22 @@ mcl_banners = {} mcl_banners.colors = { -- Format: -- [ID] = { banner description, wool, unified dyes color group, overlay color, dye, color name for emblazonings } - ["unicolor_white"] = {"white", S("White Banner"), "mcl_wool:white", "#FFFFFF", "mcl_dye:white", N("White") }, + ["unicolor_white"] = {"white", S("White Banner"), "mcl_wool:white", "#C8C8C8", "mcl_dye:white", N("White") }, ["unicolor_darkgrey"] = {"grey", S("Grey Banner"), "mcl_wool:grey", "#303030", "mcl_dye:dark_grey", N("Grey") }, ["unicolor_grey"] = {"silver", S("Light Grey Banner"), "mcl_wool:silver", "#5B5B5B", "mcl_dye:grey", N("Light Grey") }, ["unicolor_black"] = {"black", S("Black Banner"), "mcl_wool:black", "#000000", "mcl_dye:black", N("Black") }, - ["unicolor_red"] = {"red", S("Red Banner"), "mcl_wool:red", "#BC0000", "mcl_dye:red", N("Red") }, - ["unicolor_yellow"] = {"yellow", S("Yellow Banner"), "mcl_wool:yellow", "#E6CD00", "mcl_dye:yellow", N("Yellow") }, - ["unicolor_dark_green"] = {"green", S("Green Banner"), "mcl_wool:green", "#006000", "mcl_dye:dark_green", N("Green") }, - ["unicolor_cyan"] = {"cyan", S("Cyan Banner"), "mcl_wool:cyan", "#00ACAC", "mcl_dye:cyan", N("Cyan") }, - ["unicolor_blue"] = {"blue", S("Blue Banner"), "mcl_wool:blue", "#0000AC", "mcl_dye:blue", N("Blue") }, - ["unicolor_red_violet"] = {"magenta", S("Magenta Banner"), "mcl_wool:magenta", "#AC007C", "mcl_dye:magenta", N("Magenta")}, - ["unicolor_orange"] = {"orange", S("Orange Banner"), "mcl_wool:orange", "#E67300", "mcl_dye:orange", N("Orange") }, - ["unicolor_violet"] = {"purple", S("Purple Banner"), "mcl_wool:purple", "#6400AC", "mcl_dye:violet", N("Violet") }, - ["unicolor_brown"] = {"brown", S("Brown Banner"), "mcl_wool:brown", "#603000", "mcl_dye:brown", N("Brown") }, - ["unicolor_pink"] = {"pink", S("Pink Banner"), "mcl_wool:pink", "#DE557C", "mcl_dye:pink", N("Pink") }, - ["unicolor_lime"] = {"lime", S("Lime Banner"), "mcl_wool:lime", "#30AC00", "mcl_dye:green", N("Lime") }, - ["unicolor_light_blue"] = {"light_blue", S("Light Blue Banner"), "mcl_wool:light_blue", "#4040CF", "mcl_dye:lightblue", N("Light Blue") }, + ["unicolor_red"] = {"red", S("Red Banner"), "mcl_wool:red", "#760F15", "mcl_dye:red", N("Red") }, + ["unicolor_yellow"] = {"yellow", S("Yellow Banner"), "mcl_wool:yellow", "#E2b43E", "mcl_dye:yellow", N("Yellow") }, + ["unicolor_dark_green"] = {"green", S("Green Banner"), "mcl_wool:green", "#385833", "mcl_dye:dark_green", N("Green") }, + ["unicolor_cyan"] = {"cyan", S("Cyan Banner"), "mcl_wool:cyan", "#114C56", "mcl_dye:cyan", N("Cyan") }, + ["unicolor_blue"] = {"blue", S("Blue Banner"), "mcl_wool:blue", "#20336B", "mcl_dye:blue", N("Blue") }, + ["unicolor_red_violet"] = {"magenta", S("Magenta Banner"), "mcl_wool:magenta", "#B36897", "mcl_dye:magenta", N("Magenta")}, + ["unicolor_orange"] = {"orange", S("Orange Banner"), "mcl_wool:orange", "#B35E2E", "mcl_dye:orange", N("Orange") }, + ["unicolor_violet"] = {"purple", S("Purple Banner"), "mcl_wool:purple", "#764F91", "mcl_dye:violet", N("Violet") }, + ["unicolor_brown"] = {"brown", S("Brown Banner"), "mcl_wool:brown", "#46251A", "mcl_dye:brown", N("Brown") }, + ["unicolor_pink"] = {"pink", S("Pink Banner"), "mcl_wool:pink", "#C98196", "mcl_dye:pink", N("Pink") }, + ["unicolor_lime"] = {"lime", S("Lime Banner"), "mcl_wool:lime", "#7DA553", "mcl_dye:green", N("Lime") }, + ["unicolor_light_blue"] = {"light_blue", S("Light Blue Banner"), "mcl_wool:light_blue", "#5176B2", "mcl_dye:lightblue", N("Light Blue") }, } @@ -96,8 +96,8 @@ end dofile(modpath.."/patterncraft.lua") -- Overlay ratios (0-255) -local base_color_ratio = 224 -local layer_ratio = 255 +local base_color_ratio = 225 +local layer_ratio = 225 local standing_banner_entity_offset = { x=0, y=-0.499, z=0 } local hanging_banner_entity_offset = { x=0, y=-1.7, z=0 } @@ -181,7 +181,7 @@ function mcl_banners.make_banner_texture(base_color, layers) local color = mcl_banners.colors[layerinfo.color][4] -- Generate layer texture - local layer = "(("..pattern.."^[colorize:"..color..":"..layer_ratio..")^[mask:"..pattern..")" + local layer = "((mcl_banners_banner_base.png^[colorize:"..color..":"..layer_ratio..")^[mask:"..pattern..")" finished_banner = finished_banner .. "^" .. layer end diff --git a/textures/mcl_banners_banner_base.png b/textures/mcl_banners_banner_base.png index 3ccd925645bb964163d525a6173a6211aafe1d95..b7824f0ec2a19feee5efc57e33221c5a8585caca 100644 GIT binary patch delta 1117 zcmV-j1fu(w2IdHm7=H)`00020X>r~F00b>bL_t(|+U=UZs#Gx$#`k%w#ZCk(K@e;N zI}2-H!t%a=l}~U>L9A{i+{#LDsoZq~9et&*=|K9o8;|FG<jir z4~Iia(cUwN_4f8QrD(6u-HdM#n(+<7Gytd5>7p4BXxjsDJRUEa0fDw2fM#&hmroyE zRIjJZ02pS0V8gQj7=i_Y4etT?_T|&L>5uPUFRItmmVg@R>6Rs+MtT}8fe-KAo|}ID z`2M1LT>`*HWPc&3@d|*A$U;!#?`#QRdRyx}GG3R80?<*-7_UnO&kIAF6Ksm>rp+l% zbAk~F>%Ip-N8JNq-S=hyjAZ}-vKav4I#1*5sH^el0|0m$XGdL)M<2Qb002M`7E1uw zn5+}z_7(s(ChG*by#kmX1v~(~^{>;O0qFXV!kuTl2Y+CC6i@&#EOLbE`T4#D0ER`5 zP(452w|oFQK`e>V60j1WOxkPBh$sQdq`lURh@t>H#u9+Y+xLv;`%#v+#ds?bVgSux z4uhpA5UqQ!2Jj+5FU_?;ME;=tt^hFNoCK8tZ1Miy=qrFN-rpO21)!NA=LO|FAmja` zXrN9o>wo>DXyD}moC;3?kV$`gqptum>2GiJEdab9fa@{O$X3}U=>k406hqn^Sm9snx=vZ_aJqj|uzYB1Uh%c5Y?KLd*wZL59Y6%ZoBllj5d?4g zdmAF036}Q*Ebs3@h-!iMX>E!1AVjr*l?q#Rz%YQ`ZcwilU@!pC+YRc~0t|)$@Q5pb zp-oW$z=)650<0PWM{5Dr9staUGJug(ShL8{B*@w$>;Yh(PzEqs3q$}$Yk>%W)&kQ2 zz<-Dl<2?W{V#N3?fby1@WkkgfSO7*!V$TOy#n68XfK%fs04lx!pV406Rsi^nYJoBU zEBtMNppMXs|63raBUAuxpyw` z#{gKT#8m*+DRJ+3dLT zH$(MIV1`=z0SaI!4E}4P2P0)4;Jtjrr!MUUgmwmx>-N3f!!;}aU;D}QXB~aE8eQ?paGe*3P-;w$xH9-XM^ggt^=91U?TbSE*eZ(zR1QMFAe) z7r9p2X$A^_Pf@@^+(H9Ddgc~r61LxOCulZqT5d~)p3w8u5}#s!IYEsh5GEZe6$n7l z2++lE7l6PR(g8paIW6LgEg&5N2%x2uNsB$&d+EU^uz$!(>kJgCewYF%gQ2eY49Lhu zb*41wsT4JavnbOSAbp*80C3?fYVYGG-~nU;yodW0Gz;+p%_})o#KgefY-}s-UXU77{z{pr!6f3=32^2%mDYjzrgAfsJN#DoQR)*KZ@EaO*sLe z{{pChF@abBZATB44o43Y|Kr@tZTh?bRcg))jDHiVE}*UHh@0j!!am|n{4VAZ`|=$3 z|9<@c-Iy46!%urOcxk%=Y~TI_7H*u}-> z)w;tbKnEg#iHVEzn#XphR=GGkuUchn^LX767b|B58i7$T3INtS(sSZ#MScJP002ov KP6b4+LSTaU>R}K7 From aa08a176fc60b60739116cc11b2c4350edf6104f Mon Sep 17 00:00:00 2001 From: SmokeyDope Date: Sun, 27 Aug 2023 22:20:54 +0000 Subject: [PATCH 81/82] lower ruined portal structure spawn rate --- mods/MAPGEN/mcl_structures/ruined_portal.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/MAPGEN/mcl_structures/ruined_portal.lua b/mods/MAPGEN/mcl_structures/ruined_portal.lua index 0f7df6686..ef8c806ca 100644 --- a/mods/MAPGEN/mcl_structures/ruined_portal.lua +++ b/mods/MAPGEN/mcl_structures/ruined_portal.lua @@ -12,7 +12,7 @@ end local def = { place_on = {"group:grass_block","group:dirt","mcl_core:dirt_with_grass","group:grass_block","group:sand","group:grass_block_snow","mcl_core:snow"}, - fill_ratio = 0.01, + fill_ratio = 0.006, flags = "place_center_x, place_center_z, all_floors", solid_ground = true, make_foundation = true, From b911f99d23d3e4a3051e98375c99635e5d8d32a3 Mon Sep 17 00:00:00 2001 From: SmokeyDope Date: Sun, 27 Aug 2023 04:24:33 +0000 Subject: [PATCH 82/82] fix barrel sound code for proper max hear distance --- mods/ITEMS/mcl_barrels/init.lua | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/mods/ITEMS/mcl_barrels/init.lua b/mods/ITEMS/mcl_barrels/init.lua index e2f46be28..face52d6d 100644 --- a/mods/ITEMS/mcl_barrels/init.lua +++ b/mods/ITEMS/mcl_barrels/init.lua @@ -67,7 +67,10 @@ local function barrel_open(pos, node, clicker) minetest.swap_node(pos, { name = "mcl_barrels:barrel_open", param2 = node.param2 }) open_barrels[playername] = pos - minetest.sound_play({ name = "mcl_barrels_default_barrel_open", pos = pos, gain = 0.5, max_hear_distance = 16 }, true) + minetest.sound_play({name="mcl_barrels_default_barrel_open", gain=0.5}, { + pos = pos, + max_hear_distance = 16, + }, true) end ---@param pos Vector @@ -87,8 +90,11 @@ local function update_after_close(pos) if not node then return end if node.name == "mcl_barrels:barrel_open" then minetest.swap_node(pos, { name = "mcl_barrels:barrel_closed", param2 = node.param2 }) - minetest.sound_play({ name = "mcl_barrels_default_barrel_close", pos = pos, gain = 0.5, max_hear_distance = 16 }, - true) + minetest.sound_play({name="mcl_barrels_default_barrel_close", gain=0.5}, { + pos = pos, + max_hear_distance = 16, + }, true) + end end