techage_modpack/signs_bot/signs.lua

298 lines
7.5 KiB
Lua
Raw Normal View History

2020-05-31 23:31:18 +03:00
--[[
Signs Bot
=========
2021-05-14 19:50:16 +03:00
Copyright (C) 2019-2021 Joachim Stolberg
2020-05-31 23:31:18 +03:00
GPL v3
See LICENSE.txt for more information
Signs Bot: Signs
]]--
2021-05-14 19:50:16 +03:00
-- Load support for I18n.
local S = signs_bot.S
2020-05-31 23:31:18 +03:00
local function formspec(cmnd)
cmnd = minetest.formspec_escape(cmnd)
return "size[4,7]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
"label[0.2,0;"..cmnd.."]"
end
2021-09-03 20:32:06 +03:00
local function formspecXL(help_text, bot_cmnds)
help_text = help_text or "no help"
bot_cmnds = minetest.formspec_escape(bot_cmnds)
return "size[9,8]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
"label[0,0;" .. S("Instructions:") .. "]" ..
"label[0.2,0.6;" .. help_text .. "]" ..
"textarea[0.3,4.0;9,4.9;code;" .. S("Code") .. ":;" .. bot_cmnds .. "]"
end
2020-05-31 23:31:18 +03:00
local function register_sign(def)
minetest.register_node("signs_bot:"..def.name, {
description = def.description,
inventory_image = def.image,
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{ -1/16, -8/16, -1/16, 1/16, 4/16, 1/16},
{ -6/16, -5/16, -2/16, 6/16, 3/16, -1/16},
},
},
paramtype2 = "facedir",
tiles = {
"default_wood.png",
"default_wood.png",
"default_wood.png",
"default_wood.png",
"default_wood.png",
"default_wood.png^"..def.image,
},
after_place_node = function(pos, placer)
local meta = minetest.get_meta(pos)
meta:set_string("signs_bot_cmnd", def.commands)
meta:set_string("formspec", formspec(def.commands))
meta:set_string("infotext", def.description)
end,
on_rotate = screwdriver.disallow,
paramtype = "light",
2021-05-14 19:50:16 +03:00
use_texture_alpha = signs_bot.CLIP,
2020-05-31 23:31:18 +03:00
sunlight_propagates = true,
is_ground_content = false,
groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2, sign_bot_sign = 1},
sounds = default.node_sound_wood_defaults(),
})
end
2021-09-03 20:32:06 +03:00
local function register_signXL(def)
minetest.register_node("signs_bot:"..def.name, {
description = def.description,
inventory_image = def.image,
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{ -1/16, -8/16, -1/16, 1/16, 4/16, 1/16},
{ -6/16, -5/16, -2/16, 6/16, 3/16, -1/16},
},
},
paramtype2 = "facedir",
tiles = {
"default_wood.png",
"default_wood.png",
"default_wood.png",
"default_wood.png",
"default_wood.png",
"default_wood.png^"..def.image,
},
after_place_node = function(pos, placer)
local meta = minetest.get_meta(pos)
meta:set_string("signs_bot_cmnd", def.commands)
meta:set_string("formspec", formspecXL(def.help_text, def.commands))
meta:set_string("infotext", def.description)
end,
on_rotate = screwdriver.disallow,
paramtype = "light",
use_texture_alpha = signs_bot.CLIP,
sunlight_propagates = true,
is_ground_content = false,
groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2, sign_bot_sign = 1},
sounds = default.node_sound_wood_defaults(),
})
end
2020-05-31 23:31:18 +03:00
signs_bot.register_sign = register_sign
2021-09-03 20:32:06 +03:00
signs_bot.register_signXL = register_signXL
2020-05-31 23:31:18 +03:00
register_sign({
name = "sign_right",
2021-05-14 19:50:16 +03:00
description = S('Sign "turn right"'),
2020-05-31 23:31:18 +03:00
commands = "turn_right",
image = "signs_bot_sign_right.png",
})
minetest.register_craft({
output = "signs_bot:sign_right 6",
recipe = {
{"group:wood", "default:stick", "group:wood"},
{"dye:yellow", "default:stick", "dye:black"},
{"", "", ""}
}
})
register_sign({
name = "sign_left",
2021-05-14 19:50:16 +03:00
description = S('Sign "turn left"'),
2020-05-31 23:31:18 +03:00
commands = "turn_left",
image = "signs_bot_sign_left.png",
})
minetest.register_craft({
output = "signs_bot:sign_left 6",
recipe = {
{"group:wood", "default:stick", "group:wood"},
{"dye:yellow", "default:stick", ""},
{"dye:black", "", ""}
}
})
register_sign({
name = "sign_take",
2021-05-14 19:50:16 +03:00
description = S('Sign "take item"'),
2020-05-31 23:31:18 +03:00
commands = "take_item 99\nturn_around",
image = "signs_bot_sign_take.png",
})
minetest.register_craft({
output = "signs_bot:sign_take 6",
recipe = {
{"group:wood", "default:stick", "group:wood"},
{"dye:yellow", "default:stick", ""},
{"", "dye:black", ""}
}
})
register_sign({
name = "sign_add",
2021-05-14 19:50:16 +03:00
description = S('Sign "add item"'),
2020-05-31 23:31:18 +03:00
commands = "add_item 99\nturn_around",
image = "signs_bot_sign_add.png",
})
minetest.register_craft({
output = "signs_bot:sign_add 6",
recipe = {
{"group:wood", "default:stick", "group:wood"},
{"dye:yellow", "default:stick", ""},
{"", "", "dye:black"}
}
})
register_sign({
name = "sign_stop",
2021-05-14 19:50:16 +03:00
description = S('Sign "stop"'),
2020-05-31 23:31:18 +03:00
commands = "stop",
image = "signs_bot_sign_stop.png",
})
minetest.register_craft({
output = "signs_bot:sign_stop 6",
recipe = {
{"group:wood", "default:stick", "group:wood"},
{"dye:black", "default:stick", "dye:yellow"},
{"", "", ""}
}
})
if minetest.get_modpath("minecart") then
register_sign({
name = "sign_add_cart",
2021-05-14 19:50:16 +03:00
description = S('Sign "add to cart"'),
2020-05-31 23:31:18 +03:00
commands = "drop_items 99 1\npunch_cart\nturn_around",
image = "signs_bot_sign_add_cart.png",
})
minetest.register_craft({
output = "signs_bot:sign_add_cart 4",
recipe = {
{"group:wood", "default:stick", "group:wood"},
{"dye:black", "default:stick", "dye:yellow"},
{"dye:black", "", ""}
}
})
register_sign({
name = "sign_take_cart",
2021-05-14 19:50:16 +03:00
description = S('Sign "take from cart"'),
2020-05-31 23:31:18 +03:00
commands = "pickup_items 1\npunch_cart\nturn_around",
image = "signs_bot_sign_take_cart.png",
})
minetest.register_craft({
output = "signs_bot:sign_take_cart 4",
recipe = {
{"group:wood", "default:stick", "group:wood"},
{"dye:black", "default:stick", "dye:yellow"},
{"", "dye:black", ""}
}
})
end
if minetest.get_modpath("doc") then
doc.add_entry("signs_bot", "sign_right", {
2021-05-14 19:50:16 +03:00
name = S('Sign "turn right"'),
2020-05-31 23:31:18 +03:00
data = {
item = "signs_bot:sign_right",
2021-05-14 19:50:16 +03:00
text = S("The Bot turns right when it detects this sign in front of it.")
2020-05-31 23:31:18 +03:00
},
})
doc.add_entry("signs_bot", "sign_left", {
2021-05-14 19:50:16 +03:00
name = S('Sign "turn left"'),
2020-05-31 23:31:18 +03:00
data = {
item = "signs_bot:sign_left",
2021-05-14 19:50:16 +03:00
text = S("The Bot turns left when it detects this sign in front of it.")
2020-05-31 23:31:18 +03:00
},
})
doc.add_entry("signs_bot", "sign_take", {
2021-05-14 19:50:16 +03:00
name = S('Sign "take item"'),
2020-05-31 23:31:18 +03:00
data = {
item = "signs_bot:sign_take",
text = table.concat({
2021-05-14 19:50:16 +03:00
S("The Bot takes items out of a chest in front of it and then turns around."),
S("This sign has to be placed on top of the chest."),
2020-05-31 23:31:18 +03:00
}, "\n")
},
})
doc.add_entry("signs_bot", "sign_add", {
2021-05-14 19:50:16 +03:00
name = S('Sign "add item"'),
2020-05-31 23:31:18 +03:00
data = {
item = "signs_bot:sign_add",
text = table.concat({
2021-05-14 19:50:16 +03:00
S("The Bot puts items into a chest in front of it and then turns around."),
S("This sign has to be placed on top of the chest."),
2020-05-31 23:31:18 +03:00
}, "\n")
},
})
doc.add_entry("signs_bot", "sign_stop", {
2021-05-14 19:50:16 +03:00
name = S('Sign "stop"'),
2020-05-31 23:31:18 +03:00
data = {
item = "signs_bot:sign_stop",
2021-05-14 19:50:16 +03:00
text = S("The Bot will stop in front of this sign until the sign is removed or the bot is turned off.")
2020-05-31 23:31:18 +03:00
},
})
end
if minetest.get_modpath("doc") and minetest.get_modpath("minecart") then
doc.add_entry("signs_bot", "sign_add_cart", {
2021-05-14 19:50:16 +03:00
name = S('Sign "add to cart"'),
2020-05-31 23:31:18 +03:00
data = {
item = "signs_bot:sign_add_cart",
text = table.concat({
2021-05-14 19:50:16 +03:00
S("The Bot puts items into a minecart in front of it, pushes the cart and then turns around."),
S("This sign has to be placed on top of the rail at the cart end position."),
2020-05-31 23:31:18 +03:00
}, "\n")
},
})
doc.add_entry("signs_bot", "sign_take_cart", {
2021-05-14 19:50:16 +03:00
name = S('Sign "take from cart"'),
2020-05-31 23:31:18 +03:00
data = {
item = "signs_bot:sign_take_cart",
text = table.concat({
2021-05-14 19:50:16 +03:00
S("The Bot takes items out of a minecart in front of it, pushes the cart and then turns around."),
S("This sign has to be placed on top of the rail at the cart end position."),
2020-05-31 23:31:18 +03:00
}, "\n")
},
})
end