move the snow redefinition to nodes.lua

M  src/nodes.lua
M  src/snowball.lua
This commit is contained in:
HybridDog 2016-08-13 13:05:54 +02:00
parent 6488a3b8f5
commit 1c1a5c11b7
2 changed files with 92 additions and 93 deletions

View File

@ -371,3 +371,94 @@ minetest.override_item("default:snowblock", {
-- Thinking in terms of layers, dirt_with_snow could also double as -- Thinking in terms of layers, dirt_with_snow could also double as
-- dirt_with_frost which adds subtlety to the winterscape. ~ LazyJ, 2014_04_04 -- dirt_with_frost which adds subtlety to the winterscape. ~ LazyJ, 2014_04_04
}) })
minetest.override_item("default:snow", {
drop = {
max_items = 2,
items = {
{items = {'snow:moss'}, rarity = 20,},
{items = {'default:snow'},}
}
},
leveled = 7,
node_box = {
type = "leveled",
fixed = {
{-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},
sunlight_propagates = true,
walkable = true,
--Disable placement prediction for snow.
node_placement_prediction = "",
on_construct = function(pos)
pos.y = pos.y-1
local node = minetest.get_node(pos)
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,
--Handle node drops due to node level.
on_dig = function(pos, node, digger)
local level = minetest.get_node_level(pos)
minetest.node_dig(pos, node, digger)
if minetest.get_node(pos).name ~= node.name then
local inv = digger:get_inventory()
if not inv then
return
end
local left = inv:add_item("main", "default:snow "..tostring(level/7-1))
if not left:is_empty() then
minetest.add_item({
x = pos.x + math.random()/2-0.25,
y = pos.y + math.random()/2-0.25,
z = pos.z + math.random()/2-0.25,
}, left)
end
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
end
local olddef_under = ItemStack({name=oldnode_under.name}):get_definition()
olddef_under = olddef_under or minetest.nodedef_default
local place_to
-- If node under is buildable_to, place into it instead (eg. snow)
if olddef_under.buildable_to then
place_to = under
else
-- Place above pointed node
place_to = above
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)
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
end
itemstack:take_item()
return itemstack
end,
on_use = snow.shoot_snowball
})

View File

@ -34,7 +34,7 @@ end
local someone_throwing, just_acitvated local someone_throwing, just_acitvated
--Shoot snowball --Shoot snowball
local function snow_shoot_snowball(item, player) function snow.shoot_snowball(item, player)
local addp = {y = 1.625} -- + (math.random()-0.5)/5} local addp = {y = 1.625} -- + (math.random()-0.5)/5}
local dir = player:get_look_dir() local dir = player:get_look_dir()
local dif = 2*math.sqrt(dir.z*dir.z+dir.x*dir.x) local dif = 2*math.sqrt(dir.z*dir.z+dir.x*dir.x)
@ -252,98 +252,6 @@ minetest.register_node(":default:snow", {
minetest.override_item("default:snow", {
drop = {
max_items = 2,
items = {
{items = {'snow:moss'}, rarity = 20,},
{items = {'default:snow'},}
}
},
leveled = 7,
node_box = {
type = "leveled",
fixed = {
{-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},
sunlight_propagates = true,
walkable = true,
--Disable placement prediction for snow.
node_placement_prediction = "",
on_construct = function(pos)
pos.y = pos.y-1
local node = minetest.get_node(pos)
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,
--Handle node drops due to node level.
on_dig = function(pos, node, digger)
local level = minetest.get_node_level(pos)
minetest.node_dig(pos, node, digger)
if minetest.get_node(pos).name ~= node.name then
local inv = digger:get_inventory()
if not inv then
return
end
local left = inv:add_item("main", "default:snow "..tostring(level/7-1))
if not left:is_empty() then
minetest.add_item({
x = pos.x + math.random()/2-0.25,
y = pos.y + math.random()/2-0.25,
z = pos.z + math.random()/2-0.25,
}, left)
end
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
end
local olddef_under = ItemStack({name=oldnode_under.name}):get_definition()
olddef_under = olddef_under or minetest.nodedef_default
local place_to
-- If node under is buildable_to, place into it instead (eg. snow)
if olddef_under.buildable_to then
place_to = under
else
-- Place above pointed node
place_to = above
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)
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
end
itemstack:take_item()
return itemstack
end,
on_use = snow_shoot_snowball
})
--[[ --[[
A note about default torches, melting, and "buildable_to = true" in default snow. A note about default torches, melting, and "buildable_to = true" in default snow.