From 7d63db17034e1019927827b19f1e51b1ba6eee00 Mon Sep 17 00:00:00 2001 From: BlockMen Date: Thu, 17 Apr 2014 20:42:30 +0200 Subject: [PATCH] Add glasspanes and ironbars --- mods/xpanes/README.txt | 13 ++ mods/xpanes/depends.txt | 1 + mods/xpanes/init.lua | 173 ++++++++++++++++++++++ mods/xpanes/textures/xpanes_bar.png | Bin 0 -> 410 bytes mods/xpanes/textures/xpanes_grey.png | Bin 0 -> 128 bytes mods/xpanes/textures/xpanes_pane_half.png | Bin 0 -> 108 bytes mods/xpanes/textures/xpanes_space.png | Bin 0 -> 151 bytes mods/xpanes/textures/xpanes_white.png | Bin 0 -> 150 bytes 8 files changed, 187 insertions(+) create mode 100644 mods/xpanes/README.txt create mode 100644 mods/xpanes/depends.txt create mode 100644 mods/xpanes/init.lua create mode 100644 mods/xpanes/textures/xpanes_bar.png create mode 100644 mods/xpanes/textures/xpanes_grey.png create mode 100644 mods/xpanes/textures/xpanes_pane_half.png create mode 100644 mods/xpanes/textures/xpanes_space.png create mode 100644 mods/xpanes/textures/xpanes_white.png diff --git a/mods/xpanes/README.txt b/mods/xpanes/README.txt new file mode 100644 index 00000000..021f8f80 --- /dev/null +++ b/mods/xpanes/README.txt @@ -0,0 +1,13 @@ +Minetest 0.4.x mod: xpanes +========================== + +License: +-------- +Copyright (C) xyz +modified by BlockMen (iron bars) + +This program is free software. It comes without any warranty, to +the extent permitted by applicable law. You can redistribute it +and/or modify it under the terms of the Do What The Fuck You Want +To Public License, Version 2, as published by Sam Hocevar. See +http://sam.zoy.org/wtfpl/COPYING for more details. diff --git a/mods/xpanes/depends.txt b/mods/xpanes/depends.txt new file mode 100644 index 00000000..331d858c --- /dev/null +++ b/mods/xpanes/depends.txt @@ -0,0 +1 @@ +default \ No newline at end of file diff --git a/mods/xpanes/init.lua b/mods/xpanes/init.lua new file mode 100644 index 00000000..92d9bfce --- /dev/null +++ b/mods/xpanes/init.lua @@ -0,0 +1,173 @@ +local function rshift(x, by) + return math.floor(x / 2 ^ by) +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 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}) +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 +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 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 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} +} + +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 +local function register_panes(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 + } + }) +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) + +register_panes("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'} + } +}) + +register_panes("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'} + } +}) diff --git a/mods/xpanes/textures/xpanes_bar.png b/mods/xpanes/textures/xpanes_bar.png new file mode 100644 index 0000000000000000000000000000000000000000..a8becd74129ab90c6577016f8cf005f469329cfa GIT binary patch literal 410 zcmV;L0cHM)P)Sr~?Bng)z9`;gY_wb6l;63^!oQp)cM!Z1W#*TxpqYjGSKTPVxY?m&&uHQ=1% zdc7LGC}wRzo#=1z`Fyra75m@6pgQO#P{nq?bC)TDAJ49$*iwK@FaQ7m07*qoM6N<$ Ef~|+T@Bjb+ literal 0 HcmV?d00001 diff --git a/mods/xpanes/textures/xpanes_grey.png b/mods/xpanes/textures/xpanes_grey.png new file mode 100644 index 0000000000000000000000000000000000000000..566d4f86f42a10efcca595c09eaf52b97768af37 GIT binary patch literal 128 zcmeAS@N?(olHy`uVBq!ia0vp^j3CUx1SBVv2j2ryoCO|{#S9GGLLkg|>2BR0pdgQ@ zi(^Q|oa8g-&oeVHEoAhwiVuGR6qhP-jVN&}Ey>6)VhGJiO-xY;t}HG|%`MhZ@XSlr UJ1J{d22{o1>FVdQ&MBb@03G%rAOHXW literal 0 HcmV?d00001 diff --git a/mods/xpanes/textures/xpanes_pane_half.png b/mods/xpanes/textures/xpanes_pane_half.png new file mode 100644 index 0000000000000000000000000000000000000000..30d240cadc83d0c7d81b5231f9bd588d2567c5ac GIT binary patch literal 108 zcmeAS@N?(olHy`uVBq!ia0vp^oIotV!3HFcc!WBG1PVMNiy0WWg+Q3`(%rg0KtVZA z7srr_Imti%|F>t>`}5%X|Ns1T4+9NWWrPT>Qer6Eaq_^&?X5{bl?$ literal 0 HcmV?d00001 diff --git a/mods/xpanes/textures/xpanes_space.png b/mods/xpanes/textures/xpanes_space.png new file mode 100644 index 0000000000000000000000000000000000000000..c2e875225706b9a6c835ab1f5d9d76ac140dbb1f GIT binary patch literal 151 zcmeAS@N?(olHy`uVBq!ia0vp^j3CUx1|;Q0k8}bl&H|6fVg?3oVGw3ym^DWND9B#o z>FdgVhfPFS!u;;lEal|aXmQ!2!LEx2FAG0T2??7gQu&X%Q~loCIFkZAu0d> literal 0 HcmV?d00001 diff --git a/mods/xpanes/textures/xpanes_white.png b/mods/xpanes/textures/xpanes_white.png new file mode 100644 index 0000000000000000000000000000000000000000..5c6256c11a21272dcf1e95f5736f8e4161e0a88e GIT binary patch literal 150 zcmeAS@N?(olHy`uVBq!ia0vp^j3CUx1SBVv2j2ryoCO|{#S9GG!XV7ZFl&wkP>{XE z)7O>#4x5OuHMfs&1}jiVHZvrm#5q4VH#M&W$Yo$~E=o--Nlj5G&n(GMaQE~LNYP7W n2a5A}x;Tb#Tu=V-|Gzy0>p!M{cg{pU2Wjwh^>bP0l+XkKfxsk; literal 0 HcmV?d00001