Compare commits
5 Commits
11aa5f4081
...
41de02841f
Author | SHA1 | Date |
---|---|---|
Mitori Itoshiki | 41de02841f | |
Mitori Itoshiki | f5696e6582 | |
mito551 | e01b1fbc67 | |
jojoa1997 | 319071d263 | |
mito551 | 36026391f4 |
|
@ -1,4 +1,4 @@
|
|||
Minetest Dwarves
|
||||
Freeminer Dwarves
|
||||
==========================
|
||||
Install in $path_share/games/
|
||||
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
COPYRIGHT @ jojoa1997
|
||||
CC-BY-SA
|
|
@ -0,0 +1,13 @@
|
|||
minetest.register_biome({
|
||||
name = "Ore_Hills_D",
|
||||
|
||||
node_top = "extra_biomes:dirt",
|
||||
depth_top = 2,
|
||||
node_filler = "extra_biomes:stone",
|
||||
depth_filler = 2,
|
||||
|
||||
height_min = 15,
|
||||
height_max = 35,
|
||||
heat_point = 40,
|
||||
humidity_point = 30,
|
||||
})
|
|
@ -0,0 +1 @@
|
|||
default
|
|
@ -0,0 +1,6 @@
|
|||
--
|
||||
-- Init file for Extra Biomes
|
||||
--
|
||||
|
||||
dofile(minetest.get_modpath("extra_biomes").."/nodes.lua")
|
||||
dofile(minetest.get_modpath("extra_biomes").."/biomes.lua")
|
|
@ -0,0 +1,84 @@
|
|||
--
|
||||
-- Nodes file for Extra Biomes
|
||||
--
|
||||
|
||||
-- Nodeblocks
|
||||
|
||||
minetest.register_node("extra_biomes:stone", {
|
||||
description = "Extra Biomes Stone",
|
||||
tiles = {"extra_biomes_stone.png"},
|
||||
is_ground_content = true,
|
||||
groups = {cracky=6, stone=1, melt=3000},
|
||||
freezemelt = "default:lava_source",
|
||||
drop = {
|
||||
max_items = 1,
|
||||
items = {
|
||||
{
|
||||
items = {'default:stone_with_coal'},
|
||||
rarity = 7,
|
||||
},
|
||||
{
|
||||
items = {'default:stone_with_iron'},
|
||||
rarity = 7,
|
||||
},
|
||||
{
|
||||
items = {'default:stone_with_gold'},
|
||||
rarity = 7,
|
||||
},
|
||||
{
|
||||
items = {'default:stone_with_copper'},
|
||||
rarity = 7,
|
||||
},
|
||||
{
|
||||
items = {'default:stone_with_mese'},
|
||||
rarity = 7,
|
||||
},
|
||||
{
|
||||
items = {'default:stone'},
|
||||
rarity = 5,
|
||||
},
|
||||
},
|
||||
},
|
||||
legacy_mineral = true,
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
})
|
||||
|
||||
minetest.register_node("extra_biomes:dirt", {
|
||||
description = "Extra Biomes Dirt",
|
||||
tiles = {"extra_biomes_dirt.png"},
|
||||
is_ground_content = true,
|
||||
groups = {crumbly=6, soil=1, melt=3050},
|
||||
freezemelt = "default:water_source",
|
||||
drop = {
|
||||
max_items = 1,
|
||||
items = {
|
||||
{
|
||||
items = {'default:coal_lump'},
|
||||
rarity = 7,
|
||||
},
|
||||
{
|
||||
items = {'default:gold_lump'},
|
||||
rarity = 7,
|
||||
},
|
||||
{
|
||||
items = {'default:iron_lump'},
|
||||
rarity = 7,
|
||||
},
|
||||
{
|
||||
items = {'default:copper_lump'},
|
||||
rarity = 7,
|
||||
},
|
||||
{
|
||||
items = {'default:mese_crystal'},
|
||||
rarity = 7,
|
||||
},
|
||||
{
|
||||
items = {'default:dirt_with_grass'},
|
||||
rarity = 5,
|
||||
},
|
||||
},
|
||||
},
|
||||
sounds = default.node_sound_dirt_defaults({
|
||||
footstep = {name="default_grass_footstep", gain=0.4},
|
||||
}),
|
||||
})
|
Binary file not shown.
After Width: | Height: | Size: 939 B |
Binary file not shown.
After Width: | Height: | Size: 3.2 KiB |
|
@ -0,0 +1 @@
|
|||
*~
|
|
@ -0,0 +1 @@
|
|||
default
|
|
@ -0,0 +1,200 @@
|
|||
local tmp = {}
|
||||
|
||||
minetest.register_entity("itemframes:item",{
|
||||
hp_max = 1,
|
||||
visual="wielditem",
|
||||
visual_size={x=.33,y=.33},
|
||||
collisionbox = {0,0,0,0,0,0},
|
||||
physical=false,
|
||||
textures={"air"},
|
||||
on_activate = function(self, staticdata)
|
||||
if tmp.nodename ~= nil and tmp.texture ~= nil then
|
||||
self.nodename = tmp.nodename
|
||||
tmp.nodename = nil
|
||||
self.texture = tmp.texture
|
||||
tmp.texture = nil
|
||||
else
|
||||
if staticdata ~= nil and staticdata ~= "" then
|
||||
local data = staticdata:split(';')
|
||||
if data and data[1] and data[2] then
|
||||
self.nodename = data[1]
|
||||
self.texture = data[2]
|
||||
end
|
||||
end
|
||||
end
|
||||
if self.texture ~= nil then
|
||||
self.object:set_properties({textures={self.texture}})
|
||||
end
|
||||
if self.nodename == "itemframes:pedestal" then
|
||||
self.object:set_properties({automatic_rotate=1})
|
||||
end
|
||||
end,
|
||||
get_staticdata = function(self)
|
||||
if self.nodename ~= nil and self.texture ~= nil then
|
||||
return self.nodename .. ';' .. self.texture
|
||||
end
|
||||
return ""
|
||||
end,
|
||||
})
|
||||
|
||||
|
||||
local facedir = {}
|
||||
facedir[0] = {x=0,y=0,z=1}
|
||||
facedir[1] = {x=1,y=0,z=0}
|
||||
facedir[2] = {x=0,y=0,z=-1}
|
||||
facedir[3] = {x=-1,y=0,z=0}
|
||||
|
||||
local remove_item = function(pos, node)
|
||||
local objs = nil
|
||||
if node.name == "itemframes:frame" then
|
||||
objs = minetest.env:get_objects_inside_radius(pos, .5)
|
||||
elseif node.name == "itemframes:pedestal" then
|
||||
objs = minetest.env:get_objects_inside_radius({x=pos.x,y=pos.y+1,z=pos.z}, .5)
|
||||
end
|
||||
if objs then
|
||||
for _, obj in ipairs(objs) do
|
||||
if obj and obj:get_luaentity() and obj:get_luaentity().name == "itemframes:item" then
|
||||
obj:remove()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local update_item = function(pos, node)
|
||||
remove_item(pos, node)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
if meta:get_string("item") ~= "" then
|
||||
if node.name == "itemframes:frame" then
|
||||
local posad = facedir[node.param2]
|
||||
pos.x = pos.x + posad.x*6.5/16
|
||||
pos.y = pos.y + posad.y*6.5/16
|
||||
pos.z = pos.z + posad.z*6.5/16
|
||||
elseif node.name == "itemframes:pedestal" then
|
||||
pos.y = pos.y + 12/16+.33
|
||||
end
|
||||
tmp.nodename = node.name
|
||||
tmp.texture = ItemStack(meta:get_string("item")):get_name()
|
||||
local e = minetest.env:add_entity(pos,"itemframes:item")
|
||||
if node.name == "itemframes:frame" then
|
||||
local yaw = math.pi*2 - node.param2 * math.pi/2
|
||||
e:setyaw(yaw)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local drop_item = function(pos, node)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
if meta:get_string("item") ~= "" then
|
||||
if node.name == "itemframes:frame" then
|
||||
minetest.env:add_item(pos, meta:get_string("item"))
|
||||
elseif node.name == "itemframes:pedestal" then
|
||||
minetest.env:add_item({x=pos.x,y=pos.y+1,z=pos.z}, meta:get_string("item"))
|
||||
end
|
||||
meta:set_string("item","")
|
||||
end
|
||||
remove_item(pos, node)
|
||||
end
|
||||
|
||||
minetest.register_node("itemframes:frame",{
|
||||
description = "Item frame",
|
||||
drawtype = "nodebox",
|
||||
node_box = { type = "fixed", fixed = {-0.5, -0.5, 7/16, 0.5, 0.5, 0.5} },
|
||||
selection_box = { type = "fixed", fixed = {-0.5, -0.5, 7/16, 0.5, 0.5, 0.5} },
|
||||
tiles = {"itemframes_frame.png"},
|
||||
inventory_image = "itemframes_frame.png",
|
||||
wield_image = "itemframes_frame.png",
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
sunlight_propagates = true,
|
||||
groups = { choppy=2,dig_immediate=2 },
|
||||
legacy_wallmounted = true,
|
||||
sounds = default.node_sound_defaults(),
|
||||
after_place_node = function(pos, placer, itemstack)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
meta:set_string("owner",placer:get_player_name())
|
||||
meta:set_string("infotext","Item frame (owned by "..placer:get_player_name()..")")
|
||||
end,
|
||||
on_rightclick = function(pos, node, clicker, itemstack)
|
||||
if not itemstack then return end
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
if clicker:get_player_name() == meta:get_string("owner") then
|
||||
drop_item(pos,node)
|
||||
local s = itemstack:take_item()
|
||||
meta:set_string("item",s:to_string())
|
||||
update_item(pos,node)
|
||||
end
|
||||
return itemstack
|
||||
end,
|
||||
on_punch = function(pos,node,puncher)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
if puncher:get_player_name() == meta:get_string("owner") then
|
||||
drop_item(pos, node)
|
||||
end
|
||||
end,
|
||||
can_dig = function(pos,player)
|
||||
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
return player:get_player_name() == meta:get_string("owner")
|
||||
end,
|
||||
})
|
||||
|
||||
|
||||
minetest.register_node("itemframes:pedestal",{
|
||||
description = "Pedestal",
|
||||
drawtype = "nodebox",
|
||||
node_box = { type = "fixed", fixed = {
|
||||
{-7/16, -8/16, -7/16, 7/16, -7/16, 7/16}, -- bottom plate
|
||||
{-6/16, -7/16, -6/16, 6/16, -6/16, 6/16}, -- bottom plate (upper)
|
||||
{-0.25, -6/16, -0.25, 0.25, 11/16, 0.25}, -- pillar
|
||||
{-7/16, 11/16, -7/16, 7/16, 12/16, 7/16}, -- top plate
|
||||
} },
|
||||
--selection_box = { type = "fixed", fixed = {-7/16, -0.5, -7/16, 7/16, 12/16, 7/16} },
|
||||
tiles = {"itemframes_pedestal.png"},
|
||||
paramtype = "light",
|
||||
groups = { cracky=3 },
|
||||
sounds = default.node_sound_defaults(),
|
||||
after_place_node = function(pos, placer, itemstack)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
meta:set_string("owner",placer:get_player_name())
|
||||
meta:set_string("infotext","Pedestal (owned by "..placer:get_player_name()..")")
|
||||
end,
|
||||
on_rightclick = function(pos, node, clicker, itemstack)
|
||||
if not itemstack then return end
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
if clicker:get_player_name() == meta:get_string("owner") then
|
||||
drop_item(pos,node)
|
||||
local s = itemstack:take_item()
|
||||
meta:set_string("item",s:to_string())
|
||||
update_item(pos,node)
|
||||
end
|
||||
return itemstack
|
||||
end,
|
||||
on_punch = function(pos,node,puncher)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
if puncher:get_player_name() == meta:get_string("owner") then
|
||||
drop_item(pos,node)
|
||||
end
|
||||
end,
|
||||
can_dig = function(pos,player)
|
||||
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
return player:get_player_name() == meta:get_string("owner")
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'itemframes:frame',
|
||||
recipe = {
|
||||
{'default:stick', 'default:stick', 'default:stick'},
|
||||
{'default:stick', 'default:paper', 'default:stick'},
|
||||
{'default:stick', 'default:stick', 'default:stick'},
|
||||
}
|
||||
})
|
||||
minetest.register_craft({
|
||||
output = 'itemframes:pedestal',
|
||||
recipe = {
|
||||
{'default:stone', 'default:stone', 'default:stone'},
|
||||
{'', 'default:stone', ''},
|
||||
{'default:stone', 'default:stone', 'default:stone'},
|
||||
}
|
||||
})
|
Binary file not shown.
After Width: | Height: | Size: 206 B |
Binary file not shown.
After Width: | Height: | Size: 519 B |
|
@ -0,0 +1,30 @@
|
|||
player_running_physics = {}
|
||||
minetest.register_globalstep(function(dtime)
|
||||
for _,player in ipairs(minetest.get_connected_players()) do
|
||||
--local pos = player:getpos()
|
||||
--print(dump(player:get_player_control().up))
|
||||
if player:get_player_control().up == true and player_running_physics[player:get_player_name()] == nil then
|
||||
minetest.after(0.05, function()
|
||||
if player:get_player_control().up == false then
|
||||
minetest.after(0.05, function()
|
||||
if player:get_player_control().up == true then
|
||||
player:set_physics_override(1.46, 1, 1)
|
||||
player_running_physics[player:get_player_name()] = true
|
||||
print("test1")
|
||||
end
|
||||
end)
|
||||
end
|
||||
end)
|
||||
elseif player:get_player_control().up == false and player_running_physics[player:get_player_name()] == true then
|
||||
--minetest.after(0.2, function()
|
||||
if player:get_player_control().up == false then
|
||||
player_running_physics[player:get_player_name()] = nil
|
||||
player:set_physics_override(1, 1, 1)
|
||||
print("test2")
|
||||
end
|
||||
--end)
|
||||
end
|
||||
|
||||
end
|
||||
end)
|
||||
|
Binary file not shown.
|
@ -0,0 +1,201 @@
|
|||
= Treasurer’s README file for Treasurer version 0.1 =
|
||||
== Overview ==
|
||||
Name: Treasurer
|
||||
Technical name: treasurer
|
||||
Purpose: To provide an interface for mods which want to spawn ItemStacks randomly and
|
||||
an interface for mods which create new items.
|
||||
Version: 0.1
|
||||
Dependencies: none
|
||||
License: WTFPL
|
||||
|
||||
== Introduction ==
|
||||
Problem:
|
||||
There are a bunch of mods which have cool items but they won’t appear in the world by
|
||||
themselves.
|
||||
There are some mods which randomly distribute treasures into the world. Sadly, these only
|
||||
distribute the items they know—which are just the items of the mod “default” most of the
|
||||
time. The items of the other mods are completely missed.
|
||||
|
||||
The reason for this is that the distributing mods can’t know what sort of items are available
|
||||
unless they explicitly depend on the mods that defines these. Viewed the other way round,
|
||||
the item-defining mods that also distribute these items into the world are limited in the
|
||||
sense that they only know one means of distributing items.
|
||||
|
||||
There is a gap between defining items and distributing them. Every time a mod does both,
|
||||
flexibility is limited and expansion becomes difficult.
|
||||
|
||||
To bridge this gap, Treasurer has been written. Treasurer makes it possible a) for mods to define
|
||||
treasures without bothering _how_ these are distributed into the world and b) for mods to distribute
|
||||
treasures around the world without knowledge about _what_ treasures exactly are distributed.
|
||||
|
||||
== Technical side of Treasurer ==
|
||||
=== technical overview ===
|
||||
To get a working Treasurer architecture and actually get some treasures into the world,
|
||||
you need:
|
||||
* Treasurer
|
||||
* at least one treasure registration mod
|
||||
* at least one treasure spawning mod
|
||||
|
||||
=== treasurer registration mod ===
|
||||
Firstly, there are the treasure registration mods (TRMs). The task of TRMs is to tell
|
||||
Treasurer which items does it have to offer, which relative appearance probabilities these
|
||||
treasures should have, how “precious” the treasure is considered (on a scale from 0 to 10)
|
||||
, optionally how big the stack of items should be and optionally how much worn out it is.
|
||||
TRMs must depend on at least two mods: On treasurer and on the mod or mods
|
||||
where the items are defined. Technically, a TRM consists of nothing more than a long
|
||||
list of “registration” function calls. While this seems trivial, the task of balancing
|
||||
out probabilties and balancing out preciousness levels of treasures is not trivial
|
||||
and it may take a long time to get right.
|
||||
|
||||
It is strongly recommended that a TRM really does nothing
|
||||
more than registering treasures (and not defining items, for example). If you want
|
||||
to make your mod compatible to Treasurer, don’t change your mod, write a TRM for
|
||||
it instead.
|
||||
There is an example TRM, called “trm_default_example”. It registers some items
|
||||
of the default as treasures. Unsurprisingly, it depends on treasurer and default.
|
||||
|
||||
=== treasurer spawning mods ===
|
||||
Secondly, there are the treasure spawning mods (TSMs). The task of a TSM is to somehow
|
||||
distribute the available treasures into the world. This is also called “treasure
|
||||
spawning”. How exactly the TSM spawns the treasures is completely up the TSM. But a
|
||||
TSM has to request Treasurer to get some random treasures to distribute. A TSM may
|
||||
optionally request to filter out treasures outside certain preciousness levels, so
|
||||
it can be
|
||||
Treasurer can not guarantee to return the requestet amount of treasures, it may
|
||||
return an empty table, for two reasons:
|
||||
1) There is no TRM activated. There must be at least one to work
|
||||
2) The preciousness filter filtered out. This problem can be fixed by installing more
|
||||
TRMs or by balancing the existing TRMs to cover as many preciousness levels as
|
||||
possible. It also may be that the range specified by the TSM was too small. It is
|
||||
recommended to keep the requested range at least of a size of 1.
|
||||
Treasurer does, however, guarantee that the returned treasures are always in the
|
||||
requested boundsa.
|
||||
A TSM has to at least depend on Treasurer.
|
||||
Like for TRMs, it is strongly recommended that a TSM does nothing more than spawning
|
||||
treasures. This does not exclude the possibility that a TSM does not depend
|
||||
on any other mod.
|
||||
There are two example TSMs. The first one is a very basic one and called “tsm_gift_example”.
|
||||
It gives a “welcome gift” (1 random treasure) to players who just joined the server
|
||||
or who respawn. The preciousness filter is not used. It does only depend on Treasurer.
|
||||
The second one is called “tsm_chests_example” and pretty advanced for an example.
|
||||
It places chests of the mod “default” between 20 and 200 node lenghts below the water
|
||||
surface and puts 1-6 random treasures into these. The lower the chest, the higher
|
||||
the preciousness. It depends on treasurer and default (for the chests, of course).
|
||||
|
||||
=== Recap ===
|
||||
TRMs define treasures, TSMs spawn them. Treasurer manages the pool of available treasures.
|
||||
TRMs and TSMs do not have to know anything from each other.
|
||||
TRMs and TSMs do not neccessarily have to change any line of code of other mods to function.
|
||||
Treasurer depends on nothing.
|
||||
|
||||
Important: It should always only be neccessary for TRMs and TSMs to depend on Treasurer.
|
||||
All other mods do NOT HAVE TO and SHOULD NOT depend on Treasurer.
|
||||
|
||||
|
||||
|
||||
=== On rarity and preciousness ===
|
||||
==== rarity ====
|
||||
Rarity in Treasurer works in a pretty primitive way: The relative rarities of all
|
||||
treasures from the treasure pool are simply all added up. The probabilitiy of one
|
||||
certain treasure is then simply the rarity value divided by the sum.
|
||||
|
||||
==== preciousness ====
|
||||
How “precious” an item is, is highly subjective and also not always easy to categorize.
|
||||
Preciousness in Treasurer’s terms should be therefore viewed as “utility” or as
|
||||
“reward level” or “strength” or even “beauty” or whatever positive attributes you can
|
||||
think of for items.
|
||||
So, if you create a TRM and your treasure is something you want the player work
|
||||
hard for, assign it a high preciousness. Everyday items that are already easy to
|
||||
obtain in normal gameplay certainly deserve a lower precious than items that are
|
||||
expensive to craft.
|
||||
If your treasure consists of a powerful
|
||||
item, assign it a high preciousness. When in doubt, try to value gameplay over
|
||||
personal taste. Remember that TSMs can (and will!) filter out treasures based
|
||||
on their preciousness.
|
||||
For TSM authors, consider preciousness this way: If the trouble the player has
|
||||
to get through to in order to obtain the treasure is high, better filter
|
||||
out unprecious treasures. If your TSM distributes many treasures all over the world and these
|
||||
are easy to obtain, filter out precious treasures.
|
||||
|
||||
TSMs also can just completely ignore preciousness, then the given treasures base
|
||||
on sheer luck.
|
||||
|
||||
==== Recap ====
|
||||
Rarity determines the chance of a treasure, whereas preciousness determines
|
||||
the difficulty to obtain it.
|
||||
|
||||
== Overview of examples ==
|
||||
- trm_default_example - registers items of default mod
|
||||
- tsm_chests_example - spawns chests (from the default mod)
|
||||
- tsm_gift_example - gives one treasure as a “welcome gift” to joined or respawned players
|
||||
|
||||
== Treasurer API documentation ==
|
||||
=== API documentation for treasure registration mods ===
|
||||
The API consists of one function, which is called “treasurer.register_treasure”.
|
||||
|
||||
treasurer.register_treasure - registers a new treasure
|
||||
(this means the treasure will be ready to be spawned by treasure spawning mods.
|
||||
|
||||
parameters:
|
||||
name: name of resulting ItemStack, e.g. “mymod:item”
|
||||
rarity: rarity of treasure on a scale from 0 to 1 (inclusive). lower = rarer
|
||||
preciousness: subjective preciousness on a scale from 0 to 10 (inclusive)
|
||||
higher = more precious.
|
||||
count: optional value which specifies the multiplicity of the item. Default
|
||||
is 1. See count syntax help in this file.
|
||||
wear: optional value which specifies the wear of the item. Default is 0,
|
||||
which disables the wear. See wear syntax help in this file.
|
||||
note:
|
||||
This function does some basic parameter checking to catch the most obvious
|
||||
mistakes. If invalid parameters have been passed, the input is rejected and
|
||||
the function returns false. However, it does not cover every possible
|
||||
mistake, so some invalid treasures may slip through.
|
||||
note:
|
||||
Rarity does not imply preciousness. A rare treasure may not neccessarily a
|
||||
very precious one. A treasure chest with scorched stuff inside may be very
|
||||
rare, but it’s certainly also very unprecious.
|
||||
|
||||
returns:
|
||||
true on success,
|
||||
false on failure
|
||||
|
||||
=== data formats ===
|
||||
format of count type:
|
||||
A count can be a number or a table
|
||||
|
||||
count = number
|
||||
--> it’s always number times
|
||||
|
||||
count = {min, max}
|
||||
--> it’s pseudorandomly between min and max times, math.random() will be
|
||||
used to chose the value
|
||||
count = {min, max, prob_func}
|
||||
--> it’s between min and max times, and the value is given by
|
||||
prob_func (see below)
|
||||
|
||||
format of wear type:
|
||||
completely analogous to count
|
||||
|
||||
format of prob_func function:
|
||||
prob_func = function()
|
||||
parameters:
|
||||
(none)
|
||||
returns:
|
||||
--> a random or pseudorandom number between 0 (inclusive) and 1 (exclusive).
|
||||
notes:
|
||||
prob_func is entirely optional, if it’s not used, treasurer will
|
||||
default to math.random. You can use prob_func to define your own
|
||||
random function, in case you don’t wish your values to be evenly
|
||||
distributed.
|
||||
|
||||
=== API documentation for treasure spawning mods
|
||||
The API consists of one function, called “treasurer.select_random_treasures”.
|
||||
|
||||
treasurer.select_random_treasures - request some treasures from treasurer
|
||||
parameters:
|
||||
count: (optional) amount of treasures. If this value is nil, treasurer assumes a default of 1.
|
||||
minimal_preciousness: (optional) don’t consider treasures with a lower preciousness. If nil, there’s no lower bound.
|
||||
maximum_preciousness: (optional) don’t consider treasures with a higher preciousness. If nil, there’s no upper bound.
|
||||
returns:
|
||||
a table of ItemStacks (the requested treasures) - may be empty
|
||||
|
|
@ -0,0 +1,293 @@
|
|||
--[==[
|
||||
Treasurer
|
||||
- A mod for Minetest
|
||||
version 0.1
|
||||
]==]
|
||||
|
||||
--[=[
|
||||
TABLE OF CONTENTS
|
||||
part 1: Initialization
|
||||
part 2: Treasure API
|
||||
part 3: Treasure spawning mod handling
|
||||
part 4: Internal functions
|
||||
]=]
|
||||
|
||||
--[=[
|
||||
part 1: Initialization
|
||||
]=]
|
||||
|
||||
-- This creates the main table; all functions of this mod are stored in this table
|
||||
treasurer = {}
|
||||
|
||||
-- Table which stores all the treasures
|
||||
treasurer.treasures = {}
|
||||
|
||||
--[[
|
||||
format of treasure table:
|
||||
treasure = {
|
||||
name, -- treasure name, e.g. mymod:item
|
||||
rarity, -- relative rarity on a scale from 0 to 1 (inclusive).
|
||||
-- a rare treasure must not neccessarily be a precious treasure
|
||||
count, -- count (see below)
|
||||
preciousness, -- preciousness or “worth” of the treasure.
|
||||
-- ranges from 0 (“scorched stuff”) to 10 (“diamond block”)
|
||||
wear, -- wear (see below)
|
||||
metadata, -- unused at the moment
|
||||
|
||||
}
|
||||
treasures can be nodes or items
|
||||
|
||||
format of count type:
|
||||
count = number -- it’s always number times
|
||||
count = {min, max} -- it’s pseudorandomly between min and max times, math.random() will be used to chose the value
|
||||
count = {min, max, prob_func} -- it’s between min and max times, and the value is given by prob_func (which is not neccessarily random [in the strictly mathematical sense])
|
||||
|
||||
format of wear type:
|
||||
completely analogous to count type
|
||||
|
||||
format of prob_func function:
|
||||
prob_func = function()
|
||||
--> returns a random or pseudorandom number between 0 (inclusive) and 1 (exclusive)
|
||||
prob_func is entirely optional, if it’s not used, treasurer will default to math.random.
|
||||
You can use prob_func to define your own random function, in case you don’t like an even
|
||||
distribution
|
||||
]]
|
||||
|
||||
|
||||
--[=[
|
||||
part 2: Treasurer API
|
||||
]=]
|
||||
|
||||
--[[
|
||||
treasurer.register_treasure - registers a new treasure
|
||||
(this means the treasure will be ready to be spawned by treasure spawning mods.
|
||||
|
||||
name: name of resulting ItemStack, e.g. “mymod:item”
|
||||
rarity: rarity of treasure on a scale from 0 to 1 (inclusive). lower = rarer
|
||||
preciousness: preciousness of treasure on a scale from 0 (“scorched stuff”) to 10 (“diamond block”).
|
||||
count: optional value which specifies the multiplicity of the item. Default is 1. See count syntax help in this file.
|
||||
wear: optional value which specifies the wear of the item. Default is 0, which disables the wear. See wear syntax help in this file.
|
||||
This function does some basic parameter checking to catch the most obvious mistakes. If invalid parameters have been passed, the input is rejected and the function returns false. However, it does not cover every possible mistake, so some invalid treasures may slip through.
|
||||
|
||||
returns: true on success, false on failure
|
||||
]]
|
||||
function treasurer.register_treasure(name, rarity, preciousness, count, wear )
|
||||
--[[ We don’t trust our input, so we first check if the parameters
|
||||
have the correct types and refuse to add the treasure if a
|
||||
parameter is malformed.
|
||||
What follows is a bunch of parameter checks.
|
||||
]]
|
||||
|
||||
-- check wheather name is a string
|
||||
if type(name) ~= "string" then
|
||||
minetest.log("error","[treasure] I rejected a treasure because the name was of type \""..type(name).."\" instead of \"string\".")
|
||||
return false
|
||||
end
|
||||
-- first check if rarity is even a number
|
||||
if type(rarity) == "number" then
|
||||
-- then check wheather the rarity lies in the allowed range
|
||||
if rarity < 0 or rarity > 1 then
|
||||
minetest.log("error", "[treasurer] I rejected the treasure \""..tostring(name).."\" because it’s rarity value is out of bounds. (it was "..tostring(rarity)..".)")
|
||||
return false
|
||||
end
|
||||
else
|
||||
minetest.log("error","[treasurer] I rejected the treasure \""..tostring(name).."\" because it had an illegal type of rarity. Given type was \""..type(rarity).."\".")
|
||||
return false
|
||||
end
|
||||
|
||||
-- check if preciousness is even a number
|
||||
if type(preciousness) == "number" then
|
||||
-- then check wheather the preciousness lies in the allowed range
|
||||
if preciousness < 0 or preciousness > 10 then
|
||||
minetest.log("error", "[treasurer] I rejected the treasure \""..tostring(name).."\" because it’s preciousness value is out of bounds. (it was "..tostring(preciousness)..".)")
|
||||
return false
|
||||
end
|
||||
else
|
||||
minetest.log("error","[treasurer] I rejected the treasure \""..tostring(name).."\" because it had an illegal type of preciousness. Given type was \""..type(preciousness).."\".")
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
-- first check if count is of a correct type
|
||||
if type(count) ~= "number" and type(count) ~= "nil" and type(count) ~= "table" then
|
||||
minetest.log("error", "[treasurer] I rejected the treasure \""..tostring(name).."\" because it had an illegal type of “count”. Given type was \""..type(count).."\".")
|
||||
return false
|
||||
end
|
||||
-- if count’s a table, check if it’s format is correct
|
||||
if type(count) == "table" then
|
||||
if(not (type(count[1]) == "number" and type(count[2]) == "number" and (type(count[3]) == "function" or type(count[3]) == "nil"))) then
|
||||
minetest.log("error","[treasurer] I rejected the treasure \""..tostring(name).."\" because it had a malformed table for the count parameter.")
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
-- now do the same for wear:
|
||||
-- first check if wear is of a correct type
|
||||
if type(wear) ~= "number" and type(wear) ~= "nil" and type(wear) ~= "table" then
|
||||
minetest.log("error","[treasurer] I rejected the treasure \""..tostring(name).."\" because it had an illegal type of “wear”. Given type was \""..type(wear).."\".")
|
||||
return false
|
||||
end
|
||||
-- if wear’s a table, check if it’s format is correct
|
||||
if type(wear) == "table" then
|
||||
if(not (type(wear[1]) == "number" and type(wear[2]) == "number" and (type(wear[3]) == "function" or type(wear[3]) == "nil"))) then
|
||||
minetest.log("error","[treasurer] I rejected the treasure \""..tostring(name).."\" because it had a malformed table for the wear parameter.")
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--[[ End of checks. If we reached this point of the code, all checks have been passed
|
||||
and we finally register the treasure.]]
|
||||
|
||||
-- default count is 1
|
||||
if count == nil then count = 1 end
|
||||
-- default wear is 0
|
||||
if wear == nil then wear = 0 end
|
||||
local treasure = {
|
||||
name = name,
|
||||
rarity = rarity,
|
||||
count = count,
|
||||
wear = wear,
|
||||
preciousness = preciousness,
|
||||
metadata = "",
|
||||
}
|
||||
table.insert(treasurer.treasures, treasure)
|
||||
minetest.log("info","[treasurer] Treasure successfully registered: "..name)
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
--[=[
|
||||
part 3: Treasure spawning mod (TSM) handling
|
||||
]=]
|
||||
|
||||
--[[
|
||||
treasurer.select_random_treasures - request some treasures from treasurer
|
||||
parameters:
|
||||
count: (optional) amount of items in the treasure. If this value is nil, treasurer assumes a default of 1.
|
||||
min_preciousness: (optional) don’t consider treasures with a lower preciousness. nil = no lower limit
|
||||
max_preciousness: (optional) don’t consider treasures with a higher preciousness. nil = no lower limit
|
||||
returns:
|
||||
a table of ItemStacks (the requested treasures) - may be empty
|
||||
]]
|
||||
function treasurer.select_random_treasures(count, min_preciousness, max_preciousness)
|
||||
if #treasurer.treasures == 0 and count >= 1 then
|
||||
minetest.log("info","[treasurer] I was asked to return "..count.." treasure(s) but I can’t return any because no treasure was registered to me.")
|
||||
return {}
|
||||
end
|
||||
if count == nil then count = 1 end
|
||||
local sum = 0
|
||||
local cumulate = {}
|
||||
local randoms = {}
|
||||
|
||||
-- copy treasures into helper table
|
||||
local p_treasures = {}
|
||||
for i=1,#treasurer.treasures do
|
||||
p_treasures[i] = treasurer.treasures[i]
|
||||
end
|
||||
|
||||
if(min_preciousness ~= nil) then
|
||||
-- filter out too unprecious treasures
|
||||
for t=#p_treasures,1,-1 do
|
||||
if((p_treasures[t].preciousness) < min_preciousness) then
|
||||
table.remove(p_treasures,t)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if(max_preciousness ~= nil) then
|
||||
-- filter out too precious treasures
|
||||
for t=#p_treasures,1,-1 do
|
||||
if(p_treasures[t].preciousness > max_preciousness) then
|
||||
table.remove(p_treasures,t)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for t=1,#p_treasures do
|
||||
sum = sum + p_treasures[t].rarity
|
||||
cumulate[t] = sum
|
||||
end
|
||||
for c=1,count do
|
||||
randoms[c] = math.random() * sum
|
||||
end
|
||||
|
||||
local treasures = {}
|
||||
for c=1,count do
|
||||
for t=1,#p_treasures do
|
||||
if randoms[c] < cumulate[t] then
|
||||
table.insert(treasures, p_treasures[t])
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local itemstacks = {}
|
||||
for i=1,#treasures do
|
||||
itemstacks[i] = treasurer.treasure_to_itemstack(treasures[i])
|
||||
end
|
||||
if #itemstacks < count then
|
||||
minetest.log("info","[treasurer] I was asked to return "..count.." treasure(s) but I could only return "..(#itemstacks)..".")
|
||||
end
|
||||
return itemstacks
|
||||
end
|
||||
|
||||
--[=[
|
||||
Part 4: internal functions
|
||||
]=]
|
||||
|
||||
--[[ treasurer.treasure_to_itemstack - converts a treasure table to an
|
||||
ItemStack
|
||||
parameter:
|
||||
treasure: a treasure (see format in the head of this file)
|
||||
returns:
|
||||
an ItemStack
|
||||
]]
|
||||
function treasurer.treasure_to_itemstack(treasure)
|
||||
local itemstack = {}
|
||||
itemstack.name = treasure.name
|
||||
itemstack.count = treasurer.determine_count(treasure)
|
||||
itemstack.wear = treasurer.determine_wear(treasure)
|
||||
itemstack.metadata = treasure.metadata
|
||||
|
||||
return ItemStack(itemstack)
|
||||
end
|
||||
|
||||
--[[
|
||||
This determines the count of a treasure by taking the various different
|
||||
possible types of the count value into account
|
||||
This function assumes that the treasure table is valid.
|
||||
returns: the count
|
||||
]]
|
||||
function treasurer.determine_count(treasure)
|
||||
if(type(treasure.count)=="number") then
|
||||
return treasure.count
|
||||
else
|
||||
local min,max,prob = treasure.count[1], treasure.count[2], treasure.count[3]
|
||||
if(prob == nil) then
|
||||
return(math.floor(min + math.random() * (max-min)))
|
||||
else
|
||||
return(math.floor(min + prob() * (max-min)))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--[[
|
||||
This determines the wear of a treasure by taking the various different
|
||||
possible types of the wear value into account.
|
||||
This function assumes that the treasure table is valid.
|
||||
returns: the count
|
||||
]]
|
||||
function treasurer.determine_wear(treasure)
|
||||
if(type(treasure.wear)=="number") then
|
||||
return treasure.wear
|
||||
else
|
||||
local min,max,prob = treasure.wear[1], treasure.wear[2], treasure.wear[3]
|
||||
if(prob == nil) then
|
||||
return(math.floor(min + math.random() * (max-min)))
|
||||
else
|
||||
return(math.floor(min + prob() * (max-min)))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
treasurer
|
||||
default
|
|
@ -0,0 +1,99 @@
|
|||
--[[
|
||||
This is an example Treasure Registration Mod (TRM) for the default mod.
|
||||
It is meant to use together with the default mod and the treasurer mod.
|
||||
|
||||
This TRM registers a bunch of items found in the default mod.
|
||||
|
||||
Note that the probabilities may not be very well balanced,
|
||||
this file is just there as an example. It, however, can
|
||||
still be used in actual gameplay.
|
||||
|
||||
A TRM is really nothing more than a list of item names, probabilities,
|
||||
preciousnesses, and optionally a given amount and tool wear.
|
||||
The only function ever called is treasurer.register_treasure.
|
||||
See also treasurer’s documentation for more info.
|
||||
]]
|
||||
|
||||
--[[ The following entries all use a rarity value and a count value in range
|
||||
format.
|
||||
Note that the range format is a table with two value, the first being
|
||||
the minimum and the second being the maximum value.
|
||||
]]
|
||||
--[[ The next entry means: this treasure consists of 1 to 10 gold ingots and has
|
||||
a rarity of 0.01 and a preciousness of 7 (out of 10) ]]
|
||||
treasurer.register_treasure("default:gold_ingot",0.01,7,{1,10})
|
||||
-- The following entries are similar
|
||||
treasurer.register_treasure("default:bronze_ingot",0.02,5,{1,16})
|
||||
treasurer.register_treasure("default:copper_ingot",0.06,3,{1,17})
|
||||
treasurer.register_treasure("default:steel_ingot",0.09,4,{1,20})
|
||||
treasurer.register_treasure("default:clay_brick",0.1,5,{2,12})
|
||||
treasurer.register_treasure("default:coal_lump",0.2,2,{3,10})
|
||||
treasurer.register_treasure("default:mese_crystal",0.008,9,{1,5})
|
||||
treasurer.register_treasure("dwarves:diamond",0.001,9,{1,3})
|
||||
|
||||
--[[ here is a constant (=non-random) count given
|
||||
with a rarity of 0.0001, exactly 4 diamonds spawn]]
|
||||
treasurer.register_treasure("default:diamond",0.0001,9,4)
|
||||
|
||||
-- an example of a treasure with preciousness of 10
|
||||
treasurer.register_treasure("default:mese_block",0.00002,10,1)
|
||||
|
||||
-- by the way, as you see, it is not forbidden to register the same item twice.
|
||||
|
||||
treasurer.register_treasure("default:paper",0.1,2,{3,6})
|
||||
treasurer.register_treasure("default:stick",0.1,2,{1,15})
|
||||
treasurer.register_treasure("default:stick",0.05,2,{16,33})
|
||||
treasurer.register_treasure("default:book",0.1,4,{1,2})
|
||||
|
||||
treasurer.register_treasure("default:sapling",0.05,2,{1,20})
|
||||
treasurer.register_treasure("default:junglesapling",0.03,3,{1,5})
|
||||
treasurer.register_treasure("default:apple",0.2,2,{1,7})
|
||||
|
||||
treasurer.register_treasure("default:shovel_wood",0.02,2)
|
||||
treasurer.register_treasure("default:shovel_stone",0.050,3)
|
||||
treasurer.register_treasure("default:shovel_steel",0.07,5)
|
||||
treasurer.register_treasure("default:shovel_bronze",0.006,6)
|
||||
treasurer.register_treasure("default:shovel_mese",0.0012,8)
|
||||
treasurer.register_treasure("default:shovel_diamond",0.0008,9)
|
||||
|
||||
treasurer.register_treasure("default:axe_wood",0.02,2)
|
||||
treasurer.register_treasure("default:axe_stone",0.045,3)
|
||||
treasurer.register_treasure("default:axe_steel",0.05,5)
|
||||
treasurer.register_treasure("default:axe_bronze",0.005,6)
|
||||
treasurer.register_treasure("default:axe_mese",0.0002,8)
|
||||
treasurer.register_treasure("default:axe_diamond",0.000125,9)
|
||||
|
||||
--[[ Here are some examples for wear. wear is the 5th parameter
|
||||
the format of wear is identical to the format of count
|
||||
note that the 3rd parameter (count) is nil which causes the script to use the default value
|
||||
We could as well have written an 1 here.
|
||||
]]
|
||||
treasurer.register_treasure("default:axe_wood",0.04,1,nil,{100,10000}) -- wear = randomly between 100 and 10000
|
||||
treasurer.register_treasure("default:axe_stone",0.09,2,nil,{500,11000})
|
||||
treasurer.register_treasure("default:axe_steel",0.1,4,nil,{600,18643})
|
||||
treasurer.register_treasure("default:axe_bronze",0.01,5,nil,{750,20000})
|
||||
treasurer.register_treasure("default:axe_mese",0.0002,7,nil,{1000,22000})
|
||||
treasurer.register_treasure("default:axe_diamond",0.0001,8,nil,{2000,30000})
|
||||
|
||||
treasurer.register_treasure("default:pick_wood",0.005,2)
|
||||
treasurer.register_treasure("default:pick_stone",0.018,3)
|
||||
treasurer.register_treasure("default:pick_steel",0.02,5)
|
||||
treasurer.register_treasure("default:pick_bronze",0.004,6)
|
||||
treasurer.register_treasure("default:pick_mese",0.008,8)
|
||||
treasurer.register_treasure("default:pick_diamond",0.005,9)
|
||||
|
||||
treasurer.register_treasure("default:sword_wood",0.001,2)
|
||||
treasurer.register_treasure("default:sword_stone",0.016,3)
|
||||
treasurer.register_treasure("default:sword_steel",0.02,5)
|
||||
treasurer.register_treasure("default:sword_bronze",0.015,6)
|
||||
treasurer.register_treasure("default:sword_mese",0.007,8)
|
||||
treasurer.register_treasure("default:sword_diamond",0.0035,9)
|
||||
|
||||
treasurer.register_treasure("default:rail",0.01,5,15)
|
||||
treasurer.register_treasure("default:rail",0.02,5,{1,5})
|
||||
treasurer.register_treasure("default:fence_wood",0.1,4,{1,7})
|
||||
|
||||
-- If the count is omitted, it deaults to 1.
|
||||
treasurer.register_treasure("default:sign_wall",0.1,4)
|
||||
treasurer.register_treasure("default:ladder",0.1,3,{1,2})
|
||||
treasurer.register_treasure("default:torch",0.2,2,{1,5})
|
|
@ -0,0 +1,2 @@
|
|||
treasurer
|
||||
default
|
|
@ -0,0 +1,142 @@
|
|||
--[[
|
||||
This is an example treasure spawning mod (TSM) for the default mod.
|
||||
It needs the mods “treasurer” and “default” to work.
|
||||
For an example, it is kinda advanced.
|
||||
|
||||
A TSM’s task is to somehow bring treasures (which are ItemStacks) into the world.
|
||||
This is also called “spawning treasures”.
|
||||
How it does this task is completely free to the programmer of the TSM.
|
||||
|
||||
This TSM spawns the treasures by placing chests (default:chest) between 20 and 200 node lengths below the water surface. This cau
|
||||
The chests are provided by the default mod, therefore this TSM depends on the default mod.
|
||||
The treasures are requested from the treasurer mod. The TSM asks the treasurer mod for some treasures.
|
||||
|
||||
However, the treasurer mod comes itself with no treasures whatsoever. You need another mod which tells the treasurer what treasures to add. These mods are called “treasure registration mods” (TRMs).
|
||||
For this, there is another example mod, called “trm_default_example”, which registers a bunch of items of the default mod, like default:gold_ingot.
|
||||
]]
|
||||
|
||||
--[[ here are some configuration variables ]]
|
||||
|
||||
local chests_per_chunk = 15 -- number of chests per chunk. 15 is a bit high, an actual mod might have a lower number
|
||||
local h_min = -200 -- minimum chest spawning height, relative to water_level
|
||||
local h_max = -20 -- maximum chest spawning height, relative to water_level
|
||||
local t_min = 1 -- minimum amount of treasures found in a chest
|
||||
local t_max = 6 -- maximum amount of treasures found in a chest
|
||||
|
||||
--[[ here comes the generation code
|
||||
the interesting part which involes treasurer comes way below
|
||||
]]
|
||||
minetest.register_on_generated(function(minp, maxp, seed)
|
||||
-- get the water level and convert it to a number
|
||||
local water_level = minetest.setting_get("water_level")
|
||||
if water_level == nil or type(water_level) ~= "number" then
|
||||
water_level = 1
|
||||
else
|
||||
water_level = tonumber(water_level)
|
||||
end
|
||||
|
||||
-- chests minimum and maximum spawn height
|
||||
local height_min = water_level + h_min
|
||||
local height_max = water_level + h_max
|
||||
|
||||
if(maxp.y < height_min or minp.y > height_max) then
|
||||
return
|
||||
end
|
||||
local y_min = math.max(minp.y, height_min)
|
||||
local y_max = math.min(maxp.y, height_max)
|
||||
for i=1, chests_per_chunk do
|
||||
local pos = {x=math.random(minp.x,maxp.x),z=math.random(minp.z,maxp.z), y=minp.y}
|
||||
local env = minetest.env
|
||||
|
||||
-- Find ground level
|
||||
local ground = nil
|
||||
local top = y_max
|
||||
if env:get_node({x=pos.x,y=y_max,z=pos.z}).name ~= "air" and env:get_node({x=pos.x,y=y_max,z=pos.z}).name ~= "default:water_source" and env:get_node({x=pos.x,y=y_max,z=pos.z}).name ~= "default:lava_source" then
|
||||
for y=y_max,y_min,-1 do
|
||||
local p = {x=pos.x,y=y,z=pos.z}
|
||||
if env:get_node(p).name == "air" or env:get_node(p).name == "default:water_source" or env:get_node(p) == "default:lava_source" then
|
||||
top = y
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
for y=top,y_min,-1 do
|
||||
local p = {x=pos.x,y=y,z=pos.z}
|
||||
if env:get_node(p).name ~= "air" and env:get_node(p).name ~= "default:water_source" and env:get_node(p).name ~= "default:lava_source" then
|
||||
ground = y
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if(ground~=nil) then
|
||||
local chest_pos = {x=pos.x,y=ground+1, z=pos.z}
|
||||
local nn = minetest.get_node(chest_pos).name -- chest node name (before it becomes a chest)
|
||||
if nn == "air" or nn == "default:water_source" then
|
||||
-->>>> chest spawning starts here <<<<--
|
||||
|
||||
-- first: spawn the chest
|
||||
local chest = {}
|
||||
chest.name = "default:chest"
|
||||
|
||||
-- secondly: rotate the chest
|
||||
-- find possible faces
|
||||
local xp, xm, zp, zm
|
||||
xp = minetest.get_node({x=pos.x+1,y=ground+1, z=pos.z})
|
||||
xm = minetest.get_node({x=pos.x-1,y=ground+1, z=pos.z})
|
||||
zp = minetest.get_node({x=pos.x,y=ground+1, z=pos.z+1})
|
||||
zm = minetest.get_node({x=pos.x,y=ground+1, z=pos.z-1})
|
||||
|
||||
local facedirs = {}
|
||||
if(xp.name=="air" or xp.name=="default:water_source") then
|
||||
table.insert(facedirs, minetest.dir_to_facedir({x=-1,y=0,z=0}))
|
||||
end
|
||||
if(xm.name=="air" or xm.name=="default:water_source") then
|
||||
|
||||
table.insert(facedirs, minetest.dir_to_facedir({x=1,y=0,z=0}))
|
||||
end
|
||||
if(zp.name=="air" or zp.name=="default:water_source") then
|
||||
table.insert(facedirs, minetest.dir_to_facedir({x=0,y=0,z=-1}))
|
||||
end
|
||||
if(zm.name=="air" or zm.name=="default:water_source") then
|
||||
table.insert(facedirs, minetest.dir_to_facedir({x=0,y=0,z=1}))
|
||||
end
|
||||
|
||||
-- choose a random face (if possible)
|
||||
if(#facedirs == 0) then
|
||||
minetest.set_node({x=pos.x,y=ground+1, z=pos.z+1},{name=nn})
|
||||
chest.param2 = minetest.dir_to_facedir({x=0,y=0,z=1})
|
||||
else
|
||||
chest.param2 = facedirs[math.floor(math.random(#facedirs))]
|
||||
end
|
||||
|
||||
-- Lastly: place the chest
|
||||
minetest.set_node(chest_pos,chest)
|
||||
|
||||
--->>>>>>>>>> At this point we are finally going to involve Treasurer. <<<<<<<<<<<<<<--
|
||||
-- determine a random amount of treasures
|
||||
local treasure_amount = math.ceil(math.random(t_min, t_max))
|
||||
|
||||
-- calculate preciousness of treasures based on height. higher = more precious
|
||||
local height = math.abs(h_min) - math.abs(h_max)
|
||||
local y_norm = (ground+1) - h_min
|
||||
local scale = 1 - (y_norm/height)
|
||||
local minp = scale*4 -- minimal preciousness: 0..4
|
||||
local maxp = scale*4+2.1 -- maximum preciousness: 2.1..6.1
|
||||
|
||||
-- now use these values to finally request the treasure(s)
|
||||
local treasures = treasurer.select_random_treasures(treasure_amount,minp,maxp)
|
||||
-- That’s it!
|
||||
|
||||
-- Get the inventory of the chest to place the treasures in
|
||||
local meta = minetest.get_meta(chest_pos)
|
||||
local inv = meta:get_inventory()
|
||||
|
||||
--[[ Now that we got both our treasures and the chest’s inventory,
|
||||
let’s place the treasures one for one into it. ]]
|
||||
for i=1,#treasures do
|
||||
inv:set_stack("main",i,treasures[i])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
Binary file not shown.
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 6.3 KiB |
Loading…
Reference in New Issue