From 24ddd101ffe7d02ccca93755f5abcdc1dfcc0517 Mon Sep 17 00:00:00 2001 From: Sokomine Date: Mon, 3 Aug 2015 23:18:28 +0200 Subject: [PATCH] added cottages.handmill_product so that other items can be grinded or milled --- init.lua | 17 +++++++++++++++++ nodes_straw.lua | 30 ++++++++++++++++++++---------- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/init.lua b/init.lua index 809f63b..af0cb16 100644 --- a/init.lua +++ b/init.lua @@ -36,6 +36,23 @@ end -- (i.e. in combination with realtest) dofile(minetest.get_modpath("cottages").."/adaptions.lua"); +-- add to this table what you want the handmill to convert; +-- add a stack size if you want a higher yield +cottages.handmill_product = {}; +cottages.handmill_product[ cottages.craftitem_seed_wheat ] = 'farming:flour 1'; +--[[ some examples: +cottages.handmill_product[ 'default:cobble' ] = 'default:gravel'; +cottages.handmill_product[ 'default:gravel' ] = 'default:sand'; +cottages.handmill_product[ 'default:sand' ] = 'default:dirt 2'; +cottages.handmill_product[ 'flowers:rose' ] = 'dye:red 6'; +cottages.handmill_product[ 'default:cactus' ] = 'dye:green 6'; +cottages.handmill_product[ 'default:coal_lump'] = 'dye:black 6'; +--]] +-- process that many inputs per turn +cottages.handmill_max_per_turn = 20; +cottages.handmill_min_per_turn = 0; + + -- uncomment parts you do not want dofile(minetest.get_modpath("cottages").."/nodes_furniture.lua"); dofile(minetest.get_modpath("cottages").."/nodes_historic.lua"); diff --git a/nodes_straw.lua b/nodes_straw.lua index ef1df47..a26b728 100644 --- a/nodes_straw.lua +++ b/nodes_straw.lua @@ -360,10 +360,10 @@ local cottages_handmill_formspec = "size[8,8]".. minetest.register_node("cottages:handmill", { description = S("mill, powered by punching"), drawtype = "mesh", - mesh = "cottages_handmill.obj", + mesh = "cottages_handmill.obj", tiles = {"cottages_stone.png"}, paramtype = "light", - paramtype2 = "facedir", + paramtype2 = "facedir", groups = {cracky=2}, is_ground_content = false, selection_box = { @@ -424,7 +424,7 @@ minetest.register_node("cottages:handmill", { local meta = minetest.get_meta(pos) -- only accept input the threshing floor can use/process if( listname=='flour' - or (listname=='seeds' and stack and stack:get_name() ~= cottages.craftitem_seed_wheat)) then + or (listname=='seeds' and stack and not( cottages.handmill_product[ stack:get_name()] ))) then return 0; end @@ -457,8 +457,12 @@ minetest.register_node("cottages:handmill", { local stack1 = inv:get_stack( 'seeds', 1); if( ( stack1:is_empty()) - or( not( stack1:is_empty()) and stack1:get_name() ~= cottages.craftitem_seed_wheat)) then + or( not( stack1:is_empty()) + and not( cottages.handmill_product[ stack1:get_name() ] ))) then + if not( stack1:is_empty() ) then + minetest.chat_send_player(name,"Nothing happens...") + end -- update the formspec meta:set_string("formspec", cottages_handmill_formspec.. @@ -467,7 +471,7 @@ minetest.register_node("cottages:handmill", { end -- turning the mill is a slow process; 1-21 flour are generated per turn - local anz = 1 + math.random( 0, 20 ); + local anz = 1 + math.random( cottages.handmill_min_per_turn, cottages.handmill_max_per_turn ); -- we already made sure there is only wheat inside local found = stack1:get_count(); @@ -476,17 +480,23 @@ minetest.register_node("cottages:handmill", { anz = found; end + local product_stack = ItemStack( cottages.handmill_product[ stack1:get_name() ]); + local anz_result = anz; + -- items that produce more + if( product_stack:get_count()> 1 ) then + anz_result = anz * product_stack:get_count(); + end - if( inv:room_for_item('flour','farming:flour '..tostring( anz ))) then + if( inv:room_for_item('flour', product_stack:get_name()..' '..tostring( anz_result ))) then - inv:add_item("flour",'farming:flour '..tostring( anz )); - inv:remove_item("seeds", cottages.craftitem_seed_wheat..' '..tostring( anz )); + inv:add_item( 'flour', product_stack:get_name()..' '..tostring( anz_result )); + inv:remove_item( 'seeds', stack1:get_name()..' '..tostring( anz )); local anz_left = found - anz; if( anz_left > 0 ) then - minetest.chat_send_player( name, S('You have grinded %s wheat seeds (%s are left).'):format(anz,anz_left)); + minetest.chat_send_player( name, S('You have ground a %s (%s are left).'):format(stack1:get_definition().description,(anz_left))); else - minetest.chat_send_player( name, S('You have grinded the last %s wheat seeds.'):format(anz)); + minetest.chat_send_player( name, S('You have ground the last %s.'):format(stack1:get_definition().description)); end -- if the version of MT is recent enough, rotate the mill a bit