2018-03-10 22:14:57 +01:00
|
|
|
--[[
|
|
|
|
|
|
|
|
Tubelib Addons 2
|
|
|
|
================
|
|
|
|
|
2020-11-20 14:45:28 +01:00
|
|
|
Copyright (C) 2017-2020 Joachim Stolberg
|
2018-03-10 22:14:57 +01:00
|
|
|
|
2020-11-20 14:45:28 +01:00
|
|
|
AGPL v3
|
2018-03-10 22:14:57 +01:00
|
|
|
See LICENSE.txt for more information
|
|
|
|
|
|
|
|
gateblock.lua:
|
|
|
|
|
|
|
|
]]--
|
|
|
|
|
2020-11-03 20:19:38 +01:00
|
|
|
-- Load support for I18n
|
|
|
|
local S = tubelib_addons2.S
|
|
|
|
|
2018-09-26 12:42:25 +02:00
|
|
|
local NUM_TEXTURES = 20
|
|
|
|
|
2018-03-10 22:14:57 +01:00
|
|
|
local sTextures = "Wood,Aspen Wood,Jungle Wood,Pine Wood,"..
|
|
|
|
"Cobblestone,Sandstone,Stone,Desert Sandstone,"..
|
2018-09-26 12:42:25 +02:00
|
|
|
"Desert Stone,Silver Sandstone,Mossy Cobble,Desert Cobble,"..
|
2018-03-10 22:14:57 +01:00
|
|
|
"Copper,Steel,Tin,Coral,"..
|
2018-09-26 12:42:25 +02:00
|
|
|
"Glas,Obsidian Glas,Ice,Gate Wood"
|
2018-03-10 22:14:57 +01:00
|
|
|
|
|
|
|
local tTextures = {
|
|
|
|
["Wood"]=1, ["Aspen Wood"]=2, ["Jungle Wood"]=3, ["Pine Wood"]=4,
|
|
|
|
["Cobblestone"]=5, ["Sandstone"]=6, ["Stone"]=7, ["Desert Sandstone"]=8,
|
2018-09-26 12:42:25 +02:00
|
|
|
["Desert Stone"]=9, ["Silver Sandstone"]=10, ["Mossy Cobble"]=11, ["Desert Cobble"]=12,
|
|
|
|
["Copper"]=13, ["Steel"]=14, ["Tin"]=15, ["Coral"]=16,
|
|
|
|
["Glas"]=17, ["Obsidian Glas"]=18, ["Ice"]=19, ["Gate Wood"]=20,
|
2018-03-10 22:14:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
local tPgns = {"default_wood.png", "default_aspen_wood.png", "default_junglewood.png", "default_pine_wood.png",
|
|
|
|
"default_cobble.png", "default_sandstone.png", "default_stone.png", "default_desert_sandstone.png",
|
2018-09-26 12:42:25 +02:00
|
|
|
"default_desert_stone_block.png", "default_silver_sandstone.png", "default_mossycobble.png", "default_desert_cobble.png",
|
2018-03-10 22:14:57 +01:00
|
|
|
"default_copper_block.png", "default_steel_block.png", "default_tin_block.png", "default_coral_skeleton.png",
|
2018-09-26 12:42:25 +02:00
|
|
|
"default_glass.png", "default_obsidian_glass.png", "default_ice.png", "tubelib_addon2_gate.png"}
|
2018-03-10 22:14:57 +01:00
|
|
|
|
|
|
|
for idx,pgn in ipairs(tPgns) do
|
|
|
|
minetest.register_node("tubelib_addons2:gateblock"..idx, {
|
2020-11-03 20:19:38 +01:00
|
|
|
description = S("Tubelib Gate Block"),
|
2018-03-10 22:14:57 +01:00
|
|
|
tiles = {pgn},
|
|
|
|
after_place_node = function(pos, placer)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local node = minetest.get_node(pos)
|
2020-09-24 20:19:10 +02:00
|
|
|
local number = tubelib.add_node(pos, node.name)
|
|
|
|
meta:set_string("number", number)
|
2020-11-03 20:19:38 +01:00
|
|
|
meta:set_string("infotext", S("Tubelib Gate Block").." "..number)
|
2018-03-10 22:14:57 +01:00
|
|
|
meta:set_string("formspec", "size[3,2]"..
|
|
|
|
"label[0,0;Select texture]"..
|
2018-09-26 12:42:25 +02:00
|
|
|
"dropdown[0,0.5;3;type;"..sTextures..";"..NUM_TEXTURES.."]"..
|
2020-11-03 20:19:38 +01:00
|
|
|
"button_exit[0.5,1.5;2,1;exit;"..S("Save").."]")
|
2018-03-10 22:14:57 +01:00
|
|
|
end,
|
|
|
|
|
|
|
|
on_receive_fields = function(pos, formname, fields, player)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local node = minetest.get_node(pos)
|
|
|
|
if fields.type then
|
|
|
|
node.name = "tubelib_addons2:gateblock"..tTextures[fields.type]
|
|
|
|
minetest.swap_node(pos, node)
|
|
|
|
tubelib.add_node(pos, node.name)
|
|
|
|
end
|
|
|
|
if fields.exit then
|
|
|
|
meta:set_string("formspec", nil)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
|
2020-09-24 20:19:10 +02:00
|
|
|
after_dig_node = function(pos, oldnode, oldmetadata)
|
2018-03-10 22:14:57 +01:00
|
|
|
tubelib.remove_node(pos)
|
|
|
|
end,
|
|
|
|
|
|
|
|
drawtype = "glasslike",
|
|
|
|
paramtype = "light",
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
sunlight_propagates = true,
|
|
|
|
sounds = default.node_sound_stone_defaults(),
|
2020-11-20 14:45:28 +01:00
|
|
|
groups = {cracky=2, choppy=2, crumbly=2, not_in_creative_inventory = idx == NUM_TEXTURES and 0 or 1},
|
2018-03-10 22:14:57 +01:00
|
|
|
is_ground_content = false,
|
2019-01-28 21:51:38 +01:00
|
|
|
drop = "tubelib_addons2:gateblock1",
|
2018-03-10 22:14:57 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
tubelib.register_node("tubelib_addons2:gateblock"..idx, {}, {
|
|
|
|
on_recv_message = function(pos, topic, payload)
|
|
|
|
local node = minetest.get_node(pos)
|
|
|
|
if topic == "on" then
|
2020-09-24 20:19:10 +02:00
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local number = meta:get_string("number")
|
2018-03-10 22:14:57 +01:00
|
|
|
minetest.remove_node(pos)
|
2020-09-24 20:19:10 +02:00
|
|
|
tubelib.temporary_remove_node(pos, number, node.name, {param2 = node.param2})
|
2018-03-10 22:14:57 +01:00
|
|
|
elseif topic == "off" then
|
2020-09-24 20:19:10 +02:00
|
|
|
local data = tubelib.temporary_remove_node(pos)
|
|
|
|
if data then
|
|
|
|
minetest.add_node(pos, {name = data.name, param2 = data.param2})
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_string("number", data.number)
|
2018-03-10 22:14:57 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_craft({
|
2018-09-26 12:42:25 +02:00
|
|
|
output = "tubelib_addons2:gateblock"..NUM_TEXTURES,
|
2018-03-10 22:14:57 +01:00
|
|
|
recipe = {
|
|
|
|
{"group:wood", "", ""},
|
|
|
|
{"tubelib:wlanchip", "", ""},
|
|
|
|
{"", "",""},
|
|
|
|
},
|
|
|
|
})
|