mirror of
https://codeberg.org/minenux/minetest-mod-xdecor
synced 2023-10-20 21:43:39 -07:00
Optimize some loops
This commit is contained in:
parent
30b377c052
commit
d4979519a7
@ -34,7 +34,8 @@ function enchanting.fields(pos, formname, fields, sender)
|
||||
local mese = mesestack:get_count()
|
||||
local enchs = {"durable", "fast"}
|
||||
|
||||
for _, e in pairs(enchs) do
|
||||
for i = 1, #enchs do
|
||||
local e = enchs[i]
|
||||
if enchanting.is_allowed_tool(toolname) ~= 0 and mese > 0 and fields[e] then
|
||||
toolstack:replace("xdecor:enchanted_"..toolname:sub(9).."_"..e)
|
||||
toolstack:add_wear(toolwear)
|
||||
@ -103,7 +104,8 @@ function enchanting.register_enchtools(init, m, def)
|
||||
{"pick", "durable", {cracky = long}}, {"pick", "fast", {cracky = fast}},
|
||||
{"shovel", "durable", {crumbly = long}}, {"shovel", "fast", {crumbly = fast}}
|
||||
}
|
||||
for _, x in pairs(enchtools) do
|
||||
for i = 1, #enchtools do
|
||||
local x = enchtools[i]
|
||||
local t, e, g = x[1], x[2], x[3]
|
||||
minetest.register_tool("xdecor:enchanted_"..t.."_"..m.."_"..e, {
|
||||
description = "Enchanted "..m:gsub("%l", string.upper, 1).." "..
|
||||
@ -120,11 +122,11 @@ local tools = {
|
||||
}
|
||||
local materials = {"steel", "bronze", "mese", "diamond"}
|
||||
|
||||
for _, t in pairs(tools) do
|
||||
for _, material in pairs(materials) do
|
||||
local tool, group = t[1], t[2]
|
||||
local toolname = tool.."_"..material
|
||||
local init_def = minetest.registered_tools["default:"..toolname].tool_capabilities.groupcaps[group]
|
||||
for i = 1, #tools do
|
||||
for j = 1, #materials do
|
||||
local t, m = tools[i], materials[j]
|
||||
local toolname = t[1].."_"..m
|
||||
local init_def = minetest.registered_tools["default:"..toolname].tool_capabilities.groupcaps[t[2]]
|
||||
|
||||
local tooldef = {
|
||||
times = init_def.times,
|
||||
@ -132,6 +134,6 @@ for _, material in pairs(materials) do
|
||||
dmg = init_def.damage_groups,
|
||||
maxlvl = init_def.maxlevel
|
||||
}
|
||||
enchanting.register_enchtools(init_def, material, tooldef)
|
||||
enchanting.register_enchtools(init_def, m, tooldef)
|
||||
end
|
||||
end
|
||||
|
@ -28,7 +28,7 @@ function worktable.construct(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
|
||||
local nodebtn = {}
|
||||
for i=1, #def do
|
||||
for i = 1, #def do
|
||||
nodebtn[#nodebtn+1] = "item_image_button["..(i-1)..
|
||||
",0.5;1,1;xdecor:"..def[i][1].."_cloud;"..def[i][1]..";]"
|
||||
end
|
||||
@ -63,11 +63,12 @@ function worktable.fields(pos, formname, fields, sender)
|
||||
local shape, get, outputshape = {}, {}, {}
|
||||
local anz = 0
|
||||
|
||||
for _, d in pairs(def) do
|
||||
for i = 1, #def do
|
||||
local d = def[i]
|
||||
local nb, anz = d[1], d[2]
|
||||
if outputcount < 99 and fields[nb] then
|
||||
outputshape = outputname:match(nb)
|
||||
if nb ~= outputshape and outputcount > 0 then return end
|
||||
if nb ~= outputshape and outputcount > 0 then break end
|
||||
shape = "xdecor:"..nb.."_"..inputname:sub(9)
|
||||
get = shape.." "..anz
|
||||
|
||||
@ -133,38 +134,38 @@ xdecor.register("worktable", {
|
||||
allow_metadata_inventory_move = worktable.move
|
||||
})
|
||||
|
||||
for _, m in pairs(material) do
|
||||
for n=1, #def do
|
||||
local w = def[n]
|
||||
local nodename = "default:"..m
|
||||
local function description(m, w)
|
||||
if m == "cloud" then return "" end
|
||||
return m:gsub("%l", string.upper, 1).." "..w:gsub("%l", string.upper, 1)
|
||||
end
|
||||
|
||||
local function groups(m)
|
||||
if m:find("tree") or m:find("wood") or m == "cactus" then
|
||||
return {choppy=3, not_in_creative_inventory=1}
|
||||
elseif m == "clay" or m == "snowblock" then
|
||||
return {snappy=3, not_in_creative_inventory=1}
|
||||
end
|
||||
return {cracky=3, not_in_creative_inventory=1}
|
||||
end
|
||||
|
||||
local function shady(w)
|
||||
if w:find("stair") or w == "slab" then return false end
|
||||
return true
|
||||
end
|
||||
|
||||
for n = 1, #def do
|
||||
for m = 1, #material do
|
||||
local w, x = def[n], material[m]
|
||||
local nodename = "default:"..x
|
||||
local ndef = minetest.registered_nodes[nodename]
|
||||
if not ndef then return end
|
||||
if not ndef then break end
|
||||
|
||||
local function description(m)
|
||||
if m == "cloud" then return "" end
|
||||
return m:gsub("%l", string.upper, 1).." "..w[1]:gsub("%l", string.upper, 1)
|
||||
end
|
||||
|
||||
local function groups(m)
|
||||
if m:find("tree") or m:find("wood") or m == "cactus" then
|
||||
return {choppy=3, not_in_creative_inventory=1}
|
||||
elseif m == "clay" or m == "snowblock" then
|
||||
return {snappy=3, not_in_creative_inventory=1}
|
||||
end
|
||||
return {cracky=3, not_in_creative_inventory=1}
|
||||
end
|
||||
|
||||
local function shady(w)
|
||||
if w:find("stair") or w == "slab" then return false end
|
||||
return true
|
||||
end
|
||||
|
||||
xdecor.register(w[1].."_"..m, {
|
||||
description = description(m),
|
||||
xdecor.register(w[1].."_"..x, {
|
||||
description = description(x, w[1]),
|
||||
light_source = ndef.light_source,
|
||||
sounds = ndef.sounds,
|
||||
tiles = ndef.tiles,
|
||||
groups = groups(m),
|
||||
groups = groups(x),
|
||||
node_box = {type = "fixed", fixed = w[3]},
|
||||
sunlight_propagates = shady(w[1]),
|
||||
on_place = minetest.rotate_node
|
||||
|
22
xwall.lua
22
xwall.lua
@ -12,7 +12,8 @@ local profiles = {
|
||||
{11, "_c3", 0}, {13, "_c3", 1}, {14, "_c3", 2}, {15, "_c4", 1}
|
||||
}
|
||||
|
||||
for _, p in pairs(profiles) do
|
||||
for i = 1, #profiles do
|
||||
local p = profiles[i]
|
||||
local p1, p2, p3 = p[1], p[2], p[3]
|
||||
xwall.get_candidate[p1] = {p2, p3}
|
||||
end
|
||||
@ -124,7 +125,8 @@ function xwall.construct_node_box_data(node_box_list, center_node_box_list, node
|
||||
res.c0, res.c1, res.c2, res.c3, res.c4 = {}, {}, {}, {}, {}
|
||||
local pos0, pos1, pos2, pos3, pos4 = #res.c0, #res.c1, #res.c2, #res.c3, #res.c4
|
||||
|
||||
for _, v in pairs(node_box_list) do
|
||||
for i = 1, #node_box_list do
|
||||
local v = node_box_list[i]
|
||||
pos1 = pos1 + 1
|
||||
pos2 = pos2 + 1
|
||||
pos3 = pos3 + 1
|
||||
@ -135,7 +137,8 @@ function xwall.construct_node_box_data(node_box_list, center_node_box_list, node
|
||||
res.c4[pos4] = v
|
||||
end
|
||||
|
||||
for _, v in pairs(node_box_list) do
|
||||
for i = 1, #node_box_list do
|
||||
local v = node_box_list[i]
|
||||
pos2 = pos2 + 1
|
||||
pos3 = pos3 + 1
|
||||
pos4 = pos4 + 1
|
||||
@ -144,19 +147,22 @@ function xwall.construct_node_box_data(node_box_list, center_node_box_list, node
|
||||
res.c4[pos4] = {v[3], v[2], v[1], v[6], v[5], v[4]}
|
||||
end
|
||||
|
||||
for _, v in pairs(node_box_list) do
|
||||
for i = 1, #node_box_list do
|
||||
local v = node_box_list[i]
|
||||
pos3 = pos3 + 1
|
||||
pos4 = pos4 + 1
|
||||
res.c3[pos3] = {v[4], v[2], v[3]-.5, v[1], v[5], v[6]-.5}
|
||||
res.c4[pos4] = {v[4], v[2], v[3]-.5, v[1], v[5], v[6]-.5}
|
||||
end
|
||||
|
||||
for _, v in pairs(node_box_list) do
|
||||
for i = 1, #node_box_list do
|
||||
local v = node_box_list[i]
|
||||
pos4 = pos4 + 1
|
||||
res.c4[pos4] = {v[3]-.5, v[2], v[4], v[6]-.5, v[5], v[1]}
|
||||
end
|
||||
|
||||
for _, v in pairs(center_node_box_list) do
|
||||
for i = 1, #center_node_box_list do
|
||||
local v = center_node_box_list[i]
|
||||
pos0 = pos0 + 1
|
||||
pos1 = pos1 + 1
|
||||
pos2 = pos2 + 1
|
||||
@ -169,9 +175,7 @@ function xwall.construct_node_box_data(node_box_list, center_node_box_list, node
|
||||
res.c4[pos4] = v
|
||||
end
|
||||
|
||||
if #res.c0 < 1 then
|
||||
res.c0 = nil
|
||||
end
|
||||
if #res.c0 < 1 then res.c0 = nil end
|
||||
|
||||
res.ln = node_box_line
|
||||
return res
|
||||
|
Loading…
x
Reference in New Issue
Block a user