Compare commits
35 Commits
Author | SHA1 | Date | |
---|---|---|---|
ce0442fe25 | |||
58ac474139 | |||
9dc9ab3a39 | |||
4f4489fc93 | |||
e8a15bf467 | |||
76981af958 | |||
dc799f344f | |||
6529ab9304 | |||
b4add0091c | |||
221c440034 | |||
036f502968 | |||
de45f53153 | |||
337e9e2c55 | |||
11364a550c | |||
5b4e705055 | |||
1b4cc3e94c | |||
0e5f469c3b | |||
6f9ba85f51 | |||
3737d6eb38 | |||
7f394447f1 | |||
ee3b12c07d | |||
a624a6fabe | |||
0c90b5dcf3 | |||
efbfa989d2 | |||
1510ced771 | |||
663b151dec | |||
898c7e313b | |||
0dcf9b5f0e | |||
600eaa2313 | |||
aec3bf2ed3 | |||
fd111402d5 | |||
2dd10091df | |||
76eca09e97 | |||
2df09a7ebb | |||
13ecf6a8b2 |
11
.github/workflows/luacheck.yml
vendored
Normal 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: ""
|
25
.luacheckrc
Normal 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"}
|
@ -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
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
default
|
default
|
||||||
flowers?
|
flowers?
|
||||||
|
stairs?
|
||||||
moreblocks?
|
moreblocks?
|
||||||
skins?
|
skins?
|
||||||
treecapitator?
|
treecapitator?
|
||||||
|
11
init.lua
@ -66,6 +66,7 @@ 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(srcpath.."nodes.lua")
|
dofile(srcpath.."nodes.lua")
|
||||||
|
dofile(srcpath.."stairs.lua")
|
||||||
dofile(srcpath.."mapgen.lua")
|
dofile(srcpath.."mapgen.lua")
|
||||||
dofile(srcpath.."sled.lua")
|
dofile(srcpath.."sled.lua")
|
||||||
dofile(srcpath.."falling_snow.lua")
|
dofile(srcpath.."falling_snow.lua")
|
||||||
@ -74,7 +75,7 @@ dofile(srcpath.."falling_snow.lua")
|
|||||||
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)
|
||||||
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?
|
||||||
@ -88,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
|
||||||
@ -110,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})
|
||||||
|
37
license.txt
@ -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
|
||||||
|
|
||||||
|
BIN
other_textures/fine_snow.png
Normal file
After Width: | Height: | Size: 164 B |
BIN
other_textures/fine_snow_normal.png
Normal file
After Width: | Height: | Size: 384 B |
47
readme.txt
@ -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,24 +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:
|
TODO:
|
||||||
— use the settingtypes.txt
|
|
||||||
— test if the fixed ground_y search works correctly at chunkcorners at ground level
|
— test if the fixed ground_y search works correctly at chunkcorners at ground level
|
||||||
|
39
settingtypes.txt
Normal 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
|
30
src/abms.lua
@ -1,10 +1,12 @@
|
|||||||
-- 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
|
-- 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"
|
||||||
@ -37,9 +39,9 @@ minetest.register_abm({
|
|||||||
if intensity == 1 then
|
if intensity == 1 then
|
||||||
minetest.set_node(pos, {name="default:water_source"})
|
minetest.set_node(pos, {name="default:water_source"})
|
||||||
elseif intensity == 2 then
|
elseif intensity == 2 then
|
||||||
minetest.set_node(pos, {name="default:water_flowing", param2=7})
|
minetest.set_node(pos, {name="default:water_flowing", param2=7})
|
||||||
elseif intensity == 3 then
|
elseif intensity == 3 then
|
||||||
minetest.set_node(pos, {name="default:water_flowing", param2=3})
|
minetest.set_node(pos, {name="default:water_flowing", param2=3})
|
||||||
--[[ LazyJ, you need to add param2, which defines the amount of the flowing water ~ HybridDog 2015_03_06
|
--[[ LazyJ, you need to add param2, which defines the amount of the flowing water ~ HybridDog 2015_03_06
|
||||||
This was causing "melts=2" nodes to just disappear so I changed it to replace the
|
This was causing "melts=2" nodes to just disappear so I changed it to replace the
|
||||||
node with a water_source for a couple seconds and then replace the water_source with
|
node with a water_source for a couple seconds and then replace the water_source with
|
||||||
@ -61,14 +63,13 @@ minetest.register_abm({
|
|||||||
-- the water to flow and spread before the
|
-- the water to flow and spread before the
|
||||||
-- water_source is changed to air. ~ LazyJ
|
-- water_source is changed to air. ~ LazyJ
|
||||||
if minetest.get_node(pos).name == "default:water_source" then
|
if minetest.get_node(pos).name == "default:water_source" then
|
||||||
minetest.add_node(pos,{name="air"})
|
minetest.add_node(pos,{name="air"})
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
--]]
|
--]]
|
||||||
else
|
else
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
nodeupdate(pos)
|
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -79,7 +80,7 @@ minetest.register_abm({
|
|||||||
--Water freezes when in contact with snow.
|
--Water freezes when in contact with snow.
|
||||||
minetest.register_abm({
|
minetest.register_abm({
|
||||||
nodenames = {"default:water_source"},
|
nodenames = {"default:water_source"},
|
||||||
-- Added "group:icemaker" and snowbrick. ~ LazyJ
|
-- Added "group:icemaker" and snowbrick. ~ LazyJ
|
||||||
neighbors = {"default:snow", "default:snowblock", "snow:snow_brick", "group:icemaker"},
|
neighbors = {"default:snow", "default:snowblock", "snow:snow_brick", "group:icemaker"},
|
||||||
interval = 20,
|
interval = 20,
|
||||||
chance = 4,
|
chance = 4,
|
||||||
@ -107,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
|
||||||
@ -145,7 +149,7 @@ 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
|
||||||
@ -178,7 +182,7 @@ 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
|
||||||
|
@ -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
|
|
@ -1,202 +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
|
|
||||||
|
|
||||||
local em = ""
|
|
||||||
if type(x) ~= "number" then
|
|
||||||
em = em.. "x no number but "..type(x).." "
|
|
||||||
elseif x%1 ~= 0 then
|
|
||||||
em = em.. "x no integer but "..x.." "
|
|
||||||
end
|
|
||||||
if type(y) ~= "number" then
|
|
||||||
em = em.. "y no number but "..type(y).." "
|
|
||||||
elseif y%1 ~= 0 then
|
|
||||||
em = em.. "y no integer but "..y.." "
|
|
||||||
end
|
|
||||||
if em ~= "" then
|
|
||||||
error(em)
|
|
||||||
end
|
|
||||||
|
|
||||||
if cold_perl_values[y] then
|
|
||||||
cold_perl_values[y][x] = v
|
|
||||||
end
|
|
||||||
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
|
||||||
@ -217,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 = vector.round(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
|
|
||||||
|
|
||||||
snow.register_on_configuring(function(name, v)
|
|
||||||
if name == "enable_snowfall" then
|
|
||||||
if v then
|
|
||||||
step_func = calc_snowfall
|
|
||||||
infolog("step function set to calc_snowfall")
|
|
||||||
else
|
|
||||||
step_func = function() end
|
|
||||||
infolog("step function set to empty function")
|
|
||||||
end
|
end
|
||||||
elseif name == "lighter_snowfall" then
|
|
||||||
lighter_snowfall = v
|
timer = 0
|
||||||
end
|
|
||||||
end)
|
for _, player in ipairs(minetest.get_connected_players()) do
|
||||||
|
local player_name = player:get_player_name()
|
||||||
|
local pos_player = player:get_pos()
|
||||||
|
local pposy = math.floor(pos_player.y) + 2 -- Precipitation when swimming
|
||||||
|
if pposy >= YLIMIT - 2 then
|
||||||
|
local pposx = math.floor(pos_player.x)
|
||||||
|
local pposz = math.floor(pos_player.z)
|
||||||
|
local ppos = {x = pposx, y = pposy, z = pposz}
|
||||||
|
|
||||||
|
local nobj_temp = minetest.get_perlin(np_temp)
|
||||||
|
local nobj_humid = minetest.get_perlin(np_humid)
|
||||||
|
local nobj_prec = minetest.get_perlin(np_prec)
|
||||||
|
|
||||||
|
local nval_temp = nobj_temp:get_2d({x = pposx, y = pposz})
|
||||||
|
local nval_humid = nobj_humid:get_2d({x = pposx, y = pposz})
|
||||||
|
local nval_prec = nobj_prec:get_2d({x = os.clock() / 60, y = 0})
|
||||||
|
|
||||||
|
-- Biome system: Frozen biomes below heat 35,
|
||||||
|
-- deserts below line 14 * t - 95 * h = -1496
|
||||||
|
-- h = (14 * t + 1496) / 95
|
||||||
|
-- h = 14/95 * t + 1496/95
|
||||||
|
-- where 14/95 is gradient and 1496/95 is y intersection
|
||||||
|
-- h - 14/95 t = 1496/95 y intersection
|
||||||
|
-- so area above line is
|
||||||
|
-- h - 14/95 t > 1496/95
|
||||||
|
local freeze = nval_temp < 35
|
||||||
|
local precip = nval_prec < (nval_humid - 50) / 50 + PRECOFF and
|
||||||
|
nval_humid - grad * nval_temp > yint
|
||||||
|
|
||||||
|
if snow.debug then
|
||||||
|
precip = true
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Check if player is outside
|
||||||
|
local outside = minetest.get_node_light(ppos, 0.5) == 15
|
||||||
|
|
||||||
|
-- Occasionally reset player sky
|
||||||
|
if math.random() < 0.1 then
|
||||||
|
if precip then
|
||||||
|
-- Set overcast sky
|
||||||
|
local sval
|
||||||
|
local time = minetest.get_timeofday()
|
||||||
|
if time >= 0.5 then
|
||||||
|
time = 1 - time
|
||||||
|
end
|
||||||
|
-- Sky brightness transitions:
|
||||||
|
-- First transition (24000 -) 4500, (1 -) 0.1875
|
||||||
|
-- Last transition (24000 -) 5750, (1 -) 0.2396
|
||||||
|
if time <= 0.1875 then
|
||||||
|
sval = NISVAL
|
||||||
|
elseif time >= 0.2396 then
|
||||||
|
sval = DASVAL
|
||||||
|
else
|
||||||
|
sval = math.floor(NISVAL +
|
||||||
|
((time - 0.1875) / 0.0521) * difsval)
|
||||||
|
end
|
||||||
|
-- Set sky to overcast bluish-grey
|
||||||
|
player:set_sky({
|
||||||
|
base_color = {r = sval, g = sval, b = sval + 16, a = 255},
|
||||||
|
type = "plain",
|
||||||
|
})
|
||||||
|
else
|
||||||
|
-- Reset sky to normal
|
||||||
|
player:set_sky({type = "regular"})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if precip and outside then
|
||||||
|
-- Precipitation
|
||||||
|
if freeze then
|
||||||
|
-- Snowfall
|
||||||
|
local extime = math.min((pposy + 12 - YLIMIT) / 2, 9)
|
||||||
|
|
||||||
|
local x, y, z = pposx - 24 + math.random(0, 48), pposy + 12, pposz - 24 + math.random(0, 48)
|
||||||
|
|
||||||
|
if not snow.lighter_snowfall then
|
||||||
|
snow_fall({
|
||||||
|
x = x,
|
||||||
|
y = y,
|
||||||
|
z = z
|
||||||
|
}, true)
|
||||||
|
end
|
||||||
|
|
||||||
|
for _ = 1, FLAKES do
|
||||||
|
|
||||||
|
x, y, z = pposx - 24 + math.random(0, 48), pposy + 12, pposz - 24 + math.random(0, 48)
|
||||||
|
|
||||||
|
minetest.add_particle({
|
||||||
|
pos = {
|
||||||
|
x = x,
|
||||||
|
y = y,
|
||||||
|
z = z
|
||||||
|
},
|
||||||
|
velocity = {
|
||||||
|
x = (-20 + math.random(0, 40)) / 100,
|
||||||
|
y = -2.0,
|
||||||
|
z = (-20 + math.random(0, 40)) / 100
|
||||||
|
},
|
||||||
|
acceleration = {x = 0, y = 0, z = 0},
|
||||||
|
expirationtime = extime,
|
||||||
|
size = 2.8,
|
||||||
|
collisiondetection = COLLIDE,
|
||||||
|
collision_removal = true,
|
||||||
|
vertical = false,
|
||||||
|
texture = "snowdrift_snowflake" ..
|
||||||
|
math.random(1, 12) .. ".png",
|
||||||
|
playername = player_name
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
129
src/mapgen.lua
@ -12,63 +12,65 @@ 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
|
||||||
|
|
||||||
-- perlin noise "hills" are not peaks but looking like sinus curve
|
-- perlin noise "hills" are not peaks but looking like sinus curve
|
||||||
local function upper_rarity(rarity)
|
local function upper_rarity(rarity)
|
||||||
return math.sign(rarity)*math.sin(math.abs(rarity)*math.pi/2)
|
return math.sign(rarity)*math.sin(math.abs(rarity)*math.pi/2)
|
||||||
end
|
|
||||||
|
|
||||||
local rarity = snow.mapgen_rarity
|
|
||||||
local size = snow.mapgen_size
|
|
||||||
local smooth = snow.smooth_biomes
|
|
||||||
|
|
||||||
local nosmooth_rarity, perlin_scale
|
|
||||||
local function calc_values()
|
|
||||||
nosmooth_rarity = 1-rarity/50
|
|
||||||
perlin_scale = size*100/rarity
|
|
||||||
mg.perlin_scale = perlin_scale
|
|
||||||
local smooth_rarity_max, smooth_rarity_min, smooth_rarity_dif
|
|
||||||
if smooth then
|
|
||||||
local smooth_trans_size = 4 --snow.smooth_trans_size
|
|
||||||
mg.smooth_rarity_max = upper_rarity(nosmooth_rarity+smooth_trans_size*2/perlin_scale)
|
|
||||||
mg.smooth_rarity_min = upper_rarity(nosmooth_rarity-smooth_trans_size/perlin_scale)
|
|
||||||
mg.smooth_rarity_dif = mg.smooth_rarity_max-mg.smooth_rarity_min
|
|
||||||
end
|
end
|
||||||
nosmooth_rarity = upper_rarity(nosmooth_rarity)
|
|
||||||
mg.nosmooth_rarity = nosmooth_rarity
|
|
||||||
end
|
|
||||||
calc_values()
|
|
||||||
|
|
||||||
snow.register_on_configuring(function(name, v)
|
local rarity = snow.mapgen_rarity
|
||||||
if name == "mapgen_rarity" then
|
local size = snow.mapgen_size
|
||||||
rarity = v
|
local smooth = snow.smooth_biomes
|
||||||
elseif name == "mapgen_size" then
|
|
||||||
size = v
|
local function calc_values()
|
||||||
elseif name == "smooth_biomes" then
|
nosmooth_rarity = 1-rarity/50
|
||||||
smooth = v
|
perlin_scale = size*100/rarity
|
||||||
else
|
mg.perlin_scale = perlin_scale
|
||||||
return
|
if smooth then
|
||||||
|
local smooth_trans_size = 4 --snow.smooth_trans_size
|
||||||
|
mg.smooth_rarity_max = upper_rarity(nosmooth_rarity+smooth_trans_size*2/perlin_scale)
|
||||||
|
mg.smooth_rarity_min = upper_rarity(nosmooth_rarity-smooth_trans_size/perlin_scale)
|
||||||
|
mg.smooth_rarity_dif = mg.smooth_rarity_max-mg.smooth_rarity_min
|
||||||
|
end
|
||||||
|
nosmooth_rarity = upper_rarity(nosmooth_rarity)
|
||||||
|
mg.nosmooth_rarity = nosmooth_rarity
|
||||||
end
|
end
|
||||||
-- TODO: if e.g. size and rarity get changed at once, don't calculate the values more times
|
|
||||||
calc_values()
|
calc_values()
|
||||||
end)
|
|
||||||
|
snow.register_on_configuring(function(name, v)
|
||||||
|
if name == "mapgen_rarity" then
|
||||||
|
rarity = v
|
||||||
|
elseif name == "mapgen_size" then
|
||||||
|
size = v
|
||||||
|
elseif name == "smooth_biomes" then
|
||||||
|
smooth = v
|
||||||
|
else
|
||||||
|
return
|
||||||
|
end
|
||||||
|
-- TODO: if e.g. size and rarity get changed at once, don't calculate the values more times
|
||||||
|
calc_values()
|
||||||
|
end)
|
||||||
|
|
||||||
|
|
||||||
--Identify the mapgen.
|
--Identify the mapgen.
|
||||||
local mgname = minetest.get_mapgen_setting"mg_name"
|
local mgname = minetest.get_mapgen_setting"mg_name"
|
||||||
if not mgname then
|
if not mgname then
|
||||||
minetest.log("error", "[MOD] Snow Biomes: WARNING! mapgen could not be identifyed!")
|
minetest.log("error", "[MOD] Snow Biomes: WARNING! mapgen could not be identifyed!")
|
||||||
end
|
end
|
||||||
local path = minetest.get_modpath"snow"
|
local path = minetest.get_modpath"snow"
|
||||||
if mgname == "v7" then
|
if mgname == "v7" then
|
||||||
--Load mapgen_v7 compatibility.
|
--Load mapgen_v7 compatibility.
|
||||||
dofile(path.."/src/mapgen_v7.lua")
|
dofile(path.."/src/mapgen_v7.lua")
|
||||||
else
|
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,7 @@ 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
|
||||||
|
@ -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
|
||||||
@ -186,7 +186,9 @@ local function get_perlins(sidelen)
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
local nbuf_default, nbuf_cold, nbuf_ice
|
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()
|
||||||
|
|
||||||
@ -210,7 +212,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
|||||||
local pines_tab,pnum = {},1
|
local pines_tab,pnum = {},1
|
||||||
|
|
||||||
get_perlins(x1 - x0 + 1)
|
get_perlins(x1 - x0 + 1)
|
||||||
local nvals_default = perlin_objs.default:get2dMap_flat({x=x0+150, y=z0+50}, nbuf_default)
|
local nvals_default = perlin_objs.default:get_2dMap_flat({x=x0+150, y=z0+50}, nbuf_default)
|
||||||
local nvals_cold, nvals_ice, ndia
|
local nvals_cold, nvals_ice, ndia
|
||||||
|
|
||||||
-- Choose biomes
|
-- Choose biomes
|
||||||
@ -229,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
|
||||||
@ -237,9 +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
|
||||||
nvals_cold = nvals_cold or perlin_objs.cold:get2dMap_flat({x=x0, y=z0}, nbuf_cold)
|
nvals_cold = nvals_cold or perlin_objs.cold:get_2dMap_flat({x=x0, y=z0}, nbuf_cold)
|
||||||
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
|
||||||
@ -255,7 +257,7 @@ 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
|
||||||
@ -289,7 +291,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
if not nvals_ice then
|
if not nvals_ice then
|
||||||
nvals_ice = perlin_objs.ice:get2dMap_flat({x=x0, y=z0}, nbuf_ice)
|
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
|
||||||
@ -345,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
|
||||||
@ -387,13 +390,13 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
|||||||
and (cool or icebergs)
|
and (cool or icebergs)
|
||||||
and pr:next(1,4) == 1 then
|
and pr:next(1,4) == 1 then
|
||||||
|
|
||||||
local vi = node + 1
|
local vi_ice = node + 1
|
||||||
for i = 1,6 do
|
for i = 1,6 do
|
||||||
if data[vi] == c.ice then
|
if data[vi_ice] == c.ice then
|
||||||
ice = true
|
ice = true
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
vi = vi + ndia[i]
|
vi_ice = vi_ice + ndia[i]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -504,8 +507,8 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
|||||||
-- 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 = 1, num-1 do
|
for k = 1, num-1 do
|
||||||
i = snow_tab[i]
|
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
|
||||||
@ -515,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
|
||||||
@ -576,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
|
||||||
|
212
src/nodes.lua
@ -8,7 +8,7 @@ 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,
|
||||||
@ -43,6 +43,12 @@ 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
|
||||||
@ -60,10 +66,10 @@ 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
|
||||||
|
|
||||||
|
|
||||||
-- Decorated Pine Leaves
|
-- Decorated Pine Leaves
|
||||||
@ -76,9 +82,11 @@ 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'}}
|
||||||
|
|
||||||
@ -123,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,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,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 = 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)
|
||||||
@ -262,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")
|
||||||
|
|
||||||
@ -272,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
|
||||||
|
|
||||||
@ -293,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)
|
||||||
|
|
||||||
@ -331,43 +343,38 @@ 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
|
||||||
|
|
||||||
|
local groups = minetest.registered_nodes["default:ice"].groups
|
||||||
|
groups["melt"] = 1
|
||||||
minetest.override_item("default:ice", {
|
minetest.override_item("default:ice", {
|
||||||
use_texture_alpha = true,
|
|
||||||
param2 = 0, --param2 is reserved for how much ice will freezeover.
|
|
||||||
sunlight_propagates = true, -- necessary for dirt_with_grass/snow/just dirt ABMs
|
|
||||||
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
|
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
|
||||||
minetest.override_item("default:snowblock", {
|
minetest.override_item("default:snowblock", {
|
||||||
-- LazyJ to make dirt below change to dirt_with_snow (see default, nodes.lua, dirt ABM)
|
|
||||||
liquidtype = "none",
|
liquidtype = "none",
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
sunlight_propagates = true,
|
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
|
|
||||||
-- dirt_with_frost which adds subtlety to the winterscape. ~ LazyJ, 2014_04_04
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
minetest.override_item("default:snow", {
|
minetest.override_item("default:snow", {
|
||||||
drop = {
|
drop = {
|
||||||
max_items = 2,
|
max_items = 2,
|
||||||
@ -377,13 +384,21 @@ minetest.override_item("default:snow", {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
leveled = 7,
|
leveled = 7,
|
||||||
|
paramtype2 = "leveled",
|
||||||
node_box = {
|
node_box = {
|
||||||
type = "leveled",
|
type = "leveled",
|
||||||
fixed = {
|
fixed = {-0.5, -0.5, -0.5, 0.5, -0.5, 0.5},
|
||||||
{-0.5, -0.5, -0.5, 0.5, -0.5, 0.5},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
groups = {cracky=3, crumbly=3, choppy=3, oddly_breakable_by_hand=3, falling_node=1, melts=2, float=1},
|
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,
|
sunlight_propagates = true,
|
||||||
walkable = true,
|
walkable = true,
|
||||||
node_placement_prediction = "",
|
node_placement_prediction = "",
|
||||||
@ -416,56 +431,71 @@ minetest.override_item("default:snow", {
|
|||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
--Manage snow levels.
|
--Manage snow levels.
|
||||||
on_place = function(itemstack, placer, pointed_thing)
|
on_place = function(itemstack, player, pt)
|
||||||
local under = pointed_thing.under
|
local oldnode_under = minetest.get_node_or_nil(pt.under)
|
||||||
local oldnode_under = minetest.get_node_or_nil(under)
|
if not oldnode_under then
|
||||||
local above = pointed_thing.above
|
return itemstack, false
|
||||||
|
|
||||||
if not oldnode_under
|
|
||||||
or not above then
|
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local olddef_under = ItemStack({name=oldnode_under.name}):get_definition()
|
local olddef_under = minetest.registered_nodes[oldnode_under.name]
|
||||||
olddef_under = olddef_under or minetest.nodedef_default
|
if not olddef_under then
|
||||||
|
return itemstack, false
|
||||||
|
end
|
||||||
|
|
||||||
local place_to
|
|
||||||
-- If node under is buildable_to, place into it instead (eg. snow)
|
-- If node under is buildable_to, place into it instead (eg. snow)
|
||||||
|
local pos, node
|
||||||
if olddef_under.buildable_to then
|
if olddef_under.buildable_to then
|
||||||
place_to = under
|
pos = pt.under
|
||||||
|
node = oldnode_under
|
||||||
else
|
else
|
||||||
-- Place above pointed node
|
pos = pt.above
|
||||||
place_to = above
|
node = minetest.get_node(pos)
|
||||||
|
local def = minetest.registered_nodes[node.name]
|
||||||
|
if not def
|
||||||
|
or not def.buildable_to then
|
||||||
|
return itemstack, false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local level = minetest.get_node_level(place_to)
|
-- nil player can place (for snowballs)
|
||||||
if level == 63 then
|
if player
|
||||||
minetest.set_node(place_to, {name="default:snowblock"})
|
and minetest.is_protected(pos, player:get_player_name()) then
|
||||||
else
|
return itemstack, false
|
||||||
minetest.set_node_level(place_to, level+7)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if minetest.get_node(place_to).name ~= "default:snow" then
|
if node.name ~= "default:snow" then
|
||||||
local itemstack, placed = minetest.item_place_node(itemstack, placer, pointed_thing)
|
if minetest.get_node{x=pos.x, y=pos.y-1, z=pos.z}.name ==
|
||||||
return itemstack, placed
|
"default:snow" then
|
||||||
|
-- grow the snow below (fixes levelled problem)
|
||||||
|
pos.y = pos.y - 1
|
||||||
|
else
|
||||||
|
-- place a snow
|
||||||
|
return minetest.item_place_node(itemstack, player, pt)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- grow the snow
|
||||||
|
local level = minetest.get_node_level(pos)
|
||||||
|
level = level + 7
|
||||||
|
if level < 64 then
|
||||||
|
minetest.set_node_level(pos, level)
|
||||||
|
else
|
||||||
|
-- place a snowblock and snow onto it if possible
|
||||||
|
local p = {x=pos.x, y=pos.y+1, z=pos.z}
|
||||||
|
local def = minetest.registered_nodes[minetest.get_node(p).name]
|
||||||
|
if not def
|
||||||
|
or not def.buildable_to then
|
||||||
|
return itemstack, false
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.set_node(pos, {name="default:snowblock"})
|
||||||
|
minetest.set_node(p, {name="default:snow"})
|
||||||
|
level = math.max(level - 64, 7)
|
||||||
|
minetest.set_node_level(p, level)
|
||||||
end
|
end
|
||||||
|
|
||||||
itemstack:take_item()
|
itemstack:take_item()
|
||||||
|
return itemstack, true
|
||||||
return itemstack
|
|
||||||
end,
|
end,
|
||||||
on_use = snow.shoot_snowball
|
on_use = snow.shoot_snowball
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- Do stairs files
|
|
||||||
|
|
||||||
local path = minetest.get_modpath"snow".."/src/"
|
|
||||||
|
|
||||||
dofile(path.."basic_stairs_slabs.lua")
|
|
||||||
|
|
||||||
if minetest.global_exists"stairsplus"
|
|
||||||
and minetest.get_modpath"moreblocks" then
|
|
||||||
dofile(path.."stairsplus.lua")
|
|
||||||
end
|
|
||||||
|
16
src/sled.lua
@ -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
|
||||||
|
|
||||||
|
@ -40,10 +40,10 @@ function snow.shoot_snowball(item, player)
|
|||||||
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
|
||||||
@ -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)
|
||||||
@ -129,22 +129,40 @@ 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,14 +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_luaentity().name
|
if v ~= self.object
|
||||||
|
and entity then
|
||||||
|
local entity_name = entity.name
|
||||||
if v:is_player()
|
if v:is_player()
|
||||||
or (entity_name ~= "snow:snowball_entity"
|
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
|
||||||
@ -192,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
|
||||||
@ -237,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
|
||||||
|
101
src/stairs.lua
Normal 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
|
@ -1,338 +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.settigetbool("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' MoreBlocks was found and stairsplus is available, well, 'then' go ahead with this next part:
|
|
||||||
|
|
||||||
|
|
||||||
--[[ 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,
|
|
||||||
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
|
|
||||||
|
|
||||||
-- 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
|
|
||||||
|
|
||||||
|
|
205
src/util.lua
@ -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
|
|
||||||
config = {}
|
|
||||||
for line in file:lines() 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
|
|
||||||
io.close(file)
|
|
||||||
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.settings: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)
|
|
||||||
|
Before Width: | Height: | Size: 643 B After Width: | Height: | Size: 643 B |
Before Width: | Height: | Size: 606 B After Width: | Height: | Size: 606 B |
BIN
textures/snowdrift_snowflake1.png
Normal file
After Width: | Height: | Size: 104 B |
BIN
textures/snowdrift_snowflake10.png
Normal file
After Width: | Height: | Size: 105 B |
BIN
textures/snowdrift_snowflake11.png
Normal file
After Width: | Height: | Size: 105 B |
BIN
textures/snowdrift_snowflake12.png
Normal file
After Width: | Height: | Size: 105 B |
BIN
textures/snowdrift_snowflake2.png
Normal file
After Width: | Height: | Size: 104 B |
BIN
textures/snowdrift_snowflake3.png
Normal file
After Width: | Height: | Size: 102 B |
BIN
textures/snowdrift_snowflake4.png
Normal file
After Width: | Height: | Size: 104 B |
BIN
textures/snowdrift_snowflake5.png
Normal file
After Width: | Height: | Size: 105 B |
BIN
textures/snowdrift_snowflake6.png
Normal file
After Width: | Height: | Size: 105 B |
BIN
textures/snowdrift_snowflake7.png
Normal file
After Width: | Height: | Size: 104 B |
BIN
textures/snowdrift_snowflake8.png
Normal file
After Width: | Height: | Size: 105 B |
BIN
textures/snowdrift_snowflake9.png
Normal file
After Width: | Height: | Size: 105 B |