Merge pull request #57 from oversword/bls-258

Disallow non-fuel items to be accepted as fuel quarries and harvesters
This commit is contained in:
Joachim Stolberg 2020-12-14 22:40:54 +01:00 committed by GitHub
commit 127327c71a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 4 deletions

@ -119,7 +119,7 @@ local function allow_metadata_inventory_put(pos, listname, index, stack, player)
local inv = M(pos):get_inventory()
if listname == "main" then
return stack:get_count()
elseif listname == "fuel" and stack:get_name() == "tubelib_addons1:biofuel" then
elseif listname == "fuel" and tubelib.is_fuel(stack) then
return stack:get_count()
end
return 0
@ -190,7 +190,12 @@ end
-- check the fuel level and return false if empty
local function check_fuel(pos, this, meta)
if this.fuel <= 0 then
if tubelib.get_this_item(meta, "fuel", 1) == nil then
local fuel_item = tubelib.get_this_item(meta, "fuel", 1)
if fuel_item == nil then
return false
end
if not tubelib.is_fuel(fuel_item) then
tubelib.put_item(meta, "fuel", fuel_item)
return false
end
this.fuel = BURNING_TIME
@ -443,6 +448,9 @@ tubelib.register_node("tubelib_addons1:harvester_base", {"tubelib_addons1:harves
return tubelib.get_item(M(pos), "main")
end,
on_push_item = function(pos, side, item)
if not tubelib.is_fuel(item) then
return false
end
return tubelib.put_item(M(pos), "fuel", item)
end,
on_unpull_item = function(pos, side, item)

@ -122,7 +122,7 @@ local function allow_metadata_inventory_put(pos, listname, index, stack, player)
local inv = M(pos):get_inventory()
if listname == "main" then
return stack:get_count()
elseif listname == "fuel" and stack:get_name() == "tubelib_addons1:biofuel" then
elseif listname == "fuel" and tubelib.is_fuel(stack) then
return stack:get_count()
end
return 0
@ -164,10 +164,16 @@ local function quarry_next_node(pos, meta)
-- check fuel
local fuel = meta:get_int("fuel") or 0
if fuel <= 0 then
if tubelib.get_this_item(meta, "fuel", 1) == nil then
local fuel_item = tubelib.get_this_item(meta, "fuel", 1)
if fuel_item == nil then
State:fault(pos, meta)
return
end
if not tubelib.is_fuel(fuel_item) then
State:fault(pos, meta)
tubelib.put_item(meta, "fuel", fuel_item)
return
end
fuel = BURNING_TIME
else
fuel = fuel - 1
@ -443,6 +449,9 @@ tubelib.register_node("tubelib_addons1:quarry",
return tubelib.get_item(M(pos), "main")
end,
on_push_item = function(pos, side, item)
if not tubelib.is_fuel(item) then
return false
end
return tubelib.put_item(M(pos), "fuel", item)
end,
on_unpull_item = function(pos, side, item)

@ -342,6 +342,9 @@ minetest.register_craft({
},
})
function tubelib.is_fuel(stack)
return stack:get_name() == "tubelib_addons1:biofuel"
end
tubelib.register_node("tubelib_addons1:reformer", {"tubelib_addons1:reformer_defect"}, {
on_pull_item = function(pos, side)