diff --git a/basic_machines/chest.lua b/basic_machines/chest.lua index bb447aa..8f9b2be 100644 --- a/basic_machines/chest.lua +++ b/basic_machines/chest.lua @@ -38,7 +38,7 @@ local function send_off_command(pos) local dest_num = meta:get_string("dest_num") local own_num = meta:get_string("number") local owner = meta:get_string("owner") - techage.send_message(dest_num, owner, nil, "off", own_num) + techage.send_multi(dest_num, owner, nil, "off", own_num) end @@ -48,7 +48,7 @@ local function send_command(pos) if dest_num ~= "" then local own_num = meta:get_string("number") local owner = meta:get_string("owner") - techage.send_message(dest_num, owner, nil, "on", own_num) + techage.send_multi(dest_num, owner, nil, "on", own_num) minetest.after(1, send_off_command, pos) end end diff --git a/basic_machines/forceload.lua b/basic_machines/forceload.lua index cc05167..cee6fa8 100644 --- a/basic_machines/forceload.lua +++ b/basic_machines/forceload.lua @@ -55,7 +55,9 @@ end local function add_pos(pos, player) local lPos = minetest.deserialize(player:get_attribute("techage_forceload_blocks")) or {} - if not in_list(lPos, pos) and #lPos < techage.max_num_forceload_blocks then + if not in_list(lPos, pos) and (#lPos < techage.max_num_forceload_blocks or + creative and creative.is_enabled_for and + creative.is_enabled_for(player:get_player_name())) then lPos[#lPos+1] = pos player:set_attribute("techage_forceload_blocks", minetest.serialize(lPos)) return true diff --git a/init.lua b/init.lua index 46dae34..ddf9f31 100644 --- a/init.lua +++ b/init.lua @@ -119,6 +119,7 @@ else dofile(MP.."/oil/explore.lua") dofile(MP.."/oil/tower.lua") dofile(MP.."/oil/drillbox.lua") + dofile(MP.."/oil/pumpjack.lua") --dofile(MP.."/test/generator.lua") diff --git a/oil/drillbox.lua b/oil/drillbox.lua index fb9b641..6666224 100644 --- a/oil/drillbox.lua +++ b/oil/drillbox.lua @@ -35,6 +35,7 @@ local formspec0 = "size[5,4]".. "button_exit[1,3.2;3,1;build;"..I("Build Tower").."]" local function play_sound(pos) + local mem = tubelib2.get_mem(pos) mem.handle = minetest.sound_play("techage_oildrill", { pos = pos, gain = 1, @@ -207,9 +208,16 @@ tiles.pas = { "techage_filling_ta#.png^techage_appl_oildrill.png^techage_frame_ta#.png", "techage_filling_ta#.png^techage_appl_oildrill.png^techage_frame_ta#.png", } - tiles.act = tiles.pas -tiles.def = tiles.pas +tiles.def = { + -- up, down, right, left, back, front + "techage_filling_ta#.png^techage_frame_ta#_top.png", + "techage_filling_ta#.png^techage_frame_ta#.png", + "techage_filling_ta#.png^techage_frame_ta#.png^techage_appl_outp.png^techage_appl_defect.png", + "techage_filling_ta#.png^techage_frame_ta#.png^techage_appl_inp.png^techage_appl_defect.png", + "techage_filling_ta#.png^techage_appl_oildrill.png^techage_frame_ta#.png^techage_appl_defect.png", + "techage_filling_ta#.png^techage_appl_oildrill.png^techage_frame_ta#.png^techage_appl_defect.png", +} local tubing = { on_pull_item = function(pos, in_dir, num) @@ -249,7 +257,7 @@ local tubing = { end, } -local node_name_ta2, node_name_ta3, node_name_ta4 = +local _, node_name_ta3, _ = techage.register_consumer("drillbox", I("Oil Drill Box"), tiles, { drawtype = "normal", cycle_time = CYCLE_TIME, @@ -258,6 +266,7 @@ local node_name_ta2, node_name_ta3, node_name_ta4 = aging_factor = 10, formspec = formspec, tubing = tubing, + on_state_change = on_node_state_change, after_place_node = function(pos, placer) local inv = M(pos):get_inventory() inv:set_size("src", 1) @@ -292,7 +301,7 @@ minetest.register_craft({ recipe = { {"default:steel_ingot", "default:diamond", "default:steel_ingot"}, {"techage:tubeS", "basic_materials:gear_steel", "techage:tubeS"}, - {"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"}, + {"default:steel_ingot", "techage:vacuum_tube", "default:steel_ingot"}, }, }) diff --git a/oil/explore.lua b/oil/explore.lua index 906ef8c..46114d1 100644 --- a/oil/explore.lua +++ b/oil/explore.lua @@ -268,7 +268,6 @@ minetest.register_node("techage:oil_source", { liquid_alternative_source = "techage:oil_source", liquid_viscosity = 20, liquid_range = 10, - damage_per_second = 1, post_effect_color = {a = 200, r = 1, g = 1, b = 1}, groups = {liquid = 5}, }) @@ -315,7 +314,6 @@ minetest.register_node("techage:oil_flowing", { liquid_alternative_source = "techage:oil_source", liquid_viscosity = 20, liquid_range = 10, - damage_per_second = 1, post_effect_color = {a = 200, r = 1, g = 1, b = 1}, groups = {liquid = 5, not_in_creative_inventory = 1}, }) @@ -350,11 +348,22 @@ techage.explore = {} function techage.explore.get_oil_info(pos) local amount = 0 local depth = DEPTH_MIN + local posC while amount == 0 and depth < DEPTH_MAX do depth = depth + DEPTH_STEP - local posC = {x = center(pos.x), y = center(-depth), z = center(pos.z)} + posC = {x = center(pos.x), y = center(-depth), z = center(pos.z)} amount = get_oil_amount(posC) end - return {depth = center(depth) - 1 + pos.y, amount = amount} + return {depth = center(depth) - 1 + pos.y, amount = amount, storage_pos = posC} end +function techage.explore.get_oil_amount(posC) + return M(posC):get_int("oil_amount") +end + +function techage.explore.dec_oil_amount(posC) + local meta = M(posC) + local amount = meta:get_int("oil_amount") + meta:set_int("oil_amount", amount-1) + return amount-1 +end diff --git a/oil/pumpjack.lua b/oil/pumpjack.lua new file mode 100644 index 0000000..1f270b9 --- /dev/null +++ b/oil/pumpjack.lua @@ -0,0 +1,181 @@ +--[[ + + TechAge + ======= + + Copyright (C) 2019 Joachim Stolberg + + LGPLv2.1+ + See LICENSE.txt for more information + + TA3 Pumpjack + +]]-- + +-- for lazy programmers +local S = function(pos) if pos then return minetest.pos_to_string(pos) end end +local P = minetest.string_to_pos +local M = minetest.get_meta +-- Consumer Related Data +local CRD = function(pos) return (minetest.registered_nodes[minetest.get_node(pos).name] or {}).consumer end +local CRDN = function(node) return (minetest.registered_nodes[node.name] or {}).consumer end +-- Load support for intllib. +local MP = minetest.get_modpath("techage") +local I,_ = dofile(MP.."/intllib.lua") + +local STANDBY_TICKS = 10 +local COUNTDOWN_TICKS = 10 +local CYCLE_TIME = 8 + +local function has_oil_item(pos, meta) + local storage_pos = meta:get_string("storage_pos") + if storage_pos ~= "" then + local amount = techage.explore.get_oil_amount(P(storage_pos)) + if amount > 0 then + return ItemStack("techage:oil_source") + end + end +end + +local function dec_oil_item(pos, meta) + local storage_pos = meta:get_string("storage_pos") + if storage_pos ~= "" then + techage.explore.dec_oil_amount(P(storage_pos)) + end +end + +local function pumping(pos, crd, meta, mem) + local items = has_oil_item(pos, meta) + if items ~= nil then + if techage.push_items(pos, 6, items) ~= true then + crd.State:blocked(pos, mem) + return + end + dec_oil_item(pos, meta) + crd.State:keep_running(pos, mem, COUNTDOWN_TICKS) + return + end + crd.State:fault(pos, mem) +end + +local function keep_running(pos, elapsed) + local mem = tubelib2.get_mem(pos) + local crd = CRD(pos) + pumping(pos, crd, M(pos), mem) + return crd.State:is_active(mem) +end + +local function on_rightclick(pos, node, clicker) + local mem = tubelib2.get_mem(pos) + if not minetest.is_protected(pos, clicker:get_player_name()) then + if CRD(pos).State:get_state(mem) == techage.STOPPED then + CRD(pos).State:start(pos, mem) + else + CRD(pos).State:stop(pos, mem) + end + end +end + +local tiles = {} +-- '#' will be replaced by the stage number +-- '{power}' will be replaced by the power PNG +tiles.pas = { + "techage_filling_ta#.png^techage_frame_ta#.png^techage_appl_outp.png", + "techage_filling_ta#.png^techage_frame_ta#.png^techage_appl_inp.png", + "techage_appl_pumpjack.png^techage_frame_ta#.png", + "techage_appl_pumpjack.png^techage_frame_ta#.png", + "techage_filling_ta#.png^techage_frame_ta#_top.png^techage_appl_arrow.png^[transformR90]", + "techage_filling_ta#.png^techage_frame_ta#_top.png^techage_appl_arrow.png^[transformR90]", +} +tiles.act = { + -- up, down, right, left, back, front + "techage_filling_ta#.png^techage_frame_ta#.png^techage_appl_outp.png", + "techage_filling_ta#.png^techage_frame_ta#.png^techage_appl_inp.png", + { + image = "techage_appl_pumpjack14.png^techage_frame14_ta#.png", + backface_culling = false, + animation = { + type = "vertical_frames", + aspect_w = 32, + aspect_h = 32, + length = 2.0, + }, + }, + { + image = "techage_appl_pumpjack14.png^techage_frame14_ta#.png", + backface_culling = false, + animation = { + type = "vertical_frames", + aspect_w = 32, + aspect_h = 32, + length = 2.0, + }, + }, + "techage_filling_ta#.png^techage_frame_ta#_top.png^techage_appl_arrow.png^[transformR90]", + "techage_filling_ta#.png^techage_frame_ta#_top.png^techage_appl_arrow.png^[transformR90]", +} +tiles.def = { + -- up, down, right, left, back, front + "techage_filling_ta#.png^techage_frame_ta#.png^techage_appl_outp.png", + "techage_filling_ta#.png^techage_frame_ta#.png^techage_appl_inp.png", + "techage_appl_pumpjack.png^techage_frame_ta#.png^techage_appl_defect.png", + "techage_appl_pumpjack.png^techage_frame_ta#.png^techage_appl_defect.png", + "techage_filling_ta#.png^techage_frame_ta#.png^techage_appl_defect.png", + "techage_filling_ta#.png^techage_frame_ta#.png^techage_appl_defect.png", +} + +local tubing = { + is_pusher = true, -- is a pulling/pushing node + + on_recv_message = function(pos, topic, payload) + local resp = CRD(pos).State:on_receive_message(pos, topic, payload) + if resp then + return resp + else + return "unsupported" + end + end, + on_node_load = function(pos) + CRD(pos).State:on_node_load(pos) + end, + on_node_repair = function(pos) + return CRD(pos).State:on_node_repair(pos) + end, +} + +local _, node_name_ta3, _ = + techage.register_consumer("pumpjack", I("TA3 Oil Pumpjack"), tiles, { + cycle_time = CYCLE_TIME, + standby_ticks = STANDBY_TICKS, + has_item_meter = true, + aging_factor = 10, + tubing = tubing, + after_place_node = function(pos, placer) + local node = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}) + if node.name == "techage:oil_drillbit2" then + local info = techage.explore.get_oil_info(pos) + if info then + M(pos):set_string("storage_pos", S(info.storage_pos)) + end + end + end, + on_rightclick = on_rightclick, + node_timer = keep_running, + on_rotate = screwdriver.disallow, + + groups = {choppy=2, cracky=2, crumbly=2}, + is_ground_content = false, + sounds = default.node_sound_wood_defaults(), + num_items = {0,1,1,1}, + power_consumption = {0,20,20,20}, + }, + {false, false, true, false}) -- TA3 only + +minetest.register_craft({ + output = "techage:ta3_pumpjack_pas", + recipe = { + {"", "techage:baborium_ingot", ""}, + {"dye:red", "techage:ta3_pusher_pas", "dye:red"}, + {"", "techage:oil_drillbit", ""}, + }, +}) diff --git a/textures/techage_appl_pumpjack.png b/textures/techage_appl_pumpjack.png new file mode 100644 index 0000000..e561bec Binary files /dev/null and b/textures/techage_appl_pumpjack.png differ diff --git a/textures/techage_appl_pumpjack14.png b/textures/techage_appl_pumpjack14.png new file mode 100644 index 0000000..bf2fa8f Binary files /dev/null and b/textures/techage_appl_pumpjack14.png differ diff --git a/tools/repairkit.lua b/tools/repairkit.lua index ac3936e..ab4e904 100644 --- a/tools/repairkit.lua +++ b/tools/repairkit.lua @@ -43,9 +43,9 @@ local function read_state(itemstack, user, pointed_thing) if pos then local number = techage.get_node_number(pos) if number then - local state = techage.send_request(number, "state", nil) - local counter = techage.send_request(number, "counter", nil) - local aging = techage.send_request(number, "aging", nil) + local state = techage.send_single(number, "state", nil) + local counter = techage.send_single(number, "counter", nil) + local aging = techage.send_single(number, "aging", nil) if state and counter and aging then if type(counter) ~= "number" then counter = "unknown" end minetest.chat_send_player(user:get_player_name(), "[TechAge] state ="..state..", counter = "..counter..", aging = "..aging)