mirror of
https://github.com/Lokrates/Biofuel.git
synced 2024-08-19 19:34:04 +02:00
Merge pull request #15 from sfence/sfence_vessels_magament_6ad39ec
Vessels management
This commit is contained in:
commit
8397d9dae2
61
biofuel.lua
61
biofuel.lua
@ -5,6 +5,23 @@ local S = minetest.get_translator("biofuel")
|
||||
--Biofuel:
|
||||
----------
|
||||
|
||||
--Empty Vial
|
||||
minetest.register_craftitem("biofuel:phial", {
|
||||
description = S("Empty Vial"),
|
||||
inventory_image = "biofuel_phial.png"
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "biofuel:phial 6",
|
||||
recipe = {{"default:glass"},
|
||||
{"default:glass"}},
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
type = "shapeless",
|
||||
output = "vessels:glass_fragments",
|
||||
recipe = {"biofuel:phial","biofuel:phial","biofuel:phial"},
|
||||
})
|
||||
|
||||
--Vial of Biofuel
|
||||
minetest.register_craftitem("biofuel:phial_fuel", {
|
||||
@ -16,6 +33,7 @@ minetest.register_craft({
|
||||
type = "fuel",
|
||||
recipe = "biofuel:phial_fuel",
|
||||
burntime = 10,
|
||||
replacements = {{"biofuel:phial_fuel", "biofuel:phial"}},
|
||||
})
|
||||
|
||||
|
||||
@ -24,13 +42,13 @@ minetest.register_craft({
|
||||
minetest.register_craftitem("biofuel:bottle_fuel", {
|
||||
description = S("Bottle of Biofuel"),
|
||||
inventory_image = "biofuel_bottle_fuel.png",
|
||||
groups = {biofuel = 1}
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
type = "shapeless",
|
||||
output = "biofuel:bottle_fuel",
|
||||
recipe = {"biofuel:phial_fuel", "biofuel:phial_fuel", "biofuel:phial_fuel", "biofuel:phial_fuel"}
|
||||
recipe = {"biofuel:phial_fuel", "biofuel:phial_fuel", "biofuel:phial_fuel", "biofuel:phial_fuel","vessels:glass_bottle"},
|
||||
replacements = {{"biofuel:phial_fuel", "biofuel:phial"},{"biofuel:phial_fuel", "biofuel:phial"},{"biofuel:phial_fuel", "biofuel:phial"},{"biofuel:phial_fuel", "biofuel:phial"}},
|
||||
})
|
||||
|
||||
|
||||
@ -38,11 +56,33 @@ minetest.register_craft({
|
||||
type = "fuel",
|
||||
recipe = "biofuel:bottle_fuel",
|
||||
burntime = 40,
|
||||
replacements = {{"biofuel:bottle_fuel", "vessels:glass_bottle"}},
|
||||
})
|
||||
|
||||
|
||||
--Canister of Biofuel
|
||||
|
||||
minetest.register_craftitem("biofuel:can", {
|
||||
description = S("Empty Canister"),
|
||||
inventory_image = "biofuel_fuel_can.png"
|
||||
})
|
||||
|
||||
if minetest.get_modpath("technic") then
|
||||
minetest.register_craft({
|
||||
output = "biofuel:can",
|
||||
recipe = {{"technic:water_can"}}
|
||||
})
|
||||
else
|
||||
minetest.register_craft({
|
||||
output = "biofuel:can",
|
||||
recipe = {
|
||||
{"default:steel_ingot","default:bronze_ingot","default:steel_ingot"},
|
||||
{"default:steel_ingot","","default:steel_ingot"},
|
||||
{"default:steel_ingot","default:steel_ingot","default:steel_ingot"}
|
||||
},
|
||||
})
|
||||
end
|
||||
|
||||
minetest.register_craftitem("biofuel:fuel_can", {
|
||||
description = S("Canister of Biofuel"),
|
||||
inventory_image = "biofuel_fuel_can.png"
|
||||
@ -51,7 +91,18 @@ minetest.register_craftitem("biofuel:fuel_can", {
|
||||
minetest.register_craft({
|
||||
type = "fuel",
|
||||
recipe = "biofuel:fuel_can",
|
||||
burntime = 370,
|
||||
burntime = 320,
|
||||
replacements = {{"biofuel:fuel_can", "biofuel:can"}},
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "biofuel:fuel_can",
|
||||
recipe = {
|
||||
{"biofuel:bottle_fuel", "biofuel:bottle_fuel", "biofuel:bottle_fuel"},
|
||||
{"biofuel:bottle_fuel", "biofuel:bottle_fuel", "biofuel:bottle_fuel"},
|
||||
{"biofuel:bottle_fuel", "biofuel:can", "biofuel:bottle_fuel"}
|
||||
},
|
||||
replacements = {{"biofuel:bottle_fuel", "vessels:glass_bottle"},{"biofuel:bottle_fuel", "vessels:glass_bottle"},{"biofuel:bottle_fuel", "vessels:glass_bottle"},{"biofuel:bottle_fuel", "vessels:glass_bottle"},{"biofuel:bottle_fuel", "vessels:glass_bottle"},{"biofuel:bottle_fuel", "vessels:glass_bottle"},{"biofuel:bottle_fuel", "vessels:glass_bottle"},{"biofuel:bottle_fuel", "vessels:glass_bottle"}},
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
@ -59,8 +110,8 @@ minetest.register_craft({
|
||||
recipe = {
|
||||
{"group:biofuel", "group:biofuel", "group:biofuel"},
|
||||
{"group:biofuel", "group:biofuel", "group:biofuel"},
|
||||
{"group:biofuel", "group:biofuel", "group:biofuel"}
|
||||
}
|
||||
{"group:biofuel", "biofuel:can", "group:biofuel"}
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
|
39
fix_furnace.lua
Normal file
39
fix_furnace.lua
Normal file
@ -0,0 +1,39 @@
|
||||
|
||||
-- THIS CODE CAN BE REMOVED WHEN ISSUES https://gitlab.com/VanessaE/pipeworks/-/merge_requests/47 AND https://github.com/minetest/minetest_game/pull/2895 WILL BE MERGED.
|
||||
|
||||
local function biofuel_fix_furance(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
local item = inv:get_stack("fuel", 1)
|
||||
local is_fuel = minetest.get_craft_result({method = "fuel", width = 1, items = {item:to_string()}})
|
||||
if is_fuel.time == 0 then
|
||||
inv:set_stack("fuel", 1, "")
|
||||
local leftover = inv:add_item("dst", item)
|
||||
if not leftover:is_empty() then
|
||||
local above = vector.new(pos.x, pos.y + 1, pos.z)
|
||||
local drop_pos = minetest.find_node_near(above, 1, {"air"}) or above
|
||||
minetest.item_drop(replacements[1], nil, drop_pos)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local furnace_def = minetest.registered_nodes["default:furnace"]
|
||||
local old_on_timer = furnace_def.on_timer;
|
||||
minetest.override_item("default:furnace", {
|
||||
on_timer = function(pos, elapsed)
|
||||
local ret = old_on_timer(pos, elapsed)
|
||||
biofuel_fix_furance(pos)
|
||||
return ret
|
||||
end
|
||||
})
|
||||
|
||||
local furnace_active_def = minetest.registered_nodes["default:furnace_active"]
|
||||
local old_on_timer_active = furnace_active_def.on_timer;
|
||||
minetest.override_item("default:furnace_active", {
|
||||
on_timer = function(pos, elapsed)
|
||||
local ret = old_on_timer(pos, elapsed)
|
||||
biofuel_fix_furance(pos)
|
||||
return ret
|
||||
end
|
||||
})
|
||||
|
6
init.lua
6
init.lua
@ -1,2 +1,8 @@
|
||||
dofile(minetest.get_modpath('biofuel')..'/biofuel.lua')
|
||||
dofile(minetest.get_modpath('biofuel')..'/refinery.lua')
|
||||
|
||||
-- THIS CODE CAN BE REMOVED WHEN ISSUES https://gitlab.com/VanessaE/pipeworks/-/merge_requests/47 AND https://github.com/minetest/minetest_game/pull/2895 WILL BE MERGED.
|
||||
if minetest.settings:get_bool("biofuel_fix_furnace",true) then
|
||||
dofile(minetest.get_modpath('biofuel')..'/fix_furnace.lua')
|
||||
end
|
||||
|
||||
|
55
refinery.lua
55
refinery.lua
@ -7,6 +7,7 @@
|
||||
--Modified Work Copyright (C) 2018 naturefreshmilk
|
||||
--Modified Work Copyright (C) 2019 OgelGames
|
||||
--Modified Work Copyright (C) 2020 6r1d
|
||||
--Modified Work Copyright (C) 2021 SFENCE
|
||||
|
||||
|
||||
-- Load support for MT game translation.
|
||||
@ -138,6 +139,18 @@ plants_input = tonumber(minetest.settings:get("biomass_input")) or 4 -- The num
|
||||
bottle_output = minetest.settings:get_bool("refinery_output") -- Change of refinery output between vial or bottle (settingtypes.txt)
|
||||
if bottle_output == nil then bottle_output = false end -- default false
|
||||
|
||||
local function is_vessel(input)
|
||||
if bottle_output then
|
||||
if (input=="vessels:glass_bottle") then
|
||||
return true
|
||||
end
|
||||
else
|
||||
if (input=="biofuel:phial") then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local function formspec(pos)
|
||||
local spos = pos.x..','..pos.y..','..pos.z
|
||||
@ -174,7 +187,10 @@ local function count_input(pos)
|
||||
local inv = meta:get_inventory()
|
||||
local stacks = inv:get_list('src')
|
||||
for k in pairs(stacks) do
|
||||
q = q + inv:get_stack('src', k):get_count()
|
||||
local stack = inv:get_stack('src', k)
|
||||
if (is_vessel(stack:get_name())==false) then
|
||||
q = q + stack:get_count()
|
||||
end
|
||||
end
|
||||
return q
|
||||
end
|
||||
@ -190,6 +206,18 @@ local function count_output(pos)
|
||||
return q
|
||||
end
|
||||
|
||||
local function have_vessel(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
local stacks = inv:get_list('src')
|
||||
for k in pairs(stacks) do
|
||||
if is_vessel(inv:get_stack('src', k):get_name()) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local function is_empty(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
@ -230,16 +258,17 @@ local function update_timer(pos)
|
||||
return
|
||||
end
|
||||
local count = count_input(pos)
|
||||
local vessel = have_vessel(pos)
|
||||
local refinery_time = minetest.settings:get("fuel_production_time") or 10 -- Timebase (settingtypes.txt)
|
||||
if not timer:is_started() and count >= plants_input then -- Input
|
||||
if not timer:is_started() and count >= plants_input and vessel then -- Input
|
||||
timer:start((refinery_time)/5) -- Timebase
|
||||
meta:set_int('progress', 0)
|
||||
meta:set_string('infotext', S("progress: @1%", "0"))
|
||||
return
|
||||
end
|
||||
if timer:is_started() and count < plants_input then -- Input
|
||||
if timer:is_started() and (count < plants_input or not vessel) then -- Input
|
||||
timer:stop()
|
||||
meta:set_string('infotext', S("To start fuel production add biomass "))
|
||||
meta:set_string('infotext', S("To start fuel production add biomass or vessel"))
|
||||
meta:set_int('progress', 0)
|
||||
end
|
||||
end
|
||||
@ -252,7 +281,7 @@ local function create_biofuel(pos)
|
||||
local stacks = inv:get_list('src')
|
||||
for k in pairs(stacks) do
|
||||
local stack = inv:get_stack('src', k)
|
||||
if not stack:is_empty() then
|
||||
if (not stack:is_empty()) and (not is_vessel(stack:get_name())) then
|
||||
local count = stack:get_count()
|
||||
if count <= q then
|
||||
inv:set_stack('src', k, '')
|
||||
@ -270,8 +299,10 @@ local function create_biofuel(pos)
|
||||
local count = stack:get_count()
|
||||
if 99 > count then
|
||||
if bottle_output then
|
||||
inv:remove_item('src', ItemStack('vessels:glass_bottle'))
|
||||
inv:set_stack('dst', k, 'biofuel:bottle_fuel ' .. (count + 1))
|
||||
else
|
||||
inv:remove_item('src', ItemStack('biofuel:phial'))
|
||||
inv:set_stack('dst', k, 'biofuel:phial_fuel ' .. (count + 1))
|
||||
end
|
||||
break
|
||||
@ -295,12 +326,12 @@ local function on_timer(pos)
|
||||
meta:set_int('progress', 0)
|
||||
return false
|
||||
end
|
||||
if count_input(pos) >= plants_input then --Input
|
||||
if count_input(pos) >= plants_input and have_vessel(pos) then --Input
|
||||
meta:set_string('infotext', S("progress: @1%", progress))
|
||||
return true
|
||||
else
|
||||
timer:stop()
|
||||
meta:set_string('infotext', S("To start fuel production add biomass "))
|
||||
meta:set_string('infotext', S("To start fuel production add biomass or vessel "))
|
||||
meta:set_int('progress', 0)
|
||||
return false
|
||||
end
|
||||
@ -311,7 +342,7 @@ local function on_construct(pos)
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size('src', 9) -- Input Fields
|
||||
inv:set_size('dst', 4) -- Output Fields
|
||||
meta:set_string('infotext', S("To start fuel production add biomass "))
|
||||
meta:set_string('infotext', S("To start fuel production add biomass and vessel "))
|
||||
meta:set_int('progress', 0)
|
||||
end
|
||||
|
||||
@ -343,8 +374,8 @@ local tube = {
|
||||
insert_object = function(pos, node, stack, direction)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
local convertible = is_convertible(stack:get_name())
|
||||
if not convertible then
|
||||
local insertable = is_convertible(stack:get_name()) or is_vessel(stack:get_name())
|
||||
if not insertable then
|
||||
return stack
|
||||
end
|
||||
|
||||
@ -358,7 +389,7 @@ local tube = {
|
||||
local inv = meta:get_inventory()
|
||||
stack = stack:peek_item(1)
|
||||
|
||||
return is_convertible(stack:get_name()) and inv:room_for_item("src", stack)
|
||||
return (is_convertible(stack:get_name()) or is_vessel(stack:get_name())) and inv:room_for_item("src", stack)
|
||||
end,
|
||||
input_inventory = "dst",
|
||||
connect_sides = {left = 1, right = 1, back = 1, front = 1, bottom = 1, top = 1}
|
||||
@ -381,7 +412,7 @@ local function allow_metadata_inventory_put(pos, listname, index, stack, player)
|
||||
return 0
|
||||
end
|
||||
|
||||
if listname == 'src' and is_convertible(stack:get_name()) then
|
||||
if listname == 'src' and (is_convertible(stack:get_name()) or is_vessel(stack:get_name())) then
|
||||
return stack:get_count()
|
||||
else
|
||||
return 0
|
||||
|
BIN
textures/biofuel_phial.png
Normal file
BIN
textures/biofuel_phial.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 231 B |
Loading…
Reference in New Issue
Block a user