2018-08-08 11:37:27 +02:00
|
|
|
--[[
|
|
|
|
|
|
|
|
Tubelib Addons 3
|
|
|
|
================
|
|
|
|
|
2020-11-20 14:45:28 +01:00
|
|
|
Copyright (C) 2017-2020 Joachim Stolberg
|
2018-08-08 11:37:27 +02:00
|
|
|
|
2020-11-20 14:45:28 +01:00
|
|
|
AGPL v3
|
2018-08-08 11:37:27 +02:00
|
|
|
See LICENSE.txt for more information
|
|
|
|
|
|
|
|
pusher.lua
|
|
|
|
|
|
|
|
A high performance pusher
|
|
|
|
|
|
|
|
]]--
|
|
|
|
|
2020-11-03 20:19:38 +01:00
|
|
|
-- Load support for I18n
|
|
|
|
local S = tubelib_addons3.S
|
|
|
|
|
2018-12-22 16:58:11 +01:00
|
|
|
-- for lazy programmers
|
|
|
|
local P = minetest.string_to_pos
|
|
|
|
local M = minetest.get_meta
|
|
|
|
|
|
|
|
local STANDBY_TICKS = 5
|
|
|
|
local COUNTDOWN_TICKS = 5
|
|
|
|
local CYCLE_TIME = 2
|
|
|
|
|
|
|
|
local State = tubelib.NodeStates:new({
|
|
|
|
node_name_passive = "tubelib_addons3:pusher",
|
|
|
|
node_name_active = "tubelib_addons3:pusher_active",
|
|
|
|
node_name_defect = "tubelib_addons3:pusher_defect",
|
2020-11-03 20:19:38 +01:00
|
|
|
infotext_name = S("HighPerf Pusher"),
|
2018-12-22 16:58:11 +01:00
|
|
|
cycle_time = CYCLE_TIME,
|
|
|
|
standby_ticks = STANDBY_TICKS,
|
|
|
|
has_item_meter = true,
|
2019-01-01 18:53:17 +01:00
|
|
|
aging_factor = 50,
|
2018-12-22 16:58:11 +01:00
|
|
|
})
|
2018-08-08 11:37:27 +02:00
|
|
|
|
2018-12-22 16:58:11 +01:00
|
|
|
local function pushing(pos, meta)
|
2018-08-08 11:37:27 +02:00
|
|
|
local player_name = meta:get_string("player_name")
|
|
|
|
local items = tubelib.pull_stack(pos, "L", player_name)
|
|
|
|
if items ~= nil then
|
|
|
|
if tubelib.push_items(pos, "R", items, player_name) == false then
|
|
|
|
-- place item back
|
|
|
|
tubelib.unpull_items(pos, "L", items, player_name)
|
2018-12-22 16:58:11 +01:00
|
|
|
State:blocked(pos, meta)
|
|
|
|
return
|
2018-08-08 11:37:27 +02:00
|
|
|
end
|
2019-01-01 18:53:17 +01:00
|
|
|
State:keep_running(pos, meta, COUNTDOWN_TICKS, 1)
|
2018-12-22 16:58:11 +01:00
|
|
|
return
|
2018-08-08 11:37:27 +02:00
|
|
|
end
|
2018-12-22 16:58:11 +01:00
|
|
|
State:idle(pos, meta)
|
2018-08-08 11:37:27 +02:00
|
|
|
end
|
|
|
|
|
2018-12-22 16:58:11 +01:00
|
|
|
local function keep_running(pos, elapsed)
|
2019-04-23 21:46:08 +02:00
|
|
|
if tubelib.data_not_corrupted(pos) then
|
|
|
|
local meta = M(pos)
|
|
|
|
pushing(pos, meta)
|
|
|
|
return State:is_active(meta)
|
|
|
|
end
|
|
|
|
return false
|
2018-12-22 16:58:11 +01:00
|
|
|
end
|
|
|
|
|
2018-08-08 11:37:27 +02:00
|
|
|
minetest.register_node("tubelib_addons3:pusher", {
|
2020-11-03 20:19:38 +01:00
|
|
|
description = S("HighPerf Pusher"),
|
2018-08-08 11:37:27 +02:00
|
|
|
tiles = {
|
|
|
|
-- up, down, right, left, back, front
|
|
|
|
'tubelib_pusher1.png^tubelib_addons3_node_frame4.png',
|
|
|
|
'tubelib_pusher1.png^tubelib_addons3_node_frame4.png',
|
|
|
|
'tubelib_outp.png^tubelib_addons3_node_frame4.png',
|
|
|
|
'tubelib_inp.png^tubelib_addons3_node_frame4.png',
|
|
|
|
"tubelib_pusher1.png^[transformR180]^tubelib_addons3_node_frame4.png^[transformR180]",
|
|
|
|
"tubelib_pusher1.png^tubelib_addons3_node_frame4.png",
|
|
|
|
},
|
|
|
|
|
|
|
|
after_place_node = function(pos, placer)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_string("player_name", placer:get_player_name())
|
|
|
|
local number = tubelib.add_node(pos, "tubelib_addons3:pusher")
|
2018-12-22 16:58:11 +01:00
|
|
|
State:node_init(pos, number)
|
2018-08-08 11:37:27 +02:00
|
|
|
end,
|
|
|
|
|
|
|
|
on_rightclick = function(pos, node, clicker)
|
|
|
|
if not minetest.is_protected(pos, clicker:get_player_name()) then
|
2018-12-22 16:58:11 +01:00
|
|
|
State:start(pos, M(pos))
|
2018-08-08 11:37:27 +02:00
|
|
|
end
|
|
|
|
end,
|
|
|
|
|
2020-08-12 20:15:26 +02:00
|
|
|
on_dig = function(pos, node, player)
|
|
|
|
State:on_dig_node(pos, node, player)
|
2018-08-08 11:37:27 +02:00
|
|
|
tubelib.remove_node(pos)
|
|
|
|
end,
|
|
|
|
|
|
|
|
on_timer = keep_running,
|
|
|
|
on_rotate = screwdriver.disallow,
|
|
|
|
|
|
|
|
paramtype = "light",
|
|
|
|
sunlight_propagates = true,
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
groups = {choppy=2, cracky=2, crumbly=2},
|
|
|
|
is_ground_content = false,
|
|
|
|
sounds = default.node_sound_wood_defaults(),
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
minetest.register_node("tubelib_addons3:pusher_active", {
|
2020-11-03 20:19:38 +01:00
|
|
|
description = S("HighPerf Pusher"),
|
2018-08-08 11:37:27 +02:00
|
|
|
tiles = {
|
|
|
|
-- up, down, right, left, back, front
|
|
|
|
{
|
|
|
|
image = "tubelib_addons3_pusher_active.png",
|
|
|
|
backface_culling = false,
|
|
|
|
animation = {
|
|
|
|
type = "vertical_frames",
|
|
|
|
aspect_w = 32,
|
|
|
|
aspect_h = 32,
|
|
|
|
length = 2.0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
image = "tubelib_addons3_pusher_active.png",
|
|
|
|
backface_culling = false,
|
|
|
|
animation = {
|
|
|
|
type = "vertical_frames",
|
|
|
|
aspect_w = 32,
|
|
|
|
aspect_h = 32,
|
|
|
|
length = 2.0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'tubelib_outp.png^tubelib_addons3_node_frame4.png',
|
|
|
|
'tubelib_inp.png^tubelib_addons3_node_frame4.png',
|
|
|
|
{
|
|
|
|
image = "tubelib_addons3_pusher_active.png^[transformR180]",
|
|
|
|
backface_culling = false,
|
|
|
|
animation = {
|
|
|
|
type = "vertical_frames",
|
|
|
|
aspect_w = 32,
|
|
|
|
aspect_h = 32,
|
|
|
|
length = 2.0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
image = "tubelib_addons3_pusher_active.png",
|
|
|
|
backface_culling = false,
|
|
|
|
animation = {
|
|
|
|
type = "vertical_frames",
|
|
|
|
aspect_w = 32,
|
|
|
|
aspect_h = 32,
|
|
|
|
length = 2.0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
on_rightclick = function(pos, node, clicker)
|
|
|
|
if not minetest.is_protected(pos, clicker:get_player_name()) then
|
2018-12-22 16:58:11 +01:00
|
|
|
State:stop(pos, M(pos))
|
2018-08-08 11:37:27 +02:00
|
|
|
end
|
|
|
|
end,
|
|
|
|
|
|
|
|
on_timer = keep_running,
|
|
|
|
on_rotate = screwdriver.disallow,
|
2021-01-17 22:47:23 +01:00
|
|
|
|
|
|
|
diggable = false,
|
|
|
|
can_dig = function() return false end,
|
|
|
|
|
2018-08-08 11:37:27 +02:00
|
|
|
paramtype = "light",
|
|
|
|
sunlight_propagates = true,
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
groups = {crumbly=0, not_in_creative_inventory=1},
|
|
|
|
is_ground_content = false,
|
|
|
|
sounds = default.node_sound_wood_defaults(),
|
|
|
|
})
|
|
|
|
|
2018-12-22 16:58:11 +01:00
|
|
|
minetest.register_node("tubelib_addons3:pusher_defect", {
|
2020-11-03 20:19:38 +01:00
|
|
|
description = S("HighPerf Pusher"),
|
2018-12-22 16:58:11 +01:00
|
|
|
tiles = {
|
|
|
|
-- up, down, right, left, back, front
|
|
|
|
'tubelib_pusher1.png^tubelib_addons3_node_frame4.png',
|
|
|
|
'tubelib_pusher1.png^tubelib_addons3_node_frame4.png',
|
|
|
|
'tubelib_outp.png^tubelib_addons3_node_frame4.png^tubelib_defect.png',
|
|
|
|
'tubelib_inp.png^tubelib_addons3_node_frame4.png^tubelib_defect.png',
|
|
|
|
"tubelib_pusher1.png^[transformR180]^tubelib_addons3_node_frame4.png^[transformR180]^tubelib_defect.png",
|
|
|
|
"tubelib_pusher1.png^tubelib_addons3_node_frame4.png^tubelib_defect.png",
|
|
|
|
},
|
|
|
|
|
|
|
|
after_place_node = function(pos, placer)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_string("player_name", placer:get_player_name())
|
|
|
|
local number = tubelib.add_node(pos, "tubelib_addons3:pusher")
|
|
|
|
State:node_init(pos, number)
|
|
|
|
State:defect(pos, meta)
|
|
|
|
end,
|
|
|
|
|
|
|
|
after_dig_node = function(pos)
|
|
|
|
tubelib.remove_node(pos)
|
|
|
|
end,
|
|
|
|
|
|
|
|
on_timer = keep_running,
|
|
|
|
on_rotate = screwdriver.disallow,
|
|
|
|
|
|
|
|
paramtype = "light",
|
|
|
|
sunlight_propagates = true,
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
groups = {choppy=2, cracky=2, crumbly=2, not_in_creative_inventory=1},
|
|
|
|
is_ground_content = false,
|
|
|
|
sounds = default.node_sound_wood_defaults(),
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2018-08-08 11:37:27 +02:00
|
|
|
minetest.register_craft({
|
|
|
|
output = "tubelib_addons3:pusher",
|
|
|
|
recipe = {
|
|
|
|
{"default:tin_ingot", "tubelib:pusher", ""},
|
|
|
|
{"tubelib:pusher", "default:gold_ingot", ""},
|
|
|
|
{"", "", ""},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-12-22 16:58:11 +01:00
|
|
|
tubelib.register_node("tubelib_addons3:pusher",
|
|
|
|
{"tubelib_addons3:pusher_active", "tubelib_addons3:pusher_defect"}, {
|
2018-08-08 11:37:27 +02:00
|
|
|
is_pusher = true, -- is a pulling/pushing node
|
2021-01-23 18:41:09 +01:00
|
|
|
valid_sides = {"R","L"},
|
2018-08-08 11:37:27 +02:00
|
|
|
|
|
|
|
on_recv_message = function(pos, topic, payload)
|
2018-12-22 16:58:11 +01:00
|
|
|
local resp = State:on_receive_message(pos, topic, payload)
|
|
|
|
if resp then
|
|
|
|
return resp
|
2018-08-08 11:37:27 +02:00
|
|
|
else
|
2018-12-22 16:58:11 +01:00
|
|
|
return "unsupported"
|
2018-08-08 11:37:27 +02:00
|
|
|
end
|
|
|
|
end,
|
2018-12-22 16:58:11 +01:00
|
|
|
on_node_load = function(pos)
|
|
|
|
State:on_node_load(pos)
|
|
|
|
end,
|
|
|
|
on_node_repair = function(pos)
|
|
|
|
return State:on_node_repair(pos)
|
|
|
|
end,
|
2018-08-08 11:37:27 +02:00
|
|
|
})
|