From 35d34ae5d6dfeb452f00408a7afe52cc1bbe274f Mon Sep 17 00:00:00 2001 From: TenPlus1 Date: Mon, 30 Jan 2017 21:30:10 +0000 Subject: [PATCH 1/4] update readme --- api.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/api.txt b/api.txt index 86e2eeb..01b6167 100644 --- a/api.txt +++ b/api.txt @@ -33,3 +33,5 @@ hopper:add_container({ We already have support for the wine barrel inside of the Wine mod and protected chests inside of Protector Redo, as well as default chests, furnaces and hoppers themselves. + +Note: Hoppers can transfer into locked chests but not take from them (yet). From 3b653f6da19ca48a990800ac65bb2ad9f1ab7ddd Mon Sep 17 00:00:00 2001 From: TenPlus1 Date: Mon, 30 Jan 2017 22:05:27 +0000 Subject: [PATCH 2/4] changed a few descriptions --- api.txt | 9 +++++---- init.lua | 6 +++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/api.txt b/api.txt index 01b6167..d3483f2 100644 --- a/api.txt +++ b/api.txt @@ -14,8 +14,9 @@ Make sure any mods using this function has 'hopper' in the depends.txt file. hopper:add_container({ {"where_from", "node_name", "inventory_name"} }) 'where_from' is a string telling the api that items are coming from either - the 'top' node into a hopper, going into the 'bottom' node from a - hopper or coming from a 'side' hopper into a container. + the 'top' node into a hopper below, going into the 'bottom' node + from the hopper above or coming from a 'side' hopper into the + node next door. 'node_name" is the name of the container itself (e.g. "default:chest") @@ -24,8 +25,8 @@ hopper:add_container({ {"where_from", "node_name", "inventory_name"} }) e.g. hopper:add_container({ - {"top", "default:furnace", "dst"}, -- take cooked items from above into hopper - {"bottom", "default:furnace", "src"}, -- insert items below to be cooked from hopper + {"top", "default:furnace", "dst"}, -- take cooked items from above into hopper below + {"bottom", "default:furnace", "src"}, -- insert items below to be cooked from hopper above {"side", "default:furnace", "fuel"}, -- replenish furnace fuel from hopper at side }) diff --git a/init.lua b/init.lua index 6746820..ec533a7 100644 --- a/init.lua +++ b/init.lua @@ -3,7 +3,7 @@ hopper = {} --- default containers ( from position [into hopper], from node, into node inventory ) +-- default containers local containers = { {"top", "hopper:hopper", "main"}, @@ -395,7 +395,7 @@ minetest.register_abm({ nod = containers[n][2] inv = containers[n][3] - -- hopper on top into container below + -- from top node into hopper below if where == "top" and top == nod and (node.name == "hopper:hopper" or node.name == "hopper:hopper_side") then --print ("-- top") @@ -404,7 +404,7 @@ minetest.register_abm({ {x = pos.x, y = pos.y + 1, z = pos.z}):start(0.5) return - -- container on top into hopper below + -- from top hopper into node below elseif where == "bottom" and out == nod and node.name == "hopper:hopper" then --print ("-- bot") From 2e3ef7cf7ef8d46f026f25be0a5075d3cfcea6c2 Mon Sep 17 00:00:00 2001 From: TenPlus1 Date: Tue, 31 Jan 2017 11:50:13 +0000 Subject: [PATCH 3/4] Tweaked and tidied code, uses a single abm for hoppers --- init.lua | 99 ++++++++++++++++------------------- textures/hopper_side_inv.png | Bin 363 -> 233 bytes 2 files changed, 45 insertions(+), 54 deletions(-) diff --git a/init.lua b/init.lua index ec533a7..b427503 100644 --- a/init.lua +++ b/init.lua @@ -79,7 +79,7 @@ end -- hopper minetest.register_node("hopper:hopper", { - description = "Hopper", + description = "Hopper (Place onto side of container for side-hopper)", groups = {cracky = 3}, drawtype = "nodebox", paramtype = "light", @@ -111,25 +111,24 @@ minetest.register_node("hopper:hopper", { on_place = function(itemstack, placer, pointed_thing) - local pos = pointed_thing.under - local pos2 = pointed_thing.above - local x = pos.x - pos2.x - local z = pos.z - pos2.z + local pos = pointed_thing.above + local x = pointed_thing.under.x - pos.x + local z = pointed_thing.under.z - pos.z if x == -1 then - minetest.set_node(pos2, {name = "hopper:hopper_side", param2 = 0}) + minetest.set_node(pos, {name = "hopper:hopper_side", param2 = 0}) elseif x == 1 then - minetest.set_node(pos2, {name = "hopper:hopper_side", param2 = 2}) + minetest.set_node(pos, {name = "hopper:hopper_side", param2 = 2}) elseif z == -1 then - minetest.set_node(pos2, {name = "hopper:hopper_side", param2 = 3}) + minetest.set_node(pos, {name = "hopper:hopper_side", param2 = 3}) elseif z == 1 then - minetest.set_node(pos2, {name = "hopper:hopper_side", param2 = 1}) + minetest.set_node(pos, {name = "hopper:hopper_side", param2 = 1}) else - minetest.set_node(pos2, {name = "hopper:hopper"}) + minetest.set_node(pos, {name = "hopper:hopper"}) end if not minetest.setting_getbool("creative_mode") then @@ -183,7 +182,7 @@ minetest.register_node("hopper:hopper", { -- side hopper minetest.register_node("hopper:hopper_side", { - description = "Side Hopper", + description = "Side Hopper (Place into crafting to return normal Hopper)", groups = {cracky = 3, not_in_creative_inventory = 1}, drawtype = "nodebox", paramtype = "light", @@ -260,47 +259,6 @@ minetest.register_node("hopper:hopper_side", { }) --- suck in items on top of hopper -minetest.register_abm({ - - label = "Hopper suction", - nodenames = {"hopper:hopper", "hopper:hopper_side"}, - interval = 1.0, - chance = 1, - catch_up = false, - - action = function(pos, node) - - local inv = minetest.get_meta(pos):get_inventory() - local posob - - for _,object in pairs(minetest.get_objects_inside_radius(pos, 1)) do - - if not object:is_player() - and object:get_luaentity() - and object:get_luaentity().name == "__builtin:item" - and inv - and inv:room_for_item("main", - ItemStack(object:get_luaentity().itemstring)) then - - posob = object:getpos() - - if math.abs(posob.x - pos.x) <= 0.5 - and posob.y - pos.y <= 0.85 - and posob.y - pos.y >= 0.3 then - - inv:add_item("main", - ItemStack(object:get_luaentity().itemstring)) - - object:get_luaentity().itemstring = "" - object:remove() - end - end - end - end, -}) - - -- transfer function local transfer = function(src, srcpos, dst, dstpos) @@ -346,13 +304,40 @@ end -- hopper workings minetest.register_abm({ - label = "Hopper transfer", + label = "Hopper suction and transfer", nodenames = {"hopper:hopper", "hopper:hopper_side"}, interval = 1.0, chance = 1, catch_up = false, - action = function(pos, node) + action = function(pos, node, active_object_count, active_object_count_wider) + + -- do we have any entities nearby to suck into hopper? + if active_object_count > 0 then + + local inv = minetest.get_meta(pos):get_inventory() + + for _,object in pairs(minetest.get_objects_inside_radius(pos, 1)) do + + if not object:is_player() + and object:get_luaentity() + and object:get_luaentity().name == "__builtin:item" + and inv + and inv:room_for_item("main", + ItemStack(object:get_luaentity().itemstring)) then + + if object:getpos().y - pos.y >= 0.3 then + + inv:add_item("main", + ItemStack(object:get_luaentity().itemstring)) + + object:get_luaentity().itemstring = "" + object:remove() + end + end + end + end + local front @@ -435,6 +420,12 @@ minetest.register_craft({ }, }) +-- side hopper to hopper recipe +minetest.register_craft({ + type = "shapeless", + output = "hopper:hopper", + recipe = {"hopper:hopper_side"}, +}) -- add lucky blocks if minetest.get_modpath("lucky_block") then diff --git a/textures/hopper_side_inv.png b/textures/hopper_side_inv.png index 5adeddd18c1ddae7340e4de18cba5caf09f6305e..b24b8b12e0e525dc8da118021fff679661c4a451 100644 GIT binary patch delta 217 zcmV;~04D$I0_g#e7=Hu<0001iRAbS)t{6GCz(UZXXf(|A!t$O`}f z00DGTPE!Ct=GbNc004+dL_t(2&#jTc4Z|P|MFUwN2@8O|0L2UtDeON}FsUuK%Atz- zPWTCnk3CKQU~Yz;1rfE%RX^mnpn9~US|JSaT9t4KLb)J9!BYDcn9D>001*kOjJcc000#h6eJ}hF)}bfLO)7NNmp4` zU}9ipXk>43ZhCxpi;aq$o|~zwsI#@QyS=*5($4~hS4jW>00DGTPE!Ct=GbNc008Dm zL_t(I%gvMRZo?o9MGH2@A3*p1Pdmdx=pv&2s5I>c8DmajFn{Fn_#d)bTYI+W*HUZE zgY^JZ)m*h$an7eoF%^-VCm?Fhcvp(IVpdF4#cTqchuAgD=shq2%Q3=6uYfSIj8rTv z-BSiW0r$n@ Date: Wed, 1 Feb 2017 20:35:04 +0000 Subject: [PATCH 4/4] Added intllib support (german translation by Xanthin) --- README.md | 5 +++-- depends.txt | 3 ++- init.lua | 51 ++++++++++++++++++++++++++------------------- locale/de.txt | 11 ++++++++++ locale/template.txt | 10 +++++++++ 5 files changed, 56 insertions(+), 24 deletions(-) create mode 100644 locale/de.txt create mode 100644 locale/template.txt diff --git a/README.md b/README.md index 32d2e0b..099ce04 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,8 @@ Change log: - 0.8 - Added Napiophelios' new textures and tweaked code - 0.9 - Added support for Wine mod's wine barrels - 1.0 - New furances do not work properly with hoppers so old reverted to abm furnaces -- 1.1 - Hoppers now work with new node timer Furnaces. Reduced Abm's and tidied code. -- 1.2 - Added simple API so that hoppers can work with other containers. +- 1.1 - Hoppers now work with new node timer Furnaces. Reduced Abm's and tidied code +- 1.2 - Added simple API so that hoppers can work with other containers +- 1.3 - Tweaked code to use a single abm and added intllib support Lucky Blocks: 2 diff --git a/depends.txt b/depends.txt index 8035459..53a9e75 100644 --- a/depends.txt +++ b/depends.txt @@ -1,2 +1,3 @@ default -lucky_block? \ No newline at end of file +intllib? +lucky_block? diff --git a/init.lua b/init.lua index b427503..23e8abd 100644 --- a/init.lua +++ b/init.lua @@ -3,6 +3,21 @@ hopper = {} +-- Intllib +local S + +if minetest.get_modpath("intllib") then + S = intllib.Getter() +else + S = function(s, a, ...) a = {a, ...} + return s:gsub("@(%d+)", function(n) + return a[tonumber(n)] + end) + end + +end + + -- default containers local containers = { @@ -79,7 +94,7 @@ end -- hopper minetest.register_node("hopper:hopper", { - description = "Hopper (Place onto side of container for side-hopper)", + description = S("Hopper (Place onto sides for side-hopper)"), groups = {cracky = 3}, drawtype = "nodebox", paramtype = "light", @@ -157,23 +172,20 @@ minetest.register_node("hopper:hopper", { on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) - minetest.log("action", player:get_player_name() - .." moves stuff in hopper at " - ..minetest.pos_to_string(pos)) + minetest.log("action", S("@1 moves stuff in hopper at @2", + player:get_player_name(), minetest.pos_to_string(pos))) end, on_metadata_inventory_put = function(pos, listname, index, stack, player) - minetest.log("action", player:get_player_name() - .." moves stuff to hopper at " - ..minetest.pos_to_string(pos)) + minetest.log("action", S("@1 moves stuff to hopper at @2", + player:get_player_name(), minetest.pos_to_string(pos))) end, on_metadata_inventory_take = function(pos, listname, index, stack, player) - minetest.log("action", player:get_player_name() - .." takes stuff from hopper at " - ..minetest.pos_to_string(pos)) + minetest.log("action", S("@1 moves stuff from hopper at @2", + player:get_player_name(), minetest.pos_to_string(pos))) end, on_rotate = screwdriver.disallow, @@ -182,7 +194,7 @@ minetest.register_node("hopper:hopper", { -- side hopper minetest.register_node("hopper:hopper_side", { - description = "Side Hopper (Place into crafting to return normal Hopper)", + description = S("Side Hopper (Place into crafting to return normal Hopper)"), groups = {cracky = 3, not_in_creative_inventory = 1}, drawtype = "nodebox", paramtype = "light", @@ -236,23 +248,20 @@ minetest.register_node("hopper:hopper_side", { on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) - minetest.log("action", player:get_player_name() - .." moves stuff in hopper at " - ..minetest.pos_to_string(pos)) + minetest.log("action", S("@1 moves stuff in hopper at @2", + player:get_player_name(), minetest.pos_to_string(pos))) end, on_metadata_inventory_put = function(pos, listname, index, stack, player) - minetest.log("action", player:get_player_name() - .." moves stuff to hopper at " - ..minetest.pos_to_string(pos)) + minetest.log("action", S("@1 moves stuff to hopper at @2", + player:get_player_name(), minetest.pos_to_string(pos))) end, on_metadata_inventory_take = function(pos, listname, index, stack, player) - minetest.log("action", player:get_player_name() - .." takes stuff from hopper at " - ..minetest.pos_to_string(pos)) + minetest.log("action", S("@1 moves stuff from hopper at @2", + player:get_player_name(), minetest.pos_to_string(pos))) end, on_rotate = screwdriver.rotate_simple, @@ -437,4 +446,4 @@ if minetest.get_modpath("lucky_block") then end -print ("[MOD] Hopper loaded") +print (S("[MOD] Hopper loaded")) diff --git a/locale/de.txt b/locale/de.txt new file mode 100644 index 0000000..e2249b6 --- /dev/null +++ b/locale/de.txt @@ -0,0 +1,11 @@ +# Template for translations of hopper mod +# German translation by Xanthin +# last update: 1st February 2017 + +#init.lua +[MOD] Hopper loaded = [MOD] Trichter geladen +Hopper (Place onto sides for side-hopper) = Trichter (für Seitentrichter an den Seiten platzieren) +Side Hopper (Place into crafting to return normal Hopper) = Seitentrichter (in Fertigungsraster legen, um normalen Trichter zu erhalten) +@1 moves stuff in hopper at @2 = @1 bewegt Dinge in einem Trichter bei @2 +@1 moves stuff to hopper at @2 = @1 verlagert Dinge in einen Trichter bei @2 +@1 moves stuff from hopper at @2 = @1 nimmt Dinge aus einem Trichter bei @2 diff --git a/locale/template.txt b/locale/template.txt new file mode 100644 index 0000000..0910e8d --- /dev/null +++ b/locale/template.txt @@ -0,0 +1,10 @@ +# Template for translations of hopper mod +# last update: 1st February 2017 + +#init.lua +[MOD] Hopper loaded = +Hopper (Place onto sides for side-hopper) = +Side Hopper (Place into crafting to return normal Hopper) = +@1 moves stuff in hopper at @2 +@1 moves stuff to hopper at @2 +@1 moves stuff from hopper at @2