123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- local function loom_formspec(progress)
- formspec =
- 'size[8,8.5]'..
- 'list[current_name;input;.5,1;1,1;]'..
- 'label[1.5,1.5;Input string]'..
- 'list[current_name;output;.5,3;1,1;]'..
- 'label[1.5,3.5;Take fabric]'..
- 'image[5,1;2,2.375;furniture_fabric_bg.png^[lowpart:'..(progress*20)..':furniture_fabric_fg.png]'..
- 'list[current_player;main;0,4.5;8,4;]'..
- 'listring[current_player;main]'..
- 'listring[context;input]'..
- 'listring[context;output]'..
- 'listring[current_player;main]'
- return formspec
- end
- minetest.register_node('stations:weaving_loom', {
- description = 'Weaving Loom',
- drawtype = 'mesh',
- mesh = 'stations_weaving_loom.obj',
- tiles = {'stations_weaving_loom.png'},
- sounds = default.node_sound_wood_defaults(),
- paramtype2 = 'facedir',
- paramtype = 'light',
- selection_box = {
- type = 'fixed',
- fixed = {
- {-.5, -.5, -.15, 1.5, 1.5, .15},
- }
- },
- collision_box = {
- type = 'fixed',
- fixed = {
- {-.5, -.5, -.15, 1.5, 1.5, .15},
- }
- },
- groups = {oddly_breakable_by_hand = 1, choppy=3},
- after_place_node = function(pos, placer, itemstack)
- if not epic.space_to_side(pos) then
- minetest.remove_node(pos)
- return itemstack
- end
- end,
- after_dig_node = function(pos, oldnode, oldmetadata, digger)
- epic.remove_side_node(pos, oldnode)
- end,
- on_construct = function(pos)
- local meta = minetest.get_meta(pos)
- local inv = meta:get_inventory()
- inv:set_size('main', 8*4)
- inv:set_size('input', 1)
- inv:set_size('output', 1)
- meta:set_string('progress', 0)
- meta:set_string('infotext', 'Weaving Loom')
- meta:set_string('formspec', loom_formspec(0))
- end,
- can_dig = function(pos,player)
- local meta = minetest.get_meta(pos);
- local inv = meta:get_inventory()
- if inv:is_empty('input') 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 == 'input' then
- if input == 'farming:string' 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 timer = minetest.get_node_timer(pos)
- timer:start(5)
- end,
- on_metadata_inventory_take = function(pos, listname, index, stack, player)
- if listname == 'output' then
- local meta = minetest.get_meta(pos)
- local progress = tonumber(meta:get_string('progress'))
- if progress == 0 then
- meta:set_string('infotext', 'Weaving Loom')
- meta:set_string('formspec', loom_formspec(0))
- end
- end
- end,
- on_timer = function(pos)
- local timer = minetest.get_node_timer(pos)
- local meta = minetest.get_meta(pos)
- local progress = tonumber(meta:get_string('progress'))
- local inv = meta:get_inventory()
- local input = inv:get_stack('input', 1)
- if input:get_name() == 'farming:string' then
- input:take_item()
- inv:set_stack('input',1,input)
- meta:set_string('progress', (progress+1))
- meta:set_string('infotext', 'Weaving Loom ('..((progress+1)*20)..'%)')
- meta:set_string('formspec', loom_formspec(progress+1))
- timer:start(5)
- if progress >= 4 then
- inv:add_item('output', 'furniture:fabric_white')
- meta:set_string('progress', 0)
- meta:set_string('formspec', loom_formspec(0))
- end
- end
- end,
- on_rotate = function(pos, node)
- return false
- end,
- })
- minetest.register_node('stations:weaving_loom_locked', {
- description = 'Weaving Loom (locked)',
- drawtype = 'mesh',
- mesh = 'stations_weaving_loom.obj',
- tiles = {'stations_weaving_loom.png'},
- sounds = default.node_sound_wood_defaults(),
- paramtype2 = 'facedir',
- paramtype = 'light',
- selection_box = {
- type = 'fixed',
- fixed = {
- {-.5, -.5, -.15, 1.5, 1.5, .15},
- }
- },
- collision_box = {
- type = 'fixed',
- fixed = {
- {-.5, -.5, -.15, 1.5, 1.5, .15},
- }
- },
- groups = {oddly_breakable_by_hand = 1, choppy=3},
- after_place_node = function(pos, placer, itemstack)
- if not epic.space_to_side(pos) then
- minetest.remove_node(pos)
- return itemstack
- end
- end,
- after_dig_node = function(pos, oldnode, oldmetadata, digger)
- epic.remove_side_node(pos, oldnode)
- end,
- on_construct = function(pos)
- local meta = minetest.get_meta(pos)
- local inv = meta:get_inventory()
- inv:set_size('main', 8*4)
- inv:set_size('input', 1)
- inv:set_size('output', 1)
- meta:set_string('progress', 0)
- meta:set_string('infotext', 'Weaving Loom (locked)')
- meta:set_string('formspec', loom_formspec(0))
- end,
- can_dig = function(pos,player)
- local meta = minetest.get_meta(pos);
- local inv = meta:get_inventory()
- if inv:is_empty('input') 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 == 'input' then
- if input == 'farming:string' 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 timer = minetest.get_node_timer(pos)
- timer:start(5)
- end,
- allow_metadata_inventory_take = 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
- return 99
- end
- end,
- on_metadata_inventory_take = function(pos, listname, index, stack, player)
- if listname == 'output' then
- local meta = minetest.get_meta(pos)
- local progress = tonumber(meta:get_string('progress'))
- if progress == 0 then
- meta:set_string('infotext', 'Weaving Loom')
- meta:set_string('formspec', loom_formspec(0))
- end
- end
- end,
- on_timer = function(pos)
- local timer = minetest.get_node_timer(pos)
- local meta = minetest.get_meta(pos)
- local progress = tonumber(meta:get_string('progress'))
- local inv = meta:get_inventory()
- local input = inv:get_stack('input', 1)
- if input:get_name() == 'farming:string' then
- input:take_item()
- inv:set_stack('input',1,input)
- meta:set_string('progress', (progress+1))
- meta:set_string('infotext', 'Weaving Loom ('..((progress+1)*20)..'%)')
- meta:set_string('formspec', loom_formspec(progress+1))
- timer:start(5)
- if progress >= 4 then
- inv:add_item('output', 'furniture:fabric_white')
- meta:set_string('progress', 0)
- meta:set_string('formspec', loom_formspec(0))
- end
- end
- end,
- on_rotate = function(pos, node)
- return false
- end,
- })
|