-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.lua
207 lines (178 loc) · 5.71 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
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
--------------------------------------------------------------- functions
-- adapted from http://stackoverflow.com/questions/16505905/walk-a-line-between-two-points-in-a-3d-voxel-space-visiting-all-cells
function drawLine(g0, g1, visitor)
local gx0idx = math.floor(g0.x);
local gy0idx = math.floor(g0.y);
local gz0idx = math.floor(g0.z);
local gx1idx = math.floor(g1.x);
local gy1idx = math.floor(g1.y);
local gz1idx = math.floor(g1.z);
local sx = gx1idx > gx0idx and 1 or (gx1idx < gx0idx and -1 or 0);
local sy = gy1idx > gy0idx and 1 or (gy1idx < gy0idx and -1 or 0);
local sz = gz1idx > gz0idx and 1 or (gz1idx < gz0idx and -1 or 0);
local gx = gx0idx;
local gy = gy0idx;
local gz = gz0idx;
--Planes for each axis that we will next cross
local gxp = gx0idx + (gx1idx > gx0idx and 1 or 0);
local gyp = gy0idx + (gy1idx > gy0idx and 1 or 0);
local gzp = gz0idx + (gz1idx > gz0idx and 1 or 0);
--Only used for multiplying up the error margins
local vx = g1.x == g0.x and 1 or g1.x - g0.x;
local vy = g1.y == g0.y and 1 or g1.y - g0.y;
local vz = g1.z == g0.z and 1 or g1.z - g0.z;
--Error is normalized to vx * vy * vz so we only have to multiply up
local vxvy = vx * vy;
local vxvz = vx * vz;
local vyvz = vy * vz;
--Error from the next plane accumulators, scaled up by vx*vy*vz
local errx = (gxp - g0.x) * vyvz;
local erry = (gyp - g0.y) * vxvz;
local errz = (gzp - g0.z) * vxvy;
local derrx = sx * vyvz;
local derry = sy * vxvz;
local derrz = sz * vxvy;
local testEscape = 100;
while (testEscape>0) do
testEscape = testEscape - 1;
visitor(gx, gy, gz);
if (gx == gx1idx and gy == gy1idx and gz == gz1idx) then break end
--Which plane do we cross first?
local xr = math.abs(errx);
local yr = math.abs(erry);
local zr = math.abs(errz);
if (sx ~= 0 and (sy == 0 or xr < yr) and (sz == 0 or xr < zr)) then
gx = gx+sx;
errx = errx+derrx;
elseif (sy ~= 0 and (sz == 0 or yr < zr)) then
gy = gy+sy;
erry = erry+derry;
elseif (sz ~= 0) then
gz = gz+sz;
errz = errz+derrz;
end
end --while
end --function
function drawMultiline(origin, vertices, drawfunction)
from = origin
for i, dest in ipairs(vertices) do
drawLine(from,dest , drawfunction)
from = dest
end
end--drawMultiline
function vertexCloud(minver, maxver, number)
n = number or 10
verts = {}
for i= 1, n do
table.insert(verts, {x=math.random(minver.x, maxver.x)
,y=math.random(minver.y, maxver.y)
,z=math.random(minver.z, maxver.z)
} )
end
return verts
end --vertexCloud
function drawRays(from, toverts, drawfunction)
for i,to in ipairs(toverts) do
drawLine(from, to, drawfunction)
end
end --drawRays
function drawBall( x, y, z, cid, radius, top, bottom)
top = top or 1.0
bottom = bottom or -1.0
local radiussquared = math.pow(radius, 2)
for xx = x-radius, x+radius do
for zz = z-radius, z+radius do
for yy = y+math.floor(radius*bottom), y+math.floor(radius*top) do
if ( math.pow(math.abs(x-xx), 2)
+ math.pow(math.abs(y-yy), 2)
+ math.pow(math.abs(z-zz), 2)) < radiussquared then
setXYZ( xx, yy, zz, cid)
end
end
end
end
end --drawBall
function createMultiline(position, minvertices, maxvertices, initspeed, maxspeed, maxdelta)
minvertices=minvertices or 4
maxvertices=maxvertices or 8
initspeed=initspeed or 4
maxspeed=maxspeed or 10
maxdelta=maxdelta or 2
vertices = {}
speedvec = { x=randomFloat(-initspeed,initspeed)
, y=randomFloat(-initspeed,initspeed)
, z=randomFloat(-initspeed,initspeed)}
for i = 1, math.random(minvertices,maxvertices) do
deltavec = { x=randomFloat(-maxdelta,maxdelta)
, y=randomFloat(-maxdelta,maxdelta)
, z=randomFloat(-maxdelta,maxdelta)}
position = vector.add(position, speedvec)
speedvec = vector.add(speedvec, deltavec)
speedvec = {x=math.min(maxspeed, math.max(-maxspeed, speedvec.x))
,y=math.min(maxspeed, math.max(-maxspeed, speedvec.y))
,z=math.min(maxspeed, math.max(-maxspeed, speedvec.z))
}
table.insert(vertices, position)
end
return vertices
end--createMultiline
local worldpath=minetest.get_worldpath()
local modpath = minetest.get_modpath(minetest.get_current_modname())
dofile(modpath.."/nodes.lua")
dofile(modpath.."/crafting.lua")
if minetest.setting_getbool("meatspace_override_mapgen") then
print("[meatspace] mapgen enabled")
dofile(modpath.."/mapgen.lua")
end
mobs:register_mob("meatspace:leucocyte", {
type = "monster",
collisionbox = {-0.3, -0.3, -0.3, 0.3, 0.3, 0.3},
hp_max = 12,
hp_min = 7,
visual = "mesh",
mesh = "leucocyte.x",
textures = {{"leucocyte.png","leucocyte.png", "meat.png^[colorize:#D4D:100"}},
fly = true,
fly_in = "meatspace:blood",
visual_size = {x=2, y=2},
makes_footstep_sound = false,
view_range = 13,
walk_velocity = 1,
reach =1.5,
run_velocity = 2,
damage = 2,
jump = false,
armor = 100,
drawtype = "front",
water_damage = 0,
fear_height = 5,
floats = 0,
lava_damage = 5,
light_damage = 0,
group_attack=true,
attack_animals=true,
knock_back=5,
blood_texture="meat.png",
on_rightclick = nil,
attack_type = "dogfight",
animation = {
speed_normal = 15,
speed_run = 25,
stand_start = 1,
stand_end = 100,
walk_start = 1,
walk_end = 100,
run_start = 1,
run_end = 100,
punch_start = 1,
punch_end = 100,
}
--pathfinding = 1,
})
mobs:spawn({
name = "meatspace:leucocyte",
nodes = {"meatspace:blood"},
interval = 1,
chance = 2,
})
print("[meatspace] done")