develop #35

Merged
milan merged 16 commits from develop into master 2021-07-24 12:49:35 +02:00
40 changed files with 1205 additions and 134 deletions
Showing only changes of commit d412c25a61 - Show all commits

View file

@ -16,7 +16,7 @@ function advtrains.register_platform(modprefix, preset)
description = attrans("@1 Platform (low)", desc), description = attrans("@1 Platform (low)", desc),
tiles = {btex.."^advtrains_platform.png", btex, btex, btex, btex, btex}, tiles = {btex.."^advtrains_platform.png", btex, btex, btex, btex, btex},
groups = {cracky = 1, not_blocking_trains = 1, platform=1}, groups = {cracky = 1, not_blocking_trains = 1, platform=1},
sounds = default.node_sound_stone_defaults(), sounds = ndef.sounds,
drawtype = "nodebox", drawtype = "nodebox",
node_box = { node_box = {
type = "fixed", type = "fixed",
@ -33,7 +33,7 @@ function advtrains.register_platform(modprefix, preset)
description = attrans("@1 Platform (high)", desc), description = attrans("@1 Platform (high)", desc),
tiles = {btex.."^advtrains_platform.png", btex, btex, btex, btex, btex}, tiles = {btex.."^advtrains_platform.png", btex, btex, btex, btex, btex},
groups = {cracky = 1, not_blocking_trains = 1, platform=2}, groups = {cracky = 1, not_blocking_trains = 1, platform=2},
sounds = default.node_sound_stone_defaults(), sounds = ndef.sounds,
drawtype = "nodebox", drawtype = "nodebox",
node_box = { node_box = {
type = "fixed", type = "fixed",
@ -58,7 +58,7 @@ function advtrains.register_platform(modprefix, preset)
minetest.register_node(modprefix..":platform_45_"..nodename, { minetest.register_node(modprefix..":platform_45_"..nodename, {
description = attrans("@1 Platform (45 degree)", desc), description = attrans("@1 Platform (45 degree)", desc),
groups = {cracky = 1, not_blocking_trains = 1, platform=2}, groups = {cracky = 1, not_blocking_trains = 1, platform=2},
sounds = default.node_sound_stone_defaults(), sounds = ndef.sounds,
drawtype = "mesh", drawtype = "mesh",
mesh = "advtrains_platform_diag.b3d", mesh = "advtrains_platform_diag.b3d",
selection_box = diagonalbox, selection_box = diagonalbox,
@ -80,7 +80,7 @@ function advtrains.register_platform(modprefix, preset)
minetest.register_node(modprefix..":platform_45_low_"..nodename, { minetest.register_node(modprefix..":platform_45_low_"..nodename, {
description = attrans("@1 Platform (low, 45 degree)", desc), description = attrans("@1 Platform (low, 45 degree)", desc),
groups = {cracky = 1, not_blocking_trains = 1, platform=2}, groups = {cracky = 1, not_blocking_trains = 1, platform=2},
sounds = default.node_sound_stone_defaults(), sounds = ndef.sounds,
drawtype = "mesh", drawtype = "mesh",
mesh = "advtrains_platform_diag_low.b3d", mesh = "advtrains_platform_diag_low.b3d",
selection_box = diagonalbox_low, selection_box = diagonalbox_low,

View file

@ -41,7 +41,6 @@ minetest.register_node("advtrains_interlocking:ds_danger", {
advtrains_signal = 2, advtrains_signal = 2,
save_in_at_nodedb = 1, save_in_at_nodedb = 1,
}, },
sounds = default.node_sound_stone_defaults(),
advtrains = { advtrains = {
set_aspect = setaspect, set_aspect = setaspect,
supported_aspects = suppasp, supported_aspects = suppasp,
@ -61,7 +60,6 @@ minetest.register_node("advtrains_interlocking:ds_free", {
advtrains_signal = 2, advtrains_signal = 2,
save_in_at_nodedb = 1, save_in_at_nodedb = 1,
}, },
sounds = default.node_sound_stone_defaults(),
advtrains = { advtrains = {
set_aspect = setaspect, set_aspect = setaspect,
supported_aspects = suppasp, supported_aspects = suppasp,
@ -83,7 +81,6 @@ minetest.register_node("advtrains_interlocking:ds_slow", {
advtrains_signal = 2, advtrains_signal = 2,
save_in_at_nodedb = 1, save_in_at_nodedb = 1,
}, },
sounds = default.node_sound_stone_defaults(),
advtrains = { advtrains = {
set_aspect = setaspect, set_aspect = setaspect,
supported_aspects = suppasp, supported_aspects = suppasp,

View file

@ -105,7 +105,6 @@ for _, rtab in ipairs({
}, },
drop = "advtrains_signals_ks:hs_danger_0", drop = "advtrains_signals_ks:hs_danger_0",
inventory_image = "advtrains_signals_ks_hs_inv.png", inventory_image = "advtrains_signals_ks_hs_inv.png",
sounds = default.node_sound_stone_defaults(),
advtrains = { advtrains = {
set_aspect = setaspectf(rot), set_aspect = setaspectf(rot),
supported_aspects = suppasp, supported_aspects = suppasp,
@ -151,7 +150,6 @@ for _, rtab in ipairs({
}, },
drop = "advtrains_signals_ks:ra_danger_0", drop = "advtrains_signals_ks:ra_danger_0",
inventory_image = "advtrains_signals_ks_ra_inv.png", inventory_image = "advtrains_signals_ks_ra_inv.png",
sounds = default.node_sound_stone_defaults(),
advtrains = { advtrains = {
set_aspect = setaspectf_ra(rot), set_aspect = setaspectf_ra(rot),
supported_aspects = suppasp_ra, supported_aspects = suppasp_ra,
@ -203,7 +201,6 @@ for _, rtab in ipairs({
}, },
drop = "advtrains_signals_ks:sign_8_0", drop = "advtrains_signals_ks:sign_8_0",
inventory_image = "advtrains_signals_ks_sign_8.png", inventory_image = "advtrains_signals_ks_sign_8.png",
sounds = default.node_sound_stone_defaults(),
advtrains = { advtrains = {
-- This is a static signal! No set_aspect -- This is a static signal! No set_aspect
get_aspect = function(pos, node) get_aspect = function(pos, node)
@ -239,7 +236,6 @@ for _, rtab in ipairs({
not_in_creative_inventory = (rtab.ici) and 0 or 1, not_in_creative_inventory = (rtab.ici) and 0 or 1,
}, },
drop = "advtrains_signals_ks:mast_mast_0", drop = "advtrains_signals_ks:mast_mast_0",
sounds = default.node_sound_stone_defaults(),
}) })
advtrains.trackplacer.add_worked("advtrains_signals_ks:mast","mast", "_"..rot) advtrains.trackplacer.add_worked("advtrains_signals_ks:mast","mast", "_"..rot)
end end

View file

@ -0,0 +1,120 @@
# serialize_lib API
## Serialization Library (serialize.lua)
### config table
Serialization functions accept a config table. Currently only one configuration option is defined.
config = {
skip_empty_tables = false
-- used for write_to_fd/write_to_file
-- if true, does not store empty tables
-- On next read, keys that mapped to empty tables resolve to nil
}
If you want to use all-default config options, you can pass `nil` as the config parameter.
### Serialization limits
* Only strings, booleans, numbers and tables can be serialized, no functions or userdata
* serialize_lib requires that no reference loops are present in the table to be serialized. Currently, when passing a table that has a reference loop, serialize_lib will produce a stack overflow.
### Functions
All of these functions call `error(<message>)` if an error occurs. Errors can be caught with `pcall()`.
#### write_to_fd(root_table, file, config)
Writes the contents of `root_table` to the file from the file handle given by `file`, and closes the file descriptor afterwards.
#### write_to_file(root_table, filename, config)
First, opens `filename` for write. Then, writes the contents of `root_table` to the file.
#### read_from_fd(file)
Reads the file from the file handle given by `file`, and closes the file descriptor afterwards. Returns the deserialized table.
#### read_from_file(filename)
First, opens `filename` for read. Then, reads the file and returns the deserialized table.
### External Lua Module
serialize.lua can be loaded as a standard Lua module even outside Minetest, like this:
local serialize = require("serialize")
## General API
### Minetest wrappers for serialization functions
Serialize_lib wraps write_to_file and read_from_file into 2 functions that do not throw errors but instead log the fact to the server log and have an appropriate return value:
#### serialize_lib.write_table_to_file(root_table, filename)
Serializes `root_table` into `filename`. On success, returns true. On failure, logs the error, then returns false and the error message.
#### serialize_lib.read_table_from_file(filename)
Deserializes the given file. On success, returns the deserialized table. On failure, logs the error, then returns false and the error message.
## Atomic API
serialize_lib provides functions for atomic saving. This means that if the process is interrupted during writing the save file, it is ensured that no save data gets corrupted and that instead the old state is read.
The atomic system is flexible, and can be used not only to save serialized Lua tables but arbitrary file formats by means of a callback function. This callback function gets passed a file descriptor to operate on.
### Concept
The plain scheme just overwrites the file in place. This however poses problems when we are interrupted right within the write, so we have incomplete data. So, the following scheme is applied:
Unix:
1. writes to `filename.new`
2. moves `filename.new` to `filename`, clobbering previous file
Windows:
1. writes to `filename.new`
2. delete `filename`
3. moves `filename.new` to `filename`
We count a new version of the state as "committed" after stage 2.
During loading, we apply the following order of precedence:
1. `filename`
2. `filename.new` (windows only, in case we were interrupted just before 3. when saving)
### Functions
All of these functions return either true on success or nil, error on error.
#### serialize_lib.load_atomic(filename, callback)
Load a saved state.
If 'callback' is nil: reads serialized table. Returns the read table, or nil,err on error.
If 'callback' is a function (signature `func(file_handle)` ): Counterpart to save_atomic with function argument. Opens the file and calls callback on it. If the callback function throws an error, and strict loading is enabled, that error is propagated. The callback's first return value is returned by load_atomic.
#### serialize_lib.save_atomic(data, filename, callback, config)
Save a file atomically.
'data' is the data to be saved (when a callback is used, this can be nil)
If 'callback' is nil: 'data' must be a table, and is serialized into the file
If 'callback' is a function (signature `func(data, file_handle)` ): Opens the file and calls callback on it. The 'data' argument is the data passed to save_atomic(). If the callback function throws an error, and strict loading is enabled, that error is propagated. The callback's first return value is returned by load_atomic().
Important: the callback must close the file in all cases!
#### serialize_lib.save_atomic_multiple(parts_table, filename_prefix, callbacks_table, config)
Saves multiple files synchronously. First writes all data to all `filename`.new files, then moves all files in quick succession to avoid inconsistent backups. parts_table is a table where the keys are used as part of the filename and the values are the respective data written to it.
* Example: if `parts_table={foo={...}, bar={...}}`, then `filename_prefix`foo and `filename_prefix`bar are written out.
If 'callbacks_table' is defined, it is consulted for callbacks the same way save_atomic does.
* Example: if `callbacks_table = {foo = func()...}`, then the callback is used during writing of file 'foo' (but not for 'bar')
* Note however that you must at least insert a "true" in the parts_table if you don't use the data argument.
Important: the callback must close the file in all cases!

View file

@ -65,7 +65,7 @@ local function save_atomic_move_file(filename)
end end
local function open_file_and_save_callback(callback, filename) local function open_file_and_save_callback(callback, filename)
local file, err = io.open(filename, "w") local file, err = io.open(filename, "wb")
if not file then if not file then
error("Failed opening file '"..filename.."' for write:\n"..err) error("Failed opening file '"..filename.."' for write:\n"..err)
end end
@ -75,7 +75,7 @@ local function open_file_and_save_callback(callback, filename)
end end
local function open_file_and_load_callback(filename, callback) local function open_file_and_load_callback(filename, callback)
local file, err = io.open(filename, "r") local file, err = io.open(filename, "rb")
if not file then if not file then
error("Failed opening file '"..filename.."' for read:\n"..err) error("Failed opening file '"..filename.."' for read:\n"..err)
end end
@ -97,7 +97,7 @@ function serialize_lib.load_atomic(filename, callback)
local cbfunc = callback or ser.read_from_fd local cbfunc = callback or ser.read_from_fd
-- try <filename> -- try <filename>
local file, ret = io.open(filename, "r") local file, ret = io.open(filename, "rb")
if file then if file then
-- read the file using the callback -- read the file using the callback
local success local success
@ -117,7 +117,7 @@ function serialize_lib.load_atomic(filename, callback)
serialize_lib.log_warn(ret) serialize_lib.log_warn(ret)
-- try <filename>.new -- try <filename>.new
file, ret = io.open(filename..".new", "r") file, ret = io.open(filename..".new", "rb")
if file then if file then
-- read the file using the callback -- read the file using the callback
local success local success
@ -151,7 +151,7 @@ function serialize_lib.save_atomic(data, filename, callback, config)
local cbfunc = callback or ser.write_to_fd local cbfunc = callback or ser.write_to_fd
local file, ret = io.open(filename..".new", "w") local file, ret = io.open(filename..".new", "wb")
if file then if file then
-- save the file using the callback -- save the file using the callback
local success local success
@ -189,7 +189,7 @@ function serialize_lib.save_atomic_multiple(parts_table, filename_prefix, callba
end end
local success = false local success = false
local file, ret = io.open(filename..".new", "w") local file, ret = io.open(filename..".new", "wb")
if file then if file then
-- save the file using the callback -- save the file using the callback
success, ret = pcall(cbfunc, data, file, config) success, ret = pcall(cbfunc, data, file, config)

View file

@ -57,6 +57,7 @@ function serialize_lib.read_table_from_file(filename)
local succ, ret = pcall(ser.read_from_file, filename) local succ, ret = pcall(ser.read_from_file, filename)
if not succ then if not succ then
serialize_lib.log_error(ret) serialize_lib.log_error(ret)
return false,ret
end end
return ret return ret
end end
@ -67,8 +68,9 @@ function serialize_lib.write_table_to_file(root_table, filename)
local succ, ret = pcall(ser.write_to_file, root_table, filename) local succ, ret = pcall(ser.write_to_file, root_table, filename)
if not succ then if not succ then
serialize_lib.log_error(ret) serialize_lib.log_error(ret)
return false,ret
end end
return ret return true
end end

View file

@ -0,0 +1,662 @@
GNU AFFERO GENERAL PUBLIC LICENSE
Version 3, 19 November 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU Affero General Public License is a free, copyleft license for
software and other kinds of works, specifically designed to ensure
cooperation with the community in the case of network server software.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
our General Public Licenses are intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
Developers that use our General Public Licenses protect your rights
with two steps: (1) assert copyright on the software, and (2) offer
you this License which gives you legal permission to copy, distribute
and/or modify the software.
A secondary benefit of defending all users' freedom is that
improvements made in alternate versions of the program, if they
receive widespread use, become available for other developers to
incorporate. Many developers of free software are heartened and
encouraged by the resulting cooperation. However, in the case of
software used on network servers, this result may fail to come about.
The GNU General Public License permits making a modified version and
letting the public access it on a server without ever releasing its
source code to the public.
The GNU Affero General Public License is designed specifically to
ensure that, in such cases, the modified source code becomes available
to the community. It requires the operator of a network server to
provide the source code of the modified version running there to the
users of that server. Therefore, public use of a modified version, on
a publicly accessible server, gives the public access to the source
code of the modified version.
An older license, called the Affero General Public License and
published by Affero, was designed to accomplish similar goals. This is
a different license, not a version of the Affero GPL, but Affero has
released a new version of the Affero GPL which permits relicensing under
this license.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU Affero General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Remote Network Interaction; Use with the GNU General Public License.
Notwithstanding any other provision of this License, if you modify the
Program, your modified version must prominently offer all users
interacting with it remotely through a computer network (if your version
supports such interaction) an opportunity to receive the Corresponding
Source of your version by providing access to the Corresponding Source
from a network server at no charge, through some standard or customary
means of facilitating copying of software. This Corresponding Source
shall include the Corresponding Source for any work covered by version 3
of the GNU General Public License that is incorporated pursuant to the
following paragraph.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the work with which it is combined will remain governed by version
3 of the GNU General Public License.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU Affero General Public License from time to time. Such new versions
will be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU Affero General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU Affero General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU Affero General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) {{ year }} {{ organization }}
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If your software can interact with users remotely through a computer
network, you should also make sure that it provides a way for users to
get its source. For example, if your program is a web application, its
interface could display a "Source" link that leads users to an archive
of the code. There are many ways you could offer source, and different
solutions will be better for different programs; see section 13 for the
specific requirements.
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU AGPL, see
<http://www.gnu.org/licenses/>.

View file

@ -5,3 +5,44 @@ Created out of the need to have a robust data store for advtrains.
The main purpose is to load and store large Lua table structures into files, without loading everything in memory and exhausting the function constant limit of LuaJIT. The main purpose is to load and store large Lua table structures into files, without loading everything in memory and exhausting the function constant limit of LuaJIT.
Also contains various utilities to handle files on disk in a safe manner, retain multiple versions of the same file a.s.o. Also contains various utilities to handle files on disk in a safe manner, retain multiple versions of the same file a.s.o.
## API documentation
For API documentation, see `api.md`.
## Configuration
serialize_lib includes two configuration options:
### serialize_lib_strict_loading (Strict loading)
* Type: boolean
* Default: false
Enable strict file loading mode
If enabled, if any error occurs during loading of a file using the 'atomic' API, an error is thrown. You probably need to disable this option for initial loading after creating the world.
### serialize_lib_no_auto_windows_mode (No automatic Windows Mode)
* Type: boolean
* Default: false
Do not automatically switch to "Windows mode" when saving atomically
Normally, when renaming filename.new to filename fails, serialize_lib automatically switches to a mode where it deletes filename prior to moving. Enable this option to prevent this behavior and abort saving instead.
## License
serialize_lib
Copyright (C) 2020-2021 orwell96
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.

View file

@ -3,6 +3,9 @@
-- Contains the serialization and deserialization routines -- Contains the serialization and deserialization routines
--[[ --[[
Version history:
1 - initial
2 - also escaping CR character as &r
Structure of entry: Structure of entry:
[keytype][key]:[valuetype][val] [keytype][key]:[valuetype][val]
@ -19,7 +22,7 @@ Table:
E E
example: example:
LUA_SER v=1 { LUA_SER v=2 {
Skey:Svalue key = "value", Skey:Svalue key = "value",
N1:Seins [1] = "eins", N1:Seins [1] = "eins",
B1:T [true] = { B1:T [true] = {
@ -32,7 +35,7 @@ String representations:
In strings the following characters are escaped by & In strings the following characters are escaped by &
'&' -> '&&' '&' -> '&&'
(line break) -> '&n' (line break) -> '&n'
(CR) -> '&r' --> required? (CR) -> '&r'
':' -> '&:' ':' -> '&:'
All other characters are unchanged as they bear no special meaning. All other characters are unchanged as they bear no special meaning.
]] ]]
@ -97,6 +100,7 @@ end
function escape_chars(str) function escape_chars(str)
local rstr = string.gsub(str, "&", "&&") local rstr = string.gsub(str, "&", "&&")
rstr = string.gsub(rstr, ":", "&:") rstr = string.gsub(rstr, ":", "&:")
rstr = string.gsub(rstr, "\r", "&r")
rstr = string.gsub(rstr, "\n", "&n") rstr = string.gsub(rstr, "\n", "&n")
return rstr return rstr
end end
@ -172,6 +176,7 @@ end
function unescape_chars(str) --TODO function unescape_chars(str) --TODO
local rstr = string.gsub(str, "&:", ":") local rstr = string.gsub(str, "&:", ":")
rstr = string.gsub(rstr, "&n", "\n") rstr = string.gsub(rstr, "&n", "\n")
rstr = string.gsub(rstr, "&r", "\r")
rstr = string.gsub(rstr, "&&", "&") rstr = string.gsub(rstr, "&&", "&")
return rstr return rstr
end end
@ -187,7 +192,7 @@ config = {
-- Writes the passed table into the passed file descriptor, and closes the file -- Writes the passed table into the passed file descriptor, and closes the file
local function write_to_fd(root_table, file, config) local function write_to_fd(root_table, file, config)
file:write("LUA_SER v=1\n") file:write("LUA_SER v=2\n")
write_table(root_table, file, config) write_table(root_table, file, config)
file:write("E\nEND_SER\n") file:write("E\nEND_SER\n")
file:close() file:close()
@ -197,14 +202,14 @@ end
-- Throws errors when something is wrong. Closes the file. -- Throws errors when something is wrong. Closes the file.
-- config: see above -- config: see above
local function read_from_fd(file) local function read_from_fd(file)
local first_line = file:read("*l") local first_line = file:read("*line")
if first_line ~= "LUA_SER v=1" then if not string.match(first_line, "LUA_SER v=[12]") then
file:close() file:close()
error("Expected header, got '"..first_line.."' instead!") error("Expected header, got '"..first_line.."' instead!")
end end
local t = {} local t = {}
read_table(t, file) read_table(t, file)
local last_line = file:read("*l") local last_line = file:read("*line")
file:close() file:close()
if last_line ~= "END_SER" then if last_line ~= "END_SER" then
error("Missing END_SER, got '"..last_line.."' instead!") error("Missing END_SER, got '"..last_line.."' instead!")
@ -216,7 +221,7 @@ end
-- config: see above -- config: see above
function write_to_file(root_table, filename, config) function write_to_file(root_table, filename, config)
-- try opening the file -- try opening the file
local file, err = io.open(filename, "w") local file, err = io.open(filename, "wb")
if not file then if not file then
error("Failed opening file '"..filename.."' for write:\n"..err) error("Failed opening file '"..filename.."' for write:\n"..err)
end end
@ -228,7 +233,7 @@ end
-- Opens the passed filename, and returns its deserialized contents -- Opens the passed filename, and returns its deserialized contents
function read_from_file(filename) function read_from_file(filename)
-- try opening the file -- try opening the file
local file, err = io.open(filename, "r") local file, err = io.open(filename, "rb")
if not file then if not file then
error("Failed opening file '"..filename.."' for read:\n"..err) error("Failed opening file '"..filename.."' for read:\n"..err)
end end

View file

@ -588,3 +588,43 @@ And this particular one is mapped slightly differently from the others:
(Note the +150 and +50 offsets) (Note the +150 and +50 offsets)
==================
Default game nodes
==================
Although this project was intended to be used with minetest_game, it can be
configured to work with something else instead. All you need to do is provide
the names of the nodes in your game you want biome_lib's internals to use.
Put these settings in your game's minetest.conf (or your client's own config,
if desired). You'll need to set all of them.
biome_lib_default_grow_through_nodes
Comma-separated list of things that a spawned node is allowed to grow
through. Air is always added to whatever you specify.
Default: air, default:snow
biome_lib_default_water_nodes
Comma-separated list of nodes that should be treated as water for the sake
of looking for neighboring "wet" ground.
Default: default:water_source, default:water_flowing,
default:river_water_source, default:river_water_flowing
biome_lib_default_wet_surfaces
Comma-separated list of nodes that should be considered "wet" if one of
the aforementioned water nodes is nearby.
Default: default:dirt, default:dirt_with_grass, default:sand
biome_lib_default_grow_nodes
Comma-separated list of nodes that something must be sitting on to be
able to actively change from one thing to another (such as a sapling
growing into a tree), to be used for ALL growable nodes, if the calling
mod doesn't provide its own lists.
Default: "default:dirt_with_grass"
biome_lib_default_ground_nodes
Comma-separated list of nodes to use as the "root" of something that can
gradually climb up a wall, to be used for ALL such nodes, if the calling
mod doesn't provide its own lists.
Default: "default:dirt_with_grass"

View file

@ -12,7 +12,7 @@ Both mapgen-based spawning and ABM-based spawning is supported. Growing code is
It is primarily intended for mapgen v6, but it should work fine when used with mapgen v7. It is primarily intended for mapgen v6, but it should work fine when used with mapgen v7.
**Dependencies**: default from minetest_game **Dependencies:** nothing, but if you don't use `minetest_game`, you'll need to supply some settings (see API.txt).
**Recommends**: [Plantlife Modpack](https://github.com/minetest-mods/plantlife_modpack), **Recommends**: [Plantlife Modpack](https://github.com/minetest-mods/plantlife_modpack),
[More Trees](https://github.com/minetest-mods/moretrees) [More Trees](https://github.com/minetest-mods/moretrees)

View file

@ -20,8 +20,8 @@ function biome_lib:grow_plants(opts)
local options = opts local options = opts
options.height_limit = options.height_limit or 5 options.height_limit = options.height_limit or 5
options.ground_nodes = options.ground_nodes or { "default:dirt_with_grass" } options.ground_nodes = options.ground_nodes or biome_lib.default_ground_nodes
options.grow_nodes = options.grow_nodes or { "default:dirt_with_grass" } options.grow_nodes = options.grow_nodes or biome_lib.default_grow_nodes
options.seed_diff = options.seed_diff or 0 options.seed_diff = options.seed_diff or 0
local n local n
@ -55,7 +55,7 @@ function biome_lib:grow_plants(opts)
if options.need_wall and options.verticals_list then if options.need_wall and options.verticals_list then
walldir = biome_lib:find_adjacent_wall(p_top, options.verticals_list, options.choose_random_wall) walldir = biome_lib:find_adjacent_wall(p_top, options.verticals_list, options.choose_random_wall)
end end
if (n_top.name == "air" or n_top.name == "default:snow") if biome_lib.default_grow_through_nodes[n_top.name]
and (not options.need_wall or (options.need_wall and walldir)) then and (not options.need_wall or (options.need_wall and walldir)) then
if options.grow_vertically and walldir then if options.grow_vertically and walldir then
if biome_lib:search_downward(pos, options.height_limit, options.ground_nodes) then if biome_lib:search_downward(pos, options.height_limit, options.ground_nodes) then

View file

@ -9,8 +9,6 @@
biome_lib = {} biome_lib = {}
biome_lib.air = {name = "air"} biome_lib.air = {name = "air"}
plantslib = setmetatable({}, { __index=function(t,k) print("Use of deprecated function:", k) return biome_lib[k] end })
biome_lib.blocklist_aircheck = {} biome_lib.blocklist_aircheck = {}
biome_lib.blocklist_no_aircheck = {} biome_lib.blocklist_no_aircheck = {}
@ -32,6 +30,41 @@ biome_lib.total_no_aircheck_calls = 0
biome_lib.queue_run_ratio = tonumber(minetest.settings:get("biome_lib_queue_run_ratio")) or 100 biome_lib.queue_run_ratio = tonumber(minetest.settings:get("biome_lib_queue_run_ratio")) or 100
local function tableize(s)
return string.split(string.trim(string.gsub(s, " ", "")))
end
local c1 minetest.settings:get("biome_lib_default_grow_through_nodes")
biome_lib.default_grow_through_nodes = {["air"] = true}
if c1 then
for _, i in ipairs(tableize(c1)) do
biome_lib.default_grow_through_nodes[i] = true
end
else
biome_lib.default_grow_through_nodes["default:snow"] = true
end
local c2 minetest.settings:get("biome_lib_default_water_nodes")
biome_lib.default_water_nodes = {}
if c2 then
for _, i in ipairs(tableize(c2)) do
biome_lib.default_water_nodes[i] = true
end
else
biome_lib.default_water_nodes["default:water_source"] = true
biome_lib.default_water_nodes["default:water_flowing"] = true
biome_lib.default_water_nodes["default:river_water_source"] = true
biome_lib.default_water_nodes["default:river_water_flowing"] = true
end
local c3 = minetest.settings:get("biome_lib_default_wet_surfaces")
local c4 = minetest.settings:get("biome_lib_default_ground_nodes")
local c5 = minetest.settings:get("biome_lib_default_grow_nodes")
biome_lib.default_wet_surfaces = c3 and tableize(c3) or {"default:dirt", "default:dirt_with_grass", "default:sand"}
biome_lib.default_ground_nodes = c4 and tableize(c4) or {"default:dirt_with_grass"}
biome_lib.default_grow_nodes = c5 and tableize(c5) or {"default:dirt_with_grass"}
-- Boilerplate to support localized strings if intllib mod is installed. -- Boilerplate to support localized strings if intllib mod is installed.
local S local S
if minetest.global_exists("intllib") then if minetest.global_exists("intllib") then
@ -45,12 +78,12 @@ else
end end
biome_lib.intllib = S biome_lib.intllib = S
local DEBUG = false --... except if you want to spam the console with debugging info :-) local DEBUG = minetest.settings:get_bool("biome_lib_debug", false)
function biome_lib:dbg(msg) function biome_lib:dbg(msg)
if DEBUG then if DEBUG then
print("[Plantlife] "..msg) print("[Biome Lib] "..msg)
minetest.log("verbose", "[Plantlife] "..msg) minetest.log("verbose", "[Biome Lib] "..msg)
end end
end end
@ -125,7 +158,7 @@ function biome_lib:set_defaults(biome)
biome.near_nodes_size = biome.near_nodes_size or 0 biome.near_nodes_size = biome.near_nodes_size or 0
biome.near_nodes_count = biome.near_nodes_count or 1 biome.near_nodes_count = biome.near_nodes_count or 1
biome.rarity = biome.rarity or 50 biome.rarity = biome.rarity or 50
biome.max_count = biome.max_count or 5 biome.max_count = biome.max_count or 125
if biome.check_air ~= false then biome.check_air = true end if biome.check_air ~= false then biome.check_air = true end
-- specific to abm spawner -- specific to abm spawner
@ -296,6 +329,7 @@ local function populate_single_surface(biome, pos, perlin_fertile_area, checkair
end end
function biome_lib:populate_surfaces(biome, nodes_or_function_or_model, snodes, checkair) function biome_lib:populate_surfaces(biome, nodes_or_function_or_model, snodes, checkair)
local items_added = 0
biome_lib:set_defaults(biome) biome_lib:set_defaults(biome)
@ -316,10 +350,10 @@ function biome_lib:populate_surfaces(biome, nodes_or_function_or_model, snodes,
local num_in_biome_nodes = #in_biome_nodes local num_in_biome_nodes = #in_biome_nodes
if num_in_biome_nodes == 0 then if num_in_biome_nodes == 0 then
return return 0
end end
for i = 1, math.min(biome.max_count, num_in_biome_nodes) do for i = 1, math.min(math.ceil(biome.max_count/25), num_in_biome_nodes) do
local tries = 0 local tries = 0
local spawned = false local spawned = false
while tries < 2 and not spawned do while tries < 2 and not spawned do
@ -388,7 +422,9 @@ function biome_lib:populate_surfaces(biome, nodes_or_function_or_model, snodes,
tries = tries + 1 tries = tries + 1
end end
end end
if spawned then items_added = items_added + 1 end
end end
return items_added
end end
-- Primary mapgen spawner, for mods that can work with air checking enabled on -- Primary mapgen spawner, for mods that can work with air checking enabled on
@ -411,14 +447,22 @@ function biome_lib:generate_block_with_air_checking()
biome_lib.surface_nodes_aircheck.blockhash = biome_lib.surface_nodes_aircheck.blockhash =
minetest.find_nodes_in_area_under_air(minp, maxp, biome_lib.surfaceslist_aircheck) minetest.find_nodes_in_area_under_air(minp, maxp, biome_lib.surfaceslist_aircheck)
biome_lib.actioncount_aircheck.blockhash = 1 biome_lib.actioncount_aircheck.blockhash = 1
if #biome_lib.surface_nodes_aircheck.blockhash > 0 then
biome_lib:dbg("Mapblock at "..minetest.pos_to_string(minp).." added, with "..#biome_lib.surface_nodes_aircheck.blockhash.." surface nodes detected.")
end
elseif not minetest.get_node_or_nil(minp) then
minetest.load_area(minp)
else else
if biome_lib.actionslist_aircheck[biome_lib.actioncount_aircheck.blockhash] then if biome_lib.actionslist_aircheck[biome_lib.actioncount_aircheck.blockhash] then
-- [1] is biome, [2] is node/function/model -- [1] is biome, [2] is node/function/model
biome_lib:populate_surfaces( local added = biome_lib:populate_surfaces(
biome_lib.actionslist_aircheck[biome_lib.actioncount_aircheck.blockhash][1], biome_lib.actionslist_aircheck[biome_lib.actioncount_aircheck.blockhash][1],
biome_lib.actionslist_aircheck[biome_lib.actioncount_aircheck.blockhash][2], biome_lib.actionslist_aircheck[biome_lib.actioncount_aircheck.blockhash][2],
biome_lib.surface_nodes_aircheck.blockhash, true) biome_lib.surface_nodes_aircheck.blockhash, true)
if added > 0 then
biome_lib:dbg("Ran biome_lib:populate_surfaces for block at "..minetest.pos_to_string(minp)..
". Entry #"..biome_lib.actioncount_aircheck.blockhash.." added "..added.." items.")
end
biome_lib.actioncount_aircheck.blockhash = biome_lib.actioncount_aircheck.blockhash + 1 biome_lib.actioncount_aircheck.blockhash = biome_lib.actioncount_aircheck.blockhash + 1
else else
table.remove(biome_lib.blocklist_aircheck, 1) table.remove(biome_lib.blocklist_aircheck, 1)
@ -445,7 +489,8 @@ function biome_lib:generate_block_no_aircheck()
biome_lib.surface_nodes_no_aircheck.blockhash = biome_lib.surface_nodes_no_aircheck.blockhash =
minetest.find_nodes_in_area(minp, maxp, biome_lib.surfaceslist_no_aircheck) minetest.find_nodes_in_area(minp, maxp, biome_lib.surfaceslist_no_aircheck)
biome_lib.actioncount_no_aircheck.blockhash = 1 biome_lib.actioncount_no_aircheck.blockhash = 1
elseif not minetest.get_node_or_nil(minp) then
minetest.load_area(minp)
else else
if biome_lib.actionslist_no_aircheck[biome_lib.actioncount_no_aircheck.blockhash] then if biome_lib.actionslist_no_aircheck[biome_lib.actioncount_no_aircheck.blockhash] then
biome_lib:populate_surfaces( biome_lib:populate_surfaces(
@ -617,11 +662,11 @@ function biome_lib:spawn_on_surfaces(sd,sp,sr,sc,ss,sa)
local currentsurface = minetest.get_node(pos).name local currentsurface = minetest.get_node(pos).name
if currentsurface == "default:water_source" and if biome_lib.default_water_nodes[currentsurface] and
#minetest.find_nodes_in_area( #minetest.find_nodes_in_area(
{x=pos.x, y=pos.y-biome.depth_max-1, z=pos.z}, {x=pos.x, y=pos.y-biome.depth_max-1, z=pos.z},
vector.new(pos), vector.new(pos),
{"default:dirt", "default:dirt_with_grass", "default:sand"} biome_lib.default_wet_surfaces
) == 0 then ) == 0 then
return -- On water but no ground nearby return -- On water but no ground nearby
end end
@ -682,12 +727,9 @@ function biome_lib:replace_object(pos, replacement, grow_function, walldir, seed
end end
end end
dofile(biome_lib.modpath .. "/search_functions.lua") dofile(biome_lib.modpath .. "/search_functions.lua")
assert(loadfile(biome_lib.modpath .. "/growth.lua"))(time_scale) assert(loadfile(biome_lib.modpath .. "/growth.lua"))(time_scale)
-- Check for infinite stacks -- Check for infinite stacks
if minetest.get_modpath("unified_inventory") or not minetest.settings:get_bool("creative_mode") then if minetest.get_modpath("unified_inventory") or not minetest.settings:get_bool("creative_mode") then
@ -705,10 +747,29 @@ function biome_lib:get_nodedef_field(nodename, fieldname)
return minetest.registered_nodes[nodename][fieldname] return minetest.registered_nodes[nodename][fieldname]
end end
if DEBUG then
biome_lib.last_count_air = 0
biome_lib.last_count_no_air = 0
function biome_lib.show_pending_block_counts()
if biome_lib.last_count_air ~= #biome_lib.blocklist_aircheck
or biome_lib.last_count_no_air ~= #biome_lib.blocklist_no_aircheck then
biome_lib:dbg(string.format("Pending block counts, air: %-7i no-air: %i",
#biome_lib.blocklist_aircheck, #biome_lib.blocklist_no_aircheck))
biome_lib.last_count_air = #biome_lib.blocklist_aircheck
biome_lib.last_count_no_air = #biome_lib.blocklist_no_aircheck
end
minetest.after(1, biome_lib.show_pending_block_counts)
end
biome_lib.show_pending_block_counts()
minetest.after(0, function()
print("Registered a total of "..(#biome_lib.surfaceslist_aircheck)+(#biome_lib.surfaceslist_no_aircheck).." surface types to be evaluated, spread")
print("across "..#biome_lib.actionslist_aircheck.." actions with air-checking and "..#biome_lib.actionslist_no_aircheck.." actions without.")
end)
end
print("[Biome Lib] Loaded") print("[Biome Lib] Loaded")
minetest.after(0, function()
print("[Biome Lib] Registered a total of "..(#biome_lib.surfaceslist_aircheck)+(#biome_lib.surfaceslist_no_aircheck).." surface types to be evaluated, spread")
print("[Biome Lib] across "..#biome_lib.actionslist_aircheck.." actions with air-checking and "..#biome_lib.actionslist_no_aircheck.." actions without.")
end)

View file

@ -1,4 +1,3 @@
name = biome_lib name = biome_lib
min_minetest_version = 5.2.0 min_minetest_version = 5.2.0
depends = default optional_depends = default, intllib
optional_depends = intllib

View file

@ -56,11 +56,11 @@ end
-- split into individual mapblocks to reduce lag -- split into individual mapblocks to reduce lag
minetest.register_on_generated(function(minp, maxp, blockseed) minetest.register_on_generated(function(minp, maxp, blockseed)
for x = 0, 5 do for x = 0, 4 do
local minx = minp.x + x*16 local minx = minp.x + x*16
for y = 0, 5 do for y = 0, 4 do
local miny = minp.y + y*16 local miny = minp.y + y*16
for z = 0, 5 do for z = 0, 4 do
local minz = minp.z + z*16 local minz = minp.z + z*16
local bmin = {x=minx, y=miny, z=minz} local bmin = {x=minx, y=miny, z=minz}

View file

@ -37,6 +37,17 @@ local function pine_grow(pos)
end end
-- special function for cactus growth
local function cactus_grow(pos)
default.grow_cactus(pos, minetest.get_node(pos))
end
-- special function for papyrus growth
local function papyrus_grow(pos)
default.grow_papyrus(pos, minetest.get_node(pos))
end
-- default saplings -- default saplings
local saplings = { local saplings = {
{"default:sapling", default.grow_new_apple_tree, "soil"}, {"default:sapling", default.grow_new_apple_tree, "soil"},
@ -49,7 +60,9 @@ local saplings = {
{"default:acacia_bush_sapling", default.grow_acacia_bush, "soil"}, {"default:acacia_bush_sapling", default.grow_acacia_bush, "soil"},
{"default:large_cactus_seedling", default.grow_large_cactus, "sand"}, {"default:large_cactus_seedling", default.grow_large_cactus, "sand"},
{"default:blueberry_bush_sapling", default.grow_blueberry_bush, "soil"}, {"default:blueberry_bush_sapling", default.grow_blueberry_bush, "soil"},
{"default:pine_bush_sapling", default.grow_pine_bush, "soil"} {"default:pine_bush_sapling", default.grow_pine_bush, "soil"},
{"default:cactus", cactus_grow, "sand"},
{"default:papyrus", papyrus_grow, "soil"},
} }
-- helper tables ( "" denotes a blank item ) -- helper tables ( "" denotes a blank item )

View file

@ -10,7 +10,8 @@ minetest.register_node("castle:autocraft", {
paramtype = "light", paramtype = "light",
paramtype2 = "facedir", paramtype2 = "facedir",
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
drop = "pipeworks:autocrafter",
})--[[
on_construct = function(pos) on_construct = function(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
@ -18,16 +19,6 @@ minetest.register_node("castle:autocraft", {
inv:set_size("in", 6 * 4) -- was 8 * 3 inv:set_size("in", 6 * 4) -- was 8 * 3
meta:set_string("formspec", meta:set_string("formspec",
--[[
"size[8,11]"
..default.gui_bg..default.gui_bg_img..default.gui_slots
.."list[context;craft;2.5,0;3,3]"
.."list[context;in;0,3.5;8,3]"
.."list[current_player;main;0,7;8,4]"
.."label[0,0;AUTOCRAFTER]"
.."label[0.5,1.2;Recipe ->]"
.."label[0,3;Materials:")
--]]
"size[10,9]" "size[10,9]"
..default.gui_bg..default.gui_bg_img..default.gui_slots ..default.gui_bg..default.gui_bg_img..default.gui_slots
.."list[context;craft;7,0.5;3,3]" .."list[context;craft;7,0.5;3,3]"
@ -156,3 +147,4 @@ minetest.register_abm({
end end
end, end,
}) })
]]

View file

@ -93,5 +93,5 @@ for n = 1, #pillar do
{pillar[n][4],pillar[n][4]} }, {pillar[n][4],pillar[n][4]} },
}) })
grp = {cracky = 3, not_in_craft_guide = 1} --grp = {cracky = 3, not_in_craft_guide = 1}
end end

Binary file not shown.

After

Width:  |  Height:  |  Size: 465 B

View file

@ -1,4 +1,24 @@
minetest.register_node("castle:light",{
drawtype = "glasslike",
description = "Light Block",
sunlight_propagates = true,
light_source = 12,
tiles = {"castle_street_light.png"},
groups = {cracky=2, oddly_breakable_by_hand = 3},
sounds = default.node_sound_glass_defaults(),
paramtype = "light",
})
minetest.register_craft({
output = "castle:light",
recipe = {
{"default:stick", "default:glass", "default:stick"},
{"default:glass", "default:torch", "default:glass"},
{"default:stick", "default:glass", "default:stick"},
}
})
minetest.register_node("castle:dungeon_stone", { minetest.register_node("castle:dungeon_stone", {
description = "Dungeon Stone", description = "Dungeon Stone",
drawtype = "normal", drawtype = "normal",
@ -68,6 +88,7 @@ minetest.register_node("castle:ropes",{
tiles = {"castle_ropes.png"}, tiles = {"castle_ropes.png"},
groups = {choppy = 3, snappy = 3, oddly_breakable_by_hand = 3,flammable = 1}, groups = {choppy = 3, snappy = 3, oddly_breakable_by_hand = 3,flammable = 1},
paramtype = "light", paramtype = "light",
paramtype2 = "facedir",
climbable = true, climbable = true,
walkable = false, walkable = false,
node_box = { node_box = {
@ -81,7 +102,7 @@ minetest.register_node("castle:ropes",{
fixed = { fixed = {
{-1/16, -8/16, -1/16, 1/16, 8/16, 1/16}, {-1/16, -8/16, -1/16, 1/16, 8/16, 1/16},
}, },
}, }
}) })
minetest.register_craft({ minetest.register_craft({

View file

@ -33,9 +33,9 @@ else
minetest.register_node(":ethereal:banana", { minetest.register_node(":ethereal:banana", {
description = S("Banana"), description = S("Banana"),
drawtype = "torchlike", drawtype = "torchlike",
tiles = {"banana_single.png"}, tiles = {"farming_banana_single.png"},
inventory_image = "banana_single.png", inventory_image = "farming_banana_single.png",
wield_image = "banana_single.png", wield_image = "farming_banana_single.png",
paramtype = "light", paramtype = "light",
sunlight_propagates = true, sunlight_propagates = true,
walkable = false, walkable = false,
@ -50,9 +50,9 @@ else
minetest.register_node(":ethereal:bananaleaves", { minetest.register_node(":ethereal:bananaleaves", {
description = S("Banana Leaves"), description = S("Banana Leaves"),
tiles = {"banana_leaf.png"}, tiles = {"farming_banana_leaf.png"},
inventory_image = "banana_leaf.png", inventory_image = "farming_banana_leaf.png",
wield_image = "banana_leaf.png", wield_image = "farming_banana_leaf.png",
paramtype = "light", paramtype = "light",
waving = 1, waving = 1,
groups = {snappy = 3, leafdecay = 3, leaves = 1, flammable = 2}, groups = {snappy = 3, leafdecay = 3, leaves = 1, flammable = 2},
@ -148,8 +148,8 @@ if eth then
else else
minetest.register_craftitem(":ethereal:strawberry", { minetest.register_craftitem(":ethereal:strawberry", {
description = S("Strawberry"), description = S("Strawberry"),
inventory_image = "strawberry.png", inventory_image = "farming_strawberry.png",
wield_image = "strawberry.png", wield_image = "farming_strawberry.png",
groups = {food_strawberry = 1, flammable = 2}, groups = {food_strawberry = 1, flammable = 2},
on_use = minetest.item_eat(1) on_use = minetest.item_eat(1)
}) })

View file

@ -46,6 +46,7 @@ minetest.register_node("farming:garlic_braid", {
inventory_image = "crops_garlic_braid.png", inventory_image = "crops_garlic_braid.png",
wield_image = "crops_garlic_braid.png", wield_image = "crops_garlic_braid.png",
drawtype = "nodebox", drawtype = "nodebox",
use_texture_alpha = "clip",
paramtype = "light", paramtype = "light",
paramtype2 = "facedir", paramtype2 = "facedir",
tiles = { tiles = {

View file

@ -24,6 +24,38 @@ minetest.register_craft({
recipe = {"farming:soy_pod"} recipe = {"farming:soy_pod"}
}) })
-- soy sauce
minetest.register_node("farming:soy_sauce", {
description = S("Soy Sauce"),
drawtype = "plantlike",
tiles = {"farming_soy_sauce.png"},
inventory_image = "farming_soy_sauce.png",
wield_image = "farming_soy_sauce.png",
paramtype = "light",
walkable = false,
selection_box = {
type = "fixed",
fixed = {-0.3, -0.5, -0.3, 0.3, 0.5, 0.3}
},
groups = {
vessel = 1, food_soy_sauce = 1, dig_immediate = 3, attached_node = 1
},
sounds = default.node_sound_glass_defaults()
})
minetest.register_craft( {
type = "shapeless",
output = "farming:soy_sauce",
recipe = {
"group:food_soy", "group:food_soy", "group:food_juicer",
"bucket:bucket_river_water", "vessels:glass_bottle", "group:food_salt"
},
replacements = {
{"bucket:bucket_river_water", "bucket:bucket_empty"},
{"group:food_juicer", "farming:juicer"}
}
})
-- soy milk -- soy milk
minetest.register_node("farming:soy_milk", { minetest.register_node("farming:soy_milk", {
description = S("Soy Milk"), description = S("Soy Milk"),

View file

Before

Width:  |  Height:  |  Size: 421 B

After

Width:  |  Height:  |  Size: 421 B

View file

Before

Width:  |  Height:  |  Size: 200 B

After

Width:  |  Height:  |  Size: 200 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 166 B

View file

Before

Width:  |  Height:  |  Size: 382 B

After

Width:  |  Height:  |  Size: 382 B

View file

@ -155,7 +155,8 @@ minetest.register_craftitem(":mobs:hairball", {
local newpos = {x = pos.x + dir.x, y = pos.y + dir.y + 1.5, z = pos.z + dir.z} local newpos = {x = pos.x + dir.x, y = pos.y + dir.y + 1.5, z = pos.z + dir.z}
local item = hairball_items[math.random(1, #hairball_items)] local item = hairball_items[math.random(1, #hairball_items)]
if item ~= "" then if item ~= ""
and minetest.registered_items[item] then
minetest.add_item(newpos, {name = item}) minetest.add_item(newpos, {name = item})
end end

View file

@ -37,6 +37,7 @@ mobs:register_mob("mobs_monster:lava_flan", {
}, },
water_damage = 8, water_damage = 8,
lava_damage = 0, lava_damage = 0,
fire_damage = 0,
light_damage = 0, light_damage = 0,
immune_to = { immune_to = {
{"mobs:pick_lava", -2}, -- lava pick heals 2 health {"mobs:pick_lava", -2}, -- lava pick heals 2 health
@ -240,6 +241,7 @@ mobs:register_mob("mobs_monster:obsidian_flan", {
}, },
water_damage = 0, water_damage = 0,
lava_damage = 8, lava_damage = 8,
fire_damage = 0,
light_damage = 0, light_damage = 0,
animation = { animation = {
speed_normal = 15, speed_normal = 15,

View file

@ -39,6 +39,7 @@ mobs:register_mob("mobs_monster:sand_monster", {
attack_type = "dogfight", attack_type = "dogfight",
pathfinding = true, pathfinding = true,
--specific_attack = {"player", "mobs_npc:npc"}, --specific_attack = {"player", "mobs_npc:npc"},
--ignore_invisibility = true,
reach = 2, reach = 2,
damage = 1, damage = 1,
hp_min = 4, hp_min = 4,

View file

@ -8,12 +8,12 @@ local use_cmi = minetest.global_exists("cmi")
mobs = { mobs = {
mod = "redo", mod = "redo",
version = "20210323", version = "20210405",
intllib = S, intllib = S,
invis = minetest.global_exists("invisibility") and invisibility or {} invis = minetest.global_exists("invisibility") and invisibility or {}
} }
-- localize math functions -- localize common functions
local pi = math.pi local pi = math.pi
local square = math.sqrt local square = math.sqrt
local sin = math.sin local sin = math.sin
@ -112,7 +112,8 @@ local mob_class = {
light_damage_min = 14, light_damage_min = 14,
light_damage_max = 15, light_damage_max = 15,
water_damage = 0, water_damage = 0,
lava_damage = 0, lava_damage = 4,
fire_damage = 4,
air_damage = 0, air_damage = 0,
suffocation = 2, suffocation = 2,
fall_damage = 1, fall_damage = 1,
@ -164,6 +165,7 @@ local mob_class = {
local mob_class_meta = {__index = mob_class} local mob_class_meta = {__index = mob_class}
-- play sound -- play sound
function mob_class:mob_sound(sound) function mob_class:mob_sound(sound)
@ -982,7 +984,12 @@ local is_node_dangerous = function(self, nodename)
end end
if self.lava_damage > 0 if self.lava_damage > 0
and minetest.get_item_group(nodename, "igniter") ~= 0 then and minetest.get_item_group(nodename, "lava") ~= 0 then
return true
end
if self.fire_damage > 0
and minetest.get_item_group(nodename, "fire") ~= 0 then
return true return true
end end
@ -1068,37 +1075,47 @@ function mob_class:do_env_damage()
local nodef = minetest.registered_nodes[self.standing_in] local nodef = minetest.registered_nodes[self.standing_in]
-- water -- water
if self.water_damage and nodef.groups.water then if self.water_damage ~= 0
and nodef.groups.water then
if self.water_damage ~= 0 then self.health = self.health - self.water_damage
self.health = self.health - self.water_damage effect(pos, 5, "bubble.png", nil, nil, 1, nil)
effect(pos, 5, "bubble.png", nil, nil, 1, nil) if self:check_for_death({type = "environment",
pos = pos, node = self.standing_in}) then
if self:check_for_death({type = "environment", return true
pos = pos, node = self.standing_in}) then
return true
end
end end
-- ignition source (fire or lava) -- lava damage
elseif self.lava_damage and nodef.groups.igniter then elseif self.lava_damage ~= 0
and nodef.groups.lava then
if self.lava_damage ~= 0 then self.health = self.health - self.lava_damage
self.health = self.health - self.lava_damage effect(pos, 15, "fire_basic_flame.png", 1, 5, 1, 0.2, 15, true)
effect(pos, 15, "fire_basic_flame.png", 1, 5, 1, 0.2, 15, true) if self:check_for_death({type = "environment", pos = pos,
node = self.standing_in, hot = true}) then
if self:check_for_death({type = "environment", pos = pos, return true
node = self.standing_in, hot = true}) then
return true
end
end end
-- damage_per_second node check -- fire damage
elseif nodef.damage_per_second ~= 0 then elseif self.fire_damage ~= 0
and nodef.groups.fire then
self.health = self.health - self.fire_damage
effect(pos, 15, "fire_basic_flame.png", 1, 5, 1, 0.2, 15, true)
if self:check_for_death({type = "environment", pos = pos,
node = self.standing_in, hot = true}) then
return true
end
-- damage_per_second node check (not fire and lava)
elseif nodef.damage_per_second ~= 0
and nodef.groups.lava == 0 and nodef.groups.fire == 0 then
self.health = self.health - nodef.damage_per_second self.health = self.health - nodef.damage_per_second
@ -2772,15 +2789,37 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir, damage)
return true return true
end end
-- is mob protected? -- is mob protected
if self.protected and hitter:is_player() if self.protected then
and minetest.is_protected(self.object:get_pos(),
hitter:get_player_name()) then
minetest.chat_send_player(hitter:get_player_name(), -- did player hit mob and if so is it in protected area
S("Mob has been protected!")) if hitter:is_player() then
return true local player_name = hitter:get_player_name()
if player_name ~= self.owner
and minetest.is_protected(self.object:get_pos(), player_name) then
minetest.chat_send_player(hitter:get_player_name(),
S("Mob has been protected!"))
return true
end
-- if protection is on level 2 then dont let arrows harm mobs
elseif self.protected == 2 then
local ent = hitter and hitter:get_luaentity()
if ent and ent._is_arrow then
return true -- arrow entity
elseif not ent then
return true -- non entity
end
end
end end
local weapon = hitter:get_wielded_item() local weapon = hitter:get_wielded_item()
@ -2812,7 +2851,7 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir, damage)
end end
damage = damage + (tool_capabilities.damage_groups[group] or 0) damage = damage + (tool_capabilities.damage_groups[group] or 0)
* tmp * ((armor[group] or 0) / 100.0) * tmp * ((armor[group] or 0) / 100.0)
end end
end end
@ -3149,8 +3188,7 @@ function mob_class:mob_activate(staticdata, def, dtime)
def.textures = {def.textures} def.textures = {def.textures}
end end
self.base_texture = def.textures and self.base_texture = def.textures and def.textures[random(#def.textures)]
def.textures[random(#def.textures)]
self.base_mesh = def.mesh self.base_mesh = def.mesh
self.base_size = self.visual_size self.base_size = self.visual_size
self.base_colbox = self.collisionbox self.base_colbox = self.collisionbox
@ -3557,6 +3595,7 @@ minetest.register_entity(name, setmetatable({
light_damage_max = def.light_damage_max, light_damage_max = def.light_damage_max,
water_damage = def.water_damage, water_damage = def.water_damage,
lava_damage = def.lava_damage, lava_damage = def.lava_damage,
fire_damage = def.fire_damage,
air_damage = def.air_damage, air_damage = def.air_damage,
suffocation = def.suffocation, suffocation = def.suffocation,
fall_damage = def.fall_damage, fall_damage = def.fall_damage,
@ -4562,19 +4601,21 @@ function mobs:protect(self, clicker)
local name = clicker:get_player_name() local name = clicker:get_player_name()
local tool = clicker:get_wielded_item() local tool = clicker:get_wielded_item()
local tool_name = tool:get_name()
if tool:get_name() ~= "mobs:protector" then if tool_name ~= "mobs:protector"
and tool_name ~= "mobs:protector2" then
return false return false
end end
if self.tamed == false then if not self.tamed then
minetest.chat_send_player(name, S("Not tamed!")) minetest.chat_send_player(name, S("Not tamed!"))
return true -- false return true
end end
if self.protected == true then if self.protected then
minetest.chat_send_player(name, S("Already protected!")) minetest.chat_send_player(name, S("Already protected!"))
return true -- false return true
end end
if not mobs.is_creative(clicker:get_player_name()) then if not mobs.is_creative(clicker:get_player_name()) then
@ -4582,9 +4623,15 @@ function mobs:protect(self, clicker)
clicker:set_wielded_item(tool) clicker:set_wielded_item(tool)
end end
self.protected = true -- set protection level
if tool_name == "mobs:protector" then
self.protected = true
else
self.protected = 2 ; self.fire_damage = 0
end
local pos = self.object:get_pos() local pos = self.object:get_pos()
pos.y = pos.y + self.collisionbox[2] + 0.5 pos.y = pos.y + self.collisionbox[2] + 0.5
effect(self.object:get_pos(), 25, "mobs_protect_particle.png", effect(self.object:get_pos(), 25, "mobs_protect_particle.png",

View file

@ -66,7 +66,10 @@ functions needed for the mob to work properly which contains the following:
water. water.
'air_damage' holds damage per second inflicted to mob when standing in air. 'air_damage' holds damage per second inflicted to mob when standing in air.
'lava_damage' holds the damage per second inflicted to mobs when standing 'lava_damage' holds the damage per second inflicted to mobs when standing
in lava or fire or an ignition source. in lava.
'fire_damage' holds the damage per second inflicted to mobs when standing
in fire.
'light_damage' holds the damage per second inflicted to mobs when light 'light_damage' holds the damage per second inflicted to mobs when light
level is between the min and max values below level is between the min and max values below
'light_damage_min' minimum light value when mob is affected (default: 14) 'light_damage_min' minimum light value when mob is affected (default: 14)

View file

@ -115,6 +115,22 @@ minetest.register_craft({
} }
}) })
-- level 2 protection rune
minetest.register_craftitem("mobs:protector2", {
description = S("Mob Protection Rune (Level 2)"),
inventory_image = "mobs_protector2.png",
groups = {flammable = 2}
})
minetest.register_craft({
output = "mobs:protector2",
recipe = {
{"mobs:protector", "default:mese_crystal", "mobs:protector"},
{"default:mese_crystal", "default:diamondblock", "default:mese_crystal"},
{"mobs:protector", "default:mese_crystal", "mobs:protector"}
}
})
-- saddle -- saddle
minetest.register_craftitem("mobs:saddle", { minetest.register_craftitem("mobs:saddle", {
description = S("Saddle"), description = S("Saddle"),

Binary file not shown.

After

Width:  |  Height:  |  Size: 164 B

View file

@ -77,7 +77,7 @@ function register_door(name, def)
minetest.get_meta(pt2):set_int("right", 1) minetest.get_meta(pt2):set_int("right", 1)
end end
if not minetest.setting_getbool("creative_mode") then if not minetest.settings:get_bool("creative_mode") then
itemstack:take_item() itemstack:take_item()
end end
return itemstack return itemstack
@ -150,6 +150,7 @@ function register_door(name, def)
tiles = {tb[2], tb[2], tb[2], tb[2], tb[1], tb[1].."^[transformfx"}, tiles = {tb[2], tb[2], tb[2], tb[2], tb[1], tb[1].."^[transformfx"},
paramtype = "light", paramtype = "light",
paramtype2 = "facedir", paramtype2 = "facedir",
use_texture_alpha = "clip",
is_ground_content = false, is_ground_content = false,
drop = name, drop = name,
drawtype = "nodebox", drawtype = "nodebox",
@ -187,6 +188,7 @@ function register_door(name, def)
tiles = {tt[2], tt[2], tt[2], tt[2], tt[1], tt[1].."^[transformfx"}, tiles = {tt[2], tt[2], tt[2], tt[2], tt[1], tt[1].."^[transformfx"},
paramtype = "light", paramtype = "light",
paramtype2 = "facedir", paramtype2 = "facedir",
use_texture_alpha = "clip",
is_ground_content = false, is_ground_content = false,
drop = "", drop = "",
drawtype = "nodebox", drawtype = "nodebox",
@ -224,6 +226,7 @@ function register_door(name, def)
tiles = {tb[2], tb[2], tb[2], tb[2], tb[1].."^[transformfx", tb[1]}, tiles = {tb[2], tb[2], tb[2], tb[2], tb[1].."^[transformfx", tb[1]},
paramtype = "light", paramtype = "light",
paramtype2 = "facedir", paramtype2 = "facedir",
use_texture_alpha = "clip",
is_ground_content = false, is_ground_content = false,
drop = name, drop = name,
drawtype = "nodebox", drawtype = "nodebox",
@ -261,6 +264,7 @@ function register_door(name, def)
tiles = {tt[2], tt[2], tt[2], tt[2], tt[1].."^[transformfx", tt[1]}, tiles = {tt[2], tt[2], tt[2], tt[2], tt[1].."^[transformfx", tt[1]},
paramtype = "light", paramtype = "light",
paramtype2 = "facedir", paramtype2 = "facedir",
use_texture_alpha = "clip",
is_ground_content = false, is_ground_content = false,
drop = "", drop = "",
drawtype = "nodebox", drawtype = "nodebox",
@ -404,6 +408,7 @@ function register_trapdoor(name, def)
def.drawtype = "nodebox" def.drawtype = "nodebox"
def.paramtype = "light" def.paramtype = "light"
def.paramtype2 = "facedir" def.paramtype2 = "facedir"
def.use_texture_alpha = "clip"
def.is_ground_content = false def.is_ground_content = false
local def_opened = table.copy(def) local def_opened = table.copy(def)

View file

@ -177,10 +177,10 @@ local protector_formspec = function(meta)
checkbox_faction = true checkbox_faction = true
end end
else else
if factions.get_player_factions(meta:get_string("owner")) ~= nil then local player_factions = factions.get_player_factions(meta:get_string("owner"))
if next(factions.get_player_faction(meta:get_string("owner"))) then
checkbox_faction = true if player_factions ~= nil and #player_factions >= 1 then
end checkbox_faction = true
end end
end end
end end
@ -578,6 +578,7 @@ minetest.register_node("protector:protect2", {
inventory_image = "protector_logo.png", inventory_image = "protector_logo.png",
sounds = default.node_sound_stone_defaults(), sounds = default.node_sound_stone_defaults(),
groups = {dig_immediate = 2, unbreakable = 1}, groups = {dig_immediate = 2, unbreakable = 1},
use_texture_alpha = "clip",
paramtype = "light", paramtype = "light",
paramtype2 = "wallmounted", paramtype2 = "wallmounted",
legacy_wallmounted = true, legacy_wallmounted = true,

View file

@ -0,0 +1,3 @@
josegamestest_0
Jose Anast&aacute;cio
CC BY-SA 3.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

View file

@ -497,6 +497,17 @@ stairs.register_all("bred2", "xanadu:red2",
"Decorative baked red clay 2", "Decorative baked red clay 2",
stairs.stone) stairs.stone)
stairs.register_all("compressed_cobble", "xanadu:compressed_cobble",
{cracky = 3, level = 2},
{"compressed_cobble.png"},
"Compressed Cobble",
stairs.stone)
stairs.register_all("compressed_dirt", "xanadu:compressed_dirt",
{crumbly = 2},
{"compressed_dirt.png"},
"Compressed Dirt",
stairs.stone)
end end
--= Castle Mod --= Castle Mod

View file

@ -517,7 +517,8 @@ function stamina.eat(hp_change, replace_with_item, itemstack, user, pointed_thin
minetest.sound_play(snd, {to_player = name, gain = 0.7}, true) minetest.sound_play(snd, {to_player = name, gain = 0.7}, true)
-- particle effect when eating -- particle effect when eating
local pos = user:get_pos() ; pos.y = pos.y + 1.5 -- mouth level local prop = user:get_properties()
local pos = user:get_pos() ; pos.y = pos.y + prop.eye_height -- mouth level
local texture = minetest.registered_items[itemname].inventory_image local texture = minetest.registered_items[itemname].inventory_image
local dir = user:get_look_dir() local dir = user:get_look_dir()
@ -601,8 +602,7 @@ and minetest.settings:get_bool("enable_stamina") ~= false then
if get_int_attribute(player) then if get_int_attribute(player) then
level = math.min(get_int_attribute(player), level = math.min(get_int_attribute(player), STAMINA_VISUAL_MAX)
STAMINA_VISUAL_MAX)
else else
local meta = player:get_meta() local meta = player:get_meta()
@ -620,7 +620,7 @@ and minetest.settings:get_bool("enable_stamina") ~= false then
number = level, number = level,
alignment = {x = -1, y = -1}, alignment = {x = -1, y = -1},
offset = {x = -266, y = -110}, offset = {x = -266, y = -110},
max = 0, max = 0
}) })
stamina.players[name] = { stamina.players[name] = {
@ -628,7 +628,7 @@ and minetest.settings:get_bool("enable_stamina") ~= false then
exhaustion = 0, exhaustion = 0,
poisoned = nil, poisoned = nil,
drunk = nil, drunk = nil,
sprint = nil, sprint = nil
} }
end) end)
@ -675,7 +675,6 @@ else
stamina.players[player:get_player_name()] = { stamina.players[player:get_player_name()] = {
poisoned = nil, sprint = nil, drunk = nil, exhaustion = 0} poisoned = nil, sprint = nil, drunk = nil, exhaustion = 0}
end) end)
end end
-- clear when player leaves -- clear when player leaves