techage/test/test.lua

96 lines
2.6 KiB
Lua
Raw Normal View History

2019-03-02 14:24:48 +03:00
-- 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
2019-05-11 02:21:03 +03:00
local function determine_water_dir(pos)
local pos1 = {x=pos.x+1, y=pos.y+1, z=pos.z}
local pos2 = {x=pos.x-1, y=pos.y+1, z=pos.z}
local pos3 = {x=pos.x, y=pos.y+1, z=pos.z+1}
local pos4 = {x=pos.x, y=pos.y+1, z=pos.z-1}
local node1 = minetest.get_node(pos1)
local node2 = minetest.get_node(pos2)
local node3 = minetest.get_node(pos3)
local node4 = minetest.get_node(pos4)
if node1.name == "default:water_flowing" and node2.name == "default:water_flowing" then
if node1.param2 > node2.param2 then
return 4
elseif node1.param2 < node2.param2 then
return 2
end
elseif node3.name == "default:water_flowing" and node4.name == "default:water_flowing" then
if node3.param2 > node4.param2 then
return 3
elseif node3.param2 < node4.param2 then
return 1
end
2019-03-02 14:24:48 +03:00
end
2019-05-11 02:21:03 +03:00
return 0
2019-03-02 14:24:48 +03:00
end
2019-05-11 02:21:03 +03:00
local function remove(obj)
obj:remove()
2019-03-04 00:19:30 +03:00
end
2019-05-11 02:21:03 +03:00
local function velocity(obj, dir)
obj:set_velocity(vector.multiply(tubelib2.Dir6dToVector[dir], 0.3))
minetest.after(10, remove, obj)
end
2019-03-02 14:24:48 +03:00
2019-05-11 02:21:03 +03:00
local function node_timer(pos, elapsed)
local node = minetest.get_node(techage.get_pos(pos, 'U'))
local obj = minetest.add_item({x=pos.x, y=pos.y+1, z=pos.z}, ItemStack("default:gold_lump"))
minetest.after(0.8, velocity, obj, M(pos):get_int("water_dir"))
return true
2019-03-08 01:12:07 +03:00
end
2019-05-11 02:21:03 +03:00
minetest.register_node("techage:rinser", {
description = "TechAge Rinser",
2019-03-02 14:24:48 +03:00
tiles = {
-- up, down, right, left, back, front
2019-05-11 02:21:03 +03:00
{
image = "techage_appl_sieve4_top.png^techage_frame4_ta2_top.png",
backface_culling = false,
animation = {
type = "vertical_frames",
aspect_w = 32,
aspect_h = 32,
length = 2.0,
},
},
2019-03-02 14:24:48 +03:00
'techage_electric_button.png',
},
paramtype2 = "facedir",
2019-05-11 02:21:03 +03:00
groups = {cracky=2, crumbly=2, choppy=2},
on_rotate = screwdriver.disallow,
2019-03-02 14:24:48 +03:00
is_ground_content = false,
2019-05-11 02:21:03 +03:00
after_place_node = function(pos, placer)
minetest.get_node_timer(pos):start(5)
local dir = determine_water_dir(pos)
M(pos):set_int("water_dir", dir)
end,
2019-03-02 14:24:48 +03:00
2019-05-11 02:21:03 +03:00
on_timer = node_timer,
2019-03-02 14:24:48 +03:00
})
2019-05-11 02:21:03 +03:00
local function remove_objects(pos)
for _, object in pairs(minetest.get_objects_inside_radius(pos, 1)) do
local lua_entity = object:get_luaentity()
if not object:is_player() and lua_entity and lua_entity.name == "__builtin:item" then
object:remove()
end
2019-03-08 01:12:07 +03:00
end
end
2019-05-11 02:21:03 +03:00
minetest.register_lbm({
label = "[techage] Rinser update",
name = "techage:update",
nodenames = {"techage:rinser"},
run_at_every_load = true,
action = function(pos, node)
remove_objects({x=pos.x, y=pos.y+1, z=pos.z})
end
2019-03-08 01:12:07 +03:00
})