1
0
Fork 0

New xpanes code from Minetest Game 0.4.15-dev

This commit is contained in:
Wuzzy 2017-01-09 13:39:36 +01:00
parent 985df03240
commit 4460725acb
3 changed files with 175 additions and 117 deletions

View File

@ -764,6 +764,9 @@ function default.node_sound_stone_defaults(table)
return table return table
end end
-- TODO: Maybe add custom metal sounds
default.node_sound_metal_defaults = default.node_sound_stone_defaults
function default.node_sound_dirt_defaults(table) function default.node_sound_dirt_defaults(table)
table = table or {} table = table or {}
table.footstep = table.footstep or table.footstep = table.footstep or

1
mods/xpanes/depends.txt Normal file
View File

@ -0,0 +1 @@
default

View File

@ -1,140 +1,194 @@
-- xPanes mod by xyz custom by davedevils
function pane(node, desc, dropitem, recipeitem, color) local function is_pane(pos)
local function rshift(x, by) return minetest.get_item_group(minetest.get_node(pos).name, "pane") > 0
return math.floor(x / 2 ^ by)
end end
local directions = { local function connects_dir(pos, name, dir)
{x = 1, y = 0, z = 0}, local aside = vector.add(pos, minetest.facedir_to_dir(dir))
{x = 0, y = 0, z = 1}, if is_pane(aside) then
{x = -1, y = 0, z = 0}, return true
{x = 0, y = 0, z = -1}, end
}
local function update_pane(pos) local connects_to = minetest.registered_nodes[name].connects_to
if minetest.env:get_node(pos).name:find("xpanes:pane_"..node..""..color) == nil then 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 swap(pos, node, name, param2)
if node.name == name and node.param2 == param2 then
return return
end end
local sum = 0
for i = 1, 4 do minetest.set_node(pos, {name = name, param2 = param2})
local node = minetest.env:get_node({x = pos.x + directions[i].x, y = pos.y + directions[i].y, z = pos.z + directions[i].z})
if minetest.registered_nodes[node.name].walkable ~= false then
sum = sum + 2 ^ (i - 1)
end
end
if sum == 0 then
sum = 15
end
minetest.env:add_node(pos, {name = "xpanes:pane_"..node..""..color.."_"..sum})
end end
local function update_nearby(pos) local function update_pane(pos)
for i = 1,4 do if not is_pane(pos) then
update_pane({x = pos.x + directions[i].x, y = pos.y + directions[i].y, z = pos.z + directions[i].z}) 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 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
end end
local half_blocks = { if count == 0 then
{0, -0.5, -0.06, 0.5, 0.5, 0.06}, swap(pos, node, name .. "_flat", any)
{-0.06, -0.5, 0, 0.06, 0.5, 0.5}, elseif count == 1 then
{-0.5, -0.5, -0.06, 0, 0.5, 0.06}, swap(pos, node, name .. "_flat", (any + 1) % 4)
{-0.06, -0.5, -0.5, 0.06, 0.5, 0} 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 full_blocks = { minetest.register_on_placenode(function(pos, node)
{-0.5, -0.5, -0.06, 0.5, 0.5, 0.06}, if minetest.get_item_group(node, "pane") then
{-0.06, -0.5, -0.5, 0.06, 0.5, 0.5} 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 for i = 1, 15 do
local need = {} minetest.register_alias("xpanes:" .. name .. "_" .. i, "xpanes:" .. name .. "_flat")
local cnt = 0
for j = 1, 4 do
if rshift(i, j - 1) % 2 == 1 then
need[j] = true
cnt = cnt + 1
end end
end
local take = {} local flatgroups = table.copy(def.groups)
if need[1] == true and need[3] == true then flatgroups.pane = 1
need[1] = nil minetest.register_node(":xpanes:" .. name .. "_flat", {
need[3] = nil description = def.description,
table.insert(take, 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])
end
for k in pairs(need) do
table.insert(take, half_blocks[k])
end
local texture = "xpanes_pane_"..node..""..color..".png"
if cnt == 1 then
texture = "xpanes_pane_half_"..node..""..color..".png"
end
minetest.register_node("xpanes:pane_"..node..""..color.."_"..i, {
drawtype = "nodebox", drawtype = "nodebox",
tile_images = {"xpanes_top_"..node..""..color..".png", "xpanes_top_"..node..""..color..".png", texture},
paramtype = "light", paramtype = "light",
use_texture_alpha = true,
is_ground_content = false, is_ground_content = false,
groups = {snappy=2,cracky=3,oddly_breakable_by_hand=3}, sunlight_propagates = true,
drop = dropitem, 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 = { node_box = {
type = "fixed", type = "fixed",
fixed = take fixed = {{-1/2, -1/2, -1/32, 1/2, 1/2, 1/32}},
}, },
selection_box = { selection_box = {
type = "fixed", type = "fixed",
fixed = take fixed = {{-1/2, -1/2, -1/32, 1/2, 1/2, 1/32}},
} },
connect_sides = { "left", "right" },
}) })
end
minetest.register_node("xpanes:pane_"..node..""..color, { local groups = table.copy(def.groups)
description = desc, groups.pane = 1
tile_images = {"xpanes_pane_"..node..""..color..".png"}, groups.not_in_creative_inventory = 1
inventory_image = "xpanes_pane_"..node..""..color..".png", minetest.register_node(":xpanes:" .. name, {
is_ground_content = false, drawtype = "nodebox",
paramtype = "light", paramtype = "light",
stack_max = 64, is_ground_content = false,
use_texture_alpha = true, sunlight_propagates = true,
wield_image = "xpanes_pane_"..node..""..color..".png", description = def.description,
node_placement_prediction = "", tiles = {def.textures[3], def.textures[3], def.textures[1]},
on_construct = update_pane, groups = groups,
drop = "", 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_on_placenode(update_nearby)
minetest.register_on_dignode(update_nearby)
minetest.register_craft({ minetest.register_craft({
output = 'xpanes:pane_'..node..''..color..' 16', output = "xpanes:" .. name .. "_flat 16",
recipe = def.recipe
})
end
local pane = function(description, node, append)
xpanes.register_pane("pane"..append, {
description = description,
textures = {"xpanes_pane_glass"..append..".png","xpanes_pane_half_glass"..append..".png","xpanes_top_glass"..append..".png"},
inventory_image = "xpanes_pane_glass"..append..".png",
wield_image = "xpanes_pane_glass"..append..".png",
sounds = default.node_sound_glass_defaults(),
groups = {snappy=2, cracky=3, oddly_breakable_by_hand=3},
recipe = { recipe = {
{recipeitem, recipeitem, recipeitem}, {node, node, node},
{recipeitem, recipeitem, recipeitem} {node, node, node},
} }
}) })
end end
-- Glass
pane("glass", "Glass Pane", "", "default:glass", "_natural")
pane("glass", "Red Stained Glass Pane", "", "default:glass_red", "_red")
pane("glass", "Green Stained Glass Pane", "", "default:glass_green", "_green")
pane("glass", "Blue Stained Glass Pane", "", "default:glass_blue", "_blue")
pane("glass", "Light Blue Stained Glass Pane", "", "default:glass_light_blue", "_light_blue")
pane("glass", "Black Stained Glass Pane", "", "default:glass_black", "_black")
pane("glass", "White Stained Glass Pane", "", "default:glass_white", "_white")
pane("glass", "Yellow Stained Glass Pane", "", "default:glass_yellow", "_yellow")
pane("glass", "Brown Stained Glass Pane", "", "default:glass_brown", "_brown")
pane("glass", "Orange Stained Glass Pane", "", "default:glass_orange", "_orange")
pane("glass", "Pink Stained Glass Pane", "", "default:glass_pink", "_pink")
pane("glass", "Gray Stained Glass Pane", "", "default:glass_gray", "_gray")
pane("glass", "Lime Stained Glass Pane", "", "default:glass_lime", "_lime")
pane("glass", "Light Gray Stained Glass Pane", "", "default:glass_silver", "_silver")
pane("glass", "Magenta Stained Glass Pane", "", "default:glass_magenta", "_magenta")
pane("glass", "Purple Stained Glass Pane", "", "default:glass_purple", "_purple")
pane("glass", "Cyan Stained Glass Pane", "", "default:glass_cyan", "_cyan")
-- Iron -- Iron Bar
pane("iron", "Iron Bars", "xpanes:pane_iron", "default:steel_ingot", "") xpanes.register_pane("bar", {
description = "Iron Bars",
textures = {"xpanes_pane_iron.png","xpanes_pane_half_iron.png","xpanes_top_iron.png"},
inventory_image = "xpanes_pane_iron.png",
wield_image = "xpanes_pane_iron.png",
groups = {cracky=2},
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"}
}
})
-- Glass
pane("Glass Pane", "default:glass", "_natural")
pane("Red Stained Glass Pane", "default:glass_red", "_red")
pane("Green Stained Glass Pane", "default:glass_green", "_green")
pane("Blue Stained Glass Pane", "default:glass_blue", "_blue")
pane("Light Blue Stained Glass Pane", "default:glass_light_blue", "_light_blue")
pane("Black Stained Glass Pane", "default:glass_black", "_black")
pane("White Stained Glass Pane", "default:glass_white", "_white")
pane("Yellow Stained Glass Pane", "default:glass_yellow", "_yellow")
pane("Brown Stained Glass Pane", "default:glass_brown", "_brown")
pane("Orange Stained Glass Pane", "default:glass_orange", "_orange")
pane("Pink Stained Glass Pane", "default:glass_pink", "_pink")
pane("Gray Stained Glass Pane", "default:glass_gray", "_gray")
pane("Lime Stained Glass Pane", "default:glass_lime", "_lime")
pane("Light Gray Stained Glass Pane", "default:glass_silver", "_silver")
pane("Magenta Stained Glass Pane", "default:glass_magenta", "_magenta")
pane("Purple Stained Glass Pane", "default:glass_purple", "_purple")
pane("Cyan Stained Glass Pane", "default:glass_cyan", "_cyan")