Implement scanners and add way to use them in Miner

This commit is contained in:
2025-05-08 22:25:32 +02:00
parent ea422c5999
commit 50565ca604
3 changed files with 190 additions and 3 deletions

View File

@@ -152,7 +152,8 @@ industrialtest.internal.unpackTableInto(industrialtest.Miner,{
capacity=5000,
ioConfig="iiiiii",
hasPowerInput=true,
_opPower=1000
_opPower=1000,
_scannerOpPower=10
})
function industrialtest.Miner.onConstruct(self,pos)
@@ -212,7 +213,8 @@ function industrialtest.Miner.canUpdate(self,pos)
local drillSlot=inv:get_stack("drill",1)
local srcSlot=inv:get_stack("src",1)
local level=meta:get_int("level")
return meta:get_int("industrialtest.powerAmount")>=self._opPower and not drillSlot:is_empty() and not srcSlot:is_empty() and
local requiredPower=self:getRequiredPower(pos)
return meta:get_int("industrialtest.powerAmount")>=requiredPower and not drillSlot:is_empty() and not srcSlot:is_empty() and
self:canContinue(pos,level)
end
@@ -284,8 +286,25 @@ function industrialtest.Miner.update(self,pos,elapsed,meta,inv)
local drop=self.getNodeDrop(targetPos)
self.placeMiningPipe(pos,targetPos)
inv:add_item("dst",drop)
local scannerSlot=inv:get_stack("scanner",1)
if not scannerSlot:is_empty() then
local def=scannerSlot:get_definition()
if def and def._industrialtest_self then
local filtered=def._industrialtest_self:filter(targetPos)
for _,filteredPos in ipairs(filtered) do
drop=self.getNodeDrop(filteredPos)
if inv:room_for_item("dst",drop) then
minetest.remove_node(filteredPos)
inv:add_item("dst",drop)
end
end
end
end
local requiredPower=self:getRequiredPower(pos)
meta:set_int("level",level-1)
industrialtest.api.addPower(meta,-self._opPower)
industrialtest.api.addPower(meta,-requiredPower)
return true,true
end
@@ -324,6 +343,21 @@ function industrialtest.Miner.canContinue(self,pos,level)
return not (def and def.groups and def.groups.unbreakable) and inv:room_for_item("dst",drop)
end
function industrialtest.Miner.getRequiredPower(self,pos)
local meta=minetest.get_meta(pos)
local inv=meta:get_inventory()
local scannerSlot=inv:get_stack("scanner",1)
local result=self._opPower
if not scannerSlot:is_empty() then
local def=scannerSlot:get_definition()
if def and def._industrialtest_self then
local distance=def._industrialtest_self.minerDistance or 0
result=result+(distance*distance-1)*self._scannerOpPower
end
end
return result
end
function industrialtest.Miner.getNodeDrop(pos)
local node=minetest.get_node(pos)
local def=minetest.registered_nodes[node.name]