Support for old definitions

This commit is contained in:
JoseDouglas26 2024-07-25 06:28:00 -03:00 committed by JoseDouglas26
parent 7d8851217f
commit 0eded0f2e7
2 changed files with 122 additions and 8 deletions

View File

@ -2,7 +2,7 @@
This API allows you to add fences and fence gates.
The recommended function is `mcl_fences.register_fence_and_fence_gate`.
## ` mcl_fences.register_fence = function(name, definitions)`
## ` mcl_fences.register_fence_def = function(name, definitions)`
Adds a fence with crafting recipe. A single node is created.
### Parameter
@ -25,7 +25,7 @@ The full itemstring of the new fence node.
Notes: Fences will always have the group `fence = 1`. They will always connect to solid nodes (group `solid = 1`).
## `mcl_fences.register_fence_gate = function(name, definitions)`
## `mcl_fences.register_fence_gate_def = function(name, definitions)`
Adds a fence gate with crafting recipe. This will create 2 nodes.
### Parameters
@ -57,7 +57,7 @@ This function returns 2 values, in the following order:
1. Itemstring of the closed fence gate
2. Itemstring of the open fence gate
## `mcl_fences.register_fence_and_fence_gate = function(name, commondefs, fencedefs, gatedefs)`
## `mcl_fences.register_fence_and_fence_gate_def = function(name, commondefs, fencedefs, gatedefs)`
Registers a fence and fence gate. This is basically a combination of the two functions above. This is the recommended way to add a fence / fence gate pair.
This will register 3 nodes in total with crafting recipes. (**_used in mclx_fences in the red brick nether fence and gate registration._**)
@ -80,3 +80,71 @@ This function returns 3 values, in this order:
2. Itemstring of the closed fence gate
3. Itemstring of the open fence gate
## Old definitions that are still supported
## ` mcl_fences.register_fence = function(id, fence_name, texture, groups, connects_to, sounds)`
Adds a fence without crafting recipe. A single node is created.
### Parameter
* `id`: A part of the itemstring of the node to create. The node name will be “`<modname>:<id>`
* `fence_name`: User-visible name (`description`)
* `texture`: Texture to apply on the fence (all sides)
* `groups`: Table of groups to which the fence belongs to
* `hardness`: Hardness (if unsure, pick the hardness of the material node)
* `blast_resistance`: Blast resistance (if unsure, pick the blast resistance of the material node)
* `connects_to`: Table of nodes (itemstrings) to which the fence will connect to. Use `group:<groupname>` for all members of the group `<groupname>`
* `sounds`: Node sound table for the fence
### Return value
The full itemstring of the new fence node.
Notes: Fences will always have the group `fence=1`. They will always connect to solid nodes (group `solid=1`).
## `mcl_fences.register_fence_gate = function(id, fence_gate_name, texture, groups, sounds, sound_open, sound_close, sound_gain_open, sound_gain_close)`
Adds a fence gate without crafting recipe. This will create 2 nodes.
### Parameters
* `id`: A part of the itemstring of the nodes to create. The node names will be “`<modname>:<id>_gate`” and “`<modname>:<id>_gate_open`
* `fence_gate_name`: User-visible name (`description`)
* `texture`: Texture to apply on the fence gate (all sides)
* `groups`: Table of groups to which the fence gate belongs to
* `hardness`: Hardness (if unsure, pick the hardness of the material node)
* `blast_resistance`: Blast resistance (if unsure, pick the blast resistance of the material node)
* `sounds`: Node sound table for the fence gate
* `sound_open`: Sound to play when opening fence gate (optional, default is wooden sound)
* `sound_close`: Sound to play when closing fence gate (optional, default is wooden sound)
* `sound_gain_open`: Gain (0.0-1.0) of the opening fence gate sound (optional, default is 0.3)
* `sound_gain_close`: Gain (0.0-1.0) of the closing fence gate sound (optional, default is 0.3)
Notes: Fence gates will always have the group `fence_gate=1`. The open fence gate will always have the group `not_in_creative_inventory=1`.
### Return value
This function returns 2 values, in the following order:
1. Itemstring of the closed fence gate
2. Itemstring of the open fence gate
## `mcl_fences.register_fence_and_fence_gate = function(id, fence_name, fence_gate_name, texture, groups, connects_to, sounds, sound_open, sound_close, sound_gain_open, sound_gain_close)`
Registers a fence and fence gate. This is basically a combination of the two functions above. This is the recommended way to add a fence / fence gate pair.
This will register 3 nodes in total without crafting recipes.
* `id`: A part of the itemstring of the nodes to create.
* `fence_name`: User-visible name (`description`) of the fence
* `fence_gate_name`: User-visible name (`description`) of the fence gate
* `texture`: Texture to apply on the fence and fence gate (all sides)
* `groups`: Table of groups to which the fence and fence gate belong to
* `hardness`: Hardness (if unsure, pick the hardness of the material node)
* `blast_resistance`: Blast resistance (if unsure, pick the blast resistance of the material node)
* `connects_to`: Table of nodes (itemstrings) to which the fence will connect to. Use `group:<groupname>` for all members of the group `<groupname>`
* `sounds`: Node sound table for the fence and the fence gate
* `sound_open`: Sound to play when opening fence gate (optional, default is wooden sound)
* `sound_close`: Sound to play when closing fence gate (optional, default is wooden sound)
* `sound_gain_open`: Gain (0.0-1.0) of the opening fence gate sound (optional, default is 0.3)
* `sound_gain_close`: Gain (0.0-1.0) of the closing fence gate sound (optional, default is 0.3)
### Return value
This function returns 3 values, in this order:
1. Itemstring of the fence
2. Itemstring of the closed fence gate
3. Itemstring of the open fence gate

View File

@ -186,7 +186,7 @@ local tpl_fence_gates_open = {
end
}
function mcl_fences.register_fence(name, definitions)
function mcl_fences.register_fence_def(name, definitions)
local fence_name = "mcl_fences:"..name
if not definitions.groups then
@ -226,7 +226,7 @@ function mcl_fences.register_fence(name, definitions)
return fence_name
end
function mcl_fences.register_fence_gate(name, definitions)
function mcl_fences.register_fence_gate_def(name, definitions)
local fence_gate_name = "mcl_fences:"..name.."_gate"
local fence_gate_name_open = fence_gate_name.."_open"
@ -281,11 +281,57 @@ function mcl_fences.register_fence_gate(name, definitions)
return fence_gate_name, fence_gate_name_open
end
function mcl_fences.register_fence_and_fence_gate(name, commondefs, fencedefs, gatedefs)
function mcl_fences.register_fence_and_fence_gate_def(name, commondefs, fencedefs, gatedefs)
local fence, gate, gate_open
fence = mcl_fences.register_fence(name, table.merge(commondefs, fencedefs))
gate, gate_open = mcl_fences.register_fence_gate(name, table.merge(commondefs, gatedefs))
fence = mcl_fences.register_fence_def(name, table.merge(commondefs, fencedefs))
gate, gate_open = mcl_fences.register_fence_gate_def(name, table.merge(commondefs, gatedefs))
return fence, gate, gate_open
end
-- Support for old definitions
function mcl_fences.register_fence(id, fence_name, texture, groups, hardness, blast_resistance, connects_to, sounds, burntime)
return mcl_fences.register_fence_def(id, {
description = fence_name,
tiles = { texture },
groups = groups,
_mcl_blast_resistance = blast_resistance,
_mcl_hardness = hardness,
connects_to = connects_to,
sounds = sounds,
_mcl_burntime = burntime
})
end
function mcl_fences.register_fence_gate(id, fence_gate_name, texture, groups, hardness, blast_resistance, sounds, sound_open, sound_close, sound_gain_open, sound_gain_close, burntime)
return mcl_fences.register_fence_gate_def(id, {
description = fence_gate_name,
tiles = { texture },
groups = groups,
_mcl_blast_resistance = blast_resistance,
_mcl_hardness = hardness,
sounds = sounds,
_mcl_burntime = burntime,
_mcl_fences_sounds = {
open = {
spec = sound_open,
gain = sound_gain_open
},
close = {
spec = sound_close,
gain = sound_gain_close
}
}
})
end
function mcl_fences.register_fence_and_fence_gate(id, fence_name, fence_gate_name, texture_fence, groups, hardness, blast_resistance, connects_to, sounds, sound_open, sound_close, sound_gain_open, sound_gain_close, texture_fence_gate)
if texture_fence_gate == nil then
texture_fence_gate = texture_fence
end
local fence_id = mcl_fences.register_fence(id, fence_name, texture_fence, groups, hardness, blast_resistance, connects_to, sounds)
local gate_id, open_gate_id = mcl_fences.register_fence_gate(id, fence_gate_name, texture_fence_gate, groups, hardness, blast_resistance, sounds, sound_open, sound_close, sound_gain_open, sound_gain_close)
return fence_id, gate_id, open_gate_id
end