2019-09-05 23:47:29 +03:00
|
|
|
--[[
|
|
|
|
|
|
|
|
TechAge
|
|
|
|
=======
|
|
|
|
|
2020-01-26 01:15:44 +03:00
|
|
|
Copyright (C) 2019-2020 Joachim Stolberg
|
2019-09-05 23:47:29 +03:00
|
|
|
|
2020-10-19 20:09:17 +03:00
|
|
|
AGPL v3
|
2019-09-05 23:47:29 +03:00
|
|
|
See LICENSE.txt for more information
|
2022-01-03 23:40:31 +03:00
|
|
|
|
2020-02-12 00:34:58 +03:00
|
|
|
TA2/TA3 Bucket based Liquid Sampler
|
2022-01-03 23:40:31 +03:00
|
|
|
|
2019-09-05 23:47:29 +03:00
|
|
|
]]--
|
|
|
|
|
|
|
|
-- for lazy programmers
|
|
|
|
local M = minetest.get_meta
|
|
|
|
-- 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-09-05 23:47:29 +03:00
|
|
|
|
|
|
|
local S = techage.S
|
|
|
|
|
2020-04-05 13:36:32 +03:00
|
|
|
local STANDBY_TICKS = 2
|
|
|
|
local COUNTDOWN_TICKS = 3
|
2019-09-05 23:47:29 +03:00
|
|
|
local CYCLE_TIME = 8
|
|
|
|
|
2020-01-26 01:15:44 +03:00
|
|
|
local function formspec(self, pos, nvm)
|
2019-09-05 23:47:29 +03:00
|
|
|
return "size[9,8.5]"..
|
|
|
|
default.gui_bg..
|
|
|
|
default.gui_bg_img..
|
|
|
|
default.gui_slots..
|
|
|
|
"list[context;src;0,0;1,4;]"..
|
|
|
|
"image[0,0;1,1;bucket.png]"..
|
2020-01-26 01:15:44 +03:00
|
|
|
"image[1,0;1,1;"..techage.get_power_image(pos, nvm).."]"..
|
2019-09-05 23:47:29 +03:00
|
|
|
"image[1,1.5;1,1;techage_form_arrow.png]"..
|
2020-01-26 01:15:44 +03:00
|
|
|
"image_button[1,3;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
|
|
|
|
"tooltip[1,3;1,1;"..self:get_state_tooltip(nvm).."]"..
|
2019-09-05 23:47:29 +03:00
|
|
|
"list[context;dst;2,0;7,4;]"..
|
|
|
|
"list[current_player;main;0.5,4.5;8,4;]"..
|
|
|
|
"listring[current_player;main]"..
|
|
|
|
"listring[context;src]" ..
|
|
|
|
"listring[current_player;main]"..
|
|
|
|
"listring[context;dst]" ..
|
|
|
|
"listring[current_player;main]"
|
|
|
|
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
|
|
|
|
if listname == "src" then
|
|
|
|
CRD(pos).State:start_if_standby(pos)
|
|
|
|
end
|
|
|
|
return stack:get_count()
|
|
|
|
end
|
|
|
|
|
|
|
|
local function allow_metadata_inventory_move(pos, from_list, from_index, to_list, to_index, count, player)
|
|
|
|
local inv = M(pos):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-24 22:59:26 +03:00
|
|
|
local function is_water(pos)
|
|
|
|
local node = minetest.get_node(pos)
|
|
|
|
local liquiddef = bucket.liquids[node.name]
|
|
|
|
if liquiddef ~= nil and liquiddef.itemname ~= nil and node.name == liquiddef.source then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-02-15 00:59:16 +03:00
|
|
|
local function can_start(pos, nvm, state)
|
|
|
|
local water_pos = minetest.string_to_pos(M(pos):get_string("water_pos"))
|
2020-02-24 22:59:26 +03:00
|
|
|
if not is_water(water_pos) then
|
2020-02-15 00:59:16 +03:00
|
|
|
return S("no usable water")
|
2019-09-05 23:47:29 +03:00
|
|
|
end
|
2020-02-15 00:59:16 +03:00
|
|
|
return true
|
2019-09-05 23:47:29 +03:00
|
|
|
end
|
|
|
|
|
2020-01-26 01:15:44 +03:00
|
|
|
local function sample_liquid(pos, crd, nvm, inv)
|
2020-02-15 00:59:16 +03:00
|
|
|
if inv:room_for_item("dst", {name = "bucket:bucket_water"}) and
|
|
|
|
inv:contains_item("src", {name = "bucket:bucket_empty"}) then
|
|
|
|
inv:remove_item("src", {name = "bucket:bucket_empty"})
|
|
|
|
inv:add_item("dst", {name = "bucket:bucket_water"})
|
|
|
|
crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS)
|
2019-09-05 23:47:29 +03:00
|
|
|
else
|
2020-02-15 00:59:16 +03:00
|
|
|
crd.State:idle(pos, nvm)
|
2019-09-05 23:47:29 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function keep_running(pos, elapsed)
|
|
|
|
--if tubelib.data_not_corrupted(pos) then
|
2020-01-26 01:15:44 +03:00
|
|
|
local nvm = techage.get_nvm(pos)
|
2022-01-03 23:40:31 +03:00
|
|
|
local crd = CRD(pos)
|
2019-09-05 23:47:29 +03:00
|
|
|
local inv = M(pos):get_inventory()
|
2020-01-26 01:15:44 +03:00
|
|
|
sample_liquid(pos, crd, nvm, inv)
|
2019-09-05 23:47:29 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
local function on_receive_fields(pos, formname, fields, player)
|
|
|
|
if minetest.is_protected(pos, player:get_player_name()) then
|
|
|
|
return
|
|
|
|
end
|
2020-01-26 01:15:44 +03:00
|
|
|
local nvm = techage.get_nvm(pos)
|
|
|
|
CRD(pos).State:state_button_event(pos, nvm, fields)
|
2019-09-05 23:47:29 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
local function can_dig(pos, player)
|
|
|
|
if minetest.is_protected(pos, player:get_player_name()) then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
local inv = M(pos):get_inventory()
|
|
|
|
return inv:is_empty("dst") and inv:is_empty("src")
|
|
|
|
end
|
|
|
|
|
|
|
|
local tiles = {}
|
|
|
|
-- '#' will be replaced by the stage number
|
|
|
|
-- '{power}' will be replaced by the power PNG
|
|
|
|
tiles.pas = {
|
|
|
|
-- up, down, right, left, back, front
|
2020-01-26 01:15:44 +03:00
|
|
|
"techage_filling_ta#.png^{power}^techage_frame_ta#_top.png",
|
2019-09-05 23:47:29 +03:00
|
|
|
"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_liquidsampler.png^techage_frame_ta#.png",
|
|
|
|
"techage_filling_ta#.png^techage_appl_liquidsampler.png^techage_frame_ta#.png",
|
|
|
|
}
|
|
|
|
tiles.act = {
|
|
|
|
-- up, down, right, left, back, front
|
2020-01-26 01:15:44 +03:00
|
|
|
"techage_filling_ta#.png^{power}^techage_frame_ta#_top.png",
|
2019-09-05 23:47:29 +03:00
|
|
|
"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",
|
|
|
|
{
|
|
|
|
image = "techage_filling4_ta#.png^techage_liquidsampler4.png^techage_frame4_ta#.png",
|
|
|
|
backface_culling = false,
|
|
|
|
animation = {
|
|
|
|
type = "vertical_frames",
|
|
|
|
aspect_w = 32,
|
|
|
|
aspect_h = 32,
|
|
|
|
length = 1.0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"techage_filling_ta#.png^techage_appl_liquidsampler.png^techage_frame_ta#.png",
|
|
|
|
}
|
|
|
|
|
|
|
|
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-09-05 23:47:29 +03:00
|
|
|
end
|
|
|
|
end,
|
|
|
|
on_push_item = function(pos, in_dir, stack)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
if meta:get_int("push_dir") == in_dir then
|
|
|
|
local inv = M(pos):get_inventory()
|
|
|
|
return techage.put_items(inv, "src", stack)
|
|
|
|
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,
|
|
|
|
on_recv_message = function(pos, src, topic, payload)
|
|
|
|
return CRD(pos).State:on_receive_message(pos, topic, payload)
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
|
2022-01-03 23:40:31 +03:00
|
|
|
local node_name_ta2, node_name_ta3, _ =
|
2019-09-05 23:47:29 +03:00
|
|
|
techage.register_consumer("liquidsampler", S("Liquid Sampler"), tiles, {
|
|
|
|
cycle_time = CYCLE_TIME,
|
|
|
|
standby_ticks = STANDBY_TICKS,
|
|
|
|
formspec = formspec,
|
|
|
|
tubing = tubing,
|
2020-02-15 00:59:16 +03:00
|
|
|
can_start = can_start,
|
2019-09-05 23:47:29 +03:00
|
|
|
after_place_node = function(pos, placer)
|
|
|
|
local inv = M(pos):get_inventory()
|
|
|
|
inv:set_size("src", 4)
|
|
|
|
inv:set_size("dst", 28)
|
|
|
|
local water_pos = techage.get_pos(pos, "B")
|
|
|
|
M(pos):set_string("water_pos", minetest.pos_to_string(water_pos))
|
|
|
|
end,
|
|
|
|
can_dig = can_dig,
|
|
|
|
node_timer = keep_running,
|
|
|
|
on_receive_fields = on_receive_fields,
|
|
|
|
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,2,4},
|
|
|
|
power_consumption = {0,3,5,8},
|
2020-01-26 01:15:44 +03:00
|
|
|
power_sides = {U=1},
|
2020-02-12 00:34:58 +03:00
|
|
|
},
|
|
|
|
{false, true, true, false}) -- TA2/A3
|
2019-09-05 23:47:29 +03:00
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
output = node_name_ta2,
|
|
|
|
recipe = {
|
|
|
|
{"group:wood", "default:mese_crystal", "group:wood"},
|
|
|
|
{"techage:tubeS", "bucket:bucket_empty", "techage:tubeS"},
|
|
|
|
{"group:wood", "techage:iron_ingot", "group:wood"},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
output = node_name_ta3,
|
|
|
|
recipe = {
|
|
|
|
{"", "default:mese_crystal", ""},
|
|
|
|
{"", node_name_ta2, ""},
|
|
|
|
{"", "techage:vacuum_tube", ""},
|
|
|
|
},
|
|
|
|
})
|