mirror of
https://github.com/minetest-mods/hopper.git
synced 2025-01-03 11:07:30 +01:00
Tweaked code, hopper now stores half as much
This commit is contained in:
parent
c4dad128c7
commit
3478d85500
112
init.lua
112
init.lua
@ -16,7 +16,7 @@ end
|
|||||||
-- hopper
|
-- hopper
|
||||||
minetest.register_node("hopper:hopper", {
|
minetest.register_node("hopper:hopper", {
|
||||||
description = "Hopper",
|
description = "Hopper",
|
||||||
groups = {cracky = 1, level = 2},
|
groups = {cracky = 3},
|
||||||
drawtype = "nodebox",
|
drawtype = "nodebox",
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
tiles = {"default_coal_block.png"},
|
tiles = {"default_coal_block.png"},
|
||||||
@ -40,7 +40,7 @@ minetest.register_node("hopper:hopper", {
|
|||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
meta:set_string("infotext", "Hopper")
|
meta:set_string("infotext", "Hopper")
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
inv:set_size("main", 8*4)
|
inv:set_size("main", 4*4) -- was 8*4
|
||||||
end,
|
end,
|
||||||
|
|
||||||
can_dig = function(pos, player)
|
can_dig = function(pos, player)
|
||||||
@ -78,10 +78,10 @@ minetest.register_node("hopper:hopper", {
|
|||||||
on_rotate = screwdriver.disallow,
|
on_rotate = screwdriver.disallow,
|
||||||
})
|
})
|
||||||
|
|
||||||
-- hopper side
|
-- side hopper
|
||||||
minetest.register_node("hopper:hopper_side", {
|
minetest.register_node("hopper:hopper_side", {
|
||||||
description = "Side Hopper",
|
description = "Side Hopper",
|
||||||
groups = {cracky = 1, level = 2},
|
groups = {cracky = 3},
|
||||||
drawtype = "nodebox",
|
drawtype = "nodebox",
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
@ -106,7 +106,7 @@ minetest.register_node("hopper:hopper_side", {
|
|||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
meta:set_string("infotext", "Side Hopper")
|
meta:set_string("infotext", "Side Hopper")
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
inv:set_size("main", 8*4)
|
inv:set_size("main", 4*4) -- was 8*4
|
||||||
end,
|
end,
|
||||||
|
|
||||||
can_dig = function(pos, player)
|
can_dig = function(pos, player)
|
||||||
@ -146,27 +146,34 @@ minetest.register_node("hopper:hopper_side", {
|
|||||||
|
|
||||||
-- suck in items on top of hopper
|
-- suck in items on top of hopper
|
||||||
minetest.register_abm({
|
minetest.register_abm({
|
||||||
|
|
||||||
nodenames = {"hopper:hopper", "hopper:hopper_side"},
|
nodenames = {"hopper:hopper", "hopper:hopper_side"},
|
||||||
interval = 1.0,
|
interval = 1.0,
|
||||||
chance = 1,
|
chance = 1,
|
||||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
|
||||||
|
action = function(pos, node)
|
||||||
|
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
local posob
|
local posob
|
||||||
|
|
||||||
for _,object in ipairs(minetest.get_objects_inside_radius(pos, 1)) do
|
for _,object in ipairs(minetest.get_objects_inside_radius(pos, 1)) do
|
||||||
|
|
||||||
if not object:is_player()
|
if not object:is_player()
|
||||||
and object:get_luaentity()
|
and object:get_luaentity()
|
||||||
and object:get_luaentity().name == "__builtin:item" then
|
and object:get_luaentity().name == "__builtin:item"
|
||||||
if inv and inv:room_for_item("main", ItemStack(object:get_luaentity().itemstring)) then
|
and inv
|
||||||
posob = object:getpos()
|
and inv:room_for_item("main", ItemStack(object:get_luaentity().itemstring)) then
|
||||||
if math.abs(posob.x - pos.x) <= 0.5
|
|
||||||
and posob.y - pos.y <= 0.85
|
posob = object:getpos()
|
||||||
and posob.y - pos.y >= 0.3 then
|
|
||||||
inv:add_item("main", ItemStack(object:get_luaentity().itemstring))
|
if math.abs(posob.x - pos.x) <= 0.5
|
||||||
object:get_luaentity().itemstring = ""
|
and posob.y - pos.y <= 0.85
|
||||||
object:remove()
|
and posob.y - pos.y >= 0.3 then
|
||||||
end
|
|
||||||
|
inv:add_item("main", ItemStack(object:get_luaentity().itemstring))
|
||||||
|
object:get_luaentity().itemstring = ""
|
||||||
|
object:remove()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -208,11 +215,10 @@ local transfer = function(src, srcpos, dst, dstpos)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- is item a tool
|
-- is item a tool
|
||||||
if stack:get_wear() > 0 then -- tool
|
if stack:get_wear() > 0 then
|
||||||
local it = stack:take_item(stack:get_count())
|
inv2:add_item(dst, stack:take_item(stack:get_count()))
|
||||||
inv2:add_item(dst, it)
|
|
||||||
inv:set_stack(src, i, nil)
|
inv:set_stack(src, i, nil)
|
||||||
else -- everything else
|
else -- not a tool
|
||||||
stack:take_item(1)
|
stack:take_item(1)
|
||||||
inv2:add_item(dst, item)
|
inv2:add_item(dst, item)
|
||||||
inv:set_stack(src, i, stack)
|
inv:set_stack(src, i, stack)
|
||||||
@ -227,6 +233,7 @@ end
|
|||||||
|
|
||||||
-- hopper transfer
|
-- hopper transfer
|
||||||
minetest.register_abm({
|
minetest.register_abm({
|
||||||
|
|
||||||
nodenames = {"hopper:hopper"},
|
nodenames = {"hopper:hopper"},
|
||||||
neighbors = {
|
neighbors = {
|
||||||
"default:chest", "default:chest_locked", "protector:chest",
|
"default:chest", "default:chest_locked", "protector:chest",
|
||||||
@ -235,7 +242,8 @@ minetest.register_abm({
|
|||||||
},
|
},
|
||||||
interval = 1.0,
|
interval = 1.0,
|
||||||
chance = 1,
|
chance = 1,
|
||||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
|
||||||
|
action = function(pos, node)
|
||||||
|
|
||||||
local min = {x = pos.x, y = pos.y - 1, z = pos.z}
|
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 max = {x = pos.x, y = pos.y + 1, z = pos.z}
|
||||||
@ -258,12 +266,21 @@ minetest.register_abm({
|
|||||||
or a == "hopper:hopper_side" then
|
or a == "hopper:hopper_side" then
|
||||||
|
|
||||||
-- chest/hopper above to hopper below
|
-- chest/hopper above to hopper below
|
||||||
transfer("main", {x = pos.x, y = pos.y + 1, z = pos.z}, "main", pos)
|
transfer("main", {
|
||||||
|
x = pos.x,
|
||||||
|
y = pos.y + 1,
|
||||||
|
z = pos.z
|
||||||
|
}, "main", pos)
|
||||||
|
|
||||||
elseif a == "default:furnace" or a == "default:furnace_active" then
|
elseif a == "default:furnace"
|
||||||
|
or a == "default:furnace_active" then
|
||||||
|
|
||||||
-- furnace output above to hopper below
|
-- furnace output above to hopper below
|
||||||
transfer("dst", {x = pos.x, y = pos.y + 1, z = pos.z}, "main", pos)
|
transfer("dst", {
|
||||||
|
x = pos.x,
|
||||||
|
y = pos.y + 1,
|
||||||
|
z = pos.z
|
||||||
|
}, "main", pos)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -274,12 +291,21 @@ minetest.register_abm({
|
|||||||
or b == "protector:chest" then
|
or b == "protector:chest" then
|
||||||
|
|
||||||
-- hopper above to chest below
|
-- hopper above to chest below
|
||||||
transfer("main", pos, "main", {x = pos.x, y = pos.y - 1, z = pos.z})
|
transfer("main", pos, "main", {
|
||||||
|
x = pos.x,
|
||||||
elseif b == "default:furnace" or b == "default:furnace_active" then
|
y = pos.y - 1,
|
||||||
|
z = pos.z
|
||||||
|
})
|
||||||
|
|
||||||
|
elseif b == "default:furnace"
|
||||||
|
or b == "default:furnace_active" then
|
||||||
|
|
||||||
-- hopper above to furnace source below
|
-- hopper above to furnace source below
|
||||||
transfer("main", pos, "src", {x = pos.x, y = pos.y - 1, z = pos.z})
|
transfer("main", pos, "src", {
|
||||||
|
x = pos.x,
|
||||||
|
y = pos.y - 1,
|
||||||
|
z = pos.z
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
end,
|
end,
|
||||||
@ -287,6 +313,7 @@ minetest.register_abm({
|
|||||||
|
|
||||||
-- hopper side
|
-- hopper side
|
||||||
minetest.register_abm({
|
minetest.register_abm({
|
||||||
|
|
||||||
nodenames = {"hopper:hopper_side"},
|
nodenames = {"hopper:hopper_side"},
|
||||||
neighbors = {
|
neighbors = {
|
||||||
"default:chest","default:chest_locked","protector:chest",
|
"default:chest","default:chest_locked","protector:chest",
|
||||||
@ -294,7 +321,8 @@ minetest.register_abm({
|
|||||||
},
|
},
|
||||||
interval = 1.0,
|
interval = 1.0,
|
||||||
chance = 1,
|
chance = 1,
|
||||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
|
||||||
|
action = function(pos, node)
|
||||||
|
|
||||||
local min = {x = pos.x - 1, y = pos.y, z = pos.z - 1}
|
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 max = {x = pos.x + 1, y = pos.y + 1, z = pos.z + 1}
|
||||||
@ -305,8 +333,7 @@ minetest.register_abm({
|
|||||||
local face = vm:get_node_at(pos).param2
|
local face = vm:get_node_at(pos).param2
|
||||||
|
|
||||||
local front = {}
|
local front = {}
|
||||||
--local face = minetest.get_node(pos).param2
|
--local face = minetest.get_node(pos).param2 ; print(face)
|
||||||
--print(face)
|
|
||||||
|
|
||||||
if face == 0 then
|
if face == 0 then
|
||||||
front = {x = pos.x - 1, y = pos.y, z = pos.z}
|
front = {x = pos.x - 1, y = pos.y, z = pos.z}
|
||||||
@ -335,12 +362,21 @@ minetest.register_abm({
|
|||||||
or a == "hopper:hopper_side" then
|
or a == "hopper:hopper_side" then
|
||||||
|
|
||||||
-- chest/hopper above to hopper below
|
-- chest/hopper above to hopper below
|
||||||
transfer("main", {x = pos.x, y = pos.y + 1, z = pos.z}, "main", pos)
|
transfer("main", {
|
||||||
|
x = pos.x,
|
||||||
|
y = pos.y + 1,
|
||||||
|
z = pos.z
|
||||||
|
}, "main", pos)
|
||||||
|
|
||||||
elseif a == "default:furnace" or a == "default:furnace_active" then
|
elseif a == "default:furnace"
|
||||||
|
or a == "default:furnace_active" then
|
||||||
|
|
||||||
-- furnace output above to hopper below
|
-- furnace output above to hopper below
|
||||||
transfer("dst", {x = pos.x, y = pos.y + 1, z = pos.z}, "main", pos)
|
transfer("dst", {
|
||||||
|
x = pos.x,
|
||||||
|
y = pos.y + 1,
|
||||||
|
z = pos.z
|
||||||
|
}, "main", pos)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -355,9 +391,10 @@ minetest.register_abm({
|
|||||||
-- hopper to chest beside
|
-- hopper to chest beside
|
||||||
transfer("main", pos, "main", front)
|
transfer("main", pos, "main", front)
|
||||||
|
|
||||||
elseif b == "default:furnace" or b == "default:furnace_active" then
|
elseif b == "default:furnace"
|
||||||
|
or b == "default:furnace_active" then
|
||||||
|
|
||||||
-- hopper above to furnace fuel beside
|
-- hopper to furnace fuel beside
|
||||||
transfer("main", pos, "fuel", front)
|
transfer("main", pos, "fuel", front)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -374,6 +411,7 @@ minetest.register_craft({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- hopper to side hopper recipe
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = "hopper:hopper",
|
output = "hopper:hopper",
|
||||||
recipe = {
|
recipe = {
|
||||||
@ -381,7 +419,7 @@ minetest.register_craft({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
-- side hopper recipe
|
-- side hopper back to hopper recipe
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = "hopper:hopper_side",
|
output = "hopper:hopper_side",
|
||||||
recipe = {
|
recipe = {
|
||||||
|
Loading…
Reference in New Issue
Block a user