106 lines
3.2 KiB
Lua
106 lines
3.2 KiB
Lua
-- minetest.forceload_block(pos)
|
|
-- minetest.forceload_free_block(pos)
|
|
|
|
local set_teleport = function(itemstack, user, pointed_thing)
|
|
-- TODO
|
|
local pos = pointed_thing.under
|
|
local node = minetest.get_node(pos)
|
|
if (node.name ~= "maggems_landmark:home") then
|
|
minetest.log("action", "flower not attuned yet")
|
|
return
|
|
end
|
|
local meta = itemstack:get_meta()
|
|
local home = minetest.get_meta(pos)
|
|
pos.y = pos.y + 1
|
|
-- TODO: make sure there is air above
|
|
meta:set_string("maggems_landmark:home", minetest.serialize(pos))
|
|
meta:set_string("description", "TP Flower (to " .. home:get_string("maggems_landmark:name") .. ")")
|
|
return itemstack
|
|
end
|
|
|
|
local teleport = function(itemstack, user, pointed_thing)
|
|
-- TODO: this better
|
|
local pos = minetest.deserialize(itemstack:get_meta():get_string("maggems_landmark:home"))
|
|
if (minetest.get_node(pos).name ~= "maggems_teleport:flower") then
|
|
minetest.log("warning", "expected TP flower, got " .. minetest.get_node(pos).name)
|
|
return ""
|
|
end
|
|
user:set_pos(pos)
|
|
minetest.remove_node(pos)
|
|
minetest.forceload_free_block(pos)
|
|
return ""
|
|
end
|
|
|
|
minetest.register_node("maggems_teleport:flower", {
|
|
description = "TP Flower",
|
|
drawtype = "plantlike",
|
|
waving = 0,
|
|
tiles = {{
|
|
name = "maggems_teleport_flower_animated.png",
|
|
animation = {
|
|
type = "vertical_frames",
|
|
aspect_w = 16,
|
|
aspect_h = 16,
|
|
length = 1.0,
|
|
}
|
|
}},
|
|
inventory_image = "maggems_teleport_flower.png",
|
|
wield_image = "maggems_teleport_flower.png",
|
|
sunlight_propagates = true,
|
|
paramtype = "light",
|
|
light_source = 2,
|
|
walkable = false,
|
|
buildable_to = false,
|
|
groups = {attached_node = 1, flower = 1},
|
|
-- sounds = default.node_sound_leaves_defaults(),
|
|
selection_box = {
|
|
type = "fixed",
|
|
fixed = {-2 / 16, -0.5, -2 / 16, 2 / 16, 2 / 16, 2 / 16}
|
|
},
|
|
stack_max = 1,
|
|
on_place = function(itemstack, placer, pointed_thing)
|
|
-- only place if attuned
|
|
local meta = itemstack:get_meta()
|
|
if (meta:get("maggems_landmark:home") == nil) then
|
|
return set_teleport(itemstack, placer, pointed_thing)
|
|
end
|
|
return minetest.item_place(itemstack, placer, pointed_thing)
|
|
end,
|
|
node_placement_prediction = "",
|
|
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
|
-- add metadata
|
|
local meta = itemstack:get_meta()
|
|
placer:set_pos(minetest.deserialize(meta:get_string("maggems_landmark:home")))
|
|
itemstack:replace("maggems_teleport:flower_active")
|
|
meta = itemstack:get_meta()
|
|
-- TODO: this properly
|
|
meta:set_string("maggems_landmark:home", minetest.serialize(pos))
|
|
minetest.forceload_block(pos)
|
|
return true
|
|
end,
|
|
after_destruct = function(pos, oldnode)
|
|
minetest.forceload_free_block(pos)
|
|
end,
|
|
})
|
|
|
|
minetest.register_tool("maggems_teleport:flower_active", {
|
|
description = "TP Flower (Active)",
|
|
inventory_image = "maggems_teleport_flower_active.png",
|
|
wield_image = "maggems_teleport_flower_active.png",
|
|
-- groups = {attached_node = 1, flower = 1},
|
|
-- sounds = default.node_sound_leaves_defaults(),
|
|
stack_max = 1,
|
|
on_place = teleport,
|
|
on_secondary_use = teleport,
|
|
})
|
|
|
|
minetest.register_craft({
|
|
output = 'maggems_teleport:flower',
|
|
recipe = {
|
|
{"", 'maggems:misi_crystal', ""},
|
|
{"maggems:misi_crystal",'default:mese_crystal_fragment',"maggems:misi_crystal"},
|
|
{"", 'default:stick', ""},
|
|
}
|
|
})
|
|
|