mirror of
https://github.com/minetest-mods/technic.git
synced 2025-01-05 04:07:34 +01:00
Refill behaviour for power tools and cans
Supply the on_refill hook for power tools and cans, to perform appropriate charging. This is to be used by unified_inventory's creative-mode refill slot.
This commit is contained in:
parent
0294fc8f3a
commit
00d7c9bdea
@ -14,3 +14,14 @@ function technic.swap_node(pos, name)
|
|||||||
return node.name
|
return node.name
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Fully charge RE chargeable item.
|
||||||
|
-- Must be defined early to reference in item definitions.
|
||||||
|
function technic.refill_RE_charge(stack)
|
||||||
|
local max_charge = technic.power_tools[stack:get_name()]
|
||||||
|
if not max_charge then return stack end
|
||||||
|
technic.set_RE_wear(stack, max_charge, max_charge)
|
||||||
|
local meta = minetest.deserialize(stack:get_metadata()) or {}
|
||||||
|
meta.charge = max_charge
|
||||||
|
stack:set_metadata(minetest.serialize(meta))
|
||||||
|
return stack
|
||||||
|
end
|
||||||
|
@ -33,6 +33,7 @@ minetest.register_tool("technic:blue_energy_crystal", {
|
|||||||
"technic_diamond_block_blue.png",
|
"technic_diamond_block_blue.png",
|
||||||
"technic_diamond_block_blue.png"),
|
"technic_diamond_block_blue.png"),
|
||||||
wear_represents = "technic_RE_charge",
|
wear_represents = "technic_RE_charge",
|
||||||
|
on_refill = technic.refill_RE_charge,
|
||||||
tool_capabilities = {
|
tool_capabilities = {
|
||||||
max_drop_level = 0,
|
max_drop_level = 0,
|
||||||
groupcaps = {
|
groupcaps = {
|
||||||
@ -48,6 +49,7 @@ minetest.register_tool("technic:green_energy_crystal", {
|
|||||||
"technic_diamond_block_green.png",
|
"technic_diamond_block_green.png",
|
||||||
"technic_diamond_block_green.png"),
|
"technic_diamond_block_green.png"),
|
||||||
wear_represents = "technic_RE_charge",
|
wear_represents = "technic_RE_charge",
|
||||||
|
on_refill = technic.refill_RE_charge,
|
||||||
tool_capabilities = {
|
tool_capabilities = {
|
||||||
max_drop_level = 0,
|
max_drop_level = 0,
|
||||||
groupcaps = {
|
groupcaps = {
|
||||||
@ -63,6 +65,7 @@ minetest.register_tool("technic:red_energy_crystal", {
|
|||||||
"technic_diamond_block_red.png",
|
"technic_diamond_block_red.png",
|
||||||
"technic_diamond_block_red.png"),
|
"technic_diamond_block_red.png"),
|
||||||
wear_represents = "technic_RE_charge",
|
wear_represents = "technic_RE_charge",
|
||||||
|
on_refill = technic.refill_RE_charge,
|
||||||
tool_capabilities = {
|
tool_capabilities = {
|
||||||
max_drop_level = 0,
|
max_drop_level = 0,
|
||||||
groupcaps = {
|
groupcaps = {
|
||||||
|
@ -19,6 +19,7 @@ minetest.register_tool("technic:battery", {
|
|||||||
description = S("RE Battery"),
|
description = S("RE Battery"),
|
||||||
inventory_image = "technic_battery.png",
|
inventory_image = "technic_battery.png",
|
||||||
wear_represents = "technic_RE_charge",
|
wear_represents = "technic_RE_charge",
|
||||||
|
on_refill = technic.refill_RE_charge,
|
||||||
tool_capabilities = {
|
tool_capabilities = {
|
||||||
charge = 0,
|
charge = 0,
|
||||||
max_drop_level = 0,
|
max_drop_level = 0,
|
||||||
|
@ -81,6 +81,11 @@ minetest.register_tool("technic:water_can", {
|
|||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
on_refill = function(stack)
|
||||||
|
stack:set_metadata(tostring(water_can_max_load))
|
||||||
|
set_can_wear(stack, water_can_max_load, water_can_max_load)
|
||||||
|
return stack
|
||||||
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_tool("technic:lava_can", {
|
minetest.register_tool("technic:lava_can", {
|
||||||
@ -131,5 +136,10 @@ minetest.register_tool("technic:lava_can", {
|
|||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
on_refill = function(stack)
|
||||||
|
stack:set_metadata(tostring(lava_can_max_load))
|
||||||
|
set_can_wear(stack, lava_can_max_load, lava_can_max_load)
|
||||||
|
return stack
|
||||||
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -256,6 +256,7 @@ minetest.register_tool("technic:chainsaw", {
|
|||||||
inventory_image = "technic_chainsaw.png",
|
inventory_image = "technic_chainsaw.png",
|
||||||
stack_max = 1,
|
stack_max = 1,
|
||||||
wear_represents = "technic_RE_charge",
|
wear_represents = "technic_RE_charge",
|
||||||
|
on_refill = technic.refill_RE_charge,
|
||||||
on_use = function(itemstack, user, pointed_thing)
|
on_use = function(itemstack, user, pointed_thing)
|
||||||
if pointed_thing.type ~= "node" then
|
if pointed_thing.type ~= "node" then
|
||||||
return itemstack
|
return itemstack
|
||||||
|
@ -14,6 +14,7 @@ minetest.register_tool("technic:flashlight", {
|
|||||||
inventory_image = "technic_flashlight.png",
|
inventory_image = "technic_flashlight.png",
|
||||||
stack_max = 1,
|
stack_max = 1,
|
||||||
wear_represents = "technic_RE_charge",
|
wear_represents = "technic_RE_charge",
|
||||||
|
on_refill = technic.refill_RE_charge,
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
|
@ -327,6 +327,7 @@ minetest.register_tool("technic:mining_drill", {
|
|||||||
inventory_image = "technic_mining_drill.png",
|
inventory_image = "technic_mining_drill.png",
|
||||||
stack_max = 1,
|
stack_max = 1,
|
||||||
wear_represents = "technic_RE_charge",
|
wear_represents = "technic_RE_charge",
|
||||||
|
on_refill = technic.refill_RE_charge,
|
||||||
on_use = function(itemstack, user, pointed_thing)
|
on_use = function(itemstack, user, pointed_thing)
|
||||||
if pointed_thing.type ~= "node" then
|
if pointed_thing.type ~= "node" then
|
||||||
return itemstack
|
return itemstack
|
||||||
@ -351,6 +352,7 @@ minetest.register_tool("technic:mining_drill_mk2", {
|
|||||||
description = S("Mining Drill Mk%d"):format(2),
|
description = S("Mining Drill Mk%d"):format(2),
|
||||||
inventory_image = "technic_mining_drill_mk2.png",
|
inventory_image = "technic_mining_drill_mk2.png",
|
||||||
wear_represents = "technic_RE_charge",
|
wear_represents = "technic_RE_charge",
|
||||||
|
on_refill = technic.refill_RE_charge,
|
||||||
on_use = function(itemstack, user, pointed_thing)
|
on_use = function(itemstack, user, pointed_thing)
|
||||||
mining_drill_mk2_handler(itemstack, user, pointed_thing)
|
mining_drill_mk2_handler(itemstack, user, pointed_thing)
|
||||||
return itemstack
|
return itemstack
|
||||||
@ -366,6 +368,7 @@ for i = 1, 4 do
|
|||||||
inventory_image = "technic_mining_drill_mk2.png^technic_tool_mode"..i..".png",
|
inventory_image = "technic_mining_drill_mk2.png^technic_tool_mode"..i..".png",
|
||||||
wield_image = "technic_mining_drill_mk2.png",
|
wield_image = "technic_mining_drill_mk2.png",
|
||||||
wear_represents = "technic_RE_charge",
|
wear_represents = "technic_RE_charge",
|
||||||
|
on_refill = technic.refill_RE_charge,
|
||||||
groups = {not_in_creative_inventory=1},
|
groups = {not_in_creative_inventory=1},
|
||||||
on_use = function(itemstack, user, pointed_thing)
|
on_use = function(itemstack, user, pointed_thing)
|
||||||
mining_drill_mk2_handler(itemstack, user, pointed_thing)
|
mining_drill_mk2_handler(itemstack, user, pointed_thing)
|
||||||
@ -378,6 +381,7 @@ minetest.register_tool("technic:mining_drill_mk3", {
|
|||||||
description = S("Mining Drill Mk%d"):format(3),
|
description = S("Mining Drill Mk%d"):format(3),
|
||||||
inventory_image = "technic_mining_drill_mk3.png",
|
inventory_image = "technic_mining_drill_mk3.png",
|
||||||
wear_represents = "technic_RE_charge",
|
wear_represents = "technic_RE_charge",
|
||||||
|
on_refill = technic.refill_RE_charge,
|
||||||
on_use = function(itemstack, user, pointed_thing)
|
on_use = function(itemstack, user, pointed_thing)
|
||||||
mining_drill_mk3_handler(itemstack,user,pointed_thing)
|
mining_drill_mk3_handler(itemstack,user,pointed_thing)
|
||||||
return itemstack
|
return itemstack
|
||||||
@ -393,6 +397,7 @@ for i=1,5,1 do
|
|||||||
inventory_image = "technic_mining_drill_mk3.png^technic_tool_mode"..i..".png",
|
inventory_image = "technic_mining_drill_mk3.png^technic_tool_mode"..i..".png",
|
||||||
wield_image = "technic_mining_drill_mk3.png",
|
wield_image = "technic_mining_drill_mk3.png",
|
||||||
wear_represents = "technic_RE_charge",
|
wear_represents = "technic_RE_charge",
|
||||||
|
on_refill = technic.refill_RE_charge,
|
||||||
groups = {not_in_creative_inventory=1},
|
groups = {not_in_creative_inventory=1},
|
||||||
on_use = function(itemstack, user, pointed_thing)
|
on_use = function(itemstack, user, pointed_thing)
|
||||||
mining_drill_mk3_handler(itemstack,user,pointed_thing)
|
mining_drill_mk3_handler(itemstack,user,pointed_thing)
|
||||||
|
@ -169,6 +169,7 @@ for _, m in pairs(mining_lasers_list) do
|
|||||||
inventory_image = "technic_mining_laser_mk"..m[1]..".png",
|
inventory_image = "technic_mining_laser_mk"..m[1]..".png",
|
||||||
stack_max = 1,
|
stack_max = 1,
|
||||||
wear_represents = "technic_RE_charge",
|
wear_represents = "technic_RE_charge",
|
||||||
|
on_refill = technic.refill_RE_charge,
|
||||||
on_use = function(itemstack, user)
|
on_use = function(itemstack, user)
|
||||||
local meta = minetest.deserialize(itemstack:get_metadata())
|
local meta = minetest.deserialize(itemstack:get_metadata())
|
||||||
if not meta or not meta.charge then
|
if not meta or not meta.charge then
|
||||||
|
@ -8,6 +8,7 @@ minetest.register_tool("technic:sonic_screwdriver", {
|
|||||||
description = S("Sonic Screwdriver"),
|
description = S("Sonic Screwdriver"),
|
||||||
inventory_image = "technic_sonic_screwdriver.png",
|
inventory_image = "technic_sonic_screwdriver.png",
|
||||||
wear_represents = "technic_RE_charge",
|
wear_represents = "technic_RE_charge",
|
||||||
|
on_refill = technic.refill_RE_charge,
|
||||||
on_use = function(itemstack, user, pointed_thing)
|
on_use = function(itemstack, user, pointed_thing)
|
||||||
-- Must be pointing to facedir applicable node
|
-- Must be pointing to facedir applicable node
|
||||||
if pointed_thing.type ~= "node" then
|
if pointed_thing.type ~= "node" then
|
||||||
|
Loading…
Reference in New Issue
Block a user