Add setting trash_can_throw_in (#5)
This commit is contained in:
parent
5fd3df71e9
commit
f046558327
66
init.lua
66
init.lua
@ -2,6 +2,8 @@
|
|||||||
-- Functions
|
-- Functions
|
||||||
--
|
--
|
||||||
|
|
||||||
|
local trash_can_throw_in = minetest.settings:get_bool("trash_can_throw_in") or false
|
||||||
|
|
||||||
local fdir_to_front = {
|
local fdir_to_front = {
|
||||||
{x=0, z=1},
|
{x=0, z=1},
|
||||||
{x=1, z=0},
|
{x=1, z=0},
|
||||||
@ -25,14 +27,14 @@ end
|
|||||||
--
|
--
|
||||||
-- Custom Sounds
|
-- Custom Sounds
|
||||||
--
|
--
|
||||||
function default.node_sound_metal_defaults(table)
|
local function get_dumpster_sound()
|
||||||
table = table or {}
|
local sndtab = {
|
||||||
table.footstep = table.footstep or {name="default_hard_footstep", gain=0.4}
|
footstep = {name="default_hard_footstep", gain=0.4},
|
||||||
table.dig = table.dig or {name="metal_bang", gain=0.6}
|
dig = {name="metal_bang", gain=0.6},
|
||||||
table.dug = table.dug or {name="default_dug_node", gain=1.0}
|
dug = {name="default_dug_node", gain=1.0}
|
||||||
|
}
|
||||||
default.node_sound_defaults(table)
|
default.node_sound_defaults(sndtab)
|
||||||
return table
|
return sndtab
|
||||||
end
|
end
|
||||||
|
|
||||||
--
|
--
|
||||||
@ -155,7 +157,7 @@ minetest.register_node("trash_can:dumpster", {
|
|||||||
oddly_breakable_by_hand = 1,
|
oddly_breakable_by_hand = 1,
|
||||||
},
|
},
|
||||||
|
|
||||||
sounds = default.node_sound_metal_defaults(),
|
sounds = get_dumpster_sound(),
|
||||||
|
|
||||||
on_construct = function(pos)
|
on_construct = function(pos)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
@ -230,28 +232,30 @@ minetest.register_craft({
|
|||||||
-- Misc
|
-- Misc
|
||||||
--
|
--
|
||||||
|
|
||||||
-- Remove any items thrown in trash can.
|
if trash_can_throw_in then
|
||||||
local old_on_step = minetest.registered_entities["__builtin:item"].on_step
|
-- Remove any items thrown in trash can.
|
||||||
minetest.registered_entities["__builtin:item"].on_step = function(self, dtime)
|
local old_on_step = minetest.registered_entities["__builtin:item"].on_step
|
||||||
local item_pos = self.object:getpos()
|
minetest.registered_entities["__builtin:item"].on_step = function(self, dtime)
|
||||||
-- Round the values. Not essential, but makes logging look nicer.
|
local item_pos = self.object:getpos()
|
||||||
for key, value in pairs(item_pos) do item_pos[key] = math.floor(value + 0.5) end
|
-- Round the values. Not essential, but makes logging look nicer.
|
||||||
if minetest.get_node(item_pos).name == "trash_can:trash_can_wooden" then
|
for key, value in pairs(item_pos) do item_pos[key] = math.floor(value + 0.5) end
|
||||||
local item_stack = ItemStack(self.itemstring)
|
if minetest.get_node(item_pos).name == "trash_can:trash_can_wooden" then
|
||||||
local inv = minetest.get_inventory({type="node", pos=item_pos})
|
local item_stack = ItemStack(self.itemstring)
|
||||||
local leftover = inv:add_item("trashlist", item_stack)
|
local inv = minetest.get_inventory({type="node", pos=item_pos})
|
||||||
if leftover:get_count() == 0 then
|
local leftover = inv:add_item("trashlist", item_stack)
|
||||||
self.object:remove()
|
if leftover:get_count() == 0 then
|
||||||
minetest.log("action", item_stack:to_string() ..
|
self.object:remove()
|
||||||
" added to trash can at " .. minetest.pos_to_string(item_pos))
|
minetest.log("action", item_stack:to_string() ..
|
||||||
elseif item_stack:get_count() - leftover:get_count() ~= 0 then
|
" added to trash can at " .. minetest.pos_to_string(item_pos))
|
||||||
self.set_item(self, leftover:to_string())
|
elseif item_stack:get_count() - leftover:get_count() ~= 0 then
|
||||||
minetest.log("action", item_stack:to_string() ..
|
self.set_item(self, leftover:to_string())
|
||||||
" added to trash can at " .. minetest.pos_to_string(item_pos) ..
|
minetest.log("action", item_stack:to_string() ..
|
||||||
" with " .. leftover:to_string() .. " left over"
|
" added to trash can at " .. minetest.pos_to_string(item_pos) ..
|
||||||
)
|
" with " .. leftover:to_string() .. " left over"
|
||||||
|
)
|
||||||
|
end
|
||||||
|
return
|
||||||
end
|
end
|
||||||
return
|
old_on_step(self, dtime)
|
||||||
end
|
end
|
||||||
old_on_step(self, dtime)
|
|
||||||
end
|
end
|
||||||
|
2
settingtypes.txt
Normal file
2
settingtypes.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# Requires some additional processing to check all items in the world each server step
|
||||||
|
trash_can_throw_in (Allow throwing trash into the trash can) bool true
|
Loading…
x
Reference in New Issue
Block a user