funnel renamed to hopper

This commit is contained in:
Joachim Stolberg 2019-05-01 12:01:24 +02:00
parent 096b85ee1c
commit 3bf372164b
8 changed files with 78 additions and 26 deletions

View File

@ -131,6 +131,12 @@ function techage.side_to_indir(side, param2)
return tubelib2.Turn180Deg[side_to_dir(side, param2)]
end
local function get_next_node(pos, out_dir)
local res, npos, node = Tube:compatible_node(pos, out_dir)
local in_dir = tubelib2.Turn180Deg[out_dir]
return res, npos, in_dir, Name2Name[node.name] or node.name
end
local function get_dest_node(pos, out_dir)
local spos, in_dir = Tube:get_connected_node_pos(pos, out_dir)
local _,node = Tube:get_node(spos)
@ -320,17 +326,14 @@ end
function techage.pull_items(pos, out_dir, num)
local npos, in_dir, name = get_dest_node(pos, out_dir)
if npos == nil then return end
if NodeDef[name] and NodeDef[name].on_pull_item then
if npos and NodeDef[name] and NodeDef[name].on_pull_item then
return NodeDef[name].on_pull_item(npos, in_dir, num)
end
return nil
end
function techage.push_items(pos, out_dir, stack)
local npos, in_dir, name = get_dest_node(pos, out_dir)
if npos == nil then return end
if NodeDef[name] and NodeDef[name].on_push_item then
if npos and NodeDef[name] and NodeDef[name].on_push_item then
return NodeDef[name].on_push_item(npos, in_dir, stack)
elseif name == "air" then
minetest.add_item(npos, stack)
@ -341,13 +344,42 @@ end
function techage.unpull_items(pos, out_dir, stack)
local npos, in_dir, name = get_dest_node(pos, out_dir)
if npos == nil then return end
if NodeDef[name] and NodeDef[name].on_unpull_item then
if npos and NodeDef[name] and NodeDef[name].on_unpull_item then
return NodeDef[name].on_unpull_item(npos, in_dir, stack)
end
return false
end
-------------------------------------------------------------------
-- Client side Push/Pull item functions for funnel like nodes
-- (nodes with no tube support)
-------------------------------------------------------------------
function techage.neighbour_pull_items(pos, out_dir, num)
local res, npos, in_dir, name = get_next_node(pos, out_dir)
if res and NodeDef[name] and NodeDef[name].on_pull_item then
return NodeDef[name].on_pull_item(npos, in_dir, num)
end
end
function techage.neighbour_push_items(pos, out_dir, stack)
local res, npos, in_dir, name = get_next_node(pos, out_dir)
if res and NodeDef[name] and NodeDef[name].on_push_item then
return NodeDef[name].on_push_item(npos, in_dir, stack)
elseif name == "air" then
minetest.add_item(npos, stack)
return true
end
return false
end
function techage.neighbour_unpull_items(pos, out_dir, stack)
local res, npos, in_dir, name = get_next_node(pos, out_dir)
if res and NodeDef[name] and NodeDef[name].on_unpull_item then
return NodeDef[name].on_unpull_item(npos, in_dir, stack)
end
return false
end
-------------------------------------------------------------------
-- Server side helper functions

View File

@ -45,7 +45,7 @@ else
-- Iron Age
dofile(MP.."/iron_age/main.lua")
dofile(MP.."/iron_age/gravelsieve.lua")
dofile(MP.."/iron_age/funnel.lua")
dofile(MP.."/iron_age/hopper.lua")
dofile(MP.."/iron_age/hammer.lua")
dofile(MP.."/iron_age/lighter.lua")
dofile(MP.."/iron_age/charcoalpile.lua")

View File

@ -141,6 +141,7 @@ end
techage.register_node("techage:sieve0", {"techage:sieve1", "techage:sieve2", "techage:sieve3"}, {
on_push_item = function(pos, in_dir, stack)
print("on_push_item")
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
if inv:room_for_item("src", stack) then

View File

@ -8,7 +8,7 @@
LGPLv2.1+
See LICENSE.txt for more information
Simple TA1 Funnel
Simple TA1 Hopper
]]--
@ -36,36 +36,53 @@ local function scan_for_objects(pos, inv)
end
end
local function pull_push_item(pos, meta)
local items = techage.neighbour_pull_items(pos, 6, 1)
if items then
if techage.neighbour_push_items(pos, meta:get_int("push_dir"), items) then
return true
end
-- place item back
techage.neighbour_unpull_items(pos, 6, items)
end
return false
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
print("neighbour_push_items")
if techage.neighbour_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)
print("node_timer")
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
if inv then
scan_for_objects(pos, inv)
push_item(pos, inv, meta)
if not pull_push_item(pos, meta) then
scan_for_objects(pos, inv)
push_item(pos, inv, meta)
end
end
return true
end
minetest.register_node("techage:funnel_ta1", {
description = I("TA1 Funnel"),
minetest.register_node("techage:hopper_ta1", {
description = I("TA1 Hopper"),
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",
"default_cobble.png^techage_appl_hopper_top.png",
"default_cobble.png^techage_appl_hopper.png",
"default_cobble.png^techage_appl_hopper_right.png",
"default_cobble.png^techage_appl_hopper.png",
"default_cobble.png^techage_appl_hopper.png",
"default_cobble.png^techage_appl_hopper.png",
},
drawtype = "nodebox",
@ -97,7 +114,7 @@ minetest.register_node("techage:funnel_ta1", {
end,
after_place_node = function(pos, placer)
techage.add_node(pos, "techage:funnel_ta1")
techage.add_node(pos, "techage:hopper_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)
@ -120,7 +137,7 @@ minetest.register_node("techage:funnel_ta1", {
minetest.register_craft({
output = "techage:funnel_ta1",
output = "techage:hopper_ta1",
recipe = {
{"default:stone", "", "default:stone"},
{"default:stone", "default:gold_ingot", "default:stone"},
@ -128,7 +145,7 @@ minetest.register_craft({
},
})
techage.register_node("techage:funnel_ta1", {}, {
techage.register_node("techage:hopper_ta1", {}, {
on_pull_item = nil, -- not needed
on_unpull_item = nil, -- not needed
@ -139,7 +156,9 @@ techage.register_node("techage:funnel_ta1", {}, {
end,
})
techage.register_help_page("TA1 Funnel", [[The Funnel collects dropped items
techage.register_help_page("TA1 Hopper", [[The Hopper collects dropped items
and pushes them to the right side.
Items are sucked up when they
are dropped on top of the funnel block.]], "techage:funnel_ta1")
are dropped on top of the Hopper block.
But the Hopper can also pull items out of
chests or furnace blocks, if it is placed below.]], "techage:hopper_ta1")

View File

@ -120,7 +120,7 @@ minetest.register_craft({
}
})
techage.register_recipe({
techage.ironage_register_recipe({
output = "techage:meridium_ingot",
recipe = {"default:steel_ingot", "default:mese_crystal_fragment"},
heat = 4,

View File

Before

Width:  |  Height:  |  Size: 159 B

After

Width:  |  Height:  |  Size: 159 B

View File

Before

Width:  |  Height:  |  Size: 169 B

After

Width:  |  Height:  |  Size: 169 B

View File

Before

Width:  |  Height:  |  Size: 273 B

After

Width:  |  Height:  |  Size: 273 B