Consistently capitalize constants
This should make the code more understandable. Hopefully I didn't miss anything. Non-function variables that do not change and are used outside their immediate surroundings should generally be capitalized.
This commit is contained in:
parent
7ffe9da10b
commit
b9199fb097
@ -43,13 +43,13 @@
|
||||
|
||||
local use = ...
|
||||
local S, get_node_maybe_load,
|
||||
exit_offset, digiline_offset, port_offsets,
|
||||
container_name_prefix, port_name_prefix,
|
||||
EXIT_OFFSET, DIGILINE_OFFSET, PORT_OFFSETS,
|
||||
CONTAINER_NAME_PREFIX, PORT_NAME_PREFIX,
|
||||
get_non_player_object_count,
|
||||
update_non_player_object_count = use("misc", {
|
||||
"translate", "get_node_maybe_load",
|
||||
"exit_offset", "digiline_offset", "port_offsets",
|
||||
"container_name_prefix", "port_name_prefix",
|
||||
"EXIT_OFFSET", "DIGILINE_OFFSET", "PORT_OFFSETS",
|
||||
"CONTAINER_NAME_PREFIX", "PORT_NAME_PREFIX",
|
||||
"get_non_player_object_count",
|
||||
"update_non_player_object_count",
|
||||
})
|
||||
@ -72,8 +72,8 @@ local exports = {}
|
||||
-- The object count might not be 100% accurate. The node parameter is optional.
|
||||
local function container_is_empty(pos, node)
|
||||
node = node or get_node_maybe_load(pos)
|
||||
local name_prefix = string.sub(node.name, 1, #container_name_prefix)
|
||||
if name_prefix ~= container_name_prefix then return true end
|
||||
local name_prefix = string.sub(node.name, 1, #CONTAINER_NAME_PREFIX)
|
||||
if name_prefix ~= CONTAINER_NAME_PREFIX then return true end
|
||||
-- Invalid containers are empty:
|
||||
if node.param1 == 0 and node.param2 == 0 then return true end
|
||||
local inside_pos = get_related_inside(node.param1, node.param2)
|
||||
@ -125,7 +125,7 @@ end
|
||||
|
||||
-- Sets up the exit node near inside_pos. The params encode the relation.
|
||||
local function set_up_exit(inside_pos)
|
||||
local pos = vector.add(inside_pos, exit_offset)
|
||||
local pos = vector.add(inside_pos, EXIT_OFFSET)
|
||||
minetest.set_node(pos, {name = "area_containers:exit"})
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("infotext", S("Exit"))
|
||||
@ -133,17 +133,17 @@ end
|
||||
|
||||
-- Sets up the digiline node near inside_pos. The params encode the relation.
|
||||
local function set_up_digiline(inside_pos)
|
||||
local pos = vector.add(inside_pos, digiline_offset)
|
||||
local pos = vector.add(inside_pos, DIGILINE_OFFSET)
|
||||
minetest.set_node(pos, {name = "area_containers:digiline"})
|
||||
end
|
||||
|
||||
-- Removes and cleans up previous inside ports if they are there.
|
||||
local function remove_previous_ports(inside_pos)
|
||||
for _, offset in pairs(port_offsets) do
|
||||
for _, offset in pairs(PORT_OFFSETS) do
|
||||
local pos = vector.add(inside_pos, offset)
|
||||
local prev = get_node_maybe_load(pos)
|
||||
if string.sub(prev.name, 1, #port_name_prefix)
|
||||
== port_name_prefix then
|
||||
if string.sub(prev.name, 1, #PORT_NAME_PREFIX)
|
||||
== PORT_NAME_PREFIX then
|
||||
minetest.remove_node(pos)
|
||||
local prev_def = minetest.registered_nodes[prev.name]
|
||||
if prev_def and prev_def.after_dig_node then
|
||||
@ -155,9 +155,9 @@ end
|
||||
|
||||
-- Sets up the port nodes near inside_pos. The params encode the relation.
|
||||
local function set_up_ports(param1, param2, inside_pos)
|
||||
for id, offset in pairs(port_offsets) do
|
||||
for id, offset in pairs(PORT_OFFSETS) do
|
||||
local pos = vector.add(inside_pos, offset)
|
||||
local name = port_name_prefix .. id .. "_off"
|
||||
local name = PORT_NAME_PREFIX .. id .. "_off"
|
||||
minetest.set_node(pos, {
|
||||
name = name, param1 = param1, param2 = param2,
|
||||
})
|
||||
@ -387,7 +387,7 @@ end
|
||||
|
||||
-- Teleports the player out of the container.
|
||||
function exports.exit.on_rightclick(pos, _node, clicker)
|
||||
local inside_pos = vector.subtract(pos, exit_offset)
|
||||
local inside_pos = vector.subtract(pos, EXIT_OFFSET)
|
||||
local param1, param2 = get_params_from_inside(inside_pos)
|
||||
local clicker_pos = clicker and clicker:get_pos()
|
||||
if param1 and clicker_pos and
|
||||
|
@ -27,7 +27,7 @@
|
||||
]]
|
||||
|
||||
local use = ...
|
||||
local digiline_offset = use("misc", {"digiline_offset"})
|
||||
local DIGILINE_OFFSET = use("misc", {"DIGILINE_OFFSET"})
|
||||
local get_related_container, get_related_inside,
|
||||
get_params_from_inside = use("relation", {
|
||||
"get_related_container", "get_related_inside",
|
||||
@ -41,7 +41,7 @@ exports.container = {}
|
||||
exports.digiline = {}
|
||||
|
||||
-- The connection rules (relative positions to link to) for the digiline node.
|
||||
local digiline_node_rules = {
|
||||
local DIGILINE_NODE_RULES = {
|
||||
{x = 1, y = 1, z = 0},
|
||||
{x = 0, y = 1, z = 1},
|
||||
{x = -1, y = 1, z = 0},
|
||||
@ -56,18 +56,18 @@ exports.container.digiline = {
|
||||
-- Forwards messages to the inside.
|
||||
function exports.container.digiline.effector.action(_pos, node, channel, msg)
|
||||
local inside_pos = get_related_inside(node.param1, node.param2)
|
||||
local digiline_pos = vector.add(inside_pos, digiline_offset)
|
||||
digiline:receptor_send(digiline_pos, digiline_node_rules, channel, msg)
|
||||
local digiline_pos = vector.add(inside_pos, DIGILINE_OFFSET)
|
||||
digiline:receptor_send(digiline_pos, DIGILINE_NODE_RULES, channel, msg)
|
||||
end
|
||||
|
||||
exports.digiline.digiline = {
|
||||
effector = {rules = digiline_node_rules},
|
||||
receptor = {rules = digiline_node_rules},
|
||||
effector = {rules = DIGILINE_NODE_RULES},
|
||||
receptor = {rules = DIGILINE_NODE_RULES},
|
||||
}
|
||||
|
||||
-- Forwards digiline messages to the container.
|
||||
function exports.digiline.digiline.effector.action(pos, _node, channel, msg)
|
||||
local inside_pos = vector.subtract(pos, digiline_offset)
|
||||
local inside_pos = vector.subtract(pos, DIGILINE_OFFSET)
|
||||
local param1, param2 = get_params_from_inside(inside_pos)
|
||||
if not param1 then return end
|
||||
local container_pos = get_related_container(param1, param2)
|
||||
|
2
init.lua
2
init.lua
@ -56,7 +56,7 @@ local function use(dep, keys)
|
||||
end
|
||||
end
|
||||
|
||||
if use("settings", {"enable_crafts"}) then
|
||||
if use("settings", {"ENABLE_CRAFTS"}) then
|
||||
use("crafts")
|
||||
end
|
||||
use("items")
|
||||
|
28
mesecons.lua
28
mesecons.lua
@ -30,12 +30,12 @@
|
||||
]]
|
||||
|
||||
local use = ...
|
||||
local all_container_states, port_name_prefix,
|
||||
port_offsets, port_ids_horiz, get_port_id_from_name,
|
||||
mesecon_state_on, mesecon_state_off, vec2table = use("misc", {
|
||||
"all_container_states", "port_name_prefix",
|
||||
"port_offsets", "port_ids_horiz", "get_port_id_from_name",
|
||||
"mesecon_state_on", "mesecon_state_off", "vec2table",
|
||||
local ALL_CONTAINER_STATES, PORT_NAME_PREFIX,
|
||||
PORT_OFFSETS, PORT_IDS_HORIZ, get_port_id_from_name,
|
||||
MESECON_STATE_ON, MESECON_STATE_OFF, vec2table = use("misc", {
|
||||
"ALL_CONTAINER_STATES", "PORT_NAME_PREFIX",
|
||||
"PORT_OFFSETS", "PORT_IDS_HORIZ", "get_port_id_from_name",
|
||||
"MESECON_STATE_ON", "MESECON_STATE_OFF", "vec2table",
|
||||
})
|
||||
local get_related_container, get_related_inside = use("relation", {
|
||||
"get_related_container", "get_related_inside"
|
||||
@ -48,10 +48,10 @@ exports.container = {}
|
||||
-- A container is a conductor to its insides. The position of its insides can
|
||||
-- be determined from param1 and param2.
|
||||
exports.container.mesecons = {conductor = {
|
||||
states = all_container_states,
|
||||
states = ALL_CONTAINER_STATES,
|
||||
}}
|
||||
local function container_rules_add_port(rules, port_id, self_pos, inside_pos)
|
||||
local port_pos = vector.add(inside_pos, port_offsets[port_id])
|
||||
local port_pos = vector.add(inside_pos, PORT_OFFSETS[port_id])
|
||||
local offset_to_port = vector.subtract(port_pos, self_pos)
|
||||
rules[#rules + 1] = vec2table(offset_to_port)
|
||||
end
|
||||
@ -100,7 +100,7 @@ local function get_port_rules(node)
|
||||
if container_pos then
|
||||
local id = get_port_id_from_name(node.name)
|
||||
local inside_pos = get_related_inside(node.param1, node.param2)
|
||||
local self_pos = vector.add(inside_pos, port_offsets[id])
|
||||
local self_pos = vector.add(inside_pos, PORT_OFFSETS[id])
|
||||
local container_offset =
|
||||
vector.subtract(container_pos, self_pos)
|
||||
rules[#rules + 1] = vec2table(container_offset)
|
||||
@ -110,19 +110,19 @@ end
|
||||
|
||||
-- mesecons information for port nodes that have it, with node names as keys.
|
||||
exports.ports = {}
|
||||
for _, id in ipairs(port_ids_horiz) do
|
||||
local on_state = port_name_prefix .. id .. "_on"
|
||||
local off_state = port_name_prefix .. id .. "_off"
|
||||
for _, id in ipairs(PORT_IDS_HORIZ) do
|
||||
local on_state = PORT_NAME_PREFIX .. id .. "_on"
|
||||
local off_state = PORT_NAME_PREFIX .. id .. "_off"
|
||||
exports.ports[on_state] = {
|
||||
mesecons = {conductor = {
|
||||
state = mesecon_state_on,
|
||||
state = MESECON_STATE_ON,
|
||||
offstate = off_state,
|
||||
rules = get_port_rules,
|
||||
}},
|
||||
}
|
||||
exports.ports[off_state] = {
|
||||
mesecons = {conductor = {
|
||||
state = mesecon_state_off,
|
||||
state = MESECON_STATE_OFF,
|
||||
onstate = on_state,
|
||||
rules = get_port_rules,
|
||||
}},
|
||||
|
40
misc.lua
40
misc.lua
@ -72,33 +72,33 @@ end
|
||||
exports.MCL_BLAST_RESISTANCE_INDESTRUCTIBLE = 1000000
|
||||
|
||||
-- The longest common prefix of all container node names.
|
||||
exports.container_name_prefix = "area_containers:container_"
|
||||
exports.CONTAINER_NAME_PREFIX = "area_containers:container_"
|
||||
|
||||
-- The 16 container node names counting up from off to on in binary. The bits
|
||||
-- from most to least significant are: +X, -X, +Z, -Z.
|
||||
exports.all_container_states = {}
|
||||
exports.ALL_CONTAINER_STATES = {}
|
||||
local all_container_variants = {
|
||||
"off", "0001", "0010", "0011", "0100", "0101", "0110", "0111",
|
||||
"1000", "1001", "1010", "1011", "1100", "1101", "1110", "on",
|
||||
}
|
||||
for i, variant in ipairs(all_container_variants) do
|
||||
exports.all_container_states[i] =
|
||||
exports.container_name_prefix .. variant
|
||||
exports.ALL_CONTAINER_STATES[i] =
|
||||
exports.CONTAINER_NAME_PREFIX .. variant
|
||||
end
|
||||
|
||||
-- The mesecons on and off states or nil if they could not be found.
|
||||
if minetest.global_exists("mesecon") and mesecon.state then
|
||||
exports.mesecon_state_on = mesecon.state.on
|
||||
exports.mesecon_state_off = mesecon.state.off
|
||||
exports.MESECON_STATE_ON = mesecon.state.on
|
||||
exports.MESECON_STATE_OFF = mesecon.state.off
|
||||
end
|
||||
|
||||
-- The offsets of the exit and digiline nodes from the inside position
|
||||
-- (the chamber wall position with the lowest x, y, and z.)
|
||||
exports.exit_offset = vector.new(0, 2, 1)
|
||||
exports.digiline_offset = vector.new(3, 0, 3)
|
||||
exports.EXIT_OFFSET = vector.new(0, 2, 1)
|
||||
exports.DIGILINE_OFFSET = vector.new(3, 0, 3)
|
||||
|
||||
-- A mapping from port IDs to offsets from the inside position.
|
||||
exports.port_offsets = {
|
||||
exports.PORT_OFFSETS = {
|
||||
nx = vector.new(0, 2, 4), pz = vector.new(0, 2, 6),
|
||||
px = vector.new(0, 2, 8), nz = vector.new(0, 2, 10),
|
||||
py = vector.new(0, 2, 12), ny = vector.new(0, 2, 14),
|
||||
@ -106,7 +106,7 @@ exports.port_offsets = {
|
||||
|
||||
-- A mapping from port IDs to unit vectors encoding the directions the
|
||||
-- corresponding outside ports face.
|
||||
exports.port_dirs = {
|
||||
exports.PORT_DIRS = {
|
||||
nx = vector.new(-1, 0, 0), pz = vector.new(0, 0, 1),
|
||||
px = vector.new(1, 0, 0), nz = vector.new(0, 0, -1),
|
||||
py = vector.new(0, 1, 0), ny = vector.new(0, -1, 0),
|
||||
@ -114,26 +114,26 @@ exports.port_dirs = {
|
||||
|
||||
-- The list of horizontal port IDs in the order they appear inside,
|
||||
-- left to right.
|
||||
exports.port_ids_horiz = {"nx", "pz", "px", "nz"}
|
||||
exports.PORT_IDS_HORIZ = {"nx", "pz", "px", "nz"}
|
||||
|
||||
-- The longest common prefix of all port node names.
|
||||
local port_name_prefix = "area_containers:port_"
|
||||
exports.port_name_prefix = port_name_prefix
|
||||
local PORT_NAME_PREFIX = "area_containers:port_"
|
||||
exports.PORT_NAME_PREFIX = PORT_NAME_PREFIX
|
||||
|
||||
-- Maps a port node name to the corresponding port ID.
|
||||
function exports.get_port_id_from_name(node_name)
|
||||
local prefix_length = #port_name_prefix
|
||||
local prefix_length = #PORT_NAME_PREFIX
|
||||
return string.sub(node_name, prefix_length + 1, prefix_length + 2)
|
||||
end
|
||||
|
||||
-- The names of all nodes that count as ports.
|
||||
exports.all_port_states = {}
|
||||
for _, id in ipairs(exports.port_ids_horiz) do
|
||||
table.insert(exports.all_port_states, port_name_prefix .. id .. "_on")
|
||||
table.insert(exports.all_port_states, port_name_prefix .. id .. "_off")
|
||||
exports.ALL_PORT_STATES = {}
|
||||
for _, id in ipairs(exports.PORT_IDS_HORIZ) do
|
||||
table.insert(exports.ALL_PORT_STATES, PORT_NAME_PREFIX .. id .. "_on")
|
||||
table.insert(exports.ALL_PORT_STATES, PORT_NAME_PREFIX .. id .. "_off")
|
||||
end
|
||||
table.insert(exports.all_port_states, port_name_prefix .. "py_off")
|
||||
table.insert(exports.all_port_states, port_name_prefix .. "ny_off")
|
||||
table.insert(exports.ALL_PORT_STATES, PORT_NAME_PREFIX .. "py_off")
|
||||
table.insert(exports.ALL_PORT_STATES, PORT_NAME_PREFIX .. "ny_off")
|
||||
|
||||
-- Maps a tube output direction parallel to exactly one axis to the best guess
|
||||
-- of the port ID.
|
||||
|
36
nodes.lua
36
nodes.lua
@ -20,10 +20,10 @@
|
||||
|
||||
local use = ...
|
||||
local S, null_func, merged_table, get_port_id_from_name,
|
||||
all_container_states, all_port_states, mesecon_state_on,
|
||||
ALL_CONTAINER_STATES, ALL_PORT_STATES, MESECON_STATE_ON,
|
||||
MCL_BLAST_RESISTANCE_INDESTRUCTIBLE = use("misc", {
|
||||
"translate", "null_func", "merged_table", "get_port_id_from_name",
|
||||
"all_container_states", "all_port_states", "mesecon_state_on",
|
||||
"ALL_CONTAINER_STATES", "ALL_PORT_STATES", "MESECON_STATE_ON",
|
||||
"MCL_BLAST_RESISTANCE_INDESTRUCTIBLE",
|
||||
})
|
||||
local settings = use("settings")
|
||||
@ -40,9 +40,9 @@ local container_pipeworks, port_pipeworks = use("pipeworks", {
|
||||
"container", "port",
|
||||
})
|
||||
|
||||
local mesecon_on_color = "#FCFF00"
|
||||
local mesecon_off_color = "#8A8C00"
|
||||
local digiline_color = "#4358C0"
|
||||
local MESECON_ON_COLOR = "#FCFF00"
|
||||
local MESECON_OFF_COLOR = "#8A8C00"
|
||||
local DIGILINE_COLOR = "#4358C0"
|
||||
|
||||
-- The mesecons namespace, or an empty table if it isn't available.
|
||||
local mesecon_maybe = minetest.global_exists("mesecon") and mesecon or {}
|
||||
@ -58,8 +58,8 @@ local function outer_wire_texture(color)
|
||||
end
|
||||
|
||||
local wall_base = {
|
||||
paramtype = settings.wall_light > 0 and "light" or "none",
|
||||
light_source = math.min(settings.wall_light, minetest.LIGHT_MAX),
|
||||
paramtype = settings.WALL_LIGHT > 0 and "light" or "none",
|
||||
light_source = math.min(settings.WALL_LIGHT, minetest.LIGHT_MAX),
|
||||
groups = {}, -- not_in_creative_inventory will be added.
|
||||
is_ground_content = false,
|
||||
diggable = false,
|
||||
@ -95,7 +95,7 @@ for i, id in ipairs(container_tile_ids) do
|
||||
container_tiles[i] = "area_containers_outer_port.png^" ..
|
||||
"area_containers_" .. id .. ".png"
|
||||
end
|
||||
-- The activations in parallel to all_container_states:
|
||||
-- The activations in parallel to ALL_CONTAINER_STATES:
|
||||
local container_activations = {
|
||||
{0, 0, 0, 0}, {0, 0, 0, 1}, {0, 0, 1, 0}, {0, 0, 1, 1},
|
||||
{0, 1, 0, 0}, {0, 1, 0, 1}, {0, 1, 1, 0}, {0, 1, 1, 1},
|
||||
@ -103,11 +103,11 @@ local container_activations = {
|
||||
{1, 1, 0, 0}, {1, 1, 0, 1}, {1, 1, 1, 0}, {1, 1, 1, 1},
|
||||
}
|
||||
-- Register all the container nodes:
|
||||
for i, name in ipairs(all_container_states) do
|
||||
for i, name in ipairs(ALL_CONTAINER_STATES) do
|
||||
local container_def = {
|
||||
description = S("Area Container"),
|
||||
tiles = table.copy(container_tiles),
|
||||
drop = all_container_states[1],
|
||||
drop = ALL_CONTAINER_STATES[1],
|
||||
groups = merged_table(container_pipeworks.groups, {cracky = 2}),
|
||||
on_construct = container_base.on_construct,
|
||||
after_place_node = container_after_place_node,
|
||||
@ -125,8 +125,8 @@ for i, name in ipairs(all_container_states) do
|
||||
if minetest.global_exists("mesecon") then
|
||||
local activation = container_activations[i]
|
||||
local wire_choices = {
|
||||
outer_wire_texture(mesecon_off_color),
|
||||
outer_wire_texture(mesecon_on_color),
|
||||
outer_wire_texture(MESECON_OFF_COLOR),
|
||||
outer_wire_texture(MESECON_ON_COLOR),
|
||||
}
|
||||
for j, active in ipairs(activation) do
|
||||
-- The tile corresponding to this bit:
|
||||
@ -152,7 +152,7 @@ for i, name in ipairs(all_container_states) do
|
||||
mesecon_maybe.register_mvps_stopper(name)
|
||||
end
|
||||
end
|
||||
minetest.register_alias("area_containers:container", all_container_states[1])
|
||||
minetest.register_alias("area_containers:container", ALL_CONTAINER_STATES[1])
|
||||
|
||||
register_wall("area_containers:wall", {
|
||||
description = S("Container Wall"),
|
||||
@ -167,7 +167,7 @@ register_wall("area_containers:exit", merged_table(exit_base, {
|
||||
local digiline_texture = "area_containers_wall.png"
|
||||
if minetest.global_exists("digiline") then
|
||||
digiline_texture = digiline_texture .. "^" ..
|
||||
wire_texture(digiline_color)
|
||||
wire_texture(DIGILINE_COLOR)
|
||||
end
|
||||
register_wall("area_containers:digiline", merged_table(digiline_base, {
|
||||
description = S("Container's Digiline Connection"),
|
||||
@ -175,7 +175,7 @@ register_wall("area_containers:digiline", merged_table(digiline_base, {
|
||||
}))
|
||||
|
||||
-- Register all port node variants:
|
||||
for _, name in ipairs(all_port_states) do
|
||||
for _, name in ipairs(ALL_PORT_STATES) do
|
||||
local port_mesecons = ports_mesecons[name]
|
||||
local full_def = merged_table(port_pipeworks, port_mesecons or {})
|
||||
full_def.description = S("Container's Mesecon/Tube Connection")
|
||||
@ -185,10 +185,10 @@ for _, name in ipairs(all_port_states) do
|
||||
local mesecons_spec = full_def.mesecons
|
||||
if mesecons_spec and mesecon_maybe.state then
|
||||
-- Register correct colors for mesecons-enabled ports:
|
||||
local color = mesecon_off_color
|
||||
local color = MESECON_OFF_COLOR
|
||||
if mesecons_spec and mesecons_spec.conductor and
|
||||
mesecons_spec.conductor.state == mesecon_state_on then
|
||||
color = mesecon_on_color
|
||||
mesecons_spec.conductor.state == MESECON_STATE_ON then
|
||||
color = MESECON_ON_COLOR
|
||||
end
|
||||
tile = tile .. "^" .. wire_texture(color)
|
||||
end
|
||||
|
@ -28,9 +28,9 @@
|
||||
]]
|
||||
|
||||
local use = ...
|
||||
local null_func, get_node_maybe_load, port_offsets, port_dirs,
|
||||
local null_func, get_node_maybe_load, PORT_OFFSETS, PORT_DIRS,
|
||||
get_port_id_from_direction, get_port_id_from_name = use("misc", {
|
||||
"null_func", "get_node_maybe_load", "port_offsets", "port_dirs",
|
||||
"null_func", "get_node_maybe_load", "PORT_OFFSETS", "PORT_DIRS",
|
||||
"get_port_id_from_direction", "get_port_id_from_name",
|
||||
})
|
||||
local get_related_container, get_related_inside = use("relation", {
|
||||
@ -85,7 +85,7 @@ function exports.container.tube.can_insert(_pos, node, _stack, dir)
|
||||
if node.param1 == 0 and node.param2 == 0 then return false end
|
||||
local inside_pos = get_related_inside(node.param1, node.param2)
|
||||
local port_id = get_port_id_from_direction(vector.multiply(dir, -1))
|
||||
local port_pos = vector.add(inside_pos, port_offsets[port_id])
|
||||
local port_pos = vector.add(inside_pos, PORT_OFFSETS[port_id])
|
||||
return can_insert(port_pos, vector.new(1, 0, 0))
|
||||
end
|
||||
|
||||
@ -93,7 +93,7 @@ function exports.container.tube.insert_object(_pos, node, stack, dir, owner)
|
||||
if node.param1 == 0 and node.param2 == 0 then return stack end
|
||||
local inside_pos = get_related_inside(node.param1, node.param2)
|
||||
local port_id = get_port_id_from_direction(vector.multiply(dir, -1))
|
||||
local port_pos = vector.add(inside_pos, port_offsets[port_id])
|
||||
local port_pos = vector.add(inside_pos, PORT_OFFSETS[port_id])
|
||||
pipeworks.tube_inject_item(port_pos, port_pos, vector.new(1, 0, 0),
|
||||
stack, owner)
|
||||
return ItemStack() -- All inserted.
|
||||
@ -114,14 +114,14 @@ function exports.port.tube.can_insert(_pos, node)
|
||||
local container_pos = get_related_container(node.param1, node.param2)
|
||||
if not container_pos then return false end
|
||||
local id = get_port_id_from_name(node.name)
|
||||
return can_insert(container_pos, port_dirs[id])
|
||||
return can_insert(container_pos, PORT_DIRS[id])
|
||||
end
|
||||
|
||||
function exports.port.tube.insert_object(_pos, node, stack, _dir, owner)
|
||||
local container_pos = get_related_container(node.param1, node.param2)
|
||||
if not container_pos then return stack end
|
||||
local id = get_port_id_from_name(node.name)
|
||||
pipeworks.tube_inject_item(container_pos, container_pos, port_dirs[id],
|
||||
pipeworks.tube_inject_item(container_pos, container_pos, PORT_DIRS[id],
|
||||
stack, owner)
|
||||
return ItemStack() -- All inserted.
|
||||
end
|
||||
|
@ -26,20 +26,20 @@
|
||||
|
||||
local use = ...
|
||||
local floor_blocksize = use("misc", {"floor_blocksize"})
|
||||
local inside_y_level, get_params_from_inside = use("relation", {
|
||||
"inside_y_level", "get_params_from_inside",
|
||||
local INSIDE_Y_LEVEL, get_params_from_inside = use("relation", {
|
||||
"INSIDE_Y_LEVEL", "get_params_from_inside",
|
||||
})
|
||||
|
||||
-- The minimum and maximum layers at which the protection applies.
|
||||
local min_applicable_y = inside_y_level - 16
|
||||
local max_applicable_y = inside_y_level + 16 + 15
|
||||
local MIN_APPLICABLE_Y = INSIDE_Y_LEVEL - 16
|
||||
local MAX_APPLICABLE_Y = INSIDE_Y_LEVEL + 16 + 15
|
||||
|
||||
-- Checks whether the position is protected only according to area_containers.
|
||||
-- See the overview for this file.
|
||||
local function is_area_containers_protected(pos)
|
||||
-- Check that the position is within the protected level:
|
||||
local y = pos.y
|
||||
if y >= min_applicable_y and y <= max_applicable_y then
|
||||
if y >= MIN_APPLICABLE_Y and y <= MAX_APPLICABLE_Y then
|
||||
-- The minimum position of the block containing pos:
|
||||
local block_min_pos = vector.apply(pos, floor_blocksize)
|
||||
if get_params_from_inside(block_min_pos) then
|
||||
|
24
relation.lua
24
relation.lua
@ -45,10 +45,10 @@ local exports = {}
|
||||
|
||||
-- The positioning settings should be multiples of 16.
|
||||
local DEFAULT_INSIDE_SPACING = 240
|
||||
local DEFAULT_Y_LEVEL = 16 * settings.y_level_blocks
|
||||
local DEFAULT_Y_LEVEL = 16 * settings.Y_LEVEL_BLOCKS
|
||||
local DEFAULT_X_BASE = -30608
|
||||
local DEFAULT_Z_BASE = -30608
|
||||
local MAX_CONTAINER_CACHE_SIZE = settings.max_cache_size
|
||||
local MAX_CONTAINER_CACHE_SIZE = settings.MAX_CACHE_SIZE
|
||||
|
||||
-- Check that the positioning settings are within bounds:
|
||||
local mod_setting_message =
|
||||
@ -137,7 +137,7 @@ function exports.get_params_from_inside(inside_pos)
|
||||
end
|
||||
|
||||
-- The actual Y-level (in nodes) of all inside positions (container bottoms.)
|
||||
exports.inside_y_level = Y_LEVEL
|
||||
exports.INSIDE_Y_LEVEL = Y_LEVEL
|
||||
|
||||
-- Gets the related container position. Returns nil if it isn't set.
|
||||
function exports.get_related_container(param1, param2)
|
||||
@ -171,15 +171,15 @@ end
|
||||
]]
|
||||
|
||||
-- Set up the bi-directional mapping between characters and segments of 6 bits:
|
||||
local seg2byte = {string.byte(
|
||||
local SEG2BYTE = {string.byte(
|
||||
"123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+-",
|
||||
1, -1
|
||||
)}
|
||||
assert(#seg2byte == 63)
|
||||
seg2byte[0] = string.byte("0") -- The indices must be [0-63]
|
||||
local byte2seg = {}
|
||||
assert(#SEG2BYTE == 63)
|
||||
SEG2BYTE[0] = string.byte("0") -- The indices must be [0-63]
|
||||
local BYTE2SEG = {}
|
||||
for i = 0, 63 do
|
||||
byte2seg[seg2byte[i]] = i
|
||||
BYTE2SEG[SEG2BYTE[i]] = i
|
||||
end
|
||||
|
||||
local PARAMS_STRING_LENGTH = 3
|
||||
@ -188,14 +188,14 @@ local function params_to_string(param1, param2)
|
||||
local seg1 = param1 % 64
|
||||
local seg2 = param2 % 64
|
||||
local seg3 = math.floor(param1 / 64) + math.floor(param2 / 64) * 4
|
||||
return string.char(seg2byte[seg1], seg2byte[seg2], seg2byte[seg3])
|
||||
return string.char(SEG2BYTE[seg1], SEG2BYTE[seg2], SEG2BYTE[seg3])
|
||||
end
|
||||
|
||||
local function string_to_params(str)
|
||||
local byte1, byte2, byte3 = string.byte(str, 1, 3)
|
||||
local seg1 = byte2seg[byte1]
|
||||
local seg2 = byte2seg[byte2]
|
||||
local seg3 = byte2seg[byte3]
|
||||
local seg1 = BYTE2SEG[byte1]
|
||||
local seg2 = BYTE2SEG[byte2]
|
||||
local seg3 = BYTE2SEG[byte3]
|
||||
local param1 = seg1 + (seg3 % 4) * 64
|
||||
local param2 = seg2 + math.floor(seg3 / 4) * 64
|
||||
return param1, param2
|
||||
|
@ -18,12 +18,12 @@
|
||||
]]
|
||||
|
||||
return {
|
||||
y_level_blocks = tonumber(minetest.settings:get(
|
||||
Y_LEVEL_BLOCKS = tonumber(minetest.settings:get(
|
||||
"area_containers_y_level_blocks") or 1931),
|
||||
enable_crafts = minetest.settings:get_bool(
|
||||
ENABLE_CRAFTS = minetest.settings:get_bool(
|
||||
"area_containers_enable_crafts", true),
|
||||
max_cache_size = tonumber(minetest.settings:get(
|
||||
MAX_CACHE_SIZE = tonumber(minetest.settings:get(
|
||||
"area_containers_max_cache_size") or 256),
|
||||
wall_light = tonumber(minetest.settings:get(
|
||||
WALL_LIGHT = tonumber(minetest.settings:get(
|
||||
"area_containers_wall_light") or 14),
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user