forked from mtcontrib/minetest-mod-snow
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:
parent
1510ced771
commit
efbfa989d2
@ -395,7 +395,8 @@ minetest.override_item("default:snow", {
|
|||||||
{-0.5, -0.5, -0.5, 0.5, -0.5, 0.5},
|
{-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,
|
sunlight_propagates = true,
|
||||||
walkable = true,
|
walkable = true,
|
||||||
node_placement_prediction = "",
|
node_placement_prediction = "",
|
||||||
@ -428,43 +429,71 @@ minetest.override_item("default:snow", {
|
|||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
--Manage snow levels.
|
--Manage snow levels.
|
||||||
on_place = function(itemstack, placer, pointed_thing)
|
on_place = function(itemstack, player, pt)
|
||||||
local under = pointed_thing.under
|
local oldnode_under = minetest.get_node_or_nil(pt.under)
|
||||||
local oldnode_under = minetest.get_node_or_nil(under)
|
if not oldnode_under then
|
||||||
local above = pointed_thing.above
|
return itemstack, false
|
||||||
|
|
||||||
if not oldnode_under
|
|
||||||
or not above then
|
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local olddef_under = ItemStack({name=oldnode_under.name}):get_definition()
|
local olddef_under = minetest.registered_nodes[oldnode_under.name]
|
||||||
olddef_under = olddef_under or minetest.nodedef_default
|
if not olddef_under then
|
||||||
|
return itemstack, false
|
||||||
|
end
|
||||||
|
|
||||||
local place_to
|
|
||||||
-- If node under is buildable_to, place into it instead (eg. snow)
|
-- If node under is buildable_to, place into it instead (eg. snow)
|
||||||
|
local pos, node
|
||||||
if olddef_under.buildable_to then
|
if olddef_under.buildable_to then
|
||||||
place_to = under
|
pos = pt.under
|
||||||
|
node = oldnode_under
|
||||||
else
|
else
|
||||||
-- Place above pointed node
|
pos = pt.above
|
||||||
place_to = 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
|
end
|
||||||
|
|
||||||
local level = minetest.get_node_level(place_to)
|
-- nil player can place (for snowballs)
|
||||||
if level == 63 then
|
if player
|
||||||
minetest.set_node(place_to, {name="default:snowblock"})
|
and minetest.is_protected(pos, player:get_player_name()) then
|
||||||
else
|
return itemstack, false
|
||||||
minetest.set_node_level(place_to, level+7)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if minetest.get_node(place_to).name ~= "default:snow" then
|
if node.name ~= "default:snow" then
|
||||||
local itemstack, placed = minetest.item_place_node(itemstack, placer, pointed_thing)
|
if minetest.get_node{x=pos.x, y=pos.y-1, z=pos.z}.name ==
|
||||||
return itemstack, placed
|
"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
|
end
|
||||||
|
|
||||||
itemstack:take_item()
|
itemstack:take_item()
|
||||||
|
return itemstack, true
|
||||||
return itemstack
|
|
||||||
end,
|
end,
|
||||||
on_use = snow.shoot_snowball
|
on_use = snow.shoot_snowball
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user