waspsaliva/clientmods/scaffold/railscaffold.lua

318 lines
9.2 KiB
Lua
Raw Permalink Normal View History

2020-12-21 14:31:03 -08:00
-- CC0/Unlicense Emilia/cora 2020
2020-11-24 17:08:29 -08:00
2021-03-27 14:25:11 -07:00
-- south:5,1.5
--west:-x,1.5,-5
--east:-x,1.5,5
-- north 5,1.5(3096:2.5,25025:1.5),z
local direction = ""
2020-12-21 14:31:03 -08:00
local ground = {
2020-11-24 17:08:29 -08:00
"mesecons_torch:redstoneblock"
}
2020-12-21 14:31:03 -08:00
local rails = {
"mcl_minecarts:golden_rail",
"mcl_minecarts:rail"
2020-11-24 17:08:29 -08:00
}
2020-12-21 18:48:29 -08:00
local tunnelmaterial = {
2020-12-26 20:07:44 -08:00
'mcl_core:glass_light_blue',
2021-09-11 08:23:45 -07:00
'mcl_core:glass',
2020-12-21 18:48:29 -08:00
'mcl_core:cobble',
2021-03-27 14:25:11 -07:00
'mcl_core:stone',
2020-12-26 20:07:44 -08:00
'mcl_nether:netherrack',
'mcl_core:dirt',
2020-12-21 18:48:29 -08:00
'mcl_core:andesite',
'mcl_core:diorite',
2021-09-11 08:23:45 -07:00
'mcl_core:granite',
"mesecons_torch:redstoneblock"
2020-12-21 18:48:29 -08:00
}
2020-12-26 20:07:44 -08:00
2021-09-11 08:23:45 -07:00
local lightblock = "mcl_ocean:sea_lantern"
--local lightblock = "mcl_nether:glowstone"
2021-03-27 14:25:11 -07:00
local function is_rail(pos)
pos=vector.round(pos)
if pos.y ~= 1 then return false end
if pos.z > 5 then
if pos.x == -5 then return "north" end
elseif pos.z < -5 then
if pos.x == 5 then return "south" end
end
if pos.x > 5 then
if pos.z == 5 then return "east" end
elseif pos.x < -5 then
if pos.z == -5 then return "west" end
end
return false
end
local function get_railnode(pos)
if is_rail(pos) then
return "mcl_minecarts:golden_rail"
end
if is_rail(vector.add(pos,{x=0,y=-1,x=0})) then
2021-03-27 14:25:11 -07:00
return "mesecons_torch:redstoneblock"
end
return false
end
local function is_lantern(pos)
local dir=ws.getdir()
pos=vector.round(pos)
if dir == "north" or dir == "south" then
if pos.z % 8 == 0 then
return true
end
else
if pos.x % 8 == 0 then
return true
end
end
return false
end
2020-12-26 21:24:17 -08:00
2021-02-11 20:23:57 -08:00
2020-11-27 16:15:46 -08:00
local function checknode(pos)
local lp = ws.dircoord(0,0,0)
2020-11-27 16:15:46 -08:00
local node = minetest.get_node_or_nil(pos)
if pos.y == lp.y then
if node and not node.name:find("_rail") then return true end
elseif node and node.name ~="mesecons_torch:redstoneblock" then return true
end
2020-11-27 16:15:46 -08:00
return false
end
2021-02-11 20:23:57 -08:00
local function dignodes(poss)
for k,v in pairs(poss) do
if checknode(v) then ws.dig(v) end
2020-12-26 21:24:17 -08:00
end
2021-02-11 20:23:57 -08:00
end
local function findliquids(pos,range)
range = range or 1
if not pos then return end
local liquids={'mcl_core:lava_source','mcl_core:water_source','mcl_core:lava_flowing','mcl_core:water_flowing','mcl_nether:nether_lava_source','mcl_nether:nether_lava_flowing'}
local bn=minetest.find_nodes_near(pos, range, liquids, true)
if #bn < 0 then return bn end
return false
end
local function blockliquids(pos)
if not pos then return end
local lp=ws.dircoord(0,0,0)
local liquids={'mcl_core:lava_source','mcl_core:water_source','mcl_core:lava_flowing','mcl_core:water_flowing','mcl_nether:nether_lava_source','mcl_nether:nether_lava_flowing'}
local bn=minetest.find_nodes_near(pos, 1, liquids, true)
local rt=false
if not bn then return rt end
2020-12-26 20:07:44 -08:00
for kk,vv in pairs(bn) do
if vv.y > lp.y - 1 or vv.y < -40 then
rt=true
scaffold.place_if_needed(tunnelmaterial,vv)
for i=-4,5,1 do
local tpos=vector.new(pos.x,lp.y,pos.z)
scaffold.place_if_needed(tunnelmaterial,ws.dircoord(i,2,0,tpos))
scaffold.place_if_needed(tunnelmaterial,ws.dircoord(i,0,1,tpos))
scaffold.place_if_needed(tunnelmaterial,ws.dircoord(i,1,1,tpos))
scaffold.place_if_needed(tunnelmaterial,ws.dircoord(i,0,-1,tpos))
scaffold.place_if_needed(tunnelmaterial,ws.dircoord(i,1,-1,tpos))
end
end
2020-12-26 20:07:44 -08:00
end
return rt
end
local function digob(sc)
local obpos={
ws.dircoord(0,1,2,sc),
ws.dircoord(0,1,-2,sc),
ws.dircoord(0,1,1,sc),
ws.dircoord(0,1,-1,sc),
ws.dircoord(0,0,1,sc),
ws.dircoord(0,0,-1,sc)
}
ws.dignodes(obpos,function(pos)
local nd=minetest.get_node_or_nil(pos)
if nd and (nd.name == "mcl_core:obsidian" or nd.name == "mcl_minecarts:golden_rail_on" or nd.name == "mcl_minecarts:golden_rail" )then return true end
return false
end)
end
local function invcheck(item)
if mintetest.switch_to_item(item) then return true end
refill.refill_at(ws.dircoord(1,1,0),'railkit')
2021-02-11 20:23:57 -08:00
end
local function invcheck(item)
if mintetest.switch_to_item(item) then return true end
refill.refill_at(ws.dircoord(1,1,0),'railkit')
end
local function rnd(n)
return math.ceil(n)
end
2021-02-11 20:23:57 -08:00
local function fmt(c)
return tostring(rnd(c.x))..","..tostring(rnd(c.y))..","..tostring(rnd(c.z))
end
local function map_pos(value)
if value.x then
return value
else
return {x = value[1], y = value[2], z = value[3]}
end
end
2021-03-27 14:25:11 -07:00
local function invparse(location)
if type(location) == "string" then
if string.match(location, "^[-]?[0-9]+,[-]?[0-9]+,[-]?[0-9]+$") then
return "nodemeta:" .. location
else
return location
end
elseif type(location) == "table" then
return "nodemeta:" .. fmt(map_pos(location))
end
end
2020-12-21 07:53:38 -08:00
local function take_railkit(pos)
local plinv = minetest.get_inventory(invparse(pos))
local epos=ws.find_named(plinv,'railkit')
local mv = InventoryAction("move")
mv:from(invparse(pos), "main", epos)
mv:to("current_player", "main", 8)
mv:apply()
minetest.localplayer:set_wield_index(8)
return true
2021-03-27 14:25:11 -07:00
end
local restashing=false
function scaffold.restash()
if restashing then return end
restashing=true
ws.dig(ws.dircoord(1,0,1))
ws.dig(ws.dircoord(1,1,1))
ws.dig(ws.dircoord(2,0,1))
ws.dig(ws.dircoord(2,1,1))
ws.place(ws.dircoord(1,0,1),{'mcl_chests:chest_small','mcl_chests:chest'})
ws.place(ws.dircoord(1,1,1),{'railroad'})
take_railkit(ws.dircoord(1,1,1))
minetest.after("0.5",function()
ws.place(ws.dircoord(2,0,1),{'railkit'})
ws.dig(ws.dircoord(1,1,1))
end)
minetest.after("1.0",function()
autodupe.invtake(ws.dircoord(2,0,1))
restashing=false
end)
end
local function slowdown(s)
minetest.localplayer:set_velocity(vector.new(0,0,0))
minetest.settings:set('movement_speed_fast',math.abs(s))
end
local fullspeed=100
local function speedup()
minetest.settings:set('movement_speed_fast',fullspeed)
end
2021-03-27 14:25:11 -07:00
ws.rg("RailBot","Bots", "railbot", function()
local oldi=500
for i=-50,50,1 do
local lpos=ws.dircoord(i,2,0)
local lpn=minetest.get_node_or_nil(ws.dircoord(i,0,0))
local bln=minetest.get_node_or_nil(ws.dircoord(i,-1,0))
local ltpn=minetest.get_node_or_nil(lpos)
if not bln or not lpn or not ltpn then
speedup()
elseif ( is_lantern(lpos) and ltpn.name ~= lightblock ) then
if (oldi > i) then
slowdown(8)
oldi=i
end
elseif bln.name=="mesecons_torch:redstoneblock" and lpn.name == "mcl_minecarts:golden_rail_on" then
speedup()
else
if (oldi > i) then
slowdown(8)
oldi=i
end
end
end
local goon=false
for i=-4,4,1 do
local lpos=ws.dircoord(i,2,0)
2021-03-27 14:25:11 -07:00
local lpn=minetest.get_node_or_nil(ws.dircoord(i,0,0))
local bln=minetest.get_node_or_nil(ws.dircoord(i,-1,0))
local lpos=ws.dircoord(i,2,0)
2021-03-27 14:25:11 -07:00
if not ( bln and bln.name=="mesecons_torch:redstoneblock" and lpn and lpn.name == "mcl_minecarts:golden_rail_on" ) then
goon=false
else
goon=true
2021-03-27 14:25:11 -07:00
end
digob(ws.dircoord(i,0,0))
blockliquids(ws.dircoord(i,1,0))
blockliquids(ws.dircoord(i,0,0))
ws.dig(ws.dircoord(i,1,0))
if checknode(ws.dircoord(i,0,0)) then ws.dig(ws.dircoord(i,0,0)) end
if checknode(ws.dircoord(i,-1,0)) then ws.dig(ws.dircoord(i,-1,0)) end
ws.place(ws.dircoord(i,-1,0),ground,7)
ws.place(ws.dircoord(i,0,0),rails,6)
2021-03-27 14:25:11 -07:00
local lpos=ws.dircoord(i,2,0)
if is_lantern(lpos) then
local ln=minetest.get_node_or_nil(lpos)
if not ln or ln.name ~= lightblock then
2021-03-27 14:25:11 -07:00
goon=false
ws.dig(lpos)
ws.place(lpos,{lightblock},5)
2021-03-27 14:25:11 -07:00
end
end
2020-12-21 18:48:29 -08:00
end
2021-03-27 14:25:11 -07:00
if (goon) then
local dir=ws.getdir()
local lp=minetest.localplayer:get_pos()
local rlp=vector.round(lp)
minetest.localplayer:set_pos(vector.new(rlp.x,lp.y,rlp.z))
minetest.settings:set_bool('continuous_forward',true)
else
slowdown(5)
minetest.localplayer:set_velocity(vector.new(0,0,0))
minetest.settings:set_bool('continuous_forward',false)
end
2021-03-27 14:25:11 -07:00
2021-02-11 20:23:57 -08:00
end,
function()--startfunc
minetest.settings:set('movement_speed_fast',500)
minetest.settings:set_bool('continuous_forward',false)
2021-02-11 20:23:57 -08:00
end,function() --stopfunc
minetest.localplayer:set_velocity(vector.new(0,0,0))
minetest.settings:set('movement_speed_fast',20)
minetest.settings:set_bool('continuous_forward',false)
end,{'afly_snap','autorefill'}) --'scaffold_ltbm'
2021-02-11 20:23:57 -08:00
scaffold.register_template_scaffold("LanternTBM", "scaffold_ltbm", function()
local dir=ws.getdir()
local lp=vector.round(ws.dircoord(0,0,0))
2021-03-27 14:25:11 -07:00
local pl=is_lantern(lp)
2021-02-11 20:23:57 -08:00
if pl then
local lpos=ws.dircoord(0,2,0)
local nd=minetest.get_node_or_nil(lpos)
if nd and nd.name ~= lightblock then
2021-02-11 20:23:57 -08:00
ws.dig(lpos)
ws.place(lpos,lightblock,5)
2021-02-11 20:23:57 -08:00
end
end
end)