Refactor electric sabers

This commit is contained in:
2025-04-15 22:47:44 +02:00
parent 6f864eca78
commit b383231c40
5 changed files with 141 additions and 170 deletions

View File

@@ -24,22 +24,32 @@ function industrialtest.ActivatedElectricTool.createDefinitionTable(self)
if self.digs then
self:defineToolCapabilities(def,nil,self.digSpeed)
end
if self.hits then
def.tool_capabilities.damage_groups={}
for _,hitType in ipairs(self.hits) do
def.tool_capabilities.damage_groups[hitType]=1
end
end
return def
end
function industrialtest.ActivatedElectricTool.createActiveDefinitionTable(self)
local def=self:createDefinitionTable()
if self.digs then
if self.digs or self.hits then
self:defineToolCapabilities(def,self.active.times,self.active.digSpeed)
end
def.groups.not_in_creative_inventory=1
def.after_use=function(itemstack,user,node,digparams)
if self:afterUse(itemstack,user,node,digparams) then
return itemstack
end
return nil
end
return def
end
@@ -55,9 +65,11 @@ function industrialtest.ActivatedElectricTool.beforeUse(self,itemstack,node)
if not self.isActive(itemstack) then
itemstack:set_name(itemstack:get_name().."_active")
end
return true
else
itemstack:set_name(self.name)
end
return false
end
function industrialtest.ActivatedElectricTool.afterUse(self,itemstack,user,node,digparams)
@@ -95,21 +107,41 @@ function industrialtest.ActivatedElectricTool.defineToolCapabilities(self,def,ti
end
end
end
if self.hits then
for _,hitType in ipairs(self.hits) do
if hitType=="fleshy" then
def.groups.sword=1
end
end
end
elseif industrialtest.mclAvailable then
local digTypeMapping={
choppy="axey",
cracky="pickaxey",
crumbly="shovely",
hoey="hoey"
}
def.groups.dig_speed_class=self.digSpeedClass
def._mcl_diggroups={}
for _,digType in ipairs(self.digs) do
def._mcl_diggroups[digTypeMapping[digType]]={
speed=digSpeed,
level=5-self.digLevel,
uses=-1
if self.digs then
local digTypeMapping={
choppy={"axey"},
cracky={"pickaxey"},
crumbly={"shovely"},
hoey={"hoey"},
snappy={"swordy","swordy_cobweb"}
}
def.groups.dig_speed_class=self.digSpeedClass
def._mcl_diggroups={}
for _,digType in ipairs(self.digs) do
for _,mappedDigType in ipairs(digTypeMapping[digType]) do
def._mcl_diggroups[mappedDigType]={
speed=digSpeed,
level=5-self.digLevel,
uses=-1
}
end
end
end
if self.hits then
for _,hitType in ipairs(self.hits) do
if hitType=="fleshy" then
def.groups.weapon=1
def.groups.sword=1
end
end
end
end
end
@@ -121,8 +153,8 @@ minetest.register_on_punchnode(function(pos,node,user)
local itemstack=user:get_wielded_item()
local def=itemstack:get_definition()
if def and def._industrialtest_self and def.groups and def.groups._industrialtest_activatedElectricTool then
def._industrialtest_self:beforeUse(itemstack,node)
if def and def._industrialtest_self and def.groups and def.groups._industrialtest_activatedElectricTool and
def._industrialtest_self:beforeUse(itemstack,node) then
user:set_wielded_item(itemstack)
end
end)