From 84b779f8dfcbc0c14218d34d06726b9e8b3a97e6 Mon Sep 17 00:00:00 2001 From: mckaygerhard Date: Fri, 16 Jun 2023 00:38:15 -0400 Subject: [PATCH] creatuve - updated upgraded simplified and provide privilegie feature * register privilegie of creative for older or newer engines * enhanced the formspec of the creative player to 4 rows * try to upgrade most close to track upstream original * return back text button, remove extra media check https://notabug.org/TenPlus1/creative/issues/2 * update readme information to diference features --- mods/creative/README.md | 17 ++- mods/creative/README.txt | 11 +- mods/creative/description.txt | 2 +- mods/creative/init.lua | 120 +++++++++++------- mods/creative/inventory.lua | 49 +++---- mods/creative/license.txt | 1 - mods/creative/mod.conf | 2 +- .../creative/textures/creative_clear_icon.png | Bin 605 -> 0 bytes mods/creative/textures/creative_next_icon.png | Bin 578 -> 0 bytes mods/creative/textures/creative_prev_icon.png | Bin 593 -> 0 bytes .../textures/creative_search_icon.png | Bin 1363 -> 0 bytes 11 files changed, 124 insertions(+), 78 deletions(-) delete mode 100644 mods/creative/textures/creative_clear_icon.png delete mode 100644 mods/creative/textures/creative_next_icon.png delete mode 100644 mods/creative/textures/creative_prev_icon.png delete mode 100644 mods/creative/textures/creative_search_icon.png diff --git a/mods/creative/README.md b/mods/creative/README.md index 9478a9b..68f082b 100644 --- a/mods/creative/README.md +++ b/mods/creative/README.md @@ -1,13 +1,14 @@ Minetest Game mod: creative =========================== -Simplified creative with faster loading +Simplified creative for more accurate on mobile or small screens Information ------------ This mod is named `creative` and is a replacement for default "creative" mod -of orginal game, with reduced tabs, also it uses a cached memory to faster lodaing. +of orginal game, with reduced tabs, also minenux fork it uses a cached memory and no images +to faster lodaing respect settings. ![screenshot.png](screenshot.png) @@ -19,9 +20,19 @@ for backguard compatibility with 5.2 and 0.4.16, with minimal backports, you can download from https://codeberg.org/minenux/minetest-mod-creative and after clone or downloaded renamed to `creative` (obviously replace the current one if any) -Modified by TenPlus1 (added creative privelage, reduced tab count, tweaked code), +Modified by TenPlus1 (added creative privilege, reduced tab count, tweaked code), original work is at https://notabug.org/TenPlus1/creative +The minenux fork cut down images to use only text so media download is not a hit! + +#### Api + +You can use `creative.is_creative(playername)` (older) or `creative.is_enabled_for(playername)`. + +#### Dependencies + +* sfinv + ### Authors of source code Originally by Perttu Ahola (celeron55) (MIT) diff --git a/mods/creative/README.txt b/mods/creative/README.txt index 9478a9b..ec7e6ed 100644 --- a/mods/creative/README.txt +++ b/mods/creative/README.txt @@ -1,13 +1,14 @@ Minetest Game mod: creative =========================== -Simplified creative with faster loading +Simplified creative for more accurate on mobile or small screens Information ------------ This mod is named `creative` and is a replacement for default "creative" mod -of orginal game, with reduced tabs, also it uses a cached memory to faster lodaing. +of orginal game, with reduced tabs, also minenux fork it uses a cached memory +to faster lodaing respect settings. ![screenshot.png](screenshot.png) @@ -19,9 +20,11 @@ for backguard compatibility with 5.2 and 0.4.16, with minimal backports, you can download from https://codeberg.org/minenux/minetest-mod-creative and after clone or downloaded renamed to `creative` (obviously replace the current one if any) -Modified by TenPlus1 (added creative privelage, reduced tab count, tweaked code), +Modified by TenPlus1 (added creative privilege, reduced tab count, tweaked code), original work is at https://notabug.org/TenPlus1/creative +The minenux fork cut down images to use only text so media download is not a hit! + ### Authors of source code Originally by Perttu Ahola (celeron55) (MIT) @@ -29,7 +32,7 @@ Jean-Patrick G. (kilbith) (MIT) ### Author of media (textures) -Jean-Patrick G. (kilbith) (CC BY-SA 3.0) +Jean-Patrick G. (kilbith) (CC-BY-SA 3.0) LICENSE ------- diff --git a/mods/creative/description.txt b/mods/creative/description.txt index aefb5cd..5dfff03 100644 --- a/mods/creative/description.txt +++ b/mods/creative/description.txt @@ -1 +1 @@ -Simplified creative with faster loading +Simplified creative for more accurate on mobile or small screens diff --git a/mods/creative/init.lua b/mods/creative/init.lua index 955fd2c..174ee9d 100644 --- a/mods/creative/init.lua +++ b/mods/creative/init.lua @@ -23,14 +23,19 @@ else end end +local is_50 = minetest.has_feature("object_use_texture_alpha") local is_53 = minetest.has_feature("object_step_has_moveresult") local is_54 = minetest.has_feature("direct_velocity_on_players") creative = {} creative.get_translator = S +creative.is_50 = is_50 creative.is_53 = is_53 creative.is_54 = is_54 +local privs_description = "Allow player to use creative inventory" +local privs_definition = {} + local function update_sfinv(name) minetest.after(0, function() local player = minetest.get_player_by_name(name) @@ -44,20 +49,33 @@ local function update_sfinv(name) end) end -minetest.register_privilege("creative", { - description = S("Allow player to use creative inventory"), - give_to_singleplayer = false, - give_to_admin = false, - on_grant = update_sfinv, - on_revoke = update_sfinv, -}) +if is_50 then + privs_definition = { + description = privs_description, + give_to_singleplayer = false, + give_to_admin = false, + on_grant = update_sfinv, + on_revoke = update_sfinv + } +else + privs_definition = { + description = privs_description, + give_to_singleplayer = false + } +end + +minetest.register_privilege("creative", privs_definition) local creative_mode_cache = minetest.settings:get_bool("creative_mode") -- backguard compatibility function creative.is_creative(name) - if is_53 then - return minetest.is_creative_enabled(name) + if creative.is_53 then + if name == "" then + return minetest.is_creative_enabled(name) + else + return minetest.check_player_privs(name, {creative = true}) or creative_mode_cache + end else return minetest.check_player_privs(name, {creative = true}) or creative_mode_cache end @@ -74,7 +92,7 @@ end -- For backwards compatibility: function creative.is_enabled_for(name) - return minetest.is_creative_enabled(name) + return creative.is_creative(name) end dofile(minetest.get_modpath("creative") .. "/inventory.lua") @@ -87,57 +105,67 @@ if minetest.is_creative_enabled("") then -- To speed up digging in creative, hand 'maxlevel' and 'digtime' have been -- increased such that nodes of differing levels have an insignificant -- effect on digtime. - local digtime = 42 - local caps = {times = {digtime, digtime, digtime}, uses = 0, maxlevel = 256} + local digtime = 42 + local caps = {times = {digtime, digtime, digtime}, uses = 0, maxlevel = 256} - -- Override the hand tool - minetest.override_item("", { - range = 10, - tool_capabilities = { - full_punch_interval = 0.5, - max_drop_level = 3, - groupcaps = { - crumbly = caps, - cracky = caps, - snappy = caps, - choppy = caps, - oddly_breakable_by_hand = caps, + minetest.register_item(":", { + type = "none", + wield_image = "wieldhand.png", + wield_scale = {x = 1, y = 1, z = 2.5}, + range = 10, + tool_capabilities = { + full_punch_interval = 0.5, + max_drop_level = 3, + groupcaps = { + crumbly = caps, + cracky = caps, + snappy = caps, + choppy = caps, + oddly_breakable_by_hand = caps, -- dig_immediate group doesn't use value 1. Value 3 is instant dig - dig_immediate = - {times = {[2] = digtime, [3] = 0}, uses = 0, maxlevel = 256}, - }, - damage_groups = {fleshy = 10}, - } - }) + dig_immediate = {times = {[2] = digtime, [3] = 0}, uses = 0, maxlevel = 256}, + }, + damage_groups = {fleshy = 10}, + } + }) end if minetest.register_on_mods_loaded then minetest.register_on_mods_loaded(hand_hack) else - minetest.after(0, hand_hack) + minetest.after(0.2, hand_hack) end end -- Unlimited node placement minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack) - if placer and placer:is_player() then - return minetest.is_creative_enabled(placer:get_player_name()) + if placer then + if placer:is_player() then + return creative.is_creative(placer:get_player_name()) + end end end) ---[[ Don't pick up if the item is already in the inventory -local old_handle_node_drops = minetest.handle_node_drops -function minetest.handle_node_drops(pos, drops, digger) - if not digger or not digger:is_player() or - not minetest.is_creative_enabled(digger:get_player_name()) then - return old_handle_node_drops(pos, drops, digger) - 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) +-- Don't pick up if the item is already in the inventory only in hard creative single +if creative_mode_cache then + local old_handle_node_drops = minetest.handle_node_drops + function minetest.handle_node_drops(pos, drops, digger) + if not digger then + if not digger:is_player() then + if not creative.is_creative(digger:get_player_name()) then + return old_handle_node_drops(pos, drops, digger) + end + 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 end -]] + +print("[creative] mod loaded") + diff --git a/mods/creative/inventory.lua b/mods/creative/inventory.lua index 14701fb..4098c6d 100644 --- a/mods/creative/inventory.lua +++ b/mods/creative/inventory.lua @@ -1,6 +1,6 @@ -- creative/inventory.lua --- support for MT game translation. +-- Load support for MT game translation. local S = creative.get_translator local player_inventory = {} @@ -33,7 +33,7 @@ function creative.init_creative_inventory(player) minetest.create_detached_inventory("creative_" .. player_name, { allow_move = function(inv, from_list, from_index, to_list, to_index, count, player2) local name = player2 and player2:get_player_name() or "" - if not minetest.is_creative_enabled(name) or + if not creative.is_enabled_for(name) or to_list == "main" then return 0 end @@ -44,7 +44,7 @@ function creative.init_creative_inventory(player) end, allow_take = function(inv, listname, index, stack, player2) local name = player2 and player2:get_player_name() or "" - if not minetest.is_creative_enabled(name) then + if not creative.is_enabled_for(name) then return 0 end return -1 @@ -74,8 +74,10 @@ end local function description(def, lang_code) local s = def.description - if lang_code then - s = minetest.get_translated_string(lang_code, s) + if creative.is_53 then + if lang_code then + s = minetest.get_translated_string(lang_code, s) + end end return s:gsub("\n.*", "") -- First line only end @@ -93,10 +95,13 @@ function creative.update_creative_inventory(player_name, tab_content) local items = inventory_cache[tab_content] or init_creative_cache(tab_content) - local lang + local lang = minetest.settings:get("language") or "en" local player_info = minetest.get_player_information(player_name) - if player_info and player_info.lang_code ~= "" then - lang = player_info.lang_code + + if is_53 then + if player_info and player_info.lang_code ~= "" then + lang = player_info.lang_code + end end local creative_list = {} @@ -143,12 +148,13 @@ function creative.register_tab(name, title, items) sfinv.register_page("creative:" .. name, { title = title, is_in_nav = function(self, player, context) - return minetest.is_creative_enabled(player:get_player_name()) + return creative.is_enabled_for(player:get_player_name()) end, get = function(self, player, context) local player_name = player:get_player_name() creative.update_creative_inventory(player_name, items) local inv = player_inventory[player_name] + local start_i = inv.start_i or 0 local pagenum = math.floor(inv.start_i / (4*8) + 1) local pagemax = math.max(math.ceil(inv.size / (4*8)), 1) local esc = minetest.formspec_escape @@ -156,14 +162,14 @@ function creative.register_tab(name, title, items) (inv.size == 0 and ("label[3,2;"..esc(S("No items to show.")).."]") or "") .. "label[5.8,4.15;" .. minetest.colorize("#FFFF00", tostring(pagenum)) .. " / " .. tostring(pagemax) .. "]" .. [[ - image[4.08,4.2;0.8,0.8;creative_trash_icon.png] + image[4,4;0.8,0.8;creative_trash_icon.png] listcolors[#00000069;#5A5A5A;#141318;#30434C;#FFF] - list[detached:trash;main;4.02,4.1;1,1;] + list[detached:trash;main;4,4;1,1;] listring[] - image_button[5,4.05;0.8,0.8;creative_prev_icon.png;creative_prev;] - image_button[7.25,4.05;0.8,0.8;creative_next_icon.png;creative_next;] - image_button[2.63,4.05;0.8,0.8;creative_search_icon.png;creative_search;] - image_button[3.25,4.05;0.8,0.8;creative_clear_icon.png;creative_clear;] + button[5,4.05;0.8,0.8;creative_prev;<] + button[7.25,4.05;0.8,0.8;creative_next;>] + button[2.63,4.05;0.8,0.8;creative_search;?] + button[3.25,4.05;0.8,0.8;creative_clear;X] ]] .. "tooltip[creative_search;" .. esc(S("Search")) .. "]" .. "tooltip[creative_clear;" .. esc(S("Reset")) .. "]" .. @@ -248,18 +254,17 @@ end if minetest.register_on_mods_loaded then minetest.register_on_mods_loaded(tab_items) else - minetest.after(0, tab_items) + minetest.after(0.1, tab_items) end ---creative.register_tab("all", S("Creative"), minetest.registered_items) -creative.register_tab("all", S("All"), minetest.registered_items) -creative.register_tab("nodes", S("Nodes"), registered_nodes) -creative.register_tab("tools", S("Tools"), registered_tools) -creative.register_tab("craftitems", S("Items"), registered_craftitems) +creative.register_tab("all", S("Creative"), minetest.registered_items) +--creative.register_tab("nodes", S("Nodes"), minetest.registered_nodes) +--creative.register_tab("tools", S("Tools"), minetest.registered_tools) +--creative.register_tab("craftitems", S("Items"), minetest.registered_craftitems) local old_homepage_name = sfinv.get_homepage_name function sfinv.get_homepage_name(player) - if minetest.is_creative_enabled(player:get_player_name()) then + if creative.is_enabled_for(player:get_player_name()) then return "creative:all" else return old_homepage_name(player) diff --git a/mods/creative/license.txt b/mods/creative/license.txt index 50ff9c7..4ad1d5f 100644 --- a/mods/creative/license.txt +++ b/mods/creative/license.txt @@ -30,7 +30,6 @@ Licenses of media (textures) Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) Copyright (C) 2016 Jean-Patrick G. (kilbith) -Copyright (C) 2018 paramat You are free to: Share — copy and redistribute the material in any medium or format. diff --git a/mods/creative/mod.conf b/mods/creative/mod.conf index 8aeabd1..198455a 100644 --- a/mods/creative/mod.conf +++ b/mods/creative/mod.conf @@ -1,3 +1,3 @@ name = creative depends = sfinv -description = Simplified creative with faster loading +description = Simplified creative for more accurate on mobiles or small screens diff --git a/mods/creative/textures/creative_clear_icon.png b/mods/creative/textures/creative_clear_icon.png deleted file mode 100644 index ab421d982217c402e98f09c73b76b835d80a82cb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 605 zcmeAS@N?(olHy`uVBq!ia0vp^4Is?H1|$#LC7xzrU{djPaSW-r_4e-R+(Ql`tO4F{ zUZ{I9ZumSc_C+7HDQy-jTjq|-ff4-4e!bO!68$Pd} znsEOwzsKc%4NLtmZ#*XyK93hGHu-O_|HJIm4KtB{exFj^-`(ZDe@JS|f=h)7&&z9M zIQHKcvT;8$`NMC$#t(OeIpR56-dhOl6XLjEs8BQ6;fGq|hp7%f`j{WiW;tZe+4A3F z@`DJ4KZ`$zIxtFc*FWYc5PqR{;aoVAHBjSvmSg*bZv6C0c&^9^(=?NnI398p8atAnqI|0p`N|%?+pv@8JqA3e!TT) z#n}iZ{;oYcE@;jdp7Ui6Z+}C>-Da$>z_0~`Q*p6zVGc0mN>b)g`D3mzI*-n`=Rso3&XF0 e(grecD7Rx+YuLZwxVX_ykhrI-pUXO@geCyceF(?^ diff --git a/mods/creative/textures/creative_next_icon.png b/mods/creative/textures/creative_next_icon.png deleted file mode 100644 index 4a3637dc14fa3b7279e0d910f01069a67dd67a78..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 578 zcmeAS@N?(olHy`uVBq!ia0vp^4Is?H1|$#LC7xzrVB++2aSW-r_4ck|mRO)j!$k)L zrN~B(MULeQ1O>Mzq%Z8$T*E59=w@Roi}H>+5glThcbuhu=G<#&jfko^-_8)tz`vzg+js5z_wA3;XQmy2ch}2>vtKpce`*bbT*&&>mtXDJ75?^D>NA!P zTdLw~*PdG)uFa%=a00`;(D|$8UrqhG)2dMD4EF-jgZ-sKb3(SyW!cPhL+MA{+|cu@ zcPq^hb+{V(b?vVgMFz$Vx=p7`g?7mB@I3f_`e5bPL!Jiu4C;*xI&DlFB)ASdbzl&4 zX0+gBd7vWDFxi12PmuM)@#rI)UoGW$#;U-?SP`MZ(7h0>TA0Iu1*|7Y10?i@g-HNx z%#Yhi6)|@|)iy;k=5#-t{wntCid*IrBN<~t#joCe)yeQImT6n+hm6{}M^qC$80K;E z?C1RwQt+c$VS7C@^9P2E0){qw3kL4{4;Z%T_t!?`^GE(*W8IMZ`?mP;cM(6Hu_WA< zmuYCtFJKVccaSmS2OE3BLuo<+Kbn~h{v2eK`1gQ;rygR#VW24w`S}ifXlL8-_wx(x z!}BE%9Da4S%Juh&56@W(He1EKe=aZaZx6$_Re!%e|679;RUqa+^Zg8AR&$@pUh`@J O@jYGrT-G@yGywp>G3vJf diff --git a/mods/creative/textures/creative_prev_icon.png b/mods/creative/textures/creative_prev_icon.png deleted file mode 100644 index d5e3c27a554f96aa8b7dcda8b988bd1d1703f40d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 593 zcmeAS@N?(olHy`uVBq!ia0vp^4Is?H1|$#LC7xzrV3P23aSW-r_4cl9mS~_v!$XG$ zT`80Bdqq^}_38U#wT-eruMd6ws<3qZuEfx1Isfvu#_wHmFFb$M@36FU zC-1M13s=9o{gw0AE3eL2{#?IG|7!oM@~=Cq(ptCue{w(0?EjKqJ9FxoW^DXfzWVvq z!moetJmXHdkorHkH0K89_7Rr?uuYM2Z@a2~LY zXE2LrV6$WNk%yX44OVlEuZHQyg0u0V+o#39jJtL~y@8i2VSQD|-qri!E`fO54?Mqa zv)a4pvVMd1KGrp>4{J;PV=?$~GoIn_{ePSX9xq_nBOuhk!IEGga)6D$js5EJ;`lE@ z2R0o1aBio5_22c&nHhQNtppByI2gcinBAF?N1lh(pa!TIzkm%BBTv5r!(nBhP7W3W zG_FNc@PC`CJeKy;{+Ih#wTGp}vAllzn}vVX?6A~0meo&{MXRr#>OzV)5VOGZAH$Zv VbDym?@%jehd%F6$taD0e0svuI_|X6W diff --git a/mods/creative/textures/creative_search_icon.png b/mods/creative/textures/creative_search_icon.png deleted file mode 100644 index 421b833e33575de33340cbd329cc4b8f108950b2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1363 zcmV-Z1+4msP){%yV>~7t@uyB9_-Da z4+0aw9Iyne1Dn88U=Mf?90JGjIgIc2;y0V|pQSj)1Td&)vmf{yzzlE?*aBVwRnAT| zjFfo5444N>zzg6Lt>;r5yA*AW>G|#l{z_c8%WdK9o^?$*fIxPHbU(U{)+n$2@341gl;ST9fcC$IzO_A@CA-2uuM(Ewp1Oj`=X!IBdY4{jlA{ z@Enexiy=7eTKpc^0TzJaHrg{BZR|vwX*t0zFlQvsKF{B7AlrWnYygv`QmN2xyGo@} z0ho+7-!?Ei*tSk^whCXdfqDKL;4v`X1slhs?Kch735r$>n{)1LRN2zb{Kvq}F4}oB zY)BgkUI4R3wlSxU#q_J1a?Ri9#+hGdB-lvF398X27mylo=zJ`;BxUb(ROI+5@-nHVmFZAq($B@0B!0+>m;_8-Jtd^m%)4~K0BDY?Lm zkv`plgR$!-X*0(&U@F6XmQ>JM!x2-yKzHCJ)UHt z>eobn#>3`%JO%C=`I^JZaaT?~)_{>7>d#2nT#r4VY~*VWd!ABDe*g^hP=5x(=A^ZZ z=SIHfun#G9^divLL;dLso0HZvJ{b9$!;a!6&3fDi3O&@HLfBl7W8lchD**8lASQtd zz-gd`APYgc7J#MToD0CkpqvZ9jUVccFB4~lbd-*YOjq=DyCp*6v9~9|G(1rq0uRJPN5wuYRS$BY~@mAe%zy*sEhZC;}71Gm4?@FOPO45Je!0Koo(P7>Xl-C<0Lgq6oyq zP#g(F5r`s?Zi(O*;A=geUlIJIr}HU-{kVtmE4`dQ5g7a&i@@OLSOf+?=OXw~59U(@ zp7}Wzfx*wQ2n>FXMPTrAECPd{V-Xnq9E;!^;Cq8FA|fIpA|fIpA|fIpA|fK^