2019-06-08 23:57:01 +03:00
|
|
|
--[[
|
|
|
|
|
|
|
|
TechAge
|
|
|
|
=======
|
|
|
|
|
2020-02-02 00:00:58 +03:00
|
|
|
Copyright (C) 2019-2020 Joachim Stolberg
|
2019-06-08 23:57:01 +03:00
|
|
|
|
2020-10-19 20:09:17 +03:00
|
|
|
AGPL v3
|
2019-06-08 23:57:01 +03:00
|
|
|
See LICENSE.txt for more information
|
|
|
|
|
|
|
|
TA3 Oil Drill Box
|
|
|
|
|
|
|
|
]]--
|
|
|
|
|
|
|
|
-- for lazy programmers
|
|
|
|
local M = minetest.get_meta
|
2019-07-02 22:33:12 +03:00
|
|
|
local S = techage.S
|
|
|
|
|
2019-06-08 23:57:01 +03:00
|
|
|
-- Consumer Related Data
|
2019-10-07 01:09:39 +03:00
|
|
|
local CRD = function(pos) return (minetest.registered_nodes[techage.get_node_lvm(pos).name] or {}).consumer end
|
2019-06-08 23:57:01 +03:00
|
|
|
|
2020-04-05 13:36:32 +03:00
|
|
|
local STANDBY_TICKS = 2
|
|
|
|
local COUNTDOWN_TICKS = 4
|
2020-03-31 19:27:15 +03:00
|
|
|
local CYCLE_TIME = 16
|
2019-06-08 23:57:01 +03:00
|
|
|
|
|
|
|
local formspec0 = "size[5,4]"..
|
|
|
|
default.gui_bg..
|
|
|
|
default.gui_bg_img..
|
|
|
|
default.gui_slots..
|
2019-09-28 20:40:49 +03:00
|
|
|
"image[1,0;3.4,3.4;techage_ta3.png]"..
|
2019-07-02 22:33:12 +03:00
|
|
|
"button_exit[1,3.2;3,1;build;"..S("Build derrick").."]"
|
2019-06-08 23:57:01 +03:00
|
|
|
|
|
|
|
local function play_sound(pos)
|
2020-02-02 00:00:58 +03:00
|
|
|
local mem = techage.get_mem(pos)
|
|
|
|
if not mem.handle or mem.handle == -1 then
|
|
|
|
mem.handle = minetest.sound_play("techage_oildrill", {
|
2019-06-09 22:24:39 +03:00
|
|
|
pos = pos,
|
|
|
|
gain = 1,
|
2020-02-02 00:00:58 +03:00
|
|
|
max_hear_distance = 15,
|
|
|
|
loop = true})
|
|
|
|
if mem.handle == -1 then
|
|
|
|
minetest.after(1, play_sound, pos)
|
|
|
|
end
|
2019-06-09 22:24:39 +03:00
|
|
|
end
|
2019-06-08 23:57:01 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
local function stop_sound(pos)
|
2020-02-02 00:00:58 +03:00
|
|
|
local mem = techage.get_mem(pos)
|
|
|
|
if mem.handle then
|
|
|
|
minetest.sound_stop(mem.handle)
|
|
|
|
mem.handle = nil
|
2019-06-08 23:57:01 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-01-31 21:55:10 +03:00
|
|
|
local function formspec(self, pos, nvm)
|
|
|
|
if not nvm.assemble_build then
|
2019-06-08 23:57:01 +03:00
|
|
|
return formspec0
|
|
|
|
end
|
2020-04-02 21:38:14 +03:00
|
|
|
local depth = M(pos):get_int("depth")
|
2020-01-31 21:55:10 +03:00
|
|
|
local curr_depth = pos.y - (nvm.drill_pos or pos).y
|
2019-06-08 23:57:01 +03:00
|
|
|
return "size[8,8]"..
|
|
|
|
default.gui_bg..
|
|
|
|
default.gui_bg_img..
|
|
|
|
default.gui_slots..
|
|
|
|
"list[context;src;1,1;1,1;]"..
|
|
|
|
"label[1.3,0.5;IN]"..
|
|
|
|
"item_image[1,1;1,1;techage:oil_drillbit]"..
|
2019-07-02 22:33:12 +03:00
|
|
|
"label[1,2;"..S("Drill Bit").."]"..
|
|
|
|
"label[0.5,3;"..S("Depth")..": "..curr_depth.."/"..depth.."]"..
|
2020-01-31 21:55:10 +03:00
|
|
|
"image[3.5,0;1,1;"..techage.get_power_image(pos, nvm).."]"..
|
2019-06-08 23:57:01 +03:00
|
|
|
"image[3.5,1;1,1;techage_form_arrow.png]"..
|
2020-01-31 21:55:10 +03:00
|
|
|
"image_button[3.5,2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
|
2020-03-29 23:07:05 +03:00
|
|
|
"tooltip[3.5,2;1,1;"..self:get_state_tooltip(nvm).."]"..
|
2019-06-08 23:57:01 +03:00
|
|
|
"label[6.2,0.5;OUT]"..
|
|
|
|
"list[context;dst;6,1;1,1;]"..
|
2019-07-02 22:33:12 +03:00
|
|
|
"button_exit[5,3;3,1;remove;"..S("Remove derrick").."]"..
|
2019-06-08 23:57:01 +03:00
|
|
|
"list[current_player;main;0,4;8,4;]"..
|
|
|
|
"listring[context;dst]"..
|
|
|
|
"listring[current_player;main]"..
|
|
|
|
"listring[context;src]"..
|
|
|
|
"listring[current_player;main]"..
|
|
|
|
default.get_hotbar_bg(0, 4)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function allow_metadata_inventory_put(pos, listname, index, stack, player)
|
|
|
|
if minetest.is_protected(pos, player:get_player_name()) then
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
local crd = CRD(pos)
|
|
|
|
if listname == "src" then
|
|
|
|
crd.State:start_if_standby(pos)
|
|
|
|
return stack:get_count()
|
|
|
|
end
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
|
|
|
|
local function allow_metadata_inventory_move(pos, from_list, from_index, to_list, to_index, count, player)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
local stack = inv:get_stack(from_list, from_index)
|
|
|
|
return allow_metadata_inventory_put(pos, to_list, to_index, stack, player)
|
|
|
|
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
|
|
|
|
|
2020-02-02 00:00:58 +03:00
|
|
|
local function on_rightclick(pos, node, clicker)
|
2020-01-31 21:55:10 +03:00
|
|
|
local nvm = techage.get_nvm(pos)
|
2020-02-02 00:00:58 +03:00
|
|
|
techage.set_activeformspec(pos, clicker)
|
2020-01-31 21:55:10 +03:00
|
|
|
M(pos):set_string("formspec", formspec(CRD(pos).State, pos, nvm))
|
2019-06-08 23:57:01 +03:00
|
|
|
end
|
|
|
|
|
2019-06-09 16:02:17 +03:00
|
|
|
local function on_node_state_change(pos, old_state, new_state)
|
|
|
|
if new_state == techage.RUNNING then
|
|
|
|
play_sound(pos)
|
|
|
|
else
|
|
|
|
stop_sound(pos)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-01-31 21:55:10 +03:00
|
|
|
local function drilling(pos, crd, nvm, inv)
|
|
|
|
M(pos):set_string("formspec", formspec(CRD(pos).State, pos, nvm))
|
|
|
|
nvm.drill_pos = nvm.drill_pos or {x=pos.x, y=pos.y-1, z=pos.z}
|
2019-06-09 01:25:25 +03:00
|
|
|
local owner = M(pos):get_string("owner")
|
|
|
|
local depth = M(pos):get_int("depth")
|
2020-01-31 21:55:10 +03:00
|
|
|
local curr_depth = pos.y - (nvm.drill_pos or pos).y
|
|
|
|
local node = techage.get_node_lvm(nvm.drill_pos)
|
2019-06-09 22:24:39 +03:00
|
|
|
local ndef = minetest.registered_nodes[node.name]
|
2019-06-09 01:25:25 +03:00
|
|
|
|
|
|
|
if not inv:contains_item("src", ItemStack("techage:oil_drillbit")) then
|
2020-02-02 00:00:58 +03:00
|
|
|
crd.State:idle(pos, nvm, S("Drill bits missing"))
|
2019-06-09 01:25:25 +03:00
|
|
|
elseif curr_depth >= depth then
|
2020-04-02 21:38:14 +03:00
|
|
|
M(pos):set_string("oil_found", "true")
|
|
|
|
crd.State:stop(pos, nvm)
|
2020-03-29 23:07:05 +03:00
|
|
|
elseif node.name == "techage:oilstorage" then -- old oil bubble node?
|
|
|
|
nvm.drill_pos.y = nvm.drill_pos.y-1
|
|
|
|
crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS)
|
2020-01-31 21:55:10 +03:00
|
|
|
elseif minetest.is_protected(nvm.drill_pos, owner) then
|
2020-02-02 00:00:58 +03:00
|
|
|
crd.State:fault(pos, nvm, S("Drill area is protected"))
|
2019-06-09 01:25:25 +03:00
|
|
|
elseif node.name == "techage:oil_drillbit2" then
|
2020-01-31 21:55:10 +03:00
|
|
|
nvm.drill_pos.y = nvm.drill_pos.y-1
|
|
|
|
crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS)
|
2019-08-01 23:31:43 +03:00
|
|
|
elseif minetest.get_item_group(node.name, "lava") >= 1 then
|
2020-01-31 21:55:10 +03:00
|
|
|
minetest.swap_node(nvm.drill_pos, {name = "techage:oil_drillbit2"})
|
2019-08-01 23:31:43 +03:00
|
|
|
inv:remove_item("src", ItemStack("techage:oil_drillbit"))
|
2020-01-31 21:55:10 +03:00
|
|
|
nvm.drill_pos.y = nvm.drill_pos.y-1
|
|
|
|
crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS)
|
2019-06-09 22:24:39 +03:00
|
|
|
elseif techage.can_node_dig(node, ndef) then
|
|
|
|
local drop_name = techage.dropped_node(node, ndef)
|
|
|
|
if drop_name then
|
|
|
|
local item = ItemStack(drop_name)
|
|
|
|
if not inv:room_for_item("dst", item) then
|
2020-03-29 23:07:05 +03:00
|
|
|
crd.State:blocked(pos, nvm, S("item output blocked"))
|
2019-06-09 22:24:39 +03:00
|
|
|
return
|
|
|
|
end
|
2019-06-09 01:25:25 +03:00
|
|
|
inv:add_item("dst", item)
|
2019-06-08 23:57:01 +03:00
|
|
|
end
|
2020-01-31 21:55:10 +03:00
|
|
|
minetest.swap_node(nvm.drill_pos, {name = "techage:oil_drillbit2"})
|
2019-06-09 01:25:25 +03:00
|
|
|
inv:remove_item("src", ItemStack("techage:oil_drillbit"))
|
2020-01-31 21:55:10 +03:00
|
|
|
nvm.drill_pos.y = nvm.drill_pos.y-1
|
|
|
|
crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS)
|
2020-03-29 23:07:05 +03:00
|
|
|
elseif node.name == "ignore" then
|
|
|
|
-- load world and pause the drilling for one step
|
|
|
|
minetest.emerge_area(nvm.drill_pos, nvm.drill_pos)
|
2019-06-08 23:57:01 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function keep_running(pos, elapsed)
|
2020-01-31 21:55:10 +03:00
|
|
|
local nvm = techage.get_nvm(pos)
|
2019-06-08 23:57:01 +03:00
|
|
|
local crd = CRD(pos)
|
|
|
|
local inv = M(pos):get_inventory()
|
|
|
|
if inv then
|
2020-01-31 21:55:10 +03:00
|
|
|
drilling(pos, crd, nvm, inv)
|
2019-06-08 23:57:01 +03:00
|
|
|
end
|
2020-02-02 00:00:58 +03:00
|
|
|
if techage.is_activeformspec(pos) then
|
|
|
|
M(pos):set_string("formspec", formspec(crd.State, pos, nvm))
|
|
|
|
end
|
2019-06-08 23:57:01 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
local function can_dig(pos, player)
|
|
|
|
if minetest.is_protected(pos, player:get_player_name()) then
|
|
|
|
return false
|
|
|
|
end
|
2020-01-31 21:55:10 +03:00
|
|
|
local nvm = techage.get_nvm(pos)
|
|
|
|
if nvm.assemble_locked or nvm.assemble_build then
|
2019-06-08 23:57:01 +03:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
local inv = M(pos):get_inventory()
|
|
|
|
return inv:is_empty("dst") and inv:is_empty("src")
|
|
|
|
end
|
|
|
|
|
|
|
|
local function on_receive_fields(pos, formname, fields, player)
|
|
|
|
if minetest.is_protected(pos, player:get_player_name()) then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if fields.build then
|
|
|
|
techage.oiltower.build(pos, player:get_player_name())
|
2019-06-09 16:02:17 +03:00
|
|
|
elseif fields.remove then
|
2019-06-08 23:57:01 +03:00
|
|
|
local inv = M(pos):get_inventory()
|
|
|
|
if inv:is_empty("dst") and inv:is_empty("src") then
|
|
|
|
techage.oiltower.remove(pos, player:get_player_name())
|
|
|
|
end
|
|
|
|
else
|
2020-01-31 21:55:10 +03:00
|
|
|
local nvm = techage.get_nvm(pos)
|
|
|
|
if not nvm.assemble_locked and M(pos):get_string("oil_found") ~= "true" then
|
2020-02-02 00:00:58 +03:00
|
|
|
local nvm = techage.get_nvm(pos)
|
2020-01-31 21:55:10 +03:00
|
|
|
CRD(pos).State:state_button_event(pos, nvm, fields)
|
2019-06-08 23:57:01 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local tiles = {}
|
|
|
|
-- '#' will be replaced by the stage number
|
|
|
|
tiles.pas = {
|
|
|
|
-- 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_filling_ta#.png^techage_frame_ta#.png^techage_appl_inp.png",
|
|
|
|
"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
|
|
|
|
|
|
|
|
local tubing = {
|
|
|
|
on_pull_item = function(pos, in_dir, num)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
if meta:get_int("pull_dir") == in_dir then
|
|
|
|
local inv = M(pos):get_inventory()
|
2020-04-13 14:20:38 +03:00
|
|
|
return techage.get_items(pos, inv, "dst", num)
|
2019-06-08 23:57:01 +03:00
|
|
|
end
|
|
|
|
end,
|
|
|
|
on_push_item = function(pos, in_dir, stack)
|
2020-03-31 19:27:15 +03:00
|
|
|
local nvm = techage.get_nvm(pos)
|
|
|
|
if not nvm.assemble_locked then
|
|
|
|
local meta = minetest.get_meta(pos)
|
2021-06-09 23:09:59 +03:00
|
|
|
if meta:get_int("push_dir") == in_dir then
|
2020-03-31 19:27:15 +03:00
|
|
|
local inv = M(pos):get_inventory()
|
|
|
|
CRD(pos).State:start_if_standby(pos)
|
|
|
|
return techage.put_items(inv, "src", stack)
|
|
|
|
end
|
2019-06-08 23:57:01 +03:00
|
|
|
end
|
|
|
|
end,
|
|
|
|
on_unpull_item = function(pos, in_dir, stack)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
if meta:get_int("pull_dir") == in_dir then
|
|
|
|
local inv = M(pos):get_inventory()
|
|
|
|
return techage.put_items(inv, "dst", stack)
|
|
|
|
end
|
|
|
|
end,
|
2019-08-25 19:08:30 +03:00
|
|
|
on_recv_message = function(pos, src, topic, payload)
|
2020-02-28 23:27:52 +03:00
|
|
|
return CRD(pos).State:on_receive_message(pos, topic, payload)
|
2019-06-08 23:57:01 +03:00
|
|
|
end,
|
2020-02-02 00:00:58 +03:00
|
|
|
on_node_load = function(pos, node)
|
2019-06-08 23:57:01 +03:00
|
|
|
CRD(pos).State:on_node_load(pos)
|
2020-02-02 00:00:58 +03:00
|
|
|
local nvm = techage.get_nvm(pos)
|
2020-03-29 23:07:05 +03:00
|
|
|
nvm.assemble_locked = false
|
2020-02-02 00:00:58 +03:00
|
|
|
if nvm.techage_state == techage.RUNNING then
|
|
|
|
play_sound(pos)
|
|
|
|
end
|
2019-06-08 23:57:01 +03:00
|
|
|
end,
|
|
|
|
}
|
|
|
|
|
2019-06-09 18:20:40 +03:00
|
|
|
local _, node_name_ta3, _ =
|
2019-08-26 23:19:59 +03:00
|
|
|
techage.register_consumer("drillbox", S("Oil Drill Box"), tiles, {
|
2019-06-08 23:57:01 +03:00
|
|
|
drawtype = "normal",
|
|
|
|
cycle_time = CYCLE_TIME,
|
|
|
|
standby_ticks = STANDBY_TICKS,
|
|
|
|
formspec = formspec,
|
|
|
|
tubing = tubing,
|
2019-06-09 18:20:40 +03:00
|
|
|
on_state_change = on_node_state_change,
|
2019-06-08 23:57:01 +03:00
|
|
|
after_place_node = function(pos, placer)
|
|
|
|
local inv = M(pos):get_inventory()
|
|
|
|
inv:set_size("src", 1)
|
|
|
|
inv:set_size("dst", 1)
|
|
|
|
local info = techage.explore.get_oil_info(pos)
|
2020-04-02 21:38:14 +03:00
|
|
|
M(pos):set_int("depth", info.depth - 5) -- oil bubble
|
2019-06-08 23:57:01 +03:00
|
|
|
M(pos):set_int("amount", info.amount)
|
|
|
|
M(pos):set_string("oil_found", "false")
|
2019-06-09 02:43:16 +03:00
|
|
|
M(pos):set_string("owner", placer:get_player_name())
|
2019-06-08 23:57:01 +03:00
|
|
|
end,
|
|
|
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
|
|
|
if oldmetadata.fields.oil_found == "true" then
|
|
|
|
minetest.set_node(pos, {name = "techage:oil_source"})
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
can_dig = can_dig,
|
|
|
|
node_timer = keep_running,
|
|
|
|
on_receive_fields = on_receive_fields,
|
|
|
|
on_rightclick = on_rightclick,
|
|
|
|
allow_metadata_inventory_put = allow_metadata_inventory_put,
|
|
|
|
allow_metadata_inventory_move = allow_metadata_inventory_move,
|
|
|
|
allow_metadata_inventory_take = allow_metadata_inventory_take,
|
|
|
|
groups = {choppy=2, cracky=2, crumbly=2},
|
|
|
|
sounds = default.node_sound_wood_defaults(),
|
|
|
|
num_items = {0,1,1,1},
|
|
|
|
power_consumption = {0,10,16,24},
|
2021-06-09 23:09:59 +03:00
|
|
|
tube_sides = {L=1, R=1},
|
2019-06-09 16:02:17 +03:00
|
|
|
},
|
|
|
|
{false, false, true, false}) -- TA3 only
|
2019-06-08 23:57:01 +03:00
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
output = node_name_ta3,
|
|
|
|
recipe = {
|
|
|
|
{"default:steel_ingot", "default:diamond", "default:steel_ingot"},
|
|
|
|
{"techage:tubeS", "basic_materials:gear_steel", "techage:tubeS"},
|
2019-06-09 18:20:40 +03:00
|
|
|
{"default:steel_ingot", "techage:vacuum_tube", "default:steel_ingot"},
|
2019-06-08 23:57:01 +03:00
|
|
|
},
|
|
|
|
})
|