Implement scanners and add way to use them in Miner
This commit is contained in:
parent
ea422c5999
commit
50565ca604
1
init.lua
1
init.lua
@ -86,6 +86,7 @@ dofile(modpath.."/tools/jetpack.lua")
|
|||||||
dofile(modpath.."/tools/mining_laser.lua")
|
dofile(modpath.."/tools/mining_laser.lua")
|
||||||
dofile(modpath.."/tools/nano_suit.lua")
|
dofile(modpath.."/tools/nano_suit.lua")
|
||||||
dofile(modpath.."/tools/power_storage.lua")
|
dofile(modpath.."/tools/power_storage.lua")
|
||||||
|
dofile(modpath.."/tools/scanner.lua")
|
||||||
dofile(modpath.."/tools/solar_helmet.lua")
|
dofile(modpath.."/tools/solar_helmet.lua")
|
||||||
dofile(modpath.."/tools/static_boots.lua")
|
dofile(modpath.."/tools/static_boots.lua")
|
||||||
dofile(modpath.."/tools/treetap.lua")
|
dofile(modpath.."/tools/treetap.lua")
|
||||||
|
@ -152,7 +152,8 @@ industrialtest.internal.unpackTableInto(industrialtest.Miner,{
|
|||||||
capacity=5000,
|
capacity=5000,
|
||||||
ioConfig="iiiiii",
|
ioConfig="iiiiii",
|
||||||
hasPowerInput=true,
|
hasPowerInput=true,
|
||||||
_opPower=1000
|
_opPower=1000,
|
||||||
|
_scannerOpPower=10
|
||||||
})
|
})
|
||||||
|
|
||||||
function industrialtest.Miner.onConstruct(self,pos)
|
function industrialtest.Miner.onConstruct(self,pos)
|
||||||
@ -212,7 +213,8 @@ function industrialtest.Miner.canUpdate(self,pos)
|
|||||||
local drillSlot=inv:get_stack("drill",1)
|
local drillSlot=inv:get_stack("drill",1)
|
||||||
local srcSlot=inv:get_stack("src",1)
|
local srcSlot=inv:get_stack("src",1)
|
||||||
local level=meta:get_int("level")
|
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)
|
self:canContinue(pos,level)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -284,8 +286,25 @@ function industrialtest.Miner.update(self,pos,elapsed,meta,inv)
|
|||||||
local drop=self.getNodeDrop(targetPos)
|
local drop=self.getNodeDrop(targetPos)
|
||||||
self.placeMiningPipe(pos,targetPos)
|
self.placeMiningPipe(pos,targetPos)
|
||||||
inv:add_item("dst",drop)
|
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)
|
meta:set_int("level",level-1)
|
||||||
industrialtest.api.addPower(meta,-self._opPower)
|
industrialtest.api.addPower(meta,-requiredPower)
|
||||||
|
|
||||||
return true,true
|
return true,true
|
||||||
end
|
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)
|
return not (def and def.groups and def.groups.unbreakable) and inv:room_for_item("dst",drop)
|
||||||
end
|
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)
|
function industrialtest.Miner.getNodeDrop(pos)
|
||||||
local node=minetest.get_node(pos)
|
local node=minetest.get_node(pos)
|
||||||
local def=minetest.registered_nodes[node.name]
|
local def=minetest.registered_nodes[node.name]
|
||||||
|
152
tools/scanner.lua
Normal file
152
tools/scanner.lua
Normal file
@ -0,0 +1,152 @@
|
|||||||
|
-- IndustrialTest
|
||||||
|
-- Copyright (C) 2025 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")
|
||||||
|
|
||||||
|
industrialtest.Scanner=table.copy(industrialtest.ElectricTool)
|
||||||
|
industrialtest.internal.unpackTableInto(industrialtest.Scanner,{
|
||||||
|
define={onUse=true}
|
||||||
|
})
|
||||||
|
|
||||||
|
function industrialtest.Scanner.createDefinitionTable(self)
|
||||||
|
local def=industrialtest.ElectricTool.createDefinitionTable(self)
|
||||||
|
def.groups._industrialtest_scanner=1
|
||||||
|
return def
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Used by Miner to provide Scanner functionality there
|
||||||
|
function industrialtest.Scanner.filter(self,pos)
|
||||||
|
-- dummy function
|
||||||
|
return {}
|
||||||
|
end
|
||||||
|
|
||||||
|
industrialtest.OreScanner=table.copy(industrialtest.Scanner)
|
||||||
|
|
||||||
|
function industrialtest.OreScanner.hitUse(self,itemstack,user,pointed)
|
||||||
|
if not user:is_player() then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
local positions=""
|
||||||
|
local pos=user:get_pos()
|
||||||
|
for x=pos.x-self.distance,pos.x+self.distance do
|
||||||
|
for y=pos.y-self.distance,pos.y+self.distance do
|
||||||
|
for z=pos.z-self.distance,pos.z+self.distance do
|
||||||
|
local targetPos=vector.new(x,y,z)
|
||||||
|
local node=minetest.get_node(targetPos)
|
||||||
|
if self.isOre(node) then
|
||||||
|
positions=positions..string.format("%d %d %d",x,y,z)
|
||||||
|
positions=positions..","
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local formspec={
|
||||||
|
"formspec_version[4]",
|
||||||
|
"size[10.5,11]",
|
||||||
|
"label[0.5,0.5;"..self.description.."]",
|
||||||
|
"label[0.5,1.7;"..S("Found ores").."]",
|
||||||
|
"textlist[0.5,1.9;9.5,8.6;pos;"..positions.."]"
|
||||||
|
}
|
||||||
|
local content=table.concat(formspec,"")
|
||||||
|
minetest.show_formspec(user:get_player_name(),"industrialtest:scanner",content)
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
function industrialtest.OreScanner.filter(self,pos)
|
||||||
|
local result={}
|
||||||
|
for x=pos.x-self.minerDistance,pos.x+self.minerDistance do
|
||||||
|
for z=pos.z-self.minerDistance,pos.z+self.minerDistance do
|
||||||
|
local nodePos=vector.new(x,pos.y,z)
|
||||||
|
local node=minetest.get_node(nodePos)
|
||||||
|
-- This is very hacky, but currently there is no other way of determining if node is ore
|
||||||
|
if (x~=pos.x or z~=pos.z) and self.isOre(node) then
|
||||||
|
table.insert(result,nodePos)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
|
function industrialtest.OreScanner.isOre(node)
|
||||||
|
return string.find(node.name,":stone_with_")
|
||||||
|
end
|
||||||
|
|
||||||
|
industrialtest.ODScanner=table.copy(industrialtest.OreScanner)
|
||||||
|
industrialtest.internal.unpackTableInto(industrialtest.ODScanner,{
|
||||||
|
name="industrialtest:od_scanner",
|
||||||
|
description=S("OD Scanner"),
|
||||||
|
inventoryImage="industrialtest_od_scanner.png",
|
||||||
|
capacity=100000,
|
||||||
|
flow=industrialtest.api.lvPowerFlow,
|
||||||
|
distance=7,
|
||||||
|
minerDistance=3
|
||||||
|
})
|
||||||
|
|
||||||
|
function industrialtest.ODScanner.getOpPower(self,itemstack)
|
||||||
|
return 700
|
||||||
|
end
|
||||||
|
|
||||||
|
industrialtest.ODScanner:register()
|
||||||
|
|
||||||
|
minetest.register_craft({
|
||||||
|
type="shaped",
|
||||||
|
output="industrialtest:od_scanner",
|
||||||
|
recipe={
|
||||||
|
{"",industrialtest.elementKeys.yellowDust,""},
|
||||||
|
{"industrialtest:electronic_circuit","industrialtest:re_battery","industrialtest:electronic_circuit"},
|
||||||
|
{"industrialtest:insulated_copper_cable","industrialtest:insulated_copper_cable","industrialtest:insulated_copper_cable"}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
industrialtest.OVScanner=table.copy(industrialtest.OreScanner)
|
||||||
|
industrialtest.internal.unpackTableInto(industrialtest.OVScanner,{
|
||||||
|
name="industrialtest:ov_scanner",
|
||||||
|
description=S("OV Scanner"),
|
||||||
|
inventoryImage="industrialtest_ov_scanner.png",
|
||||||
|
capacity=1000000,
|
||||||
|
flow=industrialtest.api.mvPowerFlow,
|
||||||
|
distance=11,
|
||||||
|
minerDistance=5
|
||||||
|
})
|
||||||
|
|
||||||
|
function industrialtest.OVScanner.getOpPower(self,itemstack)
|
||||||
|
return 7000
|
||||||
|
end
|
||||||
|
|
||||||
|
industrialtest.OVScanner:register()
|
||||||
|
|
||||||
|
minetest.register_craft({
|
||||||
|
type="shaped",
|
||||||
|
output="industrialtest:ov_scanner",
|
||||||
|
recipe={
|
||||||
|
{"",industrialtest.elementKeys.yellowDust,""},
|
||||||
|
{industrialtest.elementKeys.yellowDust,"industrialtest:electronic_circuit",industrialtest.elementKeys.yellowDust},
|
||||||
|
{"industrialtest:insulated_gold_cable","industrialtest:od_scanner","industrialtest:insulated_gold_cable"}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_craft({
|
||||||
|
type="shaped",
|
||||||
|
output="industrialtest:ov_scanner",
|
||||||
|
recipe={
|
||||||
|
{"",industrialtest.elementKeys.yellowDust,""},
|
||||||
|
{industrialtest.elementKeys.yellowDust,"industrialtest:electronic_circuit",industrialtest.elementKeys.yellowDust},
|
||||||
|
{"industrialtest:insulated_gold_cable","industrialtest:re_battery","industrialtest:insulated_gold_cable"}
|
||||||
|
}
|
||||||
|
})
|
Loading…
x
Reference in New Issue
Block a user