diff --git a/basis/power.lua b/basis/power.lua index 7cf4356..73cf921 100644 --- a/basis/power.lua +++ b/basis/power.lua @@ -50,6 +50,10 @@ function techage.get_pos(pos, side) return tubelib2.get_pos(pos, dir) end +function techage.percent(max_val, curr_val) + return math.min(math.ceil(((curr_val or 0) * 100.0) / (max_val or 1.0)), 100) +end + -- Both nodes are from the same power network type? local function matching_nodes(pos, peer_pos) local tube_type1 = pos and TRD(pos) and TRD(pos).power_network.tube_type @@ -218,12 +222,12 @@ function techage.generator.after_dig_node(pos, oldnode) end function techage.generator.formspec_level(mem, sum) - local percent = math.min(((sum or 0) * 100) / (mem.power_capacity or 1), 100) + local percent = techage.percent(mem.power_capacity, sum) return "techage_form_level_bg.png^[lowpart:"..percent..":techage_form_level_fg.png]" end function techage.generator.formspec_battery_capa(max_capa, current_capa) - local percent = math.min(((current_capa or 0) * 100) / (max_capa or 1), 100) + local percent = techage.percent(max_capa, current_capa) return "techage_form_level_bg.png^[lowpart:"..percent..":techage_form_level_fg.png]" end function techage.generator.formspec_battery_load(mem) diff --git a/coal_power_station/battery.lua b/coal_power_station/akkubox.lua similarity index 75% rename from coal_power_station/battery.lua rename to coal_power_station/akkubox.lua index aae6af9..47b2a1d 100644 --- a/coal_power_station/battery.lua +++ b/coal_power_station/akkubox.lua @@ -8,7 +8,7 @@ LGPLv2.1+ See LICENSE.txt for more information - TA3 Battery Box + TA3 Akku Box ]]-- @@ -25,7 +25,7 @@ local STANDBY_TICKS = 4 local COUNTDOWN_TICKS = 4 local CYCLE_TIME = 2 local POWER_CONSUMPTION = 10 -local POWER_MAX_LOAD = 1000 +local POWER_MAX_LOAD = 300 local Power = techage.ElectricCable local generator = techage.generator @@ -80,7 +80,7 @@ local function stop_node(pos, mem, state) end local State = techage.NodeStates:new({ - node_name_passive = "techage:ta3_battery", + node_name_passive = "techage:ta3_akku", cycle_time = CYCLE_TIME, standby_ticks = STANDBY_TICKS, formspec_func = formspec, @@ -100,13 +100,12 @@ local function node_timer(pos, elapsed) end elseif mem.unloading then if mem.capa > 0 then - mem.capa = mem.capa - 1 + mem.capa = mem.capa - 2 else turn_off(pos, mem) end end end - --print("node_timer", S(pos), mem.sum, mem.power_capacity) return State:is_active(mem) end @@ -115,7 +114,6 @@ local function turn_power_on(pos, in_dir, sum) if State:is_active(mem) then mem.capa = mem.capa or 0 mem.sum = sum - --print("turn_power_on", sum, dump(mem)) if mem.unloading then if sum < 0 then turn_off(pos, mem) @@ -154,8 +152,29 @@ local function on_rightclick(pos) M(pos):set_string("formspec", formspec(State, pos, mem)) end -minetest.register_node("techage:ta3_battery", { - description = "TA3 Battery", +local function get_capa(itemstack) + local meta = itemstack:get_meta() + if meta then + return meta:get_int("capa") + end + return 0 +end + +local function set_capa(pos, oldnode, digger, capa) + local node = ItemStack(oldnode.name) + local meta = node:get_meta() + meta:set_int("capa", capa or 0) + local text = I("TA3 Akku Box").." ("..techage.percent(POWER_MAX_LOAD, capa).." %)" + meta:set_string("description", text) + local inv = minetest.get_inventory({type="player", name=digger:get_player_name()}) + local left_over = inv:add_item("main", node) + if left_over:get_count() > 0 then + minetest.add_item(pos, node) + end +end + +minetest.register_node("techage:ta3_akku", { + description = I("TA3 Akku Box"), tiles = { -- up, down, right, left, back, front "techage_filling_ta3.png^techage_frame_ta3_top.png", @@ -169,6 +188,7 @@ minetest.register_node("techage:ta3_battery", { groups = {cracky=2, crumbly=2, choppy=2}, on_rotate = screwdriver.disallow, is_ground_content = false, + sounds = default.node_sound_wood_defaults(), techage = { turn_on = turn_power_on, @@ -177,17 +197,20 @@ minetest.register_node("techage:ta3_battery", { power_side = "R", }, - after_place_node = function(pos, placer) + after_place_node = function(pos, placer, itemstack) local mem = generator.after_place_node(pos) State:node_init(pos, mem, "") mem.charging = false mem.unloading = false + mem.capa = get_capa(itemstack) on_rightclick(pos) end, after_dig_node = function(pos, oldnode, oldmetadata, digger) + local mem = tubelib2.get_mem(pos) State:after_dig_node(pos, oldnode, oldmetadata, digger) generator.after_dig_node(pos, oldnode) + set_capa(pos, oldnode, digger, mem.capa) end, after_tube_update = generator.after_tube_update, @@ -196,4 +219,19 @@ minetest.register_node("techage:ta3_battery", { on_timer = node_timer, }) -Power:add_secondary_node_names({"techage:ta3_battery"}) +Power:add_secondary_node_names({"techage:ta3_akku"}) + +techage.register_help_page(I("TA3 Akku Box"), +I([[Used to store electrical energy. +Charged in about 10 min, +provides energy for 5 min.]]), "techage:ta3_akku") + + +minetest.register_craft({ + output = "techage:ta3_akku", + recipe = { + {"default:tin_ingot", "default:tin_ingot", "default:wood"}, + {"default:copper_ingot", "default:copper_ingot", "techage:electric_cableS"}, + {"techage:iron_ingot", "techage:iron_ingot", "default:wood"}, + }, +}) diff --git a/init.lua b/init.lua index e5bf497..8064429 100644 --- a/init.lua +++ b/init.lua @@ -102,7 +102,7 @@ else dofile(MP.."/coal_power_station/generator.lua") dofile(MP.."/coal_power_station/turbine.lua") dofile(MP.."/coal_power_station/cooler.lua") - dofile(MP.."/coal_power_station/battery.lua") + dofile(MP.."/coal_power_station/akkubox.lua") --dofile(MP.."/test/generator.lua") diff --git a/nodes/baborium.lua b/nodes/baborium.lua index 1294ab3..084ec84 100644 --- a/nodes/baborium.lua +++ b/nodes/baborium.lua @@ -25,6 +25,11 @@ minetest.register_craftitem("techage:baborium_lump", { inventory_image = "techage_baborium_lump.png", }) +minetest.register_craftitem("techage:baborium_ingot", { + description = "Baborium Ingot", + inventory_image = "techage_baborium_ingot.png", +}) + minetest.register_ore({ diff --git a/power/electric_cable.lua b/power/electric_cable.lua index 379d8b5..b1a04bb 100644 --- a/power/electric_cable.lua +++ b/power/electric_cable.lua @@ -25,7 +25,7 @@ local Cable = tubelib2.Tube:new({ dirs_to_check = {1,2,3,4,5,6}, max_tube_length = 1000, show_infotext = false, - force_to_use_tubes = true, + --force_to_use_tubes = true, tube_type = "electric_cable", primary_node_names = {"techage:electric_cableS", "techage:electric_cableA"}, secondary_node_names = {}, diff --git a/textures/techage_baborium_ingot.png b/textures/techage_baborium_ingot.png new file mode 100644 index 0000000..49ee67f Binary files /dev/null and b/textures/techage_baborium_ingot.png differ diff --git a/textures/techage_iron_ingot.png b/textures/techage_iron_ingot.png index f1f8634..1ef867b 100644 Binary files a/textures/techage_iron_ingot.png and b/textures/techage_iron_ingot.png differ