mirror of
https://github.com/Lokrates/Biofuel.git
synced 2024-08-19 19:34:04 +02:00
Make refineri require empthy vessel to produce biofuel.
This commit is contained in:
parent
f4ddec574c
commit
2e5f3cf217
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.
|
||||
@ -137,6 +138,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
|
||||
@ -173,7 +186,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
|
||||
@ -189,6 +205,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()
|
||||
@ -229,16 +257,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
|
||||
@ -251,7 +280,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, '')
|
||||
@ -269,8 +298,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
|
||||
@ -294,12 +325,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
|
||||
@ -310,7 +341,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
|
||||
|
||||
@ -342,8 +373,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
|
||||
|
||||
@ -357,7 +388,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_vessels(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}
|
||||
@ -380,7 +411,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
|
||||
|
Loading…
Reference in New Issue
Block a user