mirror of
https://github.com/Splizard/minetest-mod-snow.git
synced 2024-12-29 16:00:16 +01:00
some code updates
This commit is contained in:
parent
6bbc4d359e
commit
c0b40b5cbf
111
init.lua
111
init.lua
@ -71,7 +71,7 @@ dofile(minetest.get_modpath("snow").."/src/falling_snow.lua")
|
|||||||
|
|
||||||
-- Check for "MoreBlocks". If not found, skip this next "dofile".
|
-- Check for "MoreBlocks". If not found, skip this next "dofile".
|
||||||
|
|
||||||
if (minetest.get_modpath("moreblocks")) then
|
if minetest.get_modpath("moreblocks") then
|
||||||
|
|
||||||
dofile(minetest.get_modpath("snow").."/src/stairsplus.lua")
|
dofile(minetest.get_modpath("snow").."/src/stairsplus.lua")
|
||||||
|
|
||||||
@ -81,31 +81,37 @@ end
|
|||||||
--This also takes into account sourrounding snow and makes snow even.
|
--This also takes into account sourrounding snow and makes snow even.
|
||||||
function snow.place(pos)
|
function snow.place(pos)
|
||||||
local node = minetest.get_node_or_nil(pos)
|
local node = minetest.get_node_or_nil(pos)
|
||||||
local drawtype = ""
|
|
||||||
if node and minetest.registered_nodes[node.name] then
|
|
||||||
drawtype = minetest.registered_nodes[node.name].drawtype
|
|
||||||
end
|
|
||||||
|
|
||||||
--Oops, maybe there is no node?
|
--Oops, maybe there is no node?
|
||||||
if node == nil then
|
if not node
|
||||||
|
or not minetest.registered_nodes[node.name] then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local bnode = minetest.get_node({x=pos.x,y=pos.y-1,z=pos.z})
|
local bnode = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z})
|
||||||
if node.name == "default:snow" and minetest.get_node_level(pos) < 63 then
|
if node.name == "default:snow" then
|
||||||
if minetest.get_item_group(bnode.name, "leafdecay") == 0 and snow.is_uneven(pos) ~= true then
|
local level = minetest.get_node_level(pos)
|
||||||
minetest.add_node_level(pos, 7)
|
if level < 63 then
|
||||||
|
if minetest.get_item_group(bnode.name, "leafdecay") == 0
|
||||||
|
and not snow.is_uneven(pos) then
|
||||||
|
minetest.add_node_level(pos, 7)
|
||||||
|
end
|
||||||
|
elseif level == 63 then
|
||||||
|
local p = minetest.find_node_near(pos, 10, "default:dirt_with_grass")
|
||||||
|
if p
|
||||||
|
and minetest.get_node_light(p, 0.5) == 15 then
|
||||||
|
minetest.place_node({x=pos.x, y=pos.y+1, z=pos.z}, {name="default:snow"})
|
||||||
|
else
|
||||||
|
minetest.add_node(pos,{name="default:snowblock"})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
elseif node.name == "default:snow" and minetest.get_node_level(pos) == 63 then
|
elseif node.name ~= "default:ice"
|
||||||
local p = minetest.find_node_near(pos, 10, "default:dirt_with_grass")
|
and bnode.name ~= "air" then
|
||||||
if p and minetest.get_node_light(p, 0.5) == 15 then
|
local drawtype = minetest.registered_nodes[node.name].drawtype
|
||||||
minetest.place_node({x=pos.x,y=pos.y+1,z=pos.z},{name="default:snow"})
|
if drawtype == "normal"
|
||||||
else
|
or drawtype == "allfaces_optional" then
|
||||||
minetest.add_node(pos,{name="default:snowblock"})
|
pos.y = pos.y+1
|
||||||
end
|
minetest.place_node(pos, {name="default:snow"})
|
||||||
elseif node.name ~= "default:ice" and bnode.name ~= "air" then
|
|
||||||
if drawtype == "normal" or drawtype == "allfaces_optional" then
|
|
||||||
minetest.place_node({x=pos.x,y=pos.y+1,z=pos.z}, {name="default:snow"})
|
|
||||||
elseif drawtype == "plantlike" then
|
elseif drawtype == "plantlike" then
|
||||||
pos.y = pos.y - 1
|
pos.y = pos.y - 1
|
||||||
if minetest.get_node(pos).name == "default:dirt_with_grass" then
|
if minetest.get_node(pos).name == "default:dirt_with_grass" then
|
||||||
@ -117,9 +123,8 @@ end
|
|||||||
|
|
||||||
-- Checks if the snow level is even at any given pos.
|
-- Checks if the snow level is even at any given pos.
|
||||||
-- Smooth Snow
|
-- Smooth Snow
|
||||||
local smooth_snow = snow.smooth_snow
|
if snow.smooth_snow then
|
||||||
snow.is_uneven = function(pos)
|
snow.is_uneven = function(pos)
|
||||||
if smooth_snow then
|
|
||||||
local num = minetest.get_node_level(pos)
|
local num = minetest.get_node_level(pos)
|
||||||
local get_node = minetest.get_node
|
local get_node = minetest.get_node
|
||||||
local add_node = minetest.add_node
|
local add_node = minetest.add_node
|
||||||
@ -127,40 +132,46 @@ snow.is_uneven = function(pos)
|
|||||||
local foundx
|
local foundx
|
||||||
local foundy
|
local foundy
|
||||||
local foundz
|
local foundz
|
||||||
for x=-1,1 do
|
for z = -1,1 do
|
||||||
for z=-1,1 do
|
for x = -1,1 do
|
||||||
local node = get_node({x=pos.x+x,y=pos.y,z=pos.z+z})
|
local p = {x=pos.x+x, y=pos.y, z=pos.z+z}
|
||||||
local bnode = get_node({x=pos.x+x,y=pos.y-1,z=pos.z+z})
|
local node = get_node(p)
|
||||||
local drawtype
|
p.y = p.y-1
|
||||||
if node and minetest.registered_nodes[node.name] then
|
local bnode = get_node(p)
|
||||||
drawtype = minetest.registered_nodes[node.name].drawtype
|
|
||||||
end
|
if node
|
||||||
|
and minetest.registered_nodes[node.name]
|
||||||
if drawtype == "plantlike" then
|
and minetest.registered_nodes[node.name].drawtype == "plantlike"
|
||||||
if bnode.name == "default:dirt_with_grass" then
|
and bnode.name == "default:dirt_with_grass" then
|
||||||
add_node({x=pos.x+x,y=pos.y-1,z=pos.z+z}, {name="default:dirt_with_snow"})
|
add_node(p, {name="default:dirt_with_snow"})
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
p.y = p.y+1
|
||||||
|
if not (x == 0 and z == 0)
|
||||||
|
and node.name == "default:snow"
|
||||||
|
and minetest.get_node_level(p) < num then
|
||||||
|
found = true
|
||||||
|
foundx = x
|
||||||
|
foundz = z
|
||||||
|
elseif node.name == "air"
|
||||||
|
and bnode.name ~= "air"
|
||||||
|
and bnode.name ~= "default:snow" then
|
||||||
|
p.y = p.y-1
|
||||||
|
snow.place(p)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if (not(x == 0 and y == 0)) and node.name == "default:snow" and minetest.get_node_level({x=pos.x+x,y=pos.y,z=pos.z+z}) < num then
|
|
||||||
found = true
|
|
||||||
foundx = x
|
|
||||||
foundz=z
|
|
||||||
elseif node.name == "air" and bnode.name ~= "air" then
|
|
||||||
if not (bnode.name == "default:snow") then
|
|
||||||
snow.place({x=pos.x+x,y=pos.y-1,z=pos.z+z})
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
if found then
|
if found then
|
||||||
local node = get_node({x=pos.x+foundx,y=pos.y,z=pos.z+foundz})
|
local p = {x=pos.x+foundx, y=pos.y, z=pos.z+foundz}
|
||||||
if snow.is_uneven({x=pos.x+foundx,y=pos.y,z=pos.z+foundz}) ~= true then
|
if snow.is_uneven(p) ~= true then
|
||||||
minetest.add_node_level({x=pos.x+foundx,y=pos.y,z=pos.z+foundz}, 7)
|
minetest.add_node_level(p, 7)
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
snow.is_uneven = function()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -203,7 +203,7 @@ for _, name in pairs(recycle_default_slabs) do
|
|||||||
recipe = {
|
recipe = {
|
||||||
"snow:slab_"..subname_default,
|
"snow:slab_"..subname_default,
|
||||||
"snow:slab_"..subname_default,
|
"snow:slab_"..subname_default,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -229,6 +229,6 @@ for _, name in pairs(recycle_snowmod_slabs) do
|
|||||||
recipe = {
|
recipe = {
|
||||||
"snow:slab_"..subname_snowmod,
|
"snow:slab_"..subname_snowmod,
|
||||||
"snow:slab_"..subname_snowmod,
|
"snow:slab_"..subname_snowmod,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
108
src/mapgen.lua
108
src/mapgen.lua
@ -72,20 +72,21 @@ function snow.make_pine(pos,snow,xmas)
|
|||||||
local perlin1 = minetest.get_perlin(112,3, 0.5, 150)
|
local perlin1 = minetest.get_perlin(112,3, 0.5, 150)
|
||||||
local try_node = function(pos, node)
|
local try_node = function(pos, node)
|
||||||
local n = minetest.get_node(pos).name
|
local n = minetest.get_node(pos).name
|
||||||
if n == "air" or n == "ignore" then
|
if n == "air"
|
||||||
minetest.add_node(pos,node)
|
or n == "ignore" then
|
||||||
|
minetest.add_node(pos, node)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
--Clear ground.
|
--Clear ground.
|
||||||
for x=-1,1 do
|
for z = -1,1 do
|
||||||
for z=-1,1 do
|
for x = -1,1 do
|
||||||
if minetest.get_node({x=pos.x+x,y=pos.y,z=pos.z+z}).name == "default:snow" then
|
local p = {x=pos.x+x,y=pos.y,z=pos.z+z}
|
||||||
minetest.remove_node({x=pos.x+x,y=pos.y,z=pos.z+z})
|
local nd = minetest.get_node(p).name
|
||||||
|
if nd == "default:snow"
|
||||||
|
or nd == "default:snowblock" then
|
||||||
|
minetest.remove_node(p)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
if minetest.get_node({x=pos.x+x,y=pos.y,z=pos.z+z}).name == "default:snowblock" then
|
|
||||||
minetest.remove_node({x=pos.x+x,y=pos.y,z=pos.z+z})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
if xmas then
|
if xmas then
|
||||||
minetest.remove_node(pos)
|
minetest.remove_node(pos)
|
||||||
@ -107,7 +108,8 @@ function snow.make_pine(pos,snow,xmas)
|
|||||||
end
|
end
|
||||||
if xmas then
|
if xmas then
|
||||||
try_node({x=pos.x,y=pos.y+7,z=pos.z},{name="snow:star_lit"}) -- Added lit star. ~ LazyJ
|
try_node({x=pos.x,y=pos.y+7,z=pos.z},{name="snow:star_lit"}) -- Added lit star. ~ LazyJ
|
||||||
elseif snow and perlin1:get2d({x=pos.x,y=pos.z}) > 0.53 then
|
elseif snow
|
||||||
|
and perlin1:get2d({x=pos.x,y=pos.z}) > 0.53 then
|
||||||
try_node({x=pos.x,y=pos.y+7,z=pos.z},{name="default:snow"})
|
try_node({x=pos.x,y=pos.y+7,z=pos.z},{name="default:snow"})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -122,59 +124,61 @@ function snow.voxelmanip_pine(pos,a,data)
|
|||||||
local c_air = minetest.get_content_id("air")
|
local c_air = minetest.get_content_id("air")
|
||||||
|
|
||||||
local perlin1 = minetest.get_perlin(112,3, 0.5, 150)
|
local perlin1 = minetest.get_perlin(112,3, 0.5, 150)
|
||||||
--Clear ground.
|
for z = -1,1 do
|
||||||
for x=-1,1 do
|
local z = pos.z + z
|
||||||
for z=-1,1 do
|
for x = -1,1 do
|
||||||
local node = a:index(pos.x+x,pos.y,pos.z+z)
|
local x = pos.x + x
|
||||||
if data[node] == c_snow then
|
|
||||||
data[node] = c_air
|
--Clear ground.
|
||||||
end
|
local node = a:index(x,pos.y,z)
|
||||||
end
|
if data[node] == c_snow then
|
||||||
end
|
data[node] = c_air
|
||||||
--Make tree.
|
end
|
||||||
for i=0, 4 do
|
|
||||||
if i==1 or i==2 then
|
--Make tree.
|
||||||
for x=-1,1 do
|
for i = 1,2 do
|
||||||
for z=-1,1 do
|
|
||||||
local x = pos.x + x
|
|
||||||
local z = pos.z + z
|
|
||||||
local node = a:index(x,pos.y+i,z)
|
local node = a:index(x,pos.y+i,z)
|
||||||
data[node] = c_pine_needles
|
data[node] = c_pine_needles
|
||||||
if snow and x ~= 0 and z ~= 0 and perlin1:get2d({x=x,y=z}) > 0.53 then
|
if snow
|
||||||
|
and x ~= 0
|
||||||
|
and z ~= 0
|
||||||
|
and perlin1:get2d({x=x,y=z}) > 0.53 then
|
||||||
local abovenode = a:index(x,pos.y+i+1,z)
|
local abovenode = a:index(x,pos.y+i+1,z)
|
||||||
data[abovenode] = c_snow
|
data[abovenode] = c_snow
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
for i=3, 4 do
|
||||||
|
local x = pos.x
|
||||||
|
local y = pos.y+i
|
||||||
|
local z = pos.z
|
||||||
|
data[a:index(x+1,y,z)] = c_pine_needles
|
||||||
|
data[a:index(x-1,y,z)] = c_pine_needles
|
||||||
|
data[a:index(x,y,z+1)] = c_pine_needles
|
||||||
|
data[a:index(x,y,z-1)] = c_pine_needles
|
||||||
|
if snow then
|
||||||
|
if perlin1:get2d({x=x+1,y=z}) > 0.53 then
|
||||||
|
data[a:index(x+1,y+1,z)] = c_snow
|
||||||
|
end
|
||||||
|
if perlin1:get2d({x=x+1,y=z}) > 0.53 then
|
||||||
|
data[a:index(x-1,y+1,z)] = c_snow
|
||||||
|
end
|
||||||
|
if perlin1:get2d({x=x,y=z+1}) > 0.53 then
|
||||||
|
data[a:index(x,y+1,z+1)] = c_snow
|
||||||
|
end
|
||||||
|
if perlin1:get2d({x=x,y=z-1}) > 0.53 then
|
||||||
|
data[a:index(x,y+1,z-1)] = c_snow
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if i==3 or i==4 then
|
end
|
||||||
local x = pos.x
|
for i=0, 4 do
|
||||||
local y = pos.y+i
|
|
||||||
local z = pos.z
|
|
||||||
data[a:index(x+1,y,z)] = c_pine_needles
|
|
||||||
data[a:index(x-1,y,z)] = c_pine_needles
|
|
||||||
data[a:index(x,y,z+1)] = c_pine_needles
|
|
||||||
data[a:index(x,y,z-1)] = c_pine_needles
|
|
||||||
if snow then
|
|
||||||
if perlin1:get2d({x=x+1,y=z}) > 0.53 then
|
|
||||||
data[a:index(x+1,y+1,z)] = c_snow
|
|
||||||
end
|
|
||||||
if perlin1:get2d({x=x+1,y=z}) > 0.53 then
|
|
||||||
data[a:index(x-1,y+1,z)] = c_snow
|
|
||||||
end
|
|
||||||
if perlin1:get2d({x=x,y=z+1}) > 0.53 then
|
|
||||||
data[a:index(x,y+1,z+1)] = c_snow
|
|
||||||
end
|
|
||||||
if perlin1:get2d({x=x,y=z-1}) > 0.53 then
|
|
||||||
data[a:index(x,y+1,z-1)] = c_snow
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
data[a:index(pos.x,pos.y+i,pos.z)] = c_pinetree
|
data[a:index(pos.x,pos.y+i,pos.z)] = c_pinetree
|
||||||
end
|
end
|
||||||
data[a:index(pos.x,pos.y+5,pos.z)] = c_pine_needles
|
data[a:index(pos.x,pos.y+5,pos.z)] = c_pine_needles
|
||||||
data[a:index(pos.x,pos.y+6,pos.z)] = c_pine_needles
|
data[a:index(pos.x,pos.y+6,pos.z)] = c_pine_needles
|
||||||
if snow and perlin1:get2d({x=pos.x,y=pos.z}) > 0.53 then
|
if snow
|
||||||
|
and perlin1:get2d({x=pos.x,y=pos.z}) > 0.53 then
|
||||||
data[a:index(pos.x,pos.y+7,pos.z)] = c_snow
|
data[a:index(pos.x,pos.y+7,pos.z)] = c_snow
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -139,7 +139,8 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
|||||||
local ground_y = nil
|
local ground_y = nil
|
||||||
for y = maxp.y, minp.y, -1 do
|
for y = maxp.y, minp.y, -1 do
|
||||||
local nodid = data[area:index(x, y, z)]
|
local nodid = data[area:index(x, y, z)]
|
||||||
if nodid ~= c_air and nodid ~= c_ignore then
|
if nodid ~= c_air
|
||||||
|
and nodid ~= c_ignore then
|
||||||
ground_y = y
|
ground_y = y
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
@ -197,8 +197,9 @@ minetest.register_node("snow:star", {
|
|||||||
--groups = {snappy=2,dig_immediate=3},
|
--groups = {snappy=2,dig_immediate=3},
|
||||||
groups = {cracky=1, crumbly=1, choppy=1, oddly_breakable_by_hand=1}, -- Don't want the ornament breaking too easily because you have to punch it to turn it on and off. ~ LazyJ
|
groups = {cracky=1, crumbly=1, choppy=1, oddly_breakable_by_hand=1}, -- Don't want the ornament breaking too easily because you have to punch it to turn it on and off. ~ LazyJ
|
||||||
sounds = default.node_sound_glass_defaults({dig = {name="default_glass_footstep", gain=0.2}}), -- Breaking "glass" sound makes it sound like a real, broken, Xmas tree ornament (Sorry, Mom!). ;)- ~ LazyJ
|
sounds = default.node_sound_glass_defaults({dig = {name="default_glass_footstep", gain=0.2}}), -- Breaking "glass" sound makes it sound like a real, broken, Xmas tree ornament (Sorry, Mom!). ;)- ~ LazyJ
|
||||||
on_punch = function(pos, node, puncher) -- Added a "lit" star that can be punched on or off depending on your preference. ~ LazyJ
|
on_punch = function(pos, node) -- Added a "lit" star that can be punched on or off depending on your preference. ~ LazyJ
|
||||||
minetest.set_node(pos, {name = "snow:star_lit"})
|
node.name = "snow:star_lit"
|
||||||
|
minetest.set_node(pos, node)
|
||||||
nodeupdate(pos)
|
nodeupdate(pos)
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
@ -217,8 +218,9 @@ minetest.register_node("snow:star_lit", {
|
|||||||
drop = "snow:star",
|
drop = "snow:star",
|
||||||
groups = {cracky=1, crumbly=1, choppy=1, oddly_breakable_by_hand=1, not_in_creative_inventory=1},
|
groups = {cracky=1, crumbly=1, choppy=1, oddly_breakable_by_hand=1, not_in_creative_inventory=1},
|
||||||
sounds = default.node_sound_glass_defaults({dig = {name="default_glass_footstep", gain=0.2}}),
|
sounds = default.node_sound_glass_defaults({dig = {name="default_glass_footstep", gain=0.2}}),
|
||||||
on_punch = function(pos, node, puncher)
|
on_punch = function(pos, node)
|
||||||
minetest.set_node(pos, {name = "snow:star"})
|
node.name = "snow:star"
|
||||||
|
minetest.set_node(pos, node)
|
||||||
nodeupdate(pos)
|
nodeupdate(pos)
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
@ -328,7 +330,7 @@ minetest.override_item("default:ice", {
|
|||||||
on_construct = snow_onto_dirt,
|
on_construct = snow_onto_dirt,
|
||||||
liquids_pointable = true,
|
liquids_pointable = true,
|
||||||
--Make ice freeze over when placed by a maximum of 10 blocks.
|
--Make ice freeze over when placed by a maximum of 10 blocks.
|
||||||
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
after_place_node = function(pos)
|
||||||
minetest.set_node(pos, {name="default:ice", param2=math.random(0,10)})
|
minetest.set_node(pos, {name="default:ice", param2=math.random(0,10)})
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
@ -31,17 +31,20 @@ snow_snowball_ENTITY={
|
|||||||
|
|
||||||
--Snowball_entity.on_step()--> called when snowball is moving.
|
--Snowball_entity.on_step()--> called when snowball is moving.
|
||||||
snow_snowball_ENTITY.on_step = function(self, dtime)
|
snow_snowball_ENTITY.on_step = function(self, dtime)
|
||||||
self.timer=self.timer+dtime
|
self.timer = self.timer+dtime
|
||||||
|
if self.timer > 600 then
|
||||||
|
-- 10 minutes are too long for a snowball to fly somewhere
|
||||||
|
self.object:remove()
|
||||||
|
end
|
||||||
local pos = self.object:getpos()
|
local pos = self.object:getpos()
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
|
|
||||||
--Become item when hitting a node.
|
--Become item when hitting a node.
|
||||||
if self.lastpos.x~=nil then --If there is no lastpos for some reason. ~ Splizard
|
if self.lastpos.x then --If there is no lastpos for some reason. ~ Splizard
|
||||||
-- Check to see what is one node above where the snow is
|
-- Check to see what is one node above where the snow is
|
||||||
-- going to be placed. ~ LazyJ, 2014_04_08
|
-- going to be placed. ~ LazyJ, 2014_04_08
|
||||||
local abovesnowballtarget = {x=pos.x, y=pos.y+1, z=pos.z}
|
|
||||||
-- Identify the name of the node that was found above. ~ LazyJ, 2014_04_08
|
-- Identify the name of the node that was found above. ~ LazyJ, 2014_04_08
|
||||||
local findwhatisabove = minetest.get_node(abovesnowballtarget).name
|
local findwhatisabove = minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z}).name
|
||||||
-- If the node above is air, then it's OK to go on to the next step. ~ LazyJ, 2014_04_08
|
-- If the node above is air, then it's OK to go on to the next step. ~ LazyJ, 2014_04_08
|
||||||
if findwhatisabove == "air" then
|
if findwhatisabove == "air" then
|
||||||
-- If the node where the snow is going is anything except air, then it's OK to put
|
-- If the node where the snow is going is anything except air, then it's OK to put
|
||||||
@ -54,12 +57,12 @@ snow_snowball_ENTITY.on_step = function(self, dtime)
|
|||||||
--minetest.place_node({x=pos.x, y=pos.y+2, z=pos.z}, {name="default:snow"})
|
--minetest.place_node({x=pos.x, y=pos.y+2, z=pos.z}, {name="default:snow"})
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
end
|
end
|
||||||
else -- If findwhatisabove is not equal to "air" then cancel the snowball
|
else -- If findwhatisabove is not equal to "air" then cancel the snowball
|
||||||
-- with self.object:remove() ~ LazyJ, 2014_04_08
|
-- with self.object:remove() ~ LazyJ, 2014_04_08
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
self.lastpos={x=pos.x, y=pos.y, z=pos.z}
|
self.lastpos = vector.new(pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -142,9 +145,12 @@ minetest.override_item("default:snow", {
|
|||||||
--Disable placement prediction for snow.
|
--Disable placement prediction for snow.
|
||||||
node_placement_prediction = "",
|
node_placement_prediction = "",
|
||||||
on_construct = function(pos)
|
on_construct = function(pos)
|
||||||
if minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name == "default:dirt_with_grass"
|
pos.y = pos.y-1
|
||||||
or minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name == "default:dirt" then
|
local node = minetest.get_node(pos)
|
||||||
minetest.set_node({x=pos.x, y=pos.y-1, z=pos.z}, {name="default:dirt_with_snow"})
|
if node.name == "default:dirt_with_grass"
|
||||||
|
or node.name == "default:dirt" then
|
||||||
|
node.name = "default:dirt_with_snow"
|
||||||
|
minetest.set_node(pos, node)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
--Remove dirt_with_snow and replace with dirt_with_grass.
|
--Remove dirt_with_snow and replace with dirt_with_grass.
|
||||||
@ -158,57 +164,52 @@ minetest.override_item("default:snow", {
|
|||||||
local level = minetest.get_node_level(pos)
|
local level = minetest.get_node_level(pos)
|
||||||
minetest.node_dig(pos, node, digger)
|
minetest.node_dig(pos, node, digger)
|
||||||
if minetest.get_node(pos).name ~= node.name then
|
if minetest.get_node(pos).name ~= node.name then
|
||||||
if digger:get_inventory() then
|
local inv = digger:get_inventory()
|
||||||
local _, dropped_item
|
if not inv then
|
||||||
local left = digger:get_inventory():add_item("main", "default:snow "..tostring(level/7-1))
|
return
|
||||||
if not left:is_empty() then
|
end
|
||||||
local p = {
|
local left = inv:add_item("main", "default:snow "..tostring(level/7-1))
|
||||||
x = pos.x + math.random()/2-0.25,
|
if not left:is_empty() then
|
||||||
y = pos.y + math.random()/2-0.25,
|
local p = {
|
||||||
z = pos.z + math.random()/2-0.25,
|
x = pos.x + math.random()/2-0.25,
|
||||||
}
|
y = pos.y + math.random()/2-0.25,
|
||||||
minetest.add_item(p, left)
|
z = pos.z + math.random()/2-0.25,
|
||||||
end
|
}
|
||||||
|
minetest.add_item(p, left)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
--Manage snow levels.
|
--Manage snow levels.
|
||||||
on_place = function(itemstack, placer, pointed_thing)
|
on_place = function(itemstack, placer, pointed_thing)
|
||||||
local node
|
|
||||||
local above
|
|
||||||
local level
|
|
||||||
|
|
||||||
local under = pointed_thing.under
|
local under = pointed_thing.under
|
||||||
local oldnode_under = minetest.get_node_or_nil(under)
|
local oldnode_under = minetest.get_node_or_nil(under)
|
||||||
local above = pointed_thing.above
|
local above = pointed_thing.above
|
||||||
local oldnode_above = minetest.get_node_or_nil(above)
|
|
||||||
|
|
||||||
if not oldnode_under or not oldnode_above then
|
if not oldnode_under
|
||||||
|
or not above then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local olddef_under = ItemStack({name=oldnode_under.name}):get_definition()
|
local olddef_under = ItemStack({name=oldnode_under.name}):get_definition()
|
||||||
olddef_under = olddef_under or minetest.nodedef_default
|
olddef_under = olddef_under or minetest.nodedef_default
|
||||||
local olddef_above = ItemStack({name=oldnode_above.name}):get_definition()
|
|
||||||
olddef_above = olddef_above or minetest.nodedef_default
|
|
||||||
|
|
||||||
-- Place above pointed node
|
local place_to
|
||||||
local place_to = {x = above.x, y = above.y, z = above.z}
|
|
||||||
|
|
||||||
-- If node under is buildable_to, place into it instead (eg. snow)
|
-- If node under is buildable_to, place into it instead (eg. snow)
|
||||||
if olddef_under.buildable_to then
|
if olddef_under.buildable_to then
|
||||||
place_to = {x = under.x, y = under.y, z = under.z}
|
place_to = under
|
||||||
|
else
|
||||||
|
-- Place above pointed node
|
||||||
|
place_to = above
|
||||||
end
|
end
|
||||||
|
|
||||||
node = minetest.get_node(place_to)
|
local level = minetest.get_node_level(place_to)
|
||||||
level = minetest.get_node_level(place_to)
|
|
||||||
if level == 63 then
|
if level == 63 then
|
||||||
minetest.set_node(place_to, {name="default:snowblock"})
|
minetest.set_node(place_to, {name="default:snowblock"})
|
||||||
else
|
else
|
||||||
minetest.set_node_level(place_to, level+7)
|
minetest.set_node_level(place_to, level+7)
|
||||||
end
|
end
|
||||||
|
|
||||||
if node.name ~= "default:snow" then
|
if minetest.get_node(place_to).name ~= "default:snow" then
|
||||||
local itemstack, placed = minetest.item_place_node(itemstack, placer, pointed_thing)
|
local itemstack, placed = minetest.item_place_node(itemstack, placer, pointed_thing)
|
||||||
return itemstack, placed
|
return itemstack, placed
|
||||||
end
|
end
|
||||||
|
47
src/util.lua
47
src/util.lua
@ -79,7 +79,9 @@ end
|
|||||||
|
|
||||||
for i,v in pairs(snow) do
|
for i,v in pairs(snow) do
|
||||||
local t = type(v)
|
local t = type(v)
|
||||||
if t == "string" or t == "number" or t == "boolean" then
|
if t == "string"
|
||||||
|
or t == "number"
|
||||||
|
or t == "boolean" then
|
||||||
local v = minetest.setting_get("snow_"..i)
|
local v = minetest.setting_get("snow_"..i)
|
||||||
if v ~= nil then
|
if v ~= nil then
|
||||||
if v == "true" then v = true end
|
if v == "true" then v = true end
|
||||||
@ -99,7 +101,8 @@ if minetest.register_on_mapgen_init then
|
|||||||
else
|
else
|
||||||
snow.legacy = true
|
snow.legacy = true
|
||||||
end
|
end
|
||||||
if config and snow.legacy ~= config.legacy then
|
if config
|
||||||
|
and snow.legacy ~= config.legacy then
|
||||||
saveConfig(minetest.get_modpath("snow").."/config.txt", snow, doc)
|
saveConfig(minetest.get_modpath("snow").."/config.txt", snow, doc)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -110,7 +113,8 @@ local get_formspec = function()
|
|||||||
local formspec = "label[0,-0.3;Settings:]"
|
local formspec = "label[0,-0.3;Settings:]"
|
||||||
for i,v in pairs(snow) do
|
for i,v in pairs(snow) do
|
||||||
local t = type(v)
|
local t = type(v)
|
||||||
if t == "string" or t == "number" then
|
if t == "string"
|
||||||
|
or t == "number" then
|
||||||
p = p + 1.5
|
p = p + 1.5
|
||||||
formspec = formspec.."field[0.3,"..p..";2,1;snow:"..i..";"..i..";"..v.."]"
|
formspec = formspec.."field[0.3,"..p..";2,1;snow:"..i..";"..i..";"..v.."]"
|
||||||
elseif t == "boolean" then
|
elseif t == "boolean" then
|
||||||
@ -124,22 +128,27 @@ local get_formspec = function()
|
|||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||||
if formname == "snow:menu" then
|
if formname ~= "snow:menu" then
|
||||||
for i,v in pairs(snow) do
|
return
|
||||||
local t = type(v)
|
end
|
||||||
if t == "string" or t == "number" or t == "boolean" then
|
for i,v in pairs(snow) do
|
||||||
if fields["snow:"..i] then
|
local t = type(v)
|
||||||
if t == "string" then
|
if t == "string" or t == "number" or t == "boolean" then
|
||||||
snow[i] = fields["snow:"..i]
|
local field = fields["snow:"..i]
|
||||||
|
if field then
|
||||||
|
if t == "string" then
|
||||||
|
snow[i] = field
|
||||||
|
end
|
||||||
|
if t == "number" then
|
||||||
|
snow[i] = tonumber(field)
|
||||||
|
end
|
||||||
|
if t == "boolean" then
|
||||||
|
if field == "true" then
|
||||||
|
snow[i] = true
|
||||||
|
elseif field == "false" then
|
||||||
|
snow[i] = false
|
||||||
end
|
end
|
||||||
if t == "number" then
|
end
|
||||||
snow[i] = tonumber(fields["snow:"..i])
|
|
||||||
end
|
|
||||||
if t == "boolean" then
|
|
||||||
if fields["snow:"..i] == "true" then snow[i] = true end
|
|
||||||
if fields["snow:"..i] == "false" then snow[i] = false end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -149,7 +158,7 @@ end)
|
|||||||
minetest.register_chatcommand("snow", {
|
minetest.register_chatcommand("snow", {
|
||||||
description = "Show a menu for various actions",
|
description = "Show a menu for various actions",
|
||||||
privs = {server=true},
|
privs = {server=true},
|
||||||
func = function(name, param)
|
func = function(name)
|
||||||
minetest.show_formspec(name, "snow:menu", get_formspec())
|
minetest.show_formspec(name, "snow:menu", get_formspec())
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user