Compare commits

...

2 Commits

7 changed files with 183 additions and 138 deletions

View File

@ -164,20 +164,6 @@ function industrialtest.api.updateItemPowerText(itemstack)
itemstack:set_wear(65535-meta:get_int("industrialtest.powerAmount")/meta:get_int("industrialtest.powerCapacity")*65534)
end
-- \brief Adds power storage to item depending on it's definition
-- \param itemstack ItemStack to which item storage should be added
-- \returns true if power storage was successfully added, false otherwise
function industrialtest.api.preparePowerStorageItem(itemstack)
local meta=itemstack:get_meta()
local def=minetest.registered_tools[itemstack:get_name()]
if industrialtest.api.hasPowerStorage(meta) or not def or not def._industrialtest_powerStorage or not def._industrialtest_powerCapacity or not def._industrialtest_powerFlow then
return false
end
industrialtest.api.addPowerStorage(meta,def._industrialtest_powerCapacity,def._industrialtest_powerFlow,"n/a")
industrialtest.api.updateItemPowerText(itemstack)
return true
end
-- \brief Adds power to itemstack. Function checks if itemstack has power storage.
-- \param itemstack ItemStack to which add power
-- \param amount How much power to add

View File

@ -1,60 +0,0 @@
-- IndustrialTest
-- Copyright (C) 2024 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/>.
-- \brief Sets uses metadata value depending on item's definition
-- \param itemstack ItemStack which should be altered
-- \returns true if value was successfully added, false otherwise
function industrialtest.api.prepareToolItem(itemstack)
local def=minetest.registered_tools[itemstack:get_name()]
if not def then
return false
end
if def._industrialtest_tool and def.tool_capabilities and def.tool_capabilities.uses then
local meta=itemstack:get_meta()
meta:set_int("industrialtest.uses",def.tool_capabilities.uses)
return true
elseif def.groups and def.groups._industrialtest_emptyOnConstruct and itemstack:get_wear()==0 then
itemstack:set_wear(65534)
return true
end
return false
end
-- \brief Adds wear to item after it's use
-- \param itemstack ItemStack to which wear should be added
-- \returns nil
function industrialtest.api.afterToolUse(itemstack)
local meta=itemstack:get_meta()
local def=minetest.registered_tools[itemstack:get_name()]
if not def or not def._industrialtest_tool or not def.tool_capabilities or not def.tool_capabilities.uses then
return
end
if not meta:contains("industrialtest.uses") then
industrialtest.prepareToolItem(itemstack)
end
local uses=meta:get_int("industrialtest.uses")-1
if uses==0 then
itemstack:set_count(0)
minetest.sound_play({name="default_tool_breaks"},{
gain=1,
fade=0,
pitch=1
},true)
return
end
meta:set_int("industrialtest.uses",uses)
itemstack:set_wear(65535-uses/def.tool_capabilities.uses*65535)
end

View File

@ -891,18 +891,3 @@ minetest.register_craft({
{"industrialtest:tin_plate","industrialtest:tin_plate","industrialtest:tin_plate"}
}
})
-- Item callbacks
minetest.register_on_player_inventory_action(function(player,action,inventory,info)
if action=="put" then
if industrialtest.api.preparePowerStorageItem(info.stack) or industrialtest.api.prepareToolItem(info.stack) or industrialtest.api.prepareFluidStorageItem(info.stack) then
inventory:set_stack(info.listname,info.index,info.stack)
end
end
end)
minetest.register_on_craft(function(itemstack)
if industrialtest.api.preparePowerStorageItem(itemstack) or industrialtest.api.prepareToolItem(itemstack) then
return
end
industrialtest.api.prepareFluidStorageItem(itemstack)
end)

View File

@ -36,7 +36,6 @@ dofile(modpath.."/api/network.lua")
dofile(modpath.."/api/power.lua")
dofile(modpath.."/api/registration.lua")
dofile(modpath.."/api/side.lua")
dofile(modpath.."/api/tool.lua")
dofile(modpath.."/machines/machine.lua")
dofile(modpath.."/machines/activated_machine.lua")
@ -65,6 +64,8 @@ dofile(modpath.."/machines/solar_panel_generator.lua")
dofile(modpath.."/machines/wind_mill.lua")
dofile(modpath.."/tools/common.lua")
dofile(modpath.."/tools/tool.lua")
dofile(modpath.."/tools/electric_tool.lua")
dofile(modpath.."/tools/batpack.lua")
dofile(modpath.."/tools/electric_chainsaw.lua")
dofile(modpath.."/tools/electric_drill.lua")

45
tools/electric_tool.lua Normal file
View File

@ -0,0 +1,45 @@
-- 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/>.
industrialtest.ElectricTool=table.copy(industrialtest.Tool)
function industrialtest.ElectricTool.onPlace(self,itemstack,user,pointed)
self:prepareTool(itemstack)
local meta=itemstack:get_meta()
local opPower=self:getOpPower()
if meta:get_int("industrialtest.powerAmount")<opPower then
return false
end
self:use(itemstack,user,pointed)
industrialtest.api.addPowerToItem(itemstack,-opPower)
return true
end
function industrialtest.ElectricTool.prepareTool(self,itemstack)
local meta=itemstack:get_meta()
if industrialtest.api.hasPowerStorage(meta) then
return
end
industrialtest.api.addPowerStorage(meta,self.capacity,self.flow,"n/a")
industrialtest.api.updateItemPowerText(itemstack)
end
function industrialtest.ElectricTool.getOpPower(self,itemstack)
-- dummy function
return 0
end

104
tools/tool.lua Normal file
View File

@ -0,0 +1,104 @@
-- 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/>.
industrialtest.Tool={}
function industrialtest.Tool.use(self,itemstack,user,pointed)
-- dummy function
return false
end
function industrialtest.Tool.onPlace(self,itemstack,user,pointed)
if self:use(itemstack,user,pointed) then
local meta=itemstack:get_meta()
if not meta:contains("industrialtest.uses") then
self:prepareTool(itemstack)
end
local uses=meta:get_int("industrialtest.uses")-1
if uses==0 then
itemstack:set_count(0)
minetest.sound_play({name="default_tool_breaks"},{
gain=1,
fade=0,
pitch=1
},true)
return true
end
meta:set_int("industrialtest.uses",uses)
itemstack:set_wear(65535-uses/self.uses*65535)
return true
end
return false
end
function industrialtest.Tool.prepareTool(self,itemstack)
local meta=itemstack:get_meta()
meta:set_int("industrialtest.uses",self.uses)
end
function industrialtest.Tool.createDefinitionTable(self)
local def={
description=self.description,
inventory_image=self.inventoryImage,
tool_capabilities={
full_punch_interval=1,
uses=self.uses
},
on_place=function(itemstack,user,pointed)
if self:onPlace(itemstack,user,pointed) then
return itemstack
end
return nil
end,
_industrialtest_self=self
}
if industrialtest.mtgAvailable then
def.groups={
flammable=self.flammable
}
elseif industrialtest.mclAvailable then
def.groups={
tool=1
}
def._repair_material=self.repairMaterial
def._mcl_toollike_wield=true
end
return def
end
function industrialtest.Tool.register(self)
local def=self:createDefinitionTable()
minetest.register_tool(self.name,def)
end
-- Item callbacks
minetest.register_on_player_inventory_action(function(player,action,inventory,info)
if action=="put" then
local def=info.stack:get_definition()
if def and def._industrialtest_self then
def._industrialtest_self:prepareTool(info.stack)
inventory:set_stack(info.listname,info.index,info.stack)
end
end
end)
minetest.register_on_craft(function(itemstack)
local def=itemstack:get_definition()
if def and def._industrialtest_self then
def._industrialtest_self:prepareTool(itemstack)
end
end)

View File

@ -18,8 +18,6 @@ if industrialtest.mods.mclRubber then
return
end
local S=minetest.get_translator("industrialtest")
local function onTreetapUse(user,pointed)
local node=minetest.get_node_or_nil(pointed.under)
if not node then
@ -36,34 +34,23 @@ local function onTreetapUse(user,pointed)
return false
end
local definition={
local S=minetest.get_translator("industrialtest")
industrialtest.Treetap=table.copy(industrialtest.Tool)
industrialtest.internal.unpackTableInto(industrialtest.Treetap,{
name="industrialtest:treetap",
description=S("Treetap"),
inventory_image="industrialtest_treetap.png",
tool_capabilities={
full_punch_interval=1,
uses=50
},
on_place=function(itemstack,user,pointed)
if pointed.type=="node" and user and user:is_player() and onTreetapUse(user,pointed) then
industrialtest.api.afterToolUse(itemstack)
return itemstack
end
return nil
end,
_industrialtest_tool=true
}
if industrialtest.mtgAvailable then
definition.groups={
flammable=2
}
elseif industrialtest.mclAvailable then
definition.groups={
tool=1
}
definition._repair_material="group:wood"
definition._mcl_toollike_wield=true
inventoryImage="industrialtest_treetap.png",
uses=50,
flammable=2,
repairMaterial="group:wood"
})
function industrialtest.Treetap.use(self,itemstack,user,pointed)
return pointed.type=="node" and user and user:is_player() and onTreetapUse(user,pointed)
end
minetest.register_tool("industrialtest:treetap",definition)
industrialtest.Treetap:register()
minetest.register_craft({
type="shaped",
output="industrialtest:treetap",
@ -74,28 +61,25 @@ minetest.register_craft({
}
})
definition={
industrialtest.ElectricTreetap=table.copy(industrialtest.ElectricTool)
industrialtest.internal.unpackTableInto(industrialtest.ElectricTreetap,{
name="industrialtest:electric_treetap",
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=10000,
_industrialtest_powerFlow=industrialtest.api.lvPowerFlow
}
if industrialtest.mclAvailable then
definition.groups={
tool=1
}
definition._mcl_toollike_wield=true
inventoryImage="industrialtest_electric_treetap.png",
capacity=10000,
flow=industrialtest.api.lvPowerFlow
})
function industrialtest.ElectricTreetap.use(self,itemstack,user,pointed)
return user and user:is_player() and onTreetapUse(user,pointed)
end
minetest.register_tool("industrialtest:electric_treetap",definition)
function industrialtest.ElectricTreetap.getOpPower(self,itemstack)
return 50
end
industrialtest.ElectricTreetap:register()
minetest.register_craft({
type="shapeless",
output="industrialtest:electric_treetap",