forked from mrkubax10/industrialtest
Start implementing coal generator
This commit is contained in:
parent
f6383b020f
commit
511c4948d6
5
api.lua
5
api.lua
@ -31,6 +31,9 @@ industrialtest.api.hasPowerStorage=function(meta)
|
|||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
industrialtest.api.isFullyCharged=function(meta)
|
||||||
|
return meta:get_int("industrialtest.powerAmount")>=meta:get_int("industrialtest.powerCapacity")
|
||||||
|
end
|
||||||
industrialtest.api.addPower=function(meta,amount)
|
industrialtest.api.addPower=function(meta,amount)
|
||||||
local powerAmount=meta:get_int("industrialtest.powerAmount")
|
local powerAmount=meta:get_int("industrialtest.powerAmount")
|
||||||
local powerCapacity=meta:get_int("industrialtest.powerCapacity")
|
local powerCapacity=meta:get_int("industrialtest.powerCapacity")
|
||||||
@ -53,7 +56,7 @@ industrialtest.api.powerFlow=function(pos)
|
|||||||
vector.offset(pos,0,-1,0),
|
vector.offset(pos,0,-1,0),
|
||||||
vector.offset(pos,0,1,0),
|
vector.offset(pos,0,1,0),
|
||||||
vector.offset(pos,0,0,-1),
|
vector.offset(pos,0,0,-1),
|
||||||
vector.offset(pos,0,0,-1)
|
vector.offset(pos,0,0,1)
|
||||||
}
|
}
|
||||||
local neighbours={}
|
local neighbours={}
|
||||||
for key,value in ipairs(neighbourPositions) do
|
for key,value in ipairs(neighbourPositions) do
|
||||||
|
1
init.lua
1
init.lua
@ -24,3 +24,4 @@ industrialtest={}
|
|||||||
dofile(modpath.."/compatibility.lua")
|
dofile(modpath.."/compatibility.lua")
|
||||||
dofile(modpath.."/api.lua")
|
dofile(modpath.."/api.lua")
|
||||||
dofile(modpath.."/minerals.lua")
|
dofile(modpath.."/minerals.lua")
|
||||||
|
dofile(modpath.."/machines.lua")
|
||||||
|
96
machines.lua
Normal file
96
machines.lua
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
-- IndustrialTest
|
||||||
|
-- Copyright (C) 2023 mrkubax10
|
||||||
|
|
||||||
|
-- This program is free software: you can redistribute it and/or modify
|
||||||
|
-- it under the terms of the GNU General Public License as published by
|
||||||
|
-- the Free Software Foundation, either version 3 of the License, or
|
||||||
|
-- (at your option) any later version.
|
||||||
|
|
||||||
|
-- This program is distributed in the hope that it will be useful,
|
||||||
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
-- GNU General Public License for more details.
|
||||||
|
|
||||||
|
-- You should have received a copy of the GNU General Public License
|
||||||
|
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
local S=minetest.get_translator("industrialtest")
|
||||||
|
|
||||||
|
-- Generators
|
||||||
|
local function generatorFormspec(fuelPercent)
|
||||||
|
local formspec={
|
||||||
|
"formspec_version[4]",
|
||||||
|
"size[10.8,12]",
|
||||||
|
"label[0.5,0.5;"..S("Generator").."]",
|
||||||
|
"list[context;charged;4.9,1.8;1,1]",
|
||||||
|
"listring[context;charged]",
|
||||||
|
"image[4.9,2.8;1,1;default_furnace_fire_bg.png^[lowpart:"..fuelPercent..":default_furnace_fire_fg.png]",
|
||||||
|
"list[context;fuel;4.9,3.9;1,1]",
|
||||||
|
"listring[context;fuel]",
|
||||||
|
"list[current_player;main;0.5,6.25;8,1;]",
|
||||||
|
"list[current_player;main;0.5,7.5;8,3;8]"
|
||||||
|
}
|
||||||
|
return table.concat(formspec,"")
|
||||||
|
end
|
||||||
|
local definition={
|
||||||
|
description=S("Generator"),
|
||||||
|
tiles={"industrialtest_iron_furnace.png"},
|
||||||
|
paramtype2="4dir",
|
||||||
|
on_construct=function(pos,placer)
|
||||||
|
local meta=minetest.get_meta(pos)
|
||||||
|
local inv=meta:get_inventory()
|
||||||
|
inv:set_size("charged",1)
|
||||||
|
inv:set_size("fuel",1)
|
||||||
|
meta:set_string("formspec",generatorFormspec(0))
|
||||||
|
meta:set_int("fuelTime",0)
|
||||||
|
industrialtest.api.addPowerStorage(meta,5000,10,"oooooo")
|
||||||
|
end,
|
||||||
|
on_timer=function(pos,elapsed)
|
||||||
|
local meta=minetest.get_meta(pos)
|
||||||
|
local inv=meta:get_inventory()
|
||||||
|
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
|
||||||
|
local fuel,after=minetest.get_craft_result({
|
||||||
|
method="fuel",
|
||||||
|
width=1,
|
||||||
|
items=fuelList
|
||||||
|
})
|
||||||
|
if fuel.time>0 then
|
||||||
|
inv:set_stack("fuel",1,after.items[1])
|
||||||
|
fuelTime=fuel.time
|
||||||
|
meta:set_int("maxFuelTime",fuelTime)
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
fuelTime=fuelTime-elapsed
|
||||||
|
if fuelTime<0 then
|
||||||
|
fuelTime=0
|
||||||
|
end
|
||||||
|
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
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
allow_metadata_inventory_put=function(pos,listname,index,stack,player)
|
||||||
|
if listname=="charged" and not industrialtest.api.hasPowerStorage(stack:get_meta()) then
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
return stack:get_count()
|
||||||
|
end,
|
||||||
|
on_metadata_inventory_put=function(pos,listname,index,stack,player)
|
||||||
|
minetest.get_node_timer(pos):start(1.0)
|
||||||
|
end,
|
||||||
|
on_metadata_inventory_take=function(pos,listname,index,stack,player)
|
||||||
|
minetest.get_node_timer(pos):start(1.0)
|
||||||
|
end
|
||||||
|
}
|
||||||
|
if industrialtest.mtgAvailable then
|
||||||
|
definition.groups={cracky=1}
|
||||||
|
definition.sounds=default.node_sound_metal_defaults()
|
||||||
|
end
|
||||||
|
minetest.register_node("industrialtest:generator",definition)
|
Loading…
Reference in New Issue
Block a user