hades_revisited/mods/gluncarp/machines.lua

193 lines
5.1 KiB
Lua
Raw Normal View History

local S = minetest.get_translator("gluncarp")
local F = minetest.formspec_escape
local colors = {
"black",
"blue",
"brown",
"cyan",
"dark_green",
"dark_grey",
"green",
"grey",
"magenta",
"orange",
"pink",
"red",
"violet",
"white",
"yellow",
"blackgold",
}
2015-11-09 08:06:37 -08:00
minetest.register_node("gluncarp:machine", {
description = S("Carpet Workstation"),
2021-07-14 09:30:10 -07:00
_tt_help = S("Turns cloth to carpets"),
2015-11-09 08:06:37 -08:00
tiles = {
"gluncarp_machine_top.png",
"gluncarp_machine_bottom.png",
"gluncarp_machine_side2.png",
"gluncarp_machine_side1.png",
"gluncarp_machine_back.png",
"gluncarp_machine_front.png"
},
drawtype = "nodebox",
paramtype = "light",
paramtype2 = "facedir",
is_ground_content = false,
groups = {oddly_breakable_by_hand=2, choppy=3},
2015-11-09 08:06:37 -08:00
node_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.125, 0.5, -0.375, 0.125},
{-0.5, 0.375, 0.0625, 0.5, 0.4375, 0.125},
{0.4375, -0.375, -0.125, 0.5, 0.375, -0.0625},
{-0.5, -0.375, -0.125, -0.4375, 0.375, -0.0625},
{0.21875, -0.375, -0.03125, 0.28125, 0.5, 0.03125},
{-0.28125, -0.375, -0.03125, -0.21875, 0.5, 0.03125},
{-0.03125, -0.4375, -0.03125, 0.03125, 0.5, 0.03125},
{-0.3125, -0.3125, -0.03125, 0.3125, 0.3125, 0.03125},
{-0.5, -0.5, -0.25, 0.5, -0.4375, 0.25},
{0.4375, -0.4375, 0.0625, 0.5, 0.4375, 0.125},
{-0.5, -0.4375, 0.0625, -0.4375, 0.4375, 0.125},
{-0.5, 0.375, -0.125, 0.5, 0.4375, -0.0625},
{-0.5, 0.375, -0.125, -0.375, 0.4375, 0.125},
{0.375, 0.375, -0.125, 0.5, 0.4375, 0.125},
{0.21875, 0.375, -0.0625, 0.28125, 0.4375, 0.0625},
{-0.03125, 0.375, -0.0625, 0.03125, 0.4375, 0.0625},
{-0.28125, 0.375, -0.0625, -0.21875, 0.4375, 0.0625},
}
},
selection_box = {
type = 'fixed',
fixed = {
{-0.5, -0.5, -0.25, 0.5, 0.5, 0.25}
}
},
sounds = hades_sounds.node_sound_wood_defaults(),
2015-11-09 08:06:37 -08:00
after_place_node = function(pos, placer)
local meta = minetest.get_meta(pos);
meta:set_string("owner", (placer:get_player_name() or ""));
meta:set_string("infotext", S("Carpet workstation (owned by @1)", placer:get_player_name() or ""));
end,
2015-11-09 08:06:37 -08:00
2020-10-28 17:01:20 -07:00
on_rotate = "simple",
2020-10-27 07:14:33 -07:00
can_dig = function(pos,player)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
if not inv:is_empty("wool") then
return false
elseif not inv:is_empty("res") then
return false
end
return true
end,
2015-11-09 08:06:37 -08:00
2020-10-27 07:14:33 -07:00
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec", "size[10,6;]"..
"bgcolor[#00000000;neither]"..
"background9[6,6;10,6;gluncarp_background.png;true;6]"..
"list[current_name;wool;3,0.5;1,1;]"..
"list[current_name;res;6,0.5;1,1;]"..
2021-07-14 09:30:10 -07:00
"label[3,0;"..F(S("Cloth:")).."]"..
2020-10-27 07:14:33 -07:00
"label[6,0;"..F(S("Output:")).."]"..
"label[4.5,0;"..F(S("Craft:")).."]"..
"image_button[4.5,0.5;1,1;gluncarp_mach1.png;carpet; ]"..
2021-11-15 11:30:07 -08:00
"list[current_player;main;0,2;10,4;]"..
2020-10-27 07:14:33 -07:00
"listring[current_player;main]"..
"listring[current_name;wool]"..
"listring[current_player;main]"..
"listring[current_name;res]")
meta:set_string("infotext", S("Carpet workstation"))
local inv = meta:get_inventory()
2022-04-25 16:53:50 -07:00
-- Input slot (called "wool" for historic reasons only)
2020-10-27 07:14:33 -07:00
inv:set_size("wool", 1)
inv:set_size("res", 1)
end,
2015-11-09 08:06:37 -08:00
2020-10-27 07:14:33 -07:00
on_receive_fields = function(pos, formname, fields, sender)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
2015-11-09 08:06:37 -08:00
2020-10-27 07:14:33 -07:00
if not fields["carpet"] then
2015-11-09 08:06:37 -08:00
return
end
2020-10-27 07:14:33 -07:00
local count, material
2020-10-27 07:14:33 -07:00
if fields["carpet"] then
if inv:is_empty("wool") then
return
end
end
2022-04-25 16:53:50 -07:00
local clothstack = inv:get_stack("wool", 1)
local clothname = clothstack:get_name()
2020-10-27 07:14:33 -07:00
local resstack = inv:get_stack("res", 1)
2015-11-09 08:06:37 -08:00
----------------------------------------------------------------------
--Register Items
----------------------------------------------------------------------
for col=1,#colors do
local color = colors[col]
2022-04-25 16:53:50 -07:00
if clothname == "cloth:"..color then
material = color
count = 4
2022-04-25 16:53:50 -07:00
elseif clothname == "gluncarp:wool_"..color then
2020-10-27 11:55:27 -07:00
material = color
count = 4
2022-04-25 16:53:50 -07:00
elseif clothname == "stairs:slab_"..color then
material = color
count = 2
2022-04-25 16:53:50 -07:00
elseif clothname == "stairs:stair_"..color then
material = color
2020-10-27 11:55:27 -07:00
count = 3
2022-04-25 16:53:50 -07:00
elseif clothname == "stairs:stair_in_"..color then
material = color
count = 4
2022-04-25 16:53:50 -07:00
elseif clothname == "stairs:stair_out_"..color then
material = color
count = 4
end
2015-11-09 08:06:37 -08:00
end
----------------------------------------------------------------------
2020-10-27 07:14:33 -07:00
if material then
local output_item = "gluncarp:"..material
if not inv:is_empty("res") then
if resstack:get_name() ~= output_item then
return
elseif resstack:get_count() == resstack:get_stack_max() then
return
end
end
local success = false
2020-10-27 07:14:33 -07:00
for i = 0, count-1 do
local result = inv:add_item("res", output_item)
if result ~= nil then
success = true
end
end
if success then
2022-04-25 16:53:50 -07:00
clothstack:take_item()
inv:set_stack("wool", 1, clothstack)
2015-11-09 08:06:37 -08:00
end
end
2020-10-27 07:14:33 -07:00
end,
2015-11-09 08:06:37 -08:00
})
--Craft
minetest.register_craft({
2020-10-27 07:14:33 -07:00
output = 'gluncarp:machine',
recipe = {
{'group:wood', 'group:stick', 'group:wood'},
2020-11-14 13:27:58 -08:00
{'hades_farming:string', 'hades_farming:string', 'hades_farming:string'},
2020-10-27 07:14:33 -07:00
{'group:wood', "group:stick", 'group:wood'},
},
2015-11-09 08:06:37 -08:00
})