From fbcd651651f4d1988dfeaa1d916aec6596920ae8 Mon Sep 17 00:00:00 2001 From: Duane Date: Mon, 27 Jun 2016 05:00:16 -0500 Subject: [PATCH] Translocators --- goblin.lua | 2 +- init.lua | 2 +- tesseract.lua | 107 +++++++++++++++++++++++++++++++++++++++++++++++++ wallhammer.lua | 1 + 4 files changed, 110 insertions(+), 2 deletions(-) diff --git a/goblin.lua b/goblin.lua index cd0aef4..f1f82d6 100644 --- a/goblin.lua +++ b/goblin.lua @@ -40,7 +40,7 @@ local function goblin_do(self) fun_caves.search_replace(pos, dig_freq, diggable, 'air') 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 fun_caves.search_replace(self.object:getpos(), torch_freq, {"default:torch"}, "air") diff --git a/init.lua b/init.lua index 7e5cc38..0dd2166 100644 --- a/init.lua +++ b/init.lua @@ -38,7 +38,7 @@ end if not fun_caves.db then fun_caves.db = {} 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 fun_caves.db[i] = {} end diff --git a/tesseract.lua b/tesseract.lua index 28e22c2..8cb69b2 100644 --- a/tesseract.lua +++ b/tesseract.lua @@ -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) diff --git a/wallhammer.lua b/wallhammer.lua index 6c01246..d8614e1 100644 --- a/wallhammer.lua +++ b/wallhammer.lua @@ -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_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"}, + {"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"}, }