) block.
Instead of just picking-up, the gift is dropped. A nice effect, currently only in treasurer implementation, but can be ported to the non treasurer logic too.
Code: Select all
diff --git a/init.lua b/init.lua
index 2fbeaea..309adf4 100644
--- a/init.lua
+++ b/init.lua
@@ -37,6 +37,102 @@ if config:get("enable_crafts") == "true" then
dofile(MODPATH .."/crafts.lua")--if snow enabled, execute this file
end
+-- presents
+local open_present_hardcoded = function(max)
+ local drop
+ if not minetest.get_modpath("treasurer") then
+-- try to port the old logic
+ if max == 1 then
+ drop = {
+ max_items = 1, min_items = 1, items = {
+ {items = {'default:bookshelf'}, rarity = 90,},
+ {items = {'default:pick_mese'}, rarity = 80,},
+ {items = {'default:shovel_steel'}, rarity = 90,},
+ {items = {'default:axe_steel'}, rarity = 90,},
+ {items = {'default:pick_steel'}, rarity = 90,},
+ {items = {'default:sign_wall'}, rarity = 80,},
+ {items = {'default:chest'}, rarity = 80,},
+ {items = {'default:furnace'}, rarity = 80,},
+ {items = {'default:steelblock'}, rarity = 80,},
+ {items = {'default:coal_lump'}, rarity = 80,},
+ {items = {'default:pick_diamond'}, rarity = 75,},
+ {items = {'default:shovel_diamond'}, rarity = 75,},
+ {items = {'default:axe_diamond'}, rarity = 75,},
+ {items = {'default:diamondblock'}, rarity = 75},
+ {items = {'fake_fire:flint_and_steel'}, rarity = 90,},
+ {items = {'default:chest_locked'}, rarity = 80,},
+ {items = {'default:brick'}, rarity = 80,},
+ {items = {'default:dirt_with_grass'}, rarity = 80,},
+ }}
+ else
+ drop = {
+ max_items = max, items = {
+ {items = {'default:bookshelf'}, rarity = 15,},
+ {items = {'default:pick_mese'}, rarity = 20,},
+ {items = {'default:shovel_steel'}, rarity = 15,},
+ {items = {'default:axe_steel'}, rarity = 15,},
+ {items = {'default:pick_steel'}, rarity = 15,},
+ {items = {'default:sign_wall'}, rarity = 20,},
+ {items = {'default:chest'}, rarity = 20,},
+ {items = {'default:furnace'}, rarity = 20,},
+ {items = {'default:steelblock'}, rarity = 25,},
+ {items = {'default:coal_lump'}, rarity = 25,},
+ {items = {'diamonds:pick'}, rarity = 30,},
+ {items = {'diamonds:shovel'}, rarity = 30,},
+ {items = {'diamonds:axe'}, rarity = 30,},
+ {items = {'diamonds:block'}, rarity = 30,},
+ {items = {'fake_fire:flint_and_steel'}, rarity = 15,},
+ {items = {'default:chest_locked'}, rarity = 20,},
+ {items = {'default:brick'}, rarity = 25,},
+ {items = {'default:dirt_with_grass'}, rarity = 30,},
+ }}
+ end
+ end
+ return drop
+end
+
+local open_present_treasurer = function(max)
+ if minetest.get_modpath("treasurer") then
+ --- functionality ported from surprise_block
+ after_destruct = function (pos, oldnode)
+ local drops = treasurer.select_random_treasures(max)
+ for _,item in ipairs(drops) do
+ local count, name
+ if type(item) == "string" then
+ name, count = item:match("^([a-zA-Z0-9_:]*) ([0-9]*)$")
+ if not name then
+ name = item
+ end
+ if not count then
+ count = 1
+ end
+ else
+ count = item:get_count()
+ name = item:get_name()
+ end
+ if not inv or not inv:contains_item("main", ItemStack(name)) then
+ for i=1,count do
+ local obj = minetest.env:add_item(pos, name)
+ if obj ~= nil then
+ obj:get_luaentity().collect = true
+ local x = math.random(1, 5)
+ if math.random(1,2) == 1 then
+ x = -x
+ end
+ local z = math.random(1, 5)
+ if math.random(1,2) == 1 then
+ z = -z
+ end
+ obj:setvelocity({x=1/x, y=obj:getvelocity().y, z=1/z})
+ end
+ end
+ end
+ end
+ end
+
+ end
+ return after_destruct
+end
-- blocks --
@@ -336,31 +432,6 @@ minetest.register_node("christmas_craft:silver_baubles", {
------------
--nodes--
- -- presents --
-
- --store the drop in a variable
- local presents_drop = {
- max_items = 2, items = {
- {items = {'default:bookshelf'}, rarity = 15,},
- {items = {'default:pick_mese'}, rarity = 20,},
- {items = {'default:shovel_steel'}, rarity = 15,},
- {items = {'default:axe_steel'}, rarity = 15,},
- {items = {'default:pick_steel'}, rarity = 15,},
- {items = {'default:sign_wall'}, rarity = 20,},
- {items = {'default:chest'}, rarity = 20,},
- {items = {'default:furnace'}, rarity = 20,},
- {items = {'default:steelblock'}, rarity = 25,},
- {items = {'default:coal_lump'}, rarity = 25,},
- {items = {'diamonds:pick'}, rarity = 30,},
- {items = {'diamonds:shovel'}, rarity = 30,},
- {items = {'diamonds:axe'}, rarity = 30,},
- {items = {'diamonds:block'}, rarity = 30,},
- {items = {'fake_fire:flint_and_steel'}, rarity = 15,},
- {items = {'default:chest_locked'}, rarity = 20,},
- {items = {'default:brick'}, rarity = 25,},
- {items = {'default:dirt_with_grass'}, rarity = 30,},
- }}
-
minetest.register_node("christmas_craft:present_box", {
description = "Present Box",
tiles = {"christmas_craft_present_box.png"},
@@ -375,27 +446,8 @@ minetest.register_node("christmas_craft:silver_baubles", {
tiles = {"christmas_craft_present_wh.png^christmas_craft_bow_top.png", "christmas_craft_present_wh.png^christmas_craft_bow_bottom.png", "christmas_craft_present_wh.png^christmas_craft_bow_side.png"},
is_ground_content = true,
groups = {crumbly=3},
- drop = {
- max_items = 1, min_items = 1, items = {
- {items = {'default:bookshelf'}, rarity = 90,},
- {items = {'default:pick_mese'}, rarity = 80,},
- {items = {'default:shovel_steel'}, rarity = 90,},
- {items = {'default:axe_steel'}, rarity = 90,},
- {items = {'default:pick_steel'}, rarity = 90,},
- {items = {'default:sign_wall'}, rarity = 80,},
- {items = {'default:chest'}, rarity = 80,},
- {items = {'default:furnace'}, rarity = 80,},
- {items = {'default:steelblock'}, rarity = 80,},
- {items = {'default:coal_lump'}, rarity = 80,},
- {items = {'default:pick_diamond'}, rarity = 75,},
- {items = {'default:shovel_diamond'}, rarity = 75,},
- {items = {'default:axe_diamond'}, rarity = 75,},
- {items = {'default:diamondblock'}, rarity = 75},
- {items = {'fake_fire:flint_and_steel'}, rarity = 90,},
- {items = {'default:chest_locked'}, rarity = 80,},
- {items = {'default:brick'}, rarity = 80,},
- {items = {'default:dirt_with_grass'}, rarity = 80,},
- }},
+ drop = open_present_hardcoded(1), --old way
+ after_destruct = open_present_treasurer(1), --using treasurer
sounds = default.node_sound_dirt_defaults({
footstep = {name="default_grass_footstep", gain=0.4},
}),
@@ -406,7 +458,8 @@ minetest.register_node("christmas_craft:silver_baubles", {
tiles = {"christmas_craft_present_gr.png^christmas_craft_bow_top.png", "christmas_craft_present_gr.png^christmas_craft_bow_bottom.png", "christmas_craft_present_gr.png^christmas_craft_bow_side.png"},
is_ground_content = true,
groups = {crumbly=3},
- drop = presents_drop,
+ drop = open_present_hardcoded(2), --old way
+ after_destruct = open_present_treasurer(2), --using treasurer
sounds = default.node_sound_dirt_defaults({
footstep = {name="default_grass_footstep", gain=0.4},
}),
@@ -417,7 +470,8 @@ minetest.register_node("christmas_craft:silver_baubles", {
tiles = {"christmas_craft_present_re.png^christmas_craft_bow_top.png", "christmas_craft_present_re.png^christmas_craft_bow_bottom.png", "christmas_craft_present_re.png^christmas_craft_bow_side.png"},
is_ground_content = true,
groups = {crumbly=3},
- drop = presents_drop,
+ drop = open_present_hardcoded(2), --old way
+ after_destruct = open_present_treasurer(2), --using treasurer
sounds = default.node_sound_dirt_defaults({
footstep = {name="default_grass_footstep", gain=0.4},
}),
@@ -428,7 +482,8 @@ minetest.register_node("christmas_craft:silver_baubles", {
tiles = {"christmas_craft_present_bl.png^christmas_craft_bow_top.png", "christmas_craft_present_bl.png^christmas_craft_bow_bottom.png", "christmas_craft_present_bl.png^christmas_craft_bow_side.png"},
is_ground_content = true,
groups = {crumbly=3},
- drop = presents_drop,
+ drop = open_present_hardcoded(2), --old way
+ after_destruct = open_present_treasurer(2), --using treasurer
sounds = default.node_sound_dirt_defaults({
footstep = {name="default_grass_footstep", gain=0.4},
}),
@@ -439,7 +494,8 @@ minetest.register_node("christmas_craft:silver_baubles", {
tiles = {"christmas_craft_present_ye.png^christmas_craft_bow_top.png", "christmas_craft_present_ye.png^christmas_craft_bow_bottom.png", "christmas_craft_present_ye.png^christmas_craft_bow_side.png"},
is_ground_content = true,
groups = {crumbly=3},
- drop = presents_drop,
+ drop = open_present_hardcoded(2), --old way
+ after_destruct = open_present_treasurer(2), --using treasurer
sounds = default.node_sound_dirt_defaults({
footstep = {name="default_grass_footstep", gain=0.4},
}),
@@ -450,7 +506,8 @@ minetest.register_node("christmas_craft:silver_baubles", {
tiles = {"christmas_craft_present_re.png^christmas_craft_bow_top.png", "christmas_craft_present_re.png^christmas_craft_bow_bottom.png", "christmas_craft_present_re.png^christmas_craft_bow_side.png"},
is_ground_content = true,
groups = {crumbly=3},
- drop = presents_drop,
+ drop = open_present_hardcoded(2), --old way
+ after_destruct = open_present_treasurer(2), --using treasurer
sounds = default.node_sound_dirt_defaults({
footstep = {name="default_grass_footstep", gain=0.4},
}),
@@ -461,7 +518,8 @@ minetest.register_node("christmas_craft:silver_baubles", {
tiles = {"christmas_craft_present_vi.png^christmas_craft_bow_top.png", "christmas_craft_present_vi.png^christmas_craft_bow_bottom.png", "christmas_craft_present_vi.png^christmas_craft_bow_side.png"},
is_ground_content = true,
groups = {crumbly=3},
- presents_drop,
+ drop = open_present_hardcoded(2), --old way
+ after_destruct = open_present_treasurer(2), --using treasurer
sounds = default.node_sound_dirt_defaults({
footstep = {name="default_grass_footstep", gain=0.4},
}),
@@ -472,7 +530,8 @@ minetest.register_node("christmas_craft:silver_baubles", {
tiles = {"christmas_craft_present_or.png^christmas_craft_bow_top.png", "christmas_craft_present_or.png^christmas_craft_bow_bottom.png", "christmas_craft_present_or.png^christmas_craft_bow_side.png"},
is_ground_content = true,
groups = {crumbly=3},
- drop = presents_drop,
+ drop = open_present_hardcoded(2), --old way
+ after_destruct = open_present_treasurer(2), --using treasurer
sounds = default.node_sound_dirt_defaults({
footstep = {name="default_grass_footstep", gain=0.4},
}),
@@ -483,7 +542,8 @@ minetest.register_node("christmas_craft:silver_baubles", {
tiles = {"christmas_craft_present_pi.png^christmas_craft_bow_top.png", "christmas_craft_present_pi.png^christmas_craft_bow_bottom.png", "christmas_craft_present_pi.png^christmas_craft_bow_side.png"},
is_ground_content = true,
groups = {crumbly=3},
- drop = presents_drop,
+ drop = open_present_hardcoded(2), --old way
+ after_destruct = open_present_treasurer(2), --using treasurer
sounds = default.node_sound_dirt_defaults({
footstep = {name="default_grass_footstep", gain=0.4},
}),