Way to make drawers public! (tested on area mod)

fork-master
Emojigit 2021-12-30 08:02:33 +08:00
parent 70207e64f9
commit de9a114f94
No known key found for this signature in database
GPG Key ID: 2443E5F619026B90
5 changed files with 61 additions and 6 deletions

View File

@ -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

BIN
lua/.visual.lua.swp Normal file

Binary file not shown.

View File

@ -157,7 +157,7 @@ function drawers.drawer_allow_metadata_inventory_put(pos, listname, index, stack
if stack:get_count() > 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

View File

@ -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

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB