1
0
mirror of https://github.com/Splizard/minetest-mod-snow.git synced 2024-12-27 15:10:20 +01:00

Fix snow placement bug due to levelled

Before, when placing snow one node above snow, the lower snow node grew and didn't turn into a snowblock

Also, test for protection
This commit is contained in:
Hybrid Dog 2018-03-20 13:51:05 +01:00
parent 1510ced771
commit efbfa989d2

View File

@ -395,7 +395,8 @@ minetest.override_item("default:snow", {
{-0.5, -0.5, -0.5, 0.5, -0.5, 0.5},
},
},
groups = {cracky=3, crumbly=3, choppy=3, oddly_breakable_by_hand=3, falling_node=1, melts=2, float=1},
groups = {cracky=3, crumbly=3, choppy=3, oddly_breakable_by_hand=3,
falling_node=1, melts=2, float=1},
sunlight_propagates = true,
walkable = true,
node_placement_prediction = "",
@ -428,43 +429,71 @@ minetest.override_item("default:snow", {
end
end,
--Manage snow levels.
on_place = function(itemstack, placer, pointed_thing)
local under = pointed_thing.under
local oldnode_under = minetest.get_node_or_nil(under)
local above = pointed_thing.above
if not oldnode_under
or not above then
return
on_place = function(itemstack, player, pt)
local oldnode_under = minetest.get_node_or_nil(pt.under)
if not oldnode_under then
return itemstack, false
end
local olddef_under = ItemStack({name=oldnode_under.name}):get_definition()
olddef_under = olddef_under or minetest.nodedef_default
local olddef_under = minetest.registered_nodes[oldnode_under.name]
if not olddef_under then
return itemstack, false
end
local place_to
-- If node under is buildable_to, place into it instead (eg. snow)
local pos, node
if olddef_under.buildable_to then
place_to = under
pos = pt.under
node = oldnode_under
else
-- Place above pointed node
place_to = above
pos = pt.above
node = minetest.get_node(pos)
local def = minetest.registered_nodes[node.name]
if not def
or not def.buildable_to then
return itemstack, false
end
end
local level = minetest.get_node_level(place_to)
if level == 63 then
minetest.set_node(place_to, {name="default:snowblock"})
else
minetest.set_node_level(place_to, level+7)
-- nil player can place (for snowballs)
if player
and minetest.is_protected(pos, player:get_player_name()) then
return itemstack, false
end
if minetest.get_node(place_to).name ~= "default:snow" then
local itemstack, placed = minetest.item_place_node(itemstack, placer, pointed_thing)
return itemstack, placed
if node.name ~= "default:snow" then
if minetest.get_node{x=pos.x, y=pos.y-1, z=pos.z}.name ==
"default:snow" then
-- grow the snow below (fixes levelled problem)
pos.y = pos.y - 1
else
-- place a snow
return minetest.item_place_node(itemstack, player, pt)
end
end
-- grow the snow
local level = minetest.get_node_level(pos)
level = level + 7
if level < 64 then
minetest.set_node_level(pos, level)
else
-- place a snowblock and snow onto it if possible
local p = {x=pos.x, y=pos.y+1, z=pos.z}
local def = minetest.registered_nodes[minetest.get_node(p).name]
if not def
or not def.buildable_to then
return itemstack, false
end
minetest.set_node(pos, {name="default:snowblock"})
minetest.set_node(p, {name="default:snow"})
level = math.max(level - 64, 7)
minetest.set_node_level(p, level)
end
itemstack:take_item()
return itemstack
return itemstack, true
end,
on_use = snow.shoot_snowball
})