Merge pull request #18 from Treer/feature/portals-api-facedir-support

Add facedir support to Portals API
This commit is contained in:
Treer 2020-06-01 22:08:15 +10:00 committed by GitHub
commit 0e26770830
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 93 additions and 40 deletions

View File

@ -113,9 +113,28 @@ metadata).
]] ]]
local __ = {name = "air", prob = 0} local facedir_up, facedir_north, facedir_south, facedir_east, facedir_west, facedir_down = 0, 4, 8, 12, 16, 20
local AA = {name = "air", prob = 255, force_place = true}
local OO = {name = "default:obsidian", prob = 255, force_place = true} local __ = {name = "air", prob = 0}
local AA = {name = "air", prob = 255, force_place = true}
local ON = {name = "default:obsidian", facedir = facedir_north + 0, prob = 255, force_place = true}
local ON2 = {name = "default:obsidian", facedir = facedir_north + 1, prob = 255, force_place = true}
local ON3 = {name = "default:obsidian", facedir = facedir_north + 2, prob = 255, force_place = true}
local ON4 = {name = "default:obsidian", facedir = facedir_north + 3, prob = 255, force_place = true}
local OS = {name = "default:obsidian", facedir = facedir_south, prob = 255, force_place = true}
local OE = {name = "default:obsidian", facedir = facedir_east, prob = 255, force_place = true}
local OW = {name = "default:obsidian", facedir = facedir_west, prob = 255, force_place = true}
local OU = {name = "default:obsidian", facedir = facedir_up + 0, prob = 255, force_place = true}
local OU2 = {name = "default:obsidian", facedir = facedir_up + 1, prob = 255, force_place = true}
local OU3 = {name = "default:obsidian", facedir = facedir_up + 2, prob = 255, force_place = true}
local OU4 = {name = "default:obsidian", facedir = facedir_up + 3, prob = 255, force_place = true}
local OD = {name = "default:obsidian", facedir = facedir_down, prob = 255, force_place = true}
-- facedirNodeList is a list of node references which should have their facedir value copied into
-- param2 before placing a schematic. The facedir values will only be copied when the portal's frame
-- node has a paramtype2 of "facedir" or "colorfacedir".
-- Having schematics provide this list avoids needing to check every node in the schematic volume.
local facedirNodeList = {ON, ON2, ON3, ON4, OS, OE, OW, OU, OU2, OU3, OU4, OD}
-- This object defines a portal's shape, segregating the shape logic code from portal behaviour code. -- This object defines a portal's shape, segregating the shape logic code from portal behaviour code.
-- You can create a new "PortalShape" definition object which implements the same -- You can create a new "PortalShape" definition object which implements the same
@ -285,25 +304,26 @@ nether.PortalShape_Traditional = {
AA,AA,AA,AA, AA,AA,AA,AA,
AA,AA,AA,AA, AA,AA,AA,AA,
AA,AA,AA,AA, AA,AA,AA,AA,
OO,OO,OO,OO, ON,OW,OE,ON2,
OO,AA,AA,OO, OU,AA,AA,OU,
OO,AA,AA,OO, OU,AA,AA,OU,
OO,AA,AA,OO, OU,AA,AA,OU,
OO,OO,OO,OO, ON4,OE,OW,ON3,
__,__,__,__, __,__,__,__,
AA,AA,AA,AA, AA,AA,AA,AA,
AA,AA,AA,AA, AA,AA,AA,AA,
AA,AA,AA,AA, AA,AA,AA,AA,
AA,AA,AA,AA, AA,AA,AA,AA,
__,__,__,__, __,__,__,__,
AA,AA,AA,AA, AA,AA,AA,AA,
AA,AA,AA,AA, AA,AA,AA,AA,
AA,AA,AA,AA, AA,AA,AA,AA,
AA,AA,AA,AA, AA,AA,AA,AA,
} },
facedirNodes = facedirNodeList
} }
} -- End of PortalShape_Traditional class } -- End of PortalShape_Traditional class
@ -449,7 +469,7 @@ nether.PortalShape_Circular = {
__,__,AA,AA,AA,__,__, __,__,AA,AA,AA,__,__,
__,__,__,__,__,__,__, __,__,__,__,__,__,__,
__,__,__,__,__,__,__, __,__,__,__,__,__,__,
__,__,__,__,__,__,__, __,__,__,__,__,__,__,
__,AA,AA,AA,AA,AA,__, __,AA,AA,AA,AA,AA,__,
__,AA,AA,AA,AA,AA,__, __,AA,AA,AA,AA,AA,__,
@ -457,7 +477,7 @@ nether.PortalShape_Circular = {
__,AA,AA,AA,AA,AA,__, __,AA,AA,AA,AA,AA,__,
__,AA,AA,AA,AA,AA,__, __,AA,AA,AA,AA,AA,__,
__,__,__,__,__,__,__, __,__,__,__,__,__,__,
__,__,__,__,__,__,__, __,__,__,__,__,__,__,
__,AA,AA,AA,AA,AA,__, __,AA,AA,AA,AA,AA,__,
AA,AA,AA,AA,AA,AA,AA, AA,AA,AA,AA,AA,AA,AA,
@ -465,15 +485,15 @@ nether.PortalShape_Circular = {
AA,AA,AA,AA,AA,AA,AA, AA,AA,AA,AA,AA,AA,AA,
__,AA,AA,AA,AA,AA,__, __,AA,AA,AA,AA,AA,__,
__,__,AA,AA,AA,__,__, __,__,AA,AA,AA,__,__,
__,__,OO,OO,OO,__,__, __,__,OW,OW,OW,__,__,
__,OO,AA,AA,AA,OO,__, __,ON,AA,AA,AA,ON2,__,
OO,AA,AA,AA,AA,AA,OO, OU,AA,AA,AA,AA,AA,OD,
OO,AA,AA,AA,AA,AA,OO, OU,AA,AA,AA,AA,AA,OD,
OO,AA,AA,AA,AA,AA,OO, OU,AA,AA,AA,AA,AA,OD,
__,OO,AA,AA,AA,OO,__, __,ON4,AA,AA,AA,ON3,__,
__,__,OO,OO,OO,__,__, __,__,OE,OE,OE,__,__,
__,__,__,__,__,__,__, __,__,__,__,__,__,__,
__,AA,AA,AA,AA,AA,__, __,AA,AA,AA,AA,AA,__,
AA,AA,AA,AA,AA,AA,AA, AA,AA,AA,AA,AA,AA,AA,
@ -481,7 +501,7 @@ nether.PortalShape_Circular = {
AA,AA,AA,AA,AA,AA,AA, AA,AA,AA,AA,AA,AA,AA,
__,AA,AA,AA,AA,AA,__, __,AA,AA,AA,AA,AA,__,
__,__,AA,AA,AA,__,__, __,__,AA,AA,AA,__,__,
__,__,__,__,__,__,__, __,__,__,__,__,__,__,
__,AA,AA,AA,AA,AA,__, __,AA,AA,AA,AA,AA,__,
__,AA,AA,AA,AA,AA,__, __,AA,AA,AA,AA,AA,__,
@ -497,7 +517,8 @@ nether.PortalShape_Circular = {
__,__,AA,AA,AA,__,__, __,__,AA,AA,AA,__,__,
__,__,__,__,__,__,__, __,__,__,__,__,__,__,
__,__,__,__,__,__,__, __,__,__,__,__,__,__,
} },
facedirNodes = facedirNodeList
} }
} -- End of PortalShape_Circular class } -- End of PortalShape_Circular class
@ -597,35 +618,36 @@ nether.PortalShape_Platform = {
size = {x = 5, y = 5, z = 5}, size = {x = 5, y = 5, z = 5},
data = { -- note that data is upside down data = { -- note that data is upside down
__,__,__,__,__, __,__,__,__,__,
OO,OO,OO,OO,OO, OU4,OW,OW,OW,OU3,
__,AA,AA,AA,__, __,AA,AA,AA,__,
__,AA,AA,AA,__, __,AA,AA,AA,__,
__,__,__,__,__, __,__,__,__,__,
__,OO,OO,OO,__, __,OU4,OW,OU3,__,
OO,AA,AA,AA,OO, ON,AA,AA,AA,OS,
AA,AA,AA,AA,AA, AA,AA,AA,AA,AA,
AA,AA,AA,AA,AA, AA,AA,AA,AA,AA,
__,AA,AA,AA,__, __,AA,AA,AA,__,
__,OO,OO,OO,__, __,ON,OD,OS,__,
OO,AA,AA,AA,OO, ON,AA,AA,AA,OS,
AA,AA,AA,AA,AA, AA,AA,AA,AA,AA,
AA,AA,AA,AA,AA, AA,AA,AA,AA,AA,
__,AA,AA,AA,__, __,AA,AA,AA,__,
__,OO,OO,OO,__, __,OU,OE,OU2,__,
OO,AA,AA,AA,OO, ON,AA,AA,AA,OS,
AA,AA,AA,AA,AA, AA,AA,AA,AA,AA,
AA,AA,AA,AA,AA, AA,AA,AA,AA,AA,
__,AA,AA,AA,__, __,AA,AA,AA,__,
__,__,__,__,__, __,__,__,__,__,
OO,OO,OO,OO,OO, OU,OE,OE,OE,OU2,
__,AA,AA,AA,__, __,AA,AA,AA,__,
__,AA,AA,AA,__, __,AA,AA,AA,__,
__,__,__,__,__, __,__,__,__,__,
} },
facedirNodes = facedirNodeList
} }
} -- End of PortalShape_Platform class } -- End of PortalShape_Platform class
@ -1137,8 +1159,29 @@ local function is_within_portal_frame(portal_definition, pos)
end end
-- sets param2 values in the schematic to match facedir values, or 0 if the portalframe-nodedef doesn't use facedir
local function set_schematic_param2(schematic_table, frame_node_name, frame_node_color)
local paramtype2 = minetest.registered_nodes[frame_node_name].paramtype2
local isFacedir = paramtype2 == "facedir" or paramtype2 == "colorfacedir"
if schematic_table.facedirNodes ~= nil then
for _, node in ipairs(schematic_table.facedirNodes) do
if isFacedir and node.facedir ~= nil then
-- frame_node_color can be nil
local colorBits = (frame_node_color or math.floor((node.param2 or 0) / 32)) * 32
node.param2 = node.facedir + colorBits
else
node.param2 = 0
end
end
end
end
local function build_portal(portal_definition, anchorPos, orientation, destination_wormholePos) local function build_portal(portal_definition, anchorPos, orientation, destination_wormholePos)
set_schematic_param2(portal_definition.shape.schematic, portal_definition.frame_node_name, portal_definition.frame_node_color)
minetest.place_schematic( minetest.place_schematic(
portal_definition.shape.get_schematicPos_from_anchorPos(anchorPos, orientation), portal_definition.shape.get_schematicPos_from_anchorPos(anchorPos, orientation),
portal_definition.shape.schematic, portal_definition.shape.schematic,
@ -1178,8 +1221,8 @@ local function remote_portal_checkup(elapsed, portal_definition, anchorPos, orie
local wormholePos = portal_definition.shape.get_wormholePos_from_anchorPos(anchorPos, orientation) local wormholePos = portal_definition.shape.get_wormholePos_from_anchorPos(anchorPos, orientation)
local wormhole_node = minetest.get_node_or_nil(wormholePos) local wormhole_node = minetest.get_node_or_nil(wormholePos)
local portalFound, portalLit = false, false local portalFound, portalLit = false, false
if wormhole_node ~= nil and wormhole_node.name == portal_definition.wormhole_node_name then if wormhole_node ~= nil and wormhole_node.name == portal_definition.wormhole_node_name then
-- a wormhole node was there, but check the whole frame is intact -- a wormhole node was there, but check the whole frame is intact
portalFound, portalLit = is_portal_at_anchorPos(portal_definition, anchorPos, orientation, false) portalFound, portalLit = is_portal_at_anchorPos(portal_definition, anchorPos, orientation, false)
end end
@ -1864,6 +1907,10 @@ function test_portaldef_is_valid(portal_definition)
assert(portal_definition.wormhole_node_color >= 0 and portal_definition.wormhole_node_color < 8, "portaldef.wormhole_node_color must be between 0 and 7 (inclusive)") assert(portal_definition.wormhole_node_color >= 0 and portal_definition.wormhole_node_color < 8, "portaldef.wormhole_node_color must be between 0 and 7 (inclusive)")
assert(portal_definition.is_within_realm ~= nil, "portaldef.is_within_realm() must be implemented") assert(portal_definition.is_within_realm ~= nil, "portaldef.is_within_realm() must be implemented")
assert(portal_definition.find_realm_anchorPos ~= nil, "portaldef.find_realm_anchorPos() must be implemented") assert(portal_definition.find_realm_anchorPos ~= nil, "portaldef.find_realm_anchorPos() must be implemented")
if portal_definition.frame_node_color ~= nil then
assert(portal_definition.frame_node_color >= 0 and portal_definition.frame_node_color < 8, "portal_definition.frame_node_color must be between 0 and 7 (inclusive)")
end
-- todo -- todo
return result return result

View File

@ -115,6 +115,12 @@ Used by `nether.register_portal`.
-- Required. For best results, have your portal constructed of a -- Required. For best results, have your portal constructed of a
-- material nobody else is using. -- material nobody else is using.
frame_node_color = 0,
-- Optional.
-- A value from 0 to 7. Only used if the frame node's paramtype2 is
-- "colorfacedir", in which case this color will be used when a remote
-- portal is created.
shape = nether.PortalShape_Traditional, shape = nether.PortalShape_Traditional,
-- Optional. -- Optional.
-- Shapes available are: -- Shapes available are: