From de9a114f9466884d49843ecba623217e9d26ca0f Mon Sep 17 00:00:00 2001 From: Emojigit <55009343+Emojigit@users.noreply.github.com> Date: Thu, 30 Dec 2021 08:02:33 +0800 Subject: [PATCH 1/2] Way to make drawers public! (tested on area mod) --- init.lua | 23 ++++++++++++++++++++ lua/.visual.lua.swp | Bin 0 -> 1024 bytes lua/api.lua | 12 ++++++++--- lua/visual.lua | 32 +++++++++++++++++++++++++--- textures/drawers_upgrade_public.png | Bin 0 -> 5356 bytes 5 files changed, 61 insertions(+), 6 deletions(-) create mode 100644 lua/.visual.lua.swp create mode 100644 textures/drawers_upgrade_public.png diff --git a/init.lua b/init.lua index e6f31e2..30f04bb 100755 --- a/init.lua +++ b/init.lua @@ -288,6 +288,17 @@ if core.get_modpath("default") and default then groups = {drawer_upgrade = 700}, recipe_item = "default:diamond" }) + + drawers.register_drawer_upgrade("drawers:upgrade_public", { + description = S("Public Drawer Upgrade"), + inventory_image = "drawers_upgrade_public.png", + groups = {drawer_upgrade = 0, drawer_public = 1}, + craft = { + {"group:stick","default:steel_ingot","group:stick"}, + {"group:stick", "drawers:upgrade_template", "group:stick"}, + {"group:stick","default:steel_ingot","group:stick"} + } + }) elseif core.get_modpath("mcl_core") and mcl_core then drawers.register_drawer_upgrade("drawers:upgrade_iron", { description = S("Iron Drawer Upgrade (x2)"), @@ -323,6 +334,18 @@ elseif core.get_modpath("mcl_core") and mcl_core then groups = {drawer_upgrade = 1200}, recipe_item = "mcl_core:emerald" }) + + drawers.register_drawer_upgrade("drawers:upgrade_public", { + description = S("Public Drawer Upgrade"), + inventory_image = "drawers_upgrade_public.png", + groups = {drawer_upgrade = 0, drawer_public = 1}, + craft = { + {"group:stick","mcl_core:iron_ingot","group:stick"}, + {"group:stick", "drawers:upgrade_template", "group:stick"}, + {"group:stick","mcl_core:iron_ingot","group:stick"} + } + }) + end if core.get_modpath("moreores") then diff --git a/lua/.visual.lua.swp b/lua/.visual.lua.swp new file mode 100644 index 0000000000000000000000000000000000000000..0dacf8c2fd2c3e471973d2f7f0e990176ab1b846 GIT binary patch literal 1024 zcmYc?$V<%2S1{Ex(_=seatl})O7bg 1 then return 0 end - if core.get_item_group(stack:get_name(), "drawer_upgrade") < 1 then + if core.get_item_group(stack:get_name(), "drawer_upgrade_any") < 1 then return 0 end return 1 @@ -405,15 +405,16 @@ end function drawers.register_drawer_upgrade(name, def) def.groups = def.groups or {} def.groups.drawer_upgrade = def.groups.drawer_upgrade or 100 + def.groups.drawer_upgrade_any = 1 def.inventory_image = def.inventory_image or "drawers_upgrade_template.png" def.stack_max = 1 - local recipe_item = def.recipe_item or "air" + local recipe_item = def.recipe_item def.recipe_item = nil core.register_craftitem(name, def) - if not def.no_craft then + if not def.no_craft and recipe_item then core.register_craft({ output = name, recipe = { @@ -422,6 +423,11 @@ function drawers.register_drawer_upgrade(name, def) {recipe_item, "group:stick", recipe_item} } }) + elseif def.craft then + core.register_craft({ + output = name, + recipe = def.craft + }) end end diff --git a/lua/visual.lua b/lua/visual.lua index 56974b0..e978132 100755 --- a/lua/visual.lua +++ b/lua/visual.lua @@ -153,7 +153,19 @@ core.register_entity("drawers:visual", { end, on_rightclick = function(self, clicker) - if core.is_protected(self.drawer_pos, clicker:get_player_name()) then + local upgrades = core.get_meta(self.drawer_pos):get_inventory():get_list("upgrades") + + local private = true + for _,itemStack in pairs(upgrades) do + local iname = itemStack:get_name() + local idef = core.registered_items[iname] + if idef.groups.drawer_public == 1 then + private = false + break + end + end + + if private and core.is_protected(self.drawer_pos, clicker:get_player_name()) then core.record_protection_violation(self.drawer_pos, clicker:get_player_name()) return end @@ -209,14 +221,28 @@ core.register_entity("drawers:visual", { end, on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir) - local node = minetest.get_node(self.object:get_pos()) + local pos = self.object:get_pos() + local node = minetest.get_node(pos) if core.get_item_group(node.name, "drawer") == 0 then self.object:remove() return end + + local upgrades = core.get_meta(pos):get_inventory():get_list("upgrades") + + local private = true + for _,itemStack in pairs(upgrades) do + local iname = itemStack:get_name() + local idef = core.registered_items[iname] + if idef.groups.drawer_public == 1 then + private = false + break + end + end + local add_stack = not puncher:get_player_control().sneak - if core.is_protected(self.drawer_pos, puncher:get_player_name()) then + if private and core.is_protected(self.drawer_pos, puncher:get_player_name()) then core.record_protection_violation(self.drawer_pos, puncher:get_player_name()) return end diff --git a/textures/drawers_upgrade_public.png b/textures/drawers_upgrade_public.png new file mode 100644 index 0000000000000000000000000000000000000000..941ebf0fb5de2da7c32a983e5d26007a582bc681 GIT binary patch literal 5356 zcmeHLd00|u7suT!TQs#r6R}dq5V)WMiYY>BhFPwur5Cu+Ras$S*9Qjp z7#qznLZMK`e!h&Q$oFLRM^^_q_Ow4i1bQ=)gTrM@!6dX;BI3dE5L&iM451+f%tN6R zcTb1KZSFr~G<+;XWup5cb6Xj|<<%pn)dlm~{M;H^+llg?yg54hwOadkj9j>oJ2c+n zr15V<pCH^kseFhPwAYw!2i2_VDzYVz{1EFaFf?gvI`ULDG&lyhgxIusk~ zvGtE!;cXyd`B;l$8Q%RS34uV_BIm7{-F+w}IS z8E4G*5Is+`i<2%Lt?$kYURiZFt9mI$KWdGo^Hoy0HRphlg;mn!DW=bjbnTYRkvuUP zFf4z3@Zyrqq$M$tTGbg>x8r0xSXIi)%1aX4b%0mfqTJ|*&wsJrNbt|B?>2LMTj##U z*mbU?e;ff#=NPnDYkBm(WBTa3`Py7P$uQB5+?MyGt7+UbR0R43p>oFlJ5}1*h6icI zHd@-A`L#jlnLBN#Xdgn^UzVF+(K9R>y#Hvn+a^@})}P>1ldj3oP4vvhCRIlE_6(yS z^j58H(pf{MyD_;ZEPBrmUi3NUF=RRW%p-3@g6iOoG6sKNq0MjQgu04-0l(_!A6Am= z0b3zd5-6ewHu~}op;zo5rKFyvif0F}<&(SYc=>bLo{e(${1>%1{-Db+gQa3( zQ`*J+4_FD0KIs2!MM6q$#IAdRw8@bnp*&u?YwL!H+EtPVF^(m+Z!Wb- zI&~+dq!yXEMeQQpblFDhx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mzn)i%1nJ-zMFqAKS0A})Y zHgee|WX8Pbk>M~HiVuF`@I<_z#Xj2iZ1Lmsb<40J;ZIB6uf14NbwVXqu2~08@h?Kt zz4Vw{V{GV07UZqh?eU?#*C~j`Y^PUZrculTbBx;h)_l0wE4+UHS@y1}8?}3IRl|e{ zx`~;|Emao^1=Z==Z%Z>Bk9Of&Gj=Y%b%cdY)s=~KELvHtHXWy=j1jx#E?l2KZ%>s_ z9u04-aWEcupuIazD9TSO_CWb{|B$X@X{l|y>gtL?MUqdP=tBuSFsSp>pOW)~B8e@s zHJuf>D440)q@q0VHgGUex`L9*_9)F}ohphrzk}V@);6FdaS;nG+0uX@l;`t1$WuR* z7Te#4fm)|$<%?X56Za)gLXCvUnOIG?4kRm4mX^;f^}Aejv*roD~@v5ixGvl=#>u?5tg03 Date: Thu, 30 Dec 2021 08:06:09 +0800 Subject: [PATCH 2/2] fix luacheck --- lua/.visual.lua.swp | Bin 1024 -> 0 bytes lua/visual.lua | 6 +++--- 2 files changed, 3 insertions(+), 3 deletions(-) delete mode 100644 lua/.visual.lua.swp diff --git a/lua/.visual.lua.swp b/lua/.visual.lua.swp deleted file mode 100644 index 0dacf8c2fd2c3e471973d2f7f0e990176ab1b846..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1024 zcmYc?$V<%2S1{Ex(_=seatl})O7bg