add `hopper` support (#18)

This commit is contained in:
nixnoxus 2022-02-04 00:40:38 +01:00 committed by GitHub
parent a8fceb249d
commit d68e90f017
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 3 deletions

View File

@ -148,7 +148,8 @@ function homedecor.register_furnace(name, furnacedef)
can_dig = furnace_can_dig,
allow_metadata_inventory_put = furnace_allow_put,
allow_metadata_inventory_move = furnace_allow_move,
inventory = { lockable = true }
inventory = { lockable = true },
is_furnace = true
}
local def_active = {
@ -162,7 +163,8 @@ function homedecor.register_furnace(name, furnacedef)
can_dig = furnace_can_dig,
allow_metadata_inventory_put = furnace_allow_put,
allow_metadata_inventory_move = furnace_allow_move,
inventory = { lockable = true }
inventory = { lockable = true },
is_furnace = true
}
if furnacedef.extra_nodedef_fields then

View File

@ -1,5 +1,12 @@
local S = minetest.get_translator("homedecor_common")
local has_hopper = minetest.get_modpath("hopper")
local has_safe_hopper = has_hopper and
-- mod from https://github.com/minetest-mods/hopper respects the owner
(hopper.neighbors or
-- mod from https://notabug.org/TenPlus1/hopper respects the owner since 20220123
(hopper.version and hopper.version >= "20220123"))
local default_can_dig = function(pos,player)
local meta = minetest.get_meta(pos)
return meta:get_inventory():is_empty("main")
@ -97,6 +104,23 @@ function homedecor.handle_inventory(name, def, original_def)
end
local locked = inventory.locked
if has_hopper and (not locked or has_safe_hopper) then
if inventory.size then
hopper:add_container({
{"top", "homedecor:"..name, "main"},
{"bottom", "homedecor:"..name, "main"},
{"side", "homedecor:"..name, "main"},
})
elseif original_def.is_furnace then
hopper:add_container({
{"top", "homedecor:"..name, "dst"},
{"bottom", "homedecor:"..name, "src"},
{"side", "homedecor:"..name, "fuel"},
})
end
end
if locked then
local after_place_node = def.after_place_node
def.after_place_node = function(pos, placer)

View File

@ -1,4 +1,4 @@
name = homedecor_common
description = Homedecor mod: common
depends = default, creative
optional_depends = screwdriver
optional_depends = screwdriver, hopper

View File

@ -6,6 +6,8 @@ local placeholder_node = "homedecor:expansion_placeholder"
function homedecor.register(name, original_def)
local def = table.copy(original_def)
def.is_furnace = nil
def.drawtype = def.drawtype
or (def.mesh and "mesh")
or (def.node_box and "nodebox")