From ad0ad110392f2f827f05e59b399520da0eceedf7 Mon Sep 17 00:00:00 2001 From: FaceDeer Date: Sat, 4 Feb 2017 18:58:15 -0700 Subject: [PATCH] Vertical hoppers can now be rotated on their side and work as expected Consistency is now maintained for side and vertical hoppers regarding which face of a target node they inject items into. Injecting from the top goes to the same inventory regardless of what hopper type did the injecting, and likewise injecting from the side goes ot the same inventory. --- init.lua | 34 +++++++++++++++++++++++++++------- locale/de.po | 7 ++++--- locale/template.pot | 7 ++++--- 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/init.lua b/init.lua index c9a3edb..f0568b8 100644 --- a/init.lua +++ b/init.lua @@ -24,7 +24,7 @@ if single_craftable_item then else hopper_usage = hopper_usage .. S("Hopper blocks come in both 'vertical' and 'side' forms. They can be interconverted between the two forms via the crafting grid.\n\n") end -hopper_usage = hopper_usage .. S("When used with furnaces, vertical hoppers inject items into the furnace's \"raw material\" inventory slot and side hoppers inject items into the furnace's \"fuel\" inventory slot.\n\nItems that cannot be placed in a target block's inventory will remain in the hopper.\n\nHoppers have the same permissions as the player that placed them. Hoppers placed by you are allowed to take items from or put items into locked chests that you own, but hoppers placed by other players will be unable to do so. A hopper's own inventory is not not owner-locked, though, so you can use this as a way to allow other players to deposit items into your locked chests.") +hopper_usage = hopper_usage .. S("When used with furnaces, hoppers inject items into the furnace's \"raw material\" inventory slot when the narrow end is attached to the top or bottom and inject items into the furnace's \"fuel\" inventory slot when attached to the furnace's side.\n\nItems that cannot be placed in a target block's inventory will remain in the hopper.\n\nHoppers have the same permissions as the player that placed them. Hoppers placed by you are allowed to take items from or put items into locked chests that you own, but hoppers placed by other players will be unable to do so. A hopper's own inventory is not not owner-locked, though, so you can use this as a way to allow other players to deposit items into your locked chests.") local containers = {} local neighbors = {} @@ -54,7 +54,10 @@ function hopper:add_container(list) end end --- default containers ( relative position, target node, node inventory affected ) +-- "top" indicates what inventory the hopper will take items from if this node is located at the hopper's wide end +-- "side" indicates what inventory the hopper will put items into if this node is located at the hopper's narrow end and at the same height as the hopper +-- "bottom" indicates what inventory the hopper will put items into if this node is located at the hopper's narrow end and either above or below the hopper. + hopper:add_container({ {"top", "hopper:hopper", "main"}, {"bottom", "hopper:hopper", "main"}, @@ -156,6 +159,7 @@ minetest.register_node("hopper:hopper", { groups = {cracky = 3}, drawtype = "nodebox", paramtype = "light", + paramtype2 = "facedir", tiles = { "hopper_top_" .. texture_resolution .. ".png", "hopper_top_" .. texture_resolution .. ".png", @@ -465,6 +469,15 @@ local directions = { [23]={["src"]={x=0, y=-1, z=0},["dst"]={x=0, y=0, z=-1}}, } +local bottomdir = function(facedir) + return ({[0]={x=0, y=-1, z=0}, + {x=0, y=0, z=-1}, + {x=0, y=0, z=1}, + {x=-1, y=0, z=0}, + {x=1, y=0, z=0}, + {x=0, y=1, z=0}})[math.floor(facedir/4)] +end + -- hopper workings minetest.register_abm({ label = "Hopper transfer", @@ -475,13 +488,20 @@ minetest.register_abm({ catch_up = false, action = function(pos, node, active_object_count, active_object_count_wider) - local source_pos, destination_pos + local source_pos, destination_pos, destination_dir if node.name == "hopper:hopper_side" then source_pos = vector.add(pos, directions[node.param2].src) - destination_pos = vector.add(pos, directions[node.param2].dst) + destination_dir = directions[node.param2].dst + destination_pos = vector.add(pos, destination_dir) else - source_pos = {x=pos.x, y=pos.y+1, z=pos.z} - destination_pos = {x=pos.x, y=pos.y-1, z=pos.z} + destination_dir = bottomdir(node.param2) + source_pos = vector.subtract(pos, destination_dir) + destination_pos = vector.add(pos, destination_dir) + end + + local output_direction + if destination_dir.y == 0 then + output_direction = "horizontal" end local source_node = minetest.get_node(source_pos) @@ -492,7 +512,7 @@ minetest.register_abm({ end if containers[destination_node.name] ~= nil then - if node.name == "hopper:hopper_side" then + if output_direction == "horizontal" then send_item_to(pos, destination_pos, destination_node, containers[destination_node.name]["side"]) else send_item_to(pos, destination_pos, destination_node, containers[destination_node.name]["bottom"]) diff --git a/locale/de.po b/locale/de.po index 00d1085..a55e62c 100644 --- a/locale/de.po +++ b/locale/de.po @@ -50,9 +50,10 @@ msgstr "" #: init.lua:24 msgid "" -"When used with furnaces, vertical hoppers inject items into the furnace's " -"\"raw material\" inventory slot and side hoppers inject items into the " -"furnace's \"fuel\" inventory slot.\n" +"When used with furnaces, hoppers inject items into the furnace's \"raw " +"material\" inventory slot when the narrow end is attached to the top or " +"bottom and inject items into the furnace's \"fuel\" inventory slot when " +"attached to the furnace's side.\n" "\n" "Items that cannot be placed in a target block's inventory will remain in the " "hopper.\n" diff --git a/locale/template.pot b/locale/template.pot index bac2819..da14790 100644 --- a/locale/template.pot +++ b/locale/template.pot @@ -50,9 +50,10 @@ msgstr "" #: init.lua:24 msgid "" -"When used with furnaces, vertical hoppers inject items into the furnace's " -"\"raw material\" inventory slot and side hoppers inject items into the " -"furnace's \"fuel\" inventory slot.\n" +"When used with furnaces, hoppers inject items into the furnace's \"raw " +"material\" inventory slot when the narrow end is attached to the top or " +"bottom and inject items into the furnace's \"fuel\" inventory slot when " +"attached to the furnace's side.\n" "\n" "Items that cannot be placed in a target block's inventory will remain in the " "hopper.\n"