35 Commits

Author SHA1 Message Date
ce0442fe25 Fix Warnings 2021-04-24 13:50:28 +02:00
58ac474139 Add a GitHub action to run luacheck
I don't know much about github actions, so I hope it works correctly.
The yml file is based on https://github.com/ChaosWormz/teleport-request/blob/master/.github/workflows/build.yml
2021-03-21 18:39:27 +01:00
9dc9ab3a39 Small line-to-long style fix and update .luacheckrc 2021-03-21 18:27:41 +01:00
4f4489fc93 Makes ice slippery and removes messages of depreciation 2021-03-21 18:24:25 +01:00
e8a15bf467 Add a luacheckrc and fix errors reported by luacheck
* stairs is now added to depends.txt
* The mapgen perlin noise functions use a buffer now
2021-01-30 17:34:10 +01:00
76981af958 Remove unused variables and do some whitespace fixes 2021-01-30 17:08:00 +01:00
dc799f344f Note about broken mapgen rarity setting 2018-11-25 18:19:21 +01:00
6529ab9304 Fix settingtypes.txt setting description 2018-11-25 18:12:51 +01:00
b4add0091c mapgen: Fix crashes when smooth transition is disabled 2018-11-25 18:07:23 +01:00
221c440034 Shorten max snowball life to ten seconds. (#39) 2018-08-18 10:24:24 +02:00
036f502968 Fix snow walkability
Fixes stair-like snow slopes
2018-08-07 15:50:50 +02:00
de45f53153 Make mapgen work again 2018-08-07 15:40:07 +02:00
337e9e2c55 Fix default settings
Some boolean settings disappeared in 0c90b5dcf3
2018-08-07 15:39:28 +02:00
11364a550c Prod snowballs when they are stuck 2018-08-07 15:03:13 +02:00
5b4e705055 Call this 4.0. 2018-04-23 23:16:35 +12:00
1b4cc3e94c Sane defaults for the boolean settings. 2018-04-23 22:53:17 +12:00
0e5f469c3b Merge branch 'master' of https://github.com/Splizard/minetest-mod-snow 2018-04-23 22:42:46 +12:00
6f9ba85f51 Merge pull request #31 from DS-Minetest/sboxl
make snow selection_box leveled
2018-04-23 22:40:34 +12:00
3737d6eb38 Merge pull request #30 from DS-Minetest/mod_conf
add mod.conf
2018-04-23 22:32:59 +12:00
7f394447f1 Disable mapgen by default, minetest has snow biomes now. 2018-04-23 22:28:55 +12:00
ee3b12c07d Replace falling_snow with paramat's functional snowdrift mechanics. 2018-04-23 22:28:21 +12:00
a624a6fabe Minor change to the sled message, hold sneak instead of press sneak! 2018-04-23 21:41:35 +12:00
0c90b5dcf3 Use the nice new settings api. 2018-04-23 21:27:20 +12:00
efbfa989d2 Fix snow placement bug due to levelled
Before, when placing snow one node above snow, the lower snow node grew and didn't turn into a snowblock

Also, test for protection
2018-03-20 14:13:33 +01:00
1510ced771 Add old minetest_game snow texture to other_texures 2018-02-15 17:45:09 +01:00
663b151dec Fix spawn_falling_node crash 2018-02-15 17:44:27 +01:00
Foz
898c7e313b Rewrite stairs code.
- Handle stairsplus stairs and MTG stairs in the same file.
 - Only create stairs using stairsplus or MTG stairs, not both.
 - Handle map switching from MTG stairs to stairsplus automatically.
 - If using stairsplus:
   - Move stairsplus nodes to proper namespace.
   - Alias stairsplus nodes that moved to a new namespace.
   - Alias duplicated ice and snowblock stairs and slabs to their new namespace.
   - Make ice_brick sawable too.
   - Unify stairsplus cut ice and default:ice texture brightness.
 - If using MTG stairs:
   - Move stairs and slabs to MTG stairs namespace.
   - Alias stairs and slabs that moved to the new namespace.
2018-01-15 18:05:19 +01:00
0dcf9b5f0e Fix missing snow leaves and apple leavesdecay 2017-12-17 12:10:55 +01:00
600eaa2313 Attempt to fix snow leaves leafdecay 2017-12-16 15:45:37 +01:00
aec3bf2ed3 Remove redundant (and obsolete) nodeupdate 2017-12-16 15:29:27 +01:00
fd111402d5
M  src/snowball.lua
2017-12-16 15:22:36 +01:00
2dd10091df make snow selection_box leveled 2017-09-08 19:52:28 +02:00
76eca09e97 add mod.conf 2017-09-08 16:58:26 +02:00
2df09a7ebb Fix pinetree leafdecay 2017-06-25 20:44:50 +02:00
13ecf6a8b2 Merge pull request #26 from FozLand/master
Remove reference to undeclared global variable.
2017-06-19 13:33:24 +12:00
104 changed files with 961 additions and 1542 deletions

11
.github/workflows/luacheck.yml vendored Normal file
View File

@ -0,0 +1,11 @@
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 Executable file → Normal file
View File

25
.luacheckrc Normal file
View File

@ -0,0 +1,25 @@
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 Executable file → Normal file
View File

5
changelog.txt Executable file → Normal file
View File

@ -1,5 +1,10 @@
CHANGELOG: 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 Version 3.2

4
depends.txt Executable file → Normal file
View File

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

55
init.lua Executable file → Normal file
View File

@ -47,43 +47,35 @@ http://github.com/Splizard/minetest-mod-snow/
-- Until something else can be figured out, use paramat's "Snowdrift" mod instead. -- Until something else can be figured out, use paramat's "Snowdrift" mod instead.
-- dofile(modpath.."/falling_snow.lua") -- dofile(modpath.."/falling_snow.lua")
local load_time_start = minetest.get_us_time()
-- Original init.lua File Broken into Smaller Files -- Original init.lua File Broken into Smaller Files
local modpath = minetest.get_modpath("snow") local srcpath = minetest.get_modpath"snow".."/src/"
dofile(modpath.."/src/abms.lua") dofile(srcpath.."abms.lua")
dofile(modpath.."/src/aliases.lua") dofile(srcpath.."aliases.lua")
dofile(modpath.."/src/crafting.lua") dofile(srcpath.."crafting.lua")
-- The formspec menu didn't work when util.lua was the very first "dofile" so I moved -- 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 -- 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 -- 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 -- I put it lower on the list and that seems to do the trick. ~ LazyJ
dofile(modpath.."/src/util.lua") dofile(srcpath.."util.lua")
dofile(modpath.."/src/snowball.lua") dofile(srcpath.."snowball.lua")
-- To get Xmas tree saplings, the "christmas_content", true or false, in "util.lua" has to be determined first. -- 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 -- That means "nodes.lua", where the saplings are controlled, has to come after "util.lua". ~ LazyJ
dofile(modpath.."/src/nodes.lua") dofile(srcpath.."nodes.lua")
dofile(modpath.."/src/basic_stairs_slabs.lua") dofile(srcpath.."stairs.lua")
-- dofile(modpath.."/src/mapgen.lua") dofile(srcpath.."mapgen.lua")
dofile(modpath.."/src/sled.lua") dofile(srcpath.."sled.lua")
-- dofile(modpath.."/src/falling_snow.lua") dofile(srcpath.."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 local is_uneven
--This function places snow checking at the same time for snow level and increasing as needed. --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. --This also takes into account sourrounding snow and makes snow even.
function snow.place(pos) function snow.place(pos, disablesound)
if pos.y < -19000 then return end -- Don't put anything in the nether!
local node = minetest.get_node_or_nil(pos) local node = minetest.get_node_or_nil(pos)
--Oops, maybe there is no node? --Oops, maybe there is no node?
@ -97,17 +89,23 @@ function snow.place(pos)
if level < 63 then 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 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 and not is_uneven(pos) then
if not disablesound then
minetest.sound_play("default_snow_footstep", {pos=pos}) minetest.sound_play("default_snow_footstep", {pos=pos})
end
minetest.add_node_level(pos, 7) minetest.add_node_level(pos, 7)
end end
elseif level == 63 then elseif level == 63 then
local p = minetest.find_node_near(pos, 10, "default:dirt_with_grass") local p = minetest.find_node_near(pos, 10, "default:dirt_with_grass")
if p if p
and minetest.get_node_light(p, 0.5) == 15 then and minetest.get_node_light(p, 0.5) == 15 then
if not disablesound then
minetest.sound_play("default_grass_footstep", {pos=pos}) 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"}) minetest.place_node({x=pos.x, y=pos.y+1, z=pos.z}, {name="default:snow"})
else else
if not disablesound then
minetest.sound_play("default_snow_footstep", {pos=pos}) minetest.sound_play("default_snow_footstep", {pos=pos})
end
minetest.add_node(pos, {name="default:snowblock"}) minetest.add_node(pos, {name="default:snowblock"})
end end
end end
@ -119,7 +117,7 @@ function snow.place(pos)
or drawtype == "allfaces_optional" then or drawtype == "allfaces_optional" then
pos.y = pos.y+1 pos.y = pos.y+1
local sound = data.sounds local sound = data.sounds
if sound then if sound and not disablesound then
sound = sound.footstep sound = sound.footstep
if sound then if sound then
minetest.sound_play(sound.name, {pos=pos, gain=sound.gain}) minetest.sound_play(sound.name, {pos=pos, gain=sound.gain})
@ -198,3 +196,12 @@ snow.register_on_configuring(function(name, v)
end end
end 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 Executable file → Normal file
View File

@ -1,3 +1,40 @@
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 GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007 Version 3, 29 June 2007

1
mod.conf Normal file
View File

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

BIN
models/sled.blend Normal file

Binary file not shown.

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

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

Before

Width:  |  Height:  |  Size: 656 B

After

Width:  |  Height:  |  Size: 656 B

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

Before

Width:  |  Height:  |  Size: 82 B

After

Width:  |  Height:  |  Size: 82 B

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 164 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 384 B

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

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

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

Before

Width:  |  Height:  |  Size: 83 B

After

Width:  |  Height:  |  Size: 83 B

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

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

Before

Width:  |  Height:  |  Size: 300 B

After

Width:  |  Height:  |  Size: 300 B

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

Before

Width:  |  Height:  |  Size: 81 B

After

Width:  |  Height:  |  Size: 81 B

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

Before

Width:  |  Height:  |  Size: 371 B

After

Width:  |  Height:  |  Size: 371 B

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

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

Before

Width:  |  Height:  |  Size: 164 B

After

Width:  |  Height:  |  Size: 164 B

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

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

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

Before

Width:  |  Height:  |  Size: 726 B

After

Width:  |  Height:  |  Size: 726 B

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

Before

Width:  |  Height:  |  Size: 127 B

After

Width:  |  Height:  |  Size: 127 B

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

Before

Width:  |  Height:  |  Size: 190 B

After

Width:  |  Height:  |  Size: 190 B

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

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

Before

Width:  |  Height:  |  Size: 297 B

After

Width:  |  Height:  |  Size: 297 B

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

Before

Width:  |  Height:  |  Size: 602 B

After

Width:  |  Height:  |  Size: 602 B

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

Before

Width:  |  Height:  |  Size: 204 B

After

Width:  |  Height:  |  Size: 204 B

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

Before

Width:  |  Height:  |  Size: 719 B

After

Width:  |  Height:  |  Size: 719 B

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

Before

Width:  |  Height:  |  Size: 553 B

After

Width:  |  Height:  |  Size: 553 B

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

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

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

Before

Width:  |  Height:  |  Size: 602 B

After

Width:  |  Height:  |  Size: 602 B

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

Before

Width:  |  Height:  |  Size: 602 B

After

Width:  |  Height:  |  Size: 602 B

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

Before

Width:  |  Height:  |  Size: 204 B

After

Width:  |  Height:  |  Size: 204 B

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

Before

Width:  |  Height:  |  Size: 371 B

After

Width:  |  Height:  |  Size: 371 B

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

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

Before

Width:  |  Height:  |  Size: 164 B

After

Width:  |  Height:  |  Size: 164 B

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

Before

Width:  |  Height:  |  Size: 572 B

After

Width:  |  Height:  |  Size: 572 B

49
readme.txt Executable file → Normal file
View File

@ -5,21 +5,19 @@
____) | | | | (_) \ V V / | | | | (_) | (_| | ____) | | | | (_) \ V V / | | | | (_) | (_| |
|_____/|_| |_|\___/ \_/\_/ |_| |_|\___/ \__,_| |_____/|_| |_|\___/ \_/\_/ |_| |_|\___/ \__,_|
Version 3.2 Version 4.0
By Splizard and LazyJ. By Splizard, HybridDog and LazyJ.
Minetest version: 0.4.9 Minetest version: 0.4.16+
Depends: default Depends: default
License: GPL v2 License: GPL v3
Complimentary Mods: Complimentary Mods:
--------------------- ---------------------
* "Snowdrift" by paramat
* "More Blocks" by Calinou (2014_05_11 or newer) * "More Blocks" by Calinou (2014_05_11 or newer)
* "Skins" by Zeg9 * "Skins" by Zeg9
Install: Install:
Forum post: http://minetest.net/forum/viewtopic.php?id=2290 Forum post: http://minetest.net/forum/viewtopic.php?id=2290
@ -43,26 +41,8 @@ Place this folder in your minetest mods folder.
world's "world.mt" file: world's "world.mt" file:
load_mod_snow = true load_mod_snow = true
NOTICE
While this mod is installed you may experience slower map loading while a snow biome is generated.
USAGE: 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 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 and ice melts when near warm blocks such as torches or igniters such as lava.
Snow blocks freeze water source blocks around them. Snow blocks freeze water source blocks around them.
@ -86,18 +66,21 @@ Icy Snow:
Snow Ice Snow Ice
Ice Snow 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: Config file:
------------ ------------
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. You can change various settings from the advanced settings in Minetest.
As admin you can use the /snow command in-game to make various changes.
* Go to the settings tab.
* Click on Advanced Settings.
* Click on Mods.
* Click on snow.
* Change stuff!
UNINSTALL: UNINSTALL:
------------ ------------
Simply delete the folder snow from the mods folder. 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 Executable file → Normal file
View File

39
settingtypes.txt Normal file
View File

@ -0,0 +1,39 @@
#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 Executable file → Normal file
View File

@ -1,23 +1,12 @@
--Backwards Compatability. -- Added to change dirt_with_snow to dirt if covered with blocks that don't let
minetest.register_abm({ -- light through (sunlight_propagates) or have a light paramtype and
nodenames = {"snow:snow1","snow:snow2","snow:snow3","gsnow4","snow:snow5","snow:snow6","snow:snow7","snow:snow8"}, -- liquidtype combination. ~ LazyJ, 2014_03_08
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({ minetest.register_abm({
nodenames = {"default:dirt_with_snow"}, nodenames = {"default:dirt_with_snow"},
interval = 2, interval = 2,
chance = 20, chance = 20,
action = function(pos, node) action = function(pos)
local name = minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z}).name local name = minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z}).name
local nodedef = minetest.registered_nodes[name] local nodedef = minetest.registered_nodes[name]
if name ~= "ignore" if name ~= "ignore"
@ -81,7 +70,6 @@ minetest.register_abm({
else else
return return
end end
nodeupdate(pos)
end, end,
}) })
@ -120,7 +108,10 @@ minetest.register_abm({
if math.random(2) == 2 then if math.random(2) == 2 then
p.y = pos.y p.y = pos.y
if minetest.get_node(p).name == "default:water_source" then 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 end
end end
@ -152,13 +143,13 @@ minetest.register_abm({
--[[
--Grow Pine Saplings --Grow Pine Saplings
minetest.register_abm({ minetest.register_abm({
nodenames = {"snow:sapling_pine"}, nodenames = {"snow:sapling_pine"},
interval = 10, interval = 10,
chance = 50, chance = 50,
action = function(pos, node) action = function(pos)
-- Check if there is enough vertical-space for the sapling to grow without -- Check if there is enough vertical-space for the sapling to grow without
-- hitting anything else. ~ LazyJ, 2014_04_10 -- hitting anything else. ~ LazyJ, 2014_04_10
@ -171,7 +162,7 @@ minetest.register_abm({
end end
-- 'then' let the sapling grow into a tree. ~ LazyJ -- '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 -- This finds the sapling under the grown tree. ~ LazyJ
if minetest.get_node(pos).name == "snow:sapling_pine" then if minetest.get_node(pos).name == "snow:sapling_pine" then
-- This switches the sapling to a tree trunk. ~ LazyJ -- This switches the sapling to a tree trunk. ~ LazyJ
@ -181,17 +172,17 @@ minetest.register_abm({
minetest.log("action", "A pine sapling grows into a tree at "..minetest.pos_to_string(pos)) minetest.log("action", "A pine sapling grows into a tree at "..minetest.pos_to_string(pos))
end end
end end
})]] })
--[[
--Grow Christmas Tree Saplings --Grow Christmas Tree Saplings
minetest.register_abm({ minetest.register_abm({
nodenames = {"snow:xmas_tree"}, nodenames = {"snow:xmas_tree"},
interval = 10, interval = 10,
chance = 50, chance = 50,
action = function(pos, node) action = function(pos)
-- 'If' there is air in each of the 8 nodes dirctly above the sapling,... ~LazyJ -- 'If' there is air in each of the 8 nodes dirctly above the sapling,... ~LazyJ
for i = 1,8 do for i = 1,8 do
@ -201,14 +192,14 @@ minetest.register_abm({
end end
-- 'then' let the sapling grow into a tree. ~ LazyJ -- '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 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, --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. -- then don't anything; including not allowing the sapling to grow.
-- ~ LazyJ, 2014_04_10 -- ~ LazyJ, 2014_04_10
--end --end
end end
})]] })

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

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

View File

@ -1,302 +0,0 @@
-- 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 Executable file → Normal file
View File

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

@ -1,184 +1,6 @@
--[[ -- 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 local ground_y = nil
for y=pos.y+10,pos.y+20,1 do for y=pos.y+10,pos.y+20,1 do
local n = minetest.get_node({x=pos.x,y=y,z=pos.z}).name local n = minetest.get_node({x=pos.x,y=y,z=pos.z}).name
@ -199,99 +21,191 @@ local function snow_fall(pos, player, animate)
pos = {x=pos.x, y=ground_y, z=pos.z} 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) snow.place(pos, true)
--minetest.place_node({x=pos.x, y=pos.y+2, z=pos.z}, {name="default:snow"}) -- LazyJ --minetest.place_node({x=pos.x, y=pos.y+2, z=pos.z}, {name="default:snow"}) -- LazyJ
end end
-- Snow local YLIMIT = 1 -- Set to world's water level
local lighter_snowfall = snow.lighter_snowfall -- Particles are timed to disappear at this y
local function calc_snowfall() -- Particles do not spawn when player's head is below this y
for _, player in pairs(minetest.get_connected_players()) do local PRECSPR = 6 -- Time scale for precipitation variation in minutes
local ppos = player:getpos() 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
-- Make sure player is not in a cave/house... local np_prec = {
if get_snow(ppos) offset = 0,
and minetest.get_node_light(ppos, 0.5) == 15 then scale = 1,
local animate spread = {x = PRECSPR, y = PRECSPR, z = PRECSPR},
if not lighter_snowfall then seed = 813,
local vel = {x=0, y=-1, z=-1} octaves = 1,
local acc = {x=0, y=0, z=0} persist = 0,
minetest.add_particlespawner(get_snow_particledef({ lacunarity = 2.0,
amount = 5, --flags = ""
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()
}))
minetest.add_particlespawner(get_snow_particledef({ -- These 2 must match biome heat and humidity noise parameters for a world
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()
}))
animate = false local np_temp = {
else offset = 50,
animate = true scale = 50,
end spread = {x = 1000, y = 1000, z = 1000},
seed = 5349,
octaves = 3,
persist = 0.5,
lacunarity = 2.0,
--flags = ""
}
if math.random(1,5) == 4 then local np_humid = {
snow_fall( offset = 50,
randpos( scale = 50,
addvectors(ppos, {x=-20, y=0, z=-20}), spread = {x = 1000, y = 1000, z = 1000},
addvectors(ppos, {x= 20, y=0, z= 20}) seed = 842,
), octaves = 3,
player, persist = 0.5,
animate lacunarity = 2.0,
) --flags = ""
end }
end
end
end
local step_func
minetest.register_globalstep(function() -- Stuff
step_func()
end) local difsval = DASVAL - NISVAL
local grad = 14 / 95
local yint = 1496 / 95
-- Globalstep function
local timer = 0
if snow.enable_snowfall then if snow.enable_snowfall then
step_func = calc_snowfall minetest.register_globalstep(function(dtime)
infolog("step function set to calc_snowfall") timer = timer + dtime
else if timer < GSCYCLE then
step_func = function() end return
infolog("step function set to empty function")
end end
snow.register_on_configuring(function(name, v) timer = 0
if name == "enable_snowfall" then
if v then for _, player in ipairs(minetest.get_connected_players()) do
step_func = calc_snowfall local player_name = player:get_player_name()
infolog("step function set to calc_snowfall") local pos_player = player:get_pos()
else local pposy = math.floor(pos_player.y) + 2 -- Precipitation when swimming
step_func = function() end if pposy >= YLIMIT - 2 then
infolog("step function set to empty function") 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
elseif name == "lighter_snowfall" then
lighter_snowfall = v
end end
end) end)
end

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

@ -12,6 +12,9 @@ saplings grow into trees. --]]
-- Part 1: To disable the mapgen, add the *starting* comment under this line. -- 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 {} snow.mapgen = snow.mapgen or {}
local mg = snow.mapgen local mg = snow.mapgen
@ -25,12 +28,10 @@ local rarity = snow.mapgen_rarity
local size = snow.mapgen_size local size = snow.mapgen_size
local smooth = snow.smooth_biomes local smooth = snow.smooth_biomes
local nosmooth_rarity, perlin_scale
local function calc_values() local function calc_values()
nosmooth_rarity = 1-rarity/50 nosmooth_rarity = 1-rarity/50
perlin_scale = size*100/rarity perlin_scale = size*100/rarity
mg.perlin_scale = perlin_scale mg.perlin_scale = perlin_scale
local smooth_rarity_max, smooth_rarity_min, smooth_rarity_dif
if smooth then if smooth then
local smooth_trans_size = 4 --snow.smooth_trans_size local smooth_trans_size = 4 --snow.smooth_trans_size
mg.smooth_rarity_max = upper_rarity(nosmooth_rarity+smooth_trans_size*2/perlin_scale) mg.smooth_rarity_max = upper_rarity(nosmooth_rarity+smooth_trans_size*2/perlin_scale)
@ -70,6 +71,7 @@ else
--Load mapgen_v6 compatibility. --Load mapgen_v6 compatibility.
dofile(path.."/src/mapgen_v6.lua") dofile(path.."/src/mapgen_v6.lua")
end end
end
-- To complete the commenting-out add the *closing* comment under this line. -- To complete the commenting-out add the *closing* comment under this line.
@ -107,11 +109,11 @@ local xmas_tree = {
--Makes pine tree --Makes pine tree
function snow.make_pine(pos,snow,xmas) function snow.make_pine(pos,snow,xmas)
local minetest = minetest local minetest = minetest
local try_node = function(pos, node) local function try_node(p, node)
local n = minetest.get_node(pos).name local n = minetest.get_node(p).name
if n == "air" if n == "air"
or n == "ignore" then or n == "ignore" then
minetest.add_node(pos, node) minetest.add_node(p, node)
end end
end end
if xmas then if xmas then
@ -135,7 +137,7 @@ function snow.make_pine(pos,snow,xmas)
if xmas then if xmas then
try_node({x=pos.x,y=pos.y+7,z=pos.z},{name="snow:star_lit"}) -- Added lit star. ~ LazyJ try_node({x=pos.x,y=pos.y+7,z=pos.z},{name="snow:star_lit"}) -- Added lit star. ~ LazyJ
elseif snow elseif snow
and minetest.get_perlin(112,3, 0.5, perlin_scale):get2d({x=pos.x,y=pos.z}) > nosmooth_rarity then and minetest.get_perlin(112,3, 0.5, perlin_scale):get_2d({x=pos.x,y=pos.z}) > nosmooth_rarity then
try_node({x=pos.x,y=pos.y+7,z=pos.z},{name="default:snow"}) try_node({x=pos.x,y=pos.y+7,z=pos.z},{name="default:snow"})
end end
end end
@ -147,20 +149,19 @@ function snow.voxelmanip_pine(pos,a,data)
local c_snow = minetest.get_content_id("default:snow") local c_snow = minetest.get_content_id("default:snow")
local c_pine_needles = minetest.get_content_id("snow:needles") local c_pine_needles = minetest.get_content_id("snow:needles")
local c_pinetree = minetest.get_content_id("default:pinetree") 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) local perlin1 = minetest.get_perlin(112,3, 0.5, perlin_scale)
for z = -1,1 do for off_z = -1,1 do
local z = pos.z + z local z = pos.z + off_z
for x = -1,1 do for off_x = -1,1 do
local x = pos.x + x local x = pos.x + off_x
--Make tree. --Make tree.
for i = 1,2 do for i = 1,2 do
data[a:index(x,pos.y+i,z)] = c_pine_needles data[a:index(x,pos.y+i,z)] = c_pine_needles
if x ~= 0 if x ~= 0
and z ~= 0 and z ~= 0
and perlin1:get2d({x=x,y=z}) > nosmooth_rarity then and perlin1:get_2d({x=x,y=z}) > nosmooth_rarity then
local abovenode = a:index(x,pos.y+i+1,z) local abovenode = a:index(x,pos.y+i+1,z)
data[abovenode] = c_snow data[abovenode] = c_snow
end end
@ -175,16 +176,16 @@ function snow.voxelmanip_pine(pos,a,data)
data[a:index(x-1,y,z)] = c_pine_needles data[a:index(x-1,y,z)] = c_pine_needles
data[a:index(x,y,z+1)] = c_pine_needles data[a:index(x,y,z+1)] = c_pine_needles
data[a:index(x,y,z-1)] = c_pine_needles data[a:index(x,y,z-1)] = c_pine_needles
if perlin1:get2d({x=x+1,y=z}) > nosmooth_rarity then if perlin1:get_2d({x=x+1,y=z}) > nosmooth_rarity then
data[a:index(x+1,y+1,z)] = c_snow data[a:index(x+1,y+1,z)] = c_snow
end end
if perlin1:get2d({x=x+1,y=z}) > nosmooth_rarity then if perlin1:get_2d({x=x+1,y=z}) > nosmooth_rarity then
data[a:index(x-1,y+1,z)] = c_snow data[a:index(x-1,y+1,z)] = c_snow
end end
if perlin1:get2d({x=x,y=z+1}) > nosmooth_rarity then if perlin1:get_2d({x=x,y=z+1}) > nosmooth_rarity then
data[a:index(x,y+1,z+1)] = c_snow data[a:index(x,y+1,z+1)] = c_snow
end end
if perlin1:get2d({x=x,y=z-1}) > nosmooth_rarity then if perlin1:get_2d({x=x,y=z-1}) > nosmooth_rarity then
data[a:index(x,y+1,z-1)] = c_snow data[a:index(x,y+1,z-1)] = c_snow
end end
end end
@ -193,7 +194,29 @@ function snow.voxelmanip_pine(pos,a,data)
end end
data[a:index(pos.x,pos.y+5,pos.z)] = c_pine_needles 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 data[a:index(pos.x,pos.y+6,pos.z)] = c_pine_needles
if perlin1:get2d({x=pos.x,y=pos.z}) > nosmooth_rarity then if perlin1:get_2d({x=pos.x,y=pos.z}) > nosmooth_rarity then
data[a:index(pos.x,pos.y+7,pos.z)] = c_snow data[a:index(pos.x,pos.y+7,pos.z)] = c_snow
end end
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 Executable file → Normal file
View File

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

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

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

@ -8,11 +8,16 @@ local nodedef = {
tiles = {"snow_needles.png"}, tiles = {"snow_needles.png"},
waving = 1, waving = 1,
paramtype = "light", paramtype = "light",
groups = {snappy=3, leafdecay=5}, groups = {snappy=3},
furnace_burntime = 1, furnace_burntime = 1,
drop = { drop = {
max_items = 1, max_items = 1,
items = { items = {
{
-- player will get sapling with 1/20 chance
items = {'snow:sapling_pine'},
rarity = 20,
},
{ {
items = {'snow:needles'}, items = {'snow:needles'},
} }
@ -27,17 +32,23 @@ 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. The Xmas tree needles are registred and defined a farther down in this nodes.lua file.
~ LazyJ ~ LazyJ
]]
if snow.christmas_content then if snow.christmas_content then
table.insert(nodedef.drop.items, 1, { table.insert(nodedef.drop.items, 1, {
-- player will get xmas tree with 1/120 chance -- player will get xmas tree with 1/120 chance
items = {'snow:xmas_tree'}, items = {"snow:xmas_tree"},
rarity = 120, rarity = 120,
}) })
end end
]]
minetest.register_node("snow:needles", table.copy(nodedef)) 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) snow.register_on_configuring(function(name, v)
if name == "christmas_content" then if name == "christmas_content" then
local drop = minetest.registered_nodes["snow:needles"].drop local drop = minetest.registered_nodes["snow:needles"].drop
@ -56,8 +67,8 @@ end)
-- Christmas egg -- Christmas egg
if minetest.global_exists"skins" then if minetest.global_exists("skins") then
skins.add"character_snow_man" skins.add("character_snow_man")
end end
@ -71,16 +82,18 @@ if snow.disable_deco_needle_ani then
else else
-- Animated, "blinking lights" version. ~ LazyJ -- Animated, "blinking lights" version. ~ LazyJ
nodedef.inventory_image = minetest.inventorycube("snow_needles_decorated.png") nodedef.inventory_image = minetest.inventorycube("snow_needles_decorated.png")
nodedef.tiles = { nodedef.tiles = {{
{name="snow_needles_decorated_animated.png", animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=20.0}} name="snow_needles_decorated_animated.png",
} animation={type="vertical_frames", aspect_w=16, aspect_h=16,
length=20.0}
}}
end end
nodedef.drop.items[#nodedef.drop.items] = {items = {'snow:needles_decorated'}} nodedef.drop.items[#nodedef.drop.items] = {items = {'snow:needles_decorated'}}
minetest.register_node("snow:needles_decorated", nodedef) minetest.register_node("snow:needles_decorated", nodedef)
--[[ Saplings -- Saplings
nodedef = { nodedef = {
description = "Pine Sapling", description = "Pine Sapling",
@ -106,7 +119,7 @@ nodedef.inventory_image = "snow_xmas_tree.png"
nodedef.wield_image = "snow_xmas_tree.png" nodedef.wield_image = "snow_xmas_tree.png"
minetest.register_node("snow:xmas_tree", nodedef) minetest.register_node("snow:xmas_tree", nodedef)
]]
nodedef = { nodedef = {
description = "Star", description = "Star",
@ -118,12 +131,15 @@ nodedef = {
walkable = false, walkable = false,
-- Don't want the ornament breaking too easily because you have to punch it to turn it on and off. ~ LazyJ -- 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}, 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 -- Breaking "glass" sound makes it sound like a real, broken, Xmas tree
sounds = default.node_sound_glass_defaults({dig = {name="default_glass_footstep", gain=0.2}}), -- ornament (Sorry, Mom!). ;)- ~ LazyJ
on_punch = function(pos, node) -- Added a "lit" star that can be punched on or off depending on your preference. ~ 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)
node.name = "snow:star_lit" node.name = "snow:star_lit"
minetest.set_node(pos, node) minetest.set_node(pos, node)
nodeupdate(pos)
end, end,
} }
@ -132,14 +148,13 @@ minetest.register_node("snow:star", table.copy(nodedef))
-- Star (Lit Version) on Xmas Trees -- Star (Lit Version) on Xmas Trees
nodedef.description = nodedef.description.." Lighted" nodedef.description = nodedef.description.." Lighted"
nodedef.light_source = default.LIGHT_MAX nodedef.light_source = minetest.LIGHT_MAX
nodedef.tiles = {"snow_star_lit.png"} nodedef.tiles = {"snow_star_lit.png"}
nodedef.drop = "snow:star" nodedef.drop = "snow:star"
nodedef.groups.not_in_creative_inventory = 1 nodedef.groups.not_in_creative_inventory = 1
nodedef.on_punch = function(pos, node) nodedef.on_punch = function(pos, node)
node.name = "snow:star" node.name = "snow:star"
minetest.set_node(pos, node) minetest.set_node(pos, node)
nodeupdate(pos)
end end
minetest.register_node("snow:star_lit", nodedef) minetest.register_node("snow:star_lit", nodedef)
@ -257,6 +272,15 @@ nodedef.groups.flammable = 1
minetest.register_node("snow:apple", nodedef) minetest.register_node("snow:apple", nodedef)
snow.known_plants[minetest.get_content_id("default:apple")] = minetest.get_content_id("snow:apple") 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 -- TODO
snow.known_plants[minetest.get_content_id("default:jungleleaves")] = minetest.get_content_id("default:jungleleaves") snow.known_plants[minetest.get_content_id("default:jungleleaves")] = minetest.get_content_id("default:jungleleaves")
@ -267,8 +291,7 @@ local function snow_onto_dirt(pos)
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
if node.name == "default:dirt_with_grass" if node.name == "default:dirt_with_grass"
or node.name == "default:dirt" then or node.name == "default:dirt" then
node.name = "default:dirt_with_snow" minetest.set_node(pos, {name = "default:dirt_with_snow"})
minetest.set_node(pos, node)
end end
end end
@ -288,33 +311,27 @@ nodedef = {
-- by player position. ~ LazyJ -- by player position. ~ LazyJ
-- I made this a little harder to dig than snow blocks because -- 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 -- 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}, 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},
--Let's use the new snow sounds instead of the old grass sounds. ~ LazyJ --Let's use the new snow sounds instead of the old grass sounds. ~ LazyJ
sounds = default.node_sound_dirt_defaults({ sounds = default.node_sound_snow_defaults(),
footstep = {name="default_snow_footstep", gain=0.25}, -- The "on_construct" part below, thinking in terms of layers,
dig = {name="default_dig_crumbly", gain=0.4}, -- dirt_with_snow could also double as dirt_with_frost which adds subtlety
dug = {name="default_snow_footstep", gain=0.75}, -- to the winterscape. ~ LazyJ
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 on_construct = snow_onto_dirt
} }
-- Snow Brick -- Snow Brick
minetest.register_node("snow:snow_brick", table.copy(nodedef)) minetest.register_node("snow:snow_brick", table.copy(nodedef))
-- hard Ice Brick, original texture from LazyJ -- hard Ice Brick, original texture from LazyJ
local ibdef = table.copy(nodedef) local ibdef = table.copy(nodedef)
ibdef.description = "Ice Brick" ibdef.description = "Ice Brick"
ibdef.tiles = {"snow_ice_brick.png"} ibdef.tiles = {"snow_ice_brick.png"}
ibdef.use_texture_alpha = true ibdef.use_texture_alpha = "blend"
ibdef.drawtype = "glasslike" ibdef.drawtype = "glasslike"
ibdef.groups = {cracky=1, crumbly=1, choppy=1, melts=1} ibdef.groups = {cracky=1, crumbly=1, choppy=1, melts=1, cools_lava = 1, slippery = 3}
ibdef.sounds = default.node_sound_glass_defaults({ ibdef.sounds = default.node_sound_ice_defaults()
dug = {name="default_hard_footstep", gain=1}
})
minetest.register_node("snow:ice_brick", ibdef) minetest.register_node("snow:ice_brick", ibdef)
@ -326,43 +343,159 @@ nodedef.tiles = {"snow_snow_cobble.png"}
minetest.register_node("snow:snow_cobble", nodedef) minetest.register_node("snow:snow_cobble", nodedef)
-- Override Default Nodes to Add Extra Functions -- Override Default Nodes to Add Extra Functions
-- This adds code to the existing default ice. ~ LazyJ local groups = minetest.registered_nodes["default:ice"].groups
groups["melt"] = 1
minetest.override_item("default:ice", { 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", drawtype = "glasslike",
inventory_image = minetest.inventorycube("default_ice.png").."^[brighten", 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"},
liquidtype = "none", liquidtype = "none",
-- I made this a lot harder to dig than snow blocks because ice is much more dense groups = groups,
-- 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, on_construct = snow_onto_dirt,
liquids_pointable = true, liquids_pointable = true,
--Make ice freeze over when placed by a maximum of 10 blocks. --Make ice freeze over when placed by a maximum of 10 blocks.
after_place_node = function(pos) after_place_node = function(pos)
minetest.set_node(pos, {name="default:ice", param2=math.random(0,10)}) minetest.set_node(pos, {name="default:ice", param2=math.random(0,10)})
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 end
})
-- This adds code to the existing, default snowblock. ~ LazyJ
minetest.override_item("default:snowblock", { minetest.override_item("default:snowblock", {
liquidtype = "none", -- LazyJ to make dirt below change to dirt_with_snow (see default, nodes.lua, dirt ABM) liquidtype = "none",
paramtype = "light", -- LazyJ to make dirt below change to dirt_with_snow (see default, nodes.lua, dirt ABM) paramtype = "light",
sunlight_propagates = true, -- LazyJ to make dirt below change to dirt_with_snow (see default, nodes.lua, dirt ABM) sunlight_propagates = true,
-- Snow blocks should be easy to dig because they are just fluffy snow. ~ LazyJ on_construct = snow_onto_dirt,
groups = {cracky=3, crumbly=3, choppy=3, oddly_breakable_by_hand=3, melts=1, icemaker=1, cooks_into_ice=1, falling_node=1}, groups = groups,
--drop = "snow:snow_cobble", })
on_construct = snow_onto_dirt
-- Thinking in terms of layers, dirt_with_snow could also double as minetest.override_item("default:snow", {
-- dirt_with_frost which adds subtlety to the winterscape. ~ LazyJ, 2014_04_04 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
}) })

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

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

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

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

101
src/stairs.lua Normal file
View File

@ -0,0 +1,101 @@
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

View File

@ -1,342 +0,0 @@
-- ===============================================================================
-- 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 Executable file → Normal file
View File

@ -1,38 +1,25 @@
--Global config and function table. --Global config and function table.
snow = { snow = {
snowball_gravity = 100/109, snowball_gravity = tonumber(minetest.settings:get("snow_snowball_gravity")) or 0.91,
snowball_velocity = 19, snowball_velocity = tonumber(minetest.settings:get("snow_snowball_velocity")) or 19,
sleds = true, sleds = minetest.settings:get_bool("snow_sleds", true),
enable_snowfall = true, enable_snowfall = minetest.settings:get_bool("snow_enable_snowfall", true),
lighter_snowfall = false, lighter_snowfall = minetest.settings:get_bool("snow_lighter_snowfall", false),
debug = false, debug = minetest.settings:get_bool("snow_debug", false),
smooth_biomes = true, smooth_biomes = minetest.settings:get_bool("snow_smooth_biomes", true),
christmas_content = true, christmas_content = minetest.settings:get_bool("snow_christmas_content", true),
smooth_snow = true, smooth_snow = minetest.settings:get_bool("snow_smooth_snow", true),
min_height = 3, min_height = tonumber(minetest.settings:get("snow_min_height")) or 3,
mapgen_rarity = 18, mapgen_rarity = tonumber(minetest.settings:get("snow_mapgen_rarity")) or 18,
mapgen_size = 210, mapgen_size = tonumber(minetest.settings:get("snow_mapgen_size")) or 210,
} disable_mapgen = minetest.settings:get_bool("snow_disable_mapgen", true),
--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 -- functions for dynamically changing settings
snow.register_on_configuring = function() end
--[[
local on_configurings,n = {},1 local on_configurings,n = {},1
function snow.register_on_configuring(func) function snow.register_on_configuring(func)
on_configurings[n] = func on_configurings[n] = func
@ -65,164 +52,4 @@ local function value_from_string(v)
end end
return v return v
end 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 Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

0
textures/character_snow_man_preview.png Executable file → Normal 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 Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 211 B

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

Before

Width:  |  Height:  |  Size: 249 B

After

Width:  |  Height:  |  Size: 249 B

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

Before

Width:  |  Height:  |  Size: 122 B

After

Width:  |  Height:  |  Size: 122 B

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

Before

Width:  |  Height:  |  Size: 118 B

After

Width:  |  Height:  |  Size: 118 B

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

Before

Width:  |  Height:  |  Size: 269 B

After

Width:  |  Height:  |  Size: 269 B

BIN
textures/snow_ice.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 643 B

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

Before

Width:  |  Height:  |  Size: 665 B

After

Width:  |  Height:  |  Size: 665 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 606 B

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

Before

Width:  |  Height:  |  Size: 190 B

After

Width:  |  Height:  |  Size: 190 B

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

Before

Width:  |  Height:  |  Size: 619 B

After

Width:  |  Height:  |  Size: 619 B

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

Before

Width:  |  Height:  |  Size: 660 B

After

Width:  |  Height:  |  Size: 660 B

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

Before

Width:  |  Height:  |  Size: 884 B

After

Width:  |  Height:  |  Size: 884 B

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

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

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

Before

Width:  |  Height:  |  Size: 120 B

After

Width:  |  Height:  |  Size: 120 B

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

Before

Width:  |  Height:  |  Size: 272 B

After

Width:  |  Height:  |  Size: 272 B

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

Before

Width:  |  Height:  |  Size: 262 B

After

Width:  |  Height:  |  Size: 262 B

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

Before

Width:  |  Height:  |  Size: 229 B

After

Width:  |  Height:  |  Size: 229 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 269 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 297 B

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

Before

Width:  |  Height:  |  Size: 327 B

After

Width:  |  Height:  |  Size: 327 B

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

Before

Width:  |  Height:  |  Size: 319 B

After

Width:  |  Height:  |  Size: 319 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 484 B

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

Before

Width:  |  Height:  |  Size: 737 B

After

Width:  |  Height:  |  Size: 737 B

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

Before

Width:  |  Height:  |  Size: 349 B

After

Width:  |  Height:  |  Size: 349 B

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

Before

Width:  |  Height:  |  Size: 302 B

After

Width:  |  Height:  |  Size: 302 B

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

Before

Width:  |  Height:  |  Size: 124 B

After

Width:  |  Height:  |  Size: 124 B

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

Before

Width:  |  Height:  |  Size: 117 B

After

Width:  |  Height:  |  Size: 117 B

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

Before

Width:  |  Height:  |  Size: 299 B

After

Width:  |  Height:  |  Size: 299 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 104 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 104 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 104 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 B

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