Add rail rendering (WIP)

This commit is contained in:
Nils Dagsson Moskopp 2022-05-22 23:07:20 +02:00
parent 4fa5c94515
commit 2c51da9c7d
Signed by: erle
GPG Key ID: A3BC671C35191080
1 changed files with 130 additions and 0 deletions

130
init.lua
View File

@ -113,6 +113,8 @@ xmaps.create_map_item = function(pos, properties)
{ 150, 105, 55 }, -- more liquid
{ 60, 35, 16 }, -- tree outline
{ 150, 105, 55 }, -- tree fill
{ 60, 35, 15 }, -- rail line
{ 60, 35, 15 }, -- rail line
}
for x = 1,size,1 do
for z = 1,size,1 do
@ -166,6 +168,126 @@ xmaps.create_map_item = function(pos, properties)
local image = tga_encoder.image(pixels)
local positions = minetest.find_nodes_in_area_under_air(
minp,
maxp,
"group:rail"
)
RAIL = 10
for _, p in ipairs(positions) do
local z = p.z - minp.z + 1
local x = p.x - minp.x + 1
pixels[z][x] = { RAIL }
end
-- thin out diagonal lines
for z = 1,#pixels do
for x = 1,#pixels[z] do
if (
RAIL == pixels[z][x][1] and
x < #pixels[z] -1 and
RAIL == pixels[z][x+1][1] and
not ( RAIL == pixels[z][x+2][1] )
) then
local color = 0 + ( ( x + z + 1 ) % 2 )
pixels[z][x+1] = { color }
end
if (
RAIL == pixels[z][x][1] and
z < #pixels - 1 and
RAIL == pixels[z+1][x][1] and
not ( RAIL == pixels[z+2][x][1] )
) then
local color = 0 + ( ( x + z + 1 ) % 2 )
pixels[z+1][x] = { color }
end
end
end
for _, p in ipairs(positions) do
local z = p.z - minp.z + 1
local x = p.x - minp.x + 1
local draw_rail = (
z > 1 and
z < size - 1 and
x > 1 and
x < size - 1
)
if draw_rail then
local _ = { nil } -- transparent
local R = { 11 } -- line
local rail
local node_sw = minetest.get_node({
x=p.x - 1,
y=p.y,
z=p.z - 1,
})
local node_se = minetest.get_node({
x=p.x - 1,
y=p.y,
z=p.z + 1,
})
local node_nw = minetest.get_node({
x=p.x + 1,
y=p.y,
z=p.z - 1,
})
local node_ne = minetest.get_node({
x=p.x + 1,
y=p.y,
z=p.z + 1,
})
if (
minetest.get_item_group(
node_sw.name,
"rail"
) > 0 or
minetest.get_item_group(
node_se.name,
"rail"
) > 0 or
minetest.get_item_group(
node_nw.name,
"rail"
) > 0 or
minetest.get_item_group(
node_ne.name,
"rail"
) > 0
) then
rail = {
{ R, _, R },
{ _, R, _ },
{ R, _, R },
}
else
rail = {
{ _, R, _ },
{ R, R, R },
{ _, R, _ },
}
end
if 0 == ( x + z ) % 4 then
rail = {}
end
assert( rail )
image:blit_icon(
rail,
{
x = x - 2,
z = z - 2,
},
{
[4] = true,
[5] = true,
[6] = true,
[7] = true,
[8] = true,
[9] = true,
[11] = true,
}
)
end
end
local positions = minetest.find_nodes_in_area(
minp,
maxp,
@ -207,6 +329,8 @@ xmaps.create_map_item = function(pos, properties)
[7] = true,
[8] = true,
[9] = true,
[10] = true,
[11] = true,
}
)
end
@ -279,6 +403,8 @@ xmaps.create_map_item = function(pos, properties)
[7] = true,
[8] = true,
[9] = true,
[10] = true,
[11] = true,
}
)
end
@ -321,6 +447,8 @@ xmaps.create_map_item = function(pos, properties)
[7] = true,
[8] = true,
[9] = true,
[10] = true,
[11] = true,
}
)
end
@ -362,6 +490,8 @@ xmaps.create_map_item = function(pos, properties)
[7] = true,
[8] = true,
[9] = true,
[10] = true,
[11] = true,
}
)
end