reduce texturename repetition via __index
This commit is contained in:
parent
4dc3f159c9
commit
810ae99008
@ -153,15 +153,8 @@ local function on_output_change(pos, inventory, stack)
|
||||
if not input.items or input.type ~= "normal" then return end
|
||||
local items, width = normalize(input.items), input.width
|
||||
local item_idx, width_idx = 1, 1
|
||||
for i = 1, 9 do
|
||||
if width_idx <= width then
|
||||
inventory:set_stack("recipe", i, items[item_idx])
|
||||
item_idx = item_idx + 1
|
||||
else
|
||||
inventory:set_stack("recipe", i, ItemStack(""))
|
||||
end
|
||||
width_idx = (width_idx < 3) and (width_idx + 1) or 1
|
||||
end
|
||||
inventory:set_width("recipe", 3)
|
||||
inventory:set_list("recipe", items)
|
||||
-- we'll set the output slot in after_recipe_change to the actual result of the new recipe
|
||||
end
|
||||
after_recipe_change(pos, inventory)
|
||||
|
@ -10,12 +10,9 @@ minetest.register_craft( {
|
||||
})
|
||||
|
||||
if pipeworks.enable_accelerator_tube then
|
||||
local accelerator_noctr_textures = {"pipeworks_accelerator_tube_noctr.png", "pipeworks_accelerator_tube_noctr.png", "pipeworks_accelerator_tube_noctr.png",
|
||||
"pipeworks_accelerator_tube_noctr.png", "pipeworks_accelerator_tube_noctr.png", "pipeworks_accelerator_tube_noctr.png"}
|
||||
local accelerator_plain_textures = {"pipeworks_accelerator_tube_plain.png" ,"pipeworks_accelerator_tube_plain.png", "pipeworks_accelerator_tube_plain.png",
|
||||
"pipeworks_accelerator_tube_plain.png", "pipeworks_accelerator_tube_plain.png", "pipeworks_accelerator_tube_plain.png"}
|
||||
local accelerator_end_textures = {"pipeworks_accelerator_tube_end.png", "pipeworks_accelerator_tube_end.png", "pipeworks_accelerator_tube_end.png",
|
||||
"pipeworks_accelerator_tube_end.png", "pipeworks_accelerator_tube_end.png", "pipeworks_accelerator_tube_end.png"}
|
||||
local accelerator_noctr_textures = { "pipeworks_accelerator_tube_noctr.png" }
|
||||
local accelerator_plain_textures = { "pipeworks_accelerator_tube_plain.png" }
|
||||
local accelerator_end_textures = { "pipeworks_accelerator_tube_end.png" }
|
||||
local accelerator_short_texture = "pipeworks_accelerator_tube_short.png"
|
||||
local accelerator_inv_texture = "pipeworks_accelerator_tube_inv.png"
|
||||
|
||||
@ -39,12 +36,9 @@ if pipeworks.enable_accelerator_tube then
|
||||
end
|
||||
|
||||
if pipeworks.enable_crossing_tube then
|
||||
local crossing_noctr_textures = {"pipeworks_crossing_tube_noctr.png", "pipeworks_crossing_tube_noctr.png", "pipeworks_crossing_tube_noctr.png",
|
||||
"pipeworks_crossing_tube_noctr.png", "pipeworks_crossing_tube_noctr.png", "pipeworks_crossing_tube_noctr.png"}
|
||||
local crossing_plain_textures = {"pipeworks_crossing_tube_plain.png" ,"pipeworks_crossing_tube_plain.png", "pipeworks_crossing_tube_plain.png",
|
||||
"pipeworks_crossing_tube_plain.png", "pipeworks_crossing_tube_plain.png", "pipeworks_crossing_tube_plain.png"}
|
||||
local crossing_end_textures = {"pipeworks_crossing_tube_end.png", "pipeworks_crossing_tube_end.png", "pipeworks_crossing_tube_end.png",
|
||||
"pipeworks_crossing_tube_end.png", "pipeworks_crossing_tube_end.png", "pipeworks_crossing_tube_end.png"}
|
||||
local crossing_noctr_textures = { "pipeworks_crossing_tube_noctr.png" }
|
||||
local crossing_plain_textures = { "pipeworks_crossing_tube_plain.png" }
|
||||
local crossing_end_textures = { "pipeworks_crossing_tube_end.png" }
|
||||
local crossing_short_texture = "pipeworks_crossing_tube_short.png"
|
||||
local crossing_inv_texture = "pipeworks_crossing_tube_inv.png"
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
if pipeworks.enable_detector_tube then
|
||||
local detector_plain_textures = {"pipeworks_detector_tube_plain.png", "pipeworks_detector_tube_plain.png", "pipeworks_detector_tube_plain.png",
|
||||
"pipeworks_detector_tube_plain.png", "pipeworks_detector_tube_plain.png", "pipeworks_detector_tube_plain.png"}
|
||||
local detector_plain_textures = { "pipeworks_detector_tube_plain.png" }
|
||||
local detector_inv_texture = "pipeworks_detector_tube_inv.png"
|
||||
local detector_tube_step = 2 * tonumber(minetest.setting_get("dedicated_server_step"))
|
||||
pipeworks.register_tube("pipeworks:detector_tube_on", "Detecting Pneumatic Tube Segment on (you hacker you)",
|
||||
@ -65,21 +64,15 @@ if pipeworks.enable_detector_tube then
|
||||
end
|
||||
|
||||
if pipeworks.enable_conductor_tube then
|
||||
local conductor_plain_textures = {"pipeworks_conductor_tube_plain.png", "pipeworks_conductor_tube_plain.png", "pipeworks_conductor_tube_plain.png",
|
||||
"pipeworks_conductor_tube_plain.png", "pipeworks_conductor_tube_plain.png", "pipeworks_conductor_tube_plain.png"}
|
||||
local conductor_noctr_textures = {"pipeworks_conductor_tube_noctr.png", "pipeworks_conductor_tube_noctr.png", "pipeworks_conductor_tube_noctr.png",
|
||||
"pipeworks_conductor_tube_noctr.png", "pipeworks_conductor_tube_noctr.png", "pipeworks_conductor_tube_noctr.png"}
|
||||
local conductor_end_textures = {"pipeworks_conductor_tube_end.png", "pipeworks_conductor_tube_end.png", "pipeworks_conductor_tube_end.png",
|
||||
"pipeworks_conductor_tube_end.png", "pipeworks_conductor_tube_end.png", "pipeworks_conductor_tube_end.png"}
|
||||
local conductor_plain_textures = { "pipeworks_conductor_tube_plain.png" }
|
||||
local conductor_noctr_textures = { "pipeworks_conductor_tube_noctr.png" }
|
||||
local conductor_end_textures = { "pipeworks_conductor_tube_end.png" }
|
||||
local conductor_short_texture = "pipeworks_conductor_tube_short.png"
|
||||
local conductor_inv_texture = "pipeworks_conductor_tube_inv.png"
|
||||
|
||||
local conductor_on_plain_textures = {"pipeworks_conductor_tube_on_plain.png", "pipeworks_conductor_tube_on_plain.png", "pipeworks_conductor_tube_on_plain.png",
|
||||
"pipeworks_conductor_tube_on_plain.png", "pipeworks_conductor_tube_on_plain.png", "pipeworks_conductor_tube_on_plain.png"}
|
||||
local conductor_on_noctr_textures = {"pipeworks_conductor_tube_on_noctr.png", "pipeworks_conductor_tube_on_noctr.png", "pipeworks_conductor_tube_on_noctr.png",
|
||||
"pipeworks_conductor_tube_on_noctr.png", "pipeworks_conductor_tube_on_noctr.png", "pipeworks_conductor_tube_on_noctr.png"}
|
||||
local conductor_on_end_textures = {"pipeworks_conductor_tube_on_end.png", "pipeworks_conductor_tube_on_end.png", "pipeworks_conductor_tube_on_end.png",
|
||||
"pipeworks_conductor_tube_on_end.png", "pipeworks_conductor_tube_on_end.png", "pipeworks_conductor_tube_on_end.png"}
|
||||
local conductor_on_plain_textures = { "pipeworks_conductor_tube_on_plain.png" }
|
||||
local conductor_on_noctr_textures = { "pipeworks_conductor_tube_on_noctr.png" }
|
||||
local conductor_on_end_textures = { "pipeworks_conductor_tube_on_end.png" }
|
||||
|
||||
pipeworks.register_tube("pipeworks:conductor_tube_off", "Conducting Pneumatic Tube Segment", conductor_plain_textures, conductor_noctr_textures,
|
||||
conductor_end_textures, conductor_short_texture, conductor_inv_texture,
|
||||
|
@ -3,8 +3,7 @@ if pipeworks.enable_mese_tube then
|
||||
"pipeworks_mese_tube_noctr_4.png", "pipeworks_mese_tube_noctr_5.png", "pipeworks_mese_tube_noctr_6.png"}
|
||||
local mese_plain_textures = {"pipeworks_mese_tube_plain_1.png", "pipeworks_mese_tube_plain_2.png", "pipeworks_mese_tube_plain_3.png",
|
||||
"pipeworks_mese_tube_plain_4.png", "pipeworks_mese_tube_plain_5.png", "pipeworks_mese_tube_plain_6.png"}
|
||||
local mese_end_textures = {"pipeworks_mese_tube_end.png", "pipeworks_mese_tube_end.png", "pipeworks_mese_tube_end.png",
|
||||
"pipeworks_mese_tube_end.png", "pipeworks_mese_tube_end.png", "pipeworks_mese_tube_end.png"}
|
||||
local mese_end_textures = { "pipeworks_mese_tube_end.png" }
|
||||
local mese_short_texture = "pipeworks_mese_tube_short.png"
|
||||
local mese_inv_texture = "pipeworks_mese_tube_inv.png"
|
||||
local function update_formspec(pos)
|
||||
|
@ -105,12 +105,9 @@ local function get_receivers(pos, channel)
|
||||
return receivers
|
||||
end
|
||||
|
||||
local teleport_noctr_textures={"pipeworks_teleport_tube_noctr.png","pipeworks_teleport_tube_noctr.png","pipeworks_teleport_tube_noctr.png",
|
||||
"pipeworks_teleport_tube_noctr.png","pipeworks_teleport_tube_noctr.png","pipeworks_teleport_tube_noctr.png"}
|
||||
local teleport_plain_textures={"pipeworks_teleport_tube_plain.png","pipeworks_teleport_tube_plain.png","pipeworks_teleport_tube_plain.png",
|
||||
"pipeworks_teleport_tube_plain.png","pipeworks_teleport_tube_plain.png","pipeworks_teleport_tube_plain.png"}
|
||||
local teleport_end_textures={"pipeworks_teleport_tube_end.png","pipeworks_teleport_tube_end.png","pipeworks_teleport_tube_end.png",
|
||||
"pipeworks_teleport_tube_end.png","pipeworks_teleport_tube_end.png","pipeworks_teleport_tube_end.png"}
|
||||
local teleport_noctr_textures={ "pipeworks_teleport_tube_noctr.png" }
|
||||
local teleport_plain_textures={ "pipeworks_teleport_tube_plain.png" }
|
||||
local teleport_end_textures={ "pipeworks_teleport_tube_end.png" }
|
||||
local teleport_short_texture="pipeworks_teleport_tube_short.png"
|
||||
local teleport_inv_texture="pipeworks_teleport_tube_inv.png"
|
||||
|
||||
|
@ -11,20 +11,30 @@ local REGISTER_COMPATIBILITY = true
|
||||
local vti = {4, 3, 2, 1, 6, 5}
|
||||
|
||||
local default_textures = {
|
||||
noctrs = { "pipeworks_tube_noctr.png", "pipeworks_tube_noctr.png", "pipeworks_tube_noctr.png",
|
||||
"pipeworks_tube_noctr.png", "pipeworks_tube_noctr.png", "pipeworks_tube_noctr.png"},
|
||||
plain = { "pipeworks_tube_plain.png", "pipeworks_tube_plain.png", "pipeworks_tube_plain.png",
|
||||
"pipeworks_tube_plain.png", "pipeworks_tube_plain.png", "pipeworks_tube_plain.png"},
|
||||
ends = { "pipeworks_tube_end.png", "pipeworks_tube_end.png", "pipeworks_tube_end.png",
|
||||
"pipeworks_tube_end.png", "pipeworks_tube_end.png", "pipeworks_tube_end.png"},
|
||||
noctrs = { "pipeworks_tube_noctr.png" },
|
||||
plain = { "pipeworks_tube_plain.png" },
|
||||
ends = { "pipeworks_tube_end.png" },
|
||||
short = "pipeworks_tube_short.png",
|
||||
inv = "pipeworks_tube_inv.png",
|
||||
}
|
||||
|
||||
local texture_mt = {
|
||||
__index = function(table, key)
|
||||
local size, idx = #table, tonumber(key)
|
||||
if size > 0 then -- avoid endless loops with empty tables
|
||||
while idx > size do idx = idx - size end
|
||||
return table[idx]
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
local register_one_tube = function(name, tname, dropname, desc, plain, noctrs, ends, short, inv, special, connects, style)
|
||||
noctrs = noctrs or default_textures.noctrs
|
||||
setmetatable(noctrs, texture_mt)
|
||||
plain = plain or default_textures.plain
|
||||
setmetatable(plain, texture_mt)
|
||||
ends = ends or default_textures.ends
|
||||
setmetatable(ends, texture_mt)
|
||||
short = short or default_textures.short
|
||||
inv = inv or default_textures.inv
|
||||
|
||||
|
@ -1,10 +1,7 @@
|
||||
if pipeworks.enable_sand_tube then
|
||||
local sand_noctr_textures = {"pipeworks_sand_tube_noctr.png", "pipeworks_sand_tube_noctr.png", "pipeworks_sand_tube_noctr.png",
|
||||
"pipeworks_sand_tube_noctr.png", "pipeworks_sand_tube_noctr.png", "pipeworks_sand_tube_noctr.png"}
|
||||
local sand_plain_textures = {"pipeworks_sand_tube_plain.png", "pipeworks_sand_tube_plain.png", "pipeworks_sand_tube_plain.png",
|
||||
"pipeworks_sand_tube_plain.png", "pipeworks_sand_tube_plain.png", "pipeworks_sand_tube_plain.png"}
|
||||
local sand_end_textures = {"pipeworks_sand_tube_end.png", "pipeworks_sand_tube_end.png", "pipeworks_sand_tube_end.png",
|
||||
"pipeworks_sand_tube_end.png", "pipeworks_sand_tube_end.png", "pipeworks_sand_tube_end.png"}
|
||||
local sand_noctr_textures = { "pipeworks_sand_tube_noctr.png" }
|
||||
local sand_plain_textures = { "pipeworks_sand_tube_plain.png" }
|
||||
local sand_end_textures = { "pipeworks_sand_tube_end.png" }
|
||||
local sand_short_texture = "pipeworks_sand_tube_short.png"
|
||||
local sand_inv_texture = "pipeworks_sand_tube_inv.png"
|
||||
|
||||
@ -39,12 +36,9 @@ if pipeworks.enable_sand_tube then
|
||||
end
|
||||
|
||||
if pipeworks.enable_mese_sand_tube then
|
||||
local mese_sand_noctr_textures = {"pipeworks_mese_sand_tube_noctr.png", "pipeworks_mese_sand_tube_noctr.png", "pipeworks_mese_sand_tube_noctr.png",
|
||||
"pipeworks_mese_sand_tube_noctr.png", "pipeworks_mese_sand_tube_noctr.png", "pipeworks_mese_sand_tube_noctr.png"}
|
||||
local mese_sand_plain_textures = {"pipeworks_mese_sand_tube_plain.png", "pipeworks_mese_sand_tube_plain.png", "pipeworks_mese_sand_tube_plain.png",
|
||||
"pipeworks_mese_sand_tube_plain.png", "pipeworks_mese_sand_tube_plain.png", "pipeworks_mese_sand_tube_plain.png"}
|
||||
local mese_sand_end_textures = {"pipeworks_mese_sand_tube_end.png", "pipeworks_mese_sand_tube_end.png", "pipeworks_mese_sand_tube_end.png",
|
||||
"pipeworks_mese_sand_tube_end.png", "pipeworks_mese_sand_tube_end.png", "pipeworks_mese_sand_tube_end.png"}
|
||||
local mese_sand_noctr_textures = { "pipeworks_mese_sand_tube_noctr.png" }
|
||||
local mese_sand_plain_textures = { "pipeworks_mese_sand_tube_plain.png" }
|
||||
local mese_sand_end_textures = { "pipeworks_mese_sand_tube_end.png" }
|
||||
local mese_sand_short_texture = "pipeworks_mese_sand_tube_short.png"
|
||||
local mese_sand_inv_texture = "pipeworks_mese_sand_tube_inv.png"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user