-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathinit.lua
115 lines (104 loc) · 3.28 KB
/
init.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
minetest.register_tool("mapp:map", {
description = "map",
inventory_image = "map_block.png",
on_use = function(itemstack, user, pointed_thing)
map_handler(itemstack,user,pointed_thing)
end,
})
function map_handler (itemstack, user, pointed_thing)
--Bechmark variables.
local clock = os.clock
local start = clock()
local pos = user:getpos()
local player_name=user:get_player_name()
local mapar = {}
local map
local p
local pp
local po = {x = 0, y = 0, z = 0}
local tile = ""
local yaw
local rotate = 0
pos.y = pos.y + 1
yaw = user:get_look_yaw()
if yaw ~= nil then
-- Find rotation and texture based on yaw.
yaw = math.deg(yaw)
yaw = math.fmod (yaw, 360)
if yaw < 90 then
rotate = 90
elseif yaw < 180 then
rotate = 180
elseif yaw < 270 then
rotate = 270
else
rotate = 0
end
yaw = math.fmod(yaw, 90)
yaw = math.floor(yaw / 10) * 10
end
--Localise some global minetest variables for speed.
local env = minetest.env
local registered_nodes = minetest.registered_nodes
for i = -17,17,1 do
mapar[i+17] = {}
for j = -17,17,1 do
mapar[i+17][j+17] = {}
po.x, po.y, po.z = pos.x+i, pos.y, pos.z+j
local no = env:get_node(po)
local k=po.y
if no.name == "air" then
while no.name == "air" do
k=k-1
po.x, po.y, po.z = pos.x+i, k, pos.z+j
no = env:get_node(po)
end
elseif no.name ~= "air" and (no.name ~= "ignore") then
while (no.name ~= "air") and (no.name ~= "ignore") do
k=k+1
po.x, po.y, po.z = pos.x+i, k, pos.z+j
no = env:get_node(po)
end
k=k-1
po.x, po.y, po.z = pos.x+i, k, pos.z+j
end
local node = env:get_node(po)
local tiles
local def = registered_nodes[node.name]
if def then tiles = def["tiles"] end
if tiles ~=nil then
tile = tiles[1]
end
if type(tile)=="table" then
tile=tile["name"]
end
mapar[i+17][j+17].y = k
mapar[i+17][j+17].im = tile
end
end
--Optimisation technique.
--Lua does not edit string buffers via concatenation, using a table and then invoking table.concat is MUCH faster.
p = {}
pp = #p
pp = pp + 1
p[pp] = "size[5.2,5]"
for i=1,32,1 do
for j=1,32,1 do
if mapar[i][j].y ~= mapar[i][j+1].y then mapar[i][j].im = mapar[i][j].im .. "^1black_blockt.png" end
if mapar[i][j].y ~= mapar[i][j-1].y then mapar[i][j].im = mapar[i][j].im .. "^1black_blockb.png" end
if mapar[i][j].y ~= mapar[i-1][j].y then mapar[i][j].im = mapar[i][j].im .. "^1black_blockl.png" end
if mapar[i][j].y ~= mapar[i+1][j].y then mapar[i][j].im = mapar[i][j].im .. "^1black_blockr.png" end
pp = pp + 1
p[pp] = "image[".. 0.15*(i) ..",".. 0.15*(32-j)+0.1 ..";0.2,0.2;" .. mapar[i][j].im .. "]"
end
end
pp = pp + 1
if rotate ~= 0 then
p[pp] = "image[".. 0.15*(16)+0.075 ..",".. 0.15*(16)-0.085 ..";0.4,0.4;d" .. yaw .. ".png^[transformFYR".. rotate .."]"
else
p[pp] = "image[".. 0.15*(16)+0.075 ..",".. 0.15*(16)-0.085 ..";0.4,0.4;d" .. yaw .. ".png^[transformFY]"
end
map = table.concat(p, "\n")
minetest.show_formspec(player_name, "mapp:map", map)
print("[Mapp] Map generated in: ".. clock() - start.." seconds.")
end