/
worldedge.lua
211 lines (168 loc) · 4.62 KB
/
worldedge.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
minetest.register_node("kalite:plastic_grass", {
description = "Plastic Grass",
tiles = {"default_grass.png"},
groups = {cracky=default.dig.cobble, soil=3}
})
-- Map Generation
local c_cloud = minetest.get_content_id("default:cloud")
local c_plastic_grass = minetest.get_content_id("kalite:plastic_grass")
--local c_air = minetest.get_content_id("air")
minetest.register_on_generated(function(minp, maxp, seed)
if maxp.y < 14400
or minp.y > 14401 then
return
end
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
local data = vm:get_data()
local area = VoxelArea:new{MinEdge = emin, MaxEdge = emax}
local x1 = maxp.x
local y1 = maxp.y
local z1 = maxp.z
local x0 = minp.x
local y0 = minp.y
local z0 = minp.z
for z = z0, z1 do
for x = x0, x1 do
--3
--[[
for vi in area:iter(x0, 14400, z0, x1, 14400, z1) do
data[vi] = c_cloud
end
for vi in area:iter(x0, 14401, z0, x1, 14401, z1) do
data[vi] = c_plastic_grass
end
--]]
--2
---[[
data[area:index(x, 14400, z)] = c_cloud
data[area:index(x, 14401, z)] = c_plastic_grass
--]]
--1
--[[
for y = y0, y1 do
local vi = area:index(x, y, z)
if y == 14400 then
data[vi] = c_cloud
elseif y == 14401 then
data[vi] = c_plastic_grass
else
data[vi] = c_air
end
end
--]]
end
end
vm:set_data(data)
vm:set_lighting({day = 0, night = 0})
vm:calc_lighting()
vm:write_to_map(data)
end)
-- Black sky in caves
-- Damage players trying to dig to the bottom
-- TODO Damage players at world's edge. Possibly
-- teleport to the other side. Shouldn't have
-- to worry about the top, but put that in there
-- for completeness.
local dur = 0
minetest.register_globalstep(function(dtime)
dur = dur + dtime
if dur > 2 then
for _, player in pairs(minetest.get_connected_players()) do --ipairs
local pos = player:getpos()
if pos.y < -29999 then
if player ~= nil and player:get_hp() > 0.1 then
local player_hp = player:get_hp()
player:set_hp(player_hp - 1)
dur = 0
end
end
if pos.y < -60 then
player:set_sky("black", "plain", {})
end
if pos.y >= -60 then
player:set_sky({}, "regular", {})
end
end
end
end)
-- The following is a part of PlayerPlus by TenPlus1
--[[
local function node_ok(pos, fallback)
fallback = fallback or "air"
local node = minetest.get_node_or_nil(pos)
if not node then
return fallback
end
if minetest.registered_nodes[node.name] then
return node.name
end
return fallback
end
local pp = {}
local def = {}
local time = 0
minetest.register_globalstep(function(dtime)
time = time + dtime
-- every 1 second
if time < 1 then
return
end
-- reset time for next check
time = 0
-- check players
for _,player in pairs(minetest.get_connected_players()) do
-- where am I?
local pos = player:getpos()
-- what is around me?
pos.y = pos.y - 0.1 -- standing on
local nod_stand = node_ok(pos)
pos.y = pos.y + 1.5 -- head level
local nod_head = node_ok(pos)
pos.y = pos.y - 1.2 -- feet level
local nod_feet = node_ok(pos)
pos.y = pos.y - 0.2 -- reset pos
-- is 3d_armor mod active? if so make armor physics default
if minetest.get_modpath("3d_armor") then
def = armor.def[player:get_player_name()] or {}
end
-- set to armor physics or defaults
pp.speed = def.speed or 1
pp.jump = def.jump or 1
pp.gravity = def.gravity or 1
-- standing on ice? if so walk faster
if nod_stand == "default:ice" then
pp.speed = pp.speed + 0.4
end
-- standing on snow? if so walk slower
if nod_stand == "default:snow"
or nod_stand == "default:snowblock"
-- wading in water? if so walk slower
or minetest.registered_nodes[nod_feet].groups.water then
pp.speed = pp.speed - 0.4
end
-- set player physics
player:set_physics_override(pp.speed, pp.jump, pp.gravity)
--print ("Speed:", pp.speed, "Jump:", pp.jump, "Gravity:", pp.gravity)
-- is player suffocating inside node? (only solid "normal" type nodes)
if minetest.registered_nodes[nod_head].walkable
and minetest.registered_nodes[nod_head].drawtype == "normal"
and not minetest.check_player_privs(player:get_player_name(), {noclip = true}) then
-- While I see why this is here, I think
-- Consider using get_air instead, if available.
if player:get_hp() > 0 then
player:set_hp(player:get_hp() - 2)
end
end
-- am I near a cactus?
local near = minetest.find_node_near(pos, 1, "default:cactus")
if near then
-- am I touching the cactus? if so it hurts
for _,object in pairs(minetest.get_objects_inside_radius(near, 1.1)) do
if object:get_hp() > 0 then
object:set_hp(object:get_hp() - 2)
end
end
end
end
end)
--]]