Translocators

This commit is contained in:
Duane 2016-06-27 05:00:16 -05:00
parent 02337a1187
commit fbcd651651
4 changed files with 110 additions and 2 deletions

View file

@ -40,7 +40,7 @@ local function goblin_do(self)
fun_caves.search_replace(pos, dig_freq, diggable, 'air') fun_caves.search_replace(pos, dig_freq, diggable, 'air')
end end
fun_caves.search_replace(pos, dig_freq * 2, burnable, 'fire:basic_flame') fun_caves.search_replace(pos, dig_freq * 3, burnable, 'fire:basic_flame')
-- steal torches -- steal torches
fun_caves.search_replace(self.object:getpos(), torch_freq, {"default:torch"}, "air") fun_caves.search_replace(self.object:getpos(), torch_freq, {"default:torch"}, "air")

View file

@ -38,7 +38,7 @@ end
if not fun_caves.db then if not fun_caves.db then
fun_caves.db = {} fun_caves.db = {}
end end
for _, i in pairs({'teleport_data', 'hunger', 'armor_expire'}) do for _, i in pairs({'teleport_data', 'hunger', 'armor_expire', 'translocators'}) do
if not fun_caves.db[i] then if not fun_caves.db[i] then
fun_caves.db[i] = {} fun_caves.db[i] = {}
end end

View file

@ -321,3 +321,110 @@ minetest.register_craft({
} }
}) })
local function translocate(pos, node, clicker, itemstack, pointed_thing)
local meta = minetest.get_meta(pos)
local id = meta:get_string('id')
local pair = fun_caves.db.translocators[tonumber(id)]
if #pair < 2 then
return
end
local pos2
if minetest.serialize(pair[2]) == minetest.serialize(pos) then
pos2 = table.copy(pair[1])
else
pos2 = table.copy(pair[2])
end
pos2.y = pos2.y + 1
clicker:setpos(pos2)
end
local function trans_use(itemstack, user, pointed_thing)
if not itemstack then
return
end
local data = minetest.deserialize(itemstack:get_metadata())
local player_name = user:get_player_name()
minetest.chat_send_player(player_name, "You see a serial number: "..data.id)
end
local function trans_place(itemstack, placer, pointed_thing)
if not (itemstack and pointed_thing) then
return
end
local data = minetest.deserialize(itemstack:get_metadata())
local pos = pointed_thing.above
local pair = fun_caves.db.translocators[tonumber(data.id)]
if #pair > 1 then
print('* Fun Caves: high error in translocator storage')
end
pair[#pair+1] = pos
local ret = minetest.item_place_node(itemstack, placer, pointed_thing)
local meta = minetest.get_meta(pos)
meta:set_string('id', data.id)
return ret
end
local function trans_dig(pos, node, digger)
if not (pos and digger) then
return
end
-------------------------------------
-- This needs to check for protection.
-------------------------------------
local meta = minetest.get_meta(pos)
local id = meta:get_string('id')
local data = { id = id }
local pair = fun_caves.db.translocators[tonumber(data.id)]
if #pair < 1 then
print('* Fun Caves: low error in translocator storage')
end
print(minetest.serialize(pair[1]), minetest.serialize(pos))
local inv = digger:get_inventory()
local item = ItemStack(node.name)
local data_str = minetest.serialize(data)
item:set_metadata(data_str)
inv:add_item('main', item)
minetest.remove_node(pos)
if #pair > 1 and minetest.serialize(pair[2]) == minetest.serialize(pos) then
table.remove(pair, 2)
else
table.remove(pair, 1)
end
end
newnode = fun_caves.clone_node("default:steelblock")
newnode.description = "Translocator Pair"
newnode.on_rightclick = translocate
newnode.on_use = trans_use
newnode.on_place = trans_place
newnode.on_dig = trans_dig
newnode.stack_max = 1
newnode.groups = {cracky = 3, oddly_breakable_by_hand = 3}
minetest.register_node("fun_caves:translocator", newnode)
for _, gem in pairs(gems) do
print(dump(gem))
minetest.register_craft({
output = 'fun_caves:translocator 2',
type = 'shapeless',
recipe = {
'fun_caves:'..gem.lower,
'default:mese_crystal',
'default:steelblock',
}
})
end
minetest.register_on_craft(function(itemstack, player, old_craft_grid, craft_inv)
if itemstack:get_name() ~= "fun_caves:translocator" then
return
end
data = {}
data.id = string.format('%d', #fun_caves.db.translocators+1)
fun_caves.db.translocators[#fun_caves.db.translocators+1] = {}
local data_str = minetest.serialize(data)
itemstack:set_metadata(data_str)
end)

View file

@ -18,6 +18,7 @@ local default_material = {
{"fun_caves:stone_with_lichen","default_stone", "Stone", {cracky = 3, not_in_creative_inventory=1}, "default:cobble"}, {"fun_caves:stone_with_lichen","default_stone", "Stone", {cracky = 3, not_in_creative_inventory=1}, "default:cobble"},
{"fun_caves:stone_with_algae","default_stone", "Stone", {cracky = 3, not_in_creative_inventory=1}, "default:cobble"}, {"fun_caves:stone_with_algae","default_stone", "Stone", {cracky = 3, not_in_creative_inventory=1}, "default:cobble"},
{"fun_caves:stone_with_moss","default_stone", "Stone", {cracky = 3, not_in_creative_inventory=1}, "default:cobble"}, {"fun_caves:stone_with_moss","default_stone", "Stone", {cracky = 3, not_in_creative_inventory=1}, "default:cobble"},
{"default:mossycobble","default_stone", "Stone", {cracky = 3, not_in_creative_inventory=1}, "default:cobble"},
{"fun_caves:stone_with_salt","caverealms_salty2", "Stone", {cracky = 3, not_in_creative_inventory=1}, "fun_caves:stone_with_salt"}, {"fun_caves:stone_with_salt","caverealms_salty2", "Stone", {cracky = 3, not_in_creative_inventory=1}, "fun_caves:stone_with_salt"},
} }