gates_long/init.lua
2025-08-22 02:32:06 +02:00

161 lines
5.8 KiB
Lua

-- Long Gates Mod
-- Version: 1.0
-- Depends: default
-- Original Author: (Falls bekannt, hier eintragen, oder deinen Namen)
-- Modified for 1.5 collision height by: (Dein Name/User)
gates_long = {}
gates_long.register_gate = function( type_name, desc, tiles, craft_from)
-- the closed version contains the string "fence" in its name - thus preventing mobs from jumping over
minetest.register_node("gates_long:fence_gate_closed_"..type_name, {
description = desc.." fence gate (closed)",
drawtype = "nodebox",
-- top, bottom, side1, side2, inner, outer
tiles = tiles,
paramtype = "light",
paramtype2 = "facedir",
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2, fence=1}, -- HINZUGEFÜGT: fence=1
node_box = { -- Diese Definition bleibt für das Aussehen des Tores
type = "fixed",
fixed = {
-- horizontal wood
{ -0.85, -0.25, -0.02, -0.005, -0.05, 0.02},
{ -0.85, 0.15, -0.02, -0.005, 0.35, 0.02},
{ 0.005, -0.25, -0.02, 0.85, -0.05, 0.02},
{ 0.005, 0.15, -0.02, 0.85, 0.35, 0.02},
-- vertical wood
{ -0.80, -0.05, -0.02, -0.60, 0.15, 0.02},
{ 0.60, -0.05, -0.02, 0.80, 0.15, 0.02},
{ -0.25, -0.05, -0.02, -0.05, 0.15, 0.02},
{ 0.05, -0.05, -0.02, 0.25, 0.15, 0.02},
-- locking mechanism (top)
{ -0.15, 0.32, -0.01, 0.15, 0.38, 0.01},
-- locking mechanism (bottom)
{ -0.15, -0.28, -0.01, 0.15, -0.22, 0.01},
-- hinges for the horizontal wood
{ -0.91, -0.24, -0.015, -0.84, -0.06, 0.015},
{ -0.91, 0.16, -0.015, -0.84, 0.34, 0.015},
{ 0.84, -0.24, -0.015, 0.91, -0.06, 0.015},
{ 0.84, 0.16, -0.015, 0.91, 0.34, 0.015},
},
},
-- NEU: Explizite Collision_box für 1.5 Blöcke Höhe
collision_box = {
type = "fixed",
fixed = {
-- {x1, y1, z1, x2, y2, z2}
-- y1 = -0.5 (Boden des Nodes)
-- y2 = 1.0 (entspricht -0.5 + 1.5 Höhe)
-- x und z Werte basieren auf der Breite/Tiefe der originalen Selection Box / Node_Box Ausdehnung
{ -0.85, -0.5, -0.05, 0.85, 1.0, 0.05}
}
},
selection_box = { -- Angepasst, um die neue Höhe widerzuspiegeln
type = "fixed",
fixed = {
-- x und z Werte wie oben, y von -0.5 bis 1.0
{ -0.85, -0.5, -0.1, 0.85, 1.0, 0.1},
},
},
on_rightclick = function(pos, node, puncher)
minetest.swap_node(pos, {name = "gates_long:gate_open_"..type_name, param2 = node.param2})
end,
is_ground_content = false,
})
-- the opened version allows cattle to pass (until it autocloses)
minetest.register_node("gates_long:gate_open_"..type_name, {
description = desc.." fence gate (open)",
drawtype = "nodebox",
-- top, bottom, side1, side2, inner, outer
tiles = tiles,
paramtype = "light",
paramtype2 = "facedir",
drop = "gates_long:fence_gate_closed_"..type_name,
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1},
node_box = {
type = "fixed",
fixed = {
-- horizontal wood
{ -0.87, -0.25, -0.02, -0.83, -0.05, 0.85},
{ -0.87, 0.15, -0.02, -0.83, 0.35, 0.85},
{ 0.83, -0.25, -0.02, 0.87, -0.05, 0.85},
{ 0.83, 0.15, -0.02, 0.87, 0.35, 0.85},
-- vertical wood
{ -0.87, -0.05, 0.80, -0.83, 0.15, 0.60},
{ -0.87, -0.05, 0.25, -0.83, 0.15, 0.05},
{ 0.83, -0.05, 0.80, 0.87, 0.15, 0.60},
{ 0.83, -0.05, 0.25, 0.87, 0.15, 0.05},
-- locking mechanism (top) - they are only on one side
{ -0.86, 0.32, 0.53, -0.84, 0.38, 0.83},
-- locking mechanism (bottom) - these as well
{ -0.86, -0.28, 0.53, -0.84, -0.22, 0.83},
-- hinges for the horizontal wood (they remain the same)
{ -0.91, -0.24, -0.015, -0.84, -0.06, 0.015},
{ -0.91, 0.16, -0.015, -0.84, 0.34, 0.015},
{ 0.84, -0.24, -0.015, 0.91, -0.06, 0.015},
{ 0.84, 0.16, -0.015, 0.91, 0.34, 0.015},
},
},
selection_box = { -- Diese Selection Box bleibt für das geöffnete Tor wie sie war (oder ggf. an das Aussehen anpassen)
type = "fixed",
fixed = {
{ -0.90, -0.25, 0, 0.90, 0.35, 0.50},
},
},
on_rightclick = function(pos, node, puncher)
minetest.swap_node(pos, {name = "gates_long:fence_gate_closed_"..type_name, param2 = node.param2})
end,
is_ground_content = false,
})
-- automaticly close the gates again to prevent cattle from escaping
minetest.register_abm({
nodenames = {"gates_long:gate_open_"..type_name},
interval = 5, -- Schließt alle 5 Sekunden
chance = 1, -- Mit einer Wahrscheinlichkeit von 1 (also immer, wenn der Check läuft)
action = function(pos, old_node)
minetest.swap_node(pos, {name = "gates_long:fence_gate_closed_"..type_name, param2 = old_node.param2})
end
})
minetest.register_craft({
output = "gates_long:fence_gate_closed_"..type_name.." 2",
recipe = {
{ "default:steel_ingot", craft_from, "default:steel_ingot" },
{ "", craft_from, "" },
}
})
end
-- Registrierung der verschiedenen Tortypen
gates_long.register_gate( 'wood', 'Wooden', {'default_wood.png'}, "default:wood" )
gates_long.register_gate( 'junglewood','Junglewood',{'default_junglewood.png'}, "default:junglewood" )
gates_long.register_gate( 'pine', 'Pine', {'default_pine_wood.png'}, "default:pine_wood" )
gates_long.register_gate( 'acacia', 'Acacia', {'default_acacia_wood.png'}, "default:acacia_wood" )
-- Der 'tree' Typ hier ist etwas ungewöhnlich, da er normalerweise für Stämme verwendet wird und nicht für Bretter.
-- Die Textur-Transformation [transformR90 deutet darauf hin, dass die Textur gedreht wird.
-- Stelle sicher, dass "default:tree" das Material ist, das du für diesen Tortyp verwenden möchtest.
gates_long.register_gate( 'tree', 'Tree Wood',{'default_tree.png^[transformR90'}, "default:tree" )
-- Optional: Nachricht beim Laden der Mod
minetest.log("action", "[MOD] Long Gates (gates_long) with 1.5 collision height loaded.")
-- Ende der Datei