From 4ee6a67516376fc8935aa7ccfb4562e65f1c27f3 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Mon, 20 Sep 2021 09:22:13 +0200 Subject: [PATCH] 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^5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