Add files via upload

This commit is contained in:
Noodlemire 2018-06-10 22:23:14 -05:00 committed by GitHub
parent 6edba72928
commit aadf924fa4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 464 additions and 1 deletions

202
LICENSE.txt Normal file
View File

@ -0,0 +1,202 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2018 Noodlemire
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@ -1 +1,22 @@
# clumpfall
Clump Fall Nodes
[clumpfall]
-------------------------------------------------------------------------------------------------------------
About
-------------------------------------------------------------------------------------------------------------
This mod is designed to allow almost every node in Minetest to fall down, similar to sand or gravel. However, there are two key differences between regular Falling Nodes and Clump Fall Nodes; first that nodes that are part of the new "clump_fall_node" group will fall down slowly in small "clumps", gradually cascading until there is nothing left in the air. The other key difference is that individual nodes don't automatically fall just because nothing is immediately underneath them. Instead, if there's a block below and to the side or corner of the node in question, then the node still won't fall. Because Clump Fall Nodes only start to fall if there are no other Clump Fall Nodes connected to their underside, lower edges, or lower corners, this means that pyramid shapes will often become structurally sound. It also means that cubic houses won't need to be completely filled with supports in order to keep their roofs from collapsing, and that giant holes won't appear on the world's surface every time a cave collapses.
-------------------------------------------------------------------------------------------------------------
Dependencies and Support
-------------------------------------------------------------------------------------------------------------
This mod has no dependencies, not even optional ones. Support that this mod has for others is built-in and automatic, able to effect all added nodes without much issue, and is able to correctly differentiate between nodes that should be Clump Fall Nodes and nodes that are Falling Nodes, Attached Nodes, Liquid, or Unbreakable.
-------------------------------------------------------------------------------------------------------------
License
-------------------------------------------------------------------------------------------------------------
The Apache 2.0 License is used with this mod. See http://www.apache.org/licenses/LICENSE-2.0 or LICENSE.md for more details.
-------------------------------------------------------------------------------------------------------------
Installation
-------------------------------------------------------------------------------------------------------------
Download, unzip, and place within the usual minetest/current/mods folder, and it will behave in relation to the Minetest engine like any other mod.

240
init.lua Normal file
View File

@ -0,0 +1,240 @@
--[[
Copyright 2018 Noodlemire
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
--]]
--the maximum radius of blocks to cause to fall at once.
local clump_radius = 1
--[[
Description:
Searches for clump_fall_nodes within a given volume of radius clump_radius and all of the center points between the 3D points given by the parameters.
Parameters:
Two 3D vectors; the first is the smaller, and the second is the larger. These are the two corners of the volume to be searched through. Note that clump_radius is added on to these min and max points, so keep that in mind in relation to the size of the volume that is actually effected by this function.
Returns:
A table containing the positions of all clump_fall_nodes found
--]]
function check_group_for_fall(min_pos, max_pos)
--Local created to temporarily store clump_fall_nodes that should fall down
local nodes_that_can_fall = {}
--iterates through the entire cubic volume contained between the minimum and maximum positions
for t = min_pos.z - clump_radius, max_pos.z + clump_radius do
for n = min_pos.y - clump_radius, max_pos.y + clump_radius do
for i = min_pos.x - clump_radius, max_pos.x + clump_radius do
--Creates a 3D vector to store the position that is currently being inspected
local check_this = {x=i, y=n, z=t}
--If the position currently being checked belongs to the clump_fall_node group, then
if minetest.get_item_group(minetest.get_node(check_this).name, "clump_fall_node") ~= 0 then
--First create a variable that assumes that there are no clump_fall_nodes underneath the current position
local has_bottom_support = false
--This then checks each node under the current position within a 3x3 area for blocks within the clump_fall_node group
for b = t - 1, t + 1 do
for a = i - 1, i + 1 do
local bottom_pos = {x=a, y=n-1, z=b}
--As long as at least a single node belongs to the clump_fall_node group, has_bottom_support will be set to true.
if minetest.get_item_group(minetest.get_node(bottom_pos).name, "clump_fall_node") ~= 0 then
has_bottom_support = true
end
end
end
--If at least one clump_fall_node was found underneath, nothing else will happen. If none are found, the current position will be placed within the table nodes_that_can_fall
if has_bottom_support == false then
table.insert(nodes_that_can_fall, {x=i, y=n, z=t})
end
end
end
end
end
--Once all this looping is complete, the list of nodes that can fall is complete and can be returned.
return nodes_that_can_fall
end
--[[
Description:
Initiate a clump fall that starts within the given 3D points, and if needed, will cascade farther until there is nothing left in the area that can fall
Parameters:
Any number of 3D vectors of which to draw a cubic volume around. This volume will be the starting point for this clump_fall
Returns:
Nothing
--]]
function clump_fall(...)
--Used to store an array version of the arguments
local arg_array = ({...})[1]
--Used to store an array version of the arguments once they are standardized
local node_pos_to_check = {}
--This check is needed to properly standardize the arguments. Without it, results of this function would be needlessly inconsistant.
if type(arg_array[1]) ~= "table" then
node_pos_to_check = {arg_array}
else
node_pos_to_check = arg_array
end
--List of postions of nodes that check_group_for_fall() found to need falling
local node_pos_to_fall = {}
--Variable that assumes that no nodes needed to fall
local found_no_fallable_nodes = true
--Stores the largest x, y, and z values out of the 3D vertices given by the arguments
local max_pos = {x, y, z}
--Stores the smallest x, y, and z values out of the 3D vertices given by the arguments
local min_pos = {x, y, z}
--To be used later in this function, this stores the largest x, y, and z values of nodes that were actually found to need falling.
local new_max_pos = {x, y, z}
--To be used later in this function, this stores the smallest x, y, and z values of nodes that were actually found to need falling.
local new_min_pos = {x, y, z}
--Compares max_pos and min_pos to the list of arguments, and individually sets the x, y, and z values of each to, respectively, the largest/smallest x/y/z values
for v, pos_find_minmax in pairs(node_pos_to_check) do
if max_pos.x == nil or max_pos.x < pos_find_minmax.x then
max_pos.x = pos_find_minmax.x
end
if max_pos.y == nil or max_pos.y < pos_find_minmax.y then
max_pos.y = pos_find_minmax.y
end
if max_pos.z == nil or max_pos.z < pos_find_minmax.z then
max_pos.z = pos_find_minmax.z
end
if min_pos.x == nil or min_pos.x > pos_find_minmax.x then
min_pos.x = pos_find_minmax.x
end
if min_pos.y == nil or min_pos.y > pos_find_minmax.y then
min_pos.y = pos_find_minmax.y
end
if min_pos.z == nil or min_pos.z > pos_find_minmax.z then
min_pos.z = pos_find_minmax.z
end
end
--Now that min_pos and max_pos have been calculated, they can be used to find fallable nodes
node_pos_to_fall = check_group_for_fall(min_pos, max_pos)
--Next, iterate through each of the newfound clump_fall_node positions, if any...
for v,pos_fall in pairs(node_pos_to_fall) do
--Used to store the node at the current position
local node_fall = minetest.get_node(pos_fall)
--Gets the metadata of the node at the current position
local meta = minetest.get_meta(pos_fall)
--Will be used to store any metadata in a table
local metatable = {}
--If there is any metadata, then
if meta ~= nil then
--Convert that metadata to a table and store it in metatable
metatable = meta:to_table()
end
--Make one more check in case the node at the current postion already fell or has otherwise been replaced
if minetest.get_item_group(node_fall.name, "clump_fall_node") ~= 0 then
--Finally, a falling_node is placed at the current position just as the node that used to be here is removed
minetest.remove_node(pos_fall)
spawn_falling_node(pos_fall, node_fall, metatable)
--Since a node has truly been found that needed to fall, found_no_fallable_nodes can be set to false
found_no_fallable_nodes = false
--Compares new_max_pos and new_min_pos to the location of each falling node, and individually sets the x, y, and z values of each to, respectively, the largest/smallest x/y/z values
if new_max_pos.x == nil or new_max_pos.x < pos_fall.x then
new_max_pos.x = pos_fall.x
end
if new_max_pos.y == nil or new_max_pos.y < pos_fall.y then
new_max_pos.y = pos_fall.y
end
if new_max_pos.z == nil or new_max_pos.z < pos_fall.z then
new_max_pos.z = pos_fall.z
end
if new_min_pos.x == nil or new_min_pos.x > pos_fall.x then
new_min_pos.x = pos_fall.x
end
if new_min_pos.y == nil or new_min_pos.y > pos_fall.y then
new_min_pos.y = pos_fall.y
end
if new_min_pos.z == nil or new_min_pos.z > pos_fall.z then
new_min_pos.z = pos_fall.z
end
end
end
--If nodes were found that need to fall in the next round of cascading, loop by calling this very method after 1 second of in-game time passes
if found_no_fallable_nodes == false then
--This will be used with the new min and max position that have been found.
--These are used instead of the old ones so that the range of cascading can't expand indefinitely and cause crashes
minetest.after(1, clump_fall, {new_min_pos, new_max_pos})
end
end
--[[
Description:
To be once immediately after initialization, this function iterates through every registered node, including those that were registered by other mods, and turns once that don't already fall by themselves into clump_fall_nodes
Parameters:
None
Returns:
Nothing
--]]
function make_nodes_fallable()
--Inspect each registered node, one at a time
for nodename, nodereal in pairs(minetest.registered_nodes) do
--create a temporary list of the current node's groups
local temp_node_group_list = nodereal.groups
--Ensure that the nodes being modified aren't the placeholder block types that tecnically don't exist
if nodename ~= "air" and nodename ~= "ignore" and
minetest.get_item_group(nodename, "falling_node") == 0 and --Don't need to affect nodes that already fall by themselves
minetest.get_item_group(nodename, "attached_node") == 0 and --Same thing for nodes in this group, which fall when no longer attached to another node
minetest.get_item_group(nodename, "liquid") == 0 and --Same thing for nodes in this group, which do technically fall and spread around
minetest.get_item_group(nodename, "unbreakable") == 0 and --Lastly, if a block is invulnerable to begin with, it shouldn't fall down like a typical node
minetest.get_item_group(nodename, "bed") == 0 then --Beds are able to create untouchable, solid nodes if they fall in a certain way (TODO: fix this)
--Initialize a new group variable in the temp list known as "clump_fall_node" as 1
temp_node_group_list.clump_fall_node = 1
--Override the node's previous group list with the one that includes the new clump_fall_node group
minetest.override_item(nodename, {groups = temp_node_group_list})
else
--For the rest, ensure that clump_fall_node is set to 0 and properly initialized
temp_node_group_list.clump_fall_node = 0
--Override the node's previous group list with the one that includes the new clump_fall_node group
minetest.override_item(nodename, {groups = temp_node_group_list})
end
end
end
--[[
Description:
Parameters:
pos: The postion to spawn the falling_node
node: The node itself to imitate (NOT its name or location)
meta: The metadata table to store information about the node to imitate, such as rotation and inventory
Returns:
Nothing
--]]
function spawn_falling_node(pos, node, meta)
--Create a __builtin:falling_node entity and add it to minetest
local entity_fall = minetest.add_entity(pos, "__builtin:falling_node")
--If successful, then
if entity_fall then
--Set its nodetype and metadata to the given arguments node and meta, respectively
entity_fall:get_luaentity():set_node(node, meta)
end
end
--After all nodes have been registered and 0 seconds have passed, run the make_nodes_fallable function
minetest.after(0, make_nodes_fallable)
--Set the clump_fall function to run at any postion where a node is dug, placed, or punched
minetest.register_on_dignode(clump_fall)
minetest.register_on_placenode(clump_fall)
minetest.register_on_punchnode(clump_fall)