Refactor batpacks

This commit is contained in:
2025-04-08 21:28:28 +02:00
parent 6147074e05
commit dfdce73376
8 changed files with 236 additions and 147 deletions

View File

@@ -14,7 +14,7 @@
-- 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={}
industrialtest.Tool=table.copy(industrialtest.Item)
function industrialtest.Tool.use(self,itemstack,user,pointed)
-- dummy function
@@ -25,7 +25,7 @@ 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)
self:prepare(itemstack)
end
local uses=meta:get_int("industrialtest.uses")-1
if uses==0 then
@@ -44,33 +44,25 @@ function industrialtest.Tool.onPlace(self,itemstack,user,pointed)
return false
end
function industrialtest.Tool.prepareTool(self,itemstack)
function industrialtest.Tool.prepare(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
local def=industrialtest.Item.createDefinitionTable(self)
def.tool_capabilities={
full_punch_interval=1,
uses=self.uses
}
def.on_place=function(itemstack,user,pointed)
if self:onPlace(itemstack,user,pointed) then
return itemstack
end
return nil
end
if industrialtest.mtgAvailable then
def.groups={
flammable=self.flammable
}
elseif industrialtest.mclAvailable then
if industrialtest.mclAvailable then
def.groups={
tool=1
}
@@ -80,25 +72,3 @@ function industrialtest.Tool.createDefinitionTable(self)
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)