Implement Electric Treetap
This commit is contained in:
parent
da3d99164b
commit
72f9c22903
59
tools.lua
59
tools.lua
|
@ -16,6 +16,21 @@
|
||||||
|
|
||||||
local S=minetest.get_translator("industrialtest")
|
local S=minetest.get_translator("industrialtest")
|
||||||
|
|
||||||
|
local function onTreetapUse(user,pointed)
|
||||||
|
local node=minetest.get_node_or_nil(pointed.under)
|
||||||
|
if not node then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
-- Note: if more nodes from which treetap can extract will be added then they shouldn't be added here
|
||||||
|
-- Instead they should have additional entry in definition which will denote that treetap can be used on them
|
||||||
|
if node.name=="industrialtest:rubber_wood_with_rubber" then
|
||||||
|
local inv=user:get_inventory()
|
||||||
|
inv:add_item("main",ItemStack("industrialtest:sticky_resin"))
|
||||||
|
minetest.set_node(pointed.under,{name="industrialtest:rubber_wood"})
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
local definition={
|
local definition={
|
||||||
description=S("Treetap"),
|
description=S("Treetap"),
|
||||||
inventory_image="industrialtest_treetap.png",
|
inventory_image="industrialtest_treetap.png",
|
||||||
|
@ -24,21 +39,10 @@ local definition={
|
||||||
uses=50
|
uses=50
|
||||||
},
|
},
|
||||||
on_place=function(itemstack,user,pointed)
|
on_place=function(itemstack,user,pointed)
|
||||||
if pointed.type=="node" and user and user:is_player() then
|
if pointed.type=="node" and user and user:is_player() and onTreetapUse(user,pointed) then
|
||||||
local node=minetest.get_node_or_nil(pointed.under)
|
|
||||||
if not node then
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
-- Note: if more nodes from which treetap can extract will be added then they shouldn't be added here
|
|
||||||
-- Instead they should have additional entry in definition which will denote that treetap can be used on them
|
|
||||||
if node.name=="industrialtest:rubber_wood_with_rubber" then
|
|
||||||
local inv=user:get_inventory()
|
|
||||||
inv:add_item("main",ItemStack("industrialtest:sticky_resin"))
|
|
||||||
minetest.set_node(pointed.under,{name="industrialtest:rubber_wood"})
|
|
||||||
industrialtest.api.afterToolUse(itemstack)
|
industrialtest.api.afterToolUse(itemstack)
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
end
|
|
||||||
return nil
|
return nil
|
||||||
end,
|
end,
|
||||||
_industrialtest_tool=true
|
_industrialtest_tool=true
|
||||||
|
@ -64,3 +68,34 @@ minetest.register_craft({
|
||||||
{"group:wood","",""}
|
{"group:wood","",""}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
definition={
|
||||||
|
description=S("Electric Treetap"),
|
||||||
|
inventory_image="industrialtest_electric_treetap.png",
|
||||||
|
on_place=function(itemstack,user,pointed)
|
||||||
|
local meta=itemstack:get_meta()
|
||||||
|
if meta:get_int("industrialtest.powerAmount")>=50 and user and user:is_player() and onTreetapUse(user,pointed) then
|
||||||
|
industrialtest.api.addPowerToItem(itemstack,-50)
|
||||||
|
return itemstack
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end,
|
||||||
|
_industrialtest_powerStorage=true,
|
||||||
|
_industrialtest_powerCapacity=7000,
|
||||||
|
_industrialtest_powerFlow=industrialtest.api.lvPowerFlow
|
||||||
|
}
|
||||||
|
if industrialtest.mclAvailable then
|
||||||
|
definition.groups={
|
||||||
|
tool=1
|
||||||
|
}
|
||||||
|
definition._mcl_toollike_wield=true
|
||||||
|
end
|
||||||
|
minetest.register_tool("industrialtest:electric_treetap",definition)
|
||||||
|
minetest.register_craft({
|
||||||
|
type="shapeless",
|
||||||
|
output="industrialtest:electric_treetap",
|
||||||
|
recipe={
|
||||||
|
"industrialtest:treetap",
|
||||||
|
"industrialtest:electronic_circuit",
|
||||||
|
"industrialtest:re_battery"
|
||||||
|
}
|
||||||
|
})
|
Loading…
Reference in New Issue