Fix door controller bugs & add item source test block
This commit is contained in:
parent
b46b422a5a
commit
29aacdd579
@ -54,6 +54,7 @@ local function chat(player, text)
|
||||
end
|
||||
|
||||
local function postload_area(pos)
|
||||
minetest.log("warning", "[FLB] area "..P2S(pos).." not loaded!")
|
||||
if not minetest.forceload_block(pos, true) then
|
||||
minetest.after(60, postload_area, pos)
|
||||
end
|
||||
|
100
basic_machines/itemsource.lua
Normal file
100
basic_machines/itemsource.lua
Normal file
@ -0,0 +1,100 @@
|
||||
--[[
|
||||
|
||||
TechAge
|
||||
=======
|
||||
|
||||
Copyright (C) 2019-2020 Joachim Stolberg
|
||||
|
||||
AGPL v3
|
||||
See LICENSE.txt for more information
|
||||
|
||||
Item Source Block
|
||||
]]--
|
||||
|
||||
-- for lazy programmers
|
||||
local M = minetest.get_meta
|
||||
local S = techage.S
|
||||
|
||||
local CYCLE_TIME = 30
|
||||
|
||||
local function formspec()
|
||||
return "size[8,7.2]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
"list[context;main;3.5,0.8;1,1;]"..
|
||||
"list[current_player;main;0,3.5;8,4;]"..
|
||||
"listring[context;main]"..
|
||||
"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
|
||||
|
||||
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
|
||||
|
||||
minetest.register_node("techage:itemsource", {
|
||||
description = "Techage Item Source",
|
||||
tiles = {
|
||||
-- up, down, right, left, back, front
|
||||
"techage_filling_ta3.png^techage_frame_ta3_top.png^techage_appl_arrow.png",
|
||||
"techage_filling_ta3.png^techage_frame_ta3.png",
|
||||
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_outp.png",
|
||||
"techage_filling_ta3.png^techage_frame_ta3.png",
|
||||
"techage_filling_ta3.png^techage_appl_nodedetector.png^techage_frame_ta3.png",
|
||||
"techage_filling_ta3.png^techage_appl_nodedetector.png^techage_frame_ta3.png",
|
||||
},
|
||||
|
||||
after_place_node = function(pos, placer)
|
||||
local meta = M(pos)
|
||||
local node = minetest.get_node(pos)
|
||||
meta:set_int("push_dir", techage.side_to_outdir("R", node.param2))
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size('main', 1)
|
||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||
meta:set_string("infotext", "Techage Item Source")
|
||||
meta:set_string("formspec", formspec())
|
||||
end,
|
||||
|
||||
on_timer = function(pos, elapsed)
|
||||
local meta = M(pos)
|
||||
local inv = meta:get_inventory()
|
||||
local stack = inv:get_stack('main', 1)
|
||||
if stack:get_count() > 0 then
|
||||
local push_dir = meta:get_int("push_dir")
|
||||
if techage.push_items(pos, push_dir, stack) then
|
||||
local cnt = meta:get_int("counter") + stack:get_count()
|
||||
meta:set_int("counter", cnt)
|
||||
meta:set_string("infotext", "Techage Item Source: "..cnt)
|
||||
end
|
||||
end
|
||||
return true
|
||||
end,
|
||||
|
||||
allow_metadata_inventory_put = allow_metadata_inventory_put,
|
||||
allow_metadata_inventory_take = allow_metadata_inventory_take,
|
||||
|
||||
paramtype2 = "facedir", -- important!
|
||||
on_rotate = screwdriver.disallow, -- important!
|
||||
is_ground_content = false,
|
||||
drop = "",
|
||||
groups = {crumbly = 3, cracky = 3, snappy = 3},
|
||||
sounds = default.node_sound_glass_defaults(),
|
||||
})
|
||||
|
||||
techage.register_node({"techage:itemsource"}, {
|
||||
on_node_load = function(pos)
|
||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||
end,
|
||||
})
|
1
init.lua
1
init.lua
@ -159,6 +159,7 @@ dofile(MP.."/basic_machines/liquidsampler.lua")
|
||||
dofile(MP.."/basic_machines/quarry.lua")
|
||||
dofile(MP.."/basic_machines/ta4_chest.lua")
|
||||
dofile(MP.."/basic_machines/ta4_injector.lua")
|
||||
dofile(MP.."/basic_machines/itemsource.lua")
|
||||
|
||||
-- Liquids II
|
||||
dofile(MP.."/liquids/tank.lua")
|
||||
|
@ -143,7 +143,8 @@ local function show_nodes(pos)
|
||||
local param2 = param2_list[idx]
|
||||
if pos and param2 and name ~= "" then
|
||||
if not minetest.is_protected(pos, owner) then
|
||||
if name ~= "air" then
|
||||
local node = minetest.get_node(pos)
|
||||
if node.name == "air" then
|
||||
minetest.add_node(pos, {name = name, param2 = param2})
|
||||
end
|
||||
res = true
|
||||
@ -174,12 +175,15 @@ local function hide_nodes(pos)
|
||||
if pos then
|
||||
if not minetest.is_protected(pos, owner) then
|
||||
local node = minetest.get_node_or_nil(pos)
|
||||
if node then
|
||||
local meta = minetest.get_meta(pos)
|
||||
if node and (not meta or not next((meta:to_table()).fields)) then
|
||||
minetest.remove_node(pos)
|
||||
if node.name ~= "air" then
|
||||
item_list[idx] = ItemStack({name = node.name, count = 1})
|
||||
param2_list[idx] = node.param2
|
||||
end
|
||||
else
|
||||
item_list[idx] = ItemStack({name = "air", count = 1})
|
||||
item_list[idx] = nil
|
||||
param2_list[idx] = 0
|
||||
end
|
||||
res = true
|
||||
@ -256,7 +260,7 @@ minetest.register_node("techage:ta3_doorcontroller2", {
|
||||
meta:set_string("status", S("Blocks are back"))
|
||||
meta:set_string("formspec", formspec1(meta))
|
||||
local name = player:get_player_name()
|
||||
MarkedNodes[name] = {}
|
||||
MarkedNodes[name] = nil
|
||||
end
|
||||
elseif fields.hide then
|
||||
if hide_nodes(pos) then
|
||||
@ -264,7 +268,7 @@ minetest.register_node("techage:ta3_doorcontroller2", {
|
||||
meta:set_string("status", S("Blocks are disappeared"))
|
||||
meta:set_string("formspec", formspec1(meta))
|
||||
local name = player:get_player_name()
|
||||
MarkedNodes[name] = {}
|
||||
MarkedNodes[name] = nil
|
||||
end
|
||||
end
|
||||
end,
|
||||
|
Loading…
Reference in New Issue
Block a user