mirror of
https://github.com/minetest-mods/hopper.git
synced 2025-01-02 18:47:30 +01:00
Add .luacheckrc and fix its warnings
This commit is contained in:
parent
6624eedf02
commit
30b5654802
22
.luacheckrc
Normal file
22
.luacheckrc
Normal file
@ -0,0 +1,22 @@
|
||||
std = "lua51c"
|
||||
|
||||
ignore = {
|
||||
"21[23]", -- unused argument
|
||||
}
|
||||
|
||||
max_line_length = 250
|
||||
|
||||
read_globals = {
|
||||
"default",
|
||||
"ItemStack",
|
||||
"lucky_block",
|
||||
"minetest",
|
||||
"screwdriver",
|
||||
"vector",
|
||||
}
|
||||
|
||||
globals = {"hopper"}
|
||||
|
||||
files["doc.lua"] = {
|
||||
max_line_length = 9999,
|
||||
}
|
4
abms.lua
4
abms.lua
@ -5,7 +5,7 @@ minetest.register_abm({
|
||||
nodenames = {"hopper:hopper", "hopper:hopper_side"},
|
||||
interval = 1.0,
|
||||
chance = 1,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
action = function(pos, _, _, active_object_count_wider)
|
||||
if active_object_count_wider == 0 then
|
||||
return
|
||||
end
|
||||
@ -85,7 +85,7 @@ minetest.register_abm({
|
||||
chance = 1,
|
||||
catch_up = false,
|
||||
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
action = function(pos, node, _, _)
|
||||
local source_pos, destination_pos, destination_dir
|
||||
if node.name == "hopper:hopper_side" then
|
||||
source_pos = vector.add(pos, directions[node.param2].src)
|
||||
|
10
crafts.lua
10
crafts.lua
@ -7,14 +7,14 @@ if minetest.get_modpath("default") then
|
||||
{"","default:steel_ingot",""},
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
minetest.register_craft({
|
||||
output = "hopper:chute",
|
||||
recipe = {
|
||||
{"default:steel_ingot","default:chest","default:steel_ingot"},
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
minetest.register_craft({
|
||||
output = "hopper:sorter",
|
||||
recipe = {
|
||||
@ -23,7 +23,7 @@ if minetest.get_modpath("default") then
|
||||
{"","default:steel_ingot",""},
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
if not hopper.config.single_craftable_item then
|
||||
minetest.register_craft({
|
||||
output = "hopper:hopper_side",
|
||||
@ -32,13 +32,13 @@ if minetest.get_modpath("default") then
|
||||
{"","","default:steel_ingot"},
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
minetest.register_craft({
|
||||
output = "hopper:hopper_side",
|
||||
type="shapeless",
|
||||
recipe = {"hopper:hopper"},
|
||||
})
|
||||
|
||||
|
||||
minetest.register_craft({
|
||||
output = "hopper:hopper",
|
||||
type="shapeless",
|
||||
|
@ -48,10 +48,7 @@ minetest.register_node("hopper:chute", {
|
||||
end,
|
||||
|
||||
on_place = function(itemstack, placer, pointed_thing, node_name)
|
||||
local pos = pointed_thing.under
|
||||
local pos2 = pointed_thing.above
|
||||
local x = pos.x - pos2.x
|
||||
local z = pos.z - pos2.z
|
||||
|
||||
local returned_stack, success = minetest.item_place_node(itemstack, placer, pointed_thing)
|
||||
if success then
|
||||
|
@ -22,10 +22,10 @@ end
|
||||
-- because they are literally *side* hoppers - their spouts point to the side rather than to the front, so
|
||||
-- the default item_place_node orientation code will not orient them pointing toward the selected surface.
|
||||
local hopper_on_place = function(itemstack, placer, pointed_thing, node_name)
|
||||
local returned_stack, success
|
||||
local returned_stack, success, _
|
||||
|
||||
if not (hopper.config.single_craftable_item or node_name == "hopper:hopper_side") then
|
||||
returned_stack, success = minetest.item_place_node(itemstack, placer, pointed_thing)
|
||||
returned_stack, _ = minetest.item_place_node(itemstack, placer, pointed_thing)
|
||||
return returned_stack
|
||||
end
|
||||
|
||||
@ -47,12 +47,12 @@ local hopper_on_place = function(itemstack, placer, pointed_thing, node_name)
|
||||
end
|
||||
|
||||
if param2 then
|
||||
returned_stack, success = minetest.item_place_node(ItemStack("hopper:hopper_side"), placer, pointed_thing, param2)
|
||||
_, success = minetest.item_place_node(ItemStack("hopper:hopper_side"), placer, pointed_thing, param2)
|
||||
else
|
||||
if hopper.config.single_craftable_item then
|
||||
node_name = "hopper:hopper" -- For cases where single_craftable_item was set on an existing world and there are still side hoppers in player inventories
|
||||
end
|
||||
returned_stack, success = minetest.item_place_node(ItemStack(node_name), placer, pointed_thing)
|
||||
_, success = minetest.item_place_node(ItemStack(node_name), placer, pointed_thing)
|
||||
end
|
||||
|
||||
if success then
|
||||
|
@ -81,10 +81,7 @@ minetest.register_node("hopper:sorter", {
|
||||
end,
|
||||
|
||||
on_place = function(itemstack, placer, pointed_thing, node_name)
|
||||
local pos = pointed_thing.under
|
||||
local pos2 = pointed_thing.above
|
||||
local x = pos.x - pos2.x
|
||||
local z = pos.z - pos2.z
|
||||
|
||||
local returned_stack, success = minetest.item_place_node(itemstack, placer, pointed_thing)
|
||||
if success then
|
||||
@ -171,44 +168,28 @@ minetest.register_node("hopper:sorter", {
|
||||
local node = minetest.get_node(pos)
|
||||
local dir = minetest.facedir_to_dir(node.param2)
|
||||
local default_destination_pos = vector.add(pos, dir)
|
||||
local default_output_direction
|
||||
if dir.y == 0 then
|
||||
default_output_direction = "horizontal"
|
||||
end
|
||||
local default_output_direction = (dir.y == 0) and "side" or "bottom"
|
||||
|
||||
dir = bottomdir(node.param2)
|
||||
local filter_destination_pos = vector.add(pos, dir)
|
||||
local filter_output_direction
|
||||
if dir.y == 0 then
|
||||
filter_output_direction = "horizontal"
|
||||
end
|
||||
local filter_output_direction = (dir.y == 0) and "side" or "bottom"
|
||||
|
||||
local success = false
|
||||
--- returns success? = true/false
|
||||
local function try_send_item(output_dir, dst_pos)
|
||||
local dst_node = minetest.get_node(dst_pos)
|
||||
local registered_inventories = hopper.get_registered(dst_node.name)
|
||||
|
||||
local filter_destination_node = minetest.get_node(filter_destination_pos)
|
||||
local registered_inventories = hopper.get_registered(filter_destination_node.name)
|
||||
if registered_inventories ~= nil then
|
||||
if filter_output_direction == "horizontal" then
|
||||
success = hopper.send_item_to(pos, filter_destination_pos, filter_destination_node, registered_inventories["side"], filter_items)
|
||||
else
|
||||
success = hopper.send_item_to(pos, filter_destination_pos, filter_destination_node, registered_inventories["bottom"], filter_items)
|
||||
end
|
||||
else
|
||||
success = hopper.send_item_to(pos, filter_destination_pos, filter_destination_node, nil, filter_items)
|
||||
end
|
||||
|
||||
if not success then -- weren't able to put something in the filter destination, for whatever reason. Now we can start moving stuff forward to the default.
|
||||
local default_destination_node = minetest.get_node(default_destination_pos)
|
||||
local registered_inventories = hopper.get_registered(default_destination_node.name)
|
||||
if registered_inventories ~= nil then
|
||||
if default_output_direction == "horizontal" then
|
||||
hopper.send_item_to(pos, default_destination_pos, default_destination_node, registered_inventories["side"])
|
||||
else
|
||||
hopper.send_item_to(pos, default_destination_pos, default_destination_node, registered_inventories["bottom"])
|
||||
end
|
||||
else
|
||||
hopper.send_item_to(pos, default_destination_pos, default_destination_node)
|
||||
return hopper.send_item_to(pos, dst_pos, dst_node, registered_inventories[output_dir], filter_items)
|
||||
end
|
||||
|
||||
return hopper.send_item_to(pos, dst_pos, dst_node, nil, filter_items)
|
||||
end
|
||||
|
||||
if not try_send_item(filter_output_direction, filter_destination_pos) then
|
||||
-- weren't able to put something in the filter destination, for whatever reason.
|
||||
-- Now we can start moving stuff forward to the default.
|
||||
try_send_item(default_output_direction, default_destination_pos)
|
||||
end
|
||||
|
||||
if not inv:is_empty("main") then
|
||||
|
@ -1,4 +1,3 @@
|
||||
local S = minetest.get_translator("hopper")
|
||||
local FS = hopper.translator_escaped
|
||||
-- Target inventory retrieval
|
||||
|
||||
@ -76,6 +75,7 @@ local function get_container_inventory(node_pos, inv_info)
|
||||
if get_inventory_fn then
|
||||
inventory = get_inventory_fn(node_pos)
|
||||
if not inventory then
|
||||
local target_node = minetest.get_node(node_pos)
|
||||
minetest.log("error","No inventory from api get_inventory function: " ..
|
||||
target_node.name .. " on " .. vector.to_string(node_pos))
|
||||
end
|
||||
@ -131,12 +131,12 @@ end
|
||||
|
||||
-- Used to put items from the hopper inventory into the target block
|
||||
hopper.send_item_to = function(hopper_pos, target_pos, target_node, target_inv_info, filtered_items)
|
||||
local hopper_meta = minetest.get_meta(hopper_pos)
|
||||
local target_def = minetest.registered_nodes[target_node.name]
|
||||
if not target_def then
|
||||
return false
|
||||
end
|
||||
|
||||
local hopper_meta = minetest.get_meta(hopper_pos)
|
||||
local eject_item = hopper.config.eject_button_enabled and hopper_meta:get_string("eject") == "true" and target_def.buildable_to
|
||||
|
||||
if not eject_item and not target_inv_info then
|
||||
@ -144,7 +144,6 @@ hopper.send_item_to = function(hopper_pos, target_pos, target_node, target_inv_i
|
||||
end
|
||||
|
||||
--hopper inventory
|
||||
local hopper_meta = minetest.get_meta(hopper_pos);
|
||||
local hopper_inv = hopper_meta:get_inventory()
|
||||
if hopper_inv:is_empty("main") == true then
|
||||
return false
|
||||
|
Loading…
Reference in New Issue
Block a user