diff --git a/airutils_biofuel.lua b/airutils_biofuel.lua new file mode 100644 index 0000000..8263ad2 --- /dev/null +++ b/airutils_biofuel.lua @@ -0,0 +1,257 @@ +---------- +--biofuel +---------- + +local module_name = "airutils" + +if minetest.get_modpath("technic") then + if technic then + technic.register_extractor_recipe({input = {"farming:wheat 33"}, output = "biofuel:biofuel 1"}) + technic.register_extractor_recipe({input = {"farming:corn 33"}, output = "biofuel:biofuel 1"}) + technic.register_extractor_recipe({input = {"farming:potato 33"}, output = "biofuel:biofuel 1"}) + technic.register_extractor_recipe({input = {"default:papyrus 99"}, output = "biofuel:biofuel 1"}) + end +end + + +if minetest.get_modpath("basic_machines") then + if basic_machines then + basic_machines.grinder_recipes["farming:wheat"] = {50,"biofuel:biofuel",1} + basic_machines.grinder_recipes["farming:corn"] = {50,"biofuel:biofuel",1} + basic_machines.grinder_recipes["farming:potato"] = {50,"biofuel:biofuel",1} + basic_machines.grinder_recipes["default:papyrus"] = {70,"biofuel:biofuel",1} + end +end + +if minetest.get_modpath("default") then + minetest.register_craft({ + output = module_name .. ":biofuel_distiller", + recipe = { + {"default:copper_ingot", "default:copper_ingot", "default:copper_ingot"}, + {"default:steel_ingot" , "", "default:steel_ingot"}, + {"default:steel_ingot" , "default:steel_ingot", "default:steel_ingot"}, + }, + }) +end +if minetest.get_modpath("mcl_core") then + minetest.register_craft({ + output = module_name .. ":biofuel_distiller", + recipe = { + {"mcl_copper:copper_ingot", "mcl_copper:copper_ingot", "mcl_copper:copper_ingot"}, + {"mcl_core:iron_ingot" , "", "mcl_core:iron_ingot"}, + {"mcl_core:iron_ingot" , "mcl_core:iron_ingot", "mcl_core:iron_ingot"}, + }, + }) +end + + +-- biofuel +minetest.register_craftitem(":biofuel:biofuel",{ + description = "Bio Fuel", + inventory_image = "biofuel_inv.png", +}) + +minetest.register_craft({ + type = "fuel", + recipe = "biofuel:biofuel", + burntime = 50, +}) + +local ferment = { + {"default:papyrus", "biofuel:biofuel"}, + {"farming:wheat", "biofuel:biofuel"}, + {"farming:corn", "biofuel:biofuel"}, + {"farming:baked_potato", "biofuel:biofuel"}, + {"farming:potato", "biofuel:biofuel"} +} + +local ferment_groups = {'flora', 'leaves', 'flower', 'sapling', 'tree', 'wood', 'stick', 'plant', 'seed', + 'leafdecay', 'leafdecay_drop', 'mushroom', 'vines' } + +-- distiller +local biofueldistiller_formspec = "size[8,9]" + .. "list[current_name;src;2,1;1,1;]" .. airutils.get_itemslot_bg(2, 1, 1, 1) + .. "list[current_name;dst;5,1;1,1;]" .. airutils.get_itemslot_bg(5, 1, 1, 1) + .. "list[current_player;main;0,5;8,4;]" .. airutils.get_itemslot_bg(0, 5, 8, 4) + .. "listring[current_name;dst]" + .. "listring[current_player;main]" + .. "listring[current_name;src]" + .. "listring[current_player;main]" + .. "image[3.5,1;1,1;gui_furnace_arrow_bg.png^[transformR270]" + +minetest.register_node( module_name .. ":biofuel_distiller", { + description = "Biofuel Distiller", + tiles = {"airutils_metal.png", "airutils_aluminum.png", "airutils_copper.png" }, + drawtype = "mesh", + mesh = "airutils_biofuel_distiller.b3d", + paramtype = "light", + paramtype2 = "facedir", + groups = { + choppy = 2, oddly_breakable_by_hand = 1, flammable = 2 + }, + legacy_facedir_simple = true, + + on_place = minetest.rotate_node, + + on_construct = function(pos) + + local meta = minetest.get_meta(pos) + + meta:set_string("formspec", biofueldistiller_formspec) + meta:set_string("infotext", "Biofuel Distiller") + meta:set_float("status", 0.0) + + local inv = meta:get_inventory() + + inv:set_size("src", 1) + inv:set_size("dst", 1) + end, + + can_dig = function(pos,player) + + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + + if not inv:is_empty("dst") + or not inv:is_empty("src") then + return false + end + + return true + end, + + allow_metadata_inventory_take = function(pos, listname, index, stack, player) + + if minetest.is_protected(pos, player:get_player_name()) then + return 0 + end + + return stack:get_count() + end, + + allow_metadata_inventory_put = function(pos, listname, index, stack, player) + + if minetest.is_protected(pos, player:get_player_name()) then + return 0 + end + + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + + if listname == "src" then + return stack:get_count() + elseif listname == "dst" then + return 0 + end + end, + + allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) + + if minetest.is_protected(pos, player:get_player_name()) then + return 0 + end + + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + local stack = inv:get_stack(from_list, from_index) + + if to_list == "src" then + return count + elseif to_list == "dst" then + return 0 + end + end, + + on_metadata_inventory_put = function(pos) + + local timer = minetest.get_node_timer(pos) + + timer:start(5) + end, + + on_timer = function(pos) + + local meta = minetest.get_meta(pos) ; if not meta then return end + local inv = meta:get_inventory() + + -- is barrel empty? + if not inv or inv:is_empty("src") then + + meta:set_float("status", 0.0) + meta:set_string("infotext", "Fuel Distiller") + + return false + end + + -- does it contain any of the source items on the list? + local has_item + + --normal items + for n = 1, #ferment do + if inv:contains_item("src", ItemStack(ferment[n][1])) then + has_item = n + break + end + end + + --groups + local has_group + if not has_item then + local inv_content = inv:get_list("src") + if inv_content then + for k, v in pairs(inv_content) do + local item_name = v:get_name() + for n = 1, #ferment_groups do + if minetest.get_item_group(item_name, ferment_groups[n]) == 1 then + has_group = n + break + end + end + end + end + end + + if not has_item and not has_group then + return false + end + + -- is there room for additional fermentation? + if has_item and not inv:room_for_item("dst", ferment[has_item][2]) then + meta:set_string("infotext", "Fuel Distiller (FULL)") + return true + end + + if has_group and not inv:room_for_item("dst", "biofuel:biofuel") then + meta:set_string("infotext", "Fuel Distiller (FULL)") + return true + end + + local status = meta:get_float("status") + + -- fermenting (change status) + if status < 100 then + meta:set_string("infotext", "Fuel Distiller " .. status .. "% done") + meta:set_float("status", status + 5) + else + if not has_group then + inv:remove_item("src", ferment[has_item][1]) + inv:add_item("dst", ferment[has_item][2]) + else + for i,itemstack in pairs(inv:get_list("src")) do + inv:remove_item("src", ItemStack(itemstack:get_name().." 1")) + end + inv:add_item("dst", "biofuel:biofuel") + end + + meta:set_float("status", 0,0) + end + + if inv:is_empty("src") then + meta:set_float("status", 0.0) + meta:set_string("infotext", "Fuel Distiller") + end + + return true + end, +}) + diff --git a/init.lua b/init.lua index 8fd36fb..7ab7bf8 100644 --- a/init.lua +++ b/init.lua @@ -35,6 +35,7 @@ end if not minetest.settings:get_bool('airutils.disable_repair') then dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "airutils_repair.lua") end + airutils.get_wind = dofile(minetest.get_modpath("airutils") .. DIR_DELIM ..'/wind.lua') dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "common_entities.lua") dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "airutils_wind.lua") @@ -43,6 +44,10 @@ dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "light.lua") dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "physics_lib.lua") dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "lib_planes" .. DIR_DELIM .. "init.lua") +if not minetest.settings:get_bool('airutils.disable_biofuel') then + dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "airutils_biofuel.lua") +end + if minetest.get_modpath("player_api") and not minetest.settings:get_bool('airutils.disable_uniforms') then dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "pilot_skin_manager.lua") end diff --git a/inventory_management.lua b/inventory_management.lua index a671b31..5643172 100644 --- a/inventory_management.lua +++ b/inventory_management.lua @@ -2,8 +2,8 @@ local storage = minetest.get_mod_storage() airutils.modname = minetest.get_current_modname() --function to format formspec for mineclone. In case of minetest, just returns an empty string -local function get_itemslot_bg(a, b, c, d) - if airutils.is_mcl then +function airutils.get_itemslot_bg(a, b, c, d) + if mcl_formspec then return mcl_formspec.get_itemslot_bg(a,b,c,d) end return "" @@ -19,54 +19,54 @@ local function get_formspec_by_size(self, size) end local default_inventory_formspecs = { ["2"]="size[8,6]".. background .. - "list[detached:" .. self._inv_id .. ";main;3.0,0;3,1;]" .. get_itemslot_bg(3.0, 0, 2, 1) .. - "list[current_player;main;0,2;8,4;]" .. get_itemslot_bg(0, 2, 8, 4) .. + "list[detached:" .. self._inv_id .. ";main;3.0,0;3,1;]" .. airutils.get_itemslot_bg(3.0, 0, 2, 1) .. + "list[current_player;main;0,2;8,4;]" .. airutils.get_itemslot_bg(0, 2, 8, 4) .. "listring[]", ["3"]="size[8,6]".. background .. - "list[detached:" .. self._inv_id .. ";main;2.5,0;3,1;]" .. get_itemslot_bg(2.5, 0, 3, 1) .. - "list[current_player;main;0,2;8,4;]" .. get_itemslot_bg(0, 2, 8, 4) .. + "list[detached:" .. self._inv_id .. ";main;2.5,0;3,1;]" .. airutils.get_itemslot_bg(2.5, 0, 3, 1) .. + "list[current_player;main;0,2;8,4;]" .. airutils.get_itemslot_bg(0, 2, 8, 4) .. "listring[]", ["4"]="size[8,6]".. background .. - "list[detached:" .. self._inv_id .. ";main;2,0;4,1;]" .. get_itemslot_bg(2.0, 0, 4, 1) .. - "list[current_player;main;0,2;8,4;]" .. get_itemslot_bg(0, 2, 8, 4) .. + "list[detached:" .. self._inv_id .. ";main;2,0;4,1;]" .. airutils.get_itemslot_bg(2.0, 0, 4, 1) .. + "list[current_player;main;0,2;8,4;]" .. airutils.get_itemslot_bg(0, 2, 8, 4) .. "listring[]", ["6"]="size[8,6]".. background .. - "list[detached:" .. self._inv_id .. ";main;1,0;6,1;]".. get_itemslot_bg(1.0, 0, 6, 1) .. - "list[current_player;main;0,2;8,4;]" .. get_itemslot_bg(0, 2, 8, 4) .. + "list[detached:" .. self._inv_id .. ";main;1,0;6,1;]".. airutils.get_itemslot_bg(1.0, 0, 6, 1) .. + "list[current_player;main;0,2;8,4;]" .. airutils.get_itemslot_bg(0, 2, 8, 4) .. "listring[]", ["8"]="size[8,6]".. background .. - "list[detached:" .. self._inv_id .. ";main;0,0;8,1;]".. get_itemslot_bg(0, 0, 8, 1) .. - "list[current_player;main;0,2;8,4;]" .. get_itemslot_bg(0, 2, 8, 4) .. + "list[detached:" .. self._inv_id .. ";main;0,0;8,1;]".. airutils.get_itemslot_bg(0, 0, 8, 1) .. + "list[current_player;main;0,2;8,4;]" .. airutils.get_itemslot_bg(0, 2, 8, 4) .. "listring[]", ["12"]="size[8,7]".. background .. - "list[detached:" .. self._inv_id .. ";main;1,0;6,2;]".. get_itemslot_bg(1, 0, 6, 2) .. - "list[current_player;main;0,3;8,4;]" .. get_itemslot_bg(0, 3, 8, 4) .. + "list[detached:" .. self._inv_id .. ";main;1,0;6,2;]".. airutils.get_itemslot_bg(1, 0, 6, 2) .. + "list[current_player;main;0,3;8,4;]" .. airutils.get_itemslot_bg(0, 3, 8, 4) .. "listring[]", ["16"]="size[8,7]".. background .. - "list[detached:" .. self._inv_id .. ";main;0,0;8,2;]".. get_itemslot_bg(0, 0, 8, 2) .. - "list[current_player;main;0,3;8,4;]" .. get_itemslot_bg(0, 3, 8, 4) .. + "list[detached:" .. self._inv_id .. ";main;0,0;8,2;]".. airutils.get_itemslot_bg(0, 0, 8, 2) .. + "list[current_player;main;0,3;8,4;]" .. airutils.get_itemslot_bg(0, 3, 8, 4) .. "listring[]", ["24"]="size[8,8]".. background .. - "list[detached:" .. self._inv_id .. ";main;0,0;8,3;]".. get_itemslot_bg(0, 0, 8, 3) .. - "list[current_player;main;0,4;8,4;]" .. get_itemslot_bg(0, 4, 8, 4) .. + "list[detached:" .. self._inv_id .. ";main;0,0;8,3;]".. airutils.get_itemslot_bg(0, 0, 8, 3) .. + "list[current_player;main;0,4;8,4;]" .. airutils.get_itemslot_bg(0, 4, 8, 4) .. "listring[]", ["32"]="size[8,9]".. background .. - "list[detached:" .. self._inv_id .. ";main;0,0.3;8,4;]".. get_itemslot_bg(0, 0.3, 8, 4) .. - "list[current_player;main;0,5;8,4;]".. get_itemslot_bg(0, 5, 8, 4) .. + "list[detached:" .. self._inv_id .. ";main;0,0.3;8,4;]".. airutils.get_itemslot_bg(0, 0.3, 8, 4) .. + "list[current_player;main;0,5;8,4;]".. airutils.get_itemslot_bg(0, 5, 8, 4) .. "listring[]" .. hotbar, ["50"]="size[10,10]".. background .. - "list[detached:" .. self._inv_id .. ";main;0,0;10,5;]".. get_itemslot_bg(0, 0, 10, 5) .. - "list[current_player;main;1,6;8,4;]" .. get_itemslot_bg(1, 6, 8, 4) .. + "list[detached:" .. self._inv_id .. ";main;0,0;10,5;]".. airutils.get_itemslot_bg(0, 0, 10, 5) .. + "list[current_player;main;1,6;8,4;]" .. airutils.get_itemslot_bg(1, 6, 8, 4) .. "listring[]", } diff --git a/mod.conf b/mod.conf index 7a8e6b6..a4a24eb 100644 --- a/mod.conf +++ b/mod.conf @@ -2,4 +2,4 @@ name = airutils title=AirUtils description=A lib for airplanes and some useful tools author=apercy -optional_depends=player_api, emote, climate_api +optional_depends=player_api, emote, climate_api, biofuel diff --git a/models/airutils_biofuel_distiller.b3d b/models/airutils_biofuel_distiller.b3d new file mode 100644 index 0000000..f6d37aa Binary files /dev/null and b/models/airutils_biofuel_distiller.b3d differ diff --git a/textures/airutils_aluminum.png b/textures/airutils_aluminum.png new file mode 100755 index 0000000..5b4e746 Binary files /dev/null and b/textures/airutils_aluminum.png differ diff --git a/textures/airutils_biofuel_inv.png b/textures/airutils_biofuel_inv.png new file mode 100644 index 0000000..7cf2469 Binary files /dev/null and b/textures/airutils_biofuel_inv.png differ diff --git a/textures/airutils_copper.png b/textures/airutils_copper.png new file mode 100755 index 0000000..f90530f Binary files /dev/null and b/textures/airutils_copper.png differ