mirror of
https://github.com/minetest/minetest_game.git
synced 2025-06-30 22:00:22 +02:00
Version MFF.
This commit is contained in:
305
mods/xpanes/init.lua
Normal file → Executable file
305
mods/xpanes/init.lua
Normal file → Executable file
@ -1,175 +1,174 @@
|
||||
xpanes = {}
|
||||
|
||||
local function rshift(x, by)
|
||||
return math.floor(x / 2 ^ by)
|
||||
local function is_pane(pos)
|
||||
return minetest.get_item_group(minetest.get_node(pos).name, "pane") > 0
|
||||
end
|
||||
|
||||
local directions = {
|
||||
{x = 1, y = 0, z = 0},
|
||||
{x = 0, y = 0, z = 1},
|
||||
{x = -1, y = 0, z = 0},
|
||||
{x = 0, y = 0, z = -1},
|
||||
}
|
||||
local function connects_dir(pos, name, dir)
|
||||
local aside = vector.add(pos, minetest.facedir_to_dir(dir))
|
||||
if is_pane(aside) then
|
||||
return true
|
||||
end
|
||||
|
||||
local function update_pane(pos,name)
|
||||
if minetest.get_node(pos).name:find("xpanes:"..name) == nil then
|
||||
return
|
||||
end
|
||||
local sum = 0
|
||||
for i = 1, 4 do
|
||||
local node = minetest.get_node({x = pos.x + directions[i].x, y = pos.y + directions[i].y, z = pos.z + directions[i].z})
|
||||
local pane_num = minetest.registered_nodes[node.name].groups.pane or 0
|
||||
if (minetest.registered_nodes[node.name].walkable ~= false and minetest.registered_nodes[node.name].drawtype ~= "nodebox") or pane_num > 0 then
|
||||
sum = sum + 2 ^ (i - 1)
|
||||
end
|
||||
end
|
||||
if sum == 0 then
|
||||
sum = 15
|
||||
end
|
||||
minetest.set_node(pos, {name = "xpanes:"..name.."_"..sum})
|
||||
local connects_to = minetest.registered_nodes[name].connects_to
|
||||
if not connects_to then
|
||||
return false
|
||||
end
|
||||
local list = minetest.find_nodes_in_area(aside, aside, connects_to)
|
||||
|
||||
if #list > 0 then
|
||||
return true
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
local function update_nearby(pos,n)
|
||||
if n == nil then n = minetest.get_node(pos) end
|
||||
if not n or not n.name then return end
|
||||
local name = string.sub(n.name,8,10)
|
||||
if name ~= "bar" then name = "pane" end
|
||||
for i = 1,4 do
|
||||
update_pane({x = pos.x + directions[i].x, y = pos.y + directions[i].y, z = pos.z + directions[i].z}, name)
|
||||
end
|
||||
local function swap(pos, node, name, param2)
|
||||
if node.name == name and node.param2 == param2 then
|
||||
return
|
||||
end
|
||||
|
||||
minetest.set_node(pos, {name = name, param2 = param2})
|
||||
end
|
||||
|
||||
local half_blocks = {
|
||||
{0, -0.5, -1/32, 0.5, 0.5, 1/32},
|
||||
{-1/32, -0.5, 0, 1/32, 0.5, 0.5},
|
||||
{-0.5, -0.5, -1/32, 0, 0.5, 1/32},
|
||||
{-1/32, -0.5, -0.5, 1/32, 0.5, 0}
|
||||
}
|
||||
local function update_pane(pos)
|
||||
if not is_pane(pos) then
|
||||
return
|
||||
end
|
||||
local node = minetest.get_node(pos)
|
||||
local name = node.name
|
||||
if name:sub(-5) == "_flat" then
|
||||
name = name:sub(1, -6)
|
||||
end
|
||||
|
||||
local full_blocks = {
|
||||
{-0.5, -0.5, -1/32, 0.5, 0.5, 1/32},
|
||||
{-1/32, -0.5, -0.5, 1/32, 0.5, 0.5}
|
||||
}
|
||||
local any = node.param2
|
||||
local c = {}
|
||||
local count = 0
|
||||
for dir = 0, 3 do
|
||||
c[dir] = connects_dir(pos, name, dir)
|
||||
if c[dir] then
|
||||
any = dir
|
||||
count = count + 1
|
||||
end
|
||||
end
|
||||
|
||||
local sb_half_blocks = {
|
||||
{0, -0.5, -0.06, 0.5, 0.5, 0.06},
|
||||
{-0.06, -0.5, 0, 0.06, 0.5, 0.5},
|
||||
{-0.5, -0.5, -0.06, 0, 0.5, 0.06},
|
||||
{-0.06, -0.5, -0.5, 0.06, 0.5, 0}
|
||||
}
|
||||
if count == 0 then
|
||||
swap(pos, node, name .. "_flat", any)
|
||||
elseif count == 1 then
|
||||
swap(pos, node, name .. "_flat", (any + 1) % 4)
|
||||
elseif count == 2 then
|
||||
if (c[0] and c[2]) or (c[1] and c[3]) then
|
||||
swap(pos, node, name .. "_flat", (any + 1) % 4)
|
||||
else
|
||||
swap(pos, node, name, 0)
|
||||
end
|
||||
else
|
||||
swap(pos, node, name, 0)
|
||||
end
|
||||
end
|
||||
|
||||
local sb_full_blocks = {
|
||||
{-0.5, -0.5, -0.06, 0.5, 0.5, 0.06},
|
||||
{-0.06, -0.5, -0.5, 0.06, 0.5, 0.5}
|
||||
}
|
||||
--register panes and bars
|
||||
minetest.register_on_placenode(function(pos, node)
|
||||
if minetest.get_item_group(node, "pane") then
|
||||
update_pane(pos)
|
||||
end
|
||||
for i = 0, 3 do
|
||||
local dir = minetest.facedir_to_dir(i)
|
||||
update_pane(vector.add(pos, dir))
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_on_dignode(function(pos)
|
||||
for i = 0, 3 do
|
||||
local dir = minetest.facedir_to_dir(i)
|
||||
update_pane(vector.add(pos, dir))
|
||||
end
|
||||
end)
|
||||
|
||||
xpanes = {}
|
||||
function xpanes.register_pane(name, def)
|
||||
for i = 1, 15 do
|
||||
local need = {}
|
||||
local cnt = 0
|
||||
for j = 1, 4 do
|
||||
if rshift(i, j - 1) % 2 == 1 then
|
||||
need[j] = true
|
||||
cnt = cnt + 1
|
||||
end
|
||||
end
|
||||
local take = {}
|
||||
local take2 = {}
|
||||
if need[1] == true and need[3] == true then
|
||||
need[1] = nil
|
||||
need[3] = nil
|
||||
table.insert(take, full_blocks[1])
|
||||
table.insert(take2, sb_full_blocks[1])
|
||||
end
|
||||
if need[2] == true and need[4] == true then
|
||||
need[2] = nil
|
||||
need[4] = nil
|
||||
table.insert(take, full_blocks[2])
|
||||
table.insert(take2, sb_full_blocks[2])
|
||||
end
|
||||
for k in pairs(need) do
|
||||
table.insert(take, half_blocks[k])
|
||||
table.insert(take2, sb_half_blocks[k])
|
||||
end
|
||||
local texture = def.textures[1]
|
||||
if cnt == 1 then
|
||||
texture = def.textures[1].."^"..def.textures[2]
|
||||
end
|
||||
minetest.register_node("xpanes:"..name.."_"..i, {
|
||||
drawtype = "nodebox",
|
||||
tiles = {def.textures[3], def.textures[3], texture},
|
||||
paramtype = "light",
|
||||
groups = def.groups,
|
||||
drop = "xpanes:"..name,
|
||||
sounds = def.sounds,
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = take
|
||||
},
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = take2
|
||||
}
|
||||
})
|
||||
for i = 1, 15 do
|
||||
minetest.register_alias("xpanes:" .. name .. "_" .. i, "xpanes:" .. name .. "_flat")
|
||||
end
|
||||
|
||||
local flatgroups = table.copy(def.groups)
|
||||
flatgroups.pane = 1
|
||||
minetest.register_node(":xpanes:" .. name .. "_flat", {
|
||||
description = def.description,
|
||||
drawtype = "nodebox",
|
||||
paramtype = "light",
|
||||
is_ground_content = false,
|
||||
sunlight_propagates = true,
|
||||
inventory_image = def.inventory_image,
|
||||
wield_image = def.wield_image,
|
||||
paramtype2 = "facedir",
|
||||
tiles = {def.textures[3], def.textures[3], def.textures[1]},
|
||||
groups = flatgroups,
|
||||
drop = "xpanes:" .. name .. "_flat",
|
||||
sounds = def.sounds,
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {{-1/2, -1/2, -1/32, 1/2, 1/2, 1/32}},
|
||||
},
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = {{-1/2, -1/2, -1/32, 1/2, 1/2, 1/32}},
|
||||
},
|
||||
connect_sides = { "left", "right" },
|
||||
})
|
||||
|
||||
local groups = table.copy(def.groups)
|
||||
groups.pane = 1
|
||||
groups.not_in_creative_inventory = 1
|
||||
minetest.register_node(":xpanes:" .. name, {
|
||||
drawtype = "nodebox",
|
||||
paramtype = "light",
|
||||
is_ground_content = false,
|
||||
sunlight_propagates = true,
|
||||
description = def.description,
|
||||
tiles = {def.textures[3], def.textures[3], def.textures[1]},
|
||||
groups = groups,
|
||||
drop = "xpanes:" .. name .. "_flat",
|
||||
sounds = def.sounds,
|
||||
node_box = {
|
||||
type = "connected",
|
||||
fixed = {{-1/32, -1/2, -1/32, 1/32, 1/2, 1/32}},
|
||||
connect_front = {{-1/32, -1/2, -1/2, 1/32, 1/2, -1/32}},
|
||||
connect_left = {{-1/2, -1/2, -1/32, -1/32, 1/2, 1/32}},
|
||||
connect_back = {{-1/32, -1/2, 1/32, 1/32, 1/2, 1/2}},
|
||||
connect_right = {{1/32, -1/2, -1/32, 1/2, 1/2, 1/32}},
|
||||
},
|
||||
connects_to = {"group:pane", "group:stone", "group:glass", "group:wood", "group:tree"},
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "xpanes:" .. name .. "_flat 16",
|
||||
recipe = def.recipe
|
||||
})
|
||||
end
|
||||
|
||||
minetest.register_node("xpanes:"..name, def)
|
||||
|
||||
minetest.register_craft({
|
||||
output = "xpanes:"..name.." 16",
|
||||
recipe = def.recipe
|
||||
})
|
||||
end
|
||||
|
||||
minetest.register_on_placenode(update_nearby)
|
||||
minetest.register_on_dignode(update_nearby)
|
||||
|
||||
xpanes.register_pane("pane", {
|
||||
description = "Glass Pane",
|
||||
tiles = {"xpanes_space.png"},
|
||||
drawtype = "airlike",
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
walkable = false,
|
||||
pointable = false,
|
||||
diggable = false,
|
||||
buildable_to = true,
|
||||
air_equivalent = true,
|
||||
textures = {"default_glass.png","xpanes_pane_half.png","xpanes_white.png"},
|
||||
inventory_image = "default_glass.png",
|
||||
wield_image = "default_glass.png",
|
||||
sounds = default.node_sound_glass_defaults(),
|
||||
groups = {snappy=2,cracky=3,oddly_breakable_by_hand=3,pane=1},
|
||||
on_construct = function(pos)
|
||||
update_pane(pos, "pane")
|
||||
end,
|
||||
recipe = {
|
||||
{'default:glass', 'default:glass', 'default:glass'},
|
||||
{'default:glass', 'default:glass', 'default:glass'}
|
||||
description = "Glass Pane",
|
||||
textures = {"default_glass.png","xpanes_pane_half.png","xpanes_white.png"},
|
||||
inventory_image = "default_glass.png",
|
||||
wield_image = "default_glass.png",
|
||||
sounds = default.node_sound_glass_defaults(),
|
||||
groups = {snappy=2, cracky=3, oddly_breakable_by_hand=3, pane=1},
|
||||
recipe = {
|
||||
{"default:glass", "default:glass", "default:glass"},
|
||||
{"default:glass", "default:glass", "default:glass"}
|
||||
}
|
||||
})
|
||||
|
||||
xpanes.register_pane("bar", {
|
||||
description = "Iron bar",
|
||||
tiles = {"xpanes_space.png"},
|
||||
drawtype = "airlike",
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
walkable = false,
|
||||
pointable = false,
|
||||
diggable = false,
|
||||
buildable_to = true,
|
||||
air_equivalent = true,
|
||||
textures = {"xpanes_bar.png","xpanes_bar.png","xpanes_space.png"},
|
||||
inventory_image = "xpanes_bar.png",
|
||||
wield_image = "xpanes_bar.png",
|
||||
groups = {snappy=2,cracky=3,oddly_breakable_by_hand=3,pane=1},
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
on_construct = function(pos)
|
||||
update_pane(pos, "bar")
|
||||
end,
|
||||
recipe = {
|
||||
{'default:steel_ingot', 'default:glass', 'default:glass'},
|
||||
{'default:glass', 'default:glass', 'default:glass'}
|
||||
description = "Iron bar",
|
||||
textures = {"xpanes_bar.png","xpanes_bar.png","xpanes_bar_top.png"},
|
||||
inventory_image = "xpanes_bar.png",
|
||||
wield_image = "xpanes_bar.png",
|
||||
groups = {cracky=3, pane=1}, -- //MFF
|
||||
sounds = default.node_sound_metal_defaults(),
|
||||
recipe = {
|
||||
{"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"},
|
||||
{"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"}
|
||||
}
|
||||
})
|
||||
|
||||
|
Reference in New Issue
Block a user