1
0
mirror of https://github.com/Splizard/minetest-mod-snow.git synced 2025-06-29 23:00:24 +02:00

1 Commits

Author SHA1 Message Date
84561db68a Version MFF. 2018-09-08 16:30:03 +02:00
104 changed files with 1545 additions and 964 deletions

View File

@ -1,11 +0,0 @@
on: [push, pull_request]
name: luacheck
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: lint
uses: Roang-zero1/factorio-mod-luacheck@master
with:
luacheckrc_url: ""

0
.gitignore vendored Normal file → Executable file
View File

View File

@ -1,25 +0,0 @@
read_globals = {
"dump", "vector",
"table", "math", "PseudoRandom", "VoxelArea",
"stairs", "stairsplus", "skins", "treecapitator",
default = {
fields = {
player_attached = {
read_only = false,
other_fields = true
}
},
other_fields = true
},
minetest = {
fields = {
registered_nodes = {
read_only = false,
other_fields = true
}
},
other_fields = true
}
}
globals = {"snow"}
-- ignore = {"421", "423"}

0
LazyJ-changelog.txt Normal file → Executable file
View File

5
changelog.txt Normal file → Executable file
View File

@ -1,10 +1,5 @@
CHANGELOG:
------------
Version 4.0
Snow mod is now a complimentary mod to the default snow found in minetest.
HybridDog's large changes, fixes and more (see commit log).
Version 3.2

4
depends.txt Normal file → Executable file
View File

@ -1,6 +1,4 @@
default
flowers?
stairs?
moreblocks?
skins?
treecapitator?
watershed?

55
init.lua Normal file → Executable file
View File

@ -47,35 +47,43 @@ http://github.com/Splizard/minetest-mod-snow/
-- Until something else can be figured out, use paramat's "Snowdrift" mod instead.
-- dofile(modpath.."/falling_snow.lua")
local load_time_start = minetest.get_us_time()
-- Original init.lua File Broken into Smaller Files
local srcpath = minetest.get_modpath"snow".."/src/"
dofile(srcpath.."abms.lua")
dofile(srcpath.."aliases.lua")
dofile(srcpath.."crafting.lua")
local modpath = minetest.get_modpath("snow")
dofile(modpath.."/src/abms.lua")
dofile(modpath.."/src/aliases.lua")
dofile(modpath.."/src/crafting.lua")
-- The formspec menu didn't work when util.lua was the very first "dofile" so I moved
-- it and all the other original "dofiles", in order, to the bottom of the list. ~ LazyJ
-- Minetest would crash if the mapgen was called upon before the rest of other snow lua files so
-- I put it lower on the list and that seems to do the trick. ~ LazyJ
dofile(srcpath.."util.lua")
dofile(srcpath.."snowball.lua")
dofile(modpath.."/src/util.lua")
dofile(modpath.."/src/snowball.lua")
-- To get Xmas tree saplings, the "christmas_content", true or false, in "util.lua" has to be determined first.
-- That means "nodes.lua", where the saplings are controlled, has to come after "util.lua". ~ LazyJ
dofile(srcpath.."nodes.lua")
dofile(srcpath.."stairs.lua")
dofile(srcpath.."mapgen.lua")
dofile(srcpath.."sled.lua")
dofile(srcpath.."falling_snow.lua")
dofile(modpath.."/src/nodes.lua")
dofile(modpath.."/src/basic_stairs_slabs.lua")
-- dofile(modpath.."/src/mapgen.lua")
dofile(modpath.."/src/sled.lua")
-- dofile(modpath.."/src/falling_snow.lua")
-- Check for "MoreBlocks". If not found, skip this next "dofile".
if rawget(_G, "stairsplus")
and minetest.get_modpath("moreblocks") then
dofile(modpath.."/src/stairsplus.lua")
end
local is_uneven
--This function places snow checking at the same time for snow level and increasing as needed.
--This also takes into account sourrounding snow and makes snow even.
function snow.place(pos, disablesound)
function snow.place(pos)
if pos.y < -19000 then return end -- Don't put anything in the nether!
local node = minetest.get_node_or_nil(pos)
--Oops, maybe there is no node?
@ -89,23 +97,17 @@ function snow.place(pos, disablesound)
if level < 63 then
if minetest.get_item_group(minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name, "leafdecay") == 0
and not is_uneven(pos) then
if not disablesound then
minetest.sound_play("default_snow_footstep", {pos=pos})
end
minetest.add_node_level(pos, 7)
end
elseif level == 63 then
local p = minetest.find_node_near(pos, 10, "default:dirt_with_grass")
if p
and minetest.get_node_light(p, 0.5) == 15 then
if not disablesound then
minetest.sound_play("default_grass_footstep", {pos=pos})
end
minetest.place_node({x=pos.x, y=pos.y+1, z=pos.z}, {name="default:snow"})
else
if not disablesound then
minetest.sound_play("default_snow_footstep", {pos=pos})
end
minetest.add_node(pos, {name="default:snowblock"})
end
end
@ -117,7 +119,7 @@ function snow.place(pos, disablesound)
or drawtype == "allfaces_optional" then
pos.y = pos.y+1
local sound = data.sounds
if sound and not disablesound then
if sound then
sound = sound.footstep
if sound then
minetest.sound_play(sound.name, {pos=pos, gain=sound.gain})
@ -196,12 +198,3 @@ snow.register_on_configuring(function(name, v)
end
end
end)
local time = (minetest.get_us_time() - load_time_start) / 1000000
local msg = "[snow] loaded after ca. " .. time .. " seconds."
if time > 0.01 then
print(msg)
else
minetest.log("info", msg)
end

37
license.txt Normal file → Executable file
View File

@ -1,40 +1,3 @@
License of media (snowdrift are from paramat)
---------------------------
Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)
You are free to:
Share — copy and redistribute the material in any medium or format.
Adapt — remix, transform, and build upon the material for any purpose, even commercially.
The licensor cannot revoke these freedoms as long as you follow the license terms.
Under the following terms:
Attribution — You must give appropriate credit, provide a link to the license, and
indicate if changes were made. You may do so in any reasonable manner, but not in any way
that suggests the licensor endorses you or your use.
ShareAlike — If you remix, transform, or build upon the material, you must distribute
your contributions under the same license as the original.
No additional restrictions — You may not apply legal terms or technological measures that
legally restrict others from doing anything the license permits.
Notices:
You do not have to comply with the license for elements of the material in the public
domain or where your use is permitted by an applicable exception or limitation.
No warranties are given. The license may not give you all of the permissions necessary
for your intended use. For example, other rights such as publicity, privacy, or moral
rights may limit how you use the material.
For more details:
http://creativecommons.org/licenses/by-sa/3.0/
License of source code and other textures.
----------------------
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007

View File

@ -1 +0,0 @@
name = snow

Binary file not shown.

0
models/sled.x Normal file → Executable file
View File

0
other_textures/connected_textures_ice.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 656 B

After

Width:  |  Height:  |  Size: 656 B

0
other_textures/default_ice.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 82 B

After

Width:  |  Height:  |  Size: 82 B

0
other_textures/default_ice.xcf Normal file → Executable file
View File

Binary file not shown.

Before

Width:  |  Height:  |  Size: 164 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 384 B

0
other_textures/inkscape_default_ice.svg Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

0
other_textures/mocha.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 83 B

After

Width:  |  Height:  |  Size: 83 B

0
other_textures/mocha.xcf Normal file → Executable file
View File

0
other_textures/original_snow_snow_brick.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 300 B

After

Width:  |  Height:  |  Size: 300 B

0
other_textures/rect2985.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 81 B

After

Width:  |  Height:  |  Size: 81 B

0
other_textures/snow_ice.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 371 B

After

Width:  |  Height:  |  Size: 371 B

0
other_textures/snow_needles_decorated_animated.xcf Normal file → Executable file
View File

0
other_textures/snow_snow.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 164 B

After

Width:  |  Height:  |  Size: 164 B

0
other_textures/snow_snow_brick.xcf Normal file → Executable file
View File

0
other_textures/snow_snow_cobble.xcf Normal file → Executable file
View File

0
other_textures/snow_snow_side.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 726 B

After

Width:  |  Height:  |  Size: 726 B

0
other_textures/snow_snowball.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 127 B

After

Width:  |  Height:  |  Size: 127 B

0
other_textures/snow_snowfall.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 190 B

After

Width:  |  Height:  |  Size: 190 B

0
other_textures/snow_star_lit.xcf Normal file → Executable file
View File

0
other_textures/xdefault_cobble.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 297 B

After

Width:  |  Height:  |  Size: 297 B

0
other_textures/xdefault_furnace_bottom.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 602 B

After

Width:  |  Height:  |  Size: 602 B

0
other_textures/xdefault_furnace_fire_bg.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 204 B

After

Width:  |  Height:  |  Size: 204 B

0
other_textures/xdefault_furnace_fire_fg.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 719 B

After

Width:  |  Height:  |  Size: 719 B

0
other_textures/xdefault_furnace_front.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 553 B

After

Width:  |  Height:  |  Size: 553 B

0
other_textures/xdefault_furnace_front_active.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

0
other_textures/xdefault_furnace_side.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 602 B

After

Width:  |  Height:  |  Size: 602 B

0
other_textures/xdefault_furnace_top.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 602 B

After

Width:  |  Height:  |  Size: 602 B

0
other_textures/xdefault_glass.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 204 B

After

Width:  |  Height:  |  Size: 204 B

0
other_textures/xdefault_ice.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 371 B

After

Width:  |  Height:  |  Size: 371 B

0
other_textures/xdefault_ice.xcf Normal file → Executable file
View File

0
other_textures/xdefault_snow.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 164 B

After

Width:  |  Height:  |  Size: 164 B

0
other_textures/xdefault_stone_brick.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 572 B

After

Width:  |  Height:  |  Size: 572 B

49
readme.txt Normal file → Executable file
View File

@ -5,19 +5,21 @@
____) | | | | (_) \ V V / | | | | (_) | (_| |
|_____/|_| |_|\___/ \_/\_/ |_| |_|\___/ \__,_|
Version 4.0
Version 3.2
By Splizard, HybridDog and LazyJ.
By Splizard and LazyJ.
Minetest version: 0.4.16+
Minetest version: 0.4.9
Depends: default
License: GPL v3
License: GPL v2
Complimentary Mods:
---------------------
* "Snowdrift" by paramat
* "More Blocks" by Calinou (2014_05_11 or newer)
* "Skins" by Zeg9
Install:
Forum post: http://minetest.net/forum/viewtopic.php?id=2290
@ -41,8 +43,26 @@ Place this folder in your minetest mods folder.
world's "world.mt" file:
load_mod_snow = true
NOTICE
While this mod is installed you may experience slower map loading while a snow biome is generated.
USAGE:
-------
If you walk around a bit you will find snow biomes scattered around the world.
There are nine biome types:
* Normal
* Icebergs
* Icesheet
* Broken icesheet
* Icecave
* Coast
* Alpine
* Snowy
* Plain
Snow can be picked up and thrown as snowballs or stacked into snow blocks.
Snow and ice melts when near warm blocks such as torches or igniters such as lava.
Snow blocks freeze water source blocks around them.
@ -66,21 +86,18 @@ Icy Snow:
Snow Ice
Ice Snow
MAPGEN_V7:
------------
If you are using minetest 0.4.8 or the latest dev version of minetest you can choose to generate a v7 map.
This option can be found when creating a new map from the menu.
Snow Biomes has support for this though you might need a couple other biomes too otherwise you will only spawn snow.
There are a couple of bugs and limitations with this such as no ice being generated at the moment.
Config file:
------------
You can change various settings from the advanced settings in Minetest.
* Go to the settings tab.
* Click on Advanced Settings.
* Click on Mods.
* Click on snow.
* Change stuff!
After starting a game in minetest with snow mod, a config file will be placed in this folder that contains the various options for snow mod.
As admin you can use the /snow command in-game to make various changes.
UNINSTALL:
------------
Simply delete the folder snow from the mods folder.
TODO:
— test if the fixed ground_y search works correctly at chunkcorners at ground level

0
schematics/pine.mts Normal file → Executable file
View File

View File

@ -1,39 +0,0 @@
#The gravity of thrown snowballs.
snow_snowball_gravity (Snowball Gravity) float 0.91
#How fast players throw snowballs.
snow_snowball_velocity (Snowball Velocity) float 19
#Enable/Disable sleds.
snow_sleds (Enable Sleds) bool true
#Enables falling snow.
snow_enable_snowfall (Enable Snowfall) bool true
#Reduces the amount of resources and fps used by snowfall.
snow_lighter_snowfall (Use Light Snowfall) bool false
#Enables debug output. Currently it only prints mgv6 info.
snow_debug (Debug Mode) bool false
#Disable this to remove christmas saplings from being found.
snow_christmas_content (Enable Christmas Content) bool true
#Enables smooth biome transitions.
snow_smooth_biomes (Smooth Biome Transitions) bool true
#The minumum height a snow biome will generate (mgv7)
snow_min_height (Minumum Height for Snow Biomes) int 3
#Disable this to stop snow from being smoothed.
snow_smooth_snow (Multiple Snow Levels) bool true
#mapgen rarity in %. Note that this and mapgen_size do not work right because
#sinus instead of Gauss curve is used as estimation.
snow_mapgen_rarity (Snow Biome Rarity %) float 18
#size of the generated… (has an effect to the rarity, too)
snow_mapgen_size (Snow Biome Size) float 210
#Minetest finally has capable snow biomes by default, lets not mess it up with the old snowgen.
snow_disable_mapgen (Disable mod-generated biomes) bool true

41
src/abms.lua Normal file → Executable file
View File

@ -1,12 +1,23 @@
-- 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
--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)
minetest.add_node(pos, {name="default:snow"})
minetest.set_node_level(pos, 7*(tonumber(node.name:sub(-1))))
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)
action = function(pos, node)
local name = minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z}).name
local nodedef = minetest.registered_nodes[name]
if name ~= "ignore"
@ -70,6 +81,7 @@ minetest.register_abm({
else
return
end
nodeupdate(pos)
end,
})
@ -108,10 +120,7 @@ minetest.register_abm({
if math.random(2) == 2 then
p.y = pos.y
if minetest.get_node(p).name == "default:water_source" then
minetest.add_node(p, {
name = "default:ice",
param2 = math.random(0,node.param2-1)
})
minetest.add_node(p,{name="default:ice", param2 = math.random(0,node.param2-1)})
end
end
end
@ -143,13 +152,13 @@ minetest.register_abm({
--[[
--Grow Pine Saplings
minetest.register_abm({
nodenames = {"snow:sapling_pine"},
interval = 10,
chance = 50,
action = function(pos)
action = function(pos, node)
-- Check if there is enough vertical-space for the sapling to grow without
-- hitting anything else. ~ LazyJ, 2014_04_10
@ -162,7 +171,7 @@ minetest.register_abm({
end
-- 'then' let the sapling grow into a tree. ~ LazyJ
snow.make_pine(pos,false)
-- snow.make_pine(pos,false)
-- This finds the sapling under the grown tree. ~ LazyJ
if minetest.get_node(pos).name == "snow:sapling_pine" then
-- This switches the sapling to a tree trunk. ~ LazyJ
@ -172,17 +181,17 @@ minetest.register_abm({
minetest.log("action", "A pine sapling grows into a tree at "..minetest.pos_to_string(pos))
end
end
})
})]]
--[[
--Grow Christmas Tree Saplings
minetest.register_abm({
nodenames = {"snow:xmas_tree"},
interval = 10,
chance = 50,
action = function(pos)
action = function(pos, node)
-- 'If' there is air in each of the 8 nodes dirctly above the sapling,... ~LazyJ
for i = 1,8 do
@ -192,14 +201,14 @@ minetest.register_abm({
end
-- 'then' let the sapling grow into a tree. ~ LazyJ
snow.make_pine(pos,false,true)
--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
})
})]]

4
src/aliases.lua Normal file → Executable file
View File

@ -1,6 +1,7 @@
-- Some aliases for compatibility switches and some to make "/give" commands
-- a little easier
minetest.register_alias("snow:needles", "default:pine_needles")
minetest.register_alias("snow:snow", "default:snow")
minetest.register_alias("default_snow", "default:snow")
minetest.register_alias("snow:snowball", "default:snow")
@ -25,7 +26,8 @@ minetest.register_alias("icysnow", "snow:snow_cobble")
minetest.register_alias("snowcobble", "snow:snow_cobble")
minetest.register_alias("snowycobble", "snow:snow_cobble")
minetest.register_alias("cobblesnow", "snow:snow_cobble")
minetest.register_alias("snow:leaves", "default:pine_needles")
minetest.register_alias("snow:sapling_pine", "default:pine_sapling")
-- To clean up my first stairsplus attempt.
-- Stair

302
src/basic_stairs_slabs.lua Executable file
View File

@ -0,0 +1,302 @@
-- 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
-- what of the recipeitem can be copied
local recipe_values = {
"description", "tiles", "groups", "sounds", "use_texture_alpha", "sunlight_propagates",
"freezemelt", "liquidtype", "sunlight_propagates",
"stair_desc", "slab_desc"
}
local stairdef = {
drawtype = "nodebox",
paramtype = "light",
paramtype2 = "facedir",
is_ground_content = 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}
}),
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
local node = minetest.get_node(pos)
if node.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 node.name == "default:dirt" then
node.name = "default:dirt_with_snow"
minetest.set_node(pos, node)
end
end
}
-- Node will be called snow:stair_<subname>
local function register_stair(subname, recipeitem, newdef)
local def = table.copy(stairdef)
for n,i in pairs(newdef) do
def[n] = i
end
local name = "snow:stair_" .. subname
minetest.register_node(name, def)
--[[
-- for replace ABM
minetest.register_node("snow:stair_" .. subname.."upside_down", {
replace_name = "snow:stair_" .. subname,
groups = {slabs_replace=1},
})
--]]
minetest.register_craft({
output = name .. " 6",
recipe = {
{recipeitem, "", ""},
{recipeitem, recipeitem, ""},
{recipeitem, recipeitem, recipeitem},
},
})
-- Flipped recipe
minetest.register_craft({
output = name .. " 6",
recipe = {
{"", "", recipeitem},
{"", recipeitem, recipeitem},
{recipeitem, recipeitem, recipeitem},
},
})
end
local slabdef = table.copy(stairdef)
slabdef.node_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
}
slabdef.on_place = nil
-- Node will be called snow:slab_<subname>
local function register_slab(subname, recipeitem, newdef)
local def = table.copy(slabdef)
local name = "snow:slab_" .. subname
def.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, slabnode
local p0 = pointed_thing.under
local p1 = pointed_thing.above
local n0 = minetest.get_node(p0)
local n1 = minetest.get_node(p1)
local n0_is_upside_down = (n0.name == name and
n0.param2 >= 20)
if n0.name == name
and not n0_is_upside_down
and p0.y+1 == p1.y then
slabpos = p0
slabnode = n0
elseif n1.name == name 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
local param2
-- 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
elseif n0_is_upside_down
and p0.y+1 ~= p1.y then
-- If pointing at the side of a upside down slab
param2 = 20
end
return minetest.item_place(itemstack, placer, pointed_thing, param2)
end
for n,i in pairs(newdef) do
def[n] = i
end
minetest.register_node(name, def)
--[[
-- for replace ABM
minetest.register_node("snow:slab_" .. subname.."upside_down", {
replace_name = "snow:slab_"..subname,
groups = {slabs_replace=1},
})
--]]
minetest.register_craft({
output = name .. " 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>
local function register_stair_and_slab(subname, recipeitem, def)
local recipedef = minetest.registered_nodes[recipeitem]
for _,i in pairs(recipe_values) do
if def[i] == nil
and recipedef[i] ~= nil then
def[i] = recipedef[i]
end
end
local groups = table.copy(def.groups)
groups.cooks_into_ice = nil
if groups.melts then
groups.melts = math.min(groups.melts+1, 3)
end
def.groups = groups
local stair_desc = def.stair_desc
def.stair_desc = nil
local slab_desc = def.slab_desc
def.slab_desc = nil
def.description = stair_desc
register_stair(subname, recipeitem, def)
def.description = slab_desc
register_slab(subname, recipeitem, def)
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", "Ice Stairs", "Ice Slabs"},
{"snowblock", "default:snowblock", "Snowblock Stairs", "Snowblock Slabs"},
{"snow_cobble", "snow:snow_cobble", "Snow Cobble Stairs", "Snow Cobble Slabs"},
{"snow_brick", "snow:snow_brick", "Snow Brick Stair", "Snow Brick Slab"},
{"ice_brick", "snow:ice_brick", "Ice Brick Stair", "Ice Brick Slab"},
}
for _, row in pairs(list_of_snow_stuff) do
register_stair_and_slab(row[1], row[2], {
stair_desc = row[3],
slab_desc = row[4],
})
end

0
src/crafting.lua Normal file → Executable file
View File

442
src/falling_snow.lua Normal file → Executable file
View File

@ -1,6 +1,184 @@
-- Parameters
--[[
--=================
--======================================
LazyJ's Fork of Splizard's "Snow" Mod
by LazyJ
version: Umpteen and 7/5ths something or another.
2014_04_12
--======================================
--=================
local function snow_fall(pos)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
both are already fixed -- Hybrid Dog
--]]
--=============================================================
-- CODE STUFF
--=============================================================
local weather_legacy
local worldpath = minetest.get_worldpath()
local read_weather_legacy = function ()
local file = io.open(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(worldpath.."/weather_v6", "w+")
file:write(weather_legacy)
file:close()
end
weather_legacy = read_weather_legacy() or ""
local function leg_step()
if weather_legacy == "snow" then
if math.random(1000) == 1 then
weather_legacy = "none"
save_weather_legacy()
end
elseif math.random(5000) == 2 then
weather_legacy = "snow"
save_weather_legacy()
end
minetest.after(2, leg_step)
end
minetest.after(4, leg_step)
local function infolog(msg)
minetest.log("info", "[snow] falling_snow: "..msg)
end
-- copied from meru mod
local SEEDDIFF3 = 9130 -- 9130 -- Values should match minetest mapgen desert perlin.
local OCTAVES3 = 3 -- 3
local PERSISTENCE3 = 0.5 -- 0.5
local SCALE3 = 250 -- 250
-- cache perlin noise tests
local perlin_scale, rarity
local cold_perl_values = {}
setmetatable(cold_perl_values, {__mode = "kv"})
local function cold_perlin_test(x, y)
if not cold_perl_values[y] then
cold_perl_values[y] = {}
setmetatable(cold_perl_values[y], {__mode = "kv"})
end
local v = cold_perl_values[y][x]
if v ~= nil then
return v
end
if not rarity then
rarity = snow.mapgen.smooth_rarity_min
perlin_scale = snow.mapgen.perlin_scale
end
v = minetest.get_perlin(112,3, 0.5, perlin_scale):get2d({x=x, y=y}) >= rarity
cold_perl_values[y][x] = v
return v
end
-- disable falling snow in desert
local desert_perl_values = {}
setmetatable(desert_perl_values, {__mode = "kv"})
local function is_desert(x, y)
if not desert_perl_values[y] then
desert_perl_values[y] = {}
setmetatable(desert_perl_values[y], {__mode = "kv"})
end
local v = desert_perl_values[y][x]
if v ~= nil then
return v
end
-- Offsets must match minetest mapgen desert perlin.
-- Smooth transition 0.35 to 0.45.
v = minetest.get_perlin(SEEDDIFF3, OCTAVES3, PERSISTENCE3, SCALE3):get2d({x=x+150,y=y+50}) <= 0.35
desert_perl_values[y][x] = v
return v
end
--Get snow at position.
local function get_snow(pos)
return weather_legacy == "snow" --Legacy support.
and cold_perlin_test(pos.x, pos.z)
and not is_desert(pos.x, pos.z)
end
local addvectors = vector.add
--Returns a random position between minp and maxp.
-- TODO: make a fload random position
local function randpos(minp, maxp)
local x,z
if minp.x > maxp.x then
x = math.random(maxp.x,minp.x)
else
x = math.random(minp.x,maxp.x)
end
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=minp.y,z=z}
end
local default_snow_particle = {
amount = 3,
time = 0.5,
exptime = 5,
size = 50,
collisiondetection = false,
vertical = false,
}
local function get_snow_particledef(data)
for n,i in pairs(default_snow_particle) do
data[n] = data[n] or i
end
for _,i in pairs({"vel", "acc", "exptime", "size"}) do
data["min"..i] = data[i]
data["max"..i] = data[i]
end
data.texture = "weather_snow.png^[transform"..math.random(0,7)
return data
end
local function snow_fall(pos, player, animate)
local ground_y = nil
for y=pos.y+10,pos.y+20,1 do
local n = minetest.get_node({x=pos.x,y=y,z=pos.z}).name
@ -21,191 +199,99 @@ local function snow_fall(pos)
pos = {x=pos.x, y=ground_y, z=pos.z}
if not get_snow(pos) then
return
end
if animate then
local spos = {x=pos.x, y=ground_y+10, z=pos.z}
minetest.add_particlespawner(get_snow_particledef({
minpos = addvectors(spos, {x=-9, y=3, z=-9}),
maxpos = addvectors(spos, {x= 9, y=5, z= 9}),
vel = {x=0, y=-1, z=-1},
acc = {x=0, y=0, z=0},
playername = 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
local YLIMIT = 1 -- Set to world's water level
-- Particles are timed to disappear at this y
-- Particles do not spawn when player's head is below this y
local PRECSPR = 6 -- Time scale for precipitation variation in minutes
local PRECOFF = -0.4 -- Precipitation offset, higher = rains more often
local GSCYCLE = 0.5 -- Globalstep cycle (seconds)
local FLAKES = 32 -- Snowflakes per cycle
--~ local DROPS = 128 -- Raindrops per cycle
--~ local RAINGAIN = 0.2 -- Rain sound volume
local COLLIDE = false -- Whether particles collide with nodes
local NISVAL = 39 -- Clouds RGB value at night
local DASVAL = 175 -- Clouds RGB value in daytime
-- Snow
local lighter_snowfall = snow.lighter_snowfall
local function calc_snowfall()
for _, player in pairs(minetest.get_connected_players()) do
local ppos = player:getpos()
local np_prec = {
offset = 0,
scale = 1,
spread = {x = PRECSPR, y = PRECSPR, z = PRECSPR},
seed = 813,
octaves = 1,
persist = 0,
lacunarity = 2.0,
--flags = ""
}
-- Make sure player is not in a cave/house...
if get_snow(ppos)
and minetest.get_node_light(ppos, 0.5) == 15 then
local animate
if not lighter_snowfall then
local vel = {x=0, y=-1, z=-1}
local acc = {x=0, y=0, z=0}
minetest.add_particlespawner(get_snow_particledef({
amount = 5,
minpos = addvectors(ppos, {x=-9, y=3, z=-9}),
maxpos = addvectors(ppos, {x= 9, y=5, z= 9}),
vel = vel,
acc = acc,
size = 25,
playername = player:get_player_name()
}))
-- These 2 must match biome heat and humidity noise parameters for a world
minetest.add_particlespawner(get_snow_particledef({
amount = 4,
minpos = addvectors(ppos, {x=-5, y=3.2, z=-5}),
maxpos = addvectors(ppos, {x= 5, y=1.6, z= 5}),
vel = vel,
acc = acc,
exptime = 4,
size = 25,
playername = player:get_player_name()
}))
local np_temp = {
offset = 50,
scale = 50,
spread = {x = 1000, y = 1000, z = 1000},
seed = 5349,
octaves = 3,
persist = 0.5,
lacunarity = 2.0,
--flags = ""
}
animate = false
else
animate = true
end
local np_humid = {
offset = 50,
scale = 50,
spread = {x = 1000, y = 1000, z = 1000},
seed = 842,
octaves = 3,
persist = 0.5,
lacunarity = 2.0,
--flags = ""
}
if math.random(1,5) == 4 then
snow_fall(
randpos(
addvectors(ppos, {x=-20, y=0, z=-20}),
addvectors(ppos, {x= 20, y=0, z= 20})
),
player,
animate
)
end
end
end
end
-- Stuff
local difsval = DASVAL - NISVAL
local grad = 14 / 95
local yint = 1496 / 95
-- Globalstep function
local timer = 0
local step_func
minetest.register_globalstep(function()
step_func()
end)
if snow.enable_snowfall then
minetest.register_globalstep(function(dtime)
timer = timer + dtime
if timer < GSCYCLE then
return
end
timer = 0
for _, player in ipairs(minetest.get_connected_players()) do
local player_name = player:get_player_name()
local pos_player = player:get_pos()
local pposy = math.floor(pos_player.y) + 2 -- Precipitation when swimming
if pposy >= YLIMIT - 2 then
local pposx = math.floor(pos_player.x)
local pposz = math.floor(pos_player.z)
local ppos = {x = pposx, y = pposy, z = pposz}
local nobj_temp = minetest.get_perlin(np_temp)
local nobj_humid = minetest.get_perlin(np_humid)
local nobj_prec = minetest.get_perlin(np_prec)
local nval_temp = nobj_temp:get_2d({x = pposx, y = pposz})
local nval_humid = nobj_humid:get_2d({x = pposx, y = pposz})
local nval_prec = nobj_prec:get_2d({x = os.clock() / 60, y = 0})
-- Biome system: Frozen biomes below heat 35,
-- deserts below line 14 * t - 95 * h = -1496
-- h = (14 * t + 1496) / 95
-- h = 14/95 * t + 1496/95
-- where 14/95 is gradient and 1496/95 is y intersection
-- h - 14/95 t = 1496/95 y intersection
-- so area above line is
-- h - 14/95 t > 1496/95
local freeze = nval_temp < 35
local precip = nval_prec < (nval_humid - 50) / 50 + PRECOFF and
nval_humid - grad * nval_temp > yint
if snow.debug then
precip = true
end
-- Check if player is outside
local outside = minetest.get_node_light(ppos, 0.5) == 15
-- Occasionally reset player sky
if math.random() < 0.1 then
if precip then
-- Set overcast sky
local sval
local time = minetest.get_timeofday()
if time >= 0.5 then
time = 1 - time
end
-- Sky brightness transitions:
-- First transition (24000 -) 4500, (1 -) 0.1875
-- Last transition (24000 -) 5750, (1 -) 0.2396
if time <= 0.1875 then
sval = NISVAL
elseif time >= 0.2396 then
sval = DASVAL
else
sval = math.floor(NISVAL +
((time - 0.1875) / 0.0521) * difsval)
end
-- Set sky to overcast bluish-grey
player:set_sky({
base_color = {r = sval, g = sval, b = sval + 16, a = 255},
type = "plain",
})
else
-- Reset sky to normal
player:set_sky({type = "regular"})
end
end
if precip and outside then
-- Precipitation
if freeze then
-- Snowfall
local extime = math.min((pposy + 12 - YLIMIT) / 2, 9)
local x, y, z = pposx - 24 + math.random(0, 48), pposy + 12, pposz - 24 + math.random(0, 48)
if not snow.lighter_snowfall then
snow_fall({
x = x,
y = y,
z = z
}, true)
end
for _ = 1, FLAKES do
x, y, z = pposx - 24 + math.random(0, 48), pposy + 12, pposz - 24 + math.random(0, 48)
minetest.add_particle({
pos = {
x = x,
y = y,
z = z
},
velocity = {
x = (-20 + math.random(0, 40)) / 100,
y = -2.0,
z = (-20 + math.random(0, 40)) / 100
},
acceleration = {x = 0, y = 0, z = 0},
expirationtime = extime,
size = 2.8,
collisiondetection = COLLIDE,
collision_removal = true,
vertical = false,
texture = "snowdrift_snowflake" ..
math.random(1, 12) .. ".png",
playername = player_name
})
end
end
end
end
end
end)
step_func = calc_snowfall
infolog("step function set to calc_snowfall")
else
step_func = function() end
infolog("step function set to empty function")
end
snow.register_on_configuring(function(name, v)
if name == "enable_snowfall" then
if v then
step_func = calc_snowfall
infolog("step function set to calc_snowfall")
else
step_func = function() end
infolog("step function set to empty function")
end
elseif name == "lighter_snowfall" then
lighter_snowfall = v
end
end)

97
src/mapgen.lua Normal file → Executable file
View File

@ -12,26 +12,25 @@ saplings grow into trees. --]]
-- Part 1: To disable the mapgen, add the *starting* comment under this line.
local perlin_scale, nosmooth_rarity
if not snow.disable_mapgen then
print("[snow] Mapgen enabled!")
snow.mapgen = snow.mapgen or {}
local mg = snow.mapgen
snow.mapgen = snow.mapgen or {}
local mg = snow.mapgen
-- perlin noise "hills" are not peaks but looking like sinus curve
local function upper_rarity(rarity)
-- perlin noise "hills" are not peaks but looking like sinus curve
local function upper_rarity(rarity)
return math.sign(rarity)*math.sin(math.abs(rarity)*math.pi/2)
end
end
local rarity = snow.mapgen_rarity
local size = snow.mapgen_size
local smooth = snow.smooth_biomes
local rarity = snow.mapgen_rarity
local size = snow.mapgen_size
local smooth = snow.smooth_biomes
local function calc_values()
local nosmooth_rarity, perlin_scale
local function calc_values()
nosmooth_rarity = 1-rarity/50
perlin_scale = size*100/rarity
mg.perlin_scale = perlin_scale
local smooth_rarity_max, smooth_rarity_min, smooth_rarity_dif
if smooth then
local smooth_trans_size = 4 --snow.smooth_trans_size
mg.smooth_rarity_max = upper_rarity(nosmooth_rarity+smooth_trans_size*2/perlin_scale)
@ -40,10 +39,10 @@ if not snow.disable_mapgen then
end
nosmooth_rarity = upper_rarity(nosmooth_rarity)
mg.nosmooth_rarity = nosmooth_rarity
end
calc_values()
end
calc_values()
snow.register_on_configuring(function(name, v)
snow.register_on_configuring(function(name, v)
if name == "mapgen_rarity" then
rarity = v
elseif name == "mapgen_size" then
@ -55,22 +54,21 @@ if not snow.disable_mapgen then
end
-- TODO: if e.g. size and rarity get changed at once, don't calculate the values more times
calc_values()
end)
end)
--Identify the mapgen.
local mgname = minetest.get_mapgen_setting"mg_name"
if not mgname then
--Identify the mapgen.
local mgname = minetest.get_mapgen_setting"mg_name"
if not mgname then
minetest.log("error", "[MOD] Snow Biomes: WARNING! mapgen could not be identifyed!")
end
local path = minetest.get_modpath"snow"
if mgname == "v7" then
end
local path = minetest.get_modpath"snow"
if mgname == "v7" then
--Load mapgen_v7 compatibility.
dofile(path.."/src/mapgen_v7.lua")
else
else
--Load mapgen_v6 compatibility.
dofile(path.."/src/mapgen_v6.lua")
end
end
-- To complete the commenting-out add the *closing* comment under this line.
@ -109,11 +107,11 @@ local xmas_tree = {
--Makes pine tree
function snow.make_pine(pos,snow,xmas)
local minetest = minetest
local function try_node(p, node)
local n = minetest.get_node(p).name
local try_node = function(pos, node)
local n = minetest.get_node(pos).name
if n == "air"
or n == "ignore" then
minetest.add_node(p, node)
minetest.add_node(pos, node)
end
end
if xmas then
@ -137,7 +135,7 @@ function snow.make_pine(pos,snow,xmas)
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 minetest.get_perlin(112,3, 0.5, perlin_scale):get_2d({x=pos.x,y=pos.z}) > nosmooth_rarity then
and minetest.get_perlin(112,3, 0.5, perlin_scale):get2d({x=pos.x,y=pos.z}) > nosmooth_rarity then
try_node({x=pos.x,y=pos.y+7,z=pos.z},{name="default:snow"})
end
end
@ -149,19 +147,20 @@ 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_pinetree = minetest.get_content_id("default:pinetree")
local c_air = minetest.get_content_id("air")
local perlin1 = minetest.get_perlin(112,3, 0.5, perlin_scale)
for off_z = -1,1 do
local z = pos.z + off_z
for off_x = -1,1 do
local x = pos.x + off_x
for z = -1,1 do
local z = pos.z + z
for x = -1,1 do
local x = pos.x + x
--Make tree.
for i = 1,2 do
data[a:index(x,pos.y+i,z)] = c_pine_needles
if x ~= 0
and z ~= 0
and perlin1:get_2d({x=x,y=z}) > nosmooth_rarity then
and perlin1:get2d({x=x,y=z}) > nosmooth_rarity then
local abovenode = a:index(x,pos.y+i+1,z)
data[abovenode] = c_snow
end
@ -176,16 +175,16 @@ function snow.voxelmanip_pine(pos,a,data)
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 perlin1:get_2d({x=x+1,y=z}) > nosmooth_rarity then
if perlin1:get2d({x=x+1,y=z}) > nosmooth_rarity then
data[a:index(x+1,y+1,z)] = c_snow
end
if perlin1:get_2d({x=x+1,y=z}) > nosmooth_rarity then
if perlin1:get2d({x=x+1,y=z}) > nosmooth_rarity then
data[a:index(x-1,y+1,z)] = c_snow
end
if perlin1:get_2d({x=x,y=z+1}) > nosmooth_rarity then
if perlin1:get2d({x=x,y=z+1}) > nosmooth_rarity then
data[a:index(x,y+1,z+1)] = c_snow
end
if perlin1:get_2d({x=x,y=z-1}) > nosmooth_rarity then
if perlin1:get2d({x=x,y=z-1}) > nosmooth_rarity then
data[a:index(x,y+1,z-1)] = c_snow
end
end
@ -194,29 +193,7 @@ function snow.voxelmanip_pine(pos,a,data)
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 perlin1:get_2d({x=pos.x,y=pos.z}) > nosmooth_rarity then
if perlin1:get2d({x=pos.x,y=pos.z}) > nosmooth_rarity then
data[a:index(pos.x,pos.y+7,pos.z)] = c_snow
end
end
-- treecapitator support
if minetest.global_exists"treecapitator" then
treecapitator.register_tree{
trees = {"default:pine_tree"},
leaves = {"snow:needles"},
range = 1,
range_up = 2,
range_down = 3,
stem_height_min = 1,
}
treecapitator.register_tree{
trees = {"default:pine_tree"},
leaves = {"snow:needles_decorated"},
fruits = {"snow:star_lit", "snow:star"},
range = 1,
range_up = 3,
range_down = 3,
stem_height_min = 1,
}
end

177
src/mapgen_v6.lua Normal file → Executable file
View File

@ -14,11 +14,11 @@ local np_default = {
-- 2D noise for coldness
local mg = snow.mapgen
local scale_coldness = mg.perlin_scale
local scale = mg.perlin_scale
local np_cold = {
offset = 0,
scale = 1,
spread = {x=scale_coldness, y=scale_coldness, z=scale_coldness},
spread = {x=scale, y=scale, z=scale},
seed = 112,
octaves = 3,
persist = 0.5
@ -172,23 +172,6 @@ snow.register_on_configuring(function(name, v)
end
end)
local perlin_objs, perlins_chulen
local function get_perlins(sidelen)
if perlins_chulen == sidelen then
return
end
perlins_chulen = sidelen
local chulens = {x=sidelen, y=sidelen}
perlin_objs = {
default = minetest.get_perlin_map(np_default, chulens),
cold = minetest.get_perlin_map(np_cold, chulens),
ice = minetest.get_perlin_map(np_ice, chulens),
}
end
local nbuf_default = {}
local nbuf_cold = {}
local nbuf_ice = {}
minetest.register_on_generated(function(minp, maxp, seed)
local t1 = os.clock()
@ -211,9 +194,10 @@ minetest.register_on_generated(function(minp, maxp, seed)
local snow_tab,num = {},1
local pines_tab,pnum = {},1
get_perlins(x1 - x0 + 1)
local nvals_default = perlin_objs.default:get_2dMap_flat({x=x0+150, y=z0+50}, nbuf_default)
local nvals_cold, nvals_ice, ndia
local sidelen = x1 - x0 + 1
local chulens = {x=sidelen, y=sidelen, z=sidelen}
local nvals_default = minetest.get_perlin_map(np_default, chulens):get2dMap_flat{x=x0+150, y=z0+50}
local nvals_cold, nvals_ice
-- Choose biomes
local pr = PseudoRandom(seed+57)
@ -231,7 +215,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
local nodes_added
-- Loop through columns in chunk
local is_smooth = smooth and not snowy
local smooth = smooth and not snowy
local write_to_map = false
local ni = 1
for z = z0, z1 do
@ -239,9 +223,11 @@ minetest.register_on_generated(function(minp, maxp, seed)
local in_biome = false
local test
if nvals_default[ni] < 0.35 then
nvals_cold = nvals_cold or perlin_objs.cold:get_2dMap_flat({x=x0, y=z0}, nbuf_cold)
if not nvals_cold then
nvals_cold = minetest.get_perlin_map(np_cold, chulens):get2dMap_flat{x=x0, y=z0}
end
test = math.min(nvals_cold[ni], 1)
if is_smooth then
if smooth then
if test >= smooth_rarity_max
or (
test > smooth_rarity_min
@ -257,44 +243,45 @@ minetest.register_on_generated(function(minp, maxp, seed)
if not in_biome then
if alpine
and test
and test > (is_smooth and smooth_rarity_min or nosmooth_rarity) then
and test > smooth_rarity_min then
-- remove trees near alpine
local ground_y
if data[area:index(x, maxp.y, z)] == c.air then
local ytop = math.min(heightmap[ni]+20, maxp.y)
local vi = area:index(x, ytop, z)
for y = ytop, math.max(minp.y, heightmap[ni]-5), -1 do
if data[vi] ~= c.air then
for y = math.min(heightmap[ni]+20, maxp.y), math.max(minp.y, heightmap[ni]-5), -1 do
if data[area:index(x, y, z)] ~= c.air then
ground_y = y
break
end
vi = vi - area.ystride
end
end
if ground_y then
local vi = area:index(x, ground_y, z)
for _ = minp.y - 16, ground_y do
if data[vi] == c.leaves
or data[vi] == c.jungleleaves then
nodes_added = true
for y = ground_y, -16, -1 do
local vi = area:index(x, y, z)
local id = data[vi]
if id ~= c.air then
if id == c.leaves
or id == c.jungleleaves
or id == c.tree
or id == c.apple then
data[vi] = c.air
nodes_added = true
else
break
end
vi = vi - area.ystride
end
end
end
end
end
else
if not nvals_ice then
nvals_ice = perlin_objs.ice:get_2dMap_flat({x=x0, y=z0}, nbuf_ice)
nodes_added = true
write_to_map = true
if not nvals_ice then
nvals_ice = minetest.get_perlin_map(np_ice, chulens):get2dMap_flat{x=x0, y=z0}
end
local icetype = nvals_ice[ni]
local cool = icetype > 0 -- only spawns ice on edge of water
@ -308,14 +295,11 @@ minetest.register_on_generated(function(minp, maxp, seed)
-- avoid generating underground
if data[area:index(x, maxp.y, z)] == c.air then
-- search for non air node from 20 m above ground down to 5 m below ground (confined by minp and maxp)
local ytop = math.min(heightmap[ni]+20, maxp.y)
local vi = area:index(x, ytop, z)
for y = ytop, math.max(minp.y, heightmap[ni]-5), -1 do
if data[vi] ~= c.air then
for y = math.min(heightmap[ni]+20, maxp.y), math.max(minp.y, heightmap[ni]-5), -1 do
if data[area:index(x, y, z)] ~= c.air then
ground_y = y
break
end
vi = vi - area.ystride
end
end
@ -329,13 +313,12 @@ minetest.register_on_generated(function(minp, maxp, seed)
snow_tab[num] = {ground_y, z, x, test}
num = num+1
-- generate stone ground
local vi = area:index(x, ground_y, z)
for _ = math.max(-6, minp.y-6), ground_y do
for y = ground_y, math.max(-6, minp.y-6), -1 do
local vi = area:index(x, y, z)
if data[vi] == c.stone then
break
end
data[vi] = c.stone
vi = vi - area.ystride
end
elseif pines
and pr:next(1,36) == 1 then
@ -347,8 +330,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
data[area:index(x, ground_y+1, z)] = c.dry_shrub
else
if snowy
or test > (is_smooth and smooth_rarity_max or
nosmooth_rarity) then
or test > smooth_rarity_max then
-- more, deeper snow
data[node] = c.snow_block
else
@ -361,21 +343,26 @@ minetest.register_on_generated(function(minp, maxp, seed)
if not icesheet
and not icecave
and not icehole then
local y = data[node - area.ystride]
local ice = y ~= c.water and y ~= c.ice
if not ice then
ndia = ndia or {
area.zstride - 1,
1,
-2*area.zstride - 2,
area.zstride,
1 - area.zstride,
0
local nds = {
data[area:index(x+1, ground_y, z)],
data[area:index(x, ground_y, z+1)],
data[area:index(x+1, ground_y, z+1)],
data[area:index(x-1, ground_y, z-1)],
data[area:index(x-1, ground_y, z)],
data[area:index(x, ground_y, z-1)],
}
local vi = node + 1
for n = 1,6 do
local i = data[vi]
local ice
if pr:next(1,4) == 1
and (cool or icebergs) then
for _,i in ipairs(nds) do
if i == c.ice then
ice = true
break
end
end
end
if not ice then
for _,i in ipairs(nds) do
if i ~= c.water
and i ~= c.ice
and i ~= c.air
@ -383,24 +370,11 @@ minetest.register_on_generated(function(minp, maxp, seed)
ice = true
break
end
vi = vi + ndia[n]
end
if not ice
and (cool or icebergs)
and pr:next(1,4) == 1 then
local vi_ice = node + 1
for i = 1,6 do
if data[vi_ice] == c.ice then
ice = true
break
end
vi_ice = vi_ice + ndia[i]
end
end
end
local y = data[area:index(x, ground_y-1, z)]
if ice
or (y ~= c.water and y ~= c.ice) -- and y ~= "air") …I don't think y can be a string here ~HybridDog
or (icebergs and pr:next(1,6) == 1) then
data[node] = c.ice
end
@ -411,13 +385,12 @@ minetest.register_on_generated(function(minp, maxp, seed)
data[node] = c.ice
end
if icecave then
local vi = area:index(x, ground_y-1, z)
for _ = math.max(minp.y-16, -33), ground_y-1 do
for y = ground_y-1, -33, -1 do
local vi = area:index(x, y, z)
if data[vi] ~= c.water then
break
end
data[vi] = c.air
vi = vi - area.ystride
end
end
if icesheet then
@ -436,23 +409,24 @@ minetest.register_on_generated(function(minp, maxp, seed)
snow_tab[num] = {ground_y, z, x, test}
num = num+1
-- replace papyrus plants with snowblocks
local vi = area:index(x, ground_y, z)
local y = ground_y
for _ = 1,7 do
if data[vi] ~= c.papyrus then
local vi = area:index(x, y, z)
if data[vi] == c.papyrus then
data[vi] = c.snow_block
y = y-1
else
break
end
data[vi] = c.snow_block
vi = vi - area.ystride
end
elseif alpine then
-- make stone pillars out of trees and other stuff
local vi = area:index(x, ground_y, z)
for _ = 0, ground_y - math.max(-6, minp.y-6) do
if data[vi] == c.stone then
for y = ground_y, math.max(-6, minp.y-6), -1 do
local stone = area:index(x, y, z)
if data[stone] == c.stone then
break
end
data[vi] = c.stone
vi = vi - area.ystride
data[stone] = c.stone
end
-- put snow onto it
snow_tab[num] = {ground_y, z, x, test}
@ -463,8 +437,9 @@ minetest.register_on_generated(function(minp, maxp, seed)
snow_tab[num] = {ground_y, z, x, test}
num = num+1
end
local vi = area:index(x, ground_y, z)
for _ = 0, 12 do
for y = 0, 12 do
y = ground_y-y
local vi = area:index(x, y, z)
local nd = data[vi]
local plantlike = is_plantlike(nd)
if replacements[nd] then
@ -476,7 +451,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
data[vi] = c.dirt_with_snow
break
elseif plantlike then
local under = vi - area.ystride
local under = area:index(x, y-1, z)
if data[under] == c.dirt_with_grass then
-- replace other plants with shrubs
data[vi] = c.snow_shrub
@ -487,7 +462,6 @@ minetest.register_on_generated(function(minp, maxp, seed)
elseif nd == c.stone then
break
end
vi = vi - area.ystride
end
end
end
@ -501,14 +475,15 @@ minetest.register_on_generated(function(minp, maxp, seed)
return
end
-- try to fix oom memory crashes
minetest.after(0, collectgarbage)
if num ~= 1 then
for i = 1, num-1 do
i = snow_tab[i]
for _,i in pairs(snow_tab) do
-- set snow
data[area:index(i[3], i[1]+1, i[2])] = c.snow
end
for k = 1, num-1 do
local i = snow_tab[k]
for _,i in pairs(snow_tab) do
local y,z,x,test = unpack(i)
test = (test-nosmooth_rarity)/(1-nosmooth_rarity) -- /(1-0.53)
if test > 0 then
@ -518,8 +493,8 @@ minetest.register_on_generated(function(minp, maxp, seed)
if h ~= 1 then
-- search for nearby snow
y = y+1
for off = -1,1,2 do
for _,cord in pairs({{x+off,z}, {x,z+off}}) do
for i = -1,1,2 do
for _,cord in pairs({{x+i,z}, {x,z+i}}) do
local nd = data[area:index(cord[1], y, cord[2])]
if nd == c.air
or is_plantlike(nd) then
@ -553,8 +528,8 @@ minetest.register_on_generated(function(minp, maxp, seed)
if pines
and pnum ~= 1 then
local spawn_pine = snow.voxelmanip_pine
for i = 1, pnum-1 do
spawn_pine(pines_tab[i], area, data)
for _,pos in pairs(pines_tab) do
spawn_pine(pos, area, data)
end
end
@ -579,7 +554,7 @@ local biome_strings = {
{"snowy", "plain", "alpine", "normal", "normal"},
{"cool", "icebergs", "icesheet", "icecave", "icehole"}
}
function biome_to_string(num)
function biome_to_string(num,num2)
local biome = biome_strings[1][num] or "unknown "..num
return biome
end

0
src/mapgen_v7.lua Normal file → Executable file
View File

257
src/nodes.lua Normal file → Executable file
View File

@ -8,16 +8,11 @@ local nodedef = {
tiles = {"snow_needles.png"},
waving = 1,
paramtype = "light",
groups = {snappy=3},
groups = {snappy=3, leafdecay=5},
furnace_burntime = 1,
drop = {
max_items = 1,
items = {
{
-- player will get sapling with 1/20 chance
items = {'snow:sapling_pine'},
rarity = 20,
},
{
items = {'snow:needles'},
}
@ -32,23 +27,17 @@ If christmas_content is enabled, then this next part will override the pine need
The Xmas tree needles are registred and defined a farther down in this nodes.lua file.
~ LazyJ
]]
if snow.christmas_content then
table.insert(nodedef.drop.items, 1, {
-- player will get xmas tree with 1/120 chance
items = {"snow:xmas_tree"},
items = {'snow:xmas_tree'},
rarity = 120,
})
end
]]
minetest.register_node("snow:needles", table.copy(nodedef))
default.register_leafdecay{
trunks = {"default:pine_tree"},
leaves = {"snow:needles"},
radius = 2,
}
snow.register_on_configuring(function(name, v)
if name == "christmas_content" then
local drop = minetest.registered_nodes["snow:needles"].drop
@ -66,10 +55,10 @@ end)
-- Christmas egg
if minetest.global_exists("skins") then
skins.add("character_snow_man")
end
-- Christmas egg
if minetest.global_exists"skins" then
skins.add"character_snow_man"
end
-- Decorated Pine Leaves
@ -82,18 +71,16 @@ if snow.disable_deco_needle_ani then
else
-- Animated, "blinking lights" version. ~ LazyJ
nodedef.inventory_image = minetest.inventorycube("snow_needles_decorated.png")
nodedef.tiles = {{
name="snow_needles_decorated_animated.png",
animation={type="vertical_frames", aspect_w=16, aspect_h=16,
length=20.0}
}}
nodedef.tiles = {
{name="snow_needles_decorated_animated.png", animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=20.0}}
}
end
nodedef.drop.items[#nodedef.drop.items] = {items = {'snow:needles_decorated'}}
minetest.register_node("snow:needles_decorated", nodedef)
-- Saplings
--[[ Saplings
nodedef = {
description = "Pine Sapling",
@ -119,7 +106,7 @@ nodedef.inventory_image = "snow_xmas_tree.png"
nodedef.wield_image = "snow_xmas_tree.png"
minetest.register_node("snow:xmas_tree", nodedef)
]]
nodedef = {
description = "Star",
@ -131,15 +118,12 @@ nodedef = {
walkable = false,
-- Don't want the ornament breaking too easily because you have to punch it to turn it on and off. ~ LazyJ
groups = {cracky=1, crumbly=1, choppy=1, oddly_breakable_by_hand=1},
-- Breaking "glass" sound makes it sound like a real, broken, Xmas tree
-- ornament (Sorry, Mom!). ;)- ~ LazyJ
sounds = default.node_sound_glass_defaults(
{dig = {name="default_glass_footstep", gain=0.2}}),
-- Added a "lit" star that can be punched on or off depending on your
-- preference. ~ LazyJ
on_punch = function(pos, node)
-- Breaking "glass" sound makes it sound like a real, broken, Xmas tree ornament (Sorry, Mom!). ;)- ~ LazyJ
sounds = default.node_sound_glass_defaults({dig = {name="default_glass_footstep", gain=0.2}}),
on_punch = function(pos, node) -- Added a "lit" star that can be punched on or off depending on your preference. ~ LazyJ
node.name = "snow:star_lit"
minetest.set_node(pos, node)
nodeupdate(pos)
end,
}
@ -148,13 +132,14 @@ minetest.register_node("snow:star", table.copy(nodedef))
-- Star (Lit Version) on Xmas Trees
nodedef.description = nodedef.description.." Lighted"
nodedef.light_source = minetest.LIGHT_MAX
nodedef.light_source = default.LIGHT_MAX
nodedef.tiles = {"snow_star_lit.png"}
nodedef.drop = "snow:star"
nodedef.groups.not_in_creative_inventory = 1
nodedef.on_punch = function(pos, node)
node.name = "snow:star"
minetest.set_node(pos, node)
nodeupdate(pos)
end
minetest.register_node("snow:star_lit", nodedef)
@ -272,15 +257,6 @@ nodedef.groups.flammable = 1
minetest.register_node("snow:apple", nodedef)
snow.known_plants[minetest.get_content_id("default:apple")] = minetest.get_content_id("snow:apple")
if not snow.disable_mapgen then
-- decay from default/nodes.lua:2537
default.register_leafdecay{
trunks = {"default:tree"},
leaves = {"snow:apple", "snow:leaves"},
radius = minetest.get_mapgen_setting"mg_name" == "v6" and 2 or 3,
}
end
-- TODO
snow.known_plants[minetest.get_content_id("default:jungleleaves")] = minetest.get_content_id("default:jungleleaves")
@ -291,7 +267,8 @@ local function snow_onto_dirt(pos)
local node = minetest.get_node(pos)
if node.name == "default:dirt_with_grass"
or node.name == "default:dirt" then
minetest.set_node(pos, {name = "default:dirt_with_snow"})
node.name = "default:dirt_with_snow"
minetest.set_node(pos, node)
end
end
@ -311,27 +288,33 @@ nodedef = {
-- 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, cools_lava = 1, snowy = 1},
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_snow_defaults(),
-- 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
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 = snow_onto_dirt
}
-- Snow Brick
minetest.register_node("snow:snow_brick", table.copy(nodedef))
-- hard Ice Brick, original texture from LazyJ
local ibdef = table.copy(nodedef)
ibdef.description = "Ice Brick"
ibdef.tiles = {"snow_ice_brick.png"}
ibdef.use_texture_alpha = "blend"
ibdef.use_texture_alpha = true
ibdef.drawtype = "glasslike"
ibdef.groups = {cracky=1, crumbly=1, choppy=1, melts=1, cools_lava = 1, slippery = 3}
ibdef.sounds = default.node_sound_ice_defaults()
ibdef.groups = {cracky=1, crumbly=1, choppy=1, melts=1}
ibdef.sounds = default.node_sound_glass_defaults({
dug = {name="default_hard_footstep", gain=1}
})
minetest.register_node("snow:ice_brick", ibdef)
@ -343,159 +326,43 @@ nodedef.tiles = {"snow_snow_cobble.png"}
minetest.register_node("snow:snow_cobble", nodedef)
-- Override Default Nodes to Add Extra Functions
local groups = minetest.registered_nodes["default:ice"].groups
groups["melt"] = 1
-- 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
param2 = 0,
--param2 is reserved for how much ice will freezeover.
sunlight_propagates = true, -- 2
drawtype = "glasslike",
use_texture_alpha = "blend",
param2 = 0, --param2 is reserved for how much ice will freezeover.
sunlight_propagates = true, -- necessary for dirt_with_grass/snow/just dirt ABMs
tiles = {"snow_ice.png^[brighten"},
inventory_image = minetest.inventorycube("default_ice.png").."^[brighten",
liquidtype = "none",
groups = groups,
-- 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=2, crumbly=1, choppy=1, --[[oddly_breakable_by_hand=1,]] melts=1},
on_construct = snow_onto_dirt,
liquids_pointable = true,
--Make ice freeze over when placed by a maximum of 10 blocks.
after_place_node = function(pos)
minetest.set_node(pos, {name="default:ice", param2=math.random(0,10)})
end,
end
})
groups = minetest.registered_nodes["default:snowblock"].groups
for g,v in pairs({melts=1, icemaker=1, cooks_into_ice=1, falling_node=1}) do
groups[g] = v
end
-- This adds code to the existing, default snowblock. ~ LazyJ
minetest.override_item("default:snowblock", {
liquidtype = "none",
paramtype = "light",
sunlight_propagates = true,
on_construct = snow_onto_dirt,
groups = groups,
})
minetest.override_item("default:snow", {
drop = {
max_items = 2,
items = {
{items = {'snow:moss'}, rarity = 20,},
{items = {'default:snow'},}
}
},
leveled = 7,
paramtype2 = "leveled",
node_box = {
type = "leveled",
fixed = {-0.5, -0.5, -0.5, 0.5, -0.5, 0.5},
},
collision_box = {
type = "leveled",
fixed = {-0.5, -0.5, -0.5, 0.5, -0.5, 0.5},
},
selection_box = {
type = "leveled",
fixed = {-0.5, -0.5, -0.5, 0.5, -0.5, 0.5},
},
groups = {cracky=3, crumbly=3, choppy=3, oddly_breakable_by_hand=3,
falling_node=1, melts=2, float=1},
sunlight_propagates = true,
walkable = true,
node_placement_prediction = "",
on_construct = function(pos)
pos.y = pos.y-1
local node = minetest.get_node(pos)
if node.name == "default:dirt_with_grass"
or node.name == "default:dirt" then
node.name = "default:dirt_with_snow"
minetest.set_node(pos, node)
end
end,
--Handle node drops due to node level.
on_dig = function(pos, node, digger)
local level = minetest.get_node_level(pos)
minetest.node_dig(pos, node, digger)
if minetest.get_node(pos).name ~= node.name then
local inv = digger:get_inventory()
if not inv then
return
end
local left = inv:add_item("main", "default:snow "..tostring(level/7-1))
if not left:is_empty() then
minetest.add_item({
x = pos.x + math.random()/2-0.25,
y = pos.y + math.random()/2-0.25,
z = pos.z + math.random()/2-0.25,
}, left)
end
end
end,
--Manage snow levels.
on_place = function(itemstack, player, pt)
local oldnode_under = minetest.get_node_or_nil(pt.under)
if not oldnode_under then
return itemstack, false
end
local olddef_under = minetest.registered_nodes[oldnode_under.name]
if not olddef_under then
return itemstack, false
end
-- If node under is buildable_to, place into it instead (eg. snow)
local pos, node
if olddef_under.buildable_to then
pos = pt.under
node = oldnode_under
else
pos = pt.above
node = minetest.get_node(pos)
local def = minetest.registered_nodes[node.name]
if not def
or not def.buildable_to then
return itemstack, false
end
end
-- nil player can place (for snowballs)
if player
and minetest.is_protected(pos, player:get_player_name()) then
return itemstack, false
end
if node.name ~= "default:snow" then
if minetest.get_node{x=pos.x, y=pos.y-1, z=pos.z}.name ==
"default:snow" then
-- grow the snow below (fixes levelled problem)
pos.y = pos.y - 1
else
-- place a snow
return minetest.item_place_node(itemstack, player, pt)
end
end
-- grow the snow
local level = minetest.get_node_level(pos)
level = level + 7
if level < 64 then
minetest.set_node_level(pos, level)
else
-- place a snowblock and snow onto it if possible
local p = {x=pos.x, y=pos.y+1, z=pos.z}
local def = minetest.registered_nodes[minetest.get_node(p).name]
if not def
or not def.buildable_to then
return itemstack, false
end
minetest.set_node(pos, {name="default:snowblock"})
minetest.set_node(p, {name="default:snow"})
level = math.max(level - 64, 7)
minetest.set_node_level(p, level)
end
itemstack:take_item()
return itemstack, true
end,
on_use = snow.shoot_snowball
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, falling_node=1},
--drop = "snow:snow_cobble",
on_construct = snow_onto_dirt
-- 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
})

16
src/sled.lua Normal file → Executable file
View File

@ -53,6 +53,8 @@ than I originally planned. :p ~ LazyJ
-- Helper functions
--
vector.zero = vector.zero or {x=0, y=0, z=0}
local function table_find(t, v)
for i = 1,#t do
if t[i] == v then
@ -81,7 +83,7 @@ local sled = {
local players_sled = {}
local function join_sled(self, player)
local pos = self.object:get_pos()
local pos = self.object:getpos()
player:setpos(pos)
local name = player:get_player_name()
players_sled[name] = true
@ -89,7 +91,7 @@ local function join_sled(self, player)
default.player_set_animation(player, "sit" , 30)
self.driver = name
self.object:set_attach(player, "", {x=0,y=-9,z=0}, {x=0,y=90,z=0})
self.object:set_yaw(player:get_look_yaw())-- - math.pi/2)
self.object:setyaw(player:get_look_yaw())-- - math.pi/2)
end
local function leave_sled(self, player)
@ -127,7 +129,7 @@ local function sled_rightclick(self, player)
position = {x=0.5, y=0.89},
name = "sled",
scale = {x=2, y=2},
text = "You are on the sled! Hold the sneak key to get off the sled.", -- LazyJ
text = "You are on the sled! Press the sneak key to get off the sled.", -- LazyJ
direction = 0,
})
-- End part 1
@ -154,9 +156,9 @@ function sled:on_rightclick(player)
on_sled_click(self, player)
end
function sled:on_activate(staticdata)
function sled:on_activate(staticdata, dtime_s)
self.object:set_armor_groups({immortal=1})
self.object:set_acceleration({x=0, y=-10, z=0})
self.object:setacceleration({x=0, y=-10, z=0})
if staticdata then
self.v = tonumber(staticdata)
end
@ -200,7 +202,7 @@ function sled:on_step(dtime)
return
end
if player:get_player_control().sneak
or not accelerating_possible(vector.round(self.object:get_pos())) then
or not accelerating_possible(vector.round(self.object:getpos())) then
leave_sled(self, player)
end
end
@ -220,7 +222,7 @@ minetest.register_craftitem("snow:sled", {
if players_sled[placer:get_player_name()] then
return
end
local pos = placer:get_pos()
local pos = placer:getpos()
if accelerating_possible(vector.round(pos)) then
pos.y = pos.y+0.5

195
src/snowball.lua Normal file → Executable file
View File

@ -6,13 +6,13 @@
-- 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 creative_mode = minetest.settings:get_bool"creative_mode"
local creative_mode = minetest.setting_getbool("creative_mode")
local snowball_velocity, entity_attack_delay
local function update_snowball_vel(v)
snowball_velocity = v
local walkspeed = tonumber(minetest.settings:get"movement_speed_walk") or 4
local walkspeed = tonumber(minetest.setting_get("movement_speed_walk")) or 4
entity_attack_delay = (walkspeed+1)/v
end
update_snowball_vel(snow.snowball_velocity)
@ -27,23 +27,23 @@ snow.register_on_configuring(function(name, v)
end)
local function get_gravity()
local grav = tonumber(minetest.settings:get"movement_gravity") or 9.81
local grav = tonumber(minetest.setting_get("movement_gravity")) or 9.81
return grav*snowball_gravity
end
local someone_throwing, just_acitvated
--Shoot snowball
function snow.shoot_snowball(item, player)
local function snow_shoot_snowball(item, player)
local addp = {y = 1.625} -- + (math.random()-0.5)/5}
local dir = player:get_look_dir()
local dif = 2*math.sqrt(dir.z*dir.z+dir.x*dir.x)
addp.x = dir.z/dif -- + (math.random()-0.5)/5
addp.z = -dir.x/dif -- + (math.random()-0.5)/5
local pos = vector.add(player:get_pos(), addp)
local pos = vector.add(player:getpos(), addp)
local obj = minetest.add_entity(pos, "snow:snowball_entity")
obj:set_velocity(vector.multiply(dir, snowball_velocity))
obj:set_acceleration({x=dir.x*-3, y=-get_gravity(), z=dir.z*-3})
obj:setvelocity(vector.multiply(dir, snowball_velocity))
obj:setacceleration({x=dir.x*-3, y=-get_gravity(), z=dir.z*-3})
obj:get_luaentity().thrower = player:get_player_name()
if creative_mode then
if not someone_throwing then
@ -64,7 +64,7 @@ if creative_mode then
local item = player:get_wielded_item()
local itemname = item:get_name()
if itemname == "default:snow" then
snow.shoot_snowball(nil, player)
snow_shoot_snowball(nil, player)
active = true
break
end
@ -103,25 +103,25 @@ local snow_snowball_ENTITY = {
function snow_snowball_ENTITY.on_activate(self)
self.object:set_properties({textures = {"default_snowball.png^[transform"..math.random(0,7)}})
self.object:set_acceleration({x=0, y=-get_gravity(), z=0})
self.lastpos = self.object:get_pos()
self.object:setacceleration({x=0, y=-get_gravity(), z=0})
self.lastpos = self.object:getpos()
minetest.after(0.1, function(obj)
if not obj then
return
end
local vel = obj:get_velocity()
local vel = obj:getvelocity()
if vel
and vel.y ~= 0 then
return
end
minetest.after(0, function(object)
if not object then
minetest.after(0, function(obj)
if not obj then
return
end
local vel_obj = object:get_velocity()
if not vel_obj
or vel_obj.y == 0 then
object:remove()
local vel = obj:getvelocity()
if not vel
or vel.y == 0 then
obj:remove()
end
end, obj)
end, self.object)
@ -129,40 +129,22 @@ end
--Snowball_entity.on_step()--> called when snowball is moving.
function snow_snowball_ENTITY.on_step(self, dtime)
self.timer = self.timer + dtime
if self.timer > 10 then
-- 10 seconds is too long for a snowball to fly somewhere
self.timer = self.timer+dtime
if self.timer > 600 then
-- 10 minutes are too long for a snowball to fly somewhere
self.object:remove()
return
end
if self.physical then
local vel = self.object:get_velocity()
local fell = vel.y == 0
local fell = self.object:getvelocity().y == 0
if not fell then
if self.probably_stuck then
self.probably_stuck = nil
end
return
end
if self.probably_stuck
and vel.x == 0
and vel.z == 0 then
-- add a small velocity to move it from the corner
vel.x = math.random() - 0.5
vel.z = math.random() - 0.5
self.object:set_velocity(vel)
self.probably_stuck = nil
return
end
local pos = vector.round(self.object:get_pos())
local pos = vector.round(self.object:getpos())
if minetest.get_node(pos).name == "air" then
pos.y = pos.y-1
if minetest.get_node(pos).name == "air" then
if vel.x == 0
and vel.z == 0 then
self.probably_stuck = true
end
return
end
end
@ -171,16 +153,16 @@ function snow_snowball_ENTITY.on_step(self, dtime)
return
end
local pos = vector.round(self.object:get_pos())
local pos = vector.round(self.object:getpos())
if vector.equals(pos, self.lastpos) then
return
end
if minetest.get_node(pos).name ~= "air" then
self.object:set_acceleration({x=0, y=-get_gravity(), z=0})
--self.object:set_velocity({x=0, y=0, z=0})
self.object:setacceleration({x=0, y=-get_gravity(), z=0})
--self.object:setvelocity({x=0, y=0, z=0})
pos = self.lastpos
self.object:setpos(pos)
minetest.sound_play("default_snow_footstep", {pos=pos, gain=vector.length(self.object:get_velocity())/30})
minetest.sound_play("default_snow_footstep", {pos=pos, gain=vector.length(self.object:getvelocity())/30})
self.object:set_properties({physical = true})
self.physical = true
return
@ -191,16 +173,13 @@ function snow_snowball_ENTITY.on_step(self, dtime)
return
end
for _,v in pairs(minetest.get_objects_inside_radius(pos, 1.73)) do
local entity = v:get_luaentity()
if v ~= self.object
and entity then
local entity_name = entity.name
if v:is_player()
or (entity_name ~= "snow:snowball_entity"
if v ~= self.object then
local entity_name = v:get_entity_name()
if entity_name ~= "snow:snowball_entity"
and entity_name ~= "__builtin:item"
and entity_name ~= "gauges:hp_bar") then
local vvel = v:get_velocity() or v:get_player_velocity()
local veldif = self.object:get_velocity()
and entity_name ~= "gauges:hp_bar" then
local vvel = v:getvelocity() or v:get_player_velocity()
local veldif = self.object:getvelocity()
if vvel then
veldif = vector.subtract(veldif, vvel)
end
@ -212,15 +191,7 @@ function snow_snowball_ENTITY.on_step(self, dtime)
{full_punch_interval=1, damage_groups = {fleshy=math.ceil(gain)}}
)
minetest.sound_play("default_snow_footstep", {pos=pos, gain=gain})
-- spawn_falling_node
local obj = minetest.add_entity(pos, "__builtin:falling_node")
if obj then
obj:get_luaentity():set_node{name = "default:snow"}
else
minetest.log("error", "Couldn't spawn falling node")
end
spawn_falling_node(pos, {name = "default:snow"})
self.object:remove()
return
end
@ -265,16 +236,11 @@ minetest.register_node(":default:snow", {
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
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
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
@ -285,6 +251,97 @@ minetest.register_node(":default:snow", {
minetest.override_item("default:snow", {
drop = {
max_items = 2,
items = {
{items = {'snow:moss'}, rarity = 20,},
{items = {'default:snow'},}
}
},
leveled = 7,
node_box = {
type = "leveled",
fixed = {
{-0.5, -0.5, -0.5, 0.5, -0.5, 0.5},
},
},
groups = {cracky=3, crumbly=3, choppy=3, oddly_breakable_by_hand=3, falling_node=1, melts=2, float=1},
sunlight_propagates = true,
--Disable placement prediction for snow.
node_placement_prediction = "",
on_construct = function(pos)
pos.y = pos.y-1
local node = minetest.get_node(pos)
if node.name == "default:dirt_with_grass"
or node.name == "default:dirt" then
node.name = "default:dirt_with_snow"
minetest.set_node(pos, node)
end
end,
--Handle node drops due to node level.
on_dig = function(pos, node, digger)
local level = minetest.get_node_level(pos)
minetest.node_dig(pos, node, digger)
if minetest.get_node(pos).name ~= node.name then
local inv = digger:get_inventory()
if not inv then
return
end
local left = inv:add_item("main", "default:snow "..tostring(level/7-1))
if not left:is_empty() then
minetest.add_item({
x = pos.x + math.random()/2-0.25,
y = pos.y + math.random()/2-0.25,
z = pos.z + math.random()/2-0.25,
}, left)
end
end
end,
--Manage snow levels.
on_place = function(itemstack, placer, pointed_thing)
local under = pointed_thing.under
local oldnode_under = minetest.get_node_or_nil(under)
local above = pointed_thing.above
if not oldnode_under
or not above then
return
end
local olddef_under = ItemStack({name=oldnode_under.name}):get_definition()
olddef_under = olddef_under or minetest.nodedef_default
local place_to
-- If node under is buildable_to, place into it instead (eg. snow)
if olddef_under.buildable_to then
place_to = under
else
-- Place above pointed node
place_to = above
end
local level = minetest.get_node_level(place_to)
if level == 63 then
minetest.set_node(place_to, {name="default:snowblock"})
else
minetest.set_node_level(place_to, level+7)
end
if minetest.get_node(place_to).name ~= "default:snow" then
local itemstack, placed = minetest.item_place_node(itemstack, placer, pointed_thing)
return itemstack, placed
end
itemstack:take_item()
return itemstack
end,
on_use = snow_shoot_snowball
})
--[[
A note about default torches, melting, and "buildable_to = true" in default snow.

View File

@ -1,101 +0,0 @@
local snow_nodes = {
snow = { "ice_brick", "snow_brick", "snow_cobble" },
default = { "ice", "snowblock" }
}
if minetest.get_modpath("moreblocks") and
minetest.global_exists("stairsplus") then
-- For users converting from MTG stairs to stairsplus, these nodes are aliased
-- from the stairs namespace to their source mod.
local was_in_stairs = {
ice_brick = true,
snow_brick = true,
snow_cobble = true,
ice = false, -- moreblocks will take care of this one, and
snowblock = false, -- this one, because they are in the default namespace.
}
-- Some nodes were incorrectly placed into the snow namespace. Alias these to
-- their proper namespace (default).
local was_in_snow = {
ice_brick = false,
snow_brick = false,
snow_cobble = false,
ice = true,
snowblock = true,
}
-- Some nodes were incorrectly placed into the moreblocks namespace. Alias
-- these to their proper namespace (either snow or default).
local was_in_moreblocks = {
ice_brick = false,
snow_brick = true,
snow_cobble = true,
ice = true,
snowblock = true,
}
for mod, nodes in pairs(snow_nodes) do
for _, name in pairs(nodes) do
local nodename = mod .. ":" .. name
local ndef = table.copy(minetest.registered_nodes[nodename])
ndef.sunlight_propagates = true
ndef.groups.melts = 2
ndef.groups.icemaker = nil
ndef.groups.cooks_into_ice = nil
ndef.after_place_node = nil
if string.find(name, "ice") then
ndef.use_texture_alpha = "blend"
else
ndef.use_texture_alpha = "opaque"
end
stairsplus:register_all(mod, name, nodename, ndef)
if was_in_stairs[name] then
minetest.register_alias("stairs:stair_" .. name, mod .. ":stair_" .. name)
minetest.register_alias("stairs:slab_" .. name, mod .. ":slab_" .. name)
end
if was_in_snow[name] then
minetest.register_alias("snow:stair_" .. name, mod .. ":stair_" .. name)
minetest.register_alias("snow:slab_" .. name, mod .. ":slab_" .. name)
end
if was_in_moreblocks[name] then
stairsplus:register_alias_all("moreblocks", name, mod, name)
end
end
end
elseif minetest.global_exists("stairs") then -- simple stairs and slabs only
for mod, nodes in pairs(snow_nodes) do
for _, name in pairs(nodes) do
local nodename = mod .. ":" .. name
local ndef = table.copy(minetest.registered_nodes[nodename])
local desc_stair = ndef.description .. " Stair"
local desc_slab = ndef.description .. " Slab"
local images = ndef.tiles
local sounds = ndef.sounds
local groups = ndef.groups
groups.melts = 2
groups.icemaker = nil
groups.cooks_into_ice = nil
stairs.register_stair_and_slab(name, nodename,
groups, images, desc_stair, desc_slab, sounds)
-- Add transparency if used (e.g. ice and ice_brick).
minetest.override_item("stairs:stair_" .. name,
{use_texture_alpha = ndef.use_texture_alpha})
minetest.override_item("stairs:slab_" .. name,
{use_texture_alpha = ndef.use_texture_alpha})
-- Alias all stairs and slabs from snow to the stairs namespace.
minetest.register_alias("snow:stair_" .. name, "stairs:stair_" .. name)
minetest.register_alias("snow:slab_" .. name, "stairs:slab_" .. name)
end
end
end

342
src/stairsplus.lua Executable file
View File

@ -0,0 +1,342 @@
-- ===============================================================================
-- 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"))
and rawget(_G, "stairsplus")
-- 'If' MoreBlocks was found and stairsplus is available, 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 = ndef.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

205
src/util.lua Normal file → Executable file
View File

@ -1,25 +1,38 @@
--Global config and function table.
snow = {
snowball_gravity = tonumber(minetest.settings:get("snow_snowball_gravity")) or 0.91,
snowball_velocity = tonumber(minetest.settings:get("snow_snowball_velocity")) or 19,
sleds = minetest.settings:get_bool("snow_sleds", true),
enable_snowfall = minetest.settings:get_bool("snow_enable_snowfall", true),
lighter_snowfall = minetest.settings:get_bool("snow_lighter_snowfall", false),
debug = minetest.settings:get_bool("snow_debug", false),
smooth_biomes = minetest.settings:get_bool("snow_smooth_biomes", true),
christmas_content = minetest.settings:get_bool("snow_christmas_content", true),
smooth_snow = minetest.settings:get_bool("snow_smooth_snow", true),
min_height = tonumber(minetest.settings:get("snow_min_height")) or 3,
mapgen_rarity = tonumber(minetest.settings:get("snow_mapgen_rarity")) or 18,
mapgen_size = tonumber(minetest.settings:get("snow_mapgen_size")) or 210,
disable_mapgen = minetest.settings:get_bool("snow_disable_mapgen", true),
snowball_gravity = 100/109,
snowball_velocity = 19,
sleds = true,
enable_snowfall = true,
lighter_snowfall = false,
debug = false,
smooth_biomes = true,
christmas_content = true,
smooth_snow = true,
min_height = 3,
mapgen_rarity = 18,
mapgen_size = 210,
}
--Config documentation.
local doc = {
snowball_gravity = "The gravity of thrown snowballs",
snowball_velocity = "How fast players throw snowballs",
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. Currently it only prints mgv6 info.",
smooth_biomes = "Enables smooth transition of biomes (mgv6)",
smooth_snow = "Disable this to stop snow from being smoothed.",
christmas_content = "Disable this to remove christmas saplings from being found.",
min_height = "The minumum height a snow biome will generate (mgv7)",
mapgen_rarity = "mapgen rarity in %",
mapgen_size = "size of the generated… (has an effect to the rarity, too)",
}
-- functions for dynamically changing settings
snow.register_on_configuring = function() end
--[[
local on_configurings,n = {},1
function snow.register_on_configuring(func)
on_configurings[n] = func
@ -52,4 +65,164 @@ local function value_from_string(v)
end
return v
end
--]]
local allowed_types = {string = true, number = true, boolean = true}
--Saves contents of config to file.
local function saveConfig(path, config, doc)
local file = io.open(path,"w")
if not file then
minetest.log("error", "[snow] could not open config file for writing at "..path)
return
end
for i,v in pairs(config) do
if allowed_types[type(v)] then
if doc and doc[i] then
file:write("# "..doc[i].."\n")
end
file:write(i.." = "..tostring(v).."\n")
end
end
file:close()
end
local modpath = minetest.get_modpath("snow")
minetest.register_on_shutdown(function()
saveConfig(modpath.."/config.txt", snow, doc)
end)
-- load settings from config.txt
local config
do
local path = modpath.."/config.txt"
local file = io.open(path,"r")
if not file then
--Create config file.
return
end
io.close(file)
config = {}
for line in io.lines(path) do
if line:sub(1,1) ~= "#" then
local i, v = line:match("^(%S*) = (%S*)")
if i and v then
config[i] = value_from_string(v)
end
end
end
end
if config then
for i,v in pairs(config) do
if type(snow[i]) == type(v) then
snow[i] = v
else
minetest.log("error", "[snow] wrong type of setting "..i)
end
end
else
saveConfig(modpath.."/config.txt", snow, doc)
end
-- load settings from minetest.conf
for i,v in pairs(snow) do
if allowed_types[type(v)] then
local v = minetest.setting_get("snow_"..i)
if v ~= nil then
snow[i] = value_from_string(v)
end
end
end
--MENU
local function form_sort_func(a,b)
return a[1] < b[1]
end
--[[
local function form_sort_func_bool(a,b)
if a[2] == b[2] then
return a[1] < b[1]
else
return b[2]
end
end--]]
local function get_formspec()
local ids,n1,n2 = {{},{}},1,1
for i,v in pairs(snow) do
local t = type(v)
if t == "string"
or t == "number" then
ids[2][n2] = {i,v}
n2 = n2+1
elseif t == "boolean" then
ids[1][n1] = {i,v}
n1 = n1+1
end
end
table.sort(ids[2], form_sort_func)
table.sort(ids[1], form_sort_func)
local p = -0.5
local formspec = "label[0,-0.3;Settings:]"
for n = 1,n1-1 do
local i,v = unpack(ids[1][n])
p = p + 0.5
formspec = formspec.."checkbox[0,"..p..";snow:"..i..";"..i..";"..tostring(v).."]"
end
for n = 1,n2-1 do
local i,v = unpack(ids[2][n])
p = p + 1.5
formspec = formspec.."field[0.3,"..p..";2,1;snow:"..i..";"..i..";"..v.."]"
end
p = p + 1
formspec = "size[4,"..p..";]\n"..formspec
return formspec
end
minetest.register_chatcommand("snow", {
description = "Show a menu for various actions",
privs = {server=true},
func = function(name)
minetest.chat_send_player(name, "Showing snow menu…")
minetest.show_formspec(name, "snow:menu", get_formspec())
end,
})
minetest.register_on_player_receive_fields(function(player, formname, fields)
if formname ~= "snow:menu" then
return
end
for i,v in pairs(snow) do
local t = type(v)
if allowed_types[t] then
local field = fields["snow:"..i]
if field then
if t == "number" then
field = tonumber(field)
elseif t == "boolean" then
if field == "true" then
field = true
elseif field == "false" then
field = false
else
field = nil
end
elseif t ~= "string" then
field = nil
end
if field ~= nil then
change_setting(i, field)
end
end
end
end
end)

0
textures/character_snow_man.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

0
textures/character_snow_man_preview.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 3.7 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

0
textures/character_snow_man_preview_back.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 211 B

0
textures/snow_apple.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 249 B

After

Width:  |  Height:  |  Size: 249 B

0
textures/snow_dandelion_white.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 122 B

After

Width:  |  Height:  |  Size: 122 B

0
textures/snow_dandelion_yellow.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 118 B

After

Width:  |  Height:  |  Size: 118 B

0
textures/snow_geranium.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 269 B

After

Width:  |  Height:  |  Size: 269 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 643 B

0
textures/snow_ice_brick.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 665 B

After

Width:  |  Height:  |  Size: 665 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 606 B

0
textures/snow_leaves.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 190 B

After

Width:  |  Height:  |  Size: 190 B

0
textures/snow_moss.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 619 B

After

Width:  |  Height:  |  Size: 619 B

0
textures/snow_needles.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 660 B

After

Width:  |  Height:  |  Size: 660 B

0
textures/snow_needles_decorated.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 884 B

After

Width:  |  Height:  |  Size: 884 B

0
textures/snow_needles_decorated_animated.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

0
textures/snow_rose.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 120 B

After

Width:  |  Height:  |  Size: 120 B

0
textures/snow_sapling_pine.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 272 B

After

Width:  |  Height:  |  Size: 272 B

0
textures/snow_shrub.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 262 B

After

Width:  |  Height:  |  Size: 262 B

0
textures/snow_shrub_covering.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 229 B

After

Width:  |  Height:  |  Size: 229 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 269 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 297 B

0
textures/snow_sled.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 327 B

After

Width:  |  Height:  |  Size: 327 B

0
textures/snow_snow_brick.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 319 B

After

Width:  |  Height:  |  Size: 319 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 484 B

0
textures/snow_snow_cobble.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 737 B

After

Width:  |  Height:  |  Size: 737 B

0
textures/snow_star.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 349 B

After

Width:  |  Height:  |  Size: 349 B

0
textures/snow_star_lit.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 302 B

After

Width:  |  Height:  |  Size: 302 B

0
textures/snow_tulip.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 124 B

After

Width:  |  Height:  |  Size: 124 B

0
textures/snow_viola.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 117 B

After

Width:  |  Height:  |  Size: 117 B

0
textures/snow_xmas_tree.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 299 B

After

Width:  |  Height:  |  Size: 299 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 104 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 105 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 105 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 105 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 104 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 102 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 104 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 105 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 105 B

Some files were not shown because too many files have changed in this diff Show More