2018-06-24 22:33:00 +02:00
|
|
|
--[[
|
|
|
|
|
|
|
|
sl_controller
|
|
|
|
=============
|
|
|
|
|
2020-11-20 14:45:28 +01:00
|
|
|
Copyright (C) 2017-2020 Joachim Stolberg
|
2018-06-24 22:33:00 +02:00
|
|
|
|
2020-11-20 14:45:28 +01:00
|
|
|
AGPL v3
|
2018-06-24 22:33:00 +02:00
|
|
|
See LICENSE.txt for more information
|
|
|
|
|
|
|
|
battery.lua:
|
2022-06-09 23:49:50 +02:00
|
|
|
|
2018-08-28 22:24:43 +02:00
|
|
|
REPLACED BY SMARTLINE BATTERY !!!
|
2018-06-24 22:33:00 +02:00
|
|
|
|
|
|
|
]]--
|
|
|
|
|
2018-06-26 23:04:25 +02:00
|
|
|
local function calc_percent(content)
|
2022-06-09 23:49:50 +02:00
|
|
|
local val = (sl_controller.battery_capacity -
|
2018-06-26 23:04:25 +02:00
|
|
|
math.min(content or 0, sl_controller.battery_capacity))
|
|
|
|
return 100 - math.floor((val * 100.0 / sl_controller.battery_capacity))
|
|
|
|
end
|
|
|
|
|
2018-06-24 22:33:00 +02:00
|
|
|
local function on_timer(pos, elapsed)
|
|
|
|
local meta = minetest.get_meta(pos)
|
2018-06-26 23:04:25 +02:00
|
|
|
local percent = calc_percent(meta:get_int("content"))
|
2018-06-24 22:33:00 +02:00
|
|
|
meta:set_string("infotext", "Battery ("..percent.."%)")
|
|
|
|
if percent == 0 then
|
|
|
|
local node = minetest.get_node(pos)
|
|
|
|
node.name = "sl_controller:battery_empty"
|
|
|
|
minetest.swap_node(pos, node)
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2018-07-07 13:16:35 +02:00
|
|
|
local function register_battery(ext, percent, nici)
|
2018-06-26 23:04:25 +02:00
|
|
|
minetest.register_node("sl_controller:battery"..ext, {
|
2018-06-30 00:23:18 +02:00
|
|
|
description = "Battery "..ext,
|
2018-06-26 23:04:25 +02:00
|
|
|
inventory_image = 'sl_controller_battery_inventory.png',
|
|
|
|
wield_image = 'sl_controller_battery_inventory.png',
|
|
|
|
tiles = {
|
|
|
|
-- up, down, right, left, back, front
|
|
|
|
"smartline.png",
|
|
|
|
"smartline.png",
|
|
|
|
"smartline.png",
|
|
|
|
"smartline.png",
|
|
|
|
"smartline.png",
|
|
|
|
"smartline.png^sl_controller_battery_green.png",
|
|
|
|
},
|
2018-06-24 22:33:00 +02:00
|
|
|
|
2018-06-26 23:04:25 +02:00
|
|
|
drawtype = "nodebox",
|
|
|
|
node_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = {
|
|
|
|
{ -6/32, -6/32, 14/32, 6/32, 6/32, 16/32},
|
|
|
|
},
|
2018-06-24 22:33:00 +02:00
|
|
|
},
|
2022-06-09 23:49:50 +02:00
|
|
|
|
2018-06-26 23:04:25 +02:00
|
|
|
after_place_node = function(pos, placer)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_int("content", sl_controller.battery_capacity * percent)
|
|
|
|
local node = minetest.get_node(pos)
|
|
|
|
node.name = "sl_controller:battery"
|
|
|
|
minetest.swap_node(pos, node)
|
|
|
|
on_timer(pos, 1)
|
|
|
|
minetest.get_node_timer(pos):start(30)
|
|
|
|
end,
|
2022-06-09 23:49:50 +02:00
|
|
|
|
2018-06-26 23:04:25 +02:00
|
|
|
on_timer = on_timer,
|
2022-06-09 23:49:50 +02:00
|
|
|
|
|
|
|
|
2018-06-26 23:04:25 +02:00
|
|
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
|
|
|
local percent = calc_percent(tonumber(oldmetadata.fields.content))
|
|
|
|
local stack
|
|
|
|
if percent > 95 then
|
2018-08-28 22:24:43 +02:00
|
|
|
stack = ItemStack("smartline:battery")
|
2018-06-26 23:04:25 +02:00
|
|
|
elseif percent > 75 then
|
2018-08-28 22:24:43 +02:00
|
|
|
stack = ItemStack("smartline:battery75")
|
2018-06-26 23:04:25 +02:00
|
|
|
elseif percent > 50 then
|
2018-08-28 22:24:43 +02:00
|
|
|
stack = ItemStack("smartline:battery50")
|
2018-06-26 23:04:25 +02:00
|
|
|
elseif percent > 25 then
|
2018-08-28 22:24:43 +02:00
|
|
|
stack = ItemStack("smartline:battery25")
|
2018-06-26 23:04:25 +02:00
|
|
|
else
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local inv = minetest.get_inventory({type="player", name=digger:get_player_name()})
|
|
|
|
inv:add_item("main", stack)
|
|
|
|
end,
|
|
|
|
|
|
|
|
paramtype = "light",
|
|
|
|
sunlight_propagates = true,
|
|
|
|
paramtype2 = "facedir",
|
2018-07-07 13:16:35 +02:00
|
|
|
groups = {choppy=1, cracky=1, crumbly=1, not_in_creative_inventory=nici},
|
2018-06-26 23:04:25 +02:00
|
|
|
drop = "",
|
|
|
|
is_ground_content = false,
|
|
|
|
sounds = default.node_sound_stone_defaults(),
|
2022-06-09 23:49:50 +02:00
|
|
|
on_blast = function() end,
|
2018-06-26 23:04:25 +02:00
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2018-08-28 22:24:43 +02:00
|
|
|
register_battery("", 1.0, 1)
|
2018-07-07 13:16:35 +02:00
|
|
|
register_battery("75", 0.75, 1)
|
|
|
|
register_battery("50", 0.5, 1)
|
|
|
|
register_battery("25", 0.25, 1)
|
2018-06-24 22:33:00 +02:00
|
|
|
|
|
|
|
minetest.register_node("sl_controller:battery_empty", {
|
|
|
|
description = "Battery",
|
|
|
|
tiles = {
|
|
|
|
-- up, down, right, left, back, front
|
|
|
|
"smartline.png",
|
|
|
|
"smartline.png",
|
|
|
|
"smartline.png",
|
|
|
|
"smartline.png",
|
|
|
|
"smartline.png",
|
|
|
|
"smartline.png^sl_controller_battery_red.png",
|
|
|
|
},
|
|
|
|
|
|
|
|
drawtype = "nodebox",
|
|
|
|
node_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = {
|
|
|
|
{ -6/32, -6/32, 14/32, 6/32, 6/32, 16/32},
|
|
|
|
},
|
|
|
|
},
|
2022-06-09 23:49:50 +02:00
|
|
|
|
2018-06-24 22:33:00 +02:00
|
|
|
after_place_node = function(pos, placer)
|
|
|
|
local meta = minetest.get_meta(pos)
|
2018-07-26 19:48:57 +02:00
|
|
|
meta:set_int("content", 0)
|
2018-06-24 22:33:00 +02:00
|
|
|
end,
|
2022-06-09 23:49:50 +02:00
|
|
|
|
2018-06-24 22:33:00 +02:00
|
|
|
paramtype = "light",
|
|
|
|
sunlight_propagates = true,
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
groups = {choppy=1, cracky=1, crumbly=1, not_in_creative_inventory=1},
|
|
|
|
drop = "",
|
|
|
|
is_ground_content = false,
|
|
|
|
sounds = default.node_sound_stone_defaults(),
|
2022-06-09 23:49:50 +02:00
|
|
|
on_blast = function() end,
|
2018-06-24 22:33:00 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
|
2018-08-28 22:24:43 +02:00
|
|
|
--if minetest.global_exists("moreores") then
|
|
|
|
-- minetest.register_craft({
|
|
|
|
-- output = "sl_controller:battery 2",
|
|
|
|
-- recipe = {
|
|
|
|
-- {"", "moreores:silver_ingot", ""},
|
|
|
|
-- {"", "default:copper_ingot", ""},
|
|
|
|
-- {"", "moreores:silver_ingot", ""},
|
|
|
|
-- }
|
|
|
|
-- })
|
|
|
|
--else
|
|
|
|
-- minetest.register_craft({
|
|
|
|
-- output = "sl_controller:battery 2",
|
|
|
|
-- recipe = {
|
|
|
|
-- {"", "default:tin_ingot", ""},
|
|
|
|
-- {"", "default:copper_ingot", ""},
|
|
|
|
-- {"", "default:tin_ingot", ""},
|
|
|
|
-- }
|
|
|
|
-- })
|
|
|
|
--end
|