1
0
Fork 0

unify codestyle [2]

This commit is contained in:
AFCMS 2021-05-25 13:18:12 +02:00
parent 9e074af07f
commit 49044ac15e
3 changed files with 35 additions and 15 deletions

View File

@ -46,6 +46,28 @@ Your commit names should be relatively descriptive, e.g. when saying "Fix #issue
Contributors will be credited in `CREDITS.md`. Contributors will be credited in `CREDITS.md`.
## Code Style
Each mod must provide `mod.conf`.
Each mod which add API functions should store functions inside a global table named like the mod.
Object oriented API shoud be avoided e.g.:`function mobs.register_mod(self)`
Functions should be defined in this way:
```
function mcl_xyz.stuff(param) end
```
Insteed of this way:
```
mcl_xyz.stuff = function(param) end
```
Indentation must be unified, more likely with tabs.
Time sensitive mods should make a local copy of most used API functions to improve performances.
```
local vector = vector
local get_node = minetest.get_node
```
## Features > 1.12 ## Features > 1.12
If you want to make a feature that was added in a Minecraft version later than 1.12, you should fork MineClone5 (mineclone5 branch in the repository) and add your changes to this. If you want to make a feature that was added in a Minecraft version later than 1.12, you should fork MineClone5 (mineclone5 branch in the repository) and add your changes to this.

View File

@ -13,7 +13,7 @@ minetest.log("info", "[mcl_moon] Moon phase offset of this world: "..phase_offse
mcl_moon = {} mcl_moon = {}
mcl_moon.MOON_PHASES = MOON_PHASES mcl_moon.MOON_PHASES = MOON_PHASES
mcl_moon.get_moon_phase = function() function mcl_moon.get_moon_phase()
local after_midday = 0 local after_midday = 0
-- Moon phase changes after midday -- Moon phase changes after midday
local tod = minetest.get_timeofday() local tod = minetest.get_timeofday()
@ -23,7 +23,7 @@ mcl_moon.get_moon_phase = function()
return (minetest.get_day_count() + phase_offset + after_midday) % MOON_PHASES return (minetest.get_day_count() + phase_offset + after_midday) % MOON_PHASES
end end
local get_moon_texture = function() local function get_moon_texture()
local phase = mcl_moon.get_moon_phase() local phase = mcl_moon.get_moon_phase()
local x = phase % MOON_PHASES_HALF local x = phase % MOON_PHASES_HALF
local y local y

View File

@ -20,7 +20,7 @@ mcl_weather.rain = {
init_done = false, init_done = false,
} }
mcl_weather.rain.sound_handler = function(player) function mcl_weather.rain.sound_handler(player)
return minetest.sound_play("weather_rain", { return minetest.sound_play("weather_rain", {
to_player = player:get_player_name(), to_player = player:get_player_name(),
loop = true, loop = true,
@ -28,7 +28,7 @@ mcl_weather.rain.sound_handler = function(player)
end end
-- set skybox based on time (uses skycolor api) -- set skybox based on time (uses skycolor api)
mcl_weather.rain.set_sky_box = function() function mcl_weather.rain.set_sky_box()
if mcl_weather.state == "rain" then if mcl_weather.state == "rain" then
mcl_weather.skycolor.add_layer( mcl_weather.skycolor.add_layer(
"weather-pack-rain-sky", "weather-pack-rain-sky",
@ -46,8 +46,7 @@ end
-- creating manually parctiles instead of particles spawner because of easier to control -- creating manually parctiles instead of particles spawner because of easier to control
-- spawn position. -- spawn position.
mcl_weather.rain.add_rain_particles = function(player) function mcl_weather.rain.add_rain_particles(player)
mcl_weather.rain.last_rp_count = 0 mcl_weather.rain.last_rp_count = 0
for i=mcl_weather.rain.particles_count, 1,-1 do for i=mcl_weather.rain.particles_count, 1,-1 do
local random_pos_x, random_pos_y, random_pos_z = mcl_weather.get_random_pos_by_player_look_dir(player) local random_pos_x, random_pos_y, random_pos_z = mcl_weather.get_random_pos_by_player_look_dir(player)
@ -70,7 +69,7 @@ mcl_weather.rain.add_rain_particles = function(player)
end end
-- Simple random texture getter -- Simple random texture getter
mcl_weather.rain.get_texture = function() function mcl_weather.rain.get_texture()
local texture_name local texture_name
local random_number = math.random() local random_number = math.random()
if random_number > 0.33 then if random_number > 0.33 then
@ -85,7 +84,7 @@ end
-- register player for rain weather. -- register player for rain weather.
-- basically needs for origin sky reference and rain sound controls. -- basically needs for origin sky reference and rain sound controls.
mcl_weather.rain.add_player = function(player) function mcl_weather.rain.add_player(player)
if mcl_weather.players[player:get_player_name()] == nil then if mcl_weather.players[player:get_player_name()] == nil then
local player_meta = {} local player_meta = {}
player_meta.origin_sky = {player:get_sky()} player_meta.origin_sky = {player:get_sky()}
@ -95,7 +94,7 @@ end
-- remove player from player list effected by rain. -- remove player from player list effected by rain.
-- be sure to remove sound before removing player otherwise soundhandler reference will be lost. -- be sure to remove sound before removing player otherwise soundhandler reference will be lost.
mcl_weather.rain.remove_player = function(player) function mcl_weather.rain.remove_player(player)
local player_meta = mcl_weather.players[player:get_player_name()] local player_meta = mcl_weather.players[player:get_player_name()]
if player_meta ~= nil and player_meta.origin_sky ~= nil then if player_meta ~= nil and player_meta.origin_sky ~= nil then
player:set_clouds({color="#FFF0F0E5"}) player:set_clouds({color="#FFF0F0E5"})
@ -119,7 +118,7 @@ end)
-- adds and removes rain sound depending how much rain particles around player currently exist. -- adds and removes rain sound depending how much rain particles around player currently exist.
-- have few seconds delay before each check to avoid on/off sound too often -- have few seconds delay before each check to avoid on/off sound too often
-- when player stay on 'edge' where sound should play and stop depending from random raindrop appearance. -- when player stay on 'edge' where sound should play and stop depending from random raindrop appearance.
mcl_weather.rain.update_sound = function(player) function mcl_weather.rain.update_sound(player)
local player_meta = mcl_weather.players[player:get_player_name()] local player_meta = mcl_weather.players[player:get_player_name()]
if player_meta ~= nil then if player_meta ~= nil then
if player_meta.sound_updated ~= nil and player_meta.sound_updated + 5 > minetest.get_gametime() then if player_meta.sound_updated ~= nil and player_meta.sound_updated + 5 > minetest.get_gametime() then
@ -140,7 +139,7 @@ mcl_weather.rain.update_sound = function(player)
end end
-- rain sound removed from player. -- rain sound removed from player.
mcl_weather.rain.remove_sound = function(player) function mcl_weather.rain.remove_sound(player)
local player_meta = mcl_weather.players[player:get_player_name()] local player_meta = mcl_weather.players[player:get_player_name()]
if player_meta ~= nil and player_meta.sound_handler ~= nil then if player_meta ~= nil and player_meta.sound_handler ~= nil then
minetest.sound_fade(player_meta.sound_handler, -0.5, 0.0) minetest.sound_fade(player_meta.sound_handler, -0.5, 0.0)
@ -150,7 +149,7 @@ mcl_weather.rain.remove_sound = function(player)
end end
-- callback function for removing rain -- callback function for removing rain
mcl_weather.rain.clear = function() function mcl_weather.rain.clear()
mcl_weather.rain.raining = false mcl_weather.rain.raining = false
mcl_weather.rain.sky_last_update = -1 mcl_weather.rain.sky_last_update = -1
mcl_weather.rain.init_done = false mcl_weather.rain.init_done = false
@ -166,11 +165,10 @@ minetest.register_globalstep(function(dtime)
if mcl_weather.state ~= "rain" then if mcl_weather.state ~= "rain" then
return false return false
end end
mcl_weather.rain.make_weather() mcl_weather.rain.make_weather()
end) end)
mcl_weather.rain.make_weather = function() function mcl_weather.rain.make_weather()
if mcl_weather.rain.init_done == false then if mcl_weather.rain.init_done == false then
mcl_weather.rain.raining = true mcl_weather.rain.raining = true
mcl_weather.rain.set_sky_box() mcl_weather.rain.set_sky_box()
@ -190,7 +188,7 @@ mcl_weather.rain.make_weather = function()
end end
-- Switch the number of raindrops: "thunder" for many raindrops, otherwise for normal raindrops -- Switch the number of raindrops: "thunder" for many raindrops, otherwise for normal raindrops
mcl_weather.rain.set_particles_mode = function(mode) function mcl_weather.rain.set_particles_mode(mode)
if mode == "thunder" then if mode == "thunder" then
mcl_weather.rain.particles_count = PARTICLES_COUNT_THUNDER mcl_weather.rain.particles_count = PARTICLES_COUNT_THUNDER
else else