local slab_str = "stairs:slab_wood"

function applyModSupport()
   local moreblocks_found = false
   local technic_worldgen = false
   local modnames = minetest.get_modnames()
   for i, name in ipairs(modnames) do
      if name == "moreblocks" then
         moreblocks_found = true
      end
      if name == "technic_worldgen" then
         technic_worldgen = true
      end
   end

   if moreblocks_found == true and technic_worldgen == true then
      minetest.log("applying patch to mod " .. minetest.get_current_modname())
      minetest.log("converting '" .. slab_str .. "' to 'moreblocks:slab_wood'")
      slab_str = "moreblocks:slab_wood"
   end
end

minetest.register_craft({
      output = 'drinks:juice_press',
      recipe = {
         {'default:stick', 'default:steel_ingot', 'default:stick'},
         {'default:stick', 'bucket:bucket_empty', 'default:stick'},
         {slab_str, slab_str, 'vessels:drinking_glass'},
         }
})

minetest.register_craft({
      output = 'drinks:liquid_barrel',
      recipe = {
         {'group:wood', 'group:wood', 'group:wood'},
         {'group:wood', 'group:wood', 'group:wood'},
         {slab_str, '', slab_str},
         }
})

drinks = {}
drinks.drink_table = {}
drinks.juiceable = {}
drinks.shortname = {
   ['jcu'] = {size = 2, name = 'vessels:drinking_glass'},
   ['jbo'] = {size = 4, name = 'vessels:glass_bottle'},
   ['jsb'] = {size = 4, name = 'vessels:steel_bottle'},
   ['jbu'] = {size = 16, name = 'bucket:bucket_empty'}
}

drinks.longname = {
   ['vessels:drinking_glass'] = {size = 2, name = 'jcu'},
   ['vessels:glass_bottle'] = {size = 4, name = 'jbo'},
   ['vessels:steel_bottle'] = {size = 4, name = 'jsb'},
   ['bucket:bucket_empty'] = {size = 16, name = 'jbu'},
}

drinks.juice_name = {
   ['apple'] = 'apple',
   ['cactus'] = 'cactus',
   ['blueberries'] = 'blueberries',
   ['melon_8'] = 'melon',
   ['melon_slice'] = 'melon',
   ['tomato'] = 'tomato',
   ['carrot'] = 'carrot',
   ['cucumber'] = 'cucumber',
   ['grapes'] = 'grapes',
   ['pumpkin'] = 'pumpkin',
   ['raspberries'] = 'raspberries',
   ['rhubarb'] = 'rhubarb',
   ['pineapple'] = 'pineapple',
   ['pineapple_ring'] = 'pineapple',
   ['banana'] = 'banana',
   ['orange'] = 'orange',
   ['prickly_pear'] = 'cactus',
   ['barrel_cacti_1'] = 'cactus',
   ['barrel_cacti_2'] = 'cactus',
   ['barrel_cacti_3'] = 'cactus'
}

--Default
drinks.juiceable['apple'] = true -- Name of fruit to make juiceable.
drinks.juiceable['cactus'] = true
drinks.juiceable['blueberries'] = true
table.insert(drinks.drink_table, {'apple', 'Apple', '#ecff56'})
table.insert(drinks.drink_table, {'cactus', 'Cactus', '#96F97B'})
table.insert(drinks.drink_table, {'blueberries', 'Blueberry', '#521dcb'})

--Farming_redo
drinks.juiceable['melon_8'] = true
drinks.juiceable['melon_slice'] = true
drinks.juiceable['tomato'] = true
drinks.juiceable['carrot'] = true
drinks.juiceable['cucumber'] = true
drinks.juiceable['grapes'] = true
drinks.juiceable['pumpkin'] = true
drinks.juiceable['raspberries'] = true
drinks.juiceable['rhubarb'] = true
drinks.juiceable['pineapple'] = true
drinks.juiceable['pineapple_ring'] = true
table.insert(drinks.drink_table, {'melon', 'Melon', '#ef4646'})
table.insert(drinks.drink_table, {'tomato', 'Tomato', '#990000'})
table.insert(drinks.drink_table, {'carrot', 'Carrot', '#ed9121'})
table.insert(drinks.drink_table, {'cucumber', 'Cucumber', '#73af59'})
table.insert(drinks.drink_table, {'grapes', 'Grape', '#b20056'})
table.insert(drinks.drink_table, {'pumpkin', 'Pumpkin', '#ffc04c'})
table.insert(drinks.drink_table, {'raspberries', 'Raspberry', '#C70039'})
table.insert(drinks.drink_table, {'rhubarb', 'Rhubarb', '#fb8461'})
table.insert(drinks.drink_table, {'pineapple', 'Pineapple', '#dcd611'})

--Epic_trees
drinks.juiceable['banana'] = true
drinks.juiceable['orange'] = true
table.insert(drinks.drink_table, {'banana', 'Banana', '#eced9f'})
table.insert(drinks.drink_table, {'orange', 'Orange', '#ffc417'})

--Desert_life
drinks.juiceable['prickly_pear'] = true
drinks.juiceable['barrel_cacti_1'] = true
drinks.juiceable['barrel_cacti_2'] = true
drinks.juiceable['barrel_cacti_3'] = true
table.insert(drinks.drink_table, {'prickly', 'Cactus', '#96F97B'})
table.insert(drinks.drink_table, {'barrel', 'Cactus', '#96F97B'})


-- replace craftitem to node definition
-- use existing node as template (e.g. 'vessel:glass_bottle')
drinks.register_item = function( name, template, def )
   local template_def = minetest.registered_nodes[template]
   if template_def then
   local drinks_def = table.copy(template_def)

   -- replace/add values
   for k,v in pairs(def) do
      if k == "groups" then
         -- special handling for groups: merge instead replace
         for g,n in pairs(v) do
            drinks_def[k][g] = n
         end
      else
         drinks_def[k]=v
      end
   end

   if def.inventory_image then
      drinks_def.wield_image = drinks_def.inventory_image
      drinks_def.tiles = { drinks_def.inventory_image }
   end

   minetest.register_node( name, drinks_def )
   end
end

dofile(minetest.get_modpath('drinks')..'/drinks.lua')
dofile(minetest.get_modpath('drinks')..'/drink_machines.lua')
dofile(minetest.get_modpath('drinks')..'/formspecs.lua')
