Another refactor of Island Ownership System, remove crappy (wandering) water and stop injecting wandering into default lava

This commit is contained in:
Kimapr 2019-12-10 10:44:28 +05:00
parent e4f3d04e45
commit cf417265cf
6 changed files with 354 additions and 390 deletions

View File

@ -1,2 +1,2 @@
name = nc_sieve
depends = nc_woodwork, nc_stonework, nc_terrain, nc_sky_liquids, nc_lode, nc_lux, nc_api
depends = nc_woodwork, nc_stonework, nc_terrain, nc_lode, nc_lux, nc_api

View File

@ -134,110 +134,99 @@ local duo4 = {
items={{name = modname..":super_random_dust", count = 4, scatter = 2}}
}
local dirts = {
["nc_terrain:gravel"] = duo,
["nc_terrain:gravel_loose"] = duo,
["nc_terrain:sand"] = duo2,
["nc_terrain:sand_loose"] = duo2,
["nc_tree:leaves_loose"] = {node = "nc_sky_liquids:hm_water_source"}
}
local dirtss = {
["nc_terrain:gravel"] = duo3,
["nc_terrain:gravel_loose"] = duo3,
["nc_terrain:sand"] = duo4,
["nc_terrain:sand_loose"] = duo4,
["nc_tree:leaves_loose"] = {node = "nc_sky_liquids:hm_water_source"},
}
for _,dat in pairs({
{
sievables = {
["nc_terrain:gravel"] = duo,
["nc_terrain:gravel_loose"] = duo,
["nc_terrain:sand"] = duo2,
["nc_terrain:sand_loose"] = duo2,
["nc_tree:leaves_loose"] = {node = "nc_terrain:water_source"},
},
name = modname..":sieve"
},
{
sievables = {
["nc_terrain:gravel"] = duo3,
["nc_terrain:gravel_loose"] = duo3,
["nc_terrain:sand"] = duo4,
["nc_terrain:sand_loose"] = duo4,
["nc_tree:leaves_loose"] = {node = "nc_terrain:water_source"},
},
name = modname..":sieve_stone"
}
})
do
for k,v in pairs(dirts) do
for k,v in pairs(dat.sievables) do
nodecore.register_craft({
label = "use a sieve with "..k,
action = "pummel",
toolgroups = {crumbly = 1},
nodes = {
{match = {name = k}, replace = v.node or "air"},
{y=-1,match = dat.name}
},
items = v.items
})
end
nodecore.register_craft({
label = "use a sieve with "..k,
action = "pummel",
toolgroups = {crumbly = 1},
nodes = {
{match = {name = k}, replace = v.node or "air"},
{y=-1,match = modname .. ":sieve"}
},
items = v.items
})
end
for k,v in pairs(dirtss) do
for _,dat in pairs({
{
drop = {
["nc_terrain:cobble"] = 30,
["nc_lode:cobble_loose"] = 10,
["nc_lux:cobble1_loose"] = 1,
["nc_sponge:sponge_living"]=1
},
name = modname..":random_dust"
},
{
ores = {
["nc_terrain:cobble"] = 50,
["nc_lode:cobble_loose"] = 50,
["nc_lux:cobble1_loose"] = 5,
["nc_sponge:sponge_living"]=5,
["rdust"]=1
},
name = modname..":super_random_dust"
}
})
do
nodecore.register_craft({
label = "use a stone sieve with "..k,
action = "pummel",
toolgroups = {crumbly = 1},
nodes = {
{match = {name = k}, replace = v.node or "air"},
{y=-1,match = modname .. ":sieve_stone"}
},
items = v.items
})
nodecore.register_craft({
label = "pack very random dust into cobble",
action = "pummel",
toolgroups = {thumpy = 2},
nodes = {
{match = {name = modname..":super_random_dust",count=16},replace = "nc_terrain:cobble"}
},
after = function(pos)
local chances = {}
local mc = 1
for k,v in pairs(dat.drop) do
for n=mc,mc-1+v do
chances[n] = k
end
mc=mc+v
end
local ore = chances[math.random(1,mc-1)]
if ore == "rdust" then
nodecore.item_eject(pos,modname..":super_random_dust",5,20)
else
minetest.set_node(pos,{name=ore})
end
end
})
end
local ores = {
["nc_lode:cobble_loose"] = 10,
["nc_lux:cobble1_loose"] = 1,
["nc_sponge:sponge_living"]=1
}
local sores = {
["nc_lode:cobble_loose"] = 50,
["nc_lux:cobble1_loose"] = 5,
["nc_sponge:sponge_living"]=5,
["rdust"]=1
}
nodecore.register_craft({
label = "pack random dust into cobble",
action = "pummel",
toolgroups = {thumpy = 2},
nodes = {
{match = {name = modname..":random_dust",count=8},replace = "nc_terrain:cobble"}
},
after = function(pos)
local chances = {}
local mc = 1
for k,v in pairs(ores) do
for n=mc,mc-1+v do
chances[n] = k
end
mc=mc+v
end
local ore = chances[math.random(1,mc-1)]
minetest.set_node(pos,{name=ore})
end
})
nodecore.register_craft({
label = "pack very random dust into cobble",
action = "pummel",
toolgroups = {thumpy = 2},
nodes = {
{match = {name = modname..":super_random_dust",count=8},replace = "nc_terrain:cobble"}
},
after = function(pos)
local chances = {}
local mc = 1
for k,v in pairs(sores) do
for n=mc,mc-1+v do
chances[n] = k
end
mc=mc+v
end
local ore = chances[math.random(1,mc-1)]
if ore == "rdust" then
nodecore.item_eject(pos,modname..":super_random_dust",5,10)
else
minetest.set_node(pos,{name=ore})
end
end
})
nodecore.register_craft({
label = "assemble wood sieve",
norotate = true,

View File

@ -3,10 +3,24 @@ local nodecore
= nodecore
-- LUALOCALS > ---------------------------------------------------------
print("injecting stuff...")
local ntgr = nodecore.tree_growth_rate
function nodecore.tree_growth_rate(pos)
return ntgr(pos)*10
end
nodecore.register_craft({
label = "melt cobble to lava",
action = "cook",
touchgroups = {flame = 4},
duration = 30,
cookfx = true,
nodes = {
{
match = "nc_terrain:cobble",
replace = "nc_terrain:lava_source"
}
}
})
nodecore.register_cook_abm({nodenames = {"nc_terrain:cobble"}, neighbors = {"group:flame"}})

View File

@ -90,57 +90,125 @@ local function save()
store:set_string("players",minetest.serialize(players))
store:set_string("cells",minetest.serialize(cells))
end
local function pid(x,z)
return "i"..x.."_"..z
end
local function checkpos(x,z)
local cell = cells[pid(x,z)]
local v = true
if cell then
v = cell.valid
else
v = store:get_string(pid(x,z)) == ""
end
return v
end
minetest.override_item("ignore",{
drawtype = "normal",
tiles={"nc_terrain_lava.png","nc_terrain_lava.png","nc_terrain_lava.png","nc_terrain_lava.png","nc_terrain_lava.png","nc_terrain_lava.png"},
walkable=true,
pointable=true
})
local function gen_island_pos(name)
local x,z = 0,0
local ok = checkpos(x,z)
while not ok do
x,z = x+math.random(-1,1),z+math.random(-1,1)
ok = checkpos(x,z)
end
local range,ip
local ocell = cells[pid(x,z)]
if ocell and ocell.valid then
range = ocell.islandrange
ip = ocell.islandpos
if players[ocell.name] and players[ocell.name].island == pid(x,z) then
players[ocell.name] = nil
do
local c = cells
cells = {}
for k,v in pairs(c) do
if v.island then
if v.valid and not v.name or v.name == "" then
table.insert(cells,{pos=v.islandpos,valid=v.valid})
end
else
table.insert(cells,v)
end
local ref = minetest.get_player_by_name(name)
local pos = ip
pos = {x=f(pos.x),y=f(pos.y),z=f(pos.z)}
ref:set_pos({x=pos.x,y=pos.y+256,z=pos.z})
else
range = {min={x=x*128-64,y=256-64,z=z*128-64},max={x=x*128+64,y=256+64,z=z*128+64}}
ip = {x=x*128+math.random(-32,32),y=256+math.random(-32,32),z=z*128+math.random(-32,32)}
spawn_island(name,ip)
end
local p = players
players = {}
for k,v in pairs(p) do
players[k] = {pos=v.islandpos or v.pos, valid = v.valid}
end
save()
end
local air_c = minetest.get_content_id("air")
local function island_range(x,y,z)
return {x=x-32,y=y-32,z=z-32},{x=x+32,y=y+32,z=z+32}
end
local function checkpos(x,y,z)
local vm = VoxelManip(island_range(x,y,z))
local emi,ema = vm:get_emerged_area()
local dat = vm:get_data()
local ar = VoxelArea:new{MinEdge=emi,MaxEdge=ema}
for x = x-32,x+32 do
for y = y-32,y+32 do
for z = z-32,z+32 do
if dat[ar:index(x,y,z)] ~= air_c then
return false
end
end
end
end
return true
end
local function intersect(a,b)
local ap1,ap2 = a[1],a[2]
local bp1,bp2 = b[1],b[2]
local ax1,ay1,az1 = ap1.x,ap1.y,ap1.z
local ax2,ay2,az2 = ap2.x,ap2.y,ap2.z
local bx1,by1,bz1 = bp1.x,bp1.y,bp1.z
local bx2,by2,bz2 = bp2.x,bp2.y,bp2.z
return
ax1 <= bx2 and
ax2 >= bx1 and
ay1 <= by2 and
ay2 >= by1 and
az1 <= bz2 and
az2 >= bz1
end
local function get_standing_island(name)
local ref = minetest.get_player_by_name(name)
local pos = ref:get_pos()
local islands = {}
for k,v in pairs(cells) do
if intersect({island_range(v.pos.x,v.pos.y,v.pos.z)},{pos,pos}) then
table.insert(islands,{pos=v.pos,owner=nil,valid = not not v.valid,t=cells,k=k})
end
end
for k,v in pairs(players) do
if intersect({island_range(v.pos.x,v.pos.y,v.pos.z)},{pos,pos}) then
table.insert(islands,{pos=v.pos,owner=k,valid = not not v.valid,t=players,k=k})
end
end
if #islands == 0 then
return
end
local closesti = table.remove(islands)
local closestl = vector.length(vector.subtract(closesti.pos,pos))
while #islands > 0 do
local isl = table.remove(islands)
local l = vector.length(vector.subtract(isl.pos,pos))
if l < closestl then
closesti = isl
closestl = l
end
end
return closesti
end
local function gen_island_pos(name)
local x,y,z = 0,0,0
local ok = checkpos(x,y,z)
for k,isl in ipairs(cells) do
if isl and isl.valid then
table.remove(cells,k)
local ip = isl.pos
local ref = minetest.get_player_by_name(name)
local pos = ip
players[name] = {pos = pos, valid = false}
save()
pos = {x=f(pos.x),y=f(pos.y),z=f(pos.z)}
ref:set_pos({x=pos.x,y=pos.y+256,z=pos.z})
return
end
end
while not ok do
x,z = x+math.random(-256,256),z+math.random(-256,256)
y=256+math.random(-64,64)
ok = checkpos(x,y,z)
end
local ip = {x=x,y=y,z=z}
spawn_island(name,ip)
local pl = {
island = pid(x,z),
islandpos = ip,
islandrange = range,
name = name
pos = ip,
valid = false
}
players[name] = pl
cells[pid(x,z)] = pl
save()
end
local updrate = 0.5
@ -157,12 +225,21 @@ minetest.register_globalstep(function(dt)
if to_upd <= 0 then
to_upd = to_upd+updrate
for k,ref in pairs(minetest.get_connected_players()) do
local is = get_standing_island(ref:get_player_name())
if is and is.t == cells and not minetest.check_player_privs(ref,{server = true}) then
cells[is.k].valid = false
end
local p = ref:get_pos()
if p.y < 0 then
ref:set_hp(ref:get_hp()-2,{reason="set_hp"})
if p.y < -128 then
local meta = ref:get_meta()
local pos = minetest.string_to_pos(meta:get_string("islandpos"))
local land = players[ref:get_player_name()]
local pos
if land then
pos = land.pos
elseif minetest.check_player_privs(ref,{interact = true}) then
gen_island_pos(ref:get_player_name())
end
if pos then
pos.y=pos.y+256
ref:set_pos(pos)
@ -173,13 +250,43 @@ minetest.register_globalstep(function(dt)
end
end)
local function get_standing_island(name)
local ref = minetest.get_player_by_name(name)
local pos = ref:get_pos()
local x = math.floor(pos.x/128+.5)
local z = math.floor(pos.z/128+.5)
return pid(x,z)
end
minetest.register_chatcommand("register", {
description = "Register island",
privs = {server = true},
func = function(name,param)
if get_standing_island(name) then
minetest.chat_send_player(name,"There is an island already")
return
end
local ref = minetest.get_player_by_name(name)
local pos = ref:get_pos()
ip = {x=f(pos.x+.5),y=f(pos.y+.5)-11,z=f(pos.z+.5)}
table.insert(cells,{pos=ip, valid=false})
minetest.chat_send_player(name,"OK")
save()
end
})
minetest.register_chatcommand("unregister", {
description = "Unregister island",
privs = {server = true},
func = function(name,param)
local is = get_standing_island(name)
if not is then
minetest.chat_send_player(name,"No island here")
return
end
if is.t == cells then
cells[is.k] = nil
end
if is.t == players then
local nam = is.owner
players[nam] = nil
end
minetest.chat_send_player(name,"OK")
save()
end
})
minetest.register_chatcommand("assign", {
description = "Reassign this island",
@ -190,17 +297,17 @@ minetest.register_chatcommand("assign", {
minetest.chat_send_player(name,"No player "..param)
return
end
players[param] = nil
if not cells[is] then
if players[param] then
local ois = players[param]
table.insert(cells,{pos=ois.pos,valid = false})
players[param] = nil
end
if not is then
minetest.chat_send_player(name,"No island here")
return
end
if not cells[is] then
range = {min={x=x*128-64,y=256-64,z=z*128-64},max={x=x*128+64,y=256+64,z=z*128+64}}
ip = {x=x*128+math.random(-32,32),y=256+math.random(-32,32),z=z*128+math.random(-32,32)}
spawn_island(param,ip)
else
cells[is].name = param
players[name] = {pos = is.pos, valid = is.valid}
is.t[is.k] = nil
end
minetest.chat_send_player(name,"OK")
save()
@ -212,26 +319,31 @@ minetest.register_chatcommand("unassign", {
privs = {server = true},
func = function(name,param)
local is = get_standing_island(name)
if not cells[is] then
minetest.chat_send_player(name,"This cell is not assigned")
if not is then
minetest.chat_send_player(name,"No island here")
return
end
local nam = cells[is].name
players[nam] = nil
cells[is].name = ""
store:set_string(is,"")
if is.t == cells then
minetest.chat_send_player(name,"Island is already unassigned")
return
end
if is.t == players then
local nam = is.owner
players[nam] = nil
table.insert(cells,{pos=is.pos,valid=is.valid})
end
minetest.chat_send_player(name,"OK")
save()
end
})
minetest.register_chatcommand("validate", {
description = "Make this island avaible for newcomers",
description = "Make this island avaible for newcomers, if not owned by a player",
privs = {server = true},
func = function(name,param)
local is = get_standing_island(name)
if cells[is] then
cells[is].valid = true
if is then
is.t[is.k].valid = true
minetest.chat_send_player(name,"OK")
else
minetest.chat_send_player(name,"No island here")
@ -246,8 +358,9 @@ minetest.register_chatcommand("invalidate", {
privs = {server = true},
func = function(name,param)
local is = get_standing_island(name)
if cells[is] then
cells[is].valid = false
if is then
is.t[is.k].valid = false
minetest.chat_send_player(name,"OK")
else
minetest.chat_send_player(name,"No island here")
return
@ -260,15 +373,14 @@ minetest.register_chatcommand("query", {
description = "Query information about this island",
func = function(name,param)
local is = get_standing_island(name)
if cells[is] then
minetest.chat_send_player(name,is..": [")
minetest.chat_send_player(name," owner: "..((cells[is].name == "" and "(none)" or cells[is].name) or "(none)"))
minetest.chat_send_player(name," takeable: "..tostring(cells[is].valid))
minetest.chat_send_player(name," pos: "..minetest.pos_to_string(cells[is].islandpos))
minetest.chat_send_player(name," range: "..minetest.serialize(cells[is].islandrange))
if is then
minetest.chat_send_player(name,"[")
minetest.chat_send_player(name," owner: "..((is.owner == "" and "(none)" or is.owner) or "(none)"))
minetest.chat_send_player(name," takeable: "..tostring(is.valid))
minetest.chat_send_player(name," pos: "..minetest.pos_to_string(is.pos))
minetest.chat_send_player(name,"]")
else
minetest.chat_send_player(name,is..": No island here")
minetest.chat_send_player(name,"No island here")
end
save()
end
@ -280,9 +392,7 @@ minetest.register_chatcommand("reset",{
func = function(name)
local pl = players[name]
if pl then
store:set_string(pl.island,"")
pl.name = nil
pl.valid = false
players[name] = nil
end
gen_island_pos(name)
end
@ -291,18 +401,38 @@ minetest.register_chatcommand("reset",{
minetest.register_on_joinplayer(function(ref)
local meta = ref:get_meta()
local name = ref:get_player_name()
if meta:get_string("island") ~= "" then
if not cells[meta:get_string("island")] then
local pl = {
island = meta:get_string("island"),
islandpos = minetest.string_to_pos(meta:get_string("islandpos")),
islandrange = minetest.deserialize(meta:get_string("islandrange")),
name = name
}
players[name] = pl
cells[meta:get_string("island")] = pl
else
gen_island_pos(name)
if meta:get_string("islandpos") ~= "" then
if not players[name] then
local pos = minetest.string_to_pos(meta:get_string("islandpos"))
local hascell = false
for k,v in pairs(players) do
if vector.length(vector.subtract(v.pos,pos)) < 8 then
hascell = true
break
end
end
while true do
local rem = false
for k,v in pairs(cells) do
if vector.length(vector.subtract(v.pos,pos)) < 8 then
table.remove(cells,k)
rem = true
break
end
end
if not rem then
break
end
end
if not hascell then
local pl = {
pos = pos,
valid = false
}
players[name] = pl
else
gen_island_pos(name)
end
end
save()
meta:set_string("island","")
@ -313,8 +443,33 @@ minetest.register_on_joinplayer(function(ref)
gen_island_pos(name)
else
local p = players[name]
local c = cells[p.island]
if c.name ~= p.name then
if p.islandpos then
players[name] = {pos = p.islandpos, valid = false}
save()
end
local pos = players[name].pos
local hascell = false
for k,v in pairs(players) do
if vector.length(vector.subtract(v.pos,pos)) < 8 and k ~= name then
hascell = true
break
end
end
while true do
local rem = false
for k,v in pairs(cells) do
if vector.length(vector.subtract(v.pos,pos)) < 8 then
table.remove(cells,k)
rem = true
break
end
end
if not rem then
break
end
end
if hascell then
players[name] = nil
gen_island_pos(name)
end
end

View File

@ -1,192 +0,0 @@
-- LUALOCALS < ---------------------------------------------------------
local ipairs, minetest, nodecore, pairs, type
= ipairs, minetest, nodecore, pairs, type
-- LUALOCALS > ---------------------------------------------------------
local modname = minetest.get_current_modname()
local function regterrain(def)
def.name = def.name or def.description:gsub("%W", "_"):lower()
def.fullname = modname .. ":" .. def.name
def.tiles = def.tiles or { def.fullname:gsub("%W", "_") .. ".png" }
def.is_ground_content = true
if def.liquidtype then
def.liquid_alternative_flowing = def.fullname .. "_flowing"
def.liquid_alternative_source = def.fullname .. "_source"
def.fullname = def.fullname .. "_" .. def.liquidtype
def.special_tiles = def.special_tiles or { def.tiles[1], def.tiles[1] }
end
def.mapgen = def.mapgen or { def.name }
minetest.register_node(def.fullname, def)
for _, v in pairs(def.mapgen) do
minetest.register_alias("mapgen_" .. v, def.fullname)
end
end
local function clone(t)
local c = minetest.deserialize(minetest.serialize(t))
for k, v in pairs(t) do
if type(v) == "function" then c[k] = v end
end
return c
end
local function regliquid(def)
local t = clone(def)
t.drawtype = "liquid"
t.liquidtype = "source"
regterrain(t)
t = clone(def)
t.mapgen = { }
t.drawtype = "flowingliquid"
t.liquidtype = "flowing"
t.paramtype2 = "flowingliquid"
regterrain(t)
end
local function anim(name, len)
return {
name = name,
animation = {
type = "vertical_frames",
aspect_w = 16,
aspect_h = 16,
length = len
}
}
end
regliquid({
description = "HM Water",
mapgen = {},
tiles = {anim("nc_terrain_water.png", 4)},
special_tiles = {
anim("nc_terrain_water_flow.png", 4),
anim("nc_terrain_water_flow.png", 4)
},
paramtype = "light",
liquid_viscosity = 1,
liquid_renewable = true,
alpha = 192,
walkable = false,
pointable = false,
diggable = false,
buildable_to = true,
drowning = 1,
drop = "",
groups = {coolant = 1, water = 2, moist = 2},
post_effect_color = {a = 103, r = 30, g = 76, b = 90},
sounds = nodecore.sounds("nc_terrain_watery")
})
local src = modname..":hm_water_source"
local flow = modname..":hm_water_flowing"
nodecore.register_limited_abm({
label = "Water Renew",
interval = 1,
chance = 1,
nodenames = {flow},
neirbours = {src},
action = function(pos, node)
local n2 = minetest.get_node({x=pos.x,y=pos.y-1,z=pos.z}).name
if n2 == flow then
local count = 0
for x=-1,1 do
for y=0,1 do
for z=-1,1 do
if (x*x+y*y+z*z)^0.5 == 1 and minetest.get_node({x=pos.x+x,y=pos.y+y,z=pos.z+z}) == src then
count = count + 1
end
end
end
end
if count >= 2 then
minetest.set_node(pos,{name=src})
end
end
end
})
nodecore.register_limited_abm({
label = "Water Flowing",
interval = 1,
chance = 2,
nodenames = {src},
neighbours = {flow},
action = function(pos, node)
local miny = pos.y
local found = {}
nodecore.scan_flood(pos, 5, function(p)
local nn = minetest.get_node(p).name
if nn == src then return end
if nn ~= flow then return false end
if p.y > miny then return end
if p.y == miny then
found[#found + 1] = p
return
end
miny = p.y
found = {p}
end)
if #found < 1 then return end
local np = nodecore.pickrand(found)
minetest.set_node(np, node)
minetest.set_node(pos, {name = flow, param2 = 7})
end
})
nodecore.register_craft({
label = "melt cobble to lava",
action = "cook",
touchgroups = {flame = 4},
duration = 30,
cookfx = true,
nodes = {
{
match = "nc_terrain:cobble",
replace = "nc_terrain:lava_source"
}
}
})
nodecore.register_cook_abm({nodenames = {"nc_terrain:cobble"}, neighbors = {"group:flame"}})
local src2 = "nc_terrain:lava_source"
local flow2 = "nc_terrain:lava_flowing"
nodecore.register_limited_abm({
label = "Lava Flowing",
interval = 2,
chance = 2,
nodenames = {src2},
neighbours = {flow2},
action = function(pos, node)
local miny = pos.y
local found = {}
nodecore.scan_flood(pos, 5, function(p)
local nn = minetest.get_node(p).name
if nn == src2 then return end
if nn ~= flow2 then return false end
if p.y > miny then return end
if p.y == miny then
found[#found + 1] = p
return
end
miny = p.y
found = {p}
end)
if #found < 1 then return end
local np = nodecore.pickrand(found)
minetest.set_node(np, node)
minetest.set_node(pos, {name = flow2, param2 = 7})
end
})

View File

@ -1,2 +0,0 @@
name = nc_sky_liquids
depends = nc_api, nc_api_craft, nc_terrain