add vector_line.lua
This commit is contained in:
parent
33bf0b6c6b
commit
1bc80e0fdd
15
init.lua
15
init.lua
@ -326,11 +326,11 @@ local function ore(name, scarcity, num_ores, size, min, max)
|
||||
end
|
||||
ore("lapis_lazuli_ore", 10*10*10, 3, 10, -150, -80)
|
||||
ore("lapis_lazuli_ore", 7*7*7, 3, 10, -300, -150)
|
||||
ore("goldstone", 11*11*11, 4, 11, -1000, -450)
|
||||
ore("goldstone", 8*8*8, 4, 11, -31000, -1000)
|
||||
ore("iringnite_ore", 40*40*40, 4, 11, -2000, -1000)
|
||||
ore("iringnite_ore", 20*20*20, 4, 11, -3000, -2000)
|
||||
ore("iringnite_ore", 11*11*11, 4, 11, -31000, -3000)
|
||||
ore("goldstone", 11*11*11, 4, 11, -2000, -1000)
|
||||
ore("goldstone", 8*8*8, 4, 11, -31000, -2000)
|
||||
ore("iringnite_ore", 40*40*40, 4, 11, -4000, -3000)
|
||||
ore("iringnite_ore", 20*20*20, 4, 11, -5000, -4000)
|
||||
ore("iringnite_ore", 11*11*11, 4, 11, -31000, -5000)
|
||||
minetest.register_ore({
|
||||
ore_type = "sheet",
|
||||
ore = "extrablocks:marble_ore",
|
||||
@ -355,8 +355,8 @@ minetest.register_ore({
|
||||
ore = "extrablocks:fokni_gneb_ore",
|
||||
wherein = "default:stone",
|
||||
clust_size = 10,
|
||||
height_min = -100,
|
||||
height_max = -32,
|
||||
height_min = -10000,
|
||||
height_max = -6000,
|
||||
noise_params = {offset=0, scale=1, spread={x=20, y=20, z=20}, seed=114, octaves=3, persist=0.70}
|
||||
})
|
||||
|
||||
@ -376,5 +376,6 @@ end
|
||||
if extrablocks_tools then
|
||||
dofile(path.."/tools.lua")
|
||||
end
|
||||
dofile(path.."/vector_line.lua")
|
||||
dofile(path.."/mining_lasers.lua")
|
||||
print(string.format("[extrablocks] loaded after ca. %.2fs", os.clock() - load_time_start))
|
||||
|
@ -1,17 +1,17 @@
|
||||
--license LGPLv2+
|
||||
|
||||
local r_corr = 0.25 --remove a bit more nodes (if shooting diagonal) to let it look like a hole (sth like antialiasing)
|
||||
--local r_corr = 0.25 --remove a bit more nodes (if shooting diagonal) to let it look like a hole (sth like antialiasing)
|
||||
local mk1_charge = 40000
|
||||
|
||||
local mining_lasers_list = {
|
||||
-- {<num>, <range of the laser shots>, <max_charge>},
|
||||
{"1", 7, mk1_charge},
|
||||
{"2", 11, mk1_charge*4},
|
||||
{"3", 30, mk1_charge*16},
|
||||
-- {<num>, <range of the laser shots>, <max_charge>, (math.sqrt(1+100*(range+0.4))-1)/50},
|
||||
{"1", 7, mk1_charge, 0.52},
|
||||
{"2", 11, mk1_charge*4, 0.66},
|
||||
{"3", 30, mk1_charge*16, 1.08},
|
||||
}
|
||||
|
||||
local f_1 = 0.5-r_corr
|
||||
local f_2 = 0.5+r_corr
|
||||
--local f_1 = 0.5-r_corr
|
||||
--local f_2 = 0.5+r_corr
|
||||
|
||||
-- Taken from the Flowers mod by erlehmann.
|
||||
local function table_contains(t, v)
|
||||
@ -23,7 +23,7 @@ local function table_contains(t, v)
|
||||
return false
|
||||
end
|
||||
|
||||
local function get_used_dir(dir)
|
||||
--[[local function get_used_dir(dir)
|
||||
local abs_dir = {x=math.abs(dir.x), y=math.abs(dir.y), z=math.abs(dir.z)}
|
||||
local dir_max = math.max(abs_dir.x, abs_dir.y, abs_dir.z)
|
||||
if dir_max == abs_dir.x then
|
||||
@ -54,7 +54,7 @@ local function node_tab(z, d)
|
||||
return {n1}
|
||||
end
|
||||
return {n1, n2}
|
||||
end
|
||||
end]]
|
||||
|
||||
local function laser_node(pos, player)
|
||||
local node = minetest.get_node(pos)
|
||||
@ -74,7 +74,10 @@ local function laser_node(pos, player)
|
||||
end
|
||||
|
||||
local function laser_nodes(pos, dir, player, range)
|
||||
local t_dir = get_used_dir(dir)
|
||||
for _,p in ipairs(vector.line(pos, dir, range)) do
|
||||
laser_node(p, player)
|
||||
end
|
||||
--[[ local t_dir = get_used_dir(dir)
|
||||
local dir_typ = t_dir[1]
|
||||
if t_dir[3] == "+" then
|
||||
f_tab = {0, range}
|
||||
@ -117,19 +120,18 @@ local function laser_nodes(pos, dir, player, range)
|
||||
laser_node({x=pos.x+x, y=pos.y+y, z=pos.z+z}, player)
|
||||
end
|
||||
end
|
||||
end
|
||||
end]]
|
||||
end
|
||||
|
||||
local function laser_shoot(player, range, particle_texture, sound)
|
||||
local function laser_shoot(player, range, particle_texture, particle_time, sound)
|
||||
local t1 = os.clock()
|
||||
|
||||
local playerpos=player:getpos()
|
||||
local dir=player:get_look_dir()
|
||||
|
||||
local startpos = {x=playerpos.x, y=playerpos.y+1.6, z=playerpos.z}
|
||||
local a = {x=dir.x*50, y=dir.y*50, z=dir.z*50}
|
||||
local delay = (math.sqrt(1+100*(range+0.4))-1)/50
|
||||
minetest.add_particle(startpos, dir, a, delay, 1, false, particle_texture)
|
||||
local a = vector.multiply(dir, 50)
|
||||
minetest.add_particle(startpos, dir, a, particle_time, 1, false, particle_texture)
|
||||
laser_nodes(vector.round(startpos), dir, player, range)
|
||||
minetest.sound_play(sound, {pos = playerpos, gain = 1.0, max_hear_distance = range})
|
||||
|
||||
@ -144,7 +146,7 @@ for _,m in ipairs(mining_lasers_list) do
|
||||
inventory_image = "technic_mining_laser_mk"..m[1]..".png",
|
||||
stack_max = 1,
|
||||
on_use = function(itemstack, user)
|
||||
laser_shoot(user, m[2], "technic_laser_beam_mk"..m[1]..".png", "technic_laser_mk"..m[1])
|
||||
laser_shoot(user, m[2], "technic_laser_beam_mk"..m[1]..".png", m[4], "technic_laser_mk"..m[1])
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
30
mvmt.lua
30
mvmt.lua
@ -25,28 +25,28 @@ end
|
||||
|
||||
local function acc(p)
|
||||
if p:get_player_control()["sneak"] then
|
||||
return 0.1
|
||||
return 3
|
||||
end
|
||||
return -1
|
||||
return 30
|
||||
end
|
||||
|
||||
local jpllist = {}
|
||||
|
||||
minetest.register_craftitem("extrablocks:rocket_bag", {
|
||||
description = "Experimental Rocket Bag",
|
||||
inventory_image = "extrablocks_rbp.png",
|
||||
metadata = "off",
|
||||
on_use = function(itemstack, user)
|
||||
local item = itemstack:to_table();
|
||||
if item["metadata"]=="off" then
|
||||
local accel = acc(user)
|
||||
user:set_physics_override(nil,nil,accel)
|
||||
item["metadata"] = "on"
|
||||
lit_rocket(pos)
|
||||
else
|
||||
user:set_physics_override(nil,nil,1)
|
||||
item["metadata"] = "off"
|
||||
on_use = function(_, user)
|
||||
local enabled = jpllist[user:get_player_name()]
|
||||
if enabled then
|
||||
user:set_physics_override({jump=1})
|
||||
jpllist[user:get_player_name()] = false
|
||||
off_rocket(pos)
|
||||
else
|
||||
local accel = acc(user)
|
||||
user:set_physics_override({jump=accel})
|
||||
jpllist[user:get_player_name()] = true
|
||||
lit_rocket(pos)
|
||||
end
|
||||
itemstack:replace(item)
|
||||
return itemstack
|
||||
return
|
||||
end,
|
||||
})
|
||||
|
107
vector_line.lua
Normal file
107
vector_line.lua
Normal file
@ -0,0 +1,107 @@
|
||||
--license LGPLv2+
|
||||
|
||||
local r_corr = 0.25 --remove a bit more nodes (if shooting diagonal) to let it look like a hole (sth like antialiasing)
|
||||
|
||||
-- this doesn't need to be calculated every time
|
||||
local f_1 = 0.5-r_corr
|
||||
local f_2 = 0.5+r_corr
|
||||
|
||||
--returns information about the direction
|
||||
local function get_used_dir(dir)
|
||||
local abs_dir = {x=math.abs(dir.x), y=math.abs(dir.y), z=math.abs(dir.z)}
|
||||
local dir_max = math.max(abs_dir.x, abs_dir.y, abs_dir.z)
|
||||
if dir_max == abs_dir.x then
|
||||
local tab = {"x", {x=1, y=dir.y/dir.x, z=dir.z/dir.x}}
|
||||
if dir.x >= 0 then
|
||||
tab[3] = "+"
|
||||
end
|
||||
return tab
|
||||
end
|
||||
if dir_max == abs_dir.y then
|
||||
local tab = {"y", {x=dir.x/dir.y, y=1, z=dir.z/dir.y}}
|
||||
if dir.y >= 0 then
|
||||
tab[3] = "+"
|
||||
end
|
||||
return tab
|
||||
end
|
||||
local tab = {"z", {x=dir.x/dir.z, y=dir.y/dir.z, z=1}}
|
||||
if dir.z >= 0 then
|
||||
tab[3] = "+"
|
||||
end
|
||||
return tab
|
||||
end
|
||||
|
||||
local function node_tab(z, d)
|
||||
local n1 = math.floor(z*d+f_1)
|
||||
local n2 = math.floor(z*d+f_2)
|
||||
if n1 == n2 then
|
||||
return {n1}
|
||||
end
|
||||
return {n1, n2}
|
||||
end
|
||||
|
||||
local function return_line(pos, dir, range) --range ~= length
|
||||
local tab = {}
|
||||
local num = 1
|
||||
local t_dir = get_used_dir(dir)
|
||||
local dir_typ = t_dir[1]
|
||||
if t_dir[3] == "+" then
|
||||
f_tab = {0, range, 1}
|
||||
else
|
||||
f_tab = {0, -range, -1}
|
||||
end
|
||||
local d_ch = t_dir[2]
|
||||
if dir_typ == "x" then
|
||||
for d = f_tab[1],f_tab[2],f_tab[3] do
|
||||
local x = d
|
||||
local ytab = node_tab(d_ch.y, d)
|
||||
local ztab = node_tab(d_ch.z, d)
|
||||
for _,y in ipairs(ytab) do
|
||||
for _,z in ipairs(ztab) do
|
||||
tab[num] = {x=pos.x+x, y=pos.y+y, z=pos.z+z}
|
||||
num = num+1
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif dir_typ == "y" then
|
||||
for d = f_tab[1],f_tab[2],f_tab[3] do
|
||||
local xtab = node_tab(d_ch.x, d)
|
||||
local y = d
|
||||
local ztab = node_tab(d_ch.z, d)
|
||||
for _,x in ipairs(xtab) do
|
||||
for _,z in ipairs(ztab) do
|
||||
tab[num] = {x=pos.x+x, y=pos.y+y, z=pos.z+z}
|
||||
num = num+1
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
for d = f_tab[1],f_tab[2],f_tab[3] do
|
||||
local xtab = node_tab(d_ch.x, d)
|
||||
local ytab = node_tab(d_ch.y, d)
|
||||
local z = d
|
||||
for _,x in ipairs(xtab) do
|
||||
for _,y in ipairs(ytab) do
|
||||
tab[num] = {x=pos.x+x, y=pos.y+y, z=pos.z+z}
|
||||
num = num+1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return tab
|
||||
end
|
||||
|
||||
function vector.line(pos, dir, range)
|
||||
--assert_vector(pos)
|
||||
if not range then --dir = pos2
|
||||
return return_line(pos, vector.direction(pos, dir), vector.distance(pos, dir))
|
||||
end
|
||||
return return_line(pos, dir, range)
|
||||
end
|
||||
|
||||
function vector.straightdelay(s, v, a)
|
||||
if not a then
|
||||
return s/v
|
||||
end
|
||||
return (math.sqrt(v*v+2*a*s)-v)/a
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user