2015-09-17 15:38:52 +02:00
|
|
|
local function get_hopper_formspec(pos)
|
|
|
|
local spos = pos.x .. "," .. pos.y .. "," ..pos.z
|
|
|
|
local formspec =
|
|
|
|
"size[8,9]"
|
|
|
|
.. default.gui_bg
|
|
|
|
.. default.gui_bg_img
|
|
|
|
.. default.gui_slots
|
|
|
|
.. "list[nodemeta:" .. spos .. ";main;0,0.3;8,4;]"
|
|
|
|
.. "list[current_player;main;0,4.85;8,1;]"
|
|
|
|
.. "list[current_player;main;0,6.08;8,3;8]"
|
|
|
|
.. "listring[nodemeta:" .. spos .. ";main]"
|
|
|
|
.. "listring[current_player;main]"
|
|
|
|
return formspec
|
|
|
|
end
|
|
|
|
|
2015-06-12 11:42:11 +02:00
|
|
|
-- hopper
|
|
|
|
minetest.register_node("hopper:hopper", {
|
|
|
|
description = "Hopper",
|
2015-09-17 12:11:01 +02:00
|
|
|
groups = {cracky = 1, level = 2},
|
2015-06-12 11:42:11 +02:00
|
|
|
drawtype = "nodebox",
|
|
|
|
paramtype = "light",
|
|
|
|
tiles = {"default_coal_block.png"},
|
|
|
|
node_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = {
|
|
|
|
--funnel walls
|
|
|
|
{-0.5, 0.0, 0.4, 0.5, 0.5, 0.5},
|
|
|
|
{0.4, 0.0, -0.5, 0.5, 0.5, 0.5},
|
|
|
|
{-0.5, 0.0, -0.5, -0.4, 0.5, 0.5},
|
|
|
|
{-0.5, 0.0, -0.5, 0.5, 0.5, -0.4},
|
|
|
|
--funnel base
|
|
|
|
{-0.5, 0.0, -0.5, 0.5, 0.1, 0.5},
|
|
|
|
--spout
|
|
|
|
{-0.3, -0.3, -0.3, 0.3, 0.0, 0.3},
|
|
|
|
{-0.15, -0.3, -0.15, 0.15, -0.5, 0.15},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
on_construct = function(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_string("infotext", "Hopper")
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
inv:set_size("main", 8*4)
|
|
|
|
end,
|
|
|
|
|
2015-09-17 12:11:01 +02:00
|
|
|
can_dig = function(pos, player)
|
2015-06-12 11:42:11 +02:00
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
return inv:is_empty("main")
|
|
|
|
end,
|
|
|
|
|
2015-09-17 12:11:01 +02:00
|
|
|
on_rightclick = function(pos, node, clicker, itemstack)
|
2015-09-17 15:38:52 +02:00
|
|
|
minetest.show_formspec(
|
|
|
|
clicker:get_player_name(),
|
|
|
|
"hopper:hopper",
|
|
|
|
get_hopper_formspec(pos)
|
|
|
|
)
|
2015-09-17 12:11:01 +02:00
|
|
|
end,
|
|
|
|
|
2015-06-12 11:42:11 +02:00
|
|
|
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
2015-09-17 12:11:01 +02:00
|
|
|
minetest.log("action", player:get_player_name()
|
|
|
|
.." moves stuff in hopper at "
|
|
|
|
..minetest.pos_to_string(pos))
|
2015-06-12 11:42:11 +02:00
|
|
|
end,
|
|
|
|
|
2015-09-17 12:11:01 +02:00
|
|
|
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))
|
2015-06-12 11:42:11 +02:00
|
|
|
end,
|
|
|
|
|
2015-09-17 12:11:01 +02:00
|
|
|
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))
|
2015-06-12 11:42:11 +02:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
-- hopper side
|
|
|
|
minetest.register_node("hopper:hopper_side", {
|
|
|
|
description = "Side Hopper",
|
2015-09-17 12:11:01 +02:00
|
|
|
groups = {cracky = 1, level = 2},
|
2015-06-12 11:42:11 +02:00
|
|
|
drawtype = "nodebox",
|
|
|
|
paramtype = "light",
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
tiles = {"default_coal_block.png"},
|
|
|
|
node_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = {
|
|
|
|
--funnel walls
|
|
|
|
{-0.5, 0.0, 0.4, 0.5, 0.5, 0.5},
|
|
|
|
{0.4, 0.0, -0.5, 0.5, 0.5, 0.5},
|
|
|
|
{-0.5, 0.0, -0.5, -0.4, 0.5, 0.5},
|
|
|
|
{-0.5, 0.0, -0.5, 0.5, 0.5, -0.4},
|
|
|
|
--funnel base
|
|
|
|
{-0.5, 0.0, -0.5, 0.5, 0.1, 0.5},
|
|
|
|
--spout
|
|
|
|
{-0.3, -0.3, -0.3, 0.3, 0.0, 0.3},
|
|
|
|
{-0.7, -0.3, -0.15, 0.15, 0.0, 0.15},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
on_construct = function(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_string("infotext", "Side Hopper")
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
inv:set_size("main", 8*4)
|
|
|
|
end,
|
|
|
|
|
2015-09-17 12:11:01 +02:00
|
|
|
can_dig = function(pos, player)
|
2015-06-12 11:42:11 +02:00
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
return inv:is_empty("main")
|
|
|
|
end,
|
|
|
|
|
2015-09-17 12:11:01 +02:00
|
|
|
on_rightclick = function(pos, node, clicker, itemstack)
|
2015-09-17 15:38:52 +02:00
|
|
|
minetest.show_formspec(
|
|
|
|
clicker:get_player_name(),
|
|
|
|
"hopper:hopper_side",
|
|
|
|
get_hopper_formspec(pos)
|
|
|
|
)
|
2015-09-17 12:11:01 +02:00
|
|
|
end,
|
|
|
|
|
2015-06-12 11:42:11 +02:00
|
|
|
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
2015-09-17 12:11:01 +02:00
|
|
|
minetest.log("action", player:get_player_name()
|
|
|
|
.." moves stuff in hopper at "
|
|
|
|
..minetest.pos_to_string(pos))
|
2015-06-12 11:42:11 +02:00
|
|
|
end,
|
|
|
|
|
2015-09-17 12:11:01 +02:00
|
|
|
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))
|
2015-06-12 11:42:11 +02:00
|
|
|
end,
|
|
|
|
|
2015-09-17 12:11:01 +02:00
|
|
|
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))
|
2015-06-12 11:42:11 +02:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
-- suck in items on top of hopper
|
|
|
|
minetest.register_abm({
|
2015-09-17 12:11:01 +02:00
|
|
|
nodenames = {"hopper:hopper", "hopper:hopper_side"},
|
2015-06-12 11:42:11 +02:00
|
|
|
interval = 1.0,
|
|
|
|
chance = 1,
|
|
|
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
local posob
|
|
|
|
|
|
|
|
for _,object in ipairs(minetest.get_objects_inside_radius(pos, 1)) do
|
2015-09-17 12:11:01 +02:00
|
|
|
if not object:is_player()
|
|
|
|
and object:get_luaentity()
|
|
|
|
and object:get_luaentity().name == "__builtin:item" then
|
2015-06-12 11:42:11 +02:00
|
|
|
if inv and inv:room_for_item("main", ItemStack(object:get_luaentity().itemstring)) then
|
|
|
|
posob = object:getpos()
|
2015-09-17 12:11:01 +02:00
|
|
|
if math.abs(posob.x - pos.x) <= 0.5
|
|
|
|
and posob.y - pos.y <= 0.85
|
|
|
|
and posob.y - pos.y >= 0.3 then
|
2015-06-12 11:42:11 +02:00
|
|
|
inv:add_item("main", ItemStack(object:get_luaentity().itemstring))
|
|
|
|
object:get_luaentity().itemstring = ""
|
|
|
|
object:remove()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
-- transfer function
|
|
|
|
local transfer = function(src, srcpos, dst, dstpos)
|
|
|
|
|
|
|
|
-- source inventory
|
|
|
|
local meta = minetest.get_meta(srcpos)
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
local invsize = inv:get_size(src)
|
|
|
|
|
|
|
|
-- check for empty source
|
|
|
|
if inv:is_empty(src) == true then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
-- destination inventory
|
|
|
|
local meta2 = minetest.get_meta(dstpos)
|
|
|
|
local inv2 = meta2:get_inventory()
|
|
|
|
local invsize2 = inv2:get_size(dst)
|
|
|
|
|
|
|
|
local stack, item
|
|
|
|
|
|
|
|
-- transfer item
|
2015-09-17 12:11:01 +02:00
|
|
|
for i = 1, invsize do
|
2015-06-12 11:42:11 +02:00
|
|
|
|
|
|
|
stack = inv:get_stack(src, i)
|
|
|
|
item = stack:get_name()
|
|
|
|
|
|
|
|
-- if slot not empty
|
|
|
|
if item ~= "" then
|
|
|
|
|
|
|
|
-- room in destination?
|
|
|
|
if inv2:room_for_item(dst, item) == false then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
-- is item a tool
|
|
|
|
if stack:get_wear() > 0 then -- tool
|
|
|
|
local it = stack:take_item(stack:get_count())
|
|
|
|
inv2:add_item(dst, it)
|
|
|
|
inv:set_stack(src, i, nil)
|
|
|
|
else -- everything else
|
|
|
|
stack:take_item(1)
|
|
|
|
inv2:add_item(dst, item)
|
|
|
|
inv:set_stack(src, i, stack)
|
|
|
|
end
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
-- hopper transfer
|
|
|
|
minetest.register_abm({
|
|
|
|
nodenames = {"hopper:hopper"},
|
|
|
|
neighbors = {
|
2015-09-17 12:11:01 +02:00
|
|
|
"default:chest", "default:chest_locked", "protector:chest",
|
|
|
|
"hopper:hopper", "hopper:hopper_side", "default:furnace",
|
|
|
|
"default:furnace_active"
|
2015-06-12 11:42:11 +02:00
|
|
|
},
|
|
|
|
interval = 1.0,
|
|
|
|
chance = 1,
|
|
|
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
|
|
|
|
2015-09-17 12:11:01 +02:00
|
|
|
local min = {x = pos.x, y = pos.y - 1, z = pos.z}
|
|
|
|
local max = {x = pos.x, y = pos.y + 1, z = pos.z}
|
|
|
|
local vm = minetest.get_voxel_manip()
|
|
|
|
local emin, emax = vm:read_from_map(min, max)
|
|
|
|
local area = VoxelArea:new{MinEdge = emin, MaxEdge = emax}
|
|
|
|
local data = vm:get_data()
|
|
|
|
local a = vm:get_node_at({x = pos.x, y = pos.y + 1, z = pos.z}).name
|
|
|
|
local b = vm:get_node_at({x = pos.x, y = pos.y - 1, z = pos.z}).name
|
2015-06-12 11:42:11 +02:00
|
|
|
|
2015-09-17 12:11:01 +02:00
|
|
|
--local a = minetest.get_node({x = pos.x, y = pos.y + 1, z = pos.z}).name
|
|
|
|
--local b = minetest.get_node({x = pos.x, y = pos.y - 1, z = pos.z}).name
|
2015-06-12 11:42:11 +02:00
|
|
|
|
2015-06-16 11:08:18 +02:00
|
|
|
-- input (from above)
|
2015-06-12 11:42:11 +02:00
|
|
|
|
|
|
|
if a == "default:chest"
|
|
|
|
or a == "default:chest_locked"
|
|
|
|
or a == "protector:chest"
|
|
|
|
or a == "hopper:hopper"
|
|
|
|
or a == "hopper:hopper_side" then
|
|
|
|
|
|
|
|
-- chest/hopper above to hopper below
|
2015-09-17 12:11:01 +02:00
|
|
|
transfer("main", {x = pos.x, y = pos.y + 1, z = pos.z}, "main", pos)
|
2015-06-12 11:42:11 +02:00
|
|
|
|
|
|
|
elseif a == "default:furnace" or a == "default:furnace_active" then
|
|
|
|
|
|
|
|
-- furnace output above to hopper below
|
2015-09-17 12:11:01 +02:00
|
|
|
transfer("dst", {x = pos.x, y = pos.y + 1, z = pos.z}, "main", pos)
|
2015-06-12 11:42:11 +02:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2015-06-16 11:08:18 +02:00
|
|
|
-- output (to below)
|
2015-06-12 11:42:11 +02:00
|
|
|
|
|
|
|
if b == "default:chest"
|
|
|
|
or b == "default:chest_locked"
|
|
|
|
or b == "protector:chest" then
|
|
|
|
|
|
|
|
-- hopper above to chest below
|
2015-09-17 12:11:01 +02:00
|
|
|
transfer("main", pos, "main", {x = pos.x, y = pos.y - 1, z = pos.z})
|
2015-06-12 11:42:11 +02:00
|
|
|
|
|
|
|
elseif b == "default:furnace" or b == "default:furnace_active" then
|
|
|
|
|
|
|
|
-- hopper above to furnace source below
|
2015-09-17 12:11:01 +02:00
|
|
|
transfer("main", pos, "src", {x = pos.x, y = pos.y - 1, z = pos.z})
|
2015-06-12 11:42:11 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
-- hopper side
|
|
|
|
minetest.register_abm({
|
|
|
|
nodenames = {"hopper:hopper_side"},
|
|
|
|
neighbors = {
|
|
|
|
"default:chest","default:chest_locked","protector:chest",
|
|
|
|
"hopper:hopper","hopper:hopper_side","default:furnace","default:furnace_active"
|
|
|
|
},
|
|
|
|
interval = 1.0,
|
|
|
|
chance = 1,
|
|
|
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
|
|
|
|
2015-09-17 12:11:01 +02:00
|
|
|
local min = {x = pos.x - 1, y = pos.y, z = pos.z - 1}
|
|
|
|
local max = {x = pos.x + 1, y = pos.y + 1, z = pos.z + 1}
|
|
|
|
local vm = minetest.get_voxel_manip()
|
|
|
|
local emin, emax = vm:read_from_map(min, max)
|
|
|
|
local area = VoxelArea:new{MinEdge = emin, MaxEdge = emax}
|
|
|
|
local data = vm:get_data()
|
2015-06-12 11:42:11 +02:00
|
|
|
local face = vm:get_node_at(pos).param2
|
|
|
|
|
|
|
|
local front = {}
|
|
|
|
--local face = minetest.get_node(pos).param2
|
|
|
|
--print(face)
|
|
|
|
|
|
|
|
if face == 0 then
|
2015-09-17 12:11:01 +02:00
|
|
|
front = {x = pos.x - 1, y = pos.y, z = pos.z}
|
2015-06-12 11:42:11 +02:00
|
|
|
elseif face == 1 then
|
2015-09-17 12:11:01 +02:00
|
|
|
front = {x = pos.x, y = pos.y, z = pos.z + 1}
|
2015-06-12 11:42:11 +02:00
|
|
|
elseif face == 2 then
|
2015-09-17 12:11:01 +02:00
|
|
|
front = {x = pos.x + 1, y = pos.y, z = pos.z}
|
2015-06-12 11:42:11 +02:00
|
|
|
elseif face == 3 then
|
2015-09-17 12:11:01 +02:00
|
|
|
front = {x = pos.x, y = pos.y, z = pos.z - 1}
|
2015-06-12 11:42:11 +02:00
|
|
|
end
|
|
|
|
|
2015-09-17 12:11:01 +02:00
|
|
|
local a = vm:get_node_at({x = pos.x, y = pos.y + 1,z = pos.z}).name
|
2015-06-12 11:42:11 +02:00
|
|
|
local b = vm:get_node_at(front).name
|
|
|
|
|
2015-09-17 12:11:01 +02:00
|
|
|
-- local a = minetest.get_node({x = pos.x, y = pos.y + 1, z = pos.z}).name
|
2015-06-12 11:42:11 +02:00
|
|
|
-- local b = minetest.get_node(front).name
|
|
|
|
|
2015-06-16 11:08:18 +02:00
|
|
|
-- input (from above)
|
2015-06-12 11:42:11 +02:00
|
|
|
|
|
|
|
if a == "default:chest"
|
|
|
|
or a == "default:chest_locked"
|
|
|
|
or a == "protector:chest"
|
|
|
|
or a == "hopper:hopper"
|
|
|
|
or a == "hopper:hopper_side" then
|
|
|
|
|
|
|
|
-- chest/hopper above to hopper below
|
2015-09-17 12:11:01 +02:00
|
|
|
transfer("main", {x = pos.x, y = pos.y + 1, z = pos.z}, "main", pos)
|
2015-06-12 11:42:11 +02:00
|
|
|
|
|
|
|
elseif a == "default:furnace" or a == "default:furnace_active" then
|
|
|
|
|
|
|
|
-- furnace output above to hopper below
|
2015-09-17 12:11:01 +02:00
|
|
|
transfer("dst", {x = pos.x, y = pos.y + 1, z = pos.z}, "main", pos)
|
2015-06-12 11:42:11 +02:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2015-06-16 11:08:18 +02:00
|
|
|
-- output (to side)
|
2015-06-12 11:42:11 +02:00
|
|
|
|
|
|
|
if b == "default:chest"
|
|
|
|
or b == "default:chest_locked"
|
2015-06-16 11:08:18 +02:00
|
|
|
or b == "protector:chest"
|
|
|
|
or b == "hopper:hopper"
|
|
|
|
or b == "hopper:hopper_side" then
|
2015-06-12 11:42:11 +02:00
|
|
|
|
|
|
|
-- hopper to chest beside
|
|
|
|
transfer("main", pos, "main", front)
|
|
|
|
|
|
|
|
elseif b == "default:furnace" or b == "default:furnace_active" then
|
|
|
|
|
|
|
|
-- hopper above to furnace fuel beside
|
|
|
|
transfer("main", pos, "fuel", front)
|
|
|
|
end
|
|
|
|
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
-- hopper recipe
|
|
|
|
minetest.register_craft({
|
|
|
|
output = "hopper:hopper",
|
|
|
|
recipe = {
|
|
|
|
{"default:steel_ingot", "", "default:steel_ingot"},
|
|
|
|
{"default:steel_ingot", "default:chest", "default:steel_ingot"},
|
|
|
|
{"", "default:steel_ingot", ""},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
output = "hopper:hopper",
|
|
|
|
recipe = {
|
|
|
|
{"hopper:hopper_side"},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
-- side hopper recipe
|
|
|
|
minetest.register_craft({
|
|
|
|
output = "hopper:hopper_side",
|
|
|
|
recipe = {
|
|
|
|
{"hopper:hopper"},
|
|
|
|
},
|
|
|
|
})
|