123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- unified_inventory.register_craft_type('churn', {
- description = 'Butter Churn',
- icon = 'stations_churn_icon.png',
- width = 1,
- height = 1
- })
- unified_inventory.register_craft({
- type = 'churn',
- items = {'mobs:bucket_milk'},
- output = 'food:butter 4'
- })
- local function milk_formspec(pos)
- local meta = minetest.get_meta(pos)
- local milk_level = tonumber(meta:get_string('milk'))
- local formspec =
- 'size[8,8.5]'..
- 'list[current_name;input;.5,0;1,1;]'..
- 'label[1.5,0.25;Input Milk]'..
- 'list[current_name;output;.5,2.5;1,1;]'..
- 'label[1.5,2.75;Take Butter]'..
- 'list[current_player;main;0,4.5;8,4;]'..
- 'image[5,.5;1,3;stations_stain_bg.png^[lowpart:'..(milk_level*12.5)..':stations_churn_fg.png]'..
- 'listring[context;output]'..
- 'listring[current_player;main]'..
- 'listring[context;input]'
- return formspec
- end
- minetest.register_node('stations:churn', {
- description = 'Butter Churn',
- drawtype = 'mesh',
- mesh = 'stations_churn.obj',
- tiles = {'stations_churn.png'},
- use_texture_alpha = 'opaque',
- sounds = default.node_sound_wood_defaults(),
- paramtype2 = 'facedir',
- paramtype = 'light',
- selection_box = {
- type = 'fixed',
- fixed = {{-.3, -.5, -.3, .3, .3, .3},
- {-.1, .3, -.1, .1, 1, .1}}},
- collision_box = {
- type = 'fixed',
- fixed = {{-.3, -.5, -.3, .3, .3, .3},
- {-.1, .3, -.1, .1, 1, .1}}},
- 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('input', 1)
- inv:set_size('output', 1)
- meta:set_string('infotext', 'Butter Churn')
- meta:set_string('milk', 0)
- meta:set_string('formspec', milk_formspec(pos))
- end,
- after_place_node = function(pos, placer, itemstack)
- if not epic.space_on_top(pos) then
- minetest.remove_node(pos)
- return itemstack
- end
- end,
- after_dig_node = function(pos, oldnode, oldmetadata, digger)
- epic.remove_top_node(pos, oldnode)
- 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 == 'mobs:bucket_milk' 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 input = stack:get_name()
- if listname == 'input' then
- if input == 'mobs:bucket_milk' then
- local meta = minetest.get_meta(pos)
- local inv = meta:get_inventory()
- local milk_level = tonumber(meta:get_string('milk'))
- if milk_level + 4 <= 8 then
- local timer = minetest.get_node_timer(pos)
- inv:set_stack('input', 1, 'bucket:bucket_empty')
- meta:set_string('milk', (milk_level + 4))
- timer:start(10)
- meta:set_string('formspec', milk_formspec(pos))
- meta:set_string('infotext', 'Making Butter')
- end
- end
- end
- end,
- on_timer = function(pos)
- local meta = minetest.get_meta(pos)
- local inv = meta:get_inventory()
- local milk_level = tonumber(meta:get_string('milk'))
- if milk_level >= 1 then
- local timer = minetest.get_node_timer(pos)
- inv:add_item('output', 'food:butter')
- meta:set_string('milk', (milk_level - 1))
- timer:start(10)
- meta:set_string('formspec', milk_formspec(pos))
- meta:set_string('infotext', 'Making Butter')
- else
- meta:set_string('infotext', 'Butter Churn')
- end
- end,
- })
- minetest.register_node('stations:churn_locked', {
- description = 'Butter Churn (locked)',
- drawtype = 'mesh',
- mesh = 'stations_churn.obj',
- tiles = {'stations_churn.png'},
- use_texture_alpha = 'opaque',
- sounds = default.node_sound_wood_defaults(),
- paramtype2 = 'facedir',
- paramtype = 'light',
- selection_box = {
- type = 'fixed',
- fixed = {{-.3, -.5, -.3, .3, .3, .3},
- {-.1, .3, -.1, .1, 1, .1}}},
- collision_box = {
- type = 'fixed',
- fixed = {{-.3, -.5, -.3, .3, .3, .3},
- {-.1, .3, -.1, .1, 1, .1}}},
- 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('input', 1)
- inv:set_size('output', 1)
- meta:set_string('infotext', 'Butter Churn (locked)')
- meta:set_string('milk', 0)
- meta:set_string('formspec', milk_formspec(pos))
- end,
- after_place_node = function(pos, placer, itemstack)
- if not epic.space_on_top(pos) then
- minetest.remove_node(pos)
- return itemstack
- end
- end,
- after_dig_node = function(pos, oldnode, oldmetadata, digger)
- epic.remove_top_node(pos, oldnode)
- 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 == 'mobs:bucket_milk' 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 input = stack:get_name()
- if listname == 'input' then
- if input == 'mobs:bucket_milk' then
- local meta = minetest.get_meta(pos)
- local inv = meta:get_inventory()
- local milk_level = tonumber(meta:get_string('milk'))
- if milk_level + 4 <= 8 then
- local timer = minetest.get_node_timer(pos)
- inv:set_stack('input', 1, 'bucket:bucket_empty')
- meta:set_string('milk', (milk_level + 4))
- timer:start(10)
- meta:set_string('formspec', milk_formspec(pos))
- meta:set_string('infotext', 'Making Butter')
- end
- end
- end
- end,
- on_timer = function(pos)
- local meta = minetest.get_meta(pos)
- local inv = meta:get_inventory()
- local milk_level = tonumber(meta:get_string('milk'))
- if milk_level >= 1 then
- local timer = minetest.get_node_timer(pos)
- inv:add_item('output', 'food:butter')
- meta:set_string('milk', (milk_level - 1))
- timer:start(10)
- meta:set_string('formspec', milk_formspec(pos))
- meta:set_string('infotext', 'Making Butter')
- else
- meta:set_string('infotext', 'Butter Churn')
- end
- 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,
- })
|