Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)"),
Expand Down Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions lua/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = {
Expand All @@ -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

32 changes: 29 additions & 3 deletions lua/visual.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment on lines +161 to +162
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idef might be nil when items are removed from the game. This is an edge-case, but yet a potential bug.

Also I suggest to move all protection checks to a local function so that on_rightclick and on_punch use the identical checks.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if idef.groups.drawer_public == 1 then
if idef and 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
Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if idef.groups.drawer_public == 1 then
if idef and 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
Expand Down
Binary file added textures/drawers_upgrade_public.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.