From 3bf372164bebda8fb220b816fb28eb4da15295e7 Mon Sep 17 00:00:00 2001 From: Joachim Stolberg Date: Wed, 1 May 2019 12:01:24 +0200 Subject: [PATCH] funnel renamed to hopper --- basis/command.lua | 46 ++++++++++++--- init.lua | 2 +- iron_age/gravelsieve.lua | 1 + iron_age/{funnel.lua => hopper.lua} | 53 ++++++++++++------ iron_age/meridium.lua | 2 +- ...ppl_funnel.png => techage_appl_hopper.png} | Bin ...ight.png => techage_appl_hopper_right.png} | Bin ...el_top.png => techage_appl_hopper_top.png} | Bin 8 files changed, 78 insertions(+), 26 deletions(-) rename iron_age/{funnel.lua => hopper.lua} (70%) rename textures/{techage_appl_funnel.png => techage_appl_hopper.png} (100%) rename textures/{techage_appl_funnel_right.png => techage_appl_hopper_right.png} (100%) rename textures/{techage_appl_funnel_top.png => techage_appl_hopper_top.png} (100%) diff --git a/basis/command.lua b/basis/command.lua index fc488b3..cd8764c 100644 --- a/basis/command.lua +++ b/basis/command.lua @@ -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 diff --git a/init.lua b/init.lua index 1b9c6ff..aa6c72e 100644 --- a/init.lua +++ b/init.lua @@ -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") diff --git a/iron_age/gravelsieve.lua b/iron_age/gravelsieve.lua index ae0e0c9..4db9864 100644 --- a/iron_age/gravelsieve.lua +++ b/iron_age/gravelsieve.lua @@ -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 diff --git a/iron_age/funnel.lua b/iron_age/hopper.lua similarity index 70% rename from iron_age/funnel.lua rename to iron_age/hopper.lua index d090235..217addc 100644 --- a/iron_age/funnel.lua +++ b/iron_age/hopper.lua @@ -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") \ No newline at end of file +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") \ No newline at end of file diff --git a/iron_age/meridium.lua b/iron_age/meridium.lua index 9150f3d..db37ae8 100644 --- a/iron_age/meridium.lua +++ b/iron_age/meridium.lua @@ -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, diff --git a/textures/techage_appl_funnel.png b/textures/techage_appl_hopper.png similarity index 100% rename from textures/techage_appl_funnel.png rename to textures/techage_appl_hopper.png diff --git a/textures/techage_appl_funnel_right.png b/textures/techage_appl_hopper_right.png similarity index 100% rename from textures/techage_appl_funnel_right.png rename to textures/techage_appl_hopper_right.png diff --git a/textures/techage_appl_funnel_top.png b/textures/techage_appl_hopper_top.png similarity index 100% rename from textures/techage_appl_funnel_top.png rename to textures/techage_appl_hopper_top.png