From a5c10e33999e859d97db28ef64c9a75648c60419 Mon Sep 17 00:00:00 2001 From: sys4-fr Date: Wed, 5 Dec 2018 21:56:40 +0100 Subject: [PATCH] =?UTF-8?q?Ajout=20du=20support=20de=20treasurer=20pour=20?= =?UTF-8?q?les=20coffres=20des=20=C3=A9paves?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- seawrecks/depends.txt | 3 +- seawrecks/init.lua | 150 ++++++++++-------------------------------- 2 files changed, 36 insertions(+), 117 deletions(-) diff --git a/seawrecks/depends.txt b/seawrecks/depends.txt index 331d858..820b226 100644 --- a/seawrecks/depends.txt +++ b/seawrecks/depends.txt @@ -1 +1,2 @@ -default \ No newline at end of file +default +treasurer? diff --git a/seawrecks/init.lua b/seawrecks/init.lua index 4c921aa..4ac0d0e 100644 --- a/seawrecks/init.lua +++ b/seawrecks/init.lua @@ -1,5 +1,25 @@ --- NODES +-- Fill chests function +local random = math.random +local function fill_chest(pos, min_pre, max_pre) + local n = minetest.get_node(pos) + if n and n.name and n.name == "default:chest" then + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + inv:set_size("main", 32) + local stacks = {} + if minetest.get_modpath("treasurer") ~= nil then + stacks = treasurer.select_random_treasures(8, min_pre, max_pre, {"weapons", "armor"}) + end -- TODO else if no treasurer + for s=1,#stacks do + if not inv:contains_item("main", stacks[s]) then + inv:set_stack("main", random(1,32), stacks[s]) + end + end + end +end + +-- NODES minetest.register_node("seawrecks:woodship", { description = "Sand for the wooden ship", @@ -13,118 +33,12 @@ minetest.register_node("seawrecks:uboot", { description = "Dirt for the U-boot", tiles = {"default_dirt.png"}, is_ground_content = true, - groups = {crumbly=3,soil=1, not_in_creative_inventory=1}, - sounds = default.node_sound_dirt_defaults(), + groups = {crumbly=3, falling_node=1, sand=1, soil=1, not_in_creative_inventory=1}, + sounds = default.node_sound_sand_defaults(), }) -minetest.register_node("seawrecks:woodshipchest", { - description = "Wooden ship chest", - tiles = {"default_chest_top.png", "default_chest_top.png", "default_chest_side.png", - "default_chest_side.png", "default_chest_side.png", "default_chest_front.png"}, - paramtype2 = "facedir", - groups = {choppy=2,oddly_breakable_by_hand=2, not_in_creative_inventory=1}, - drop = 'default:chest', - legacy_facedir_simple = true, - is_ground_content = false, - sounds = default.node_sound_wood_defaults(), - on_construct = function(pos) - local meta = minetest.get_meta(pos) - meta:set_string("formspec", - "size[8,9]".. - "list[current_name;main;0,0;8,4;]".. - "list[current_player;main;0,5;8,4;]" .. - "listring[current_name;main]" .. - "listring[current_player;main]") - meta:set_string("infotext", "Woodship chest") - local inv = meta:get_inventory() - inv:set_size("main", 8*4) -meta:from_table({ - inventory = { - main = {[1] = "default:tree 99", [2] = "default:jungletree 99", [3] = "default:wood 99", [4] = "default:junglewood 99", [5] = "default:sapling 99", [6] = "default:junglesapling 99", [7] = "default:grass_1 99", [8] = "default:junglegrass 99", [32] = ""} - }, - fields = { - formspec = "size[8,9;]list[context;main;0,0;8,4;]list[current_player;main;0,5;8,4;]" .. - "listring[context;main]" .. - "listring[current_player;main]", - infotext = "Normal chest" - } -}) - end, - can_dig = function(pos,player) - local meta = minetest.get_meta(pos); - local inv = meta:get_inventory() - return inv:is_empty("main") - end, - on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) - minetest.log("action", player:get_player_name().. - " moves stuff in chest at "..minetest.pos_to_string(pos)) - end, - on_metadata_inventory_put = function(pos, listname, index, stack, player) - minetest.log("action", player:get_player_name().. - " moves stuff to chest at "..minetest.pos_to_string(pos)) - end, - on_metadata_inventory_take = function(pos, listname, index, stack, player) - minetest.log("action", player:get_player_name().. - " takes stuff from chest at "..minetest.pos_to_string(pos)) - end, -}) - -minetest.register_node("seawrecks:ubootchest", { - description = "U-boot chest", - tiles = {"default_chest_top.png", "default_chest_top.png", "default_chest_side.png", - "default_chest_side.png", "default_chest_side.png", "default_chest_front.png"}, - paramtype2 = "facedir", - groups = {choppy=2,oddly_breakable_by_hand=2, not_in_creative_inventory=1}, - drop = 'default:chest', - legacy_facedir_simple = true, - is_ground_content = false, - sounds = default.node_sound_wood_defaults(), - on_construct = function(pos) - local meta = minetest.get_meta(pos) - meta:set_string("formspec", - "size[8,9]".. - "list[current_name;main;0,0;8,4;]".. - "list[current_player;main;0,5;8,4;]" .. - "listring[current_name;main]" .. - "listring[current_player;main]") - meta:set_string("infotext", "U-boot chest") - local inv = meta:get_inventory() - inv:set_size("main", 8*4) -meta:from_table({ - inventory = { - main = {[1] = "default:gold_ingot 99", [2] = "default:mese_crystal 99", [3] = "default:diamond 99", [32] = ""} - }, - fields = { - formspec = "size[8,9;]list[context;main;0,0;8,4;]list[current_player;main;0,5;8,4;]" .. - "listring[context;main]" .. - "listring[current_player;main]", - infotext = "Normal chest" - } -}) - end, - can_dig = function(pos,player) - local meta = minetest.get_meta(pos); - local inv = meta:get_inventory() - return inv:is_empty("main") - end, - on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) - minetest.log("action", player:get_player_name().. - " moves stuff in chest at "..minetest.pos_to_string(pos)) - end, - on_metadata_inventory_put = function(pos, listname, index, stack, player) - minetest.log("action", player:get_player_name().. - " moves stuff to chest at "..minetest.pos_to_string(pos)) - end, - on_metadata_inventory_take = function(pos, listname, index, stack, player) - minetest.log("action", player:get_player_name().. - " takes stuff from chest at "..minetest.pos_to_string(pos)) - end, -}) - - -- WRECK GENERATION - minetest.register_ore({ ore_type = "scatter", ore = "seawrecks:woodship", @@ -139,11 +53,11 @@ minetest.register_ore({ minetest.register_ore({ ore_type = "scatter", ore = "seawrecks:uboot", - wherein = "default:dirt", - clust_scarcity = 30*30*30, + wherein = "default:sand", + clust_scarcity = 40*40*40, clust_num_ores = 1, clust_size = 12, - y_max = -8, + y_max = -10, y_min = -31000, }) @@ -358,7 +272,9 @@ local yp = {x = pos.x, y = pos.y + 3, z = pos.z} pos.y = pos.y - 7 pos.z = pos.z + 1 pos.x = pos.x - 2 - minetest.add_node(pos, {name = "seawrecks:woodshipchest"}) + --minetest.add_node(pos, {name = "seawrecks:woodshipchest"}) + minetest.add_node(pos, {name = "default:chest"}) + fill_chest(pos, 0, 3) else return @@ -375,7 +291,7 @@ local yp = {x = pos.x, y = pos.y + 8, z = pos.z} if minetest.get_node(pos).name == "seawrecks:uboot" and (minetest.get_node(yp).name == "default:water_source" or minetest.get_node(yp).name == "noairblocks:water_sourcex") then - minetest.add_node(pos, {name = "default:dirt"}) + minetest.add_node(pos, {name = "default:sand"}) pos.y = pos.y + 1 pos.x = pos.x - 15 @@ -925,10 +841,12 @@ local yp = {x = pos.x, y = pos.y + 8, z = pos.z} pos.y = pos.y - 7 pos.x = pos.x +16 pos.z = pos.z +3 - minetest.add_node(pos, {name = "seawrecks:ubootchest"}) + --minetest.add_node(pos, {name = "seawrecks:ubootchest"}) + minetest.add_node(pos, {name = "default:chest"}) + fill_chest(pos, 7, 10) else return end end -}) \ No newline at end of file +})