forked from mrkubax10/industrialtest
Don't destroy generator that has items inside
This commit is contained in:
parent
511c4948d6
commit
6c62b8d4a3
35
machines.lua
35
machines.lua
@ -32,6 +32,21 @@ local function generatorFormspec(fuelPercent)
|
||||
}
|
||||
return table.concat(formspec,"")
|
||||
end
|
||||
local function generatorMclAfterDigNode(pos,oldnode,oldmeta,digger)
|
||||
-- Taken from https://git.minetest.land/MineClone2/MineClone2/src/branch/master/mods/ITEMS/mcl_furnaces/init.lua#L538
|
||||
local meta=minetest.get_meta(pos)
|
||||
local meta2=meta
|
||||
meta:from_table(oldmeta)
|
||||
local inv=meta:get_inventory()
|
||||
for _,listname in ipairs({"src", "dst", "fuel"}) do
|
||||
local stack=inv:get_stack(listname,1)
|
||||
if not stack:is_empty() then
|
||||
local p = {x=pos.x+math.random(0, 10)/10-0.5, y=pos.y, z=pos.z+math.random(0, 10)/10-0.5}
|
||||
minetest.add_item(p, stack)
|
||||
end
|
||||
end
|
||||
meta:from_table(meta2:to_table())
|
||||
end
|
||||
local definition={
|
||||
description=S("Generator"),
|
||||
tiles={"industrialtest_iron_furnace.png"},
|
||||
@ -51,7 +66,10 @@ local definition={
|
||||
local fuelTime=meta:get_int("fuelTime")
|
||||
local fuelList=inv:get_list("fuel")
|
||||
local chargedList=inv:get_list("charged")
|
||||
if fuelTime==0 and not industrialtest.api.isFullyCharged(meta) then
|
||||
if industrialtest.api.isFullyCharged(meta) then
|
||||
return false
|
||||
else
|
||||
if fuelTime==0 then
|
||||
local fuel,after=minetest.get_craft_result({
|
||||
method="fuel",
|
||||
width=1,
|
||||
@ -65,6 +83,7 @@ local definition={
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
fuelTime=fuelTime-elapsed
|
||||
if fuelTime<0 then
|
||||
fuelTime=0
|
||||
@ -72,9 +91,10 @@ local definition={
|
||||
meta:set_int("fuelTime",fuelTime)
|
||||
meta:set_string("formspec",generatorFormspec(fuelTime/meta:get_int("maxFuelTime")*100))
|
||||
industrialtest.api.addPower(meta,100)
|
||||
if fuelTime>0 then
|
||||
if fuelTime>0 or fuelList[1]:get_count()>0 then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end,
|
||||
allow_metadata_inventory_put=function(pos,listname,index,stack,player)
|
||||
if listname=="charged" and not industrialtest.api.hasPowerStorage(stack:get_meta()) then
|
||||
@ -90,7 +110,16 @@ local definition={
|
||||
end
|
||||
}
|
||||
if industrialtest.mtgAvailable then
|
||||
definition.groups={cracky=1}
|
||||
definition.groups={cracky=2}
|
||||
definition.sounds=default.node_sound_metal_defaults()
|
||||
definition.can_dig=function(pos)
|
||||
local meta=minetest.get_meta(pos)
|
||||
local inv=meta:get_inventory()
|
||||
return not (inv:get_list("charged")[1]:get_count()>0 or inv:get_list("fuel")[1]:get_count()>0)
|
||||
end
|
||||
elseif industrialtest.mclAvailable then
|
||||
definition.after_dig_node=generatorMclAfterDigNode
|
||||
definition._mcl_blast_resistance=3.5
|
||||
definition._mcl_hardness=3.9
|
||||
end
|
||||
minetest.register_node("industrialtest:generator",definition)
|
||||
|
Loading…
Reference in New Issue
Block a user