From c3cf92baa66a1b888cca6b5128a0bf2181784db9 Mon Sep 17 00:00:00 2001 From: Michieal Date: Wed, 15 Feb 2023 02:09:21 -0500 Subject: [PATCH] Created mcl_oxidization API, and converted mcl_copper to use it. Documented API. --- mods/CORE/mcl_oxidization/API.md | 46 +++++++++++++++++++++++++++++ mods/CORE/mcl_oxidization/init.lua | 20 +++++++++++++ mods/CORE/mcl_oxidization/mod.conf | 4 +++ mods/ITEMS/mcl_copper/functions.lua | 12 -------- mods/ITEMS/mcl_copper/mod.conf | 2 +- 5 files changed, 71 insertions(+), 13 deletions(-) create mode 100644 mods/CORE/mcl_oxidization/API.md create mode 100644 mods/CORE/mcl_oxidization/init.lua create mode 100644 mods/CORE/mcl_oxidization/mod.conf diff --git a/mods/CORE/mcl_oxidization/API.md b/mods/CORE/mcl_oxidization/API.md new file mode 100644 index 000000000..e5c70f36b --- /dev/null +++ b/mods/CORE/mcl_oxidization/API.md @@ -0,0 +1,46 @@ +# Mineclone Oxidization API +This document explains the API of this mod. + +### `register_oxidation_abm(abm_name, node_name)` +Registers the ABM for the oxidization of nodes. It expects that the variable +`_mcl_oxidized_variant` be set with the node name of the oxidized version. + +#### Parameters: +`abm_name`: A unique name for the abm to register. + +`node_name`: the name of the node to check, and to oxidize. + +#### Usage: +To use this API, add `_mcl_oxidized_variant = my_oxidized_node_name,` to the node +definition of the desired node, and then call +`register_oxidation_abm(my_oxidizable_node_abm, my_oxidizable_node)` in your code. +This abm will swap out the nodes with the more oxidized version of the node, one +stage at a time. + +#### Example of Usage: +From mcl_copper: +```lua +local block_oxidation = { + { "", "_exposed" }, + { "_cut", "_exposed_cut" }, + { "_exposed", "_weathered" }, + { "_exposed_cut", "_weathered_cut" }, + { "_weathered", "_oxidized" }, + { "_weathered_cut", "_oxidized_cut" } +} + +for _, b in pairs(block_oxidation) do + register_oxidation_abm("Copper oxidation", "mcl_copper:block" .. b[1], "mcl_copper:block" .. b[2]) +end +``` + +### Oxidization Removal +Make sure that the Oxidized Node has this in its definition: + +`_mcl_stripped_variant = my_less_oxidized_node,` + +And axes in mineclone will scrape the oxidization level down, usually by one stage. +An example of usage: `_mcl_stripped_variant = "mcl_copper:block",` + +Implementation of other tools for scraping does not yet exist, but may in the future. + diff --git a/mods/CORE/mcl_oxidization/init.lua b/mods/CORE/mcl_oxidization/init.lua new file mode 100644 index 000000000..cd0094655 --- /dev/null +++ b/mods/CORE/mcl_oxidization/init.lua @@ -0,0 +1,20 @@ +--- +--- Generated by EmmyLua(https://github.com/EmmyLua) +--- Created by michieal. +--- DateTime: 2/15/23 1:11 AM +--- + +function register_oxidation_abm(abm_name, node_name, oxidized_variant) + minetest.register_abm({ + label = abm_name, + nodenames = { node_name }, + interval = 500, + chance = 3, + action = function(pos, node) + local def = minetest.registered_nodes[node_name] + if def and def._mcl_oxidized_variant then + minetest.swap_node(pos, { name = oxidized_variant, param2 = node.param2 }) + end + end, + }) +end diff --git a/mods/CORE/mcl_oxidization/mod.conf b/mods/CORE/mcl_oxidization/mod.conf new file mode 100644 index 000000000..c35885ddb --- /dev/null +++ b/mods/CORE/mcl_oxidization/mod.conf @@ -0,0 +1,4 @@ +title = Oxidization API for Mineclone 2 +name = mcl_oxidization +author = Michieal, NO11 +description = Turns NO11's oxidization function into an API. diff --git a/mods/ITEMS/mcl_copper/functions.lua b/mods/ITEMS/mcl_copper/functions.lua index db756e425..8410526ac 100644 --- a/mods/ITEMS/mcl_copper/functions.lua +++ b/mods/ITEMS/mcl_copper/functions.lua @@ -1,17 +1,5 @@ --local deepslate_mod = minetest.get_modpath("mcl_deepslate") -local function register_oxidation_abm(abm_name, node_name, oxidized_variant) - minetest.register_abm({ - label = abm_name, - nodenames = { node_name }, - interval = 500, - chance = 3, - action = function(pos, node) - minetest.swap_node(pos, { name = oxidized_variant, param2 = node.param2 }) - end, - }) -end - --[[ local stairs = { {"stair", "exposed", "_inner", "cut_inner"}, diff --git a/mods/ITEMS/mcl_copper/mod.conf b/mods/ITEMS/mcl_copper/mod.conf index 8cf5fd579..ec849bcc8 100644 --- a/mods/ITEMS/mcl_copper/mod.conf +++ b/mods/ITEMS/mcl_copper/mod.conf @@ -1,4 +1,4 @@ name = mcl_copper author = NO11 -depends = mcl_core, mcl_sounds, mcl_stairs, mcl_util +depends = mcl_core, mcl_sounds, mcl_stairs, mcl_util, mcl_oxidization description = Adds Copper Ore, blocks and items.