diff --git a/machines/machine.lua b/machines/machine.lua index 1125db0..410dfe4 100644 --- a/machines/machine.lua +++ b/machines/machine.lua @@ -128,27 +128,37 @@ function industrialtest.Machine.onMetadataInventoryMove(self,pos,fromList,fromIn if toList=="upgrades" then local meta=minetest.get_meta(pos) local inv=meta:get_inventory() - local stack=inv:get_stack(fromList,fromIndex) - industrialtest.internal.applyUpgrade(pos,meta,stack) + local itemstack=inv:get_stack(fromList,fromIndex) + local def=itemstack:get_definition() + if def and def._industrialtest_self and def._industrialtest_self.apply then + def._industrialtest_self:apply(pos) + end elseif fromList=="upgrades" then local meta=minetest.get_meta(pos) local inv=meta:get_inventory() - local stack=inv:get_stack(fromList,fromIndex) - industrialtest.internal.removeUpgrade(pos,meta,stack) + local itemstack=inv:get_stack(fromList,fromIndex) + local def=itemstack:get_definition() + if def and def._industrialtest_self and def._industrialtest_self.remove then + def._industrialtest_self:remove(pos) + end end end function industrialtest.Machine.onMetadataInventoryPut(self,pos,listname,index,stack) if listname=="upgrades" then - local meta=minetest.get_meta(pos) - industrialtest.internal.applyUpgrade(pos,meta,stack) + local def=stack:get_definition() + if def and def._industrialtest_self and def._industrialtest_self.apply then + def._industrialtest_self:apply(pos) + end end end function industrialtest.Machine.onMetadataInventoryTake(self,pos,listname,index,stack) if listname=="upgrades" then - local meta=minetest.get_meta(pos) - industrialtest.internal.removeUpgrade(pos,meta,stack) + local def=stack:get_definition() + if def and def._industrialtest_self and def._industrialtest_self.remove then + def._industrialtest_self:remove(pos) + end end end @@ -289,8 +299,8 @@ function industrialtest.Machine.register(self) industrialtest.api.addTag(self.name,"usesTimer") end -function industrialtest.Machine.allowMoveToUpgradeSlot(pos,toIndex,stack) - local def=minetest.registered_items[stack:get_name()] +function industrialtest.Machine.allowMoveToUpgradeSlot(pos,toIndex,itemstack) + local def=itemstack:get_definition() if not def or not def.groups or not def.groups._industrialtest_machineUpgrade then return 0 end @@ -300,5 +310,5 @@ function industrialtest.Machine.allowMoveToUpgradeSlot(pos,toIndex,stack) if not targetSlot:is_empty() then return 0 end - return stack:get_count() + return itemstack:get_count() end diff --git a/machines/simple_electric_item_processor.lua b/machines/simple_electric_item_processor.lua index f157418..4c13bbb 100644 --- a/machines/simple_electric_item_processor.lua +++ b/machines/simple_electric_item_processor.lua @@ -107,8 +107,8 @@ function industrialtest.SimpleElectricItemProcessor.onMetadataInventoryMove(self end end -function industrialtest.SimpleElectricItemProcessor.onMetadataInventoryPut(self,pos) - industrialtest.ActivatedElectricMachine.onMetadataInventoryPut(self,pos) +function industrialtest.SimpleElectricItemProcessor.onMetadataInventoryPut(self,pos,listname,index,stack) + industrialtest.ActivatedElectricMachine.onMetadataInventoryPut(self,pos,listname,index,stack) self:triggerIfNeeded(pos) end diff --git a/upgrades.lua b/upgrades.lua index ad82072..5ddf404 100644 --- a/upgrades.lua +++ b/upgrades.lua @@ -16,106 +16,56 @@ local S=minetest.get_translator("industrialtest") -industrialtest.internal.applyUpgrade=function(pos,meta,stack) - local def=minetest.registered_items[stack:get_name()] - if def.groups._industrialtest_upgradeSpeed then - local speed=industrialtest.api.getMachineSpeed(meta) - meta:set_int("industrialtest.speed",math.min(4,speed+def.groups._industrialtest_upgradeSpeed)) - elseif def.groups._industrialtest_upgradeTransformer then - local flows={ - industrialtest.api.lvPowerFlow, - industrialtest.api.mvPowerFlow, - industrialtest.api.hvPowerFlow, - industrialtest.api.evPowerFlow, - industrialtest.api.ivPowerFlow - } - local machineFlow=meta:get_int("industrialtest.powerFlow") - local upgradedFlow=machineFlow - for _,flow in ipairs(flows) do - if flow>machineFlow then - upgradedFlow=flow - break - end - end - meta:set_int("industrialtest.powerFlow",upgradedFlow) - local networks=industrialtest.api.isAttachedToNetwork(meta) - if networks then - for _,network in ipairs(networks) do - industrialtest.api.createNetworkMapForNode(network) - end - end - elseif def.groups._industrialtest_upgradePowerStorage then - meta:set_int("industrialtest.powerCapacity",meta:get_int("industrialtest.powerCapacity")+10000) - local nodeDef=minetest.registered_nodes[minetest.get_node(pos).name] - if nodeDef._industrialtest_updateFormspec then - nodeDef._industrialtest_updateFormspec(pos) - end - local networks=industrialtest.api.isAttachedToNetwork(meta) - if networks then - for _,network in ipairs(networks) do - minetest.get_node_timer(network):start(industrialtest.updateDelay) - end - end - end -end +industrialtest.Upgrade={} -industrialtest.internal.removeUpgrade=function(pos,meta,stack) - local def=minetest.registered_items[stack:get_name()] - if def.groups._industrialtest_upgradeSpeed and meta:contains("industrialtest.speed") then - local speed=meta:get_int("industrialtest.speed") - meta:set_int("industrialtest.speed",math.max(1,speed-def.groups._industrialtest_upgradeSpeed)) - elseif def.groups._industrialtest_upgradeTransformer then - local flows={ - industrialtest.api.lvPowerFlow, - industrialtest.api.mvPowerFlow, - industrialtest.api.hvPowerFlow, - industrialtest.api.evPowerFlow, - industrialtest.api.ivPowerFlow - } - local machineFlow=meta:get_int("industrialtest.powerFlow") - local downgradedFlow=machineFlow - for i=#flows,1,-1 do - local flow=flows[i] - if flowmachineFlow then + upgradedFlow=flow + break + end + end + meta:set_int("industrialtest.powerFlow",upgradedFlow) + local networks=industrialtest.api.isAttachedToNetwork(meta) + if networks then + for _,network in ipairs(networks) do + industrialtest.api.createNetworkMapForNode(network) + end + end +end + +function industrialtest.TransformerUpgrade.remove(self,pos) + local meta=minetest.get_meta(pos) + local flows={ + industrialtest.api.lvPowerFlow, + industrialtest.api.mvPowerFlow, + industrialtest.api.hvPowerFlow, + industrialtest.api.evPowerFlow, + industrialtest.api.ivPowerFlow + } + local machineFlow=meta:get_int("industrialtest.powerFlow") + local downgradedFlow=machineFlow + for i=#flows,1,-1 do + local flow=flows[i] + if flow