New features (#1)

* add trample counting via node metadata

* flattenable cotton
This commit is contained in:
FaceDeer 2019-12-27 18:21:18 -06:00 committed by GitHub
parent 3574eef7fc
commit 6251601649
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 108 additions and 27 deletions

View File

@ -13,16 +13,21 @@ trample_def:
{
trampled_node_name = , -- If this is not defined it defaults to the trampleable node name with "_trampled" appended.
trampled_node_def_override = {}, -- If trampled_node_name doesn't exist a new node will be registered based on the definition of trampleable_node_name. Any properties in this table will be used to override properties ignored if trampled_node_name is a node that already exists.
probability = 1, -- chance that stepping on this node will cause it to turn into the trampled version
probability = 1, -- chance that stepping on this node will cause it to turn into the trampled version (0.0 to 1.0)
trample_count = 1, -- The number of times this node needs to be stepped on (and pass the probability check) to transition to the trampled state
randomize_trampled_param2 = nil, -- if true, sets param2 of trampled node to math.random(0,3)
erodes = true, -- sets the trampled node up to erode back into the non-trampled verison. ignored if trampled_node_name is a node that already exists, since that may already have an erosion target established
add_footprint_overlay = true, -- Applies the footprint texture over the +Y tile of the trampleable node. ignored if trampled_node_name is a node that already exists
footprint_overlay_texture = , -- defaults to "trail_footprint.png"
footprint_overlay_texture = "trail_footprint.png",
footprint_opacity = 64, -- defaults to 64 (0 is transparent, 255 is fully opaque)
hard_pack_node_name = nil, -- If the trampled node is walked on again this is the node that it can get trampled into further. ignored if trampled_node_name is a node that already exists, since it's expected this has already been established
hard_pack_probability = 0.1, -- The probability that walking on a trampled node will turn it into the hard-packed node. ignored if trampled_node_name is a node that already exists
hard_pack_probability = 0.1, -- The probability that walking on a trampled node will turn it into the hard-packed node (0.0 to 1.0). ignored if trampled_node_name is a node that already exists
hard_pack_count = 1, -- The number of times the trampled node needs to be stepped on (and pass the probability check) to turn to the hard packed state
}
Note that all of the parameters in trample_def have default values, so if you want you can just pass in nil and the trail mod will create a footstep-marked version of the node and set it all up for you with no further information needed. "trail.register_trample_node("modname:dirt")" will work.
If you've defined a hard_pack_node and want to have it able to erode back to base soil, you can use this callback to manually add it to the erosion system:
trail.register_erosion(source_node_name, destination_node_name)

104
init.lua
View File

@ -4,14 +4,15 @@ trail = {}
-- Parameters
local FOO = true -- Enable footprints.
local FUNCYC = 0.2 -- Function cycle in seconds.
local GLOBALSTEP_INTERVAL = 0.2 -- Function cycle in seconds.
local TRACHA = minetest.settings:get("trail_hardpack_chance") or 0.1 -- Chance walked dirt/grass is worn and compacted to trail:trail.
local ICECHA = minetest.settings:get("trail_ice_chance") or 0.05 -- Chance walked snowblock is compacted to ice.
local HARDPACK_PROBABILITY = minetest.settings:get("trail_hardpack_probability") or 0.5 -- Chance walked dirt/grass is worn and compacted to trail:trail.
local HARDPACK_COUNT = minetest.settings:get("trail_hardpack_count") or 5 -- Number of times the above chance needs to be passed for soil to compact.
local ICE_PROBABILITY = minetest.settings:get("trail_ice_probability") or 0.05 -- Chance walked snowblock is compacted to ice.
local EROSION = minetest.settings:get_bool("trail_erosion", true) -- Enable footprint erosion.
local TRAIL_EROSION = minetest.settings:get_bool("trail_trail_erosion", true) -- Allow hard-packed soil to erode back to dirt
local EROINT = minetest.settings:get("trail_erosion_interval") or 16 -- Erosion interval.
local EROCHA = minetest.settings:get("trail_erosion_chance") or 128 -- Erosion 1/x chance.
local EROSION_INTERVAL = minetest.settings:get("trail_erosion_interval") or 16 -- Erosion interval.
local EROSION_CHANCE = minetest.settings:get("trail_erosion_chance") or 128 -- Erosion 1/x chance.
-- Utility
@ -42,6 +43,8 @@ local trails = {}
local erosion = {}
trail.register_trample_node = function(trampleable_node_name, trample_def)
trample_def = trample_def or {} -- Everything has defaults, so if no trample_def is passed in just use an empty table.
if trails[trampleable_node_name] then
minetest.log("error", "[trail] Attempted to call trail.register_trample_node to register trampleable node "
.. trampleable_node_name ..", which has already been registered as trampleable.")
@ -104,12 +107,14 @@ trail.register_trample_node = function(trampleable_node_name, trample_def)
local hard_pack_node_name = trample_def.hard_pack_node_name
if hard_pack_node_name then
local hard_pack_probability = trample_def.hard_pack_probability or 0.1
trails[trampled_node_name] = {name=hard_pack_node_name, probability=hard_pack_probability}
local hard_pack_count = trample_def.hard_pack_count or 1
trails[trampled_node_name] = {name=hard_pack_node_name, probability=hard_pack_probability, count = hard_pack_count}
end
end
local probability = trample_def.probability or 1
trails[trampleable_node_name] = {name=trampled_node_name, probability=probability, randomize_trampled_param2 = trample_def.randomize_trampled_param2,}
local trample_count = trample_def.trample_count or 1
trails[trampleable_node_name] = {name=trampled_node_name, probability=probability, randomize_trampled_param2 = trample_def.randomize_trampled_param2, count = trample_count}
end
trail.register_erosion = function(source_node_name, destination_node_name)
@ -164,28 +169,31 @@ if default_modpath then
trampled_node_def_override = {description = "Dirt with Footprint",},
hard_pack_node_name = "trail:trail",
footprint_opacity = 96,
hard_pack_probability = TRACHA,
hard_pack_probability = HARDPACK_PROBABILITY,
})
trail.register_trample_node("default:dirt_with_grass", {
trampled_node_name = "trail:dirt_with_grass",
trampled_node_def_override = {description = "Dirt with Grass and Footprint",},
hard_pack_node_name = "trail:trail",
hard_pack_probability = TRACHA,
hard_pack_probability = HARDPACK_PROBABILITY,
hard_pack_count = HARDPACK_COUNT,
})
trail.register_trample_node("default:dirt_with_dry_grass", {
trampled_node_name = "trail:dirt_with_dry_grass",
trampled_node_def_override = {description = "Dirt with Dry Grass and Footprint",},
hard_pack_node_name = "trail:trail",
hard_pack_probability = TRACHA,
hard_pack_probability = HARDPACK_PROBABILITY,
hard_pack_count = HARDPACK_COUNT,
})
trail.register_trample_node("default:dirt_with_snow", {
trampled_node_name = "trail:dirt_with_snow",
trampled_node_def_override = {description = "Dirt with Snow and Footprint",},
hard_pack_node_name = "trail:trail",
hard_pack_probability = TRACHA,
hard_pack_probability = HARDPACK_PROBABILITY,
hard_pack_count = HARDPACK_COUNT,
})
trail.register_trample_node("default:dirt_with_rainforest_litter", {
@ -193,7 +201,8 @@ if default_modpath then
trampled_node_def_override = {description = "Dirt with Rainforest Litter and Footprint",},
hard_pack_node_name = "trail:trail",
footprint_opacity = 96,
hard_pack_probability = TRACHA,
hard_pack_probability = HARDPACK_PROBABILITY,
hard_pack_count = HARDPACK_COUNT,
})
trail.register_trample_node("default:dirt_with_coniferous_litter", {
@ -201,7 +210,8 @@ if default_modpath then
trampled_node_def_override = {description = "Dirt with Coniferous Litter and Footprint",},
hard_pack_node_name = "trail:trail",
footprint_opacity = 128,
hard_pack_probability = TRACHA,
hard_pack_probability = HARDPACK_PROBABILITY,
hard_pack_count = HARDPACK_COUNT,
})
-- Default sand
@ -233,7 +243,7 @@ if default_modpath then
trampled_node_name = "trail:snowblock",
trampled_node_def_override = {description = "Snow Block with Footprint",},
hard_pack_node_name = "default:ice",
hard_pack_probability = ICECHA,
hard_pack_probability = ICE_PROBABILITY,
})
trail.register_trample_node("default:snow", {
@ -283,6 +293,43 @@ if minetest.get_modpath("farming") then
trampled_node_name = "trail:wheat",
randomize_trampled_param2 = true,
})
minetest.register_node("trail:cotton", {
description = "Flattened Cotton",
tiles = {"trail_flat_cotton.png"},
inventory_image = "trail_flat_cotton.png",
drawtype = "nodebox",
paramtype = "light",
paramtype2 = "facedir",
buildable_to = true,
node_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.5, 0.5, -3 / 8, 0.5}
},
},
groups = {snappy = 3, flammable = 2, attached_node = 1},
drop = "",
sounds = sounds,
})
trail.register_trample_node("farming:cotton_5", {
trampled_node_name = "trail:cotton",
randomize_trampled_param2 = true,
})
trail.register_trample_node("farming:cotton_6", {
trampled_node_name = "trail:cotton",
randomize_trampled_param2 = true,
})
trail.register_trample_node("farming:cotton_7", {
trampled_node_name = "trail:cotton",
randomize_trampled_param2 = true,
})
trail.register_trample_node("farming:cotton_8", {
trampled_node_name = "trail:cotton",
randomize_trampled_param2 = true,
})
end
-- Globalstep function
@ -297,11 +344,26 @@ if FOO then
return 0
end
local test_trample_count = function(trail_def, pos)
local target_count = trail_def.count
if target_count <= 1 then
return true
end
local meta = minetest.get_meta(pos)
local trampled_count = meta:get_int("trail_trample_count")
trampled_count = trampled_count + 1
if trampled_count >= target_count then
return true
end
meta:set_int("trail_trample_count", trampled_count)
return false
end
local math_floor = math.floor
minetest.register_globalstep(function(dtime)
timer = timer + dtime
if timer > FUNCYC then
if timer > GLOBALSTEP_INTERVAL then
timer = 0
for _, player in ipairs(minetest.get_connected_players()) do
local pos = player:getpos()
@ -339,7 +401,9 @@ if FOO then
y = math_floor(pos_y + 0.5),
z = pos_z_plus_half
}
minetest.set_node(p_snowpl, {name = trail_def.name, param2 = get_param2(trail_def)})
if test_trample_count(trail_def, p_snowpl) then
minetest.set_node(p_snowpl, {name = trail_def.name, param2 = get_param2(trail_def)})
end
end
else
local p_ground = {
@ -355,7 +419,9 @@ if FOO then
y = math_floor(pos_y - 0.5),
z =pos_z_plus_half
}
minetest.set_node(p_groundpl, {name = trail_def.name, param2 = get_param2(trail_def)})
if test_trample_count(trail_def, p_groundpl) then
minetest.set_node(p_groundpl, {name = trail_def.name, param2 = get_param2(trail_def)})
end
end
end
end
@ -371,8 +437,8 @@ end
if EROSION then
minetest.register_abm({
nodenames = {"group:trail_erodes"},
interval = EROINT,
chance = EROCHA,
interval = EROSION_INTERVAL,
chance = EROSION_CHANCE,
catch_up = true,
action = function(pos, node, _, _)
local nodename = node.name

View File

@ -26,10 +26,12 @@ https://opensource.org/licenses/MIT
License of media (textures)
trail_flat_wheat.png
trail_flat_wheat.png by paramat
trail_footprint.png (from https://github.com/minetest/minetest_game/commit/c7b9e734ffd815e9b86b1fcceba2293e3067785e by paramat)
trail_trailside.png
trail_trailtop.png
trail_trailside.png by paramat
trail_trailtop.png by paramat
trail_flat_cotton.png by FaceDeer (C) 2019
---------------------------
Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)

View File

@ -3,5 +3,13 @@ trail_erosion (Erode footsteps back to original soil type) bool true
trail_trail_erosion (Erode hard-packed trails back to dirt) bool true
trail_erosion_interval (Erosion ABM interval) int 16
trail_erosion_chance (Erosion ABM 1/x chance) int 128
trail_hardpack_chance (Chance footprints in dirt turn to hardpacked soil) float 0.1
trail_ice_chance (Chance footprints in snow turn to ice) float 0.05
#This setting works in combination with trail_hardpack_count. It gives the
#probability that a player stepping on a footprint will increment the hardpack
#counter. So by default, every time you step on a footprint there's a 1/2
#chance the counter increments for that node.
trail_hardpack_probability (Probability footprints in dirt turn to hardpacked soil) float 0.5
#This setting works in combination with trail_hardpack_probability. By default,
#once a footprint has been stepped on enough to increment its counter 5 times
#it'll turn the soil hard-packed.
trail_hardpack_count (Number of times the hardpack check needs to pass) int 3
trail_ice_probability (Chance footprints in snow turn to ice) float 0.05

Binary file not shown.

After

Width:  |  Height:  |  Size: 621 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 196 B

After

Width:  |  Height:  |  Size: 189 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 483 B

After

Width:  |  Height:  |  Size: 461 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 276 B

After

Width:  |  Height:  |  Size: 272 B