Furnace: Attempt to fix exploits
authorAuke Kok <sofar@foo-projects.org>
Thu, 15 Dec 2016 07:45:48 +0000 (23:45 -0800)
committerparamat <mat.gregory@virginmedia.com>
Sat, 17 Dec 2016 20:01:46 +0000 (20:01 +0000)
The fuel would remain active even if source went empty, giving
free cook time to newly inserted items. This patch is supposed
to stop this.

mods/default/furnace.lua

index fed7cf2e446b3d83ad59c8b0c4fdf5c163e551ea..4b82205825ece9ff25223960bc19bea59fa24839 100644 (file)
@@ -116,6 +116,7 @@ local function furnace_node_timer(pos, elapsed)
        local srclist, fuellist
 
        local cookable, cooked
+       local fuel
 
        local update = true
        while update do
@@ -154,7 +155,8 @@ local function furnace_node_timer(pos, elapsed)
                        -- Furnace ran out of fuel
                        if cookable then
                                -- We need to get new fuel
-                               local fuel, afterfuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist})
+                               local afterfuel
+                               fuel, afterfuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist})
 
                                if fuel.time == 0 then
                                        -- No valid fuel in fuel list
@@ -164,7 +166,6 @@ local function furnace_node_timer(pos, elapsed)
                                        -- Take fuel from fuel list
                                        inv:set_stack("fuel", 1, afterfuel.items[1])
                                        update = true
-
                                        fuel_totaltime = fuel.time + (fuel_time - fuel_totaltime)
                                        src_time = src_time + elapsed
                                end
@@ -179,6 +180,13 @@ local function furnace_node_timer(pos, elapsed)
                elapsed = 0
        end
 
+       if fuel and fuel_totaltime > fuel.time then
+               fuel_totaltime = fuel.time
+       end
+       if srclist[1]:is_empty() then
+               src_time = 0
+       end
+
        --
        -- Update formspec, infotext and node
        --