Update copyrights & require Minetest v0.4.16 or greater

Also adds nether.register_wormhole_node(), moving the wormhole node template into portal_api.lua, and allowing wormhole nodes with custom post_effect_color to be more easily created.
This commit is contained in:
Treer 2020-01-08 20:06:00 +11:00 committed by SmallJoker
parent 3945467152
commit 1d19546345
4 changed files with 166 additions and 75 deletions

View File

@ -1,70 +1,40 @@
--[[
Nether mod for minetest
Copyright (C) 2013 PilzAdam
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR
BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.
]]--
local S = nether.get_translator local S = nether.get_translator
-- Portal node -- Portal/wormhole node
minetest.register_node("nether:portal", { nether.register_wormhole_node("nether:portal", {
description = S("Nether Portal"), description = S("Nether Portal"),
tiles = {
"nether_transparent.png",
"nether_transparent.png",
"nether_transparent.png",
"nether_transparent.png",
{
name = "nether_portal.png",
animation = {
type = "vertical_frames",
aspect_w = 16,
aspect_h = 16,
length = 0.5,
},
},
{
name = "nether_portal.png",
animation = {
type = "vertical_frames",
aspect_w = 16,
aspect_h = 16,
length = 0.5,
},
},
},
drawtype = "nodebox",
paramtype = "light",
paramtype2 = "colorfacedir",
palette = "nether_portals_palette.png",
post_effect_color = { post_effect_color = {
-- post_effect_color can't be changed dynamically in Minetest like the portal colour is. -- post_effect_color can't be changed dynamically in Minetest like the portal colour is.
-- If you need a different post_effect_color then create a custom node and set it as the -- If you need a different post_effect_color then use register_wormhole_node to create
-- wormhole_node_name in your portaldef. -- another wormhole node and set it as the wormhole_node_name in your portaldef.
-- Hopefully this colour is close enough to magenta to work with the traditional magenta -- Hopefully this colour is close enough to magenta to work with the traditional magenta
-- portals, close enough to red to work for a red portal, and also close enough to red to -- portals, close enough to red to work for a red portal, and also close enough to red to
-- work with blue & cyan portals - since blue portals are sometimes portrayed as being red -- work with blue & cyan portals - since blue portals are sometimes portrayed as being red
-- from the opposite side / from the inside. -- from the opposite side / from the inside.
a = 160, r = 128, g = 0, b = 80 a = 160, r = 128, g = 0, b = 80
}, }
sunlight_propagates = true,
use_texture_alpha = true,
walkable = false,
diggable = false,
pointable = false,
buildable_to = false,
is_ground_content = false,
drop = "",
light_source = 5,
alpha = 192,
node_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.1, 0.5, 0.5, 0.1},
},
},
groups = {not_in_creative_inventory = 1},
mesecons = {receptor = {
state = "on",
rules = function(node)
return nether.get_mesecon_emission_rules_from_colorfacedir(node.param2)
end
}}
}) })

View File

@ -1,6 +1,30 @@
-- see portal_api.txt for documentation --[[
Portal API for Minetest
See portal_api.txt for documentation
--
Copyright (C) 2020 Treer
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR
BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.
]]--
local DEBUG = false local DEBUG = false
local IGNORE_MODSTORAGE_PORTALS = false -- set true if you don't want portals to remember where they were linked - sometimes it's handy for debugging to have the portal always recalculate its target local DEBUG_IGNORE_MODSTORAGE = false -- setting true prevents portals from knowing where other portals are, forcing find_realm_anchorpos() etc. to be executed every time
nether.registered_portals = {} nether.registered_portals = {}
@ -18,6 +42,10 @@ nether.portals_palette = {
} }
if minetest.get_mod_storage == nil then
error(nether.modname .. " does not support Minetest versions earlier than 0.4.16", 0)
end
--[[ --[[
Positions Positions
@ -619,7 +647,7 @@ end
-- Add portal information to mod storage, so new portals may find existing portals near the target location. -- Add portal information to mod storage, so new portals may find existing portals near the target location.
-- Do this whenever a portal is created or changes its ignition state -- Do this whenever a portal is created or changes its ignition state
local function store_portal_location_info(portal_name, anchorPos, orientation, ignited) local function store_portal_location_info(portal_name, anchorPos, orientation, ignited)
if not IGNORE_MODSTORAGE_PORTALS then if not DEBUG_IGNORE_MODSTORAGE then
mod_storage:set_string( mod_storage:set_string(
minetest.pos_to_string(anchorPos) .. " is " .. portal_name, minetest.pos_to_string(anchorPos) .. " is " .. portal_name,
minetest.serialize({orientation = orientation, active = ignited}) minetest.serialize({orientation = orientation, active = ignited})
@ -630,7 +658,7 @@ end
-- Remove portal information from mod storage. -- Remove portal information from mod storage.
-- Do this if a portal frame is destroyed such that it cannot be ignited anymore. -- Do this if a portal frame is destroyed such that it cannot be ignited anymore.
local function remove_portal_location_info(portal_name, anchorPos) local function remove_portal_location_info(portal_name, anchorPos)
if not IGNORE_MODSTORAGE_PORTALS then if not DEBUG_IGNORE_MODSTORAGE then
mod_storage:set_string(minetest.pos_to_string(anchorPos) .. " is " .. portal_name, "") mod_storage:set_string(minetest.pos_to_string(anchorPos) .. " is " .. portal_name, "")
end end
end end
@ -649,7 +677,7 @@ local function list_closest_portals(portal_definition, anchorPos, distance_limit
local result = {} local result = {}
if not IGNORE_MODSTORAGE_PORTALS then if not DEBUG_IGNORE_MODSTORAGE then
local isRealm = portal_definition.is_within_realm(anchorPos) local isRealm = portal_definition.is_within_realm(anchorPos)
if distance_limit == nil then distance_limit = -1 end if distance_limit == nil then distance_limit = -1 end
@ -1618,6 +1646,85 @@ minetest.register_lbm({
-- ==================== -- -- ==================== --
-- the fallback defaults for wormhole nodedefs
local wormhole_nodedef_default = {
description = S("Portal wormhole"),
tiles = {
"nether_transparent.png",
"nether_transparent.png",
"nether_transparent.png",
"nether_transparent.png",
{
name = "nether_portal.png",
animation = {
type = "vertical_frames",
aspect_w = 16,
aspect_h = 16,
length = 0.5,
},
},
{
name = "nether_portal.png",
animation = {
type = "vertical_frames",
aspect_w = 16,
aspect_h = 16,
length = 0.5,
},
},
},
drawtype = "nodebox",
paramtype = "light",
paramtype2 = "colorfacedir",
palette = "nether_portals_palette.png",
post_effect_color = {
-- post_effect_color can't be changed dynamically in Minetest like the portal colour is.
-- If you need a different post_effect_color then use register_wormhole_node() to create
-- another wormhole node with the right post_effect_color and set it as the wormhole_node_name
-- in your portaldef.
-- Hopefully this colour is close enough to magenta to work with the traditional magenta
-- portals, close enough to red to work for a red portal, and also close enough to red to
-- work with blue & cyan portals - since blue portals are sometimes portrayed as being red
-- from the opposite side / from the inside.
a = 160, r = 128, g = 0, b = 80
},
sunlight_propagates = true,
use_texture_alpha = true,
walkable = false,
diggable = false,
pointable = false,
buildable_to = false,
is_ground_content = false,
drop = "",
light_source = 5,
alpha = 192,
node_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.1, 0.5, 0.5, 0.1},
},
},
groups = {not_in_creative_inventory = 1},
mesecons = {receptor = {
state = "on",
rules = function(node)
return nether.get_mesecon_emission_rules_from_colorfacedir(node.param2)
end
}}
}
-- Call only at load time
function nether.register_wormhole_node(name, nodedef)
assert(name ~= nil, "Unable to register wormhole node: Name is nil")
assert(nodedef ~= nil, "Unable to register wormhole node ''" .. name .. "'': nodedef is nil")
for key, value in pairs(wormhole_nodedef_default) do
if nodedef[key] == nil then nodedef[key] = value end
end
minetest.register_node(name, nodedef)
end
-- The fallback defaults for registered portaldef tables -- The fallback defaults for registered portaldef tables
local portaldef_default = { local portaldef_default = {
shape = nether.PortalShape_Traditional, shape = nether.PortalShape_Traditional,

View File

@ -74,18 +74,28 @@ Call these functions only at load time:
clashes with a portal already registered by another mod, e.g. if the size clashes with a portal already registered by another mod, e.g. if the size
and frame node is not unique. and frame node is not unique.
A false return value should be handled, you could: A false return value should be handled, you could:
* Fall back to using a secondary material for portals to be built with. * Fall back to using a secondary material for portals to be built with.
* Use error() to exit lua with a message explaining how two mods are * Use error() to exit lua with a message explaining how two mods are
clashing and how it can be resolved. clashing and how it can be resolved.
* Continue without a portal (the reason will be logged for the user). * Continue without a portal (the reason will be logged for the user).
* `nether.unregister_portal(name)` * `nether.unregister_portal(name)`
* Unregisters the portal from the engine, and deletes the entry with key * Unregisters the portal from the engine, and deletes the entry with key
`name` from `nether.registered_portals` and associated internal tables. `name` from `nether.registered_portals` and associated internal tables.
* Returns true on success * Returns true on success
* register_portal_ignition_item(name, ignition_failure_sound) * You will probably never need to call this, it exists only for completeness.
* `nether.register_portal_ignition_item(name, ignition_failure_sound)`
* ignition_failure_sound is optional, it plays any time an attempt to use * ignition_failure_sound is optional, it plays any time an attempt to use
the item occurs if a portal is not ignited. the item occurs if a portal is not ignited.
* `nether.register_wormhole_node(name, nodedef_overrides)`
* Can be used to register wormhole nodes with a different post_effect_color
from the "nether:portal" node. "Post effect color" is the tint the world
takes on when you are standing inside a portal. `post_effect_color` is the
only key/value that is needed in the nodedef_overrides table to achieve that,
but the function allows any nodedef key/value to be specified/overridden.
* Invokes `minetest.register_node()`, so can only be called at mod load time.
* After `register_wormhole_node()`, invoke `register_portal()` and include
`wormhole_node_name` in the portal_definition, assigning it the name of the
new wormhole node.
Portal definition Portal definition

View File

@ -1,13 +1,16 @@
--[[ --[[
Nether mod portal examples for Minetest Nether mod portal examples for Minetest
These portal API examples work independently of the Nether realm and Nether portal. These portal API examples work independently of the Nether realm
To try these examples, enable them in Mintest -> Settings -> All settings -> Mods -> nether and Nether portal. To try these examples, enable them in:
Once enabled, their shapes/plans will be shown in the book of portals. Mintest -> Settings -> All settings -> Mods -> nether
Once enabled, details on how to build them can be found in dungeon
chests in the book of portals.
-- --
Copyright (C) 2019 Treer Copyright (C) 2020 Treer
Permission to use, copy, modify, and/or distribute this software for Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the any purpose with or without fee is hereby granted, provided that the
@ -61,7 +64,7 @@ if minetest.settings:get_bool("nether_enable_portal_example_floatlands", ENABLE_
nether.register_portal("floatlands_portal", { nether.register_portal("floatlands_portal", {
shape = nether.PortalShape_Platform, shape = nether.PortalShape_Platform,
frame_node_name = "default:ice", frame_node_name = "default:ice",
wormhole_node_color = 7, -- 2 is blue wormhole_node_color = 7, -- 7 is white
particle_texture = { particle_texture = {
name = "nether_particle_anim1.png", name = "nether_particle_anim1.png",
animation = { animation = {
@ -146,7 +149,7 @@ if minetest.settings:get_bool("nether_enable_portal_example_surfacetravel", ENAB
is_within_realm = function(pos) is_within_realm = function(pos)
-- Always return true, because these portals always just take you around the surface -- Always return true, because these portals always just take you around the surface
-- rather than taking you to a realm -- rather than taking you to a different realm
return true return true
end, end,
@ -185,7 +188,8 @@ if minetest.settings:get_bool("nether_enable_portal_example_surfacetravel", ENAB
-- use the existing portal that was found near target_x, target_z -- use the existing portal that was found near target_x, target_z
return existing_portal_location, existing_portal_orientation return existing_portal_location, existing_portal_orientation
else else
-- find a good location for the new portal -- find a good location for the new portal, or if that isn't possible then at
-- least adjust the coords a little so portals don't line up in a grid
local adj_x, adj_z = 0, 0 local adj_x, adj_z = 0, 0
if minetest.get_spawn_level ~= nil then -- older versions of Minetest don't have this if minetest.get_spawn_level ~= nil then -- older versions of Minetest don't have this
@ -198,7 +202,7 @@ if minetest.settings:get_bool("nether_enable_portal_example_surfacetravel", ENAB
minetest.get_mapgen_setting("seed") * 3 minetest.get_mapgen_setting("seed") * 3
) )
local attemptLimit = 12 -- how many attempts we'll make at finding a good location local attemptLimit = 15 -- how many attempts we'll make at finding a good location
for attempt = 1, attemptLimit do for attempt = 1, attemptLimit do
adj_x = math.floor(prng:rand_normal_dist(-search_radius, search_radius, 2) + 0.5) adj_x = math.floor(prng:rand_normal_dist(-search_radius, search_radius, 2) + 0.5)
adj_z = math.floor(prng:rand_normal_dist(-search_radius, search_radius, 2) + 0.5) adj_z = math.floor(prng:rand_normal_dist(-search_radius, search_radius, 2) + 0.5)