diff --git a/init.lua b/init.lua index 30539f6..814ba51 100644 --- a/init.lua +++ b/init.lua @@ -39,6 +39,10 @@ dofile(modpath.."/api/side.lua") dofile(modpath.."/api/tool.lua") dofile(modpath.."/machines/common.lua") +dofile(modpath.."/machines/machine.lua") +dofile(modpath.."/machines/activated_machine.lua") +dofile(modpath.."/machines/electric_machine.lua") +dofile(modpath.."/machines/activated_electric_machine.lua") dofile(modpath.."/machines/canning_machine.lua") dofile(modpath.."/machines/chargepad.lua") dofile(modpath.."/machines/compressor.lua") diff --git a/machines/activated_electric_machine.lua b/machines/activated_electric_machine.lua new file mode 100644 index 0000000..6e5bfa2 --- /dev/null +++ b/machines/activated_electric_machine.lua @@ -0,0 +1,40 @@ +-- 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 . + +industrialtest.ActivatedElectricMachine=table.copy(industrialtest.ElectricMachine) + +function industrialtest.ActivatedElectricMachine.onTimer(self,pos,elapsed) + industrialtest.ElectricMachine.requestPower(self,pos) + return industrialtest.ActivatedMachine.onTimer(self,pos,elapsed) +end + +industrialtest.ActivatedElectricMachine.register=industrialtest.ActivatedMachine.register + +industrialtest.ActivatedElectricMachine.createDefinitionTable=industrialtest.ActivatedMachine.createDefinitionTable + +industrialtest.ActivatedElectricMachine.shouldActivate=industrialtest.ActivatedMachine.shouldActivate + +industrialtest.ActivatedElectricMachine.shouldDeactivate=industrialtest.ActivatedMachine.shouldDeactivate + +industrialtest.ActivatedElectricMachine.beforeActivation=industrialtest.ActivatedMachine.beforeActivation + +industrialtest.ActivatedElectricMachine.beforeDeactivation=industrialtest.ActivatedMachine.beforeDeactivation + +function industrialtest.ActivatedElectricMachine.activeOnTimer(self,pos,elapsed) + industrialtest.ElectricMachine.requestPower(self,pos) + return industrialtest.ActivatedMachine.activeOnTimer(self,pos,elapsed) +end + diff --git a/machines/activated_machine.lua b/machines/activated_machine.lua new file mode 100644 index 0000000..13ae731 --- /dev/null +++ b/machines/activated_machine.lua @@ -0,0 +1,95 @@ +-- 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 . + +industrialtest.ActivatedMachine=table.copy(industrialtest.Machine) + +function industrialtest.ActivatedMachine.onTimer(self,pos,elapsed) + local result=industrialtest.Machine.onTimer(self,pos,elapsed) + + if self:shouldActivate(pos) then + self:beforeActivation(pos) + minetest.swap_node(pos,{ + name=self.name.."_active", + param2=minetest.get_node(pos).param2 + }) + minetest.get_node_timer(pos):start(industrialtest.updateDelay) + return false + end + + return result +end + +function industrialtest.ActivatedMachine.register(self) + industrialtest.Machine.register(self) + + local def=self:createActiveDefinitionTable() + minetest.register_node(self.name.."_active",def) +end + +function industrialtest.ActivatedMachine.createActiveDefinitionTable(self) + local def=self:createDefinitionTable() + def.description=nil + def.drop=def.drop or self.name + def.on_timer=function(pos,elapsed) + return self:activeOnTimer(pos,elapsed) + end + if industrialtest.mclAvailable then + def.groups.not_in_creative_inventory=1 + def._doc_items_create_entry=false + end + return def +end + +function industrialtest.ActivatedMachine.shouldActivate(self,pos) + return false +end + +function industrialtest.ActivatedMachine.shouldDeactivate(self,pos) + return false +end + +function industrialtest.ActivatedMachine.beforeActivation(self,pos) +end + +function industrialtest.ActivatedMachine.beforeDeactivation(self,pos) +end + +function industrialtest.ActivatedMachine.activeOnTimer(self,pos,elapsed) + local meta=minetest.get_meta(pos) + local inv=meta:get_inventory() + local shouldRerunTimer=false + local shouldUpdateFormspec=false + + if self.activeUpdate then + shouldRerunTimer,shouldUpdateFormspec=self:activeUpdate(pos,elapsed,meta,inv) + end + + if shouldUpdateFormspec then + self:updateFormspec(pos) + end + + if self:shouldDeactivate(pos) then + self:beforeDeactivation(pos) + minetest.swap_node(pos,{ + name=self.name, + param2=minetest.get_node(pos).param2 + }) + minetest.get_node_timer(pos):start(industrialtest.updateDelay) + return false + end + + return shouldRerunTimer +end diff --git a/machines/common.lua b/machines/common.lua index 7464e8c..479fb55 100644 --- a/machines/common.lua +++ b/machines/common.lua @@ -33,20 +33,6 @@ industrialtest.internal.mclAfterDigNode=function(pos,oldmeta,lists) meta:from_table(meta2:to_table()) end -industrialtest.internal.allowMoveToUpgradeSlot=function(pos,toIndex,stack) - local def=minetest.registered_items[stack:get_name()] - if not def or not def.groups or not def.groups._industrialtest_machineUpgrade then - return 0 - end - local meta=minetest.get_meta(pos) - local inv=meta:get_inventory() - local targetSlot=inv:get_stack("upgrades",toIndex) - if not targetSlot:is_empty() then - return 0 - end - return stack:get_count() -end - industrialtest.internal.chargeFromPowerStorageItem=function(meta,inv) local shouldRerunTimer=false local shouldUpdateFormspec=false @@ -63,228 +49,6 @@ industrialtest.internal.chargeFromPowerStorageItem=function(meta,inv) return shouldRerunTimer,shouldUpdateFormspec end -machine.getFormspec=function(pos,config) - local formspec - if industrialtest.mtgAvailable then - formspec={ - "formspec_version[4]", - "size[10.8,12]", - "label[0.5,0.5;"..config.displayName.."]", - "list[current_player;main;0.5,6.25;8,1]", - "list[current_player;main;0.5,7.5;8,3;8]", - "listring[current_player;main]", - (config.getFormspec and config.getFormspec(pos) or "") - } - elseif industrialtest.mclAvailable then - formspec={ - "size[10.04,12]", - "label[0.25,0.25;"..config.displayName.."]", - "list[current_player;main;0.5,7;9,3;9]", - mcl_formspec.get_itemslot_bg(0.5,7,9,3), - "list[current_player;main;0.5,10.24;9,1]", - mcl_formspec.get_itemslot_bg(0.5,10.24,9,1), - "listring[current_player;main]", - (config.getFormspec and config.getFormspec(pos) or "") - } - end - return table.concat(formspec,"") -end - -machine.onConstruct=function(pos,config) - local meta=minetest.get_meta(pos) - local inv=meta:get_inventory() - - industrialtest.api.addPowerStorage(meta,config.capacity,config.flow,config.ioConfig) - - if config.groups then - if config.groups._industrialtest_hasPowerInput then - local connections=industrialtest.api.getConnections(pos) - for _,conn in ipairs(connections) do - local connectionMeta=minetest.get_meta(conn) - if industrialtest.api.isNetworkMaster(connectionMeta) then - industrialtest.api.createNetworkMapForNode(conn) - minetest.get_node_timer(conn):start(industrialtest.updateDelay) - else - local def=minetest.registered_nodes[minetest.get_node(conn).name] - if def.groups._industrialtest_cable then - local networks=industrialtest.api.isAttachedToNetwork(connectionMeta) - if networks then - for _,network in ipairs(networks) do - industrialtest.api.createNetworkMapForNode(network) - minetest.get_node_timer(network):start(industrialtest.updateDelay) - end - end - end - end - end - end - if config.groups._industrialtest_hasPowerOutput then - meta:set_string("industrialtest.network",minetest.serialize(industrialtest.api.createNetworkMap(pos))) - end - end - - if config.onConstruct then - config.onConstruct(pos,meta,inv) - end - - if not config.withoutFormspec then - meta:set_string("formspec",machine.getFormspec(pos,config)) - end - - minetest.get_node_timer(pos):start(industrialtest.updateDelay) -end - -machine.onDestruct=function(pos,config) - local meta=minetest.get_meta(pos) - if industrialtest.api.isNetworkMaster(meta) then - local network=industrialtest.api.createNetworkMap(pos,true) - for _,endpoint in ipairs(network) do - local endpointMeta=minetest.get_meta(endpoint.position) - local networks=industrialtest.api.isAttachedToNetwork(endpointMeta) - for key,value in ipairs(networks) do - if value.x==pos.x and value.y==pos.y and value.z==pos.z then - table.remove(networks,key) - break - end - end - endpointMeta:set_string("industrialtest.networks",minetest.serialize(networks)) - end - end - local networks=industrialtest.api.isAttachedToNetwork(meta) - if networks then - for _,network in ipairs(networks) do - industrialtest.api.removeNodeFromNetwork(network,pos) - end - end - if config.onDestruct then - config.onDestruct(pos) - end -end - -machine.onTimer=function(pos,elapsed,config) - local meta=minetest.get_meta(pos) - local inv=meta:get_inventory() - local shouldRerunTimer=false - local shouldUpdateFormspec=false - - if config.onTimer then - shouldRerunTimer,shouldUpdateFormspec=config.onTimer(pos,elapsed,meta,inv) - end - - local def=minetest.registered_nodes[minetest.get_node(pos).name] - if def.groups and def.groups._industrialtest_hasPowerInput and not industrialtest.api.isFullyCharged(meta) then - 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 - - if shouldUpdateFormspec then - machine.updateFormspec(pos,config) - end - - return shouldRerunTimer -end - -machine.allowMetadataInventoryMove=function(pos,fromList,fromIndex,toList,toIndex,count,config) - local meta=minetest.get_meta(pos) - local inv=meta:get_inventory() - local movedItemStack=inv:get_stack(fromList,1) - - if toList=="upgrades" then - return industrialtest.internal.allowMoveToUpgradeSlot(pos,toIndex,movedItemStack) - end - - local found=false - if config.powerSlots then - for _,value in ipairs(config.powerSlots) do - if value==toList then - found=true - break - end - end - end - if found and not industrialtest.api.hasPowerStorage(movedItemStack:get_meta()) then - return 0 - end - - if config.allowMetadataInventoryMove then - return config.allowMetadataInventoryMove(pos,fromList,fromIndex,toList,toIndex,count) - end - - return count -end - -machine.allowMetadataInventoryPut=function(pos,listname,index,stack,player,config) - if listname=="upgrades" then - return industrialtest.internal.allowMoveToUpgradeSlot(pos,index,stack) - end - - local found=false - if config.powerSlots then - for _,value in ipairs(config.powerSlots) do - if value==listname then - found=true - break - end - end - end - if found and not industrialtest.api.hasPowerStorage(stack:get_meta()) then - return 0 - end - - if config.allowMetadataInventoryPut then - return config.allowMetadataInventoryPut(pos,listname,index,stack,player) - end - - return stack:get_count() -end - -machine.allowMetadataInventoryTake=function(pos,listname,index,stack,player,config) - if config.allowMetadataInventoryTake then - return config.allowMetadataInventoryTake(pos,listname,index,stack,player) - end - return stack:get_count() -end - -machine.onMetadataInventoryMove=function(pos,fromList,fromIndex,toList,toIndex,count) - 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) - 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) - end -end - -machine.onMetadataInventoryPut=function(pos,listname,index,stack) - if listname=="upgrades" then - local meta=minetest.get_meta(pos) - industrialtest.internal.applyUpgrade(pos,meta,stack) - end -end - -machine.onMetadataInventoryTake=function(pos,listname,index,stack) - if listname=="upgrades" then - local meta=minetest.get_meta(pos) - industrialtest.internal.removeUpgrade(pos,meta,stack) - end -end - -machine.updateFormspec=function(pos,config) - if config.withoutFormspec then - return - end - local meta=minetest.get_meta(pos) - meta:set_string("formspec",machine.getFormspec(pos,config)) -end - function industrialtest.internal.registerMachine(config) local definition={ description=config.displayName, @@ -335,52 +99,6 @@ function industrialtest.internal.registerMachine(config) return machine.getFormspec(pos,config) end } - if industrialtest.mtgAvailable then - definition.groups={cracky=2} - if config.sounds=="metal" then - definition.sounds=default.node_sound_metal_defaults() - end - definition.can_dig=function(pos) - local meta=minetest.get_meta(pos) - local inv=meta:get_inventory() - for _,value in ipairs(config.storageSlots) do - if inv:get_stack(value,1):get_count()>0 then - return false - end - end - return true - end - elseif industrialtest.mclAvailable then - definition.after_dig_node=function(pos,oldnode,oldmeta) - industrialtest.internal.mclAfterDigNode(pos,oldmeta,config.storageSlots) - end - if config.sounds=="metal" then - definition.sounds=mcl_sounds.node_sound_metal_defaults() - end - definition.groups={ - pickaxey=1, - container=2 - } - definition._mcl_blast_resistance=3.5 - definition._mcl_hardness=3.9 - definition._mcl_hoppers_on_try_pull=function(pos, hop_pos, hop_inv, hop_list) - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - local stack = inv:get_stack("dst", 1) - if not stack:is_empty() and hop_inv:room_for_item(hop_list, stack) then - return inv, "dst", 1 - end - return nil, nil, nil - end - definition._mcl_hoppers_on_try_push=function(pos, hop_pos, hop_inv, hop_list) - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - return inv, "src", mcl_util.select_stack(hop_inv, hop_list, inv, "src") - end - definition._mcl_hoppers_on_after_push=function(pos) - minetest.get_node_timer(pos):start(industrialtest.updateDelay) - end - end definition.groups._industrialtest_wrenchUnmountable=1 if config.requiresWrench then definition.drop="industrialtest:machine_block" diff --git a/machines/electric_machine.lua b/machines/electric_machine.lua new file mode 100644 index 0000000..ed7856e --- /dev/null +++ b/machines/electric_machine.lua @@ -0,0 +1,129 @@ +-- 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 . + +industrialtest.ElectricMachine=table.copy(industrialtest.Machine) + +function industrialtest.ElectricMachine.onConstruct(self,pos) + local meta=minetest.get_meta(pos) + + industrialtest.api.addPowerStorage(meta,self.capacity,self.flow,self.ioConfig) + + if self.hasPowerInput then + local connections=industrialtest.api.getConnections(pos) + for _,conn in ipairs(connections) do + local connectionMeta=minetest.get_meta(conn) + if industrialtest.api.isNetworkMaster(connectionMeta) then + industrialtest.api.createNetworkMapForNode(conn) + minetest.get_node_timer(conn):start(industrialtest.updateDelay) + else + local def=minetest.registered_nodes[minetest.get_node(conn).name] + if def.groups._industrialtest_cable then + local networks=industrialtest.api.isAttachedToNetwork(connectionMeta) + if networks then + for _,network in ipairs(networks) do + industrialtest.api.createNetworkMapForNode(network) + minetest.get_node_timer(network):start(industrialtest.updateDelay) + end + end + end + end + end + if self.hasPowerOutput then + meta:set_string("industrialtest.network",minetest.serialize(industrialtest.api.createNetworkMap(pos))) + end + end + + industrialtest.Machine.onConstruct(self,pos) +end + +function industrialtest.ElectricMachine.onDestruct(self,pos) + local meta=minetest.get_meta(pos) + + if industrialtest.api.isNetworkMaster(meta) then + local network=industrialtest.api.createNetworkMap(pos,true) + for _,endpoint in ipairs(network) do + local endpointMeta=minetest.get_meta(endpoint.position) + local networks=industrialtest.api.isAttachedToNetwork(endpointMeta) + for key,value in ipairs(networks) do + if value.x==pos.x and value.y==pos.y and value.z==pos.z then + table.remove(networks,key) + break + end + end + endpointMeta:set_string("industrialtest.networks",minetest.serialize(networks)) + end + end + local networks=industrialtest.api.isAttachedToNetwork(meta) + if networks then + for _,network in ipairs(networks) do + industrialtest.api.removeNodeFromNetwork(network,pos) + end + end + + -- don't call onDestruct from parent class because it doesn't do anything +end + +function industrialtest.ElectricMachine.onTimer(self,pos,elapsed) + local result=industrialtest.Machine.onTimer(self,pos,elapsed) + self:requestPower(pos) + return result +end + +function industrialtest.Machine.allowMetadataInventoryMove(self,pos,fromList,fromIndex,toList,toIndex,count) + local found=false + if self.powerLists then + for _,value in ipairs(self.powerLists) do + if value==toList then + found=true + break + end + end + end + if found and not industrialtest.api.hasPowerStorage(movedItemStack:get_meta()) then + return 0 + end + + return industrialtest.Machine.allowMetadataInventoryMove(self,pos,fromList,fromIndex,toList,toIndex,count) +end + +function industrialtest.Machine.allowMetadataInventoryPut(self,pos,listname,index,stack,player) + local found=false + if self.powerLists then + for _,value in ipairs(self.powerLists) do + if value==listname then + found=true + break + end + end + end + if found and not industrialtest.api.hasPowerStorage(stack:get_meta()) then + return 0 + end + + return industrialtest.Machine.allowMetadataInventoryPut(self,pos,listname,index,stack,player) +end + +function industrialtest.ElectricMachine.requestPower(self,pos) + local meta=minetest.get_meta(pos) + if self.hasPowerInput and not industrialtest.api.isFullyCharged(meta) then + 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 diff --git a/machines/machine.lua b/machines/machine.lua new file mode 100644 index 0000000..00a39e8 --- /dev/null +++ b/machines/machine.lua @@ -0,0 +1,233 @@ +-- 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 . + +industrialtest.Machine={} + +function industrialtest.Machine.onConstruct(self,pos) + meta:set_string("formspec",self:getFormspec(pos)) + minetest.get_node_timer(pos):start(industrialtest.updateDelay) +end + +function industrialtest.Machine.onDestruct(self) + -- dummy function +end + +function industrialtest.Machine.getFormspec(self,pos) + local formspec + if industrialtest.mtgAvailable then + formspec={ + "formspec_version[4]", + "size[10.8,12]", + "label[0.5,0.5;"..self.description.."]", + "list[current_player;main;0.5,6.25;8,1]", + "list[current_player;main;0.5,7.5;8,3;8]", + "listring[current_player;main]" + } + elseif industrialtest.mclAvailable then + formspec={ + "size[10.04,12]", + "label[0.25,0.25;"..self.description.."]", + "list[current_player;main;0.5,7;9,3;9]", + mcl_formspec.get_itemslot_bg(0.5,7,9,3), + "list[current_player;main;0.5,10.24;9,1]", + mcl_formspec.get_itemslot_bg(0.5,10.24,9,1), + "listring[current_player;main]" + } + end + return table.concat(formspec,"") +end + +function industrialtest.Machine.updateFormspec(self,pos) + if self.withoutFormspec then + return + end + + local meta=minetest.get_meta(pos) + meta:set_string("formspec",self:getFormspec(pos)) +end + +function industrialtest.Machine.onTimer(self,pos,elapsed) + local meta=minetest.get_meta(pos) + local inv=meta:get_inventory() + local shouldRerunTimer=false + local shouldUpdateFormspec=false + + if self.update then + shouldRerunTimer,shouldUpdateFormspec=self:update(pos,elapsed,meta,inv) + end + + if shouldUpdateFormspec then + self:updateFormspec(pos) + end + + return shouldRerunTimer +end + +function industrialtest.Machine.allowMetadataInventoryMove(self,pos,fromList,fromIndex,toList,toIndex,count) + local meta=minetest.get_meta(pos) + local inv=meta:get_inventory() + local movedItemStack=inv:get_stack(fromList,1) + + if toList=="upgrades" then + return self.allowMoveToUpgradeSlot(pos,toIndex,movedItemStack) + end + + return count +end + +function industrialtest.Machine.allowMetadataInventoryPut(self,pos,listname,index,stack,player) + if listname=="upgrades" then + return self.allowMoveToUpgradeSlot(pos,index,stack) + end + + return stack:get_count() +end + +function industrialtest.Machine.createDefinitionTable(self) + local def={ + description=self.description, + on_construct=function(pos) + self:onConstruct(pos) + end, + on_destruct=function(pos) + self:onDestruct(pos) + end, + on_timer=function(pos,elapsed) + return self:onTimer(pos,elapsed) + end, + allow_metadata_inventory_move=function(pos,fromList,fromIndex,toList,toIndex,count) + return self:allowMetadataInventoryMove(pos,fromList,fromIndex,toList,toIndex,count) + end, + allow_metadata_inventory_put=function(pos,listname,index,stack,player) + return self:allowMetadataInventoryPut(pos,listname,index,stack,player) + end, + allow_metadata_inventory_take=function(pos,listname,index,stack,player) + return self:allowMetadataInventoryTake(pos,listname,index,stack,player) + end, + on_metadata_inventory_put=function(pos,listname,index,stack,player) + self:onMetadataInventoryPut(pos,listname,index,stack) + end, + on_metadata_inventory_move=function(pos,fromList,fromIndex,toList,toIndex,count) + self:onMetadataInventoryMove(pos,fromList,fromIndex,toList,toIndex) + end, + on_metadata_inventory_take=function(pos,listname,index,stack,player) + self:onMetadataInventoryTake(pos,listname,index,stack) + end, + _industrialtest_self=self + } + + if industrialtest.mtgAvailable then + def.groups={cracky=2} + if self.sounds=="metal" then + def.sounds=default.node_sound_metal_defaults() + end + def.can_dig=function(pos) + local meta=minetest.get_meta(pos) + local inv=meta:get_inventory() + for _,value in ipairs(self.storageSlots) do + if inv:get_stack(value,1):get_count()>0 then + return false + end + end + return true + end + elseif industrialtest.mclAvailable then + def.after_dig_node=function(pos,oldnode,oldmeta) + industrialtest.internal.mclAfterDigNode(pos,oldmeta,self.storageSlots) + end + if config.sounds=="metal" then + definition.sounds=mcl_sounds.node_sound_metal_defaults() + end + def.groups={ + pickaxey=1, + container=2 + } + def._mcl_blast_resistance=3.5 + def._mcl_hardness=3.9 + def._mcl_hoppers_on_try_pull=function(pos, hop_pos, hop_inv, hop_list) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + local stack = inv:get_stack("dst", 1) + if not stack:is_empty() and hop_inv:room_for_item(hop_list, stack) then + return inv, "dst", 1 + end + return nil, nil, nil + end + def._mcl_hoppers_on_try_push=function(pos, hop_pos, hop_inv, hop_list) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + return inv, "src", mcl_util.select_stack(hop_inv, hop_list, inv, "src") + end + def._mcl_hoppers_on_after_push=function(pos) + minetest.get_node_timer(pos):start(industrialtest.updateDelay) + end + end + + def.groups._industrialtest_wrenchUnmountable=1 + if self.requiresWrench then + def.drop="industrialtest:machine_block" + end + + return def +end + +function industrialtest.Machine.register(self) + local def=self:createDefinitionTable() + minetest.register_node(self.name,def) + industrialtest.api.addTag(self.name,"usesTimer") +end + +function industrialtest.Machine.onMetadataInventoryMove(pos,fromList,fromIndex,toList,toIndex,count) + 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) + 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) + end +end + +function industrialtest.Machine.onMetadataInventoryPut(pos,listname,index,stack) + if listname=="upgrades" then + local meta=minetest.get_meta(pos) + industrialtest.internal.applyUpgrade(pos,meta,stack) + end +end + +function industrialtest.Machine.onMetadataInventoryTake(pos,listname,index,stack) + if listname=="upgrades" then + local meta=minetest.get_meta(pos) + industrialtest.internal.removeUpgrade(pos,meta,stack) + end +end + +function industrialtest.Machine.allowMoveToUpgradeSlot(pos,toIndex,stack) + local def=minetest.registered_items[stack:get_name()] + if not def or not def.groups or not def.groups._industrialtest_machineUpgrade then + return 0 + end + local meta=minetest.get_meta(pos) + local inv=meta:get_inventory() + local targetSlot=inv:get_stack("upgrades",toIndex) + if not targetSlot:is_empty() then + return 0 + end + return stack:get_count() +end