Skip to content

Commit

Permalink
Fuel device: fix imediatly result on first step. Fixes #1834
Browse files Browse the repository at this point in the history
  • Loading branch information
alek13 committed Dec 12, 2024
1 parent e767d52 commit 47b8159
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 30 deletions.
26 changes: 4 additions & 22 deletions mods/lord/Core/fuel_device/src/fuel_device/Device.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,6 @@ end
-- -----------------------------------------------------------------------------------------------
-- Private functions:

--- @private
--- @param pos table<number,number,number>
--- @return NodeMetaRef
local function get_initiated_meta(pos)
local meta = minetest.get_meta(pos)
for _, name in pairs({
'fuel_totaltime',
'fuel_time',
'src_totaltime',
'src_time'
}) do
if not meta:get_float(name) then
meta:set_float(name, 0.0)
end
end
return meta
end

--- @param meta NodeMetaRef
local function reset_meta_times(meta)
for _, name in pairs({
Expand All @@ -84,7 +66,7 @@ local function reset_meta_times(meta)
'src_totaltime',
'src_time'
}) do
meta:set_float(name, 0.0)
meta:set_int(name, 0)
end
end

Expand All @@ -95,7 +77,7 @@ end
--- @return NodeMetaRef
function Device:get_meta()
if not self.meta then
self.meta = get_initiated_meta(self.position)
self.meta = minetest.get_meta(self.position)
end

return self.meta
Expand Down Expand Up @@ -124,8 +106,8 @@ end
--- @param hint string text shown in `infotext` after `"<Device.NAME>: "`
function Device:activate(hint)
local meta = self:get_meta()
local percent = math_floor(meta:get_float('fuel_time') / meta:get_float('fuel_totaltime') * 100)
local item_percent = math_floor(meta:get_float('src_time') / meta:get_float('src_totaltime') * 100)
local percent = math_floor(meta:get_int('fuel_time') / meta:get_int('fuel_totaltime') * 100)
local item_percent = math_floor(meta:get_int('src_time') / meta:get_int('src_totaltime') * 100)
minetest.swap_node_if_not_same(self.position, self.node_name.active)
self:get_meta():set_string('infotext', self.NAME .. ': ' .. hint .. ' (' .. percent .. '%)')
self:get_meta():set_string('formspec', self.form.get_spec('active', percent, item_percent))
Expand Down
10 changes: 3 additions & 7 deletions mods/lord/Core/fuel_device/src/fuel_device/Processor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,9 @@ end
--- @param remaining_source RecipeInput
--- @param result_source RecipeOutput
--- @param time number
local function grind_source(meta, remaining_source, result_source)
local function process_source(meta, remaining_source, result_source)
local src_time = meta:get_int('src_time')
local src_totaltime = meta:get_int('src_totaltime')

if src_time == 0 or src_totaltime == 0 then
meta:set_int('src_totaltime', result_source.time)
end
local src_totaltime = result_source.time

src_time = src_time + 1

Expand Down Expand Up @@ -154,7 +150,7 @@ function Processor:act(position)
device:activate(S('Active'))

burn_fuel(meta, remaining_fuel, result_fuel)
grind_source(meta, remaining_source, result_source)
process_source(meta, remaining_source, result_source)
else
device:deactivate(S('Out Of Fuel'))
end
Expand Down
2 changes: 1 addition & 1 deletion util/mt-ide-helper/classes/MetaDataRef.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function MetaDataRef:get_string(key) end
function MetaDataRef:set_int(key, value) end

---@param key string
---@return number
---@return number Returns `0` if `key` not present.
function MetaDataRef:get_int(key) end

---@param key string
Expand Down

0 comments on commit 47b8159

Please sign in to comment.