Refactor electric hoes
This commit is contained in:
parent
9cb5748b73
commit
6f864eca78
Before Width: | Height: | Size: 9.2 KiB After Width: | Height: | Size: 9.2 KiB |
@ -90,6 +90,8 @@ function industrialtest.ActivatedElectricTool.defineToolCapabilities(self,def,ti
|
|||||||
def.groups.pickaxe=1
|
def.groups.pickaxe=1
|
||||||
elseif digType=="crumbly" then
|
elseif digType=="crumbly" then
|
||||||
def.groups.shovel=1
|
def.groups.shovel=1
|
||||||
|
elseif digType=="hoey" then
|
||||||
|
def.groups.hoe=1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -97,7 +99,8 @@ function industrialtest.ActivatedElectricTool.defineToolCapabilities(self,def,ti
|
|||||||
local digTypeMapping={
|
local digTypeMapping={
|
||||||
choppy="axey",
|
choppy="axey",
|
||||||
cracky="pickaxey",
|
cracky="pickaxey",
|
||||||
crumbly="shovely"
|
crumbly="shovely",
|
||||||
|
hoey="hoey"
|
||||||
}
|
}
|
||||||
def.groups.dig_speed_class=self.digSpeedClass
|
def.groups.dig_speed_class=self.digSpeedClass
|
||||||
def._mcl_diggroups={}
|
def._mcl_diggroups={}
|
||||||
|
@ -15,184 +15,137 @@
|
|||||||
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
local S=minetest.get_translator("industrialtest")
|
local S=minetest.get_translator("industrialtest")
|
||||||
|
industrialtest.ElectricHoeBase=table.copy(industrialtest.ActivatedElectricTool)
|
||||||
|
industrialtest.internal.unpackTableInto(industrialtest.ElectricHoeBase,{
|
||||||
|
digs={"hoey"},
|
||||||
|
capacity=10000,
|
||||||
|
flow=industrialtest.api.lvPowerFlow
|
||||||
|
})
|
||||||
|
|
||||||
local electricHoe={}
|
function industrialtest.ElectricHoeBase.createDefinitionTable(self)
|
||||||
|
local def=industrialtest.ActivatedElectricTool.createDefinitionTable(self)
|
||||||
|
|
||||||
electricHoe.afterUse=function(itemstack,config)
|
if industrialtest.mtgAvailable then
|
||||||
local meta=itemstack:get_meta()
|
def.on_place=minetest.item_place
|
||||||
industrialtest.api.addPowerToItem(itemstack,-20)
|
elseif industrialtest.mclAvailable then
|
||||||
if meta:get_int("industrialtest.powerAmount")<20 then
|
def.on_use=nil
|
||||||
itemstack:set_name("industrialtest:"..config.name)
|
|
||||||
end
|
end
|
||||||
return itemstack
|
|
||||||
|
return def
|
||||||
end
|
end
|
||||||
|
|
||||||
local function registerElectricHoe(config)
|
function industrialtest.ElectricHoeBase.hitUse(self,itemstack,user,pointed)
|
||||||
local definition={
|
-- Taken and adapted from farming mod from Minetest Game
|
||||||
description=config.displayName,
|
local pt = pointed
|
||||||
inventory_image="industrialtest_"..config.name..".png",
|
-- check if pointing at a node
|
||||||
_industrialtest_powerStorage=true,
|
if not pt then
|
||||||
_industrialtest_powerCapacity=10000,
|
return false
|
||||||
_industrialtest_powerFlow=industrialtest.api.lvPowerFlow,
|
end
|
||||||
_industrialtest_inactiveName="industrialtest:"..config.name
|
if pt.type ~= "node" then
|
||||||
}
|
return false
|
||||||
if industrialtest.mtgAvailable then
|
end
|
||||||
-- Taken and adapted from farming mod from Minetest Game
|
|
||||||
local function onUse(user,pointed)
|
|
||||||
local pt = pointed
|
|
||||||
-- check if pointing at a node
|
|
||||||
if not pt then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
if pt.type ~= "node" then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
local under = minetest.get_node(pt.under)
|
local under = minetest.get_node(pt.under)
|
||||||
local p = {x=pt.under.x, y=pt.under.y+1, z=pt.under.z}
|
local p = {x=pt.under.x, y=pt.under.y+1, z=pt.under.z}
|
||||||
local above = minetest.get_node(p)
|
local above = minetest.get_node(p)
|
||||||
|
|
||||||
-- return if any of the nodes is not registered
|
-- return if any of the nodes is not registered
|
||||||
if not minetest.registered_nodes[under.name] then
|
if not minetest.registered_nodes[under.name] then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
if not minetest.registered_nodes[above.name] then
|
if not minetest.registered_nodes[above.name] then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
-- check if the node above the pointed thing is air
|
-- check if the node above the pointed thing is air
|
||||||
if above.name ~= "air" then
|
if above.name ~= "air" then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
-- check if pointing at soil
|
-- check if pointing at soil
|
||||||
if minetest.get_item_group(under.name, "soil") ~= 1 then
|
if minetest.get_item_group(under.name, "soil") ~= 1 then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
-- check if (wet) soil defined
|
-- check if (wet) soil defined
|
||||||
local regN = minetest.registered_nodes
|
local regN = minetest.registered_nodes
|
||||||
if regN[under.name].soil == nil or regN[under.name].soil.wet == nil or regN[under.name].soil.dry == nil then
|
if regN[under.name].soil == nil or regN[under.name].soil.wet == nil or regN[under.name].soil.dry == nil then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
local player_name = user and user:get_player_name() or ""
|
local player_name = user and user:get_player_name() or ""
|
||||||
|
|
||||||
if minetest.is_protected(pt.under, player_name) then
|
if minetest.is_protected(pt.under, player_name) then
|
||||||
minetest.record_protection_violation(pt.under, player_name)
|
minetest.record_protection_violation(pt.under, player_name)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
if minetest.is_protected(pt.above, player_name) then
|
if minetest.is_protected(pt.above, player_name) then
|
||||||
minetest.record_protection_violation(pt.above, player_name)
|
minetest.record_protection_violation(pt.above, player_name)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
-- turn the node into soil and play sound
|
-- turn the node into soil and play sound
|
||||||
minetest.set_node(pt.under, {name = regN[under.name].soil.dry})
|
minetest.set_node(pt.under, {name = regN[under.name].soil.dry})
|
||||||
minetest.sound_play("default_dig_crumbly", {
|
minetest.sound_play("default_dig_crumbly", {
|
||||||
pos = pt.under,
|
pos = pt.under,
|
||||||
gain = 0.3,
|
gain = 0.3,
|
||||||
}, true)
|
}, true)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
definition.groups={
|
|
||||||
hoe=1
|
function industrialtest.ElectricHoeBase.use(self,itemstack,user,pointed)
|
||||||
}
|
local node=minetest.get_node(pointed.under)
|
||||||
definition.on_use=function(itemstack,user,pointed)
|
if user and not user:get_player_control().sneak then
|
||||||
local meta=itemstack:get_meta()
|
if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].on_rightclick then
|
||||||
if meta:get_int("industrialtest.powerAmount")>=20 and onUse(user,pointed) then
|
minetest.registered_nodes[node.name].on_rightclick(pointed.under,node,user,itemstack)
|
||||||
industrialtest.api.addPowerToItem(itemstack,-20)
|
|
||||||
return itemstack
|
|
||||||
end
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
elseif industrialtest.mclAvailable then
|
|
||||||
-- Taken from https://git.minetest.land/MineClone2/MineClone2/src/branch/master/mods/ITEMS/mcl_farming/hoes.lua#L3
|
|
||||||
local function createSoil(pos)
|
|
||||||
if pos == nil then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
local node = minetest.get_node(pos)
|
|
||||||
local name = node.name
|
|
||||||
local above = minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z})
|
|
||||||
if minetest.get_item_group(name, "cultivatable") == 2 then
|
|
||||||
if above.name == "air" then
|
|
||||||
node.name = "mcl_farming:soil"
|
|
||||||
minetest.set_node(pos, node)
|
|
||||||
minetest.sound_play("default_dig_crumbly", { pos = pos, gain = 0.5 }, true)
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
elseif minetest.get_item_group(name, "cultivatable") == 1 then
|
|
||||||
if above.name == "air" then
|
|
||||||
node.name = "mcl_core:dirt"
|
|
||||||
minetest.set_node(pos, node)
|
|
||||||
minetest.sound_play("default_dig_crumbly", { pos = pos, gain = 0.6 }, true)
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
definition.tool_capabilities={
|
|
||||||
full_punch_interval=0.5
|
|
||||||
}
|
|
||||||
definition.groups={
|
|
||||||
tool=1
|
|
||||||
}
|
|
||||||
definition.on_place=function(itemstack,user,pointed)
|
|
||||||
local node=minetest.get_node(pointed.under)
|
|
||||||
if user and not user:get_player_control().sneak then
|
|
||||||
if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].on_rightclick then
|
|
||||||
return minetest.registered_nodes[node.name].on_rightclick(pointed.under,node,user,itemstack) or itemstack
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if minetest.is_protected(pointed.under, user:get_player_name()) then
|
|
||||||
minetest.record_protection_violation(pointed.under,user:get_player_name())
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
local meta=itemstack:get_meta()
|
|
||||||
if meta:get_int("industrialtest.powerAmount")>=20 and createSoil(pointed.under) then
|
|
||||||
industrialtest.api.addPowerToItem(itemstack,-20)
|
|
||||||
return itemstack
|
|
||||||
end
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
definition.after_use=function(itemstack)
|
|
||||||
-- Hack to make sure that chainsaw won't be destroyed when has 0 EU in MCL
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
definition._mcl_toollike_wield=true
|
|
||||||
definition._mcl_diggroups={
|
|
||||||
hoey={
|
|
||||||
speed=config.inactiveDigSpeed,
|
|
||||||
level=config.digLevel,
|
|
||||||
uses=-1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
minetest.register_tool("industrialtest:"..config.name,definition)
|
if minetest.is_protected(pointed.under, user:get_player_name()) then
|
||||||
if industrialtest.mclAvailable then
|
minetest.record_protection_violation(pointed.under,user:get_player_name())
|
||||||
definition=table.copy(definition)
|
return false
|
||||||
definition._mcl_diggroups.hoey.speed=config.activeDigSpeed
|
|
||||||
definition.groups.not_in_creative_inventory=1
|
|
||||||
definition.after_use=function(itemstack)
|
|
||||||
return electricHoe.afterUse(itemstack,config)
|
|
||||||
end
|
|
||||||
minetest.register_tool("industrialtest:"..config.name.."_active",definition)
|
|
||||||
industrialtest.internal.registeredElectricHoes["industrialtest:"..config.name.."_active"]=true
|
|
||||||
end
|
end
|
||||||
industrialtest.internal.registeredElectricHoes["industrialtest:"..config.name]=true
|
|
||||||
|
-- Taken and adapted from https://git.minetest.land/MineClone2/MineClone2/src/branch/master/mods/ITEMS/mcl_farming/hoes.lua#L3
|
||||||
|
local name = node.name
|
||||||
|
local above = minetest.get_node({x=pointed.under.x, y=pointed.under.y+1, z=pointed.under.z})
|
||||||
|
if minetest.get_item_group(name, "cultivatable") == 2 then
|
||||||
|
if above.name == "air" then
|
||||||
|
node.name = "mcl_farming:soil"
|
||||||
|
minetest.set_node(pointed.under, node)
|
||||||
|
minetest.sound_play("default_dig_crumbly", { pos = pointed.under, gain = 0.5 }, true)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
elseif minetest.get_item_group(name, "cultivatable") == 1 then
|
||||||
|
if above.name == "air" then
|
||||||
|
node.name = "mcl_core:dirt"
|
||||||
|
minetest.set_node(pointed.under, node)
|
||||||
|
minetest.sound_play("default_dig_crumbly", { pos = pointed.under, gain = 0.6 }, true)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
local definition={
|
|
||||||
name="electric_hoe",
|
function industrialtest.ElectricHoeBase.getOpPower(self,itemstack)
|
||||||
displayName=S("Electric Hoe")
|
return 50
|
||||||
}
|
|
||||||
if industrialtest.mclAvailable then
|
|
||||||
definition.inactiveDigSpeed=1
|
|
||||||
definition.digLevel=2
|
|
||||||
definition.activeDigSpeed=7
|
|
||||||
end
|
end
|
||||||
registerElectricHoe(definition)
|
|
||||||
|
industrialtest.ElectricHoe=table.copy(industrialtest.ElectricHoeBase)
|
||||||
|
industrialtest.internal.unpackTableInto(industrialtest.ElectricHoe,{
|
||||||
|
name="industrialtest:electric_hoe",
|
||||||
|
description=S("Electric Hoe"),
|
||||||
|
inventoryImage="industrialtest_electric_hoe.png",
|
||||||
|
digLevel=0,
|
||||||
|
digSpeedClass=4,
|
||||||
|
active={
|
||||||
|
digSpeed=3
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
industrialtest.ElectricHoe:register()
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
type="shaped",
|
type="shaped",
|
||||||
output="industrialtest:electric_hoe",
|
output="industrialtest:electric_hoe",
|
||||||
@ -211,17 +164,25 @@ minetest.register_craft({
|
|||||||
{"industrialtest:re_battery",""}
|
{"industrialtest:re_battery",""}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
if industrialtest.mclAvailable then
|
if industrialtest.mclAvailable then
|
||||||
registerElectricHoe({
|
industrialtest.AdvancedElectricHoe=table.copy(industrialtest.ElectricHoeBase)
|
||||||
name="diamond_electric_hoe",
|
industrialtest.internal.unpackTableInto(industrialtest.AdvancedElectricHoe,{
|
||||||
displayName=S("Diamond Electric Hoe"),
|
name="industrialtest:advanced_electric_hoe",
|
||||||
inactiveDigSpeed=1,
|
description=S("Advanced Electric Hoe"),
|
||||||
digLevel=5,
|
inventoryImage="industrialtest_advanced_electric_hoe.png",
|
||||||
activeDigSpeed=9
|
digLevel=0,
|
||||||
|
digSpeedClass=5,
|
||||||
|
active={
|
||||||
|
digSpeed=7
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
industrialtest.AdvancedElectricHoe:register()
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
type="shapeless",
|
type="shapeless",
|
||||||
output="industrialtest:diamond_electric_hoe",
|
output="industrialtest:advanced_electric_hoe",
|
||||||
recipe={
|
recipe={
|
||||||
"industrialtest:electric_hoe",
|
"industrialtest:electric_hoe",
|
||||||
industrialtest.elementKeys.diamond,
|
industrialtest.elementKeys.diamond,
|
||||||
|
@ -43,6 +43,21 @@ function industrialtest.ElectricTool.onPlace(self,itemstack,user,pointed)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function industrialtest.ElectricTool.onUse(self,itemstack,user,pointed)
|
||||||
|
self:prepare(itemstack)
|
||||||
|
|
||||||
|
local meta=itemstack:get_meta()
|
||||||
|
local opPower=self:getOpPower(itemstack)
|
||||||
|
if meta:get_int("industrialtest.powerAmount")<opPower then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
if self:hitUse(itemstack,user,pointed) then
|
||||||
|
industrialtest.api.addPowerToItem(itemstack,-opPower)
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
function industrialtest.ElectricTool.getOpPower(self,itemstack)
|
function industrialtest.ElectricTool.getOpPower(self,itemstack)
|
||||||
-- dummy function
|
-- dummy function
|
||||||
return 0
|
return 0
|
||||||
|
@ -21,6 +21,11 @@ function industrialtest.Tool.use(self,itemstack,user,pointed)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function industrialtest.Tool.hitUse(self,itemstack,user,pointed)
|
||||||
|
-- dummy function
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
function industrialtest.Tool.onPlace(self,itemstack,user,pointed)
|
function industrialtest.Tool.onPlace(self,itemstack,user,pointed)
|
||||||
if self:use(itemstack,user,pointed) then
|
if self:use(itemstack,user,pointed) then
|
||||||
local meta=itemstack:get_meta()
|
local meta=itemstack:get_meta()
|
||||||
@ -60,6 +65,12 @@ function industrialtest.Tool.createDefinitionTable(self)
|
|||||||
end
|
end
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
def.on_use=function(itemstack,user,pointed)
|
||||||
|
if self:onUse(itemstack,user,pointed) then
|
||||||
|
return itemstack
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
if industrialtest.mclAvailable then
|
if industrialtest.mclAvailable then
|
||||||
def.groups={
|
def.groups={
|
||||||
|
Loading…
x
Reference in New Issue
Block a user