forked from mtcontrib/minetest-mod-snow
Put all the extra lua files in a src directory.
(This cleans up the folder for users, who don't want to see all those strange files)
This commit is contained in:
175
src/abms.lua
Normal file
175
src/abms.lua
Normal file
@ -0,0 +1,175 @@
|
||||
--Backwards Compatability.
|
||||
minetest.register_abm({
|
||||
nodenames = {"snow:snow1","snow:snow2","snow:snow3","gsnow4","snow:snow5","snow:snow6","snow:snow7","snow:snow8"},
|
||||
interval = 1,
|
||||
chance = 1,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
local level = 7*(tonumber(node.name:sub(-1)))
|
||||
minetest.add_node(pos,{name="default:snow"})
|
||||
minetest.set_node_level(pos, level)
|
||||
end,
|
||||
})
|
||||
|
||||
|
||||
|
||||
-- Added to change dirt_with_snow to dirt if covered with blocks that don't let light through (sunlight_propagates) or have a light paramtype and liquidtype combination. ~ LazyJ, 2014_03_08
|
||||
|
||||
minetest.register_abm({
|
||||
nodenames = {"default:dirt_with_snow"},
|
||||
interval = 2,
|
||||
chance = 20,
|
||||
action = function(pos, node)
|
||||
local above = {x=pos.x, y=pos.y+1, z=pos.z}
|
||||
local name = minetest.get_node(above).name
|
||||
local nodedef = minetest.registered_nodes[name]
|
||||
if name ~= "ignore" and nodedef
|
||||
and not ((nodedef.sunlight_propagates or nodedef.paramtype == "light")
|
||||
and nodedef.liquidtype == "none") then
|
||||
minetest.set_node(pos, {name = "default:dirt"})
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
|
||||
|
||||
--Melting
|
||||
--Any node part of the group melting will melt when near warm nodes such as lava, fire, torches, etc.
|
||||
--The amount of water that replaces the node is defined by the number on the group:
|
||||
--1: one water_source
|
||||
--2: four water_flowings
|
||||
--3: one water_flowing
|
||||
|
||||
minetest.register_abm({
|
||||
nodenames = {"group:melts"},
|
||||
neighbors = {"group:igniter","default:torch","default:furnace_active","group:hot"},
|
||||
interval = 2,
|
||||
chance = 2,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
local intensity = minetest.get_item_group(node.name,"melts")
|
||||
if intensity == 1 then
|
||||
minetest.add_node(pos,{name="default:water_source"})
|
||||
elseif intensity == 2 then
|
||||
--[[ This was causing "melts=2" nodes to just disappear so I changed it to replace the
|
||||
node with a water_source for a couple seconds and then replace the water_source with
|
||||
air. This way it made a watery mess that quickly evaporated. ~ LazyJ 2014_04_24
|
||||
local check_place = function(pos,node)
|
||||
if minetest.get_node(pos).name == "air" then
|
||||
minetest.place_node(pos,node)
|
||||
end
|
||||
end
|
||||
minetest.add_node(pos,{name="default:water_flowing"})
|
||||
check_place({x=pos.x+1,y=pos.y,z=pos.z},{name="default:water_flowing"})
|
||||
check_place({x=pos.x-1,y=pos.y,z=pos.z},{name="default:water_flowing"})
|
||||
check_place({x=pos.x,y=pos.y+1,z=pos.z},{name="default:water_flowing"})
|
||||
check_place({x=pos.x,y=pos.y-1,z=pos.z},{name="default:water_flowing"})
|
||||
elseif intensity == 3 then
|
||||
--]]
|
||||
minetest.add_node(pos,{name="default:water_source"})
|
||||
minetest.after(2, function() -- 2 seconds gives just enough time for
|
||||
-- the water to flow and spread before the
|
||||
-- water_source is changed to air. ~ LazyJ
|
||||
if minetest.get_node(pos).name == "default:water_source" then
|
||||
minetest.add_node(pos,{name="air"})
|
||||
end
|
||||
end)
|
||||
end
|
||||
nodeupdate(pos)
|
||||
end,
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
--Freezing
|
||||
--Water freezes when in contact with snow.
|
||||
minetest.register_abm({
|
||||
nodenames = {"default:water_source"},
|
||||
-- Added "group:icemaker" and snowbrick. ~ LazyJ
|
||||
neighbors = {"default:snow", "default:snowblock", "snow:snow_brick", "group:icemaker"},
|
||||
interval = 20,
|
||||
chance = 4,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
minetest.add_node(pos,{name="default:ice"})
|
||||
end,
|
||||
})
|
||||
|
||||
|
||||
|
||||
--Spread moss to cobble.
|
||||
minetest.register_abm({
|
||||
nodenames = {"default:cobble"},
|
||||
neighbors = {"snow:moss"},
|
||||
interval = 20,
|
||||
chance = 6,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
minetest.add_node(pos,{name="default:mossycobble"})
|
||||
end,
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
--Grow Pine Saplings
|
||||
minetest.register_abm({
|
||||
nodenames = {"snow:sapling_pine"},
|
||||
interval = 10,
|
||||
chance = 50,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
|
||||
-- Check if there is enough vertical-space for the sapling to grow without
|
||||
-- hitting anything else. ~ LazyJ, 2014_04_10
|
||||
|
||||
if -- 'If' there is air in each of the 8 nodes dirctly above the sapling,... ~LazyJ
|
||||
minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z}).name == "air" and
|
||||
minetest.get_node({x=pos.x, y=pos.y+2, z=pos.z}).name == "air" and
|
||||
minetest.get_node({x=pos.x, y=pos.y+3, z=pos.z}).name == "air" and
|
||||
minetest.get_node({x=pos.x, y=pos.y+4, z=pos.z}).name == "air" and
|
||||
minetest.get_node({x=pos.x, y=pos.y+5, z=pos.z}).name == "air" and
|
||||
minetest.get_node({x=pos.x, y=pos.y+6, z=pos.z}).name == "air" and
|
||||
minetest.get_node({x=pos.x, y=pos.y+7, z=pos.z}).name == "air" and
|
||||
minetest.get_node({x=pos.x, y=pos.y+8, z=pos.z}).name == "air"
|
||||
then -- 'then' let the sapling grow into a tree. ~ LazyJ
|
||||
|
||||
snow.make_pine(pos,false)
|
||||
-- This finds the sapling under the grown tree. ~ LazyJ
|
||||
if minetest.get_node({x = pos.x, y = pos.y, z = pos.z}).name == "snow:sapling_pine" then
|
||||
-- This switches the sapling to a tree trunk. ~ LazyJ
|
||||
minetest.set_node(pos, {name="default:tree"})
|
||||
-- This is more for testing but it may be useful info to some admins when
|
||||
-- grepping the server logs too. ~ LazyJ
|
||||
minetest.log("action", "A pine sapling grows into a tree at "..minetest.pos_to_string(pos))
|
||||
end
|
||||
else
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
--Grow Christmas Tree Saplings
|
||||
minetest.register_abm({
|
||||
nodenames = {"snow:xmas_tree"},
|
||||
interval = 10,
|
||||
chance = 50,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
|
||||
if -- 'If' there is air in each of the 8 nodes dirctly above the sapling,... ~LazyJ
|
||||
minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z}).name == "air" and
|
||||
minetest.get_node({x=pos.x, y=pos.y+2, z=pos.z}).name == "air" and
|
||||
minetest.get_node({x=pos.x, y=pos.y+3, z=pos.z}).name == "air" and
|
||||
minetest.get_node({x=pos.x, y=pos.y+4, z=pos.z}).name == "air" and
|
||||
minetest.get_node({x=pos.x, y=pos.y+5, z=pos.z}).name == "air" and
|
||||
minetest.get_node({x=pos.x, y=pos.y+6, z=pos.z}).name == "air" and
|
||||
minetest.get_node({x=pos.x, y=pos.y+7, z=pos.z}).name == "air" and
|
||||
minetest.get_node({x=pos.x, y=pos.y+8, z=pos.z}).name == "air"
|
||||
then -- 'then' let the sapling grow into a tree. ~ LazyJ
|
||||
|
||||
snow.make_pine(pos,false,true)
|
||||
minetest.log("action", "A pine sapling grows into a Christmas tree at "..minetest.pos_to_string(pos)) -- ~ LazyJ
|
||||
else -- 'Else', if there isn't air in each of the 8 nodes above the sapling,
|
||||
-- then don't anything; including not allowing the sapling to grow.
|
||||
-- ~ LazyJ, 2014_04_10
|
||||
end
|
||||
end
|
||||
})
|
103
src/aliases.lua
Normal file
103
src/aliases.lua
Normal file
@ -0,0 +1,103 @@
|
||||
-- Some aliases for compatibility switches and some to make "/give" commands
|
||||
-- a little easier
|
||||
|
||||
minetest.register_alias("snow:snow", "default:snow")
|
||||
minetest.register_alias("default_snow", "default:snow")
|
||||
minetest.register_alias("snow:snowball", "default:snow")
|
||||
minetest.register_alias("snowball", "default:snow")
|
||||
minetest.register_alias("snowballs", "default:snow")
|
||||
minetest.register_alias("snow_ball", "default:snow")
|
||||
minetest.register_alias("snow:ice", "default:ice")
|
||||
minetest.register_alias("ice", "default:ice")
|
||||
minetest.register_alias("default_ice", "default:ice")
|
||||
minetest.register_alias("snow:dirt_with_snow", "default:dirt_with_snow")
|
||||
minetest.register_alias("dirtwithsnow", "default:dirt_with_snow")
|
||||
minetest.register_alias("snowdirt", "default:dirt_with_snow")
|
||||
minetest.register_alias("snowydirt", "default:dirt_with_snow")
|
||||
minetest.register_alias("snow:snow_block", "default:snowblock")
|
||||
minetest.register_alias("default:snow_block", "default:snowblock")
|
||||
minetest.register_alias("snowblocks", "default:snowblock")
|
||||
minetest.register_alias("snowbrick", "snow:snow_brick")
|
||||
minetest.register_alias("bricksnow", "snow:snow_brick")
|
||||
minetest.register_alias("snowbricks", "snow:snow_brick")
|
||||
minetest.register_alias("snowybricks", "snow:snow_brick")
|
||||
minetest.register_alias("snowcobble", "snow:snow_cobble")
|
||||
minetest.register_alias("snowycobble", "snow:snow_cobble")
|
||||
minetest.register_alias("cobblesnow", "snow:snow_cobble")
|
||||
|
||||
|
||||
-- To clean up my first stairsplus attempt.
|
||||
-- Stair
|
||||
minetest.register_alias(":default:stair_snowblock", "moreblocks:stair_snowblock")
|
||||
minetest.register_alias(":default:stair_snowblock_half", "moreblocks:stair_snowblock_half")
|
||||
minetest.register_alias(":default:stair_snowblock_right_half", "moreblocks:stair_snowblock_right_half")
|
||||
minetest.register_alias(":default:stair_snowblock_inner", "moreblocks:stair_snowblock_inner")
|
||||
minetest.register_alias(":default:stair_snowblock_outer", "moreblocks:stair_snowblock_outer")
|
||||
minetest.register_alias(":default:stair_snowblock_alt", "moreblocks:stair_snowblock_alt")
|
||||
minetest.register_alias(":default:stair_snowblock_alt_1", "moreblocks:stair_snowblock_alt_1")
|
||||
minetest.register_alias(":default:stair_snowblock_alt_2", "moreblocks:stair_snowblock_2")
|
||||
minetest.register_alias(":default:stair_snowblock_alt_4", "moreblocks:stair_snowblock_alt_4")
|
||||
|
||||
minetest.register_alias(":default:stair_ice", "moreblocks:stair_ice")
|
||||
minetest.register_alias(":default:stair_ice_half", "moreblocks:stair_ice_half")
|
||||
minetest.register_alias(":default:stair_ice_right_half", "moreblocks:stair_ice_right_half")
|
||||
minetest.register_alias(":default:stair_ice_inner", "moreblocks:stair_ice_inner")
|
||||
minetest.register_alias(":default:stair_ice_outer", "moreblocks:stair_ice_outer")
|
||||
minetest.register_alias(":default:stair_ice_alt", "moreblocks:stair_ice_alt")
|
||||
minetest.register_alias(":default:stair_ice_alt_1", "moreblocks:stair_ice_alt_1")
|
||||
minetest.register_alias(":default:stair_ice_alt_2", "moreblocks:stair_ice_2")
|
||||
minetest.register_alias(":default:stair_ice_alt_4", "moreblocks:stair_ice_alt_4")
|
||||
|
||||
|
||||
-- Slab
|
||||
minetest.register_alias(":default:slab_snowblock", "moreblocks:slab_snowblock")
|
||||
minetest.register_alias(":default:slab_snowblock_quarter", "moreblocks:slab_snowblock_quarter")
|
||||
minetest.register_alias(":default:slab_snowblock_three_quarter", "moreblocks:slab_snowblock_three_quarter")
|
||||
minetest.register_alias(":default:slab_snowblock_1", "moreblocks:slab_snowblock_1")
|
||||
minetest.register_alias(":default:slab_snowblock_2", "moreblocks:slab_snowblock_2")
|
||||
minetest.register_alias(":default:slab_snowblock_14", "moreblocks:slab_snowblock_14")
|
||||
minetest.register_alias(":default:slab_snowblock_15", "moreblocks:slab_snowblock_15")
|
||||
|
||||
minetest.register_alias(":default:slab_ice", "moreblocks:slab_ice")
|
||||
minetest.register_alias(":default:slab_ice_quarter", "moreblocks:slab_ice_quarter")
|
||||
minetest.register_alias(":default:slab_ice_three_quarter", "moreblocks:slab_ice_three_quarter")
|
||||
minetest.register_alias(":default:slab_ice_1", "moreblocks:slab_ice_1")
|
||||
minetest.register_alias(":default:slab_ice_2", "moreblocks:slab_ice_2")
|
||||
minetest.register_alias(":default:slab_ice_14", "moreblocks:slab_ice_14")
|
||||
minetest.register_alias(":default:slab_ice_15", "moreblocks:slab_ice_15")
|
||||
|
||||
|
||||
-- Panel
|
||||
minetest.register_alias(":default:panel_snowblock", "moreblocks:panel_snowblock")
|
||||
minetest.register_alias(":default:panel_snowblock_1", "moreblocks:panel_snowblock_1")
|
||||
minetest.register_alias(":default:panel_snowblock_2", "moreblocks:panel_snowblock_2")
|
||||
minetest.register_alias(":default:panel_snowblock_4", "moreblocks:panel_snowblock_4")
|
||||
minetest.register_alias(":default:panel_snowblock_12", "moreblocks:panel_snowblock_12")
|
||||
minetest.register_alias(":default:panel_snowblock_14", "moreblocks:panel_snowblock_14")
|
||||
minetest.register_alias(":default:panel_snowblock_15", "moreblocks:panel_snowblock_15")
|
||||
|
||||
minetest.register_alias(":default:panel_ice", "moreblocks:panel_ice")
|
||||
minetest.register_alias(":default:panel_ice_1", "moreblocks:panel_ice_1")
|
||||
minetest.register_alias(":default:panel_ice_2", "moreblocks:panel_ice_2")
|
||||
minetest.register_alias(":default:panel_ice_4", "moreblocks:panel_ice_4")
|
||||
minetest.register_alias(":default:panel_ice_12", "moreblocks:panel_ice_12")
|
||||
minetest.register_alias(":default:panel_ice_14", "moreblocks:panel_ice_14")
|
||||
minetest.register_alias(":default:panel_ice_15", "moreblocks:panel_ice_15")
|
||||
|
||||
|
||||
-- Micro
|
||||
minetest.register_alias(":default:micro_snowblock", "moreblocks:micro_snowblock")
|
||||
minetest.register_alias(":default:micro_snowblock_1", "moreblocks:micro_snowblock_1")
|
||||
minetest.register_alias(":default:micro_snowblock_2", "moreblocks:micro_snowblock_2")
|
||||
minetest.register_alias(":default:micro_snowblock_4", "moreblocks:micro_snowblock_4")
|
||||
minetest.register_alias(":default:micro_snowblock_12", "moreblocks:micro_snowblock_12")
|
||||
minetest.register_alias(":default:micro_snowblock_14", "moreblocks:micro_snowblock_14")
|
||||
minetest.register_alias(":default:micro_snowblock_15", "moreblocks:micro_snowblock_15")
|
||||
|
||||
minetest.register_alias(":default:micro_ice", "moreblocks:micro_ice")
|
||||
minetest.register_alias(":default:micro_ice_1", "moreblocks:micro_ice_1")
|
||||
minetest.register_alias(":default:micro_ice_2", "moreblocks:micro_ice_2")
|
||||
minetest.register_alias(":default:micro_ice_4", "moreblocks:micro_ice_4")
|
||||
minetest.register_alias(":default:micro_ice_12", "moreblocks:micro_ice_12")
|
||||
minetest.register_alias(":default:micro_ice_14", "moreblocks:micro_ice_14")
|
||||
minetest.register_alias(":default:micro_ice_15", "moreblocks:micro_ice_15")
|
326
src/basic_stairs_slabs.lua
Normal file
326
src/basic_stairs_slabs.lua
Normal file
@ -0,0 +1,326 @@
|
||||
-- Based on
|
||||
-- Minetest 0.4 mod: stairs
|
||||
-- See README.txt for licensing and other information.
|
||||
|
||||
|
||||
-- ADD CHECK FOR MOREBLOCKS/SKIP IF NOT FOUND CODE STUFF HERE
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
snow_stairs = {} -- This is a little trick. Without it Minetest will complain
|
||||
-- "attempt to index global 'snow' (a nil value)" and
|
||||
-- refuse to load. So a value without definition "={}"is assigned to snow.
|
||||
|
||||
-- Node will be called snow:stair_<subname>
|
||||
function snow_stairs.register_stair(subname, recipeitem, groups, images, description, sounds)
|
||||
minetest.register_node("snow:stair_" .. subname, {
|
||||
description = description,
|
||||
drawtype = "nodebox",
|
||||
tiles = images,
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
is_ground_content = true,
|
||||
groups = groups,
|
||||
sounds = default.node_sound_dirt_defaults({
|
||||
footstep = {name="default_snow_footstep", gain=0.25},
|
||||
dig = {name="default_dig_crumbly", gain=0.4},
|
||||
dug = {name="default_snow_footstep", gain=0.75},
|
||||
place = {name="default_place_node", gain=1.0}
|
||||
}),
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{-0.5, -0.5, -0.5, 0.5, 0, 0.5},
|
||||
{-0.5, 0, 0, 0.5, 0.5, 0.5},
|
||||
},
|
||||
},
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
if pointed_thing.type ~= "node" then
|
||||
return itemstack
|
||||
end
|
||||
|
||||
local p0 = pointed_thing.under
|
||||
local p1 = pointed_thing.above
|
||||
local param2 = 0
|
||||
|
||||
local placer_pos = placer:getpos()
|
||||
if placer_pos then
|
||||
local dir = {
|
||||
x = p1.x - placer_pos.x,
|
||||
y = p1.y - placer_pos.y,
|
||||
z = p1.z - placer_pos.z
|
||||
}
|
||||
param2 = minetest.dir_to_facedir(dir)
|
||||
end
|
||||
|
||||
if p0.y-1 == p1.y then
|
||||
param2 = param2 + 20
|
||||
if param2 == 21 then
|
||||
param2 = 23
|
||||
elseif param2 == 23 then
|
||||
param2 = 21
|
||||
end
|
||||
end
|
||||
|
||||
return minetest.item_place(itemstack, placer, pointed_thing, param2)
|
||||
end,
|
||||
|
||||
on_construct = function(pos)
|
||||
pos.y = pos.y - 1
|
||||
if minetest.get_node(pos).name == "default:dirt_with_grass"
|
||||
-- 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
|
||||
or minetest.get_node(pos).name == "default:dirt" then
|
||||
minetest.set_node(pos, {name="default:dirt_with_snow"})
|
||||
end
|
||||
end
|
||||
})
|
||||
--[[
|
||||
-- for replace ABM
|
||||
minetest.register_node("snow:stair_" .. subname.."upside_down", {
|
||||
replace_name = "snow:stair_" .. subname,
|
||||
groups = {slabs_replace=1},
|
||||
})
|
||||
--]]
|
||||
minetest.register_craft({
|
||||
output = 'snow:stair_' .. subname .. ' 6',
|
||||
recipe = {
|
||||
{recipeitem, "", ""},
|
||||
{recipeitem, recipeitem, ""},
|
||||
{recipeitem, recipeitem, recipeitem},
|
||||
},
|
||||
})
|
||||
|
||||
-- Flipped recipe
|
||||
minetest.register_craft({
|
||||
output = 'snow:stair_' .. subname .. ' 6',
|
||||
recipe = {
|
||||
{"", "", recipeitem},
|
||||
{"", recipeitem, recipeitem},
|
||||
{recipeitem, recipeitem, recipeitem},
|
||||
},
|
||||
})
|
||||
end
|
||||
|
||||
-- Node will be called snow:slab_<subname>
|
||||
function snow_stairs.register_slab(subname, recipeitem, groups, images, description, sounds)
|
||||
minetest.register_node("snow:slab_" .. subname, {
|
||||
description = description,
|
||||
drawtype = "nodebox",
|
||||
tiles = images,
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
is_ground_content = true,
|
||||
groups = groups,
|
||||
sounds = default.node_sound_dirt_defaults({
|
||||
footstep = {name="default_snow_footstep", gain=0.25},
|
||||
dig = {name="default_dig_crumbly", gain=0.4},
|
||||
dug = {name="default_snow_footstep", gain=0.75},
|
||||
place = {name="default_place_node", gain=1.0}
|
||||
}),
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
|
||||
},
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
if pointed_thing.type ~= "node" then
|
||||
return itemstack
|
||||
end
|
||||
|
||||
-- If it's being placed on an another similar one, replace it with
|
||||
-- a full block
|
||||
local slabpos = nil
|
||||
local slabnode = nil
|
||||
local p0 = pointed_thing.under
|
||||
local p1 = pointed_thing.above
|
||||
local n0 = minetest.get_node(p0)
|
||||
local n1 = minetest.get_node(p1)
|
||||
local param2 = 0
|
||||
|
||||
local n0_is_upside_down = (n0.name == "snow:slab_" .. subname and
|
||||
n0.param2 >= 20)
|
||||
|
||||
if n0.name == "snow:slab_" .. subname and not n0_is_upside_down and p0.y+1 == p1.y then
|
||||
slabpos = p0
|
||||
slabnode = n0
|
||||
elseif n1.name == "snow:slab_" .. subname then
|
||||
slabpos = p1
|
||||
slabnode = n1
|
||||
end
|
||||
if slabpos then
|
||||
-- Remove the slab at slabpos
|
||||
minetest.remove_node(slabpos)
|
||||
-- Make a fake stack of a single item and try to place it
|
||||
local fakestack = ItemStack(recipeitem)
|
||||
fakestack:set_count(itemstack:get_count())
|
||||
|
||||
pointed_thing.above = slabpos
|
||||
local success
|
||||
fakestack, success = minetest.item_place(fakestack, placer, pointed_thing)
|
||||
-- If the item was taken from the fake stack, decrement original
|
||||
if success then
|
||||
itemstack:set_count(fakestack:get_count())
|
||||
-- Else put old node back
|
||||
else
|
||||
minetest.set_node(slabpos, slabnode)
|
||||
end
|
||||
return itemstack
|
||||
end
|
||||
|
||||
-- Upside down slabs
|
||||
if p0.y-1 == p1.y then
|
||||
-- Turn into full block if pointing at a existing slab
|
||||
if n0_is_upside_down then
|
||||
-- Remove the slab at the position of the slab
|
||||
minetest.remove_node(p0)
|
||||
-- Make a fake stack of a single item and try to place it
|
||||
local fakestack = ItemStack(recipeitem)
|
||||
fakestack:set_count(itemstack:get_count())
|
||||
|
||||
pointed_thing.above = p0
|
||||
local success
|
||||
fakestack, success = minetest.item_place(fakestack, placer, pointed_thing)
|
||||
-- If the item was taken from the fake stack, decrement original
|
||||
if success then
|
||||
itemstack:set_count(fakestack:get_count())
|
||||
-- Else put old node back
|
||||
else
|
||||
minetest.set_node(p0, n0)
|
||||
end
|
||||
return itemstack
|
||||
end
|
||||
|
||||
-- Place upside down slab
|
||||
param2 = 20
|
||||
end
|
||||
|
||||
-- If pointing at the side of a upside down slab
|
||||
if n0_is_upside_down and p0.y+1 ~= p1.y then
|
||||
param2 = 20
|
||||
end
|
||||
|
||||
return minetest.item_place(itemstack, placer, pointed_thing, param2)
|
||||
end,
|
||||
|
||||
on_construct = function(pos)
|
||||
pos.y = pos.y - 1
|
||||
if minetest.get_node(pos).name == "default:dirt_with_grass"
|
||||
-- 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
|
||||
or minetest.get_node(pos).name == "default:dirt" then
|
||||
minetest.set_node(pos, {name="default:dirt_with_snow"})
|
||||
end
|
||||
end
|
||||
|
||||
})
|
||||
--[[
|
||||
-- for replace ABM
|
||||
minetest.register_node("snow:slab_" .. subname.."upside_down", {
|
||||
replace_name = "snow:slab_"..subname,
|
||||
groups = {slabs_replace=1},
|
||||
})
|
||||
--]]
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'snow:slab_' .. subname .. ' 6',
|
||||
recipe = {
|
||||
{recipeitem, recipeitem, recipeitem},
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
end
|
||||
--[[
|
||||
-- Replace old "upside_down" nodes with new param2 versions
|
||||
minetest.register_abm({
|
||||
nodenames = {"group:slabs_replace"},
|
||||
interval = 1,
|
||||
chance = 1,
|
||||
action = function(pos, node)
|
||||
node.name = minetest.registered_nodes[node.name].replace_name
|
||||
node.param2 = node.param2 + 20
|
||||
if node.param2 == 21 then
|
||||
node.param2 = 23
|
||||
elseif node.param2 == 23 then
|
||||
node.param2 = 21
|
||||
end
|
||||
minetest.set_node(pos, node)
|
||||
end,
|
||||
})
|
||||
--]]
|
||||
|
||||
|
||||
|
||||
-- Snow stairs and slabs require extra definitions because of their extra
|
||||
-- features (freezing, melting, and how they change dirt and dirt_with_grass). ~ LazyJ
|
||||
|
||||
-- Nodes will be called snow:{stair,slab}_<subname>
|
||||
function snow_stairs.register_stair_and_slab(subname, recipeitem, groups, images, desc_stair, desc_slab, freezemelt, liquidtype, paramtype, sunlight_propagates)
|
||||
snow_stairs.register_stair(subname, recipeitem, groups, images, desc_stair, freezemelt, liquidtype, paramtype, sunlight_propagates)
|
||||
snow_stairs.register_slab(subname, recipeitem, groups, images, desc_slab, freezemelt, liquidtype, paramtype, sunlight_propagates)
|
||||
end
|
||||
|
||||
|
||||
list_of_snow_stuff = {
|
||||
--{"row[1] = first item in row",
|
||||
-- "row[2] = second item in row",
|
||||
-- "row[3] = third item in row", and so on, and so on...}, ~ LazyJ
|
||||
{"ice", "default:ice", "default_ice.png", "Ice Stairs", "Ice Slabs"},
|
||||
{"snowblock", "default:snowblock", "default_snow.png", "Snowblock Stairs", "Snowblock Slabs"},
|
||||
{"snow_cobble", "snow:snow_cobble", "snow_snow_cobble.png", "Snow Cobble Stairs", "Snow Cobble Slabs"},
|
||||
{"snow_brick", "snow:snow_brick", "snow_snow_brick.png", "Snow Brick Stair", "Snow Brick Slab"},
|
||||
}
|
||||
|
||||
for _, row in ipairs(list_of_snow_stuff) do
|
||||
local snow_subname = row[1]
|
||||
local snow_recipeitem = row[2]
|
||||
local snow_images = row[3]
|
||||
local snow_desc_stair = row[4]
|
||||
local snow_desc_slab = row[5]
|
||||
|
||||
|
||||
|
||||
|
||||
snow_stairs.register_stair_and_slab(snow_subname, snow_recipeitem,
|
||||
{cracky=2, crumbly=2, choppy=2, oddly_breakable_by_hand=2, melts=1, icemaker=1},
|
||||
{snow_images},
|
||||
snow_desc_stair,
|
||||
snow_desc_slab,
|
||||
"default:water_source",
|
||||
"none",
|
||||
"light",
|
||||
true
|
||||
)
|
||||
|
||||
end -- End the "list of snow stuff" part of the above section. ~ LazyJ
|
||||
|
||||
|
||||
-- Snow stairs and slabs should be easier to break than the more dense and
|
||||
-- manufactured, other snow-type nodes in the list above. ~ lazyJ
|
||||
minetest.override_item("snow:stair_snowblock", {
|
||||
groups = {cracky=3, crumbly=3, choppy=3, oddly_breakable_by_hand=3, melts=2, icemaker=1},
|
||||
})
|
||||
|
||||
minetest.override_item("snow:slab_snowblock", {
|
||||
groups = {cracky=3, crumbly=3, choppy=3, oddly_breakable_by_hand=3, melts=2, icemaker=1},
|
||||
})
|
||||
|
||||
|
||||
|
||||
-- Everything above is made of snow and uses snow sounds, ice, however, should sound more like glass
|
||||
-- and be harder to dig. ~ LazyJ
|
||||
minetest.override_item("snow:stair_ice", {
|
||||
groups = {cracky=1, crumbly=1, choppy=1, oddly_breakable_by_hand=1, melts=2, icemaker=1},
|
||||
use_texture_alpha = true,
|
||||
sounds = default.node_sound_glass_defaults(),
|
||||
})
|
||||
|
||||
minetest.override_item("snow:slab_ice", {
|
||||
groups = {cracky=1, crumbly=1, choppy=1, oddly_breakable_by_hand=1, melts=2, icemaker=1},
|
||||
use_texture_alpha = true,
|
||||
sounds = default.node_sound_glass_defaults(),
|
||||
})
|
185
src/crafting.lua
Normal file
185
src/crafting.lua
Normal file
@ -0,0 +1,185 @@
|
||||
--[[
|
||||
|
||||
Crafting Sections (in order, top to bottom):
|
||||
1. Fuel
|
||||
2. Cooking
|
||||
3. Crafting and Recycling
|
||||
|
||||
The crafting recipe for the sled is in the sled.lua file.
|
||||
|
||||
~ LazyJ
|
||||
|
||||
--]]
|
||||
|
||||
-- 1. Fuel
|
||||
|
||||
minetest.register_craft({
|
||||
type = "fuel",
|
||||
recipe = "snow:needles",
|
||||
burntime = 1,
|
||||
})
|
||||
|
||||
|
||||
|
||||
minetest.register_craft({
|
||||
type = "fuel",
|
||||
recipe = "snow:sapling_pine",
|
||||
burntime = 10,
|
||||
})
|
||||
|
||||
|
||||
|
||||
minetest.register_craft({
|
||||
type = "fuel",
|
||||
recipe = "snow:needles_decorated",
|
||||
burntime = 1,
|
||||
})
|
||||
|
||||
|
||||
|
||||
minetest.register_craft({
|
||||
type = "fuel",
|
||||
recipe = "snow:xmas_tree",
|
||||
burntime = 10,
|
||||
})
|
||||
|
||||
|
||||
|
||||
-- 2. Cooking
|
||||
|
||||
--[[
|
||||
"Cooks_into_ice" is a custom group I assigned to full-sized, snow-stuff nodes
|
||||
(snow bricks, snow cobble, snow blocks, etc.) so I wouldn't have to write an individual cooking
|
||||
recipe for each one.
|
||||
|
||||
~ LazyJ
|
||||
--]]
|
||||
|
||||
minetest.register_craft({
|
||||
type = "cooking",
|
||||
cooktime = 12,
|
||||
output = "default:ice",
|
||||
recipe = "group:cooks_into_ice",
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-- 3. Crafting and Recycling
|
||||
|
||||
-- Let's make moss craftable so players can more easily create mossycobble and
|
||||
-- gives another useful purpose to pine needles. ~ LazyJ
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'snow:moss',
|
||||
recipe = {
|
||||
{'snow:needles', 'snow:needles'},
|
||||
{'snow:needles', 'snow:needles'},
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
--[[
|
||||
Most snow biomes are too small to provide enough snow as a building material and
|
||||
still have enough landscape snow to create the wintry surroundings of a
|
||||
snow village or castle. So I added this snowblock crafting recipe as a way for
|
||||
players to increase their snow supply in small increments. I considered making
|
||||
the output 9 but that would make it all too quick and easy (especially for griefers) to create lots
|
||||
of snowblocks (and then use them to water-grief by melting the snow blocks).
|
||||
|
||||
~ LazyJ
|
||||
|
||||
--]]
|
||||
|
||||
minetest.register_craft({
|
||||
type = "shapeless",
|
||||
output = 'default:snowblock 3',
|
||||
recipe = {
|
||||
'snow:snow_cobble',
|
||||
'snow:snow_cobble'
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
|
||||
minetest.register_craft({
|
||||
type = "shapeless",
|
||||
output = 'default:snowblock 3',
|
||||
recipe = {
|
||||
'default:snowblock',
|
||||
'default:snowblock'
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'snow:snow_brick',
|
||||
recipe = {
|
||||
{'default:snowblock', 'default:snowblock'},
|
||||
{'default:snowblock', 'default:snowblock'}
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
|
||||
-- Why not recycle snow_bricks back into snowblocks? ~ LazyJ
|
||||
minetest.register_craft({
|
||||
output = 'default:snowblock 4',
|
||||
recipe = {
|
||||
{'snow:snow_brick'}
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
|
||||
-- Recycle basic, half-block, slabs back into full blocks
|
||||
|
||||
-- A little "list" magic here. Instead of writing four crafts I only have to write two. ~ LazyJ
|
||||
local recycle_default_slabs = {
|
||||
"ice",
|
||||
"snowblock",
|
||||
}
|
||||
|
||||
for _, name in pairs(recycle_default_slabs) do
|
||||
local subname_default = name
|
||||
|
||||
-- This craft is for default snowblocks and default ice.
|
||||
-- 1 crafting recipe handles 2, default blocks. ~ LazyJ
|
||||
minetest.register_craft({
|
||||
type = "shapeless",
|
||||
output = "default:"..subname_default,
|
||||
recipe = {
|
||||
"snow:slab_"..subname_default,
|
||||
"snow:slab_"..subname_default,
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- Similar list magic here too. I couldn't successfully combine these in the first list
|
||||
-- because we are dealing with slabs/blocks from two different mods, the "Snow" mod and
|
||||
-- minetest_game's "Default" mod. ~ LazyJ
|
||||
|
||||
local recycle_snowmod_slabs = {
|
||||
"snow_brick",
|
||||
"snow_cobble",
|
||||
}
|
||||
|
||||
for _, name in pairs(recycle_snowmod_slabs) do
|
||||
local subname_snowmod = name
|
||||
|
||||
-- This craft is for the Snow mod's full-sized blocks.
|
||||
-- 1 crafting recipe handles 2, or more, Snow mod blocks. ~ LazyJ
|
||||
minetest.register_craft({
|
||||
type = "shapeless",
|
||||
output = "snow:"..subname_snowmod,
|
||||
recipe = {
|
||||
"snow:slab_"..subname_snowmod,
|
||||
"snow:slab_"..subname_snowmod,
|
||||
}
|
||||
})
|
||||
end
|
201
src/falling_snow.lua
Normal file
201
src/falling_snow.lua
Normal file
@ -0,0 +1,201 @@
|
||||
--[[
|
||||
--=================
|
||||
--======================================
|
||||
LazyJ's Fork of Splizard's "Snow" Mod
|
||||
by LazyJ
|
||||
version: Umpteen and 7/5ths something or another.
|
||||
2014_04_12
|
||||
--======================================
|
||||
--=================
|
||||
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
THE LIST OF CHANGES I'VE MADE
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
* Falling snow would destroy nodes it deposited snow on. I figured out that if
|
||||
I switched the 'snow.place' with 'minetest.place_node' and increased the
|
||||
y position by 2, then the nodes were nolonger destroyed and the snow
|
||||
would start to pile up.
|
||||
|
||||
|
||||
|
||||
~~~~~~
|
||||
TODO
|
||||
~~~~~~
|
||||
|
||||
* Add code to prevent snowfall from depositing snow on or
|
||||
near torches and lava.
|
||||
|
||||
* Add code to prevent snowfall from depositing snow on
|
||||
'walkable = false' defined nodes.
|
||||
|
||||
--]]
|
||||
|
||||
|
||||
|
||||
--=============================================================
|
||||
-- CODE STUFF
|
||||
--=============================================================
|
||||
|
||||
|
||||
if snow.enable_snowfall then
|
||||
|
||||
local weather_legacy
|
||||
|
||||
local read_weather_legacy = function ()
|
||||
local file = io.open(minetest.get_worldpath().."/weather_v6", "r")
|
||||
if not file then return end
|
||||
local readweather = file:read()
|
||||
file:close()
|
||||
return readweather
|
||||
end
|
||||
|
||||
--Weather for legacy versions of minetest.
|
||||
local save_weather_legacy = function ()
|
||||
local file = io.open(minetest.get_worldpath().."/weather_v6", "w+")
|
||||
file:write(weather_legacy)
|
||||
file:close()
|
||||
end
|
||||
|
||||
weather_legacy = read_weather_legacy() or ""
|
||||
|
||||
minetest.register_globalstep(function(dtime)
|
||||
if weather_legacy == "snow" then
|
||||
if math.random(1, 10000) == 1 then
|
||||
weather_legacy = "none"
|
||||
save_weather_legacy()
|
||||
end
|
||||
else
|
||||
if math.random(1, 50000) == 2 then
|
||||
weather_legacy = "snow"
|
||||
save_weather_legacy()
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
--Get snow at position.
|
||||
local get_snow = function(pos)
|
||||
--Legacy support.
|
||||
if weather_legacy == "snow" then
|
||||
local perlin1 = minetest.env:get_perlin(112,3, 0.5, 150)
|
||||
if perlin1:get2d( {x=pos.x, y=pos.z} ) > 0.53 then
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
local addvectors = vector and vector.add
|
||||
|
||||
--Returns a random position between minp and maxp.
|
||||
local randpos = function (minp, maxp)
|
||||
local x,y,z
|
||||
if minp.x > maxp.x then
|
||||
x = math.random(maxp.x,minp.x) else x = math.random(minp.x,maxp.x) end
|
||||
y = minp.y
|
||||
if minp.z > maxp.z then
|
||||
z = math.random(maxp.z,minp.z) else z = math.random(minp.z,maxp.z) end
|
||||
return {x=x,y=y,z=z}
|
||||
end
|
||||
|
||||
local snow_fall=function (pos, player, animate)
|
||||
local ground_y = nil
|
||||
for y=pos.y+10,pos.y+20,1 do
|
||||
local n = minetest.env:get_node({x=pos.x,y=y,z=pos.z}).name
|
||||
if n ~= "air" and n ~= "ignore" then
|
||||
return
|
||||
end
|
||||
end
|
||||
for y=pos.y+10,pos.y-15,-1 do
|
||||
local n = minetest.env:get_node({x=pos.x,y=y,z=pos.z}).name
|
||||
if n ~= "air" and n ~= "ignore" then
|
||||
ground_y = y
|
||||
break
|
||||
end
|
||||
end
|
||||
if not ground_y then return end
|
||||
pos = {x=pos.x, y=ground_y, z=pos.z}
|
||||
local spos = {x=pos.x, y=ground_y+10, z=pos.z}
|
||||
|
||||
|
||||
if get_snow(pos) then
|
||||
if animate then
|
||||
local minp = addvectors(spos, {x=-9, y=3, z=-9})
|
||||
local maxp = addvectors(spos, {x= 9, y=5, z= 9})
|
||||
local vel = {x=0, y= -1, z=-1}
|
||||
local acc = {x=0, y= 0, z=0}
|
||||
minetest.add_particlespawner(3, 0.5,
|
||||
minp, maxp,
|
||||
vel, vel,
|
||||
acc, acc,
|
||||
5, 5,
|
||||
50, 50,
|
||||
false, "weather_snow.png", player:get_player_name())
|
||||
end
|
||||
--snow.place(pos, true)
|
||||
minetest.place_node({x=pos.x, y=pos.y+2, z=pos.z}, {name="default:snow"}) -- LazyJ
|
||||
end
|
||||
end
|
||||
|
||||
-- Snow
|
||||
minetest.register_globalstep(function(dtime)
|
||||
for _, player in ipairs(minetest.get_connected_players()) do
|
||||
local ppos = player:getpos()
|
||||
|
||||
local sminp = addvectors(ppos, {x=-20, y=0, z=-20})
|
||||
local smaxp = addvectors(ppos, {x= 20, y=0, z= 20})
|
||||
|
||||
-- Make sure player is not in a cave/house...
|
||||
if get_snow(ppos) and minetest.env:get_node_light(ppos, 0.5) == 15 then
|
||||
|
||||
local minp = addvectors(ppos, {x=-9, y=3, z=-9})
|
||||
local maxp = addvectors(ppos, {x= 9, y=5, z= 9})
|
||||
|
||||
local minp_deep = addvectors(ppos, {x=-5, y=3.2, z=-5})
|
||||
local maxp_deep = addvectors(ppos, {x= 5, y=1.6, z= 5})
|
||||
|
||||
local vel = {x=0, y= -1, z=-1}
|
||||
local acc = {x=0, y= 0, z=0}
|
||||
|
||||
if not snow.lighter_snowfall then
|
||||
minetest.add_particlespawner(5, 0.5,
|
||||
minp, maxp,
|
||||
vel, vel,
|
||||
acc, acc,
|
||||
5, 5,
|
||||
25, 25,
|
||||
false, "weather_snow.png", player:get_player_name())
|
||||
|
||||
minetest.add_particlespawner(4, 0.5,
|
||||
minp_deep, maxp_deep,
|
||||
vel, vel,
|
||||
acc, acc,
|
||||
4, 4,
|
||||
25, 25,
|
||||
false, "weather_snow.png", player:get_player_name())
|
||||
|
||||
if math.random(1,5) == 4 then
|
||||
snow_fall(randpos(sminp, smaxp), player)
|
||||
end
|
||||
else
|
||||
if math.random(1,5) == 4 then
|
||||
snow_fall(randpos(sminp, smaxp), player, true)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
else
|
||||
|
||||
if math.random(1,5) == 4 then
|
||||
snow_fall(randpos(sminp, smaxp), player, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
end
|
180
src/mapgen.lua
Normal file
180
src/mapgen.lua
Normal file
@ -0,0 +1,180 @@
|
||||
--[[
|
||||
If you want to run PlantLife and mods that depend on it, i.e. MoreTrees, Disable the mapgen by
|
||||
commenting-out the lines starting with "local mgname = " through "end" (I left a note were to start
|
||||
and stop) Disabling "Snow's" mapgen allows MoreTrees and PlantLife to do their thing until the
|
||||
issue is figured out. However, the pine and xmas tree code is still needed for when those
|
||||
saplings grow into trees. --]]
|
||||
--The *starting* comment looks like this: --[[
|
||||
--The *closing* comment looks like this: --]]
|
||||
|
||||
-- ~ LazyJ, 2014_05_13
|
||||
|
||||
|
||||
-- Part 1: To disable the mapgen, add the *starting* comment under this line.
|
||||
|
||||
|
||||
local mgname = ""
|
||||
|
||||
--Identify the mapgen.
|
||||
minetest.register_on_mapgen_init(function(MapgenParams)
|
||||
if MapgenParams.mgname then
|
||||
mgname = MapgenParams.mgname
|
||||
else
|
||||
io.write("[MOD] Snow Biomes: WARNING! mapgen could not be identifyed!\n")
|
||||
end
|
||||
if mgname == "v7" then
|
||||
--Load mapgen_v7 compatibility.
|
||||
dofile(minetest.get_modpath("snow").."/src/mapgen_v7.lua")
|
||||
else
|
||||
--Load mapgen_v6 compatibility.
|
||||
dofile(minetest.get_modpath("snow").."/src/mapgen_v6.lua")
|
||||
end
|
||||
end)
|
||||
|
||||
-- To complete the commenting-out add the *closing* comment under this line.
|
||||
|
||||
|
||||
|
||||
|
||||
local pine_tree = {
|
||||
axiom="TABff",
|
||||
rules_a="[&T+f+ff+ff+ff+f]GA",
|
||||
rules_b="[&T+f+Gf+Gf+Gf]GB",
|
||||
trunk="default:tree",
|
||||
leaves="snow:needles",
|
||||
angle=90,
|
||||
iterations=1,
|
||||
random_level=0,
|
||||
trunk_type="single",
|
||||
thin_branches=true,
|
||||
}
|
||||
|
||||
|
||||
|
||||
local xmas_tree = {
|
||||
axiom="TABff",
|
||||
rules_a="[&T+f+ff+ff+ff+f]GA",
|
||||
rules_b="[&T+f+Gf+Gf+Gf]GB",
|
||||
trunk="default:tree",
|
||||
leaves="snow:needles_decorated",
|
||||
angle=90,
|
||||
iterations=1,
|
||||
random_level=0,
|
||||
trunk_type="single",
|
||||
thin_branches=true,
|
||||
}
|
||||
|
||||
|
||||
|
||||
--Makes pine tree
|
||||
function snow.make_pine(pos,snow,xmas)
|
||||
local env = minetest.env
|
||||
local perlin1 = env:get_perlin(112,3, 0.5, 150)
|
||||
local try_node = function(pos, node)
|
||||
local n = env:get_node(pos).name
|
||||
if n == "air" or n == "ignore" then
|
||||
env:add_node(pos,node)
|
||||
end
|
||||
end
|
||||
--Clear ground.
|
||||
for x=-1,1 do
|
||||
for z=-1,1 do
|
||||
if env:get_node({x=pos.x+x,y=pos.y,z=pos.z+z}).name == "default:snow" then
|
||||
env:remove_node({x=pos.x+x,y=pos.y,z=pos.z+z})
|
||||
end
|
||||
if env:get_node({x=pos.x+x,y=pos.y,z=pos.z+z}).name == "default:snowblock" then
|
||||
env:remove_node({x=pos.x+x,y=pos.y,z=pos.z+z})
|
||||
end
|
||||
end
|
||||
end
|
||||
if xmas then
|
||||
env:remove_node(pos)
|
||||
minetest.env:spawn_tree(pos, xmas_tree)
|
||||
else
|
||||
minetest.env:spawn_tree(pos, pine_tree)
|
||||
end
|
||||
if snow then
|
||||
local x,z = pos.x,pos.z
|
||||
try_node({x=x+1,y=pos.y+3,z=z+1},{name="default:snow"})
|
||||
try_node({x=x-1,y=pos.y+3,z=z-1},{name="default:snow"})
|
||||
try_node({x=x-1,y=pos.y+3,z=z+1},{name="default:snow"})
|
||||
try_node({x=x+1,y=pos.y+3,z=z-1},{name="default:snow"})
|
||||
|
||||
try_node({x=x+1,y=pos.y+5,z=z},{name="default:snow"})
|
||||
try_node({x=x-1,y=pos.y+5,z=z},{name="default:snow"})
|
||||
try_node({x=x,y=pos.y+5,z=z+1},{name="default:snow"})
|
||||
try_node({x=x,y=pos.y+5,z=z-1},{name="default:snow"})
|
||||
end
|
||||
if xmas then
|
||||
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
|
||||
try_node({x=pos.x,y=pos.y+7,z=pos.z},{name="default:snow"})
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
--Makes pine tree
|
||||
function snow.voxelmanip_pine(pos,a,data)
|
||||
local c_snow = minetest.get_content_id("default:snow")
|
||||
local c_pine_needles = minetest.get_content_id("snow:needles")
|
||||
local c_tree = minetest.get_content_id("default:tree")
|
||||
local c_air = minetest.get_content_id("air")
|
||||
|
||||
local perlin1 = minetest.get_perlin(112,3, 0.5, 150)
|
||||
--Clear ground.
|
||||
for x=-1,1 do
|
||||
for z=-1,1 do
|
||||
local node = a:index(pos.x+x,pos.y,pos.z+z)
|
||||
if data[node] == c_snow then
|
||||
data[node] = c_air
|
||||
end
|
||||
end
|
||||
end
|
||||
--Make tree.
|
||||
for i=0, 4 do
|
||||
if i==1 or i==2 then
|
||||
for x=-1,1 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)
|
||||
data[node] = c_pine_needles
|
||||
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)
|
||||
data[abovenode] = c_snow
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if i==3 or i==4 then
|
||||
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
|
||||
data[a:index(pos.x,pos.y+i,pos.z)] = c_tree
|
||||
end
|
||||
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
|
||||
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
|
||||
end
|
||||
end
|
278
src/mapgen_v6.lua
Normal file
278
src/mapgen_v6.lua
Normal file
@ -0,0 +1,278 @@
|
||||
--Identify content ID's of nodes
|
||||
local c_dirt_with_grass = minetest.get_content_id("default:dirt_with_grass")
|
||||
local c_snow = minetest.get_content_id("default:snow")
|
||||
local c_snow_block = minetest.get_content_id("default:snowblock")
|
||||
local c_dirt_with_snow = minetest.get_content_id("default:dirt_with_snow")
|
||||
local c_air = minetest.get_content_id("air")
|
||||
local c_ignore = minetest.get_content_id("ignore")
|
||||
local c_stone = minetest.get_content_id("default:stone")
|
||||
local c_dry_shrub = minetest.get_content_id("default:dry_shrub")
|
||||
local c_leaves = minetest.get_content_id("default:leaves")
|
||||
local c_jungleleaves = minetest.get_content_id("default:jungleleaves")
|
||||
local c_junglegrass = minetest.get_content_id("default:junglegrass")
|
||||
local c_ice = minetest.get_content_id("default:ice")
|
||||
local c_water = minetest.get_content_id("default:water_source")
|
||||
local c_papyrus = minetest.get_content_id("default:papyrus")
|
||||
local c_sand = minetest.get_content_id("default:sand")
|
||||
|
||||
--Snow biomes are found at 0.53 and greater perlin noise.
|
||||
minetest.register_on_generated(function(minp, maxp, seed)
|
||||
--if maxp.y >= -10 and maxp.y > snow.min_height then
|
||||
|
||||
--Start timer
|
||||
local t1 = os.clock()
|
||||
local in_biome = false
|
||||
|
||||
--Load Voxel Manipulator
|
||||
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
|
||||
local a = VoxelArea:new{
|
||||
MinEdge={x=emin.x, y=emin.y, z=emin.z},
|
||||
MaxEdge={x=emax.x, y=emax.y, z=emax.z},
|
||||
}
|
||||
local data = vm:get_data()
|
||||
|
||||
local debug = snow.debug
|
||||
local min_height = snow.min_height
|
||||
|
||||
--Should make things a bit faster.
|
||||
local env = minetest.env
|
||||
|
||||
|
||||
-- Assume X and Z lengths are equal
|
||||
local divlen = 16
|
||||
local divs = (maxp.x-minp.x)+1;
|
||||
local x0 = minp.x
|
||||
local z0 = minp.z
|
||||
local x1 = maxp.x
|
||||
local z1 = maxp.z
|
||||
|
||||
|
||||
--Get map specific perlin noise.
|
||||
local perlin1 = env:get_perlin(112,3, 0.5, 150)
|
||||
|
||||
--Speed hack: checks the corners and middle of the chunk for "snow biome".
|
||||
--[[if not ( perlin1:get2d( {x=x0, y=z0} ) > 0.53 ) --top left
|
||||
and not ( perlin1:get2d( { x = x0 + ( (x1-x0)/2), y=z0 } ) > 0.53 )--top middle
|
||||
and not (perlin1:get2d({x=x1, y=z1}) > 0.53) --bottom right
|
||||
and not (perlin1:get2d({x=x1, y=z0+((z1-z0)/2)}) > 0.53) --right middle
|
||||
and not (perlin1:get2d({x=x0, y=z1}) > 0.53) --bottom left
|
||||
and not (perlin1:get2d({x=x1, y=z0}) > 0.53) --top right
|
||||
and not (perlin1:get2d({x=x0+((x1-x0)/2), y=z1}) > 0.53) --left middle
|
||||
and not (perlin1:get2d({x=(x1-x0)/2, y=(z1-z0)/2}) > 0.53) --middle
|
||||
and not (perlin1:get2d({x=x0, y=z1+((z1-z0)/2)}) > 0.53) then --bottom middle
|
||||
return
|
||||
end]]
|
||||
|
||||
--Choose a biome types.
|
||||
local pr = PseudoRandom(seed+57)
|
||||
local biome
|
||||
|
||||
--Land biomes
|
||||
biome = pr:next(1, 5)
|
||||
local snowy = biome == 1 --spawns alot of snow
|
||||
local plain = biome == 2 --spawns not much
|
||||
local alpine = biome == 3 --rocky terrain
|
||||
-- biome == 4 or biome == 5 -- normal biome
|
||||
|
||||
--Water biomes
|
||||
biome2 = pr:next(1, 5)
|
||||
local cool = biome == 1 --only spawns ice on edge of water
|
||||
local icebergs = biome == 2
|
||||
local icesheet = biome == 3
|
||||
local icecave = biome == 4
|
||||
local icehole = biome == 5 --icesheet with holes
|
||||
|
||||
--Misc biome settings.
|
||||
local icy = pr:next(1, 2) == 2 --If enabled spawns ice in sand instead of snow blocks.
|
||||
local mossy = pr:next(1,2) == 1 --Spawns moss in snow.
|
||||
local shrubs = pr:next(1,2) == 1 --Spawns dry shrubs in snow.
|
||||
local pines = pr:next(1,2) == 1 --spawns pines.
|
||||
|
||||
--Debugging function
|
||||
local biomeToString = function(num,num2)
|
||||
local biome, biome2
|
||||
if num == 1 then biome = "snowy"
|
||||
elseif num == 2 then biome = "plain"
|
||||
elseif num == 3 then biome = "alpine"
|
||||
elseif num == 4 or num == 5 then biome = "normal"
|
||||
else biome = "unknown "..num end
|
||||
|
||||
if num2 == 1 then biome2 = "cool"
|
||||
elseif num2 == 2 then biome2 = "icebergs"
|
||||
elseif num2 == 3 then biome2 = "icesheet"
|
||||
elseif num2 == 4 then biome2 = "icecave"
|
||||
elseif num2 == 5 then biome2 = "icehole"
|
||||
else biome2 = "unknown "..num end
|
||||
|
||||
return biome, biome2
|
||||
end
|
||||
|
||||
local spawn_pine = snow.voxelmanip_pine
|
||||
local smooth = snow.smooth_biomes
|
||||
local legacy = snow.legacy
|
||||
|
||||
--Reseed random.
|
||||
pr = PseudoRandom(seed+68)
|
||||
|
||||
--[[if alpine then
|
||||
local trees = env:find_nodes_in_area(minp, maxp, {"default:leaves","default:tree"})
|
||||
for i,v in pairs(trees) do
|
||||
env:remove_node(v)
|
||||
end
|
||||
end]]
|
||||
|
||||
--Loop through chunk.
|
||||
for x = minp.x, maxp.x do
|
||||
for z = minp.z, maxp.z do
|
||||
|
||||
--Check if we are in a "Snow biome"
|
||||
local in_biome = false
|
||||
local test = perlin1:get2d({x=x, y=z})
|
||||
if smooth and (not snowy) and (test > 0.73 or (test > 0.43 and pr:next(0,29) > (0.73 - test) * 100 )) then
|
||||
in_biome = true
|
||||
elseif (not smooth or snowy) and test > 0.53 then
|
||||
in_biome = true
|
||||
end
|
||||
|
||||
if in_biome then
|
||||
|
||||
local perlin2 = env:get_perlin(322345,3, 0.5, 80)
|
||||
local icetype = perlin2:get2d({x=x, y=z})
|
||||
local cool = icetype > 0 --only spawns ice on edge of water
|
||||
local icebergs = icetype > -0.2 and icetype <= 0
|
||||
local icehole = icetype > -0.4 and icetype <= -0.2
|
||||
local icesheet = icetype > -0.6 and icetype <= -0.4
|
||||
local icecave = icetype <= -0.6
|
||||
|
||||
--if not plain or pr:next(1,12) == 1 then
|
||||
|
||||
-- Find ground level (0...15)
|
||||
local ground_y = nil
|
||||
for y=maxp.y,minp.y,-1 do
|
||||
local n = data[a:index(x, y, z)]
|
||||
if n ~= c_air and n ~= c_ignore then
|
||||
ground_y = y
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if ground_y then --and ground_y > min_height then
|
||||
|
||||
-- Snowy biome stuff
|
||||
local node = a:index(x, ground_y, z)
|
||||
local abovenode = a:index(x, ground_y+1, z)
|
||||
local belownode = a:index(x, ground_y+2, z)
|
||||
|
||||
if ground_y and data[node] == c_dirt_with_grass then
|
||||
--local veg
|
||||
--if legacy and mossy and pr:next(1,10) == 1 then veg = 1 end
|
||||
if alpine then
|
||||
--Gets rid of dirt
|
||||
data[abovenode] = c_snow
|
||||
for y=ground_y,-6,-1 do
|
||||
local stone = a:index(x, y, z)
|
||||
if data[stone] == "default:stone" then
|
||||
break
|
||||
else
|
||||
data[stone] = c_stone
|
||||
end
|
||||
end
|
||||
elseif (shrubs and pr:next(1,28) == 1) then
|
||||
--Spawns dry shrubs.
|
||||
data[node] = c_dirt_with_snow
|
||||
data[abovenode] = c_dry_shrub
|
||||
elseif pines and pr:next(1,36) == 1 then
|
||||
--Spawns pines.
|
||||
data[node] = c_dirt_with_snow
|
||||
spawn_pine({x=x, y=ground_y+1, z=z},a,data)
|
||||
--elseif snowy then
|
||||
--Spawns snow blocks.
|
||||
--env:add_node({x=x,y=ground_y+1,z=z}, {name="snow:snow_block"})
|
||||
--data[aanode] = c_snow
|
||||
else
|
||||
--Spawns snow.
|
||||
data[node] = c_dirt_with_snow
|
||||
data[abovenode] = c_snow
|
||||
end
|
||||
elseif ground_y and data[belownode] == c_sand then
|
||||
--Spawns ice in sand if icy, otherwise spawns snow on top.
|
||||
if not icy then
|
||||
data[node] = c_snow
|
||||
else
|
||||
data[belownode] = c_ice
|
||||
end
|
||||
elseif ground_y and data[node] == c_leaves or data[node] == c_jungleleaves then
|
||||
data[abovenode] = c_snow
|
||||
elseif ground_y and data[node] == c_junglegrass then
|
||||
data[node] = c_dry_shrub
|
||||
elseif ground_y and data[node] == c_papyrus then
|
||||
for i=ground_y, ground_y-4, -1 do
|
||||
local papyrus = a:index(x, y, z)
|
||||
if data[papyrus] == c_papyrus then
|
||||
local papyrusabove = a:index(x, ground_y, z)
|
||||
data[papyrusabove] = c_snow
|
||||
data[papyrus] = c_snow_block
|
||||
end
|
||||
end
|
||||
elseif ground_y and data[node] == c_water then
|
||||
if not icesheet and not icecave and not icehole then
|
||||
--Coastal ice.
|
||||
local x1 = data[a:index(x+1,ground_y,z)]
|
||||
local z1 = data[a:index(x,ground_y,z+1)]
|
||||
local xz1 = data[a:index(x+1,ground_y,z+1)]
|
||||
local xz2 = data[a:index(x-1,ground_y,z-1)]
|
||||
local x2 = data[a:index(x-1,ground_y,z)]
|
||||
local z2 = data[a:index(x,ground_y,z-1)]
|
||||
local y = data[a:index(x,ground_y-1,z)]
|
||||
local rand = pr:next(1,4) == 1
|
||||
if
|
||||
((x1 and x1 ~= c_water and x1 ~= c_ice and x1 ~= c_air and x1 ~= c_ignore) or ((cool or icebergs) and x1 == c_ice and rand)) or
|
||||
((z1 and z1 ~= c_water and z1 ~= c_ice and z1 ~= c_air and z1 ~= c_ignore) or ((cool or icebergs) and z1 == c_ice and rand)) or
|
||||
((xz1 and xz1 ~= c_water and xz1 ~= c_ice and xz1 ~= c_air and xz1 ~= c_ignore) or ((cool or icebergs) and xz1 == c_ice and rand)) or
|
||||
((xz2 and xz2 ~= c_water and xz2 ~= c_ice and xz2 ~= c_air and xz2 ~= c_ignore) or ((cool or icebergs) and xz2 == c_ice and rand)) or
|
||||
((x2 and x2 ~= c_water and x2 ~= c_ice and x2 ~= c_air and x2 ~= c_ignore) or ((cool or icebergs) and x2 == c_ice and rand)) or
|
||||
((z2 and z2 ~= c_water and z2 ~= c_ice and z2 ~= c_air and z2 ~= c_ignore) or ((cool or icebergs) and z2 == c_ice and rand)) or
|
||||
(y ~= c_water and y ~= c_ice and y ~= "air") or (pr:next(1,6) == 1 and icebergs) then
|
||||
data[node] = c_ice
|
||||
end
|
||||
else
|
||||
--Icesheets, Broken icesheet, Icecaves
|
||||
if (icehole and pr:next(1,10) > 1) or icecave or icesheet then
|
||||
data[node] = c_ice
|
||||
end
|
||||
if icecave then
|
||||
--Gets rid of water underneath ice
|
||||
for y=ground_y-1,-60,-1 do
|
||||
local water = a:index(x, y, z)
|
||||
if data[water] ~= c_water then
|
||||
break
|
||||
else
|
||||
data[water] = c_air
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
--end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
vm:set_data(data)
|
||||
|
||||
vm:calc_lighting(
|
||||
{x=minp.x-16, y=minp.y, z=minp.z-16},
|
||||
{x=maxp.x+16, y=maxp.y, z=maxp.z+16}
|
||||
)
|
||||
|
||||
vm:write_to_map(data)
|
||||
|
||||
|
||||
if debug then
|
||||
biome_string,biome2_string = biomeToString(biome,biome2)
|
||||
print(biome_string.." and "..biome2_string..": Snow Biome Genarated near x"..minp.x.." z"..minp.z)
|
||||
print(string.format("elapsed time: %.2fms", (os.clock() - t1) * 1000))
|
||||
end
|
||||
--end
|
||||
end)
|
147
src/mapgen_v7.lua
Normal file
147
src/mapgen_v7.lua
Normal file
@ -0,0 +1,147 @@
|
||||
minetest.register_biome({
|
||||
name = "snow_biome_default",
|
||||
|
||||
node_top = "default:dirt_with_snow",
|
||||
depth_top = 1,
|
||||
node_filler = "default:dirt",
|
||||
depth_filler = 2,
|
||||
|
||||
height_min = snow.min_height,
|
||||
height_max = snow.min_height+60,
|
||||
heat_point = 10.0,
|
||||
humidity_point = 40.0,
|
||||
})
|
||||
|
||||
minetest.register_biome({
|
||||
name = "snow_biome_forest",
|
||||
|
||||
node_top = "default:dirt_with_snow",
|
||||
depth_top = 1,
|
||||
node_filler = "default:dirt",
|
||||
depth_filler = 2,
|
||||
|
||||
height_min = snow.min_height,
|
||||
height_max = snow.min_height+60,
|
||||
heat_point = 10.0,
|
||||
humidity_point = 55.0,
|
||||
})
|
||||
|
||||
minetest.register_biome({
|
||||
name = "snow_biome_lush",
|
||||
|
||||
node_top = "default:dirt_with_snow",
|
||||
depth_top = 1,
|
||||
node_filler = "default:dirt",
|
||||
depth_filler = 2,
|
||||
|
||||
height_min = snow.min_height,
|
||||
height_max = snow.min_height+60,
|
||||
heat_point = 10.0,
|
||||
humidity_point = 70.0,
|
||||
})
|
||||
|
||||
minetest.register_biome({
|
||||
name = "snow_biome_alpine",
|
||||
|
||||
node_top = "default:stone",
|
||||
depth_top = 1,
|
||||
node_filler = "default:stone",
|
||||
|
||||
height_min = snow.min_height+60,
|
||||
height_max = 31000,
|
||||
heat_point = 10.0,
|
||||
humidity_point = 40.0,
|
||||
})
|
||||
|
||||
minetest.register_biome({
|
||||
name = "base_normal",
|
||||
|
||||
height_min = 3,
|
||||
height_max = 40,
|
||||
heat_point = 40.0,
|
||||
humidity_point = 40.0,
|
||||
})
|
||||
|
||||
minetest.register_biome({
|
||||
name = "snow_biome_sand",
|
||||
|
||||
node_top = "default:sand",
|
||||
depth_top = 3,
|
||||
node_filler = "default:stone",
|
||||
depth_filler = 0,
|
||||
|
||||
height_min = -31000,
|
||||
height_max = 2,
|
||||
heat_point = 10.0,
|
||||
humidity_point = 40.0,
|
||||
})
|
||||
|
||||
|
||||
--Pine tree.
|
||||
minetest.register_decoration({
|
||||
deco_type = "schematic",
|
||||
place_on = "default:dirt_with_snow",
|
||||
sidelen = 16,
|
||||
fill_ratio = 0.005,
|
||||
biomes = {"snow_biome_default"},
|
||||
schematic = minetest.get_modpath("snow").."/schematics/pine.mts",
|
||||
flags = "place_center_x, place_center_z",
|
||||
})
|
||||
|
||||
minetest.register_decoration({
|
||||
deco_type = "schematic",
|
||||
place_on = "default:dirt_with_snow",
|
||||
sidelen = 16,
|
||||
fill_ratio = 0.05,
|
||||
biomes = {"snow_biome_forest"},
|
||||
schematic = minetest.get_modpath("snow").."/schematics/pine.mts",
|
||||
flags = "place_center_x, place_center_z",
|
||||
})
|
||||
|
||||
minetest.register_decoration({
|
||||
deco_type = "schematic",
|
||||
place_on = "default:dirt_with_snow",
|
||||
sidelen = 16,
|
||||
fill_ratio = 0.1,
|
||||
biomes = {"snow_biome_lush"},
|
||||
schematic = minetest.get_modpath("snow").."/schematics/pine.mts",
|
||||
flags = "place_center_x, place_center_z",
|
||||
})
|
||||
|
||||
--Dry shrubs.
|
||||
minetest.register_decoration({
|
||||
deco_type = "simple",
|
||||
place_on = "default:dirt_with_snow",
|
||||
sidelen = 16,
|
||||
fill_ratio = 0.005,
|
||||
biomes = {"snow_biome_default"},
|
||||
decoration = "default:dry_shrub",
|
||||
})
|
||||
|
||||
minetest.register_decoration({
|
||||
deco_type = "simple",
|
||||
place_on = "default:dirt_with_snow",
|
||||
sidelen = 16,
|
||||
fill_ratio = 0.05,
|
||||
biomes = {"snow_biome_forest", "snow_biome_lush"},
|
||||
decoration = "default:dry_shrub",
|
||||
})
|
||||
|
||||
--Snow.
|
||||
minetest.register_decoration({
|
||||
deco_type = "simple",
|
||||
place_on = "default:dirt_with_snow",
|
||||
sidelen = 16,
|
||||
fill_ratio = 10,
|
||||
biomes = {"snow_biome_default", "snow_biome_forest", "snow_biome_lush"},
|
||||
decoration = "default:snow",
|
||||
})
|
||||
|
||||
minetest.register_decoration({
|
||||
deco_type = "simple",
|
||||
place_on = "default:stone",
|
||||
sidelen = 16,
|
||||
fill_ratio = 10,
|
||||
biomes = {"snow_biome_alpine"},
|
||||
decoration = "default:snow",
|
||||
})
|
355
src/nodes.lua
Normal file
355
src/nodes.lua
Normal file
@ -0,0 +1,355 @@
|
||||
-- NODES
|
||||
|
||||
-- Pine Needles
|
||||
minetest.register_node("snow:needles",{
|
||||
description = "Pine Needles",
|
||||
drawtype = "allfaces_optional",
|
||||
visual_scale = 1.3,
|
||||
tiles = {"snow_needles.png"},
|
||||
waving = 1,
|
||||
paramtype = "light",
|
||||
groups = {snappy=3, leafdecay=5},
|
||||
drop = {
|
||||
max_items = 1,
|
||||
items = {
|
||||
{
|
||||
-- player will get sapling with 1/20 chance
|
||||
items = {'snow:sapling_pine'},
|
||||
rarity = 20,
|
||||
},
|
||||
{
|
||||
-- player will get leaves only if he get no saplings,
|
||||
-- this is because max_items is 1
|
||||
items = {'snow:needles'},
|
||||
}
|
||||
}
|
||||
},
|
||||
sounds = default.node_sound_leaves_defaults(),
|
||||
})
|
||||
|
||||
--[[
|
||||
If christmas_content is enabled, then this next part will override the pine needles' drop code
|
||||
(in the code section above) and adds Xmas tree saplings to the items that are dropped.
|
||||
The Xmas tree needles are registred and defined a farther down in this nodes.lua file.
|
||||
|
||||
~ LazyJ
|
||||
|
||||
--]]
|
||||
|
||||
if snow.christmas_content then
|
||||
--Christmas trees
|
||||
|
||||
minetest.override_item("snow:needles", {
|
||||
drop = {
|
||||
max_items = 1,
|
||||
items = {
|
||||
{
|
||||
-- player will get xmas tree with 1/120 chance
|
||||
items = {'snow:xmas_tree'},
|
||||
rarity = 120,
|
||||
},
|
||||
{
|
||||
-- player will get sapling with 1/20 chance
|
||||
items = {'snow:sapling_pine'},
|
||||
rarity = 20,
|
||||
},
|
||||
{
|
||||
-- player will get leaves only if he get no saplings,
|
||||
-- this is because max_items is 1
|
||||
items = {'snow:needles'},
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
--Christmas easter egg
|
||||
minetest.register_on_mapgen_init( function()
|
||||
if skins then
|
||||
skins.add("character_snow_man")
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
|
||||
|
||||
--[[
|
||||
Original, static Xmas lights. Keep so people can "turn off" the
|
||||
animation if it is too much for them. ~ LazyJ
|
||||
|
||||
--Decorated Pine leaves
|
||||
minetest.register_node("snow:needles_decorated", {
|
||||
description = "Decorated Pine Needles",
|
||||
drawtype = "allfaces_optional",
|
||||
tiles = {"snow_needles_decorated.png"},
|
||||
paramtype = "light",
|
||||
groups = {snappy=3, leafdecay=3},
|
||||
drop = {
|
||||
max_items = 1,
|
||||
items = {
|
||||
{
|
||||
-- player will get xmas tree with 1/20 chance
|
||||
items = {'snow:xmas_tree'},
|
||||
rarity = 50,
|
||||
},
|
||||
{
|
||||
-- player will get sapling with 1/20 chance
|
||||
items = {'snow:sapling_pine'},
|
||||
rarity = 20,
|
||||
},
|
||||
{
|
||||
-- player will get leaves only if he get no saplings,
|
||||
-- this is because max_items is 1
|
||||
items = {'snow:needles_decorated'},
|
||||
}
|
||||
}
|
||||
},
|
||||
sounds = default.node_sound_leaves_defaults(),
|
||||
})
|
||||
--]]
|
||||
|
||||
|
||||
|
||||
-- Animated, "blinking lights" version. ~ LazyJ
|
||||
|
||||
-- Decorated Pine Leaves
|
||||
minetest.register_node("snow:needles_decorated", {
|
||||
description = "Decorated Pine Needles",
|
||||
drawtype = "allfaces_optional",
|
||||
light_source = 5,
|
||||
inventory_image = minetest.inventorycube("snow_needles_decorated.png"),
|
||||
--tiles = {"snow_needles_decorated.png"},
|
||||
tiles = {
|
||||
{name="snow_needles_decorated_animated.png", animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=20.0}}
|
||||
},
|
||||
paramtype = "light",
|
||||
groups = {snappy=3, leafdecay=5},
|
||||
drop = {
|
||||
max_items = 1,
|
||||
items = {
|
||||
{
|
||||
-- player will get xmas tree with 1/120 chance
|
||||
items = {'snow:xmas_tree'},
|
||||
rarity = 120,
|
||||
},
|
||||
{
|
||||
-- player will get sapling with 1/20 chance
|
||||
items = {'snow:sapling_pine'},
|
||||
rarity = 20,
|
||||
},
|
||||
{
|
||||
-- player will get leaves only if he get no saplings,
|
||||
-- this is because max_items is 1
|
||||
items = {'snow:needles_decorated'},
|
||||
}
|
||||
}
|
||||
},
|
||||
sounds = default.node_sound_leaves_defaults(),
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
-- Xmas Tree Sapling
|
||||
minetest.register_node("snow:xmas_tree", {
|
||||
description = "Christmas Tree",
|
||||
drawtype = "plantlike",
|
||||
visual_scale = 1.0,
|
||||
tiles = {"snow_xmas_tree.png"},
|
||||
inventory_image = "snow_xmas_tree.png",
|
||||
wield_image = "snow_xmas_tree.png",
|
||||
paramtype = "light",
|
||||
walkable = false,
|
||||
groups = {snappy=2,dig_immediate=3},
|
||||
sounds = default.node_sound_defaults(),
|
||||
})
|
||||
|
||||
|
||||
|
||||
-- Pine Sapling
|
||||
minetest.register_node("snow:sapling_pine", {
|
||||
description = "Pine Sapling",
|
||||
drawtype = "plantlike",
|
||||
visual_scale = 1.0,
|
||||
tiles = {"snow_sapling_pine.png"},
|
||||
inventory_image = "snow_sapling_pine.png",
|
||||
wield_image = "snow_sapling_pine.png",
|
||||
paramtype = "light",
|
||||
walkable = false,
|
||||
groups = {snappy=2,dig_immediate=3},
|
||||
sounds = default.node_sound_defaults(),
|
||||
|
||||
})
|
||||
|
||||
|
||||
|
||||
-- Star on Xmas Trees
|
||||
minetest.register_node("snow:star", {
|
||||
description = "Star",
|
||||
--drawtype = "torchlike",
|
||||
drawtype = "plantlike", -- Stars disappeared when viewed at the right angle. "Plantlike" solved the visual problem. ~ LazyJ
|
||||
tiles = {"snow_star.png"},
|
||||
inventory_image = "snow_star.png",
|
||||
wield_image = "snow_star.png",
|
||||
paramtype = "light",
|
||||
walkable = false,
|
||||
--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
|
||||
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
|
||||
minetest.set_node(pos, {name = "snow:star_lit"})
|
||||
nodeupdate(pos)
|
||||
end,
|
||||
})
|
||||
|
||||
|
||||
|
||||
-- Star (Lit Version) on Xmas Trees
|
||||
minetest.register_node("snow:star_lit", {
|
||||
description = "Star Lighted",
|
||||
drawtype = "plantlike",
|
||||
light_source = LIGHT_MAX,
|
||||
tiles = {"snow_star_lit.png"},
|
||||
wield_image = "snow_star.png",
|
||||
paramtype = "light",
|
||||
walkable = false,
|
||||
drop = "snow:star",
|
||||
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}}),
|
||||
on_punch = function(pos, node, puncher)
|
||||
minetest.set_node(pos, {name = "snow:star"})
|
||||
nodeupdate(pos)
|
||||
end,
|
||||
})
|
||||
|
||||
|
||||
|
||||
-- Moss
|
||||
minetest.register_node("snow:moss", {
|
||||
description = "Moss",
|
||||
tiles = {"snow_moss.png"},
|
||||
drawtype = "signlike",
|
||||
paramtype = "light",
|
||||
paramtype2 = "wallmounted",
|
||||
walkable = false,
|
||||
selection_box = {
|
||||
type = "wallmounted",
|
||||
},
|
||||
is_ground_content = true,
|
||||
groups = {crumbly=3, attached_node=1},
|
||||
})
|
||||
|
||||
|
||||
|
||||
-- Snow Brick
|
||||
minetest.register_node("snow:snow_brick", {
|
||||
description = "Snow Brick",
|
||||
tiles = {"snow_snow_brick.png"},
|
||||
is_ground_content = true,
|
||||
freezemelt = "default:water_source",
|
||||
liquidtype = "none",
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
paramtype2 = "facedir", -- Allow blocks to be rotated with the screwdriver or
|
||||
-- by player position. ~ LazyJ
|
||||
-- I made this a little harder to dig than snow blocks because
|
||||
-- I imagine snow brick as being much more dense and solid than fluffy snow. ~ LazyJ
|
||||
groups = {cracky=2, crumbly=2, choppy=2, oddly_breakable_by_hand=2, melts=1, icemaker=1, cooks_into_ice=1},
|
||||
--Let's use the new snow sounds instead of the old grass sounds. ~ LazyJ
|
||||
sounds = default.node_sound_dirt_defaults({
|
||||
footstep = {name="default_snow_footstep", gain=0.25},
|
||||
dig = {name="default_dig_crumbly", gain=0.4},
|
||||
dug = {name="default_snow_footstep", gain=0.75},
|
||||
place = {name="default_place_node", gain=1.0}
|
||||
}),
|
||||
-- The "on_construct" part below, thinking in terms of layers, dirt_with_snow could also
|
||||
-- double as dirt_with_frost which adds subtlety to the winterscape. ~ LazyJ
|
||||
on_construct = function(pos)
|
||||
pos.y = pos.y - 1
|
||||
if minetest.get_node(pos).name == "default:dirt_with_grass"
|
||||
-- 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
|
||||
or minetest.get_node(pos).name == "default:dirt" then
|
||||
minetest.set_node(pos, {name="default:dirt_with_snow"})
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
|
||||
|
||||
-- Snow Cobble ~ LazyJ
|
||||
minetest.register_node("snow:snow_cobble", {
|
||||
description = "Snow Cobble",
|
||||
tiles = {"snow_snow_cobble.png"},
|
||||
is_ground_content = true,
|
||||
freezemelt = "default:water_source",
|
||||
liquidtype = "none",
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
paramtype2 = "facedir",
|
||||
-- I made this a little harder to dig than snow blocks because
|
||||
-- I imagine snow brick as being much more dense and solid than fluffy snow. ~ LazyJ
|
||||
groups = {cracky=2, crumbly=2, choppy=2, oddly_breakable_by_hand=2, melts=1, icemaker=1, cooks_into_ice},
|
||||
sounds = default.node_sound_dirt_defaults({
|
||||
footstep = {name="default_snow_footstep", gain=0.25},
|
||||
dig = {name="default_dig_crumbly", gain=0.4},
|
||||
dug = {name="default_snow_footstep", gain=0.75},
|
||||
place = {name="default_place_node", gain=1.0}
|
||||
}),
|
||||
-- The "on_construct" part below, thinking in terms of layers, dirt_with_snow could also
|
||||
-- double as dirt_with_frost which adds subtlety to the winterscape. ~ LazyJ
|
||||
on_construct = function(pos)
|
||||
pos.y = pos.y - 1
|
||||
if minetest.get_node(pos).name == "default:dirt_with_grass"
|
||||
or minetest.get_node(pos).name == "default:dirt" then
|
||||
minetest.set_node(pos, {name="default:dirt_with_snow"})
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
|
||||
|
||||
-- Override Default Nodes to Add Extra Functions
|
||||
|
||||
-- This adds code to the existing default ice. ~ LazyJ
|
||||
minetest.override_item("default:ice", {
|
||||
-- The Lines: 1. Alpah to make semi-transparent ice, 2 to work with
|
||||
-- the dirt_with_grass/snow/just dirt ABMs. ~ LazyJ, 2014_03_09
|
||||
use_texture_alpha = true, -- 1
|
||||
sunlight_propagates = true, -- 2
|
||||
drawtype = "glasslike",
|
||||
inventory_image = minetest.inventorycube("default_ice.png"),
|
||||
liquidtype = "none",
|
||||
-- I made this a lot harder to dig than snow blocks because ice is much more dense
|
||||
-- and solid than fluffy snow. ~ LazyJ
|
||||
groups = {cracky=1, crumbly=1, choppy=1, oddly_breakable_by_hand=1, melts=1},
|
||||
on_construct = function(pos)
|
||||
pos.y = pos.y - 1
|
||||
if minetest.get_node(pos).name == "default:dirt_with_grass"
|
||||
or minetest.get_node(pos).name == "default:dirt" then
|
||||
minetest.set_node(pos, {name="default:dirt_with_snow"})
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
|
||||
|
||||
-- This adds code to the existing, default snowblock. ~ LazyJ
|
||||
minetest.override_item("default:snowblock", {
|
||||
liquidtype = "none", -- LazyJ to make dirt below change to dirt_with_snow (see default, nodes.lua, dirt ABM)
|
||||
paramtype = "light", -- LazyJ to make dirt below change to dirt_with_snow (see default, nodes.lua, dirt ABM)
|
||||
sunlight_propagates = true, -- LazyJ to make dirt below change to dirt_with_snow (see default, nodes.lua, dirt ABM)
|
||||
-- Snow blocks should be easy to dig because they are just fluffy snow. ~ LazyJ
|
||||
groups = {cracky=3, crumbly=3, choppy=3, oddly_breakable_by_hand=3, melts=1, icemaker=1, cooks_into_ice=1},
|
||||
drop = "snow:snow_cobble",
|
||||
on_construct = function(pos)
|
||||
pos.y = pos.y - 1
|
||||
if minetest.get_node(pos).name == "default:dirt_with_grass"
|
||||
-- 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
|
||||
or minetest.get_node(pos).name == "default:dirt" then
|
||||
minetest.set_node(pos, {name="default:dirt_with_snow"})
|
||||
end
|
||||
end
|
||||
})
|
203
src/sled.lua
Normal file
203
src/sled.lua
Normal file
@ -0,0 +1,203 @@
|
||||
--[[
|
||||
--=================
|
||||
--======================================
|
||||
LazyJ's Fork of Splizard's "Snow" Mod
|
||||
by LazyJ
|
||||
version: Umpteen and 7/5ths something or another.
|
||||
2014_04_12
|
||||
--======================================
|
||||
--=================
|
||||
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
THE LIST OF CHANGES I'VE MADE
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
|
||||
* The HUD message that displayed when a player sat on the sled would not go away after the player
|
||||
got off the sled. I spent hours on trial-and-error while reading the lua_api.txt and scrounging
|
||||
the Internet for a needle-in-the-haystack solution as to why the hud_remove wasn't working.
|
||||
Turns out Splizard's code was mostly correct, just not assembled in the right order.
|
||||
|
||||
The key to the solution was found in the code of leetelate's scuba mod:
|
||||
http://forum.minetest.net/viewtopic.php?id=7175
|
||||
|
||||
* Changed the wording of the HUD message for clarity.
|
||||
|
||||
|
||||
~~~~~~
|
||||
TODO
|
||||
~~~~~~
|
||||
|
||||
* Figure out why the player avatars remain in a seated position, even after getting off the sled,
|
||||
if they flew while on the sled. 'default.player_set_animation', where is a better explanation
|
||||
for this and what are it's available options?
|
||||
|
||||
* Go through, clean-up my notes and get them better sorted. Some are in the code, some are
|
||||
scattered in my note-taking program. This "Oh, I'll just make a little tweak here and a
|
||||
little tweak there" project has evolved into something much bigger and more complex
|
||||
than I originally planned. :p ~ LazyJ
|
||||
|
||||
|
||||
--]]
|
||||
|
||||
|
||||
|
||||
--=============================================================
|
||||
-- CODE STUFF
|
||||
--=============================================================
|
||||
|
||||
--
|
||||
-- Helper functions
|
||||
--
|
||||
|
||||
local function is_water(pos)
|
||||
local nn = minetest.env:get_node(pos).name
|
||||
return minetest.get_item_group(nn, "water") ~= 0
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- Sled entity
|
||||
--
|
||||
|
||||
local sled = {
|
||||
physical = false,
|
||||
collisionbox = {-0.6,-0.25,-0.6, 0.6,0.3,0.6},
|
||||
visual = "mesh",
|
||||
mesh = "sled.x",
|
||||
textures = {"sled.png"},
|
||||
|
||||
driver = nil,
|
||||
sliding = false,
|
||||
}
|
||||
|
||||
local players_sled = {}
|
||||
|
||||
function sled:on_rightclick(clicker)
|
||||
if (not self.driver) and snow.sleds then
|
||||
players_sled[clicker:get_player_name()] = true
|
||||
self.driver = clicker
|
||||
self.object:set_attach(clicker, "", {x=0,y=-9,z=0}, {x=0,y=90,z=0})
|
||||
clicker:set_physics_override({
|
||||
speed = 2, -- multiplier to default value
|
||||
jump = 0, -- multiplier to default value
|
||||
gravity = 1
|
||||
})
|
||||
--[[
|
||||
local HUD =
|
||||
{
|
||||
hud_elem_type = "text", -- see HUD element types
|
||||
position = {x=0.5, y=0.89},
|
||||
name = "sled",
|
||||
scale = {x=2, y=2},
|
||||
text = "You are sledding, hold sneak to stop.",
|
||||
direction = 0,
|
||||
}
|
||||
|
||||
clicker:hud_add(HUD)
|
||||
--]]
|
||||
|
||||
-- Here is part 1 of the fix. ~ LazyJ
|
||||
HUD = clicker:hud_add({
|
||||
hud_elem_type = "text",
|
||||
position = {x=0.5, y=0.89},
|
||||
name = "sled",
|
||||
scale = {x=2, y=2},
|
||||
text = "You are on the sled! Press the sneak key to get off the sled.", -- LazyJ
|
||||
direction = 0,
|
||||
})
|
||||
-- End part 1
|
||||
end
|
||||
end
|
||||
|
||||
function sled:on_activate(staticdata, dtime_s)
|
||||
self.object:set_armor_groups({immortal=1})
|
||||
if staticdata then
|
||||
self.v = tonumber(staticdata)
|
||||
end
|
||||
end
|
||||
|
||||
function sled:get_staticdata()
|
||||
return tostring(v)
|
||||
end
|
||||
|
||||
function sled:on_punch(puncher, time_from_last_punch, tool_capabilities, direction)
|
||||
self.object:remove()
|
||||
if puncher and puncher:is_player() then
|
||||
puncher:get_inventory():add_item("main", "snow:sled")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
minetest.register_globalstep(function(dtime)
|
||||
for _, player in pairs(minetest.get_connected_players()) do
|
||||
if players_sled[player:get_player_name()] then
|
||||
default.player_set_animation(player, "sit", 0)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
function sled:on_step(dtime)
|
||||
if self.driver then
|
||||
local p = self.object:getpos()
|
||||
p.y = p.y+0.4
|
||||
local s = self.object:getpos()
|
||||
s.y = s.y -0.5
|
||||
local keys = self.driver:get_player_control()
|
||||
if keys["sneak"] or is_water(p) or (not minetest.find_node_near(s, 1, {"default:snow","default:snowblock","default:ice","default:dirt_with_snow", "group:icemaker"})) then -- LazyJ
|
||||
self.driver:set_physics_override({
|
||||
speed = 1, -- multiplier to default value
|
||||
jump = 1, -- multiplier to default value
|
||||
gravity = 1
|
||||
})
|
||||
|
||||
players_sled[self.driver:get_player_name()] = false
|
||||
self.object:set_detach()
|
||||
--self.driver:hud_remove("sled")
|
||||
self.driver:hud_remove(HUD) -- And here is part 2. ~ LazyJ
|
||||
self.driver = nil
|
||||
self.object:remove()
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_entity("snow:sled", sled)
|
||||
|
||||
|
||||
minetest.register_craftitem("snow:sled", {
|
||||
description = "Sled",
|
||||
inventory_image = "snow_sled.png",
|
||||
wield_image = "snow_sled.png",
|
||||
wield_scale = {x=2, y=2, z=1},
|
||||
liquids_pointable = true,
|
||||
stack_max = 1,
|
||||
|
||||
on_use = function(itemstack, placer)
|
||||
local pos = {x=0,y=-1000, z=0}
|
||||
local name = placer:get_player_name()
|
||||
if not players_sled[name] then
|
||||
local sled = minetest.env:add_entity(pos, "snow:sled")
|
||||
sled:get_luaentity():on_rightclick(placer)
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "snow:sled",
|
||||
recipe = {
|
||||
{"", "", ""},
|
||||
{"group:stick", "", ""},
|
||||
{"group:wood", "group:wood", "group:wood"},
|
||||
},
|
||||
})
|
||||
minetest.register_craft({
|
||||
output = "snow:sled",
|
||||
recipe = {
|
||||
{"", "", ""},
|
||||
{"", "", "group:stick"},
|
||||
{"group:wood", "group:wood", "group:wood"},
|
||||
},
|
||||
})
|
190
src/snowball.lua
Normal file
190
src/snowball.lua
Normal file
@ -0,0 +1,190 @@
|
||||
--============
|
||||
--Snowballs
|
||||
--============
|
||||
|
||||
-- Snowballs were destroying nodes if the snowballs landed just right.
|
||||
-- Quite a bit of trial-and-error learning here and it boiled down to a
|
||||
-- small handful of code lines making the difference. ~ LazyJ
|
||||
|
||||
local snowball_GRAVITY=9
|
||||
local snowball_VELOCITY=19
|
||||
|
||||
--Shoot snowball
|
||||
local snow_shoot_snowball=function (item, player, pointed_thing)
|
||||
local playerpos=player:getpos()
|
||||
local obj=minetest.add_entity({x=playerpos.x,y=playerpos.y+1.5,z=playerpos.z}, "snow:snowball_entity")
|
||||
local dir=player:get_look_dir()
|
||||
obj:setvelocity({x=dir.x*snowball_VELOCITY, y=dir.y*snowball_VELOCITY, z=dir.z*snowball_VELOCITY})
|
||||
obj:setacceleration({x=dir.x*-3, y=-snowball_GRAVITY, z=dir.z*-3})
|
||||
item:take_item()
|
||||
return item
|
||||
end
|
||||
|
||||
--The snowball Entity
|
||||
snow_snowball_ENTITY={
|
||||
physical = false,
|
||||
timer=0,
|
||||
textures = {"default_snowball.png"},
|
||||
lastpos={},
|
||||
collisionbox = {0,0,0,0,0,0},
|
||||
}
|
||||
|
||||
--Snowball_entity.on_step()--> called when snowball is moving.
|
||||
snow_snowball_ENTITY.on_step = function(self, dtime)
|
||||
self.timer=self.timer+dtime
|
||||
local pos = self.object:getpos()
|
||||
local node = minetest.get_node(pos)
|
||||
|
||||
--Become item when hitting a node.
|
||||
if self.lastpos.x~=nil then --If there is no lastpos for some reason. ~ Splizard
|
||||
-- Check to see what is one node above where the snow is
|
||||
-- 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
|
||||
local findwhatisabove = minetest.get_node(abovesnowballtarget).name
|
||||
-- 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 the node where the snow is going is anything except air, then it's OK to put
|
||||
-- the snow on it. ~ Original line of code by Splizard, comment by LazyJ so I can
|
||||
-- keep track of what this code does. ~ LazyJ, 2014_04_07
|
||||
if node.name ~= "air" then
|
||||
--snow.place(pos) -- this is the original code, I replaced it with
|
||||
-- minetest.place_node and bumped the y position up by 2 (make the snow drop
|
||||
-- from a node above and pile up). ~ LazyJ, 2014_04_07
|
||||
minetest.place_node({x=pos.x, y=pos.y+2, z=pos.z}, {name="default:snow"})
|
||||
self.object:remove()
|
||||
end
|
||||
else -- If findwhatisabove is not equal to "air" then cancel the snowball
|
||||
-- with self.object:remove() ~ LazyJ, 2014_04_08
|
||||
self.object:remove()
|
||||
end
|
||||
end
|
||||
self.lastpos={x=pos.x, y=pos.y, z=pos.z}
|
||||
end
|
||||
|
||||
|
||||
|
||||
minetest.register_entity("snow:snowball_entity", snow_snowball_ENTITY)
|
||||
|
||||
|
||||
|
||||
-- Snowball and Default Snowball Merged
|
||||
|
||||
-- They both look the same, they do basically the same thing (except one is a leftclick throw
|
||||
-- and the other is a rightclick drop),... Why not combine snow:snowball with default:snow and
|
||||
-- benefit from both? ~ LazyJ, 2014_04_08
|
||||
|
||||
--[[ Save this for reference and occasionally compare to the default code for any updates.
|
||||
|
||||
minetest.register_node(":default:snow", {
|
||||
description = "Snow",
|
||||
tiles = {"default_snow.png"},
|
||||
inventory_image = "default_snowball.png",
|
||||
wield_image = "default_snowball.png",
|
||||
is_ground_content = true,
|
||||
paramtype = "light",
|
||||
buildable_to = true,
|
||||
leveled = 7,
|
||||
drawtype = "nodebox",
|
||||
freezemelt = "default:water_flowing",
|
||||
node_box = {
|
||||
type = "leveled",
|
||||
fixed = {
|
||||
{-0.5, -0.5, -0.5, 0.5, -0.5+2/16, 0.5},
|
||||
},
|
||||
},
|
||||
groups = {crumbly=3,falling_node=1, melts=1, float=1},
|
||||
sounds = default.node_sound_dirt_defaults({
|
||||
footstep = {name="default_snow_footstep", gain=0.25},
|
||||
dug = {name="default_snow_footstep", gain=0.75},
|
||||
}),
|
||||
on_construct = function(pos)
|
||||
if minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name == "default:dirt_with_grass" or minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name == "default:dirt" then
|
||||
minetest.set_node({x=pos.x, y=pos.y-1, z=pos.z}, {name="default:dirt_with_snow"})
|
||||
end
|
||||
-- Now, let's turn the snow pile into a snowblock. ~ LazyJ
|
||||
if minetest.get_node({x=pos.x, y=pos.y-2, z=pos.z}).name == "default:snow" and -- Minus 2 because at the end of this, the layer that triggers the change to a snowblock is the second layer more than a full block, starting into a second block (-2) ~ LazyJ, 2014_04_11
|
||||
minetest.get_node({x=pos.x, y=pos.y, z=pos.z}).name == "default:snow" then
|
||||
minetest.set_node({x=pos.x, y=pos.y-2, z=pos.z}, {name="default:snowblock"})
|
||||
end
|
||||
end,
|
||||
on_use = snow_shoot_snowball -- This line is from the 'Snow' mod, the reset is default Minetest.
|
||||
})
|
||||
--]]
|
||||
|
||||
|
||||
|
||||
minetest.override_item("default:snow", {
|
||||
groups = {cracky=3, crumbly=3, choppy=3, oddly_breakable_by_hand=3,falling_node=1, melts=2, float=1},
|
||||
on_construct = function(pos)
|
||||
if minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name == "default:dirt_with_grass"
|
||||
or minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name == "default:dirt" then
|
||||
minetest.set_node({x=pos.x, y=pos.y-1, z=pos.z}, {name="default:dirt_with_snow"})
|
||||
end
|
||||
-- Now, let's turn the snow pile into a snowblock.
|
||||
if minetest.get_node({x=pos.x, y=pos.y-2, z=pos.z}).name == "default:snow" and
|
||||
-- Minus 2 because at the end of this, the layer that triggers the change to a snowblock
|
||||
-- is the second snowball layer more than the full block below. That second layer,from
|
||||
-- what I've observed, seems to push into a third node box above so by subracting 2,
|
||||
-- the swap_node target is moved back down to the first get_node y=pos.
|
||||
-- ~ LazyJ, 2014_04_24
|
||||
minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name == "default:snow" then
|
||||
minetest.set_node({x=pos.x, y=pos.y-2, z=pos.z}, {name="default:snowblock"})
|
||||
end
|
||||
end,
|
||||
on_use = snow_shoot_snowball -- This line is from the 'Snow' mod,
|
||||
-- the reset is default Minetest. ~ LazyJ
|
||||
})
|
||||
|
||||
|
||||
|
||||
--[[
|
||||
A note about default torches, melting, and "buildable_to = true" in default snow.
|
||||
|
||||
On servers where buckets are disabled, snow and ice stuff is used to set water for crops and
|
||||
water stuff like fountains, pools, ponds, ect.. It is a common practice to set a default torch on
|
||||
the snow placed where the players want water to be.
|
||||
|
||||
If you place a default torch *on* default snow to melt it, instead of melting the snow is
|
||||
*replaced* by the torch. Using "buildable_to = false" would fix this but then the snow would no
|
||||
longer pile-up in layers; the snow would stack like thin shelves in a vertical column.
|
||||
|
||||
I tinkered with the default torch's code (see below) to check for snow at the position and one
|
||||
node above (layered snow logs as the next y position above) but default snow's
|
||||
"buildable_to = true" always happened first. An interesting exercise to better learn how Minetest
|
||||
works, but otherwise not worth it. If you set a regular torch near snow, the snow will melt
|
||||
and disappear leaving you with nearly the same end result anyway. I say "nearly the same"
|
||||
because if you set a default torch on layered snow, the torch will replace the snow and be
|
||||
lit on the ground. If you were able to set a default torch *on* layered snow, the snow would
|
||||
melt and the torch would become a dropped item.
|
||||
|
||||
~ LazyJ
|
||||
|
||||
--]]
|
||||
|
||||
|
||||
-- Some of the ideas I tried. ~ LazyJ
|
||||
--[[
|
||||
local can_place_torch_on_top = function(pos)
|
||||
if minetest.get_node({x=pos.x, y=pos.y, z=pos.z}).name == "default:snow"
|
||||
or minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z}).name == "default:snow" then
|
||||
minetest.override_item("default:snow", {buildable_to = false,})
|
||||
end
|
||||
end
|
||||
--]]
|
||||
|
||||
|
||||
--[[
|
||||
minetest.override_item("default:torch", {
|
||||
--on_construct = function(pos)
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
--if minetest.get_node({x=pos.x, y=pos.y, z=pos.z}).name == "default:snow"
|
||||
-- Even though layered snow doesn't look like it's in the next position above (y+1)
|
||||
-- it registers in that position. Check the terminal's output to see the coord change.
|
||||
--or minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z}).name == "default:snow"
|
||||
if pointed_thing.name == "default:snow"
|
||||
then minetest.set_node({x=pos.x, y=pos.y+1, z=pos.z}, {name="default:torch"})
|
||||
end
|
||||
end
|
||||
})
|
||||
--]]
|
341
src/stairsplus.lua
Normal file
341
src/stairsplus.lua
Normal file
@ -0,0 +1,341 @@
|
||||
-- ===============================================================================
|
||||
-- StairsPlus Bonus!
|
||||
-- ===============================================================================
|
||||
--[[
|
||||
This section of code that makes blocks compatible with MoreBlocks' circular saw.
|
||||
I've added circular saw compatible code for default snowblocks and ice. :D
|
||||
A big thanks to Calinou and ShadowNinja for making this possible.
|
||||
|
||||
Because StairsPlus creates partial blocks, it didn't seem quite right that the
|
||||
smallest microblocks would produce a full-sized water_source node when melted.
|
||||
So I toned them down a bit by changing their melt to a temporary,
|
||||
2-second water_source. See "melts" in abms.lua file for the various intensities.
|
||||
|
||||
___...::: ATTENTION MINETEST SERVER OPERATORS :::...___
|
||||
You may or may not have noticed in your server logs that MoreBlocks stairs/slabs/
|
||||
panels/microblocks are not recorded as to when, who, what, and where. This is
|
||||
important information when trying to determine if a player who dug these blocks
|
||||
is the owner (the player who placed the block) or is a griefer stealing the block.
|
||||
|
||||
There is an option that will log when these blocks are placed but it comes at the
|
||||
cost of losing the auto-rotation of those blocks when placed. They can still be
|
||||
rotated with a screwdriver but if screwdrivers are disabled on your server your
|
||||
players won't be able to position MoreBlocks, saw-made blocks.
|
||||
|
||||
To enable logging the placement of these blocks, un-comment these lines:
|
||||
|
||||
--on_place = minetest.item_place
|
||||
|
||||
There is one in each of the "stairsplus.register_all" sections.
|
||||
|
||||
~ LazyJ
|
||||
-- ===============================================================================
|
||||
--]]
|
||||
|
||||
--snow_stairsplus = {}
|
||||
|
||||
-- Check for infinite stacks
|
||||
|
||||
--if minetest.get_modpath("unified_inventory") or not minetest.setting_getbool("creative_mode") then
|
||||
-- snow_stairsplus.expect_infinite_stacks = false
|
||||
--else
|
||||
-- snow_stairsplus.expect_infinite_stacks = true
|
||||
--end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-- First, let's run a check to see if MoreBlocks is installed; we're going to need it for the
|
||||
-- next section of stairsplus stuff. ~LazyJ
|
||||
|
||||
if (minetest.get_modpath("moreblocks"))
|
||||
|
||||
-- 'If' MoreBlocks was found, well, 'then' go ahead with this next part:
|
||||
|
||||
then
|
||||
|
||||
--[[ Leave commented out - For reference only. ~ LazyJ
|
||||
function stairsplus.register_all(modname, subname, recipeitem, fields)
|
||||
--stairsplus.register_stair_slab_panel_micro(modname, subname, recipeitem, fields)
|
||||
stairsplus:register_stair(modname, subname, recipeitem, fields)
|
||||
stairsplus:register_slab(modname, subname, recipeitem, fields)
|
||||
stairsplus:register_panel(modname, subname, recipeitem, fields)
|
||||
stairsplus:register_micro(modname, subname, recipeitem, fields)
|
||||
end
|
||||
Leave commented out
|
||||
--]]
|
||||
|
||||
|
||||
|
||||
-- Leave commented out. Another, possible piece of the puzzle, as to why the placement of
|
||||
-- stairsplus nodes aren't recorded in the logs. Shelved till I can concentrate on it again.
|
||||
-- ~ LazyJ
|
||||
|
||||
--ItemStack({name=nodename}):get_definition()
|
||||
--itemstack ={}
|
||||
--[[
|
||||
local def = itemstack:get_definition()
|
||||
function minetest.item_place_node(itemstack, placer, pointed_thing, param2)
|
||||
minetest.log("action", placer:get_player_name() .. " places node "
|
||||
.. def.name .. " at " .. minetest.pos_to_string(place_to))
|
||||
end
|
||||
Leave commented out
|
||||
--]]
|
||||
|
||||
|
||||
-- Leave commented out
|
||||
--[[ FIGURE OUT HOW TO GET THE SLABS TO SHOW UP IN THE LOG ON PLACEMENT
|
||||
|
||||
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
if pointed_thing.type ~= "node" then
|
||||
return itemstack
|
||||
end
|
||||
|
||||
-- If it's being placed on an another similar one, replace it with
|
||||
-- a full block
|
||||
local slabpos = nil
|
||||
local slabnode = nil
|
||||
local p0 = pointed_thing.under
|
||||
local p1 = pointed_thing.above
|
||||
local n0 = minetest.get_node(p0)
|
||||
local n1 = minetest.get_node(p1)
|
||||
local param2 = 0
|
||||
|
||||
local n0_is_upside_down = (n0.name == "snow:slab_" .. subname and
|
||||
n0.param2 >= 20)
|
||||
|
||||
if n0.name == "snow:slab_" .. subname and not n0_is_upside_down and p0.y+1 == p1.y then
|
||||
slabpos = p0
|
||||
slabnode = n0
|
||||
elseif n1.name == "snow:slab_" .. subname then
|
||||
slabpos = p1
|
||||
slabnode = n1
|
||||
end
|
||||
if slabpos then
|
||||
-- Remove the slab at slabpos
|
||||
minetest.remove_node(slabpos)
|
||||
-- Make a fake stack of a single item and try to place it
|
||||
local fakestack = ItemStack(recipeitem)
|
||||
fakestack:set_count(itemstack:get_count())
|
||||
|
||||
pointed_thing.above = slabpos
|
||||
local success
|
||||
fakestack, success = minetest.item_place(fakestack, placer, pointed_thing)
|
||||
-- If the item was taken from the fake stack, decrement original
|
||||
if success then
|
||||
itemstack:set_count(fakestack:get_count())
|
||||
-- Else put old node back
|
||||
else
|
||||
minetest.set_node(slabpos, slabnode)
|
||||
end
|
||||
return itemstack
|
||||
end
|
||||
|
||||
-- Upside down slabs
|
||||
if p0.y-1 == p1.y then
|
||||
-- Turn into full block if pointing at a existing slab
|
||||
if n0_is_upside_down then
|
||||
-- Remove the slab at the position of the slab
|
||||
minetest.remove_node(p0)
|
||||
-- Make a fake stack of a single item and try to place it
|
||||
local fakestack = ItemStack(recipeitem)
|
||||
fakestack:set_count(itemstack:get_count())
|
||||
|
||||
pointed_thing.above = p0
|
||||
local success
|
||||
fakestack, success = minetest.item_place(fakestack, placer, pointed_thing)
|
||||
-- If the item was taken from the fake stack, decrement original
|
||||
if success then
|
||||
itemstack:set_count(fakestack:get_count())
|
||||
-- Else put old node back
|
||||
else
|
||||
minetest.set_node(p0, n0)
|
||||
end
|
||||
return itemstack
|
||||
end
|
||||
|
||||
-- Place upside down slab
|
||||
param2 = 20
|
||||
end
|
||||
|
||||
-- If pointing at the side of a upside down slab
|
||||
if n0_is_upside_down and p0.y+1 ~= p1.y then
|
||||
param2 = 20
|
||||
end
|
||||
|
||||
return minetest.item_place(itemstack, placer, pointed_thing, param2)
|
||||
end
|
||||
Leave commented out
|
||||
--]]
|
||||
|
||||
|
||||
|
||||
--[[
|
||||
Below, in the "groups" line there is a "melts" category. Back in the ABMs lua file, melting
|
||||
code, melts=1 will produce a water_source when the full-sized snow/ice block is melted making
|
||||
a big, watery mess. melts=2 will produce a water_source only for a moment, then it changes back
|
||||
to water_flowing and then dries-up and disappears. I gave these stairs/slabs/panels/microblocks
|
||||
a melts value of 2 instead of 1 because they are not full blocks.
|
||||
|
||||
~ LazyJ
|
||||
--]]
|
||||
|
||||
-- Default snowblock and ice stairs/slabs/panels/microblocks.
|
||||
|
||||
local ndef = minetest.registered_nodes["default:ice"]
|
||||
local groups = {}
|
||||
for k, v in pairs(ndef.groups) do groups[k] = v end
|
||||
|
||||
stairsplus:register_all("moreblocks", "ice", "default:ice", {
|
||||
description = ndef.description,
|
||||
paramtype2 = "facedir",
|
||||
-- Added "icemaker=1" in groups. This ties into the freezing
|
||||
-- function in the ABMs.lua file. ~ LazyJ
|
||||
groups = {cracky=1, crumbly=1, choppy=1, oddly_breakable_by_hand=1, melts=2, icemaker=1},
|
||||
sounds = default.node_sound_glass_defaults(),
|
||||
tiles = ndef.tiles,
|
||||
-- Because of the "use_texture_alpha" line, that gives ice transparency, I couldn't combine
|
||||
-- default ice and default snowblocks in a list like MoreBlocks does. ~ LazyJ
|
||||
use_texture_alpha = true,
|
||||
sunlight_propagates = true,
|
||||
-- This "on_place" line makes placing these nodes recorded in the logs.
|
||||
-- Useful for investigating griefings and determining ownership
|
||||
-- BUT these nodes will nolonger auto-rotate into position. ~ LazyJ
|
||||
|
||||
--on_place = minetest.item_place,
|
||||
|
||||
-- The "on_construct" part below, thinking in terms of layers, dirt_with_snow could
|
||||
-- also double as dirt_with_frost which adds subtlety to the winterscape. ~ LazyJ
|
||||
on_construct = function(pos)
|
||||
pos.y = pos.y - 1
|
||||
if minetest.get_node(pos).name == "default:dirt_with_grass"
|
||||
or minetest.get_node(pos).name == "default:dirt" then
|
||||
minetest.set_node(pos, {name="default:dirt_with_snow"})
|
||||
end
|
||||
end
|
||||
})
|
||||
--end
|
||||
|
||||
|
||||
local ndef = minetest.registered_nodes["default:snowblock"]
|
||||
local groups = {}
|
||||
for k, v in pairs(ndef.groups) do groups[k] = v end
|
||||
|
||||
stairsplus:register_all("moreblocks", "snowblock", "default:snowblock", {
|
||||
description = ndef.description,
|
||||
paramtype2 = "facedir",
|
||||
-- Added "icemaker=1" in groups. This ties into the freezing function
|
||||
-- in the ABMs.lua file. ~ LazyJ
|
||||
groups = {cracky=3, crumbly=3, choppy=3, oddly_breakable_by_hand=3, melts=2, icemaker=1},
|
||||
tiles = ndef.tiles,
|
||||
sunlight_propagates = true,
|
||||
sounds = default.node_sound_dirt_defaults({
|
||||
footstep = {name="default_snow_footstep", gain=0.25},
|
||||
dig = {name="default_dig_crumbly", gain=0.4},
|
||||
dug = {name="default_snow_footstep", gain=0.75},
|
||||
place = {name="default_place_node", gain=1.0}
|
||||
}),
|
||||
-- This "on_place" line makes placing these nodes recorded in the logs.
|
||||
-- Useful for investigating griefings and determining ownership
|
||||
-- BUT these nodes will nolonger auto-rotate into position. ~ LazyJ
|
||||
|
||||
--on_place = minetest.item_place,
|
||||
|
||||
-- The "on_construct" part below, thinking in terms of layers,
|
||||
-- dirt_with_snow could also double as dirt_with_frost
|
||||
-- which adds subtlety to the winterscape. ~ LazyJ
|
||||
on_construct = function(pos)
|
||||
pos.y = pos.y - 1
|
||||
if minetest.get_node(pos).name == "default:dirt_with_grass"
|
||||
or minetest.get_node(pos).name == "default:dirt" then
|
||||
minetest.set_node(pos, {name="default:dirt_with_snow"})
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
|
||||
|
||||
-- Snow stairs/slabs/panels/microblocks.
|
||||
|
||||
local snow_nodes = {
|
||||
"snow_brick",
|
||||
"snow_cobble",
|
||||
}
|
||||
|
||||
for _, name in pairs(snow_nodes) do
|
||||
local nodename = "snow:"..name
|
||||
local ndef = minetest.registered_nodes[nodename]
|
||||
local groups = {}
|
||||
for k, v in pairs(ndef.groups) do groups[k] = v end
|
||||
|
||||
stairsplus:register_all("moreblocks", name, nodename, {
|
||||
description = ndef.description,
|
||||
drop = drop,
|
||||
groups = {cracky=2, crumbly=2, choppy=2, oddly_breakable_by_hand=2, melts=2, icemaker=1},
|
||||
tiles = ndef.tiles,
|
||||
--paramtype2 = "facedir",
|
||||
sunlight_propagates = true,
|
||||
sounds = default.node_sound_dirt_defaults({
|
||||
footstep = {name="default_snow_footstep", gain=0.25},
|
||||
dig = {name="default_dig_crumbly", gain=0.4},
|
||||
dug = {name="default_snow_footstep", gain=0.75},
|
||||
place = {name="default_place_node", gain=1.0}
|
||||
}),
|
||||
-- This "on_place" line makes placing these nodes recorded in the logs.
|
||||
-- Useful for investigating griefings and determining ownership
|
||||
-- BUT these nodes will nolonger auto-rotate into position. ~ LazyJ
|
||||
|
||||
--on_place = minetest.item_place,
|
||||
|
||||
|
||||
-- Some attempts to have both, the recording in the logs of the placing of
|
||||
-- the stairplus stuff *and* have the auto-rotation work. No luck yet.
|
||||
-- ~ LazyJ
|
||||
|
||||
--[[
|
||||
on_place = function (i, p, t)
|
||||
minetest.item_place(i, p, t, 0)
|
||||
minetest.rotate_node(i, p, t)
|
||||
end,
|
||||
--]]
|
||||
--[[
|
||||
on_place = function (i, p, t)
|
||||
minetest.rotate_node(i, p, t, 0)
|
||||
minetest.item_place(i, p, t)
|
||||
end,
|
||||
--]]
|
||||
|
||||
|
||||
|
||||
-- Picking up were we left off... ~ LazyJ
|
||||
|
||||
-- The "on_construct" part below, thinking in terms of layers, dirt_with_snow could
|
||||
-- also double as dirt_with_frost which adds subtlety to the winterscape. ~ LazyJ
|
||||
on_construct = function(pos)
|
||||
pos.y = pos.y - 1
|
||||
if minetest.get_node(pos).name == "default:dirt_with_grass"
|
||||
or minetest.get_node(pos).name == "default:dirt"
|
||||
then minetest.set_node(pos, {name="default:dirt_with_snow"})
|
||||
end
|
||||
-- Some ideas I've tried. Leaving for future reference till I can figure out a workable solution. ~ LazyJ
|
||||
--minetest.log("action", sender:get_player_name().." places" ..minetest.get_node(pos).name.. "at" ..minetest.pos_to_string(pos))
|
||||
--minetest.log("action", minetest.get_player_name().." places" ..minetest.get_node(pos).name.. "at" ..minetest.pos_to_string(pos))
|
||||
--minetest.log("action", "BINGO places "..minetest.get_name().." at "..minetest.pos_to_string(pos))
|
||||
--minetest.log("action", minetest.get_player_name().." places "..minetest.get_name().." at "..minetest.pos_to_string(pos))
|
||||
--minetest.log("action", placer:get_player_name().." places moreblocks-something at "..minetest.pos_to_string(pos))
|
||||
--minetest.log("action", " BINGO places "..minetest.get_pointed_thing().." at "..minetest.pos_to_string(pos))
|
||||
--minetest.log("action", "BINGO places moreblocks"..ndef.." at "..minetest.pos_to_string(pos))
|
||||
--minetest.log("action", "A pine sapling grows into a Christmas tree at "..minetest.pos_to_string(pos))
|
||||
--return minetest.item_place(itemstack, placer, pointed_thing, param2)
|
||||
--return minetest.item_place(itemstack, pointed_thing, param2)
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
else -- from clear up at the top, the MoreBlocks check. "Else", if MoreBlocks wasn't found, skip
|
||||
-- down to here, "return" nothing and "end" this script. ~ LazyJ
|
||||
return
|
||||
end
|
155
src/util.lua
Normal file
155
src/util.lua
Normal file
@ -0,0 +1,155 @@
|
||||
--Global config and function table.
|
||||
snow = {
|
||||
legacy = true,
|
||||
sleds = true,
|
||||
enable_snowfall = true,
|
||||
lighter_snowfall = false,
|
||||
debug = false,
|
||||
smooth_biomes = true,
|
||||
christmas_content = true,
|
||||
smooth_snow = true,
|
||||
min_height = 3,
|
||||
}
|
||||
|
||||
--Config documentation.
|
||||
local doc = {
|
||||
legacy = "Whether you are running a legacy minetest version (auto-detected).",
|
||||
sleds = "Disable this to prevent sleds from being riden.",
|
||||
enable_snowfall = "Enables falling snow.",
|
||||
lighter_snowfall = "Reduces the amount of resources and fps used by snowfall.",
|
||||
debug = "Enables debug output.",
|
||||
smooth_biomes = "Enables smooth transition of biomes",
|
||||
christmas_content = "Disable this to remove christmas saplings from being found.",
|
||||
smooth_snow = "Disable this to stop snow from being smoothed.",
|
||||
min_height = "The minumum height a snow biome will generate.",
|
||||
}
|
||||
|
||||
--Manage config.
|
||||
--Saves contents of config to file.
|
||||
local function saveConfig(path, config, doc)
|
||||
local file = io.open(path,"w")
|
||||
if file then
|
||||
for i,v in pairs(config) do
|
||||
local t = type(v)
|
||||
if t == "string" or t == "number" or t == "boolean" then
|
||||
if doc and doc[i] then
|
||||
file:write("# "..doc[i].."\n")
|
||||
end
|
||||
file:write(i.." = "..tostring(v).."\n")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
--Loads config and returns config values inside table.
|
||||
local function loadConfig(path)
|
||||
local config = {}
|
||||
local file = io.open(path,"r")
|
||||
if file then
|
||||
io.close(file)
|
||||
for line in io.lines(path) do
|
||||
if line:sub(1,1) ~= "#" then
|
||||
i, v = line:match("^(%S*) = (%S*)")
|
||||
if i and v then
|
||||
if v == "true" then v = true end
|
||||
if v == "false" then v = false end
|
||||
if tonumber(v) then v = tonumber(v) end
|
||||
config[i] = v
|
||||
end
|
||||
end
|
||||
end
|
||||
return config
|
||||
else
|
||||
--Create config file.
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_on_shutdown(function() saveConfig(minetest.get_modpath("snow").."/config.txt", snow, doc) end)
|
||||
|
||||
local config = loadConfig(minetest.get_modpath("snow").."/config.txt")
|
||||
if config then
|
||||
for i,v in pairs(config) do
|
||||
if type(snow[i]) == type(v) then
|
||||
snow[i] = v
|
||||
end
|
||||
end
|
||||
else
|
||||
saveConfig(minetest.get_modpath("snow").."/config.txt", snow, doc)
|
||||
end
|
||||
|
||||
for i,v in pairs(snow) do
|
||||
local t = type(v)
|
||||
if t == "string" or t == "number" or t == "boolean" then
|
||||
local v = minetest.setting_get("snow_"..i)
|
||||
if v ~= nil then
|
||||
if v == "true" then v = true end
|
||||
if v == "false" then v = false end
|
||||
if tonumber(v) then v = tonumber(v) end
|
||||
snow[i] = v
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--AUTO DETECT and/or OVERIDEN values--
|
||||
|
||||
--legacy--
|
||||
--Detect if we are running the latest minetest.
|
||||
if minetest.register_on_mapgen_init then
|
||||
snow.legacy = false
|
||||
else
|
||||
snow.legacy = true
|
||||
end
|
||||
if config and snow.legacy ~= config.legacy then
|
||||
saveConfig(minetest.get_modpath("snow").."/config.txt", snow, doc)
|
||||
end
|
||||
|
||||
--MENU
|
||||
|
||||
local get_formspec = function()
|
||||
local p = -0.5
|
||||
local formspec = "label[0,-0.3;Settings:]"
|
||||
for i,v in pairs(snow) do
|
||||
local t = type(v)
|
||||
if t == "string" or t == "number" then
|
||||
p = p + 1.5
|
||||
formspec = formspec.."field[0.3,"..p..";2,1;snow:"..i..";"..i..";"..v.."]"
|
||||
elseif t == "boolean" then
|
||||
p = p + 0.5
|
||||
formspec = formspec.."checkbox[0,"..p..";snow:"..i..";"..i..";"..tostring(v).."]"
|
||||
end
|
||||
end
|
||||
p = p + 1
|
||||
formspec = "size[4,"..p..";]\n"..formspec
|
||||
return formspec
|
||||
end
|
||||
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
if formname == "snow:menu" then
|
||||
for i,v in pairs(snow) do
|
||||
local t = type(v)
|
||||
if t == "string" or t == "number" or t == "boolean" then
|
||||
if fields["snow:"..i] then
|
||||
if t == "string" then
|
||||
snow[i] = fields["snow:"..i]
|
||||
end
|
||||
if t == "number" then
|
||||
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)
|
||||
|
||||
|
||||
minetest.register_chatcommand("snow", {
|
||||
description = "Show a menu for various actions",
|
||||
privs = {server=true},
|
||||
func = function(name, param)
|
||||
minetest.show_formspec(name, "snow:menu", get_formspec())
|
||||
end,
|
||||
})
|
Reference in New Issue
Block a user