Cranks, shafts, and spruce trees.

This commit is contained in:
Signal 2026-05-09 16:01:10 -04:00
parent 4659a008ac
commit 9011835cf4
40 changed files with 1496 additions and 104 deletions

350
mods/rgt_world/wood.lua Normal file
View file

@ -0,0 +1,350 @@
-- MARK: Helpers
local fence_nodebox = {
type = "connected",
fixed = {
-2/16, -0.5, -2/16,
2/16, 0.5, 2/16
},
connect_front = {
{
-1/16, -6/16, -0.5,
1/16, -2/16, 0
},
{
-1/16, 2/16, -0.5,
1/16, 6/16, 0
}
},
connect_back = {
{
-1/16, -6/16, 0,
1/16, -2/16, 0.5
},
{
-1/16, 2/16, 0,
1/16, 6/16, 0.5
}
},
connect_left = {
{
-0.5, -6/16, -1/16,
0, -2/16, 1/16
},
{
-0.5, 2/16, -1/16,
0, 6/16, 1/16
}
},
connect_right = {
{
0, -6/16, -1/16,
0.5, -2/16, 1/16
},
{
0, 2/16, -1/16,
0.5, 6/16, 1/16
}
},
}
local fence_gate_nodebox = {
type = "fixed",
fixed = {
{
-8/16, -7/16, -1/16,
-6/16, 7/16, 1/16
},
{
8/16, -7/16, -1/16,
6/16, 7/16, 1/16
},
{
-6/16, -6/16, -1/16,
6/16, -2/16, 1/16
},
{
-6/16, 2/16, -1/16,
6/16, 6/16, 1/16
}
}
}
local fence_gate_open_nodebox = {
type = "fixed",
fixed = {
{
-8/16, -7/16, -1/16,
-6/16, 7/16, 1/16
},
{
8/16, -7/16, -1/16,
6/16, 7/16, 1/16
},
{
-8/16, -6/16, 1/16,
-6/16, -2/16, 0.5
},
{
-8/16, 2/16, 1/16,
-6/16, 6/16, 0.5
},
{
8/16, -6/16, 1/16,
6/16, -2/16, 0.5
},
{
8/16, 2/16, 1/16,
6/16, 6/16, 0.5
},
}
}
local ladder_nodebox = {
type = "fixed",
fixed = {
{
-7/16, -0.5, 0.5,
-5/16, 0.5, 6/16
},
{
5/16, -0.5, 0.5,
7/16, 0.5, 6/16
},
{
-5/16, -7/16, 7.5/16,
5/16, -5/16, 6.5/16
},
{
-5/16, -3/16, 7.5/16,
5/16, -1/16, 6.5/16
},
{
-5/16, 1/16, 7.5/16,
5/16, 3/16, 6.5/16
},
{
-5/16, 5/16, 7.5/16,
5/16, 7/16, 6.5/16
},
}
}
local log_nodebox = {
type = "fixed",
fixed = {
{
-6/16, -0.5, -0.5,
6/16, 0.5, 0.5,
},
{
-0.5, -0.5, -6/16,
0.5, 0.5, 6/16,
}
}
}
function rgt.register_fence(name, texture)
rgt.register_node(name.."_fence", {
drawtype = "nodebox",
node_box = fence_nodebox,
connects_to = {"group:fence"},
paramtype = "light",
sunlight_propagates = true,
tiles = {{name = texture or "rgt_"..name.."_planks.png", align_style = "world"}},
groups = {dig_immediate = 3, fence = 1},
})
local function fence_gate_swap(pos, node, p)
if node.name:find "fence_gate_open" then
node.name = node.name:gsub("fence_gate_open", "fence_gate")
elseif node.name:find "fence_gate" then
node.name = node.name:gsub("fence_gate", "fence_gate_open")
local rot = minetest.fourdir_to_dir(node.param2)
-- Get the axis on which the gate will open.
local axis = rot.x ~= 0 and "x" or "z"
local dir = p:get_pos():direction(pos)
-- If the gate will open in the opposite direction from the player's facing direction, flip it.
if math.sign(dir[axis]) ~= math.sign(rot[axis]) then
node.param2 = (node.param2 +2) %4
end
end
minetest.swap_node(pos, node)
end
rgt.register_node(name.."_fence_gate", {
drawtype = "nodebox",
node_box = fence_gate_nodebox,
connects_to = {"group:fence"},
connect_sides = {"left", "right"},
paramtype = "light",
sunlight_propagates = true,
paramtype2 = "4dir",
tiles = {{name = "rgt_"..name.."_planks.png", align_style = "world"}},
groups = {dig_immediate = 3, fence = 1},
on_rightclick = fence_gate_swap,
})
rgt.register_node(name.."_fence_gate_open", {
drawtype = "nodebox",
node_box = fence_gate_open_nodebox,
connects_to = {"group:fence"},
connect_sides = {"left", "right"},
paramtype = "light",
sunlight_propagates = true,
paramtype2 = "4dir",
tiles = {{name = "rgt_"..name.."_planks.png", align_style = "world"}},
groups = {dig_immediate = 3, fence = 1},
on_rightclick = fence_gate_swap,
})
end
function rgt.register_ladder(name)
rgt.register_node(name.."_ladder", {
drawtype = "nodebox",
node_box = ladder_nodebox,
selection_box = {
type = "fixed",
fixed = {-7/16, -0.5, 0.5, 7/16, 0.5, 6/16}
},
paramtype = "light",
sunlight_propagates = true,
paramtype2 = "4dir",
climbable = true,
tiles = {{name = "rgt_"..name.."_planks.png", align_style = "world"}},
groups = {dig_immediate = 3, ladder = 1},
on_place = function(s, p, pt)
local under = minetest.get_node(pt.under)
-- If placing a ladder against a ladder, attempt to extend the pointed ladder rather than naively placing against it.
if under.name:find "ladder" then
local old_pt = table.copy(pt)
-- This will blow up for touchscreen users, but there's no way around it because they don't obey crosshair restrictions.
local iy = rgt.players[p:get_player_name()].pointed_node
-- `iy` can be nil in edge cases where the client clicked the node momentarily but is no longer pointing at the
-- node on the server when the message arrives and the server responds. In these cases, we just don't place anything
-- because we cannot determine the direction in which the player wishes to extend the ladder.
if not iy then return end
iy = iy.intersection_point.y
-- Try extending in the pointed direction first.
pt.above = pt.under:offset(0, iy -pt.under.y > 0 and 1 or -1, 0)
local s, success = minetest.item_place_node(s, p, pt, under.param2)
if success then return s end
-- If we can't, try extending in the other direction.
pt.above = pt.under:offset(0, iy -pt.under.y > 0 and -1 or 1, 0)
s, success = minetest.item_place_node(s, p, pt, under.param2)
if success then return s end
-- If that too fails, don't place anything. We could fall back to default placement, but that would make rapid laddering more annoying.
else
return minetest.item_place_node(s, p, pt)
end
end
})
end
-- MARK: Oak
rgt.register_node("oak_log", {
drawtype = "nodebox",
node_box = log_nodebox,
tiles = {"rgt_oak_log_top.png", "rgt_oak_log_top.png", "rgt_oak_log_side.png"},
groups = {dig_immediate = 3},
paramtype2 = "facedir",
})
rgt.register_node("oak_leaves", {
drawtype = "allfaces",
tiles = {"rgt_oak_leaves.png"},
use_texture_alpha = "clip",
groups = {dig_immediate = 3},
})
rgt.register_node("oak_planks", {
tiles = {{name = "rgt_oak_planks.png", align_style = "world"}},
_variants = "all",
groups = {dig_immediate = 3},
})
rgt.register_fence("oak")
rgt.register_ladder("oak")
-- MARK: Dark
rgt.register_node("dark_planks", {
tiles = {{name = "rgt_dark_planks.png", align_style = "world"}},
_variants = "all",
groups = {dig_immediate = 3},
})
rgt.register_fence("dark")
rgt.register_ladder("dark")
-- MARK: Spruce
rgt.register_node("spruce_log", {
drawtype = "nodebox",
node_box = log_nodebox,
tiles = {"rgt_spruce_log_top.png", "rgt_spruce_log_top.png", "rgt_spruce_log_side.png"},
groups = {dig_immediate = 3},
paramtype2 = "facedir",
})
rgt.register_node("spruce_planks", {
tiles = {{name = "rgt_spruce_planks.png", align_style = "world"}},
_variants = "all",
groups = {dig_immediate = 3},
})
rgt.register_node("spruce_leaves", {
drawtype = "allfaces",
tiles = {"rgt_spruce_leaves.png"},
use_texture_alpha = "clip",
groups = {dig_immediate = 3},
})
rgt.register_fence("spruce")
rgt.register_ladder("spruce")
-- MARK: Acacia
rgt.register_node("acacia_planks", {
tiles = {{name = "rgt_acacia_planks.png", align_style = "world"}},
_variants = "all",
groups = {dig_immediate = 3},
})
rgt.register_fence("acacia")
rgt.register_ladder("acacia")
-- MARK: Redwood
rgt.register_node("redwood_planks", {
tiles = {{name = "rgt_redwood_planks.png", align_style = "world"}},
_variants = "all",
groups = {dig_immediate = 3},
})
rgt.register_fence("redwood")
rgt.register_ladder("redwood")
-- MARK: Birch
rgt.register_node("birch_planks", {
tiles = {{name = "rgt_birch_planks.png", align_style = "world"}},
_variants = "all",
groups = {dig_immediate = 3},
})
rgt.register_fence("birch")
rgt.register_ladder("birch")