123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372 |
- local function stain_formspec(pos)
- local meta = minetest.get_meta(pos)
- local chitin_level = tonumber(meta:get_string('chitin_level'))
- local grounds_level = tonumber(meta:get_string('grounds_level'))
- local water_level = tonumber(meta:get_string('water_level'))
- formspec =
- 'size[8,8.5]'..
- 'list[current_name;chitin;.5,0;1,1;]'..
- 'label[1.5,0.25;Input chitin]'..
- 'list[current_name;grounds;.5,1;1,1;]'..
- 'label[1.5,1.25;Input coffee grounds]'..
- 'list[current_name;water;.5,2;1,1;]'..
- 'label[1.5,2.25;Input water]'..
- 'list[current_name;brush;.5,3;1,1;]'..
- 'label[1.5,3.25;Input brush]'..
- 'list[current_name;output;4.5,3;1,1;]'..
- 'image[3,.25;3,.5;station_stain_bg.png^[lowpart:'..(chitin_level*5)..':station_stain_fg.png^[transformR270]'..
- 'image[3,1.25;3,.5;station_stain_bg.png^[lowpart:'..(grounds_level*5)..':station_stain_fg.png^[transformR270]'..
- 'image[3,2.25;3,.5;station_stain_bg.png^[lowpart:'..(water_level*5)..':station_stain_fg.png^[transformR270]'..
- 'item_image_button[6,0;1,1;furniture:stain_brush1;brush1; ]'..
- 'item_image_button[6,1;1,1;furniture:stain_brush2;brush2; ]'..
- 'item_image_button[6,2;1,1;furniture:stain_brush3;brush3; ]'..
- 'item_image_button[7,0;1,1;furniture:stain_brush4;brush4; ]'..
- 'item_image_button[7,1;1,1;furniture:stain_brush5;brush5; ]'..
- 'item_image_button[7,2;1,1;furniture:stain_brush6;brush6; ]'..
- 'item_image_button[7,3;1,1;furniture:stain_brush7;brush7; ]'..
- 'list[current_player;main;0,4.5;8,4;]'..
- 'listring[context;output]'..
- 'listring[current_player;main]'
- return formspec
- end
- minetest.register_node('stations:stain', {
- description = 'Stain Station',
- drawtype = 'mesh',
- mesh = 'stations_stain.obj',
- tiles = {'stations_stain.png'},
- sounds = default.node_sound_wood_defaults(),
- paramtype2 = 'facedir',
- paramtype = 'light',
- selection_box = {
- type = 'fixed',
- fixed = {-.5, -.5, -.5, .5, .5, .5}},
- collision_box = {
- type = 'fixed',
- fixed = {-.5, -.5, -.5, .5, .5, .5}},
- groups = {oddly_breakable_by_hand = 1, choppy=3},
- on_construct = function(pos)
- local meta = minetest.get_meta(pos)
- local inv = meta:get_inventory()
- inv:set_size('main', 8*4)
- inv:set_size('chitin', 1)
- inv:set_size('grounds', 1)
- inv:set_size('water', 1)
- inv:set_size('brush', 1)
- inv:set_size('output', 1)
- meta:set_string('chitin_level', 0)
- meta:set_string('grounds_level', 0)
- meta:set_string('water_level', 0)
- meta:set_string('infotext', 'Stain Station')
- meta:set_string('formspec', stain_formspec(pos))
- end,
- can_dig = function(pos,player)
- local meta = minetest.get_meta(pos);
- local inv = meta:get_inventory()
- if inv:is_empty('chitin') and inv:is_empty('grounds') and inv:is_empty('water')
- and inv:is_empty('brush') and inv:is_empty('output') then
- return true
- else
- return false
- end
- end,
- allow_metadata_inventory_put = function(pos, listname, index, stack, player)
- local input = stack:get_name()
- if listname == 'chitin' then
- if input == 'stations:chitin' then
- return 1
- else
- return 0
- end
- elseif listname == 'grounds' then
- if input == 'stations:coffee_grounds' then
- return 1
- else
- return 0
- end
- elseif listname == 'water' then
- if input == 'bucket:bucket_river_water' or input == 'bucket:bucket_water'
- or input == 'earthbuild:clay_pot_river_water' or input == 'earthbuild:clay_pot_water' then
- return 1
- else
- return 0
- end
- elseif listname == 'brush' then
- if minetest.get_item_group(input, 'stain_brush') > 0 then
- return 99
- else
- return 0
- end
- elseif listname == 'output' then
- return 0
- end
- end,
- on_metadata_inventory_put = function(pos, listname, index, stack, player)
- local meta = minetest.get_meta(pos)
- local input = stack:get_name()
- local inv = meta:get_inventory()
- local chitin_level = tonumber(meta:get_string('chitin_level'))
- local grounds_level = tonumber(meta:get_string('grounds_level'))
- local water_level = tonumber(meta:get_string('water_level'))
- if listname == 'grounds' then
- if grounds_level + 2 <= 20 then
- meta:set_string('grounds_level', grounds_level+2)
- inv:set_stack('grounds', 1, '')
- end
- elseif listname == 'water' then
- if water_level + 10 <= 20 then
- meta:set_string('water_level', water_level+10)
- local vessel = string.sub(input, 1,3)
- if vessel == 'ear' then
- inv:set_stack('water', 1, 'earthbuild:clay_pot')
- elseif vessel == 'buc' then
- inv:set_stack('water', 1, 'bucket:bucket_empty')
- end
- end
- elseif listname == 'chitin' then
- if chitin_level + 2 <= 20 then
- meta:set_string('chitin_level', chitin_level+2)
- inv:set_stack('chitin', 1, '')
- end
- end
- meta:set_string('formspec', stain_formspec(pos))
- end,
- on_receive_fields = function(pos, formname, fields, sender)
- local meta = minetest.get_meta(pos)
- local inv = meta:get_inventory(pos)
- local chitin_level = tonumber(meta:get_string('chitin_level'))
- local grounds_level = tonumber(meta:get_string('grounds_level'))
- local water_level = tonumber(meta:get_string('water_level'))
- local brush = inv:get_stack('brush', 1)
- local brush_count = brush:get_count()
- local make_okay = false
- if chitin_level >= 1 and water_level >= 1 and brush_count >= 1 then
- if fields['brush1'] then
- if grounds_level >= 1 then
- inv:set_stack('output', 1, 'furniture:stain_brush1')
- meta:set_string('grounds_level', grounds_level-1)
- make_okay = true
- end
- elseif fields['brush2'] then
- if grounds_level >= 2 then
- inv:set_stack('output', 1, 'furniture:stain_brush2')
- meta:set_string('grounds_level', grounds_level-2)
- make_okay = true
- end
- elseif fields['brush3'] then
- if grounds_level >= 3 then
- inv:set_stack('output', 1, 'furniture:stain_brush3')
- meta:set_string('grounds_level', grounds_level-3)
- make_okay = true
- end
- elseif fields['brush4'] then
- if grounds_level >= 4 then
- inv:set_stack('output', 1, 'furniture:stain_brush4')
- meta:set_string('grounds_level', grounds_level-4)
- make_okay = true
- end
- elseif fields['brush5'] then
- if grounds_level >= 5 then
- inv:set_stack('output', 1, 'furniture:stain_brush5')
- meta:set_string('grounds_level', grounds_level-5)
- make_okay = true
- end
- elseif fields['brush6'] then
- if grounds_level >= 6 then
- inv:set_stack('output', 1, 'furniture:stain_brush6')
- meta:set_string('grounds_level', grounds_level-6)
- make_okay = true
- end
- elseif fields['brush7'] then
- if grounds_level >= 7 then
- inv:set_stack('output', 1, 'furniture:stain_brush7')
- meta:set_string('grounds_level', grounds_level-7)
- make_okay = true
- end
- end
- if make_okay == true then
- meta:set_string('chitin_level', chitin_level-1)
- meta:set_string('water_level', water_level-1)
- brush:take_item()
- inv:set_stack('brush',1,brush)
- meta:set_string('formspec', stain_formspec(pos))
- end
- end
- end,
- })
- minetest.register_node('stations:stain_locked', {
- description = 'Stain Station (locked)',
- drawtype = 'mesh',
- mesh = 'stations_stain.obj',
- tiles = {'stations_stain.png'},
- sounds = default.node_sound_wood_defaults(),
- paramtype2 = 'facedir',
- paramtype = 'light',
- selection_box = {
- type = 'fixed',
- fixed = {-.5, -.5, -.5, .5, .5, .5}},
- collision_box = {
- type = 'fixed',
- fixed = {-.5, -.5, -.5, .5, .5, .5}},
- groups = {oddly_breakable_by_hand = 1, choppy=3},
- on_construct = function(pos)
- local meta = minetest.get_meta(pos)
- local inv = meta:get_inventory()
- inv:set_size('main', 8*4)
- inv:set_size('chitin', 1)
- inv:set_size('grounds', 1)
- inv:set_size('water', 1)
- inv:set_size('brush', 1)
- inv:set_size('output', 1)
- meta:set_string('chitin_level', 0)
- meta:set_string('grounds_level', 0)
- meta:set_string('water_level', 0)
- meta:set_string('infotext', 'Stain Station (locked)')
- meta:set_string('formspec', stain_formspec(pos))
- end,
- can_dig = function(pos,player)
- local meta = minetest.get_meta(pos);
- local inv = meta:get_inventory()
- if inv:is_empty('chitin') and inv:is_empty('grounds') and inv:is_empty('water')
- and inv:is_empty('brush') and inv:is_empty('output') then
- return true
- else
- return false
- end
- end,
- allow_metadata_inventory_put = function(pos, listname, index, stack, player)
- local player_name = player:get_player_name()
- if minetest.is_protected(pos, player_name) and not minetest.check_player_privs(player, 'protection_bypass') then
- return 0
- else
- local input = stack:get_name()
- if listname == 'chitin' then
- if input == 'stations:chitin' then
- return 1
- else
- return 0
- end
- elseif listname == 'grounds' then
- if input == 'stations:coffee_grounds' then
- return 1
- else
- return 0
- end
- elseif listname == 'water' then
- if input == 'bucket:bucket_river_water' or input == 'bucket:bucket_water'
- or input == 'earthbuild:clay_pot_river_water' or input == 'earthbuild:clay_pot_water' then
- return 1
- else
- return 0
- end
- elseif listname == 'brush' then
- if minetest.get_item_group(input, 'stain_brush') > 0 then
- return 99
- else
- return 0
- end
- elseif listname == 'output' then
- return 0
- end
- end
- end,
- on_metadata_inventory_put = function(pos, listname, index, stack, player)
- local meta = minetest.get_meta(pos)
- local input = stack:get_name()
- local inv = meta:get_inventory()
- local chitin_level = tonumber(meta:get_string('chitin_level'))
- local grounds_level = tonumber(meta:get_string('grounds_level'))
- local water_level = tonumber(meta:get_string('water_level'))
- if listname == 'grounds' then
- if grounds_level + 2 <= 20 then
- meta:set_string('grounds_level', grounds_level+2)
- inv:set_stack('grounds', 1, '')
- end
- elseif listname == 'water' then
- if water_level + 10 <= 20 then
- meta:set_string('water_level', water_level+10)
- local vessel = string.sub(input, 1,3)
- if vessel == 'ear' then
- inv:set_stack('water', 1, 'earthbuild:clay_pot')
- elseif vessel == 'buc' then
- inv:set_stack('water', 1, 'bucket:bucket_empty')
- end
- end
- elseif listname == 'chitin' then
- if chitin_level + 2 <= 20 then
- meta:set_string('chitin_level', chitin_level+2)
- inv:set_stack('chitin', 1, '')
- end
- end
- meta:set_string('formspec', stain_formspec(pos))
- end,
- on_receive_fields = function(pos, formname, fields, sender)
- local player_name = sender:get_player_name()
- if minetest.is_protected(pos, player_name) and not minetest.check_player_privs(player, 'protection_bypass') then
- minetest.chat_send_player(sender, 'You don\'t have access to this station.')
- else
- local meta = minetest.get_meta(pos)
- local inv = meta:get_inventory(pos)
- local chitin_level = tonumber(meta:get_string('chitin_level'))
- local grounds_level = tonumber(meta:get_string('grounds_level'))
- local water_level = tonumber(meta:get_string('water_level'))
- local brush = inv:get_stack('brush', 1)
- local brush_count = brush:get_count()
- local make_okay = false
- if chitin_level >= 1 and water_level >= 1 and brush_count >= 1 then
- if fields['brush1'] then
- if grounds_level >= 1 then
- inv:set_stack('output', 1, 'furniture:stain_brush1')
- meta:set_string('grounds_level', grounds_level-1)
- make_okay = true
- end
- elseif fields['brush2'] then
- if grounds_level >= 2 then
- inv:set_stack('output', 1, 'furniture:stain_brush2')
- meta:set_string('grounds_level', grounds_level-2)
- make_okay = true
- end
- elseif fields['brush3'] then
- if grounds_level >= 3 then
- inv:set_stack('output', 1, 'furniture:stain_brush3')
- meta:set_string('grounds_level', grounds_level-3)
- make_okay = true
- end
- elseif fields['brush4'] then
- if grounds_level >= 4 then
- inv:set_stack('output', 1, 'furniture:stain_brush4')
- meta:set_string('grounds_level', grounds_level-4)
- make_okay = true
- end
- elseif fields['brush5'] then
- if grounds_level >= 5 then
- inv:set_stack('output', 1, 'furniture:stain_brush5')
- meta:set_string('grounds_level', grounds_level-5)
- make_okay = true
- end
- elseif fields['brush6'] then
- if grounds_level >= 6 then
- inv:set_stack('output', 1, 'furniture:stain_brush6')
- meta:set_string('grounds_level', grounds_level-6)
- make_okay = true
- end
- elseif fields['brush7'] then
- if grounds_level >= 7 then
- inv:set_stack('output', 1, 'furniture:stain_brush7')
- meta:set_string('grounds_level', grounds_level-7)
- make_okay = true
- end
- end
- if make_okay == true then
- meta:set_string('chitin_level', chitin_level-1)
- meta:set_string('water_level', water_level-1)
- brush:take_item()
- inv:set_stack('brush',1,brush)
- meta:set_string('formspec', stain_formspec(pos))
- end
- end
- end
- end,
- })
|