Implement Power Storage Upgrade
This commit is contained in:
parent
4f8acd7a86
commit
18a8e235f6
@ -226,26 +226,26 @@ machine.onMetadataInventoryMove=function(pos,fromList,fromIndex,toList,toIndex,c
|
||||
local meta=minetest.get_meta(pos)
|
||||
local inv=meta:get_inventory()
|
||||
local stack=inv:get_stack(fromList,fromIndex)
|
||||
industrialtest.internal.applyUpgrade(meta,stack)
|
||||
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(meta,stack)
|
||||
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(meta,stack)
|
||||
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(meta,stack)
|
||||
industrialtest.internal.removeUpgrade(pos,meta,stack)
|
||||
end
|
||||
end
|
||||
|
||||
|
41
upgrades.lua
41
upgrades.lua
@ -16,7 +16,7 @@
|
||||
|
||||
local S=minetest.get_translator("industrialtest")
|
||||
|
||||
industrialtest.internal.applyUpgrade=function(meta,stack)
|
||||
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)
|
||||
@ -44,10 +44,22 @@ industrialtest.internal.applyUpgrade=function(meta,stack)
|
||||
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.internal.removeUpgrade=function(meta,stack)
|
||||
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")
|
||||
@ -73,9 +85,16 @@ industrialtest.internal.removeUpgrade=function(meta,stack)
|
||||
local networks=industrialtest.api.isAttachedToNetwork(meta)
|
||||
if networks then
|
||||
for _,network in ipairs(networks) do
|
||||
industrialtest.api.createNetworkMapForNode(network)
|
||||
minetest.get_node_timer(network):start(industrialtest.updateDelay)
|
||||
end
|
||||
end
|
||||
elseif def.groups._industrialtest_upgradePowerStorage then
|
||||
meta:set_int("industrialtest.powerCapacity",meta:get_int("industrialtest.powerCapacity")-10000)
|
||||
meta:set_int("industrialtest.powerAmount",math.min(meta:get_int("industrialtest.powerAmount"),meta:get_int("industrialtest.powerCapacity")))
|
||||
local nodeDef=minetest.registered_nodes[minetest.get_node(pos).name]
|
||||
if nodeDef._industrialtest_updateFormspec then
|
||||
nodeDef._industrialtest_updateFormspec(pos)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -87,6 +106,7 @@ local function registerMachineUpgrade(config)
|
||||
_industrialtest_machineUpgrade=1,
|
||||
_industrialtest_upgradeSpeed=config.speed or nil,
|
||||
_industrialtest_upgradeTransformer=config.transformer or nil,
|
||||
_industrialtest_upgradePowerStorage=config.powerStorage or nil,
|
||||
}
|
||||
})
|
||||
end
|
||||
@ -119,3 +139,18 @@ minetest.register_craft({
|
||||
{industrialtest.elementKeys.glass,"industrialtest:electronic_circuit",industrialtest.elementKeys.glass}
|
||||
}
|
||||
})
|
||||
|
||||
registerMachineUpgrade({
|
||||
name="power_storage_upgrade",
|
||||
displayName=S("Power Storage Upgrade"),
|
||||
powerStorage=1
|
||||
})
|
||||
minetest.register_craft({
|
||||
type="shaped",
|
||||
output="industrialtest:power_storage_upgrade",
|
||||
recipe={
|
||||
{"group:wood","group:wood","group:wood"},
|
||||
{"industrialtest:insulated_copper_cable","industrialtest:re_battery","industrialtest:insulated_copper_cable"},
|
||||
{"group:wood","industrialtest:electronic_circuit","group:wood"}
|
||||
}
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user