---Arboretum Stuff require ("stdlib/event/event") function Get_Arboretum_Recipe(ArboretumTable, event) if ArboretumTable == nil then global.Arboretum_Table = {} return else local Water_Name = ArboretumTable.inventory.fluidbox[1].name local Water_Level = ArboretumTable.inventory.fluidbox[1].amount local recipe = ArboretumTable.inventory.get_recipe() --writeDebug("Inv is: "..Water_Name) writeDebug("# is: "..Water_Level) if recipe ~= nil and Water_Name == "water" and Water_Level > 99 then local plant_radius = 50 local my_inv = ArboretumTable.inventory.get_inventory(defines.inventory.assembling_machine_input).get_contents() local Item_name local Amount --[[ for n,a in pairs(my_inv) do Item_name=n Amount=a writeDebug("Inv is: "..Item_name) writeDebug("# is: "..Amount) end ]] local recipe_name = ArboretumTable.inventory.get_recipe().name if recipe_name == "bi_Arboretum_r1" then writeDebug(recipe_name..": Just plant a tree") local pos = ArboretumTable.inventory.position local surface = ArboretumTable.inventory.surface for k = 1,10 do local xxx = math.random(-plant_radius, plant_radius) local yyy = math.random(-plant_radius, plant_radius) local new_position = {x = pos.x + xxx,y = pos.y + yyy} local can_be_placed = surface.can_place_entity{name= "seedling", position = new_position, force = "neutral"} if can_be_placed then --ArboretumTable.inventory.fluidbox[1].amount = ArboretumTable.inventory.fluidbox[1].amount - 200 for n,a in pairs(my_inv) do Item_name=n Amount=a writeDebug("Inv is: "..Item_name) writeDebug("# is: "..Amount) Amount = Amount-1 ArboretumTable.inventory.get_inventory(defines.inventory.assembling_machine_input).clear() if Amount > 0 then ArboretumTable.inventory.get_inventory(defines.inventory.assembling_machine_input).insert({name = Item_name, count = Amount}) end end local create_seedling = surface.create_entity({name = "seedling", position = new_position, force = "neutral"}) seed_planted_arboretum (event, create_seedling) break else writeDebug("can't plant here") writeDebug(k) end end elseif recipe_name == "bi_Arboretum_r2" then writeDebug(recipe_name..": Just change terrain to grass - 3 (basic)") local pos = ArboretumTable.inventory.position local surface = ArboretumTable.inventory.surface for k = 1,10 do local xxx = math.random(-plant_radius, plant_radius) local yyy = math.random(-plant_radius, plant_radius) local new_position = {x = pos.x + xxx,y = pos.y + yyy} local currentTilename = surface.get_tile(new_position.x, new_position.y).name if Bi_Industries.fertility[currentTilename] then local terrain_name_s if game.active_mods["alien-biomes"] then terrain_name_s = "vegetation-green-grass-3" else terrain_name_s = "grass-3" end surface.set_tiles{{name=terrain_name_s, position=new_position}} break else writeDebug("can't change here") end end elseif recipe_name == "bi_Arboretum_r3" then writeDebug(recipe_name..": Just change terrain to grass - 1 (advanced)") local pos = ArboretumTable.inventory.position local surface = ArboretumTable.inventory.surface for k = 1,10 do local xxx = math.random(-plant_radius, plant_radius) local yyy = math.random(-plant_radius, plant_radius) local new_position = {x = pos.x + xxx,y = pos.y + yyy} local currentTilename = surface.get_tile(new_position.x, new_position.y).name if Bi_Industries.fertility[currentTilename] then local terrain_name_s if game.active_mods["alien-biomes"] then terrain_name_s = "vegetation-green-grass-31" else terrain_name_s = "grass-1" end surface.set_tiles{{name=terrain_name_s, position=new_position}} break else writeDebug("can't change here") end end elseif recipe_name == "bi_Arboretum_r4" then writeDebug(recipe_name..": Plant Tree and change the terrain to grass - 3 (basic)") local pos = ArboretumTable.inventory.position local surface = ArboretumTable.inventory.surface for k = 1,10 do local xxx = math.random(-plant_radius, plant_radius) local yyy = math.random(-plant_radius, plant_radius) local new_position = {x = pos.x + xxx,y = pos.y + yyy} local currentTilename = surface.get_tile(new_position.x, new_position.y).name local can_be_placed = surface.can_place_entity{name= "seedling", position = new_position, force = "neutral"} if can_be_placed and Bi_Industries.fertility[currentTilename] then local terrain_name if game.active_mods["alien-biomes"] then terrain_name = "vegetation-green-grass-3" else terrain_name = "grass-3" end surface.set_tiles{{name=terrain_name, position=new_position}} local create_seedling = surface.create_entity({name = "seedling", position = new_position, force = "neutral"}) entity = create_seedling seed_planted_arboretum (event, entity) break else writeDebug("can't plant or change terrain here") end end elseif recipe_name == "bi_Arboretum_r5" then writeDebug(recipe_name..": Plant Tree and change the terrain to grass - 1 (advanced)") local pos = ArboretumTable.inventory.position local surface = ArboretumTable.inventory.surface for k = 1,10 do local xxx = math.random(-plant_radius, plant_radius) local yyy = math.random(-plant_radius, plant_radius) local new_position = {x = pos.x + xxx,y = pos.y + yyy} local currentTilename = surface.get_tile(new_position.x, new_position.y).name local can_be_placed = surface.can_place_entity{name= "seedling", position = new_position, force = "neutral"} if can_be_placed and Bi_Industries.fertility[currentTilename] then local terrain_name if game.active_mods["alien-biomes"] then terrain_name = "vegetation-green-grass-1" else terrain_name = "grass-1" end surface.set_tiles{{name=terrain_name, position=new_position}} ArboretumTable.inventory.fluidbox[1].amount = ArboretumTable.inventory.fluidbox[1].amount - 200 --<-- Not Working for n,a in pairs(my_inv) do Item_name=n Amount=a writeDebug("Inv is: "..Item_name) writeDebug("# is: "..Amount) Amount = Amount-1 --ArboretumTable.inventory.get_inventory(defines.inventory.assembling_machine_input).clear() --<-- Not Working if Amount > 0 then ArboretumTable.inventory.get_inventory(defines.inventory.assembling_machine_input).insert({name = Item_name, count = Amount}) end end local create_seedling = surface.create_entity({name = "seedling", position = new_position, force = "neutral"}) seed_planted_arboretum (event, create_seedling) break else writeDebug("can't plant or change terrain here") end end else writeDebug("no recipe") end end end end --------------------------------------------------------------------