2020-12-14 01:06:03 +00:00
|
|
|
-- CC0/Unlicense Emilia & cora 2020
|
2020-11-21 18:29:37 +00:00
|
|
|
|
2020-11-21 20:09:50 +00:00
|
|
|
local category = "Scaffold"
|
|
|
|
|
2020-11-21 06:04:49 +00:00
|
|
|
scaffold = {}
|
|
|
|
scaffold.registered_scaffolds = {}
|
2020-12-27 05:07:44 +01:00
|
|
|
scaffold.lockdir = false
|
|
|
|
scaffold.locky = false
|
2021-02-02 00:05:20 +01:00
|
|
|
scaffold.constrain1 = false
|
|
|
|
scaffold.constrain2 = false
|
|
|
|
local hwps={}
|
|
|
|
|
2020-12-27 05:07:44 +01:00
|
|
|
local storage=minetest.get_mod_storage()
|
|
|
|
|
2020-12-27 06:24:17 +01:00
|
|
|
scaffold.wason = {}
|
2020-12-27 05:07:44 +01:00
|
|
|
|
2021-01-08 21:55:58 +01:00
|
|
|
local nextact = {}
|
|
|
|
|
|
|
|
local towerbot_height = 75
|
2021-02-11 03:59:20 +01:00
|
|
|
|
|
|
|
function scaffold.template(setting, func, offset, funcstop )
|
|
|
|
offset = offset or {x = 0, y = -1, z = 0}
|
|
|
|
funcstop = funcstop or function() end
|
|
|
|
|
|
|
|
return function()
|
|
|
|
if minetest.localplayer and minetest.settings:get_bool(setting) then
|
|
|
|
if scaffold.constrain1 and not inside_constraints(tgt) then return end
|
|
|
|
local tgt=vector.add(minetest.localplayer:get_pos(),offset)
|
|
|
|
func(tgt)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function scaffold.register_template_scaffold(name, setting, func, offset, funcstop)
|
|
|
|
ws.rg(name,'Scaffold',setting,scaffold.template(setting, func, offset),funcstop )
|
|
|
|
end
|
|
|
|
|
2021-02-02 00:05:20 +01:00
|
|
|
local function between(x, y, z) return y <= x and x <= z end -- x is between y and z (inclusive)
|
2021-01-08 21:55:58 +01:00
|
|
|
|
2021-02-02 00:05:20 +01:00
|
|
|
function scaffold.in_cube(tpos,wpos1,wpos2)
|
|
|
|
local xmax=wpos2.x
|
|
|
|
local xmin=wpos1.x
|
2020-12-27 05:07:44 +01:00
|
|
|
|
2021-02-02 00:05:20 +01:00
|
|
|
local ymax=wpos2.y
|
|
|
|
local ymin=wpos1.y
|
2020-12-27 05:07:44 +01:00
|
|
|
|
2021-02-02 00:05:20 +01:00
|
|
|
local zmax=wpos2.z
|
|
|
|
local zmin=wpos1.z
|
|
|
|
if wpos1.x > wpos2.x then
|
|
|
|
xmax=wpos1.x
|
|
|
|
xmin=wpos2.x
|
|
|
|
end
|
|
|
|
if wpos1.y > wpos2.y then
|
|
|
|
ymax=wpos1.y
|
|
|
|
ymin=wpos2.y
|
|
|
|
end
|
|
|
|
if wpos1.z > wpos2.z then
|
|
|
|
zmax=wpos1.z
|
|
|
|
zmin=wpos2.z
|
|
|
|
end
|
|
|
|
if between(tpos.x,xmin,xmax) and between(tpos.y,ymin,ymax) and between(tpos.z,zmin,zmax) then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
2020-12-27 05:07:44 +01:00
|
|
|
|
2021-02-02 00:05:20 +01:00
|
|
|
local function set_hwp(name,pos)
|
2021-02-11 03:59:20 +01:00
|
|
|
ws.display_wp(pos,name)
|
2021-02-02 00:05:20 +01:00
|
|
|
end
|
|
|
|
|
2021-02-11 03:59:20 +01:00
|
|
|
function scaffold.set_pos1(pos)
|
|
|
|
if not pos then local pos=minetest.localplayer:get_pos() end
|
|
|
|
scaffold.constrain1=vector.round(pos)
|
2021-02-02 00:05:20 +01:00
|
|
|
local pstr=minetest.pos_to_string(scaffold.constrain1)
|
|
|
|
set_hwp('scaffold_pos1 '..pstr,scaffold.constrain1)
|
|
|
|
minetest.display_chat_message("scaffold pos1 set to "..pstr)
|
|
|
|
end
|
2021-02-11 03:59:20 +01:00
|
|
|
function scaffold.set_pos2(pos)
|
|
|
|
if not pos then pos=minetest.localplayer:get_pos() end
|
|
|
|
scaffold.constrain2=vector.round(pos)
|
2021-02-02 00:05:20 +01:00
|
|
|
local pstr=minetest.pos_to_string(scaffold.constrain2)
|
|
|
|
set_hwp('scaffold_pos2 '..pstr,scaffold.constrain2)
|
|
|
|
minetest.display_chat_message("scaffold pos2 set to "..pstr)
|
|
|
|
end
|
|
|
|
|
|
|
|
function scaffold.reset()
|
|
|
|
scaffold.constrain1=false
|
|
|
|
scaffold.constrain2=false
|
|
|
|
for k,v in pairs(hwps) do
|
|
|
|
minetest.localplayer:hud_remove(v)
|
|
|
|
table.remove(hwps,k)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function inside_constraints(pos)
|
|
|
|
if (scaffold.constrain1 and scaffold.constrain2 and scaffold.in_cube(pos,scaffold.constrain1,scaffold.constrain2)) then return true
|
|
|
|
elseif not scaffold.constrain1 then return true
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_chatcommand("sc_pos1", { func = scaffold.set_pos1 })
|
|
|
|
minetest.register_chatcommand("sc_pos2", { func = scaffold.set_pos2 })
|
|
|
|
minetest.register_chatcommand("sc_reset", { func = scaffold.reset })
|
|
|
|
|
2020-11-21 06:04:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2020-11-21 18:29:37 +00:00
|
|
|
function scaffold.can_place_at(pos)
|
|
|
|
local node = minetest.get_node_or_nil(pos)
|
2021-02-12 05:23:57 +01:00
|
|
|
return (node and (node.name == "air" or node.name=="mcl_core:water_source" or node.name=="mcl_core:water_flowing" or node.name=="mcl_core:lava_source" or node.name=="mcl_core:lava_flowing" or minetest.get_node_def(node.name).buildable_to))
|
2020-11-21 18:29:37 +00:00
|
|
|
end
|
|
|
|
|
2020-11-22 01:29:56 +00:00
|
|
|
-- should check if wield is placeable
|
|
|
|
-- minetest.get_node(wielded:get_name()) ~= nil should probably work
|
|
|
|
-- otherwise it equips armor and eats food
|
|
|
|
function scaffold.can_place_wielded_at(pos)
|
|
|
|
local wield_empty = minetest.localplayer:get_wielded_item():is_empty()
|
|
|
|
return not wield_empty and scaffold.can_place_at(pos)
|
|
|
|
end
|
|
|
|
|
2021-03-02 13:23:30 +01:00
|
|
|
|
2020-11-21 18:29:37 +00:00
|
|
|
function scaffold.find_any_swap(items)
|
2021-03-02 13:23:30 +01:00
|
|
|
local ts=8
|
2020-11-21 18:29:37 +00:00
|
|
|
for i, v in ipairs(items) do
|
|
|
|
local n = minetest.find_item(v)
|
|
|
|
if n then
|
2021-03-02 13:23:30 +01:00
|
|
|
ws.switch_to_item(v)
|
2020-11-21 18:29:37 +00:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
function scaffold.in_list(val, list)
|
2020-12-27 05:07:44 +01:00
|
|
|
if type(list) ~= "table" then return false end
|
2020-11-21 18:29:37 +00:00
|
|
|
for i, v in ipairs(list) do
|
|
|
|
if v == val then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
-- swaps to any of the items and places if need be
|
|
|
|
-- returns true if placed and in inventory or already there, false otherwise
|
2021-01-08 21:55:58 +01:00
|
|
|
|
|
|
|
local lastact=0
|
|
|
|
local lastplc=0
|
|
|
|
local lastdig=0
|
2021-02-02 00:05:20 +01:00
|
|
|
local actint=10
|
2020-11-21 18:29:37 +00:00
|
|
|
function scaffold.place_if_needed(items, pos, place)
|
2021-02-02 00:05:20 +01:00
|
|
|
if not inside_constraints(pos) then return end
|
2021-01-08 21:55:58 +01:00
|
|
|
--if lastplc + actint > os.time() then return end
|
2021-01-10 18:03:49 +01:00
|
|
|
if not pos then return end
|
2021-01-08 21:55:58 +01:00
|
|
|
lastplc=os.time()
|
2021-02-12 05:23:57 +01:00
|
|
|
|
2020-11-21 18:29:37 +00:00
|
|
|
place = place or minetest.place_node
|
|
|
|
|
|
|
|
local node = minetest.get_node_or_nil(pos)
|
2021-01-10 18:03:49 +01:00
|
|
|
if not node then return end
|
2020-11-21 18:29:37 +00:00
|
|
|
-- already there
|
|
|
|
if node and scaffold.in_list(node.name, items) then
|
|
|
|
return true
|
|
|
|
else
|
|
|
|
local swapped = scaffold.find_any_swap(items)
|
|
|
|
|
|
|
|
-- need to place
|
|
|
|
if swapped and scaffold.can_place_at(pos) then
|
|
|
|
place(pos)
|
|
|
|
return true
|
|
|
|
-- can't place
|
|
|
|
else
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-11-24 20:23:24 +00:00
|
|
|
function scaffold.place_if_able(pos)
|
2021-02-11 03:59:20 +01:00
|
|
|
if not pos then return end
|
2021-02-02 00:05:20 +01:00
|
|
|
if not inside_constraints(pos) then return end
|
2020-11-24 20:23:24 +00:00
|
|
|
if scaffold.can_place_wielded_at(pos) then
|
|
|
|
minetest.place_node(pos)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-02-11 03:59:20 +01:00
|
|
|
local function is_diggable(pos)
|
|
|
|
if not pos then return false end
|
2020-12-21 21:19:42 +01:00
|
|
|
local nd=minetest.get_node_or_nil(pos)
|
|
|
|
if not nd then return false end
|
|
|
|
local n = minetest.get_node_def(nd.name)
|
2021-02-11 03:59:20 +01:00
|
|
|
if n and n.diggable then return true end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
function scaffold.dig(pos)
|
|
|
|
if not inside_constraints(pos) then return end
|
|
|
|
if is_diggable(pos) then
|
2021-03-02 13:23:30 +01:00
|
|
|
local nd=minetest.get_node_or_nil(pos)
|
2021-02-11 03:59:20 +01:00
|
|
|
minetest.select_best_tool(nd.name)
|
|
|
|
if emicor then emicor.supertool()
|
|
|
|
end
|
2021-03-02 13:23:30 +01:00
|
|
|
--minetest.select_best_tool(nd.name)
|
2021-02-11 03:59:20 +01:00
|
|
|
minetest.dig_node(pos)
|
2021-03-02 13:23:30 +01:00
|
|
|
|
2020-12-14 01:06:03 +00:00
|
|
|
end
|
2020-12-21 21:19:42 +01:00
|
|
|
return false
|
2020-12-14 01:06:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2020-11-21 05:31:21 +00:00
|
|
|
local mpath = minetest.get_modpath(minetest.get_current_modname())
|
|
|
|
dofile(mpath .. "/sapscaffold.lua")
|
|
|
|
dofile(mpath .. "/slowscaffold.lua")
|
2020-11-21 20:09:50 +00:00
|
|
|
dofile(mpath .. "/autofarm.lua")
|
2020-11-28 01:15:46 +01:00
|
|
|
dofile(mpath .. "/railscaffold.lua")
|
2021-01-15 00:26:36 +01:00
|
|
|
dofile(mpath .. "/wallbot.lua")
|
2021-02-11 03:59:20 +01:00
|
|
|
dofile(mpath .. "/ow2bot.lua")
|
|
|
|
--dofile(mpath .. "/squarry.lua")
|
2021-02-13 03:31:26 +01:00
|
|
|
local snapdir="north"
|
|
|
|
ws.rg('DigHead','Player','dighead',function() ws.dig(ws.dircoord(0,1,0)) end)
|
|
|
|
ws.rg('SnapYaw','Bots','snapyaw',function() ws.setdir(snapdir) end,function() snapdir=ws.getdir() end)
|
2021-02-02 00:05:20 +01:00
|
|
|
|
|
|
|
|
2021-02-15 23:41:56 +01:00
|
|
|
scaffold.register_template_scaffold("Constrain", "scaffold_constrain", function()end,false,function() scaffold.reset() end)
|
2020-11-22 01:29:56 +00:00
|
|
|
|
2021-03-02 13:23:30 +01:00
|
|
|
ws.rg("LockYaw","Scaffold", "scaffold_lockyaw", function(pos)
|
|
|
|
if minetest.settings:get_bool("freecam") then return end
|
|
|
|
local y=minetest.localplayer:get_yaw()
|
|
|
|
local yy=nil
|
|
|
|
if ( y < 45 or y > 315 ) then
|
|
|
|
yy=0
|
|
|
|
elseif (y < 135) then
|
|
|
|
yy=90
|
|
|
|
elseif (y < 225 ) then
|
|
|
|
yy=180
|
|
|
|
elseif ( y < 315 ) then
|
|
|
|
yy=270
|
|
|
|
end
|
|
|
|
if yy ~= nil then
|
|
|
|
minetest.localplayer:set_yaw(yy)
|
|
|
|
end
|
|
|
|
end)
|
2020-12-27 06:24:17 +01:00
|
|
|
|
2020-12-27 05:07:44 +01:00
|
|
|
|
2020-11-22 01:29:56 +00:00
|
|
|
scaffold.register_template_scaffold("CheckScaffold", "scaffold_check", function(pos)
|
2020-11-24 20:23:24 +00:00
|
|
|
scaffold.place_if_able(pos)
|
2020-11-22 01:29:56 +00:00
|
|
|
end)
|
|
|
|
|
|
|
|
scaffold.register_template_scaffold("HereScaffold", "scaffold_here", function(pos)
|
2020-11-24 20:23:24 +00:00
|
|
|
scaffold.place_if_able(pos)
|
2020-11-22 01:29:56 +00:00
|
|
|
end, {x = 0, y = 0, z = 0})
|
2020-11-24 20:23:24 +00:00
|
|
|
|
2020-12-14 01:06:03 +00:00
|
|
|
scaffold.register_template_scaffold("WaterScaffold", "scaffold_water", function(pos)
|
|
|
|
if (pos.x % 2 + pos.z % 2) == 0 then
|
|
|
|
scaffold.place_if_needed({
|
|
|
|
"mcl_buckets:bucket_water",
|
|
|
|
"mcl_core:water_source"
|
|
|
|
}, pos)
|
|
|
|
end
|
|
|
|
end)
|
2021-02-15 23:41:56 +01:00
|
|
|
scaffold.register_template_scaffold("WaterSpam", "scaffold_spamwater", function()
|
|
|
|
ws.do_area(3,function(pos)
|
|
|
|
scaffold.place_if_needed({
|
|
|
|
"mcl_buckets:bucket_water",
|
|
|
|
"mcl_core:water_source"
|
|
|
|
}, pos)
|
|
|
|
end,true)
|
|
|
|
|
2020-12-16 21:51:13 +01:00
|
|
|
end)
|
2020-12-21 21:19:42 +01:00
|
|
|
local function checknode(pos)
|
|
|
|
local node = minetest.get_node_or_nil(pos)
|
|
|
|
if node then return true end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2021-02-12 05:23:57 +01:00
|
|
|
scaffold.register_template_scaffold("TBM", "scaffold_tbm", function(pos)
|
|
|
|
scaffold.dig(ws.dircoord(1,1,0))
|
|
|
|
scaffold.dig(ws.dircoord(1,0,0))
|
|
|
|
end)
|
|
|
|
scaffold.register_template_scaffold("TallTBM", "scaffold_ttbm", function(pos)
|
|
|
|
pos = {
|
|
|
|
|
|
|
|
ws.dircoord(1,4,2),
|
|
|
|
ws.dircoord(1,3,2),
|
|
|
|
ws.dircoord(1,2,2),
|
|
|
|
ws.dircoord(1,1,2),
|
|
|
|
ws.dircoord(1,0,2),
|
|
|
|
|
|
|
|
ws.dircoord(1,4,-2),
|
|
|
|
ws.dircoord(1,3,-2),
|
|
|
|
ws.dircoord(1,2,-2),
|
|
|
|
ws.dircoord(1,1,-2),
|
|
|
|
ws.dircoord(1,0,-2),
|
|
|
|
|
|
|
|
|
|
|
|
ws.dircoord(1,4,1),
|
|
|
|
ws.dircoord(1,3,1),
|
|
|
|
ws.dircoord(1,2,1),
|
|
|
|
ws.dircoord(1,1,1),
|
|
|
|
ws.dircoord(1,0,1),
|
|
|
|
|
|
|
|
ws.dircoord(1,4,-1),
|
|
|
|
ws.dircoord(1,3,-1),
|
|
|
|
ws.dircoord(1,2,-1),
|
|
|
|
ws.dircoord(1,1,-1),
|
|
|
|
ws.dircoord(1,0,-1),
|
|
|
|
|
|
|
|
ws.dircoord(1,4,0),
|
|
|
|
ws.dircoord(1,3,0),
|
|
|
|
ws.dircoord(1,2,0),
|
|
|
|
ws.dircoord(1,1,0),
|
|
|
|
ws.dircoord(1,0,0)
|
|
|
|
}
|
2021-02-15 23:41:56 +01:00
|
|
|
ws.dignodes(pos)
|
|
|
|
|
2021-02-12 05:23:57 +01:00
|
|
|
minetest.settings:set_bool('continuous_forward',true)
|
|
|
|
for k,v in pairs(pos) do
|
|
|
|
local n=minetest.get_node_or_nil(v)
|
2021-02-15 23:41:56 +01:00
|
|
|
if not n or n.name ~= "air" then
|
2021-02-12 05:23:57 +01:00
|
|
|
minetest.settings:set_bool('continuous_forward',false)
|
2021-01-10 18:03:49 +01:00
|
|
|
end
|
2021-02-12 05:23:57 +01:00
|
|
|
end
|
|
|
|
end)
|
2020-12-21 21:19:42 +01:00
|
|
|
|
2021-01-15 00:26:36 +01:00
|
|
|
|
|
|
|
|
2021-01-10 18:03:49 +01:00
|
|
|
|
2021-02-12 05:23:57 +01:00
|
|
|
scaffold.register_template_scaffold("TriScaffold", "scaffold_three_wide", function(pos)
|
|
|
|
scaffold.place_if_able(pos)
|
|
|
|
scaffold.place_if_able(ws.dircoord(0, -1, 1))
|
|
|
|
scaffold.place_if_able(ws.dircoord(0, -1, -1))
|
|
|
|
end)
|
2021-01-10 18:03:49 +01:00
|
|
|
|
2021-02-12 05:23:57 +01:00
|
|
|
scaffold.register_template_scaffold("headTriScaff", "scaffold_three_wide_head", function(pos)
|
|
|
|
scaffold.place_if_able(ws.dircoord(0, 3, 0))
|
|
|
|
scaffold.place_if_able(ws.dircoord(0, 3, 1))
|
|
|
|
scaffold.place_if_able(ws.dircoord(0, 3, -1))
|
|
|
|
end)
|
2021-01-10 18:03:49 +01:00
|
|
|
|
2021-02-12 05:23:57 +01:00
|
|
|
scaffold.register_template_scaffold("QuintScaffold", "scaffold_five_wide", function(pos)
|
|
|
|
scaffold.place_if_able(pos)
|
|
|
|
scaffold.place_if_able(ws.dircoord(0, -1, 1))
|
|
|
|
scaffold.place_if_able(ws.dircoord(0, -1, -1))
|
|
|
|
scaffold.place_if_able(ws.dircoord(0, -1, 2))
|
|
|
|
scaffold.place_if_able(ws.dircoord(0, -1, -2))
|
|
|
|
end)
|
2020-12-14 01:06:03 +00:00
|
|
|
|
2020-11-28 14:11:14 +01:00
|
|
|
|
2020-12-14 01:06:03 +00:00
|
|
|
if nlist then
|
|
|
|
scaffold.register_template_scaffold("RandomScaff", "scaffold_rnd", function(below)
|
|
|
|
local n = minetest.get_node_or_nil(below)
|
2021-01-22 21:44:27 +01:00
|
|
|
local nl=nlist.get('randomscaffold')
|
|
|
|
table.shuffle(nl)
|
|
|
|
if n and not scaffold.in_list(n.name, nl) then
|
2020-12-14 01:06:03 +00:00
|
|
|
scaffold.dig(below)
|
2021-01-22 21:44:27 +01:00
|
|
|
scaffold.place_if_needed(nl, below)
|
2020-12-14 01:06:03 +00:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
end
|