techage/iron_age/funnel.lua

141 lines
3.6 KiB
Lua
Raw Normal View History

2019-04-30 23:45:28 +03:00
--[[
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
LGPLv2.1+
See LICENSE.txt for more information
Simple TA1 Funnel
]]--
-- for lazy programmers
local S = function(pos) if pos then return minetest.pos_to_string(pos) end end
local P = minetest.string_to_pos
local M = minetest.get_meta
-- Load support for intllib.
local MP = minetest.get_modpath("techage")
local I,_ = dofile(MP.."/intllib.lua")
local function scan_for_objects(pos, inv)
for _, object in pairs(minetest.get_objects_inside_radius(pos, 1)) do
local lua_entity = object:get_luaentity()
if not object:is_player() and lua_entity and lua_entity.name == "__builtin:item" then
if lua_entity.itemstring ~= "" then
local stack = ItemStack(lua_entity.itemstring)
if inv:room_for_item("main", stack) then
inv:add_item("main", stack)
object:remove()
end
end
end
end
end
local function push_item(pos, inv, meta)
if not inv:is_empty("main") then
local stack = inv:get_stack("main", 1)
local taken = stack:take_item(1)
if techage.push_items(pos, meta:get_int("push_dir"), taken) then
inv:set_stack("main", 1, stack)
end
end
end
local function node_timer(pos, elapsed)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
if inv then
scan_for_objects(pos, inv)
push_item(pos, inv, meta)
end
return true
end
minetest.register_node("techage:funnel_ta1", {
description = I("TA1 Funnel"),
tiles = {
-- up, down, right, left, back, front
"default_cobble.png^techage_appl_funnel_top.png",
"default_cobble.png^techage_appl_funnel.png",
"default_cobble.png^techage_appl_funnel_right.png",
"default_cobble.png^techage_appl_funnel.png",
"default_cobble.png^techage_appl_funnel.png",
"default_cobble.png^techage_appl_funnel.png",
},
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{-8/16, 2/16, -8/16, 8/16, 8/16, -6/16},
{-8/16, 2/16, 6/16, 8/16, 8/16, 8/16},
{-8/16, 2/16, -8/16, -6/16, 8/16, 8/16},
{ 6/16, 2/16, -8/16, 8/16, 8/16, 8/16},
{-6/16, 0/16, -6/16, 6/16, 3/16, 6/16},
{-5/16, -4/16, -5/16, 5/16, 0/16, 5/16},
{ 0/16, -4/16, -3/16, 11/16, 2/16, 3/16},
},
},
selection_box = {
type = "fixed",
fixed = {
{-8/16, 2/16, -8/16, 8/16, 8/16, 8/16},
{-5/16, -4/16, -5/16, 5/16, 0/16, 5/16},
{ 0/16, -4/16, -3/16, 11/16, 2/16, 3/16},
},
},
on_construct = function(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
inv:set_size('main', 1)
end,
after_place_node = function(pos, placer)
techage.add_node(pos, "techage:funnel_ta1")
local node = minetest.get_node(pos)
M(pos):set_int("push_dir", techage.side_to_indir("L", node.param2))
minetest.get_node_timer(pos):start(2)
end,
on_timer = node_timer,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
techage.remove_node(pos)
end,
on_rotate = screwdriver.disallow,
paramtype = "light",
sunlight_propagates = true,
paramtype2 = "facedir",
groups = {choppy=2, cracky=2, crumbly=2},
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
})
--minetest.register_craft({
-- output = "techage:funnel_ta1",
-- recipe = {
-- {"group:wood", "", "group:wood"},
-- {"default:steel_ingot", "default:mese_crystal", "tubelib:tubeS"},
-- {"group:wood", "", "group:wood"},
-- },
--})
techage.register_node("techage:funnel_ta1", {}, {
on_pull_item = nil, -- not needed
on_unpull_item = nil, -- not needed
on_push_item = function(pos, in_dir, stack)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
return techage.put_items(inv, "main", stack)
end,
})