Add ta2 gravity energy storage system
This commit is contained in:
parent
c3eb886244
commit
054283cc4d
@ -25,7 +25,7 @@ local control = networks.control
|
||||
|
||||
local STANDBY_TICKS = 4
|
||||
local CYCLE_TIME = 2
|
||||
local PWR_PERF = 100
|
||||
local PWR_PERF = 25
|
||||
|
||||
local function formspec(self, pos, nvm)
|
||||
return techage.generator_formspec(self, pos, nvm, S("Power Source"), nvm.provided, PWR_PERF)
|
||||
|
7
init.lua
7
init.lua
@ -89,7 +89,6 @@ dofile(MP.."/basis/recipe_lib.lua")
|
||||
dofile(MP.."/basis/formspec_update.lua")
|
||||
dofile(MP.."/basis/windturbine_lib.lua")
|
||||
dofile(MP.."/basis/laser_lib.lua")
|
||||
dofile(MP.."/basis/rope_lib.lua")
|
||||
|
||||
-- Main doc
|
||||
dofile(MP.."/doc/manual_DE.lua")
|
||||
@ -115,7 +114,6 @@ dofile(MP.."/power/powerswitchbox.lua")
|
||||
dofile(MP.."/power/powerswitch.lua")
|
||||
dofile(MP.."/power/protection.lua")
|
||||
dofile(MP.."/power/power_line.lua")
|
||||
dofile(MP.."/power/ta2_winch.lua")
|
||||
dofile(MP.."/power/ta4_cable.lua")
|
||||
dofile(MP.."/power/ta4_cable_wall_entry.lua")
|
||||
dofile(MP.."/power/laser.lua")
|
||||
@ -143,6 +141,11 @@ dofile(MP.."/steam_engine/boiler.lua")
|
||||
dofile(MP.."/steam_engine/cylinder.lua")
|
||||
dofile(MP.."/steam_engine/flywheel.lua")
|
||||
|
||||
-- TA2 gravity-based energy storage
|
||||
dofile(MP.."/ta2_energy_storage/ta2_rope.lua")
|
||||
dofile(MP.."/ta2_energy_storage/ta2_winch.lua")
|
||||
dofile(MP.."/ta2_energy_storage/ta2_weight_chest.lua")
|
||||
|
||||
-- Liquids I
|
||||
dofile(MP.."/liquids/liquid_pipe.lua")
|
||||
dofile(MP.."/liquids/valve.lua")
|
||||
|
@ -61,14 +61,14 @@ minetest.register_node("techage:basalt_stone_block", {
|
||||
minetest.register_node("techage:basalt_gravel", {
|
||||
description = S("Basalt Gravel"),
|
||||
tiles = {"default_gravel.png^[brighten"},
|
||||
groups = {crumbly = 2, falling_node = 1},
|
||||
groups = {crumbly = 2, falling_node = 1, gravel = 1},
|
||||
sounds = default.node_sound_gravel_defaults(),
|
||||
})
|
||||
|
||||
minetest.register_node("techage:sieved_basalt_gravel", {
|
||||
description = S("Sieved Basalt Gravel"),
|
||||
tiles = {"default_gravel.png^[brighten"},
|
||||
groups = {crumbly = 2, falling_node = 1, not_in_creative_inventory=1},
|
||||
groups = {crumbly = 2, falling_node = 1, gravel = 1, not_in_creative_inventory=1},
|
||||
sounds = default.node_sound_gravel_defaults(),
|
||||
})
|
||||
|
||||
|
@ -37,3 +37,4 @@ minetest.register_on_mods_loaded(function()
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.override_item("default:gravel", {groups = {crumbly = 2, gravel = 1, falling_node = 1}})
|
@ -1,188 +0,0 @@
|
||||
--[[
|
||||
|
||||
TechAge
|
||||
=======
|
||||
|
||||
Copyright (C) 2019-2021 Joachim Stolberg
|
||||
|
||||
GPL v3
|
||||
See LICENSE.txt for more information
|
||||
|
||||
TA4 Laser beam emitter and receiver
|
||||
|
||||
]]--
|
||||
|
||||
-- for lazy programmers
|
||||
local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end
|
||||
local S2P = minetest.string_to_pos
|
||||
local M = minetest.get_meta
|
||||
local S = techage.S
|
||||
|
||||
local STORAGE_CAPA = 1000
|
||||
|
||||
local Axle = techage.Axle
|
||||
local power = networks.power
|
||||
|
||||
minetest.register_node("techage:ta2_winch", {
|
||||
description = S("TA2 Winch"),
|
||||
tiles = {
|
||||
-- up, down, right, left, back, front
|
||||
"techage_filling_ta4.png^techage_frame_ta4_top.png",
|
||||
"techage_filling_ta4.png^techage_frame_ta4.png",
|
||||
"techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_laser.png",
|
||||
"techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_laser.png",
|
||||
"techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_laser_hole.png",
|
||||
"techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_hole_electric.png",
|
||||
},
|
||||
|
||||
after_place_node = function(pos, placer)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
local outdir = networks.side_to_outdir(pos, "R")
|
||||
M(pos):set_int("outdir", outdir)
|
||||
Axle:after_place_node(pos, {outdir})
|
||||
local pos1, pos2 = techage.renew_rope(pos, 10)
|
||||
local pos3 = {x = pos1.x, y = (pos1.y + pos2.y) / 2, z = pos1.z} -- mid-pos
|
||||
minetest.add_entity(pos3, "techage:ta2_weight_chest_entity")
|
||||
minetest.get_node_timer(pos):start(2)
|
||||
power.start_storage_calc(pos, Axle, outdir)
|
||||
end,
|
||||
|
||||
on_timer = function(pos, elapsed)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
local mem = techage.get_mem(pos)
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
|
||||
--power.start_storage_calc(pos, Axle, outdir)
|
||||
|
||||
nvm.load = power.get_storage_load(pos, Axle, outdir, STORAGE_CAPA)
|
||||
if nvm.load then
|
||||
print("on_timer" , nvm.load)
|
||||
local len = 11 - (nvm.load / STORAGE_CAPA * 10)
|
||||
local y = pos.y - len
|
||||
techage.renew_rope(pos, len)
|
||||
if mem.obj then
|
||||
mem.obj:remove()
|
||||
end
|
||||
mem.obj = minetest.add_entity({x = pos.x, y = y, z = pos.z}, "techage:ta2_weight_chest_entity")
|
||||
end
|
||||
--print("on_timer", nvm.load)
|
||||
return true
|
||||
end,
|
||||
|
||||
after_dig_node = function(pos, oldnode, oldmetadata)
|
||||
local outdir = tonumber(oldmetadata.fields.outdir or 0)
|
||||
power.start_storage_calc(pos, Axle, outdir)
|
||||
Axle:after_dig_node(pos, {outdir})
|
||||
techage.del_mem(pos)
|
||||
end,
|
||||
|
||||
get_storage_data = function(pos, tlib2)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
return {level = (nvm.load or 0) / STORAGE_CAPA, capa = STORAGE_CAPA}
|
||||
end,
|
||||
|
||||
paramtype2 = "facedir",
|
||||
groups = {choppy=2, cracky=2, crumbly=2},
|
||||
is_ground_content = false,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
})
|
||||
|
||||
minetest.register_entity("techage:ta2_weight_chest_entity", {
|
||||
initial_properties = {
|
||||
physical = true,
|
||||
collisionbox = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
|
||||
visual = "wielditem",
|
||||
textures = {"techage:ta2_weight_chest"},
|
||||
visual_size = {x=0.66, y=0.66, z=0.66},
|
||||
static_save = false,
|
||||
},
|
||||
driver_allowed = true,
|
||||
})
|
||||
|
||||
power.register_nodes({"techage:ta2_winch"}, Axle, "sto", {"R"})
|
||||
|
||||
local function allow_metadata_inventory_put(pos, listname, index, stack, player)
|
||||
if minetest.is_protected(pos, player:get_player_name()) then
|
||||
return 0
|
||||
end
|
||||
return stack:get_count()
|
||||
end
|
||||
|
||||
local function allow_metadata_inventory_take(pos, listname, index, stack, player)
|
||||
if minetest.is_protected(pos, player:get_player_name()) then
|
||||
return 0
|
||||
end
|
||||
return stack:get_count()
|
||||
end
|
||||
|
||||
local function can_dig(pos, player)
|
||||
if minetest.is_protected(pos, player:get_player_name()) then
|
||||
return false
|
||||
end
|
||||
local inv = minetest.get_meta(pos):get_inventory()
|
||||
return inv:is_empty("main")
|
||||
end
|
||||
|
||||
local function after_dig_node(pos, oldnode, oldmetadata, digger)
|
||||
techage.remove_node(pos, oldnode, oldmetadata)
|
||||
end
|
||||
|
||||
local function formspec()
|
||||
return "size[8,6.7]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
"list[context;main;1,0;6,2;]"..
|
||||
"list[current_player;main;0,3;8,4;]"..
|
||||
"listring[context;main]"..
|
||||
"listring[current_player;main]"
|
||||
end
|
||||
|
||||
minetest.register_node("techage:ta2_weight_chest", {
|
||||
description = S("TA2 Weight Chest"),
|
||||
tiles = {
|
||||
-- up, down, right, left, back, front
|
||||
"techage_filling_ta2.png^techage_frame_ta2.png^techage_weight_bottom.png",
|
||||
"techage_filling_ta2.png^techage_frame_ta2.png^techage_weight_bottom.png",
|
||||
"techage_filling_ta2.png^techage_frame_ta2.png^techage_appl_chest_back_ta3.png^techage_weight_side.png",
|
||||
"techage_filling_ta2.png^techage_frame_ta2.png^techage_appl_chest_back_ta3.png^techage_weight_side.png",
|
||||
"techage_filling_ta2.png^techage_frame_ta2.png^techage_appl_chest_back_ta3.png^techage_weight_side.png",
|
||||
"techage_filling_ta2.png^techage_frame_ta2.png^techage_appl_chest_front_ta3.png^techage_weight_side.png",
|
||||
},
|
||||
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size('main', 12)
|
||||
end,
|
||||
|
||||
after_place_node = function(pos, placer)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("owner", placer:get_player_name())
|
||||
meta:set_string("formspec", formspec())
|
||||
end,
|
||||
|
||||
techage_set_numbers = function(pos, numbers, player_name)
|
||||
return techage.logic.set_numbers(pos, numbers, player_name, S("TA2 Weight Chest"))
|
||||
end,
|
||||
|
||||
can_dig = can_dig,
|
||||
after_dig_node = after_dig_node,
|
||||
allow_metadata_inventory_put = allow_metadata_inventory_put,
|
||||
allow_metadata_inventory_take = allow_metadata_inventory_take,
|
||||
|
||||
paramtype2 = "facedir",
|
||||
groups = {choppy=2, cracky=2, crumbly=2},
|
||||
is_ground_content = false,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
})
|
||||
|
||||
--minetest.register_craft({
|
||||
-- output = "techage:ta4_laser_emitter",
|
||||
-- recipe = {
|
||||
-- {"techage:ta4_carbon_fiber", "dye:blue", "techage:ta4_carbon_fiber"},
|
||||
-- {"techage:electric_cableS", "basic_materials:energy_crystal_simple", "techage:ta4_leds"},
|
||||
-- {"default:steel_ingot", "techage:ta4_wlanchip", "default:steel_ingot"},
|
||||
-- },
|
||||
--})
|
||||
|
@ -8,16 +8,19 @@
|
||||
GPL v3
|
||||
See LICENSE.txt for more information
|
||||
|
||||
Rope basis functions
|
||||
Rope for TA2 gravity-based energy storage
|
||||
|
||||
]]--
|
||||
|
||||
local Entities = {}
|
||||
|
||||
-- Return first pos after start pos and the destination pos
|
||||
local function get_positions(pos, length)
|
||||
local function get_positions(pos, length, force)
|
||||
local pos1 = {x = pos.x, y = pos.y - 1, z = pos.z} -- start pos
|
||||
local pos2 = {x = pos.x, y = pos.y - length, z = pos.z} -- end pos
|
||||
local pos2 = {x = pos.x, y = pos.y - 1 - length, z = pos.z} -- end pos
|
||||
if force then
|
||||
return pos1, pos2 -- force given length
|
||||
end
|
||||
local _, pos3 = minetest.line_of_sight(pos1, pos2)
|
||||
return pos1, pos3 or pos2 -- new values
|
||||
end
|
||||
@ -36,15 +39,14 @@ local function add_rope(pos, pos1, pos2)
|
||||
local key = del_rope(pos)
|
||||
|
||||
pos1.y = pos1.y + 0.5 -- from
|
||||
pos2.y = pos2.y + 0.5 -- to
|
||||
pos2.y = pos2.y - 0.5 -- to
|
||||
local pos3 = {x = pos1.x, y = (pos1.y + pos2.y) / 2, z = pos1.z} -- mid-pos
|
||||
local length = math.abs(pos1.y - pos2.y)
|
||||
|
||||
local rope = minetest.add_entity(pos3, "techage:ta2_rope")
|
||||
if rope then
|
||||
rope:set_properties({visual_size = {x = 0.05, y = length}, collisionbox = {x = 0.05, y = length}})
|
||||
rope:set_properties({visual_size = {x = 0.06, y = length}, collisionbox = {x = 0.06, y = length}})
|
||||
end
|
||||
--print(pos1.y, pos2.y, pos3.y)
|
||||
Entities[key] = rope
|
||||
end
|
||||
|
||||
@ -60,11 +62,11 @@ minetest.register_entity("techage:ta2_rope", {
|
||||
"techage_rope.png",
|
||||
},
|
||||
use_texture_alpha = false,
|
||||
physical = false,
|
||||
collide_with_objects = false,
|
||||
pointable = false,
|
||||
physical = true,
|
||||
collide_with_objects = true,
|
||||
pointable = true,
|
||||
static_save = false,
|
||||
visual_size = {x = 0.05, y = 10, z = 0.05},
|
||||
visual_size = {x = 0.06, y = 10, z = 0.06},
|
||||
shaded = true,
|
||||
},
|
||||
})
|
||||
@ -72,13 +74,12 @@ minetest.register_entity("techage:ta2_rope", {
|
||||
-------------------------------------------------------------------------------
|
||||
-- API functions
|
||||
-------------------------------------------------------------------------------
|
||||
function techage.renew_rope(pos, length)
|
||||
local pos1, pos2 = get_positions(pos, length)
|
||||
function techage.renew_rope(pos, length, force)
|
||||
local pos1, pos2 = get_positions(pos, length, force)
|
||||
if pos1 then
|
||||
add_rope(pos, pos1, pos2)
|
||||
return pos1, pos2
|
||||
end
|
||||
end
|
||||
|
||||
-- techage.del_laser(pos)
|
||||
techage.del_rope = del_rope
|
138
ta2_energy_storage/ta2_weight_chest.lua
Normal file
138
ta2_energy_storage/ta2_weight_chest.lua
Normal file
@ -0,0 +1,138 @@
|
||||
--[[
|
||||
|
||||
TechAge
|
||||
=======
|
||||
|
||||
Copyright (C) 2019-2021 Joachim Stolberg
|
||||
|
||||
GPL v3
|
||||
See LICENSE.txt for more information
|
||||
|
||||
Chest for TA2 gravity-based energy storage
|
||||
|
||||
]]--
|
||||
|
||||
-- for lazy programmers
|
||||
local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end
|
||||
local S2P = minetest.string_to_pos
|
||||
local M = minetest.get_meta
|
||||
local S = techage.S
|
||||
|
||||
local function valid_weight_items(stack)
|
||||
local name = stack:get_name()
|
||||
local ndef = minetest.registered_nodes[name]
|
||||
if ndef then
|
||||
if minetest.get_item_group(name, "stone") > 0 then
|
||||
return true
|
||||
end
|
||||
if minetest.get_item_group(name, "cobble") > 0 then
|
||||
return true
|
||||
end
|
||||
if minetest.get_item_group(name, "gravel") > 0 then
|
||||
return true
|
||||
end
|
||||
if minetest.get_item_group(name, "sand") > 0 then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_entity("techage:ta2_weight_chest_entity", {
|
||||
initial_properties = {
|
||||
physical = true,
|
||||
pointable = false,
|
||||
collisionbox = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
|
||||
visual = "wielditem",
|
||||
textures = {"techage:ta2_weight_chest"},
|
||||
visual_size = {x=0.66, y=0.66, z=0.66},
|
||||
static_save = false,
|
||||
},
|
||||
})
|
||||
|
||||
local function allow_metadata_inventory_put(pos, listname, index, stack, player)
|
||||
if minetest.is_protected(pos, player:get_player_name()) then
|
||||
return 0
|
||||
end
|
||||
if not valid_weight_items(stack) then
|
||||
return 0
|
||||
end
|
||||
return stack:get_count()
|
||||
end
|
||||
|
||||
local function allow_metadata_inventory_take(pos, listname, index, stack, player)
|
||||
if minetest.is_protected(pos, player:get_player_name()) then
|
||||
return 0
|
||||
end
|
||||
return stack:get_count()
|
||||
end
|
||||
|
||||
local function can_dig(pos, player)
|
||||
if minetest.is_protected(pos, player:get_player_name()) then
|
||||
return false
|
||||
end
|
||||
local inv = minetest.get_meta(pos):get_inventory()
|
||||
return inv:is_empty("main")
|
||||
end
|
||||
|
||||
local function after_dig_node(pos, oldnode, oldmetadata, digger)
|
||||
techage.remove_node(pos, oldnode, oldmetadata)
|
||||
end
|
||||
|
||||
local function formspec()
|
||||
return "size[8,6.7]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
"list[context;main;1.5,0.2;5,2;]"..
|
||||
"list[current_player;main;0,3;8,4;]"..
|
||||
"listring[context;main]"..
|
||||
"listring[current_player;main]"
|
||||
end
|
||||
|
||||
minetest.register_node("techage:ta2_weight_chest", {
|
||||
description = S("TA2 Weight Chest"),
|
||||
tiles = {
|
||||
-- up, down, right, left, back, front
|
||||
"techage_filling_ta2.png^techage_frame_ta2.png^techage_weight_bottom.png",
|
||||
"techage_filling_ta2.png^techage_frame_ta2.png^techage_weight_bottom.png",
|
||||
"techage_filling_ta2.png^techage_frame_ta2.png^techage_appl_chest_back_ta3.png^techage_weight_side.png",
|
||||
"techage_filling_ta2.png^techage_frame_ta2.png^techage_appl_chest_back_ta3.png^techage_weight_side.png",
|
||||
"techage_filling_ta2.png^techage_frame_ta2.png^techage_appl_chest_back_ta3.png^techage_weight_side.png",
|
||||
"techage_filling_ta2.png^techage_frame_ta2.png^techage_appl_chest_back_ta3.png^techage_weight_side.png",
|
||||
},
|
||||
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size('main', 10)
|
||||
end,
|
||||
|
||||
after_place_node = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("formspec", formspec())
|
||||
end,
|
||||
|
||||
techage_set_numbers = function(pos, numbers, player_name)
|
||||
return techage.logic.set_numbers(pos, numbers, player_name, S("TA2 Weight Chest"))
|
||||
end,
|
||||
|
||||
can_dig = can_dig,
|
||||
after_dig_node = after_dig_node,
|
||||
allow_metadata_inventory_put = allow_metadata_inventory_put,
|
||||
allow_metadata_inventory_take = allow_metadata_inventory_take,
|
||||
|
||||
paramtype2 = "facedir",
|
||||
groups = {choppy=2, cracky=2, crumbly=2},
|
||||
is_ground_content = false,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "techage:ta2_weight_chest",
|
||||
recipe = {
|
||||
{"", "", ""},
|
||||
{"basic_materials:steel_strip", "techage:chest_ta2", "basic_materials:steel_strip"},
|
||||
{"", "", ""},
|
||||
},
|
||||
})
|
||||
|
181
ta2_energy_storage/ta2_winch.lua
Normal file
181
ta2_energy_storage/ta2_winch.lua
Normal file
@ -0,0 +1,181 @@
|
||||
--[[
|
||||
|
||||
TechAge
|
||||
=======
|
||||
|
||||
Copyright (C) 2019-2021 Joachim Stolberg
|
||||
|
||||
GPL v3
|
||||
See LICENSE.txt for more information
|
||||
|
||||
Winch for TA2 gravity-based energy storage
|
||||
|
||||
]]--
|
||||
|
||||
-- for lazy programmers
|
||||
local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end
|
||||
local S2P = minetest.string_to_pos
|
||||
local M = minetest.get_meta
|
||||
local S = techage.S
|
||||
|
||||
local MIN_LOAD = 99
|
||||
local MAX_ROPE_LEN = 10
|
||||
|
||||
local Axle = techage.Axle
|
||||
local power = networks.power
|
||||
|
||||
|
||||
local function chest_pos(pos)
|
||||
local pos1 = {x = pos.x, y = pos.y - 1, z = pos.z} -- start pos
|
||||
local pos2 = {x = pos.x, y = pos.y - 1 - MAX_ROPE_LEN, z = pos.z} -- end pos
|
||||
local _, pos3 = minetest.line_of_sight(pos1, pos2)
|
||||
return pos3 or pos2
|
||||
end
|
||||
|
||||
local function chest_load(nvm, pos)
|
||||
local amount = 0
|
||||
local inv = minetest.get_inventory({type = "node", pos = pos})
|
||||
nvm.stored_items = {}
|
||||
for i = 1, inv:get_size("main") do
|
||||
local stack = inv:get_stack("main", i)
|
||||
nvm.stored_items[i] = {name = stack:get_name(), count = stack:get_count()}
|
||||
amount = amount + stack:get_count()
|
||||
end
|
||||
return amount
|
||||
end
|
||||
|
||||
local function chest_full(pos)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
local pos1 = chest_pos(pos)
|
||||
local node = minetest.get_node(pos1)
|
||||
if node.name == "techage:ta2_weight_chest" then
|
||||
return chest_load(nvm, pos1) >= MIN_LOAD
|
||||
end
|
||||
end
|
||||
|
||||
-- Add chest node, remove chest entity instead
|
||||
local function add_chest(pos)
|
||||
local mem = techage.get_mem(pos)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
if mem.obj then
|
||||
mem.obj:remove()
|
||||
mem.obj = nil
|
||||
end
|
||||
if nvm.capa and nvm.capa >= MIN_LOAD then
|
||||
local pos1 = {x = pos.x, y = pos.y - (nvm.length or 1) - 1, z = pos.z}
|
||||
minetest.add_node(pos1, {name = "techage:ta2_weight_chest", param2 = 0})
|
||||
local ndef = minetest.registered_nodes["techage:ta2_weight_chest"]
|
||||
ndef.on_construct(pos1)
|
||||
ndef.after_place_node(pos1)
|
||||
local inv = minetest.get_inventory({type = "node", pos = pos1})
|
||||
for i, item in ipairs(nvm.stored_items or {}) do
|
||||
inv:set_stack("main", i, item)
|
||||
end
|
||||
end
|
||||
nvm.capa = 0
|
||||
end
|
||||
|
||||
-- Remove chest node, add rope and chest entity instead
|
||||
local function remove_chest(pos)
|
||||
local mem = techage.get_mem(pos)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
local pos1 = chest_pos(pos)
|
||||
local mass = chest_load(nvm, pos1)
|
||||
if mass > 0 then
|
||||
nvm.length = pos.y - pos1.y - 1
|
||||
nvm.capa = mass * nvm.length / MAX_ROPE_LEN
|
||||
minetest.remove_node(pos1)
|
||||
mem.obj = minetest.add_entity(pos1, "techage:ta2_weight_chest_entity")
|
||||
techage.renew_rope(pos, nvm.length)
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_node("techage:ta2_winch", {
|
||||
description = S("TA2 Winch"),
|
||||
tiles = {
|
||||
-- up, down, right, left, back, front
|
||||
"techage_filling_ta2.png^techage_appl_arrow2.png^techage_frame_ta2.png^[transformR270",
|
||||
"techage_filling_ta2.png^techage_appl_arrow2.png^techage_frame_ta2.png^techage_appl_winch_hole.png^[transformR270",
|
||||
"techage_filling_ta2.png^techage_axle_gearbox.png^techage_frame_ta2.png",
|
||||
"techage_filling_ta2.png^techage_appl_winch.png^techage_frame_ta2.png",
|
||||
"techage_filling_ta2.png^techage_appl_winch.png^techage_frame_ta2.png",
|
||||
"techage_filling_ta2.png^techage_appl_winch.png^techage_frame_ta2.png",
|
||||
},
|
||||
|
||||
after_place_node = function(pos, placer)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
local outdir = networks.side_to_outdir(pos, "R")
|
||||
M(pos):set_int("outdir", outdir)
|
||||
Axle:after_place_node(pos, {outdir})
|
||||
minetest.get_node_timer(pos):start(2)
|
||||
techage.renew_rope(pos, MAX_ROPE_LEN - 1)
|
||||
end,
|
||||
|
||||
on_timer = function(pos, elapsed)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
local mem = techage.get_mem(pos)
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
nvm.capa = nvm.capa or 1
|
||||
nvm.load = nvm.load or 0
|
||||
nvm.length = nvm.length or 1
|
||||
|
||||
if not nvm.running and power.power_available(pos, Axle, outdir) and chest_full(pos) then
|
||||
remove_chest(pos)
|
||||
power.start_storage_calc(pos, Axle, outdir)
|
||||
nvm.running = true
|
||||
elseif nvm.running and nvm.load == 0 and not power.power_available(pos, Axle, outdir) then
|
||||
add_chest(pos)
|
||||
power.start_storage_calc(pos, Axle, outdir)
|
||||
nvm.running = false
|
||||
end
|
||||
|
||||
if nvm.running then
|
||||
nvm.load = power.get_storage_load(pos, Axle, outdir, nvm.capa)
|
||||
if nvm.load then
|
||||
local length = nvm.length * (1 - nvm.load/nvm.capa)
|
||||
local y = pos.y - length - 1
|
||||
techage.renew_rope(pos, length, true)
|
||||
if mem.obj then
|
||||
mem.obj:remove()
|
||||
end
|
||||
mem.obj = minetest.add_entity({x = pos.x, y = y, z = pos.z}, "techage:ta2_weight_chest_entity")
|
||||
end
|
||||
end
|
||||
return true
|
||||
end,
|
||||
|
||||
after_dig_node = function(pos, oldnode, oldmetadata)
|
||||
add_chest(pos)
|
||||
local outdir = tonumber(oldmetadata.fields.outdir or 0)
|
||||
power.start_storage_calc(pos, Axle, outdir)
|
||||
Axle:after_dig_node(pos, {outdir})
|
||||
techage.del_mem(pos)
|
||||
end,
|
||||
|
||||
get_storage_data = function(pos, tlib2)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
nvm.load = nvm.load or 0
|
||||
nvm.capa = nvm.capa or 1
|
||||
if nvm.running then
|
||||
return {level = nvm.load / nvm.capa, capa = nvm.capa}
|
||||
end
|
||||
end,
|
||||
|
||||
paramtype2 = "facedir",
|
||||
groups = {choppy=2, cracky=2, crumbly=2},
|
||||
is_ground_content = false,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
})
|
||||
|
||||
power.register_nodes({"techage:ta2_winch"}, Axle, "sto", {"R"})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "techage:ta2_winch",
|
||||
recipe = {
|
||||
{"farming:string", "farming:string", "farming:string"},
|
||||
{"farming:string", "techage:gearbox", "farming:string"},
|
||||
{"farming:string", "farming:string", "farming:string"},
|
||||
},
|
||||
})
|
||||
|
@ -1,16 +0,0 @@
|
||||
import os, fnmatch
|
||||
|
||||
|
||||
print(">>> Convert")
|
||||
for filename in os.listdir("./"):
|
||||
if fnmatch.fnmatch(filename, "*.png"):
|
||||
print(filename)
|
||||
os.system("pngquant --skip-if-larger --quality=80 --strip --output ./%s.new ./%s" % (filename, filename))
|
||||
|
||||
print("\n>>> Copy")
|
||||
for filename in os.listdir("./"):
|
||||
if fnmatch.fnmatch(filename, "*.new"):
|
||||
print(filename)
|
||||
os.remove("./" + filename[:-4])
|
||||
os.rename("./" + filename, "./" + filename[:-4])
|
||||
|
BIN
textures/techage_appl_winch.png
Normal file
BIN
textures/techage_appl_winch.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 161 B |
BIN
textures/techage_appl_winch_hole.png
Normal file
BIN
textures/techage_appl_winch_hole.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 105 B |
Binary file not shown.
Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 270 B |
Binary file not shown.
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 254 B |
Loading…
Reference in New Issue
Block a user