|
@ -177,6 +177,29 @@ minetest.register_abm({
|
|||
end
|
||||
})
|
||||
|
||||
minetest.register_abm({
|
||||
nodenames = {"default:acaciasapling"},
|
||||
interval = 1,
|
||||
chance = 1,
|
||||
action = function(pos, node)
|
||||
local nu = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name
|
||||
local is_soil = minetest.get_item_group(nu, "soil")
|
||||
if is_soil == 0 then
|
||||
return
|
||||
end
|
||||
|
||||
minetest.log("action", "A acacia sapling grows into a tree at "..minetest.pos_to_string(pos))
|
||||
local vm = minetest.get_voxel_manip()
|
||||
local minp, maxp = vm:read_from_map({x=pos.x-16, y=pos.y-1, z=pos.z-16}, {x=pos.x+16, y=pos.y+16, z=pos.z+16})
|
||||
local a = VoxelArea:new{MinEdge=minp, MaxEdge=maxp}
|
||||
local data = vm:get_data()
|
||||
default.grow_acaciatree(data, a, pos, math.random(1,100000))
|
||||
vm:set_data(data)
|
||||
vm:write_to_map(data)
|
||||
vm:update_map()
|
||||
end
|
||||
})
|
||||
|
||||
--
|
||||
-- Lavacooling
|
||||
--
|
||||
|
|
|
@ -1,5 +1,15 @@
|
|||
-- mods/default/nodes.lua
|
||||
|
||||
-- cylinder nodebox
|
||||
detail_level = 16
|
||||
local cylbox = {}
|
||||
local detail = detail_level
|
||||
local sehne
|
||||
for i = 1, detail-1 do
|
||||
sehne = math.sqrt(0.25 - (((i/detail)-0.5)^2))
|
||||
cylbox[i]={(i/detail)-0.5, -0.5, -sehne, (i/detail)+(1/detail)-0.5, 0.5, sehne}
|
||||
end
|
||||
|
||||
minetest.register_node("default:stone", {
|
||||
description = "Stone",
|
||||
tiles = {"default_stone.png"},
|
||||
|
@ -222,7 +232,7 @@ minetest.register_node("default:clay", {
|
|||
tiles = {"default_clay.png"},
|
||||
is_ground_content = true,
|
||||
groups = {crumbly=3},
|
||||
drop = 'default:clay_lump 4',
|
||||
drop = 'default:clay_lump 8',
|
||||
sounds = default.node_sound_dirt_defaults(),
|
||||
})
|
||||
|
||||
|
@ -241,7 +251,17 @@ minetest.register_node("default:tree", {
|
|||
is_ground_content = false,
|
||||
groups = {tree=1,choppy=2,oddly_breakable_by_hand=1,flammable=2},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
on_place = minetest.rotate_node
|
||||
on_place = minetest.rotate_node,
|
||||
paramtype = "light",
|
||||
drawtype = "nodebox",
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = cylbox,
|
||||
},
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = cylbox,
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_node("default:jungletree", {
|
||||
|
@ -251,9 +271,86 @@ minetest.register_node("default:jungletree", {
|
|||
is_ground_content = false,
|
||||
groups = {tree=1,choppy=2,oddly_breakable_by_hand=1,flammable=2},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
on_place = minetest.rotate_node
|
||||
on_place = minetest.rotate_node,
|
||||
paramtype = "light",
|
||||
drawtype = "nodebox",
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = cylbox,
|
||||
},
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = cylbox,
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_node("default:acaciatree", {
|
||||
description = "Acacia Tree",
|
||||
tiles = {"default_acaciatree_top.png", "default_acaciatree_top.png", "default_acaciatree.png"},
|
||||
paramtype2 = "facedir",
|
||||
is_ground_content = false,
|
||||
groups = {tree=1,choppy=2,oddly_breakable_by_hand=1,flammable=2},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
on_place = minetest.rotate_node,
|
||||
paramtype = "light",
|
||||
drawtype = "nodebox",
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = cylbox,
|
||||
},
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = cylbox,
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_node("default:acaciatree_t", {
|
||||
description = "Acacia Tree",
|
||||
tiles = {"default_acaciatree.png"},
|
||||
paramtype2 = "facedir",
|
||||
is_ground_content = false,
|
||||
groups = {tree=1,choppy=2,oddly_breakable_by_hand=1,flammable=2,not_in_creative_inventory=1},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
on_place = minetest.rotate_node,
|
||||
paramtype = "light",
|
||||
drop = 'default:acaciatree',
|
||||
})
|
||||
|
||||
minetest.register_node("default:acaciawood", {
|
||||
description = "Acaciawood Planks",
|
||||
tiles = {"default_acaciawood.png"},
|
||||
groups = {choppy=2,oddly_breakable_by_hand=2,flammable=3,wood=1},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
})
|
||||
|
||||
minetest.register_node("default:acacialeaves", {
|
||||
description = "Acacia Leaves",
|
||||
drawtype = "allfaces_optional",
|
||||
visual_scale = 1.3,
|
||||
tiles = {"default_acacialeaves.png"},
|
||||
paramtype = "light",
|
||||
waving = 1,
|
||||
is_ground_content = false,
|
||||
groups = {snappy=3, leafdecay=3, flammable=2, leaves=1},
|
||||
drop = {
|
||||
max_items = 1,
|
||||
items = {
|
||||
{
|
||||
-- player will get sapling with 1/20 chance
|
||||
items = {'default:acaciasapling'},
|
||||
rarity = 20,
|
||||
},
|
||||
{
|
||||
-- player will get leaves only if he get no saplings,
|
||||
-- this is because max_items is 1
|
||||
items = {'default:acacialeaves'},
|
||||
}
|
||||
}
|
||||
},
|
||||
sounds = default.node_sound_leaves_defaults(),
|
||||
})
|
||||
|
||||
|
||||
minetest.register_node("default:junglewood", {
|
||||
description = "Junglewood Planks",
|
||||
tiles = {"default_junglewood.png"},
|
||||
|
@ -1416,3 +1513,21 @@ minetest.register_node("default:snowblock", {
|
|||
dug = {name="default_snow_footstep", gain=0.75},
|
||||
}),
|
||||
})
|
||||
|
||||
minetest.register_node("default:acaciasapling", {
|
||||
description = "Acacia Sapling",
|
||||
drawtype = "plantlike",
|
||||
use_texture_alpha = true,
|
||||
visual_scale = 1.0,
|
||||
tiles = {"default_acaciasapling.png"},
|
||||
inventory_image = "default_acaciasapling.png",
|
||||
wield_image = "default_acaciasapling.png",
|
||||
paramtype = "light",
|
||||
walkable = false,
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = {-0.3, -0.5, -0.3, 0.3, 0.35, 0.3}
|
||||
},
|
||||
groups = {snappy=2,dig_immediate=3,flammable=2,attached_node=1},
|
||||
sounds = default.node_sound_leaves_defaults(),
|
||||
})
|
||||
|
|
After Width: | Height: | Size: 340 B |
After Width: | Height: | Size: 454 B |
After Width: | Height: | Size: 682 B |
After Width: | Height: | Size: 731 B |
After Width: | Height: | Size: 364 B |
|
@ -1,88 +1,112 @@
|
|||
--------------------------------------------------------------------------------
|
||||
--------------------------------------------------------------------------------
|
||||
-------Minetest Time--kazea's code tweeked by cg72 with help from crazyR--------
|
||||
--------------------------------------------------------------------------------
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
||||
player_hud = {}
|
||||
player_hud.time = {}
|
||||
player_hud.lag = {}
|
||||
|
||||
local function explode(sep, input)
|
||||
local t={}
|
||||
local i=0
|
||||
for k in string.gmatch(input,"([^"..sep.."]+)") do
|
||||
t[i]=k;i=i+1
|
||||
end
|
||||
return t
|
||||
end
|
||||
local function get_lag()
|
||||
local arrayoutput = explode(", ",minetest.get_server_status())
|
||||
local arrayoutput = explode("=",arrayoutput[4])
|
||||
return "Current Lag: "..arrayoutput[1].." sec"
|
||||
end
|
||||
local function floormod ( x, y )
|
||||
return (math.floor(x) % y);
|
||||
end
|
||||
|
||||
local function get_time ( )
|
||||
local dn, secs, s, m, h
|
||||
secs = (60*60*24*minetest.env:get_timeofday());
|
||||
s = floormod(secs, 60);
|
||||
m = floormod(secs/60, 60);
|
||||
h = floormod(secs/3600, 60);
|
||||
dn = "am";
|
||||
if h >= 12 then
|
||||
h = h - 12;
|
||||
dn = "pm";
|
||||
end
|
||||
return ("Minetest time %02d:%02d "..dn):format(h, m, dn);
|
||||
end
|
||||
local function generatehud(player)
|
||||
local name = player:get_player_name()
|
||||
player_hud.time[name] = player:hud_add({
|
||||
hud_elem_type = "text",
|
||||
name = "player_hud:time",
|
||||
position = {x=0.20, y=0.965},
|
||||
text = get_time(),
|
||||
scale = {x=100,y=100},
|
||||
alignment = {x=0,y=0},
|
||||
number = 0xFFFFFF,
|
||||
})
|
||||
player_hud.lag[name] = player:hud_add({
|
||||
hud_elem_type = "text",
|
||||
name = "player_hud:lag",
|
||||
position = {x=0.80, y=0.965},
|
||||
text = get_lag(),
|
||||
scale = {x=100,y=100},
|
||||
alignment = {x=0,y=0},
|
||||
number = 0xFFFFFF,
|
||||
})
|
||||
end
|
||||
|
||||
local function removehud(player)
|
||||
local name = player:get_player_name()
|
||||
if player_hud.time[name] then
|
||||
--------------------------------------------------------------------------------
|
||||
--------------------------------------------------------------------------------
|
||||
-------Minetest Time--kazea's code tweaked by cg72 with help from crazyR--------
|
||||
----------------Zeno` simplified some math and additional tweaks ---------------
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
player_hud = {}
|
||||
player_hud.time = {}
|
||||
player_hud.lag = {}
|
||||
local timer = 0;
|
||||
local function explode(sep, input)
|
||||
local t={}
|
||||
local i=0
|
||||
for k in string.gmatch(input,"([^"..sep.."]+)") do
|
||||
t[i]=k;i=i+1
|
||||
end
|
||||
return t
|
||||
end
|
||||
local function floormod ( x, y )
|
||||
return (math.floor(x) % y);
|
||||
end
|
||||
local function get_lag(raw)
|
||||
local a = explode(", ",minetest.get_server_status())
|
||||
local b = explode("=",a[4])
|
||||
local lagnum = tonumber(string.format("%.2f", b[1]))
|
||||
local clag = 0
|
||||
if lagnum > clag then
|
||||
clag = lagnum
|
||||
else
|
||||
clag = clag * .75
|
||||
end
|
||||
if raw ~= nil then
|
||||
return clag
|
||||
else
|
||||
return ("Current Lag: %s sec"):format(clag);
|
||||
end
|
||||
end
|
||||
local function get_time ()
|
||||
local t, m, h, d
|
||||
t = 24*60*minetest.get_timeofday()
|
||||
m = floormod(t, 60)
|
||||
t = t / 60
|
||||
h = floormod(t, 60)
|
||||
|
||||
|
||||
if h == 12 then
|
||||
d = "pm"
|
||||
elseif h >= 13 then
|
||||
h = h - 12
|
||||
d = "pm"
|
||||
elseif h == 0 then
|
||||
h = 12
|
||||
d = "am"
|
||||
else
|
||||
d = "am"
|
||||
end
|
||||
return ("Minetest time %02d:%02d %s"):format(h, m, d);
|
||||
end
|
||||
local function generatehud(player)
|
||||
local name = player:get_player_name()
|
||||
player_hud.time[name] = player:hud_add({
|
||||
hud_elem_type = "text",
|
||||
name = "player_hud:time",
|
||||
position = {x=0.20, y=0.965},
|
||||
text = get_time(),
|
||||
scale = {x=100,y=100},
|
||||
alignment = {x=0,y=0},
|
||||
number = 0xFFFFFF,
|
||||
})
|
||||
player_hud.lag[name] = player:hud_add({
|
||||
hud_elem_type = "text",
|
||||
name = "player_hud:lag",
|
||||
position = {x=0.80, y=0.965},
|
||||
text = get_lag(),
|
||||
scale = {x=100,y=100},
|
||||
alignment = {x=0,y=0},
|
||||
number = 0xFFFFFF,
|
||||
})
|
||||
end
|
||||
local function updatehud(player, dtime)
|
||||
local name = player:get_player_name()
|
||||
timer = timer + dtime;
|
||||
if (timer >= 1.0) then
|
||||
timer = 0;
|
||||
if player_hud.time[name] then player:hud_change(player_hud.time[name], "text", get_time()) end
|
||||
if player_hud.lag[name] then player:hud_change(player_hud.lag[name], "text", get_lag()) end
|
||||
end
|
||||
end
|
||||
local function removehud(player)
|
||||
local name = player:get_player_name()
|
||||
if player_hud.time[name] then
|
||||
player:hud_remove(player_hud.time[name])
|
||||
end
|
||||
if player_hud.lag[name] then
|
||||
player:hud_remove(player_hud.lag[name])
|
||||
end
|
||||
end
|
||||
minetest.register_globalstep(function ( dtime )
|
||||
for _,player in ipairs(minetest.get_connected_players()) do
|
||||
updatehud(player, dtime)
|
||||
end
|
||||
end);
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
minetest.after(0,generatehud,player)
|
||||
end)
|
||||
minetest.register_on_leaveplayer(function(player)
|
||||
minetest.after(1,removehud,player)
|
||||
end)
|
||||
|
||||
|
||||
player:hud_remove(player_hud.time[name])
|
||||
end
|
||||
if player_hud.lag[name] then
|
||||
player:hud_remove(player_hud.lag[name])
|
||||
end
|
||||
end
|
||||
|
||||
local timer = 0;
|
||||
minetest.register_globalstep(function ( dtime )
|
||||
timer = timer + dtime;
|
||||
if (timer >= 1.0) then
|
||||
timer = 0;
|
||||
for _,player in ipairs(minetest.get_connected_players()) do
|
||||
removehud(player)
|
||||
generatehud(player)
|
||||
end
|
||||
end
|
||||
end);
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
minetest.after(0,generatehud,player)
|
||||
end)
|
|
@ -148,3 +148,47 @@ function default.grow_jungletree(data, a, pos, seed)
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
function default.grow_acaciatree(data, a, pos, seed) --watershed_acaciatree(x, y, z, area, data)
|
||||
local c_wsactree = minetest.get_content_id("default:acaciatree")
|
||||
local c_wsactree2 = minetest.get_content_id("default:acaciatree_t")
|
||||
local c_wsacleaf = minetest.get_content_id("default:acacialeaves")
|
||||
local xa = pos.x
|
||||
local ya = pos.y
|
||||
local za = pos.z
|
||||
|
||||
for j = -1, 6 do
|
||||
if j == 6 then
|
||||
for i = -4, 4 do
|
||||
for k = -4, 4 do
|
||||
if not (i == 0 or k == 0) then
|
||||
if math.random(7) ~= 2 then
|
||||
local vil = a:index(xa + i, ya + j, za + k)
|
||||
data[vil] = c_wsacleaf
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif j == 5 then
|
||||
for i = -2, 2, 4 do
|
||||
for k = -2, 2, 4 do
|
||||
local vit = a:index(xa + i, ya + j, za + k)
|
||||
data[vit] = c_wsactree2
|
||||
end
|
||||
end
|
||||
elseif j == 4 then
|
||||
for i = -1, 1 do
|
||||
for k = -1, 1 do
|
||||
if math.abs(i) + math.abs(k) == 2 then
|
||||
local vit = a:index(xa + i, ya + j, za + k)
|
||||
data[vit] = c_wsactree2
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
local vit = a:index(xa, ya + j + 1, za)
|
||||
data[vit] = c_wsactree
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -9,8 +9,8 @@ dofile(minetest.get_modpath(minetest.get_current_modname()).."/nodes.lua")
|
|||
c_air = minetest.get_content_id("air")
|
||||
c_grass = minetest.get_content_id("default:dirt_with_grass")
|
||||
c_dry_grass = minetest.get_content_id("mg:dirt_with_dry_grass")
|
||||
c_dirt_snow = minetest.get_content_id("default:dirt_with_snow")
|
||||
c_snow = minetest.get_content_id("default:snow")
|
||||
c_dirt_snow = minetest.get_content_id("default:dirt_with_grass") --was snow
|
||||
c_snow = minetest.get_content_id("air") --was snow
|
||||
c_sapling = minetest.get_content_id("default:sapling")
|
||||
c_tree = minetest.get_content_id("default:tree")
|
||||
c_leaves = minetest.get_content_id("default:leaves")
|
||||
|
@ -26,7 +26,7 @@ c_pineleaves = minetest.get_content_id("mg:pineleaves")
|
|||
c_dirt = minetest.get_content_id("default:dirt")
|
||||
c_stone = minetest.get_content_id("default:stone")
|
||||
c_water = minetest.get_content_id("default:water_source")
|
||||
c_ice = minetest.get_content_id("default:ice")
|
||||
c_ice = minetest.get_content_id("default:water_source") --was ice
|
||||
c_sand = minetest.get_content_id("default:sand")
|
||||
c_sandstone = minetest.get_content_id("default:sandstone")
|
||||
c_desert_sand = minetest.get_content_id("default:desert_sand")
|
||||
|
@ -129,7 +129,7 @@ local function add_leaves(data, vi, c_leaves, c_snow)
|
|||
end
|
||||
|
||||
function add_tree(data, a, x, y, z, minp, maxp, pr)
|
||||
local th = pr:next(3, 4)
|
||||
local th = pr:next(4, 10)
|
||||
for yy=math.max(minp.y, y), math.min(maxp.y, y+th) do
|
||||
local vi = a:index(x, yy, z)
|
||||
data[vi] = c_tree
|
||||
|
@ -157,7 +157,7 @@ function add_tree(data, a, x, y, z, minp, maxp, pr)
|
|||
end
|
||||
|
||||
function add_jungletree(data, a, x, y, z, minp, maxp, pr)
|
||||
local th = pr:next(7, 11)
|
||||
local th = pr:next(9, 26)
|
||||
for yy=math.max(minp.y, y), math.min(maxp.y, y+th) do
|
||||
local vi = a:index(x, yy, z)
|
||||
data[vi] = c_jungletree
|
||||
|
@ -249,7 +249,7 @@ end
|
|||
|
||||
function add_pinetree(data, a, x, y, z, minp, maxp, pr, snow)
|
||||
if snow == nil then snow = c_snow end
|
||||
local th = pr:next(9, 13)
|
||||
local th = pr:next(9, 20)
|
||||
for yy=math.max(minp.y, y), math.min(maxp.y, y+th) do
|
||||
local vi = a:index(x, yy, z)
|
||||
data[vi] = c_pinetree
|
||||
|
|
|
@ -1,8 +1,33 @@
|
|||
-- cylinder nodebox
|
||||
detail_level = 16
|
||||
local cylbox = {}
|
||||
local detail = detail_level
|
||||
local sehne
|
||||
for i = 1, detail-1 do
|
||||
sehne = math.sqrt(0.25 - (((i/detail)-0.5)^2))
|
||||
cylbox[i]={(i/detail)-0.5, -0.5, -sehne, (i/detail)+(1/detail)-0.5, 0.5, sehne}
|
||||
end
|
||||
|
||||
|
||||
|
||||
minetest.register_node("mg:savannatree", {
|
||||
description = "Savannawood Tree",
|
||||
tiles = {"mg_dry_tree_top.png", "mg_dry_tree_top.png", "mg_dry_tree.png"},
|
||||
paramtype2 = "facedir",
|
||||
is_ground_content = false,
|
||||
groups = {tree=1,choppy=2,oddly_breakable_by_hand=1,flammable=2},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
on_place = minetest.rotate_node,
|
||||
paramtype = "light",
|
||||
drawtype = "nodebox",
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = cylbox,
|
||||
},
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = cylbox,
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_node("mg:savannaleaves", {
|
||||
|
@ -86,11 +111,25 @@ minetest.register_node("mg:dirt_with_dry_grass", {
|
|||
}),
|
||||
})
|
||||
|
||||
|
||||
minetest.register_node("mg:pinetree", {
|
||||
description = "Pine Tree",
|
||||
tiles = {"mg_pine_tree_top.png", "mg_pine_tree_top.png", "mg_pine_tree.png"},
|
||||
paramtype2 = "facedir",
|
||||
is_ground_content = false,
|
||||
groups = {tree=1,choppy=2,oddly_breakable_by_hand=1,flammable=2},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
on_place = minetest.rotate_node,
|
||||
paramtype = "light",
|
||||
drawtype = "nodebox",
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = cylbox,
|
||||
},
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = cylbox,
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_node("mg:pineleaves", {
|
||||
|
|
|
@ -17,7 +17,7 @@ mg.register_tree({
|
|||
mg.register_tree({
|
||||
max_biome_humidity = -0.4,
|
||||
min_biome_temperature = 0.4,
|
||||
min_height = 2,
|
||||
min_height = 4,
|
||||
max_height = 30,
|
||||
grows_on = c_desert_sand,
|
||||
chance = 50,
|
||||
|
@ -34,7 +34,7 @@ mg.register_tree({
|
|||
min_biome_humidity = -0.4,
|
||||
max_biome_humidity = 0.4,
|
||||
min_biome_temperature = 0.4,
|
||||
min_height = 2,
|
||||
min_height = 4,
|
||||
max_height = 12,
|
||||
grows_on = c_dry_grass,
|
||||
chance = 1000,
|
||||
|
@ -57,7 +57,7 @@ mg.register_tree({
|
|||
max_biome_humidity = 0.4,
|
||||
min_biome_temperature = 0.4,
|
||||
min_height = 2,
|
||||
max_height = 40,
|
||||
max_height = 6,
|
||||
grows_on = c_dry_grass,
|
||||
chance = 1500,
|
||||
grow = add_savannabush
|
||||
|
@ -66,7 +66,7 @@ mg.register_tree({
|
|||
mg.register_tree({
|
||||
min_biome_humidity = 0.4,
|
||||
min_biome_temperature = 0.4,
|
||||
min_height = 1,
|
||||
min_height = 4,
|
||||
max_height = 40,
|
||||
grows_on = c_grass,
|
||||
chance = 14,
|
||||
|
@ -76,8 +76,8 @@ mg.register_tree({
|
|||
mg.register_tree({
|
||||
min_biome_humidity = 0.4,
|
||||
min_biome_temperature = 0.4,
|
||||
min_height = 1,
|
||||
max_height = 25,
|
||||
min_height = 8,
|
||||
max_height = 27,
|
||||
grows_on = c_grass,
|
||||
chance = 16,
|
||||
grow = add_jungletree
|
||||
|
@ -102,7 +102,7 @@ mg.register_tree({
|
|||
mg.register_tree({
|
||||
min_biome_humidity = -0.4,
|
||||
max_biome_temperature = -0.4,
|
||||
min_height = 3,
|
||||
min_height = 5,
|
||||
max_height = 55,
|
||||
grows_on = c_dirt_snow,
|
||||
chance = 40,
|
||||
|
@ -112,7 +112,7 @@ mg.register_tree({
|
|||
mg.register_tree({
|
||||
max_biome_humidity = -0.4,
|
||||
max_biome_temperature = -0.4,
|
||||
min_height = 3,
|
||||
min_height = 5,
|
||||
max_height = 55,
|
||||
grows_on = c_dirt_snow,
|
||||
chance = 500,
|
||||
|
@ -123,7 +123,7 @@ mg.register_tree({
|
|||
max_biome_humidity = -0.4,
|
||||
min_biome_temperature = -0.4,
|
||||
max_biome_temperature = 0.4,
|
||||
min_height = 1,
|
||||
min_height = 4,
|
||||
max_height = 40,
|
||||
grows_on = c_grass,
|
||||
chance = 250,
|
||||
|
@ -134,7 +134,7 @@ mg.register_tree({
|
|||
max_biome_humidity = -0.4,
|
||||
min_biome_temperature = -0.4,
|
||||
max_biome_temperature = 0.4,
|
||||
min_height = 1,
|
||||
min_height = 4,
|
||||
max_height = 40,
|
||||
grows_on = c_grass,
|
||||
chance = 60,
|
||||
|
@ -151,7 +151,7 @@ mg.register_tree({
|
|||
min_biome_humidity = 0.4,
|
||||
min_biome_temperature = -0.4,
|
||||
max_biome_temperature = 0.4,
|
||||
min_height = 1,
|
||||
min_height = 4,
|
||||
max_height = 40,
|
||||
grows_on = c_grass,
|
||||
chance = 250,
|
||||
|
@ -162,7 +162,7 @@ mg.register_tree({
|
|||
min_biome_humidity = 0.4,
|
||||
min_biome_temperature = -0.4,
|
||||
max_biome_temperature = 0.4,
|
||||
min_height = 3,
|
||||
min_height = 4,
|
||||
max_height = 40,
|
||||
grows_on = c_grass,
|
||||
chance = 3,
|
||||
|
@ -180,7 +180,7 @@ mg.register_tree({
|
|||
max_biome_humidity = 0.4,
|
||||
min_biome_temperature = -0.4,
|
||||
max_biome_temperature = 0.4,
|
||||
min_height = 3,
|
||||
min_height = 4,
|
||||
max_height = 40,
|
||||
grows_on = c_grass,
|
||||
chance = 20,
|
||||
|
@ -189,7 +189,7 @@ mg.register_tree({
|
|||
|
||||
mg.register_tree({
|
||||
min_height = 1,
|
||||
max_height = 1,
|
||||
max_height = 6,
|
||||
grows_on = c_grass,
|
||||
chance = 10,
|
||||
grow = function(data, a, x, y, z, minp, maxp, pr)
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
*~
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
Unified inventory
|
||||
=================
|
||||
|
||||
Unified Inventory replaces the default survival and creative inventory.
|
||||
It adds a nicer interface and a number of features, such as a crafting guide.
|
||||
|
||||
License
|
||||
=======
|
||||
|
||||
Copyright (C) 2012-2014 Maciej Kasatkin (RealBadAngel)
|
||||
|
||||
Unified inventory code is licensed under the GNU LGPLv2+.
|
||||
|
||||
Licenses for textures:
|
||||
|
||||
VanessaE: (WTFPL)
|
||||
* ui\_group.png
|
||||
|
||||
RealBadAngel: (WTFPL)
|
||||
* Everything else.
|
||||
|
||||
|
|
@ -0,0 +1,185 @@
|
|||
|
||||
-- Create detached creative inventory after loading all mods
|
||||
minetest.after(0.01, function()
|
||||
local rev_aliases = {}
|
||||
for source, target in pairs(minetest.registered_aliases) do
|
||||
if not rev_aliases[target] then rev_aliases[target] = {} end
|
||||
table.insert(rev_aliases[target], source)
|
||||
end
|
||||
unified_inventory.items_list = {}
|
||||
for name, def in pairs(minetest.registered_items) do
|
||||
if (not def.groups.not_in_creative_inventory or
|
||||
def.groups.not_in_creative_inventory == 0) and
|
||||
def.description and def.description ~= "" then
|
||||
table.insert(unified_inventory.items_list, name)
|
||||
local all_names = rev_aliases[name] or {}
|
||||
table.insert(all_names, name)
|
||||
for _, name in ipairs(all_names) do
|
||||
local recipes = minetest.get_all_craft_recipes(name)
|
||||
if recipes then
|
||||
for _, recipe in ipairs(recipes) do
|
||||
unified_inventory.register_craft(recipe)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
table.sort(unified_inventory.items_list)
|
||||
unified_inventory.items_list_size = #unified_inventory.items_list
|
||||
print("Unified Inventory. inventory size: "..unified_inventory.items_list_size)
|
||||
for _, name in ipairs(unified_inventory.items_list) do
|
||||
local def = minetest.registered_items[name]
|
||||
if type(def.drop) == "string" then
|
||||
local dstack = ItemStack(def.drop)
|
||||
if not dstack:is_empty() and dstack:get_name() ~= name then
|
||||
unified_inventory.register_craft({
|
||||
type = "digging",
|
||||
items = {name},
|
||||
output = def.drop,
|
||||
width = 0,
|
||||
})
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
-- load_home
|
||||
local function load_home()
|
||||
local input = io.open(unified_inventory.home_filename, "r")
|
||||
if input then
|
||||
while true do
|
||||
local x = input:read("*n")
|
||||
if x == nil then
|
||||
break
|
||||
end
|
||||
local y = input:read("*n")
|
||||
local z = input:read("*n")
|
||||
local name = input:read("*l")
|
||||
unified_inventory.home_pos[name:sub(2)] = {x = x, y = y, z = z}
|
||||
end
|
||||
io.close(input)
|
||||
else
|
||||
unified_inventory.home_pos = {}
|
||||
end
|
||||
end
|
||||
load_home()
|
||||
|
||||
function unified_inventory.set_home(player, pos)
|
||||
local player_name = player:get_player_name()
|
||||
unified_inventory.home_pos[player_name] = pos
|
||||
-- save the home data from the table to the file
|
||||
local output = io.open(unified_inventory.home_filename, "w")
|
||||
for k, v in pairs(unified_inventory.home_pos) do
|
||||
if v ~= nil then
|
||||
output:write(math.floor(v.x).." "
|
||||
..math.floor(v.y).." "
|
||||
..math.floor(v.z).." "
|
||||
..k.."\n")
|
||||
end
|
||||
end
|
||||
io.close(output)
|
||||
end
|
||||
|
||||
function unified_inventory.go_home(player)
|
||||
local pos = unified_inventory.home_pos[player:get_player_name()]
|
||||
if pos ~= nil then
|
||||
player:setpos(pos)
|
||||
end
|
||||
end
|
||||
|
||||
-- register_craft
|
||||
function unified_inventory.register_craft(options)
|
||||
if options.output == nil then
|
||||
return
|
||||
end
|
||||
local itemstack = ItemStack(options.output)
|
||||
if itemstack:is_empty() then
|
||||
return
|
||||
end
|
||||
if options.type == "normal" and options.width == 0 then
|
||||
options = { type = "shapeless", items = options.items, output = options.output, width = 0 }
|
||||
end
|
||||
if unified_inventory.crafts_table[itemstack:get_name()] == nil then
|
||||
unified_inventory.crafts_table[itemstack:get_name()] = {}
|
||||
end
|
||||
table.insert(unified_inventory.crafts_table[itemstack:get_name()],options)
|
||||
end
|
||||
|
||||
|
||||
local craft_type_defaults = {
|
||||
width = 3,
|
||||
height = 3,
|
||||
uses_crafting_grid = false,
|
||||
}
|
||||
|
||||
|
||||
function unified_inventory.craft_type_defaults(name, options)
|
||||
if not options.description then
|
||||
options.description = name
|
||||
end
|
||||
setmetatable(options, {__index = craft_type_defaults})
|
||||
return options
|
||||
end
|
||||
|
||||
|
||||
function unified_inventory.register_craft_type(name, options)
|
||||
unified_inventory.registered_craft_types[name] =
|
||||
unified_inventory.craft_type_defaults(name, options)
|
||||
end
|
||||
|
||||
|
||||
unified_inventory.register_craft_type("normal", {
|
||||
description = "Crafting",
|
||||
width = 3,
|
||||
height = 3,
|
||||
uses_crafting_grid = true,
|
||||
})
|
||||
|
||||
|
||||
unified_inventory.register_craft_type("shapeless", {
|
||||
description = "Mixing",
|
||||
width = 3,
|
||||
height = 3,
|
||||
uses_crafting_grid = true,
|
||||
})
|
||||
|
||||
|
||||
unified_inventory.register_craft_type("cooking", {
|
||||
description = "Cooking",
|
||||
width = 1,
|
||||
height = 1,
|
||||
})
|
||||
|
||||
|
||||
unified_inventory.register_craft_type("digging", {
|
||||
description = "Digging",
|
||||
width = 1,
|
||||
height = 1,
|
||||
})
|
||||
|
||||
|
||||
function unified_inventory.register_page(name, def)
|
||||
unified_inventory.pages[name] = def
|
||||
end
|
||||
|
||||
|
||||
function unified_inventory.register_button(name, def)
|
||||
if not def.action then
|
||||
def.action = function(player)
|
||||
unified_inventory.set_inventory_formspec(player, name)
|
||||
end
|
||||
end
|
||||
def.name = name
|
||||
table.insert(unified_inventory.buttons, def)
|
||||
end
|
||||
|
||||
|
||||
function unified_inventory.is_creative(playername)
|
||||
if minetest.check_player_privs(playername, {creative=true}) or
|
||||
minetest.setting_getbool("creative_mode") then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,150 @@
|
|||
-- Bags for Minetest
|
||||
|
||||
-- Copyright (c) 2012 cornernote, Brett O'Donnell <cornernote@gmail.com>
|
||||
-- License: GPLv3
|
||||
|
||||
unified_inventory.register_page("bags", {
|
||||
get_formspec = function(player)
|
||||
local player_name = player:get_player_name()
|
||||
local formspec = "background[0.06,0.99;7.92,7.52;ui_bags_main_form.png]"
|
||||
formspec = formspec.."label[0,0;Bags]"
|
||||
formspec = formspec.."button[0,2;2,0.5;bag1;Bag 1]"
|
||||
formspec = formspec.."button[2,2;2,0.5;bag2;Bag 2]"
|
||||
formspec = formspec.."button[4,2;2,0.5;bag3;Bag 3]"
|
||||
formspec = formspec.."button[6,2;2,0.5;bag4;Bag 4]"
|
||||
formspec = formspec.."listcolors[#00000000;#00000000]"
|
||||
formspec = formspec.."list[detached:"..minetest.formspec_escape(player_name).."_bags;bag1;0.5,1;1,1;]"
|
||||
formspec = formspec.."list[detached:"..minetest.formspec_escape(player_name).."_bags;bag2;2.5,1;1,1;]"
|
||||
formspec = formspec.."list[detached:"..minetest.formspec_escape(player_name).."_bags;bag3;4.5,1;1,1;]"
|
||||
formspec = formspec.."list[detached:"..minetest.formspec_escape(player_name).."_bags;bag4;6.5,1;1,1;]"
|
||||
return {formspec=formspec}
|
||||
end,
|
||||
})
|
||||
|
||||
unified_inventory.register_button("bags", {
|
||||
type = "image",
|
||||
image = "ui_bags_icon.png",
|
||||
})
|
||||
|
||||
for i = 1, 4 do
|
||||
unified_inventory.register_page("bag"..i, {
|
||||
get_formspec = function(player)
|
||||
local stack = player:get_inventory():get_stack("bag"..i, 1)
|
||||
local image = stack:get_definition().inventory_image
|
||||
local formspec = "image[7,0;1,1;"..image.."]"
|
||||
formspec = formspec.."label[0,0;Bag "..i.."]"
|
||||
formspec = formspec.."listcolors[#00000000;#00000000]"
|
||||
formspec = formspec.."list[current_player;bag"..i.."contents;0,1;8,3;]"
|
||||
local slots = stack:get_definition().groups.bagslots
|
||||
if slots == 8 then
|
||||
formspec = formspec.."background[0.06,0.99;7.92,7.52;ui_bags_sm_form.png]"
|
||||
elseif slots == 16 then
|
||||
formspec = formspec.."background[0.06,0.99;7.92,7.52;ui_bags_med_form.png]"
|
||||
elseif slots == 24 then
|
||||
formspec = formspec.."background[0.06,0.99;7.92,7.52;ui_bags_lg_form.png]"
|
||||
end
|
||||
return {formspec=formspec}
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
if formname ~= "" then
|
||||
return
|
||||
end
|
||||
for i = 1, 4 do
|
||||
if fields["bag"..i] then
|
||||
local stack = player:get_inventory():get_stack("bag"..i, 1)
|
||||
if not stack:get_definition().groups.bagslots then
|
||||
return
|
||||
end
|
||||
unified_inventory.set_inventory_formspec(player, "bag"..i)
|
||||
return
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
local player_inv = player:get_inventory()
|
||||
local bags_inv = minetest.create_detached_inventory(player:get_player_name().."_bags",{
|
||||
on_put = function(inv, listname, index, stack, player)
|
||||
player:get_inventory():set_stack(listname, index, stack)
|
||||
player:get_inventory():set_size(listname.."contents",
|
||||
stack:get_definition().groups.bagslots)
|
||||
end,
|
||||
on_take = function(inv, listname, index, stack, player)
|
||||
player:get_inventory():set_stack(listname, index, nil)
|
||||
end,
|
||||
allow_put = function(inv, listname, index, stack, player)
|
||||
if stack:get_definition().groups.bagslots then
|
||||
return 1
|
||||
else
|
||||
return 0
|
||||
end
|
||||
end,
|
||||
allow_take = function(inv, listname, index, stack, player)
|
||||
if player:get_inventory():is_empty(listname.."contents") then
|
||||
return stack:get_count()
|
||||
else
|
||||
return 0
|
||||
end
|
||||
end,
|
||||
allow_move = function(inv, from_list, from_index, to_list, to_index, count, player)
|
||||
return 0
|
||||
end,
|
||||
})
|
||||
for i=1,4 do
|
||||
local bag = "bag"..i
|
||||
player_inv:set_size(bag, 1)
|
||||
bags_inv:set_size(bag, 1)
|
||||
bags_inv:set_stack(bag, 1, player_inv:get_stack(bag, 1))
|
||||
end
|
||||
end)
|
||||
|
||||
-- register bag tools
|
||||
minetest.register_tool("unified_inventory:bag_small", {
|
||||
description = "Small Bag",
|
||||
inventory_image = "bags_small.png",
|
||||
groups = {bagslots=8},
|
||||
})
|
||||
|
||||
minetest.register_tool("unified_inventory:bag_medium", {
|
||||
description = "Medium Bag",
|
||||
inventory_image = "bags_medium.png",
|
||||
groups = {bagslots=16},
|
||||
})
|
||||
|
||||
minetest.register_tool("unified_inventory:bag_large", {
|
||||
description = "Large Bag",
|
||||
inventory_image = "bags_large.png",
|
||||
groups = {bagslots=24},
|
||||
})
|
||||
|
||||
-- register bag crafts
|
||||
minetest.register_craft({
|
||||
output = "unified_inventory:bag_small",
|
||||
recipe = {
|
||||
{"", "default:stick", ""},
|
||||
{"group:wood", "group:wood", "group:wood"},
|
||||
{"group:wood", "group:wood", "group:wood"},
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "unified_inventory:bag_medium",
|
||||
recipe = {
|
||||
{"", "", ""},
|
||||
{"default:stick", "unified_inventory:bag_small", "default:stick"},
|
||||
{"default:stick", "unified_inventory:bag_small", "default:stick"},
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "unified_inventory:bag_large",
|
||||
recipe = {
|
||||
{"", "", ""},
|
||||
{"default:stick", "unified_inventory:bag_medium", "default:stick"},
|
||||
{"default:stick", "unified_inventory:bag_medium", "default:stick"},
|
||||
},
|
||||
})
|
||||
|
|
@ -0,0 +1,191 @@
|
|||
local function default_refill(stack)
|
||||
stack:set_count(stack:get_stack_max())
|
||||
local itemdef = minetest.registered_items[stack:get_name()]
|
||||
if itemdef and (itemdef.wear_represents or "mechanical_wear") == "mechanical_wear" and stack:get_wear() ~= 0 then
|
||||
stack:set_wear(0)
|
||||
end
|
||||
return stack
|
||||
end
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
local player_name = player:get_player_name()
|
||||
unified_inventory.players[player_name] = {}
|
||||
unified_inventory.current_index[player_name] = 1
|
||||
unified_inventory.filtered_items_list[player_name] =
|
||||
unified_inventory.items_list
|
||||
unified_inventory.activefilter[player_name] = ""
|
||||
unified_inventory.apply_filter(player, "")
|
||||
unified_inventory.current_searchbox[player_name] = ""
|
||||
unified_inventory.alternate[player_name] = 1
|
||||
unified_inventory.current_item[player_name] = nil
|
||||
unified_inventory.set_inventory_formspec(player,
|
||||
unified_inventory.default)
|
||||
|
||||
-- Crafting guide inventories
|
||||
local inv = minetest.create_detached_inventory(player_name.."craftrecipe", {
|
||||
allow_put = function(inv, listname, index, stack, player)
|
||||
return 0
|
||||
end,
|
||||
allow_take = function(inv, listname, index, stack, player)
|
||||
return 0
|
||||
end,
|
||||
allow_move = function(inv, from_list, from_index, to_list,
|
||||
to_index, count, player)
|
||||
return 0
|
||||
end,
|
||||
})
|
||||
inv:set_size("output", 1)
|
||||
|
||||
-- Refill slot
|
||||
local refill = minetest.create_detached_inventory(player_name.."refill", {
|
||||
allow_put = function(inv, listname, index, stack, player)
|
||||
local player_name = player:get_player_name()
|
||||
if unified_inventory.is_creative(player_name) then
|
||||
return stack:get_count()
|
||||
else
|
||||
return 0
|
||||
end
|
||||
end,
|
||||
on_put = function(inv, listname, index, stack, player)
|
||||
local player_name = player:get_player_name()
|
||||
local handle_refill = (minetest.registered_items[stack:get_name()] or {}).on_refill or default_refill
|
||||
stack = handle_refill(stack)
|
||||
inv:set_stack(listname, index, stack)
|
||||
minetest.sound_play("electricity",
|
||||
{to_player=player_name, gain = 1.0})
|
||||
end,
|
||||
})
|
||||
refill:set_size("main", 1)
|
||||
end)
|
||||
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
if formname ~= "" then
|
||||
return
|
||||
end
|
||||
local player_name = player:get_player_name()
|
||||
|
||||
-- always take new search text, even if not searching on it yet
|
||||
if fields.searchbox ~= nil and fields.searchbox ~= unified_inventory.current_searchbox[player_name] then
|
||||
unified_inventory.current_searchbox[player_name] = fields.searchbox
|
||||
unified_inventory.set_inventory_formspec(player, unified_inventory.current_page[player_name])
|
||||
end
|
||||
|
||||
for i, def in pairs(unified_inventory.buttons) do
|
||||
if fields[def.name] then
|
||||
def.action(player)
|
||||
minetest.sound_play("click",
|
||||
{to_player=player_name, gain = 0.1})
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
-- Inventory page controls
|
||||
local start = math.floor(
|
||||
unified_inventory.current_index[player_name] / 80 + 1)
|
||||
local start_i = start
|
||||
local pagemax = math.floor(
|
||||
(#unified_inventory.filtered_items_list[player_name] - 1)
|
||||
/ (80) + 1)
|
||||
|
||||
if fields.start_list then
|
||||
start_i = 1
|
||||
end
|
||||
if fields.rewind1 then
|
||||
start_i = start_i - 1
|
||||
end
|
||||
if fields.forward1 then
|
||||
start_i = start_i + 1
|
||||
end
|
||||
if fields.rewind3 then
|
||||
start_i = start_i - 3
|
||||
end
|
||||
if fields.forward3 then
|
||||
start_i = start_i + 3
|
||||
end
|
||||
if fields.end_list then
|
||||
start_i = pagemax
|
||||
end
|
||||
if start_i < 1 then
|
||||
start_i = 1
|
||||
end
|
||||
if start_i > pagemax then
|
||||
start_i = pagemax
|
||||
end
|
||||
if not (start_i == start) then
|
||||
minetest.sound_play("paperflip1",
|
||||
{to_player=player_name, gain = 1.0})
|
||||
unified_inventory.current_index[player_name] = (start_i - 1) * 80 + 1
|
||||
unified_inventory.set_inventory_formspec(player,
|
||||
unified_inventory.current_page[player_name])
|
||||
end
|
||||
|
||||
local clicked_item = nil
|
||||
for name, value in pairs(fields) do
|
||||
if string.sub(name, 1, 12) == "item_button_" then
|
||||
clicked_item = string.sub(name, 13)
|
||||
if string.sub(clicked_item, 1, 6) == "group:" then
|
||||
minetest.sound_play("click", {to_player=player_name, gain = 0.1})
|
||||
unified_inventory.apply_filter(player, clicked_item)
|
||||
return
|
||||
end
|
||||
break
|
||||
end
|
||||
end
|
||||
if clicked_item then
|
||||
minetest.sound_play("click",
|
||||
{to_player=player_name, gain = 0.1})
|
||||
local page = unified_inventory.current_page[player_name]
|
||||
if not unified_inventory.is_creative(player_name) then
|
||||
page = "craftguide"
|
||||
end
|
||||
if page == "craftguide" then
|
||||
unified_inventory.current_item[player_name] = clicked_item
|
||||
unified_inventory.alternate[player_name] = 1
|
||||
unified_inventory.set_inventory_formspec(player,
|
||||
"craftguide")
|
||||
else
|
||||
if unified_inventory.is_creative(player_name) then
|
||||
local inv = player:get_inventory()
|
||||
local stack = ItemStack(clicked_item)
|
||||
stack:set_count(stack:get_stack_max())
|
||||
if inv:room_for_item("main", stack) then
|
||||
inv:add_item("main", stack)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if fields.searchbutton then
|
||||
unified_inventory.apply_filter(player, unified_inventory.current_searchbox[player_name])
|
||||
unified_inventory.current_searchbox[player_name] = ""
|
||||
unified_inventory.set_inventory_formspec(player,
|
||||
unified_inventory.current_page[player_name])
|
||||
minetest.sound_play("paperflip2",
|
||||
{to_player=player_name, gain = 1.0})
|
||||
end
|
||||
|
||||
-- alternate button
|
||||
if fields.alternate then
|
||||
minetest.sound_play("click",
|
||||
{to_player=player_name, gain = 0.1})
|
||||
local item_name = unified_inventory.current_item[player_name]
|
||||
if item_name then
|
||||
local alternates = 0
|
||||
local alternate = unified_inventory.alternate[player_name]
|
||||
local crafts = unified_inventory.crafts_table[item_name]
|
||||
if crafts ~= nil then
|
||||
alternates = #crafts
|
||||
end
|
||||
if alternates > 1 then
|
||||
alternate = alternate + 1
|
||||
if alternate > alternates then
|
||||
alternate = 1
|
||||
end
|
||||
unified_inventory.alternate[player_name] = alternate
|
||||
unified_inventory.set_inventory_formspec(player,
|
||||
unified_inventory.current_page[player_name])
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
datastorage={}
|
||||
datastorage["!registered_players"]={}
|
||||
|
||||
datastorage.save_data = function(table_pointer)
|
||||
local data = minetest.serialize( datastorage[table_pointer] )
|
||||
local path = minetest.get_worldpath().."/datastorage_"..table_pointer..".data"
|
||||
local file = io.open( path, "w" )
|
||||
if( file ) then
|
||||
file:write( data )
|
||||
file:close()
|
||||
return true
|
||||
else return nil
|
||||
end
|
||||
end
|
||||
|
||||
datastorage.load_data = function(table_pointer)
|
||||
local path = minetest.get_worldpath().."/datastorage_"..table_pointer..".data"
|
||||
local file = io.open( path, "r" )
|
||||
if( file ) then
|
||||
local data = file:read("*all")
|
||||
datastorage[table_pointer] = minetest.deserialize( data )
|
||||
file:close()
|
||||
return true
|
||||
else return nil
|
||||
end
|
||||
end
|
||||
|
||||
datastorage.get_container = function (player, key)
|
||||
local player_name = player:get_player_name()
|
||||
local container = datastorage[player_name]
|
||||
if container[key] == nil then
|
||||
container[key] = {}
|
||||
end
|
||||
datastorage.save_data(player_name)
|
||||
return container[key]
|
||||
end
|
||||
|
||||
-- forced save of all player's data
|
||||
datastorage.save_container = function (player)
|
||||
local player_name = player:get_player_name()
|
||||
datastorage.save_data(player_name)
|
||||
end
|
||||
|
||||
|
||||
-- Init
|
||||
if datastorage.load_data("!registered_players") == nil then
|
||||
datastorage["!registered_players"]={}
|
||||
datastorage.save_data("!registered_players")
|
||||
end
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
local player_name = player:get_player_name()
|
||||
local registered = nil
|
||||
for __,tab in ipairs(datastorage["!registered_players"]) do
|
||||
if tab["player_name"] == player_name then registered = true break end
|
||||
end
|
||||
if registered == nil then
|
||||
local new={}
|
||||
new["player_name"]=player_name
|
||||
table.insert(datastorage["!registered_players"],new)
|
||||
datastorage[player_name]={}
|
||||
datastorage.save_data("!registered_players")
|
||||
datastorage.save_data(player_name)
|
||||
else
|
||||
datastorage.load_data(player_name)
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
minetest.register_on_leaveplayer(function(player)
|
||||
local player_name = player:get_player_name()
|
||||
datastorage.save_data(player_name)
|
||||
datastorage[player_name] = nil
|
||||
end
|
||||
)
|
||||
|
||||
minetest.register_on_shutdown(function()
|
||||
for __,tab in ipairs(datastorage["!registered_players"]) do
|
||||
if datastorage[tab["player_name"]] == nil then break end
|
||||
datastorage.save_data(tab["player_name"])
|
||||
end
|
||||
end
|
||||
)
|
|
@ -0,0 +1 @@
|
|||
creative?
|
|
@ -0,0 +1,66 @@
|
|||
|
||||
unified_inventory.registered_group_items = {
|
||||
mesecon_conductor_craftable = "mesecons:wire_00000000_off",
|
||||
wool = "wool:white",
|
||||
}
|
||||
|
||||
function unified_inventory.register_group_item(groupname, itemname)
|
||||
unified_inventory.registered_group_items[groupname] = itemname
|
||||
end
|
||||
|
||||
|
||||
-- This is used when displaying craft recipes, where an ingredient is
|
||||
-- specified by group rather than as a specific item. A single-item group
|
||||
-- is represented by that item, with the single-item status signalled
|
||||
-- in the "sole" field. If the group contains no items at all, the item
|
||||
-- field will be nil.
|
||||
--
|
||||
-- Within a multiple-item group, we prefer to use an item that has the
|
||||
-- same specific name as the group, and if there are more than one of
|
||||
-- those items we prefer the one registered for the group by a mod.
|
||||
-- Among equally-preferred items, we just pick the one with the
|
||||
-- lexicographically earliest name.
|
||||
|
||||
function compute_group_item(group_name)
|
||||
local candidate_items = {}
|
||||
for itemname, itemdef in pairs(minetest.registered_items) do
|
||||
if (itemdef.groups.not_in_creative_inventory or 0) == 0 and
|
||||
(itemdef.groups[group_name] or 0) ~= 0 then
|
||||
table.insert(candidate_items, itemname)
|
||||
end
|
||||
end
|
||||
local num_candidates = #candidate_items
|
||||
if num_candidates == 0 then
|
||||
return {sole = true}
|
||||
elseif num_candidates == 1 then
|
||||
return {item = candidate_items[1], sole = true}
|
||||
end
|
||||
local bestitem = ""
|
||||
local bestpref = 0
|
||||
for _, item in ipairs(candidate_items) do
|
||||
local pref
|
||||
if item == unified_inventory.registered_group_items[group_name] then
|
||||
pref = 3
|
||||
elseif item:gsub("^[^:]+:", "") == group_name then
|
||||
pref = 2
|
||||
else
|
||||
pref = 1
|
||||
end
|
||||
if pref > bestpref or (pref == bestpref and item < bestitem) then
|
||||
bestitem = item
|
||||
bestpref = pref
|
||||
end
|
||||
end
|
||||
return {item = bestitem, sole = false}
|
||||
end
|
||||
|
||||
|
||||
local group_item_cache = {}
|
||||
|
||||
function unified_inventory.get_group_item(group_name)
|
||||
if not group_item_cache[group_name] then
|
||||
group_item_cache[group_name] = compute_group_item(group_name)
|
||||
end
|
||||
return group_item_cache[group_name]
|
||||
end
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
bags_small.png:
|
||||
http://www.clker.com/clipart-moneybag-empty.html
|
||||
|
||||
bags_medium.png:
|
||||
http://www.clker.com/clipart-backpack-1.html
|
||||
|
||||
bags_large.png / ui_bags_icon.png:
|
||||
http://www.clker.com/clipart-backpack-green-brown.html
|
||||
|
||||
ui_craftguide_icon.png / ui_craft_icon.png
|
||||
http://commons.wikimedia.org/wiki/File:Advancedsettings.png
|
||||
|
||||
ui_doubleleft_icon.png
|
||||
http://commons.wikimedia.org/wiki/File:Media-seek-backward.svg
|
||||
|
||||
ui_doubleright_icon.png
|
||||
http://commons.wikimedia.org/wiki/File:Media-seek-forward.svg
|
||||
|
||||
ui_left_icon.png / ui_right_icon.png
|
||||
http://commons.wikimedia.org/wiki/File:Media-playback-start.svg
|
||||
|
||||
ui_skip_backward_icon.png
|
||||
http://commons.wikimedia.org/wiki/File:Media-skip-backward.svg
|
||||
|
||||
ui_skip_forward_icon.png
|
||||
http://commons.wikimedia.org/wiki/File:Media-skip-forward.svg
|
||||
|
||||
ui_gohome_icon.png / ui_home_icon.png / ui_sethome_icon.png
|
||||
http://commons.wikimedia.org/wiki/File:Home_256x256.png
|
||||
|
||||
ui_moon_icon.png
|
||||
http://commons.wikimedia.org/wiki/File:FullMoon2010.jpg
|
||||
|
||||
ui_sun_icon.png
|
||||
http://commons.wikimedia.org/wiki/File:2012-10-13_15-29-35-sun.jpg
|
||||
|
||||
ui_trash_icon.png
|
||||
http://www.clker.com/clipart-29090.html
|
||||
http://www.clker.com/clipart-trash.html
|
||||
|
||||
ui_search_icon.png
|
||||
http://www.clker.com/clipart-24887.html
|
||||
|
||||
ui_off_icon.png / ui_on_icon.png
|
||||
http://www.clker.com/clipart-on-off-switches.html
|
||||
|
||||
ui_waypoints_icon.png
|
||||
http://www.clker.com/clipart-map-pin-red.html
|
||||
|
||||
ui_circular_arrows_icon.png
|
||||
http://www.clker.com/clipart-circular-arrow-pattern.html
|
||||
|
||||
ui_pencil_icon.pnc
|
||||
http://www.clker.com/clipart-2256.html
|
||||
|
||||
ui_waypoint_set_icon.png
|
||||
http://www.clker.com/clipart-larger-flag.html
|
||||
|
||||
ui_xyz_off_icon.png
|
||||
http://commons.wikimedia.org/wiki/File:No_sign.svg
|
||||
|
||||
ui_ok_icon.png
|
||||
http://commons.wikimedia.org/wiki/File:Yes_check.svg
|
||||
|
||||
inventory_plus_worldedit_gui.png
|
||||
http://commons.wikimedia.org/wiki/File:Erioll_world_2.svg
|
|
@ -0,0 +1,48 @@
|
|||
-- Unified Inventory for Minetest 0.4.8+
|
||||
|
||||
local modpath = minetest.get_modpath(minetest.get_current_modname())
|
||||
local worldpath = minetest.get_worldpath()
|
||||
|
||||
-- Data tables definitions
|
||||
unified_inventory = {}
|
||||
unified_inventory.activefilter = {}
|
||||
unified_inventory.alternate = {}
|
||||
unified_inventory.current_page = {}
|
||||
unified_inventory.current_searchbox = {}
|
||||
unified_inventory.current_index = {}
|
||||
unified_inventory.current_item = {}
|
||||
unified_inventory.registered_craft_types = {}
|
||||
unified_inventory.crafts_table = {}
|
||||
unified_inventory.crafts_table_count = 0
|
||||
unified_inventory.players = {}
|
||||
unified_inventory.items_list_size = 0
|
||||
unified_inventory.items_list = {}
|
||||
unified_inventory.filtered_items_list_size = {}
|
||||
unified_inventory.filtered_items_list = {}
|
||||
unified_inventory.pages = {}
|
||||
unified_inventory.buttons = {}
|
||||
|
||||
-- Homepos stuff
|
||||
unified_inventory.home_pos = {}
|
||||
unified_inventory.home_filename =
|
||||
worldpath.."/unified_inventory_home.home"
|
||||
|
||||
-- Default inventory page
|
||||
unified_inventory.default = "craft"
|
||||
|
||||
-- Disable default creative inventory
|
||||
if creative_inventory then
|
||||
function creative_inventory.set_creative_formspec(player, start_i, pagenum)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
dofile(modpath.."/datastorage.lua")
|
||||
dofile(modpath.."/group.lua")
|
||||
dofile(modpath.."/api.lua")
|
||||
dofile(modpath.."/internal.lua")
|
||||
dofile(modpath.."/callbacks.lua")
|
||||
dofile(modpath.."/register.lua")
|
||||
dofile(modpath.."/bags.lua")
|
||||
dofile(modpath.."/item_names.lua")
|
||||
dofile(modpath.."/waypoints.lua")
|
|
@ -0,0 +1,191 @@
|
|||
|
||||
function unified_inventory.get_formspec(player, page)
|
||||
if not player then
|
||||
return ""
|
||||
end
|
||||
local player_name = player:get_player_name()
|
||||
unified_inventory.current_page[player_name] = page
|
||||
local pagedef = unified_inventory.pages[page]
|
||||
|
||||
local formspec = "size[14,10]"
|
||||
local fsdata = nil
|
||||
|
||||
-- Background
|
||||
formspec = formspec .. "background[-0.19,-0.25;14.4,10.75;ui_form_bg.png]"
|
||||
-- Current page
|
||||
if unified_inventory.pages[page] then
|
||||
fsdata = pagedef.get_formspec(player)
|
||||
formspec = formspec .. fsdata.formspec
|
||||
else
|
||||
return "" -- Invalid page name
|
||||
end
|
||||
|
||||
-- Main buttons
|
||||
for i, def in pairs(unified_inventory.buttons) do
|
||||
if def.type == "image" then
|
||||
formspec = formspec.."image_button["
|
||||
..(0.65 * (i - 1))..",9;0.8,0.8;"
|
||||
..minetest.formspec_escape(def.image)..";"
|
||||
..minetest.formspec_escape(def.name)..";]"
|
||||
end
|
||||
end
|
||||
|
||||
if fsdata.draw_inventory ~= false then
|
||||
-- Player inventory
|
||||
formspec = formspec.."listcolors[#00000000;#00000000]"
|
||||
formspec = formspec .. "list[current_player;main;0,4.5;8,4;]"
|
||||
end
|
||||
|
||||
if fsdata.draw_item_list == false then
|
||||
return formspec
|
||||
end
|
||||
|
||||
-- Controls to flip items pages
|
||||
local start_x = 9.2
|
||||
formspec = formspec .. "image_button["..(start_x + 0.6 * 0)..",9;.8,.8;ui_skip_backward_icon.png;start_list;]"
|
||||
formspec = formspec .. "image_button["..(start_x + 0.6 * 1)..",9;.8,.8;ui_doubleleft_icon.png;rewind3;]"
|
||||
formspec = formspec .. "image_button["..(start_x + 0.6 * 2)..",9;.8,.8;ui_left_icon.png;rewind1;]"
|
||||
formspec = formspec .. "image_button["..(start_x + 0.6 * 3)..",9;.8,.8;ui_right_icon.png;forward1;]"
|
||||
formspec = formspec .. "image_button["..(start_x + 0.6 * 4)..",9;.8,.8;ui_doubleright_icon.png;forward3;]"
|
||||
formspec = formspec .. "image_button["..(start_x + 0.6 * 5)..",9;.8,.8;ui_skip_forward_icon.png;end_list;]"
|
||||
|
||||
-- Search box
|
||||
formspec = formspec .. "field[9.5,8.325;3,1;searchbox;;"..minetest.formspec_escape(unified_inventory.current_searchbox[player_name]).."]"
|
||||
formspec = formspec .. "image_button[12.2,8.1;.8,.8;ui_search_icon.png;searchbutton;]"
|
||||
|
||||
-- Items list
|
||||
if #unified_inventory.filtered_items_list[player_name] == 0 then
|
||||
formspec = formspec.."label[8.2,0;No matching items]"
|
||||
else
|
||||
local list_index = unified_inventory.current_index[player_name]
|
||||
local page = math.floor(list_index / (80) + 1)
|
||||
local pagemax = math.floor(
|
||||
(#unified_inventory.filtered_items_list[player_name] - 1)
|
||||
/ (80) + 1)
|
||||
local item = {}
|
||||
for y = 0, 9 do
|
||||
for x = 0, 7 do
|
||||
local name = unified_inventory.filtered_items_list[player_name][list_index]
|
||||
if minetest.registered_items[name] then
|
||||
formspec = formspec.."item_image_button["
|
||||
..(8.2 + x * 0.7)..","
|
||||
..(1 + y * 0.7)..";.81,.81;"
|
||||
..name..";item_button_"
|
||||
..name..";]"
|
||||
list_index = list_index + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
formspec = formspec.."label[8.2,0;Page:]"
|
||||
formspec = formspec.."label[9,0;"..page.." of "..pagemax.."]"
|
||||
end
|
||||
if unified_inventory.activefilter[player_name] ~= "" then
|
||||
formspec = formspec.."label[8.2,0.4;Filter:]"
|
||||
formspec = formspec.."label[9,0.4;"..minetest.formspec_escape(unified_inventory.activefilter[player_name]).."]"
|
||||
end
|
||||
return formspec
|
||||
end
|
||||
|
||||
function unified_inventory.set_inventory_formspec(player, page)
|
||||
if player then
|
||||
local formspec = unified_inventory.get_formspec(player, page)
|
||||
player:set_inventory_formspec(formspec)
|
||||
end
|
||||
end
|
||||
|
||||
--apply filter to the inventory list (create filtered copy of full one)
|
||||
function unified_inventory.apply_filter(player, filter)
|
||||
local player_name = player:get_player_name()
|
||||
local lfilter = string.lower(filter)
|
||||
if not pcall(function() ("technic:test"):find(lfilter) end) then
|
||||
-- Filter is invalid
|
||||
lfilter = ""
|
||||
end
|
||||
local ffilter
|
||||
if lfilter:sub(1, 6) == "group:" then
|
||||
local groups = lfilter:sub(7):split(",")
|
||||
ffilter = function(name, def)
|
||||
for _, group in ipairs(groups) do
|
||||
if not ((def.groups[group] or 0) > 0) then
|
||||
return false
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
else
|
||||
ffilter = function(name, def)
|
||||
local lname = string.lower(name)
|
||||
local ldesc = string.lower(def.description)
|
||||
return string.find(lname, lfilter) or string.find(ldesc, lfilter)
|
||||
end
|
||||
end
|
||||
unified_inventory.filtered_items_list[player_name]={}
|
||||
for name, def in pairs(minetest.registered_items) do
|
||||
if (def.groups.not_in_creative_inventory or 0) == 0 and (def.description or "") ~= "" and ffilter(name, def) then
|
||||
table.insert(unified_inventory.filtered_items_list[player_name], name)
|
||||
end
|
||||
end
|
||||
table.sort(unified_inventory.filtered_items_list[player_name])
|
||||
unified_inventory.filtered_items_list_size[player_name] = #unified_inventory.filtered_items_list[player_name]
|
||||
unified_inventory.current_index[player_name] = 1
|
||||
unified_inventory.activefilter[player_name] = filter
|
||||
unified_inventory.set_inventory_formspec(player,
|
||||
unified_inventory.current_page[player_name])
|
||||
end
|
||||
|
||||
function unified_inventory.items_in_group(groups)
|
||||
local items = {}
|
||||
for name, item in pairs(minetest.registered_items) do
|
||||
for _, group in pairs(groups:split(',')) do
|
||||
if item.groups[group] then
|
||||
table.insert(items, name)
|
||||
end
|
||||
end
|
||||
end
|
||||
return items
|
||||
end
|
||||
|
||||
function unified_inventory.sort_inventory(inv)
|
||||
local inlist = inv:get_list("main")
|
||||
local typecnt = {}
|
||||
local typekeys = {}
|
||||
for _, st in ipairs(inlist) do
|
||||
if not st:is_empty() then
|
||||
local n = st:get_name()
|
||||
local w = st:get_wear()
|
||||
local m = st:get_metadata()
|
||||
local k = string.format("%s %05d %s", n, w, m)
|
||||
if not typecnt[k] then
|
||||
typecnt[k] = {
|
||||
name = n,
|
||||
wear = w,
|
||||
metadata = m,
|
||||
stack_max = st:get_stack_max(),
|
||||
count = 0,
|
||||
}
|
||||
table.insert(typekeys, k)
|
||||
end
|
||||
typecnt[k].count = typecnt[k].count + st:get_count()
|
||||
end
|
||||
end
|
||||
table.sort(typekeys)
|
||||
local outlist = {}
|
||||
for _, k in ipairs(typekeys) do
|
||||
local tc = typecnt[k]
|
||||
while tc.count > 0 do
|
||||
local c = math.min(tc.count, tc.stack_max)
|
||||
table.insert(outlist, ItemStack({
|
||||
name = tc.name,
|
||||
wear = tc.wear,
|
||||
metadata = tc.metadata,
|
||||
count = c,
|
||||
}))
|
||||
tc.count = tc.count - c
|
||||
end
|
||||
end
|
||||
if #outlist > #inlist then return end
|
||||
while #outlist < #inlist do
|
||||
table.insert(outlist, ItemStack(nil))
|
||||
end
|
||||
inv:set_list("main", outlist)
|
||||
end
|
|
@ -0,0 +1,58 @@
|
|||
-- code based on 4itemnames mod by 4aiman
|
||||
|
||||
local wield = {}
|
||||
local huds = {}
|
||||
local dtimes = {}
|
||||
local dlimit = 3 -- hud will be hidden after this much seconds
|
||||
local airhudmod = minetest.get_modpath("4air")
|
||||
|
||||
local function get_desc(item)
|
||||
if minetest.registered_nodes[item] then return minetest.registered_nodes[item]["description"] end
|
||||
if minetest.registered_items[item] then return minetest.registered_items[item]["description"] end
|
||||
if minetest.registered_craftitems[item] then return minetest.registered_craftitems[item]["description"] end
|
||||
if minetest.registered_tools[item] then return minetest.registered_tools[item]["description"] end
|
||||
return ""
|
||||
end
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
minetest.after(0.0, function()
|
||||
local player_name = player:get_player_name()
|
||||
local off = {x=0, y=-70}
|
||||
if airhudmod then
|
||||
off.y=off.y-20
|
||||
end
|
||||
huds[player_name] = player:hud_add({
|
||||
hud_elem_type = "text",
|
||||
position = {x=0.5, y=1},
|
||||
offset = off,
|
||||
alignment = {x=0, y=0},
|
||||
number = 0xFFFFFF ,
|
||||
text = "",
|
||||
})
|
||||
--print(dump("item hud id: "..huds[player_name]))
|
||||
end)
|
||||
end)
|
||||
|
||||
minetest.register_globalstep(function(dtime)
|
||||
local players = minetest.get_connected_players()
|
||||
for i,player in ipairs(players) do
|
||||
local player_name = player:get_player_name()
|
||||
local wstack = player:get_wielded_item():get_name()
|
||||
|
||||
if dtimes[player_name] and dtimes[player_name] < dlimit then
|
||||
dtimes[player_name] = dtimes[player_name] + dtime
|
||||
if dtimes[player_name] > dlimit and huds[player_name] then
|
||||
player:hud_change(huds[player_name], 'text', "")
|
||||
end
|
||||
end
|
||||
|
||||
if wstack ~= wield[player_name] then
|
||||
wield[player_name] = wstack
|
||||
local desc = get_desc(wstack)
|
||||
dtimes[player_name] = 0
|
||||
if huds[player_name] then
|
||||
player:hud_change(huds[player_name], 'text', desc)
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
|
@ -0,0 +1,330 @@
|
|||
|
||||
minetest.register_privilege("creative", {
|
||||
description = "Can use the creative inventory",
|
||||
give_to_singleplayer = false,
|
||||
})
|
||||
|
||||
local trash = minetest.create_detached_inventory("trash", {
|
||||
--allow_put = function(inv, listname, index, stack, player)
|
||||
-- if unified_inventory.is_creative(player:get_player_name()) then
|
||||
-- return stack:get_count()
|
||||
-- else
|
||||
-- return 0
|
||||
-- end
|
||||
--end,
|
||||
on_put = function(inv, listname, index, stack, player)
|
||||
inv:set_stack(listname, index, nil)
|
||||
local player_name = player:get_player_name()
|
||||
minetest.sound_play("trash", {to_player=player_name, gain = 1.0})
|
||||
end,
|
||||
})
|
||||
trash:set_size("main", 1)
|
||||
|
||||
unified_inventory.register_button("craft", {
|
||||
type = "image",
|
||||
image = "ui_craft_icon.png",
|
||||
})
|
||||
|
||||
unified_inventory.register_button("craftguide", {
|
||||
type = "image",
|
||||
image = "ui_craftguide_icon.png",
|
||||
})
|
||||
|
||||
unified_inventory.register_button("home_gui_set", {
|
||||
type = "image",
|
||||
image = "ui_sethome_icon.png",
|
||||
action = function(player)
|
||||
local player_name = player:get_player_name()
|
||||
unified_inventory.set_home(player, player:getpos())
|
||||
local home = unified_inventory.home_pos[player_name]
|
||||
if home ~= nil then
|
||||
minetest.sound_play("dingdong",
|
||||
{to_player=player_name, gain = 1.0})
|
||||
minetest.chat_send_player(player_name,
|
||||
"Home position set to: "
|
||||
..minetest.pos_to_string(home))
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
unified_inventory.register_button("home_gui_go", {
|
||||
type = "image",
|
||||
image = "ui_gohome_icon.png",
|
||||
action = function(player)
|
||||
minetest.sound_play("teleport",
|
||||
{to_player=player:get_player_name(), gain = 1.0})
|
||||
unified_inventory.go_home(player)
|
||||
end,
|
||||
})
|
||||
|
||||
unified_inventory.register_button("misc_set_day", {
|
||||
type = "image",
|
||||
image = "ui_sun_icon.png",
|
||||
action = function(player)
|
||||
local player_name = player:get_player_name()
|
||||
if minetest.check_player_privs(player_name, {settime=true}) then
|
||||
minetest.sound_play("birds",
|
||||
{to_player=player_name, gain = 1.0})
|
||||
minetest.set_timeofday((6000 % 24000) / 24000)
|
||||
minetest.chat_send_player(player_name,
|
||||
"Time of day set to 6am")
|
||||
else
|
||||
minetest.chat_send_player(player_name,
|
||||
"You don't have the"
|
||||
.." settime priviledge!")
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
unified_inventory.register_button("misc_set_night", {
|
||||
type = "image",
|
||||
image = "ui_moon_icon.png",
|
||||
action = function(player)
|
||||
local player_name = player:get_player_name()
|
||||
if minetest.check_player_privs(player_name, {settime=true}) then
|
||||
minetest.sound_play("owl",
|
||||
{to_player=player_name, gain = 1.0})
|
||||
minetest.set_timeofday((21000 % 24000) / 24000)
|
||||
minetest.chat_send_player(player_name,
|
||||
"Time of day set to 9pm")
|
||||
else
|
||||
minetest.chat_send_player(player_name,
|
||||
"You don't have the"
|
||||
.." settime priviledge!")
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
unified_inventory.register_button("clear_inv", {
|
||||
type = "image",
|
||||
image = "ui_trash_icon.png",
|
||||
action = function(player)
|
||||
local player_name = player:get_player_name()
|
||||
if not unified_inventory.is_creative(player_name) then
|
||||
minetest.chat_send_player(player_name,
|
||||
"This button has been disabled outside"
|
||||
.." of creative mode to prevent"
|
||||
.." accidental inventory trashing."
|
||||
.." Use the trash slot instead.")
|
||||
return
|
||||
end
|
||||
player:get_inventory():set_list("main", {})
|
||||
minetest.chat_send_player(player_name, 'Inventory Cleared!')
|
||||
minetest.sound_play("trash_all",
|
||||
{to_player=player_name, gain = 1.0})
|
||||
end,
|
||||
})
|
||||
|
||||
unified_inventory.register_page("craft", {
|
||||
get_formspec = function(player, formspec)
|
||||
local player_name = player:get_player_name()
|
||||
local formspec = "background[0,1;8,3;ui_crafting_form.png]"
|
||||
formspec = formspec.."background[0,4.5;8,4;ui_main_inventory.png]"
|
||||
formspec = formspec.."label[0,0;Crafting]"
|
||||
formspec = formspec.."listcolors[#00000000;#00000000]"
|
||||
formspec = formspec.."list[current_player;craftpreview;6,1;1,1;]"
|
||||
formspec = formspec.."list[current_player;craft;2,1;3,3;]"
|
||||
formspec = formspec.."label[7,2.5;Trash:]"
|
||||
formspec = formspec.."list[detached:trash;main;7,3;1,1;]"
|
||||
if unified_inventory.is_creative(player_name) then
|
||||
formspec = formspec.."label[0,2.5;Refill:]"
|
||||
formspec = formspec.."list[detached:"..minetest.formspec_escape(player_name).."refill;main;0,3;1,1;]"
|
||||
end
|
||||
return {formspec=formspec}
|
||||
end,
|
||||
})
|
||||
|
||||
|
||||
-- stack_image_button(): generate a form button displaying a stack of items
|
||||
--
|
||||
-- Normally a simple item_image_button[] is used. If the stack contains
|
||||
-- more than one item, item_image_button[] doesn't have an option to
|
||||
-- display an item count in the way that an inventory slot does, so
|
||||
-- we have to fake it using the label facility.
|
||||
--
|
||||
-- The specified item may be a group. In that case, the group will be
|
||||
-- represented by some item in the group, along with a flag indicating
|
||||
-- that it's a group. If the group contains only one item, it will be
|
||||
-- treated as if that item had been specified directly.
|
||||
|
||||
local function stack_image_button(x, y, w, h, buttonname_prefix, item)
|
||||
local name = item:get_name()
|
||||
local count = item:get_count()
|
||||
local show_is_group = false
|
||||
local displayitem = name
|
||||
local selectitem = name
|
||||
if name:sub(1, 6) == "group:" then
|
||||
local group_name = name:sub(7)
|
||||
local group_item = unified_inventory.get_group_item(group_name)
|
||||
show_group = not group_item.sole
|
||||
displayitem = group_item.item or "unknown"
|
||||
selectitem = group_item.sole and displayitem or name
|
||||
end
|
||||
-- Hackily shift the count to the bottom right
|
||||
local shiftstr = "\n\n "
|
||||
return string.format("item_image_button[%u,%u;%u,%u;%s;%s;%s]",
|
||||
x, y, w, h,
|
||||
minetest.formspec_escape(displayitem),
|
||||
minetest.formspec_escape(buttonname_prefix..selectitem),
|
||||
count ~= 1 and shiftstr..tostring(count) or "")
|
||||
end
|
||||
|
||||
unified_inventory.register_page("craftguide", {
|
||||
get_formspec = function(player)
|
||||
local player_name = player:get_player_name()
|
||||
local formspec = ""
|
||||
formspec = formspec.."background[0,4.5;8,4;ui_main_inventory.png]"
|
||||
formspec = formspec.."background[0,1;8,3;ui_craftguide_form.png]"
|
||||
formspec = formspec.."label[0,0;Crafting Guide]"
|
||||
formspec = formspec.."listcolors[#00000000;#00000000]"
|
||||
local craftinv = minetest.get_inventory({
|
||||
type = "detached",
|
||||
name = player_name.."craftrecipe"
|
||||
})
|
||||
local item_name = unified_inventory.current_item[player_name] or ""
|
||||
|
||||
formspec = formspec.."textarea[0.3,0.6;10,1;;Result: "..minetest.formspec_escape(item_name)..";]"
|
||||
formspec = formspec.."list[detached:"..minetest.formspec_escape(player_name).."craftrecipe;output;6,1;1,1;]"
|
||||
|
||||
local alternate, alternates, craft, craft_type
|
||||
alternate = unified_inventory.alternate[player_name]
|
||||
local crafts = unified_inventory.crafts_table[item_name]
|
||||
if crafts ~= nil and #crafts > 0 then
|
||||
alternates = #crafts
|
||||
craft = crafts[alternate]
|
||||
end
|
||||
|
||||
if craft then
|
||||
craftinv:set_stack("output", 1, craft.output)
|
||||
craft_type = unified_inventory.registered_craft_types[craft.type] or
|
||||
unified_inventory.craft_type_defaults(craft.type, {})
|
||||
formspec = formspec.."label[6,3.35;Method:]"
|
||||
formspec = formspec.."label[6,3.75;"
|
||||
..minetest.formspec_escape(craft_type.description).."]"
|
||||
else
|
||||
craftinv:set_stack("output", 1, item_name)
|
||||
craft_type = unified_inventory.craft_type_defaults("", {})
|
||||
formspec = formspec.."label[6,3.35;No recipes]"
|
||||
end
|
||||
|
||||
local width = craft and craft.width or 0
|
||||
if width == 0 then
|
||||
-- Shapeless recipe
|
||||
width = craft_type.width
|
||||
end
|
||||
|
||||
local height = craft_type.height
|
||||
if craft then
|
||||
height = math.ceil(table.maxn(craft.items) / width)
|
||||
end
|
||||
|
||||
local i = 1
|
||||
-- This keeps recipes aligned to the right,
|
||||
-- so that they're close to the arrow.
|
||||
local xoffset = 1 + (3 - width)
|
||||
for y = 1, height do
|
||||
for x = 1, width do
|
||||
local item = craft and craft.items[i]
|
||||
if item then
|
||||
formspec = formspec..stack_image_button(
|
||||
xoffset + x, y, 1.1, 1.1,
|
||||
"item_button_", ItemStack(item))
|
||||
else
|
||||
-- Fake buttons just to make grid
|
||||
formspec = formspec.."image_button["
|
||||
..tostring(xoffset + x)..","..tostring(y)
|
||||
..";1,1;ui_blank_image.png;;]"
|
||||
end
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
|
||||
if craft_type.uses_crafting_grid then
|
||||
formspec = formspec.."label[6,1.95;Copy to craft grid:]"
|
||||
.."button[6,2.5;0.6,0.5;craftguide_craft_1;1]"
|
||||
.."button[6.6,2.5;0.6,0.5;craftguide_craft_10;10]"
|
||||
.."button[7.2,2.5;0.6,0.5;craftguide_craft_max;All]"
|
||||
end
|
||||
|
||||
if alternates and alternates > 1 then
|
||||
formspec = formspec.."label[0,2.6;Recipe "
|
||||
..tostring(alternate).." of "
|
||||
..tostring(alternates).."]"
|
||||
.."button[0,3.15;2,1;alternate;Alternate]"
|
||||
end
|
||||
return {formspec = formspec}
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
local amount
|
||||
for k, v in pairs(fields) do
|
||||
amount = k:match("craftguide_craft_(.*)")
|
||||
if amount then break end
|
||||
end
|
||||
if not amount then return end
|
||||
local player_name = player:get_player_name()
|
||||
local recipe_inv = minetest.get_inventory({
|
||||
type="detached",
|
||||
name=player_name.."craftrecipe",
|
||||
})
|
||||
|
||||
local output = unified_inventory.current_item[player_name]
|
||||
if (not output) or (output == "") then return end
|
||||
|
||||
local player_inv = player:get_inventory()
|
||||
|
||||
local crafts = unified_inventory.crafts_table[output]
|
||||
if (not crafts) or (#crafts == 0) then return end
|
||||
|
||||
local alternate = unified_inventory.alternate[player_name]
|
||||
|
||||
local craft = crafts[alternate]
|
||||
if craft.width > 3 then return end
|
||||
|
||||
local needed = craft.items
|
||||
|
||||
local craft_list = player_inv:get_list("craft")
|
||||
|
||||
local width = craft.width
|
||||
if width == 0 then
|
||||
-- Shapeless recipe
|
||||
width = 3
|
||||
end
|
||||
|
||||
if amount == "max" then
|
||||
amount = 99 -- Arbitrary; need better way to do this.
|
||||
else
|
||||
amount = tonumber(amount)
|
||||
end
|
||||
|
||||
for iter = 1, amount do
|
||||
local index = 1
|
||||
for y = 1, 3 do
|
||||
for x = 1, width do
|
||||
local needed_item = needed[index]
|
||||
if needed_item then
|
||||
local craft_index = ((y - 1) * 3) + x
|
||||
local craft_item = craft_list[craft_index]
|
||||
if (not craft_item) or (craft_item:is_empty()) or (craft_item:get_name() == needed_item) then
|
||||
itemname = craft_item and craft_item:get_name() or needed_item
|
||||
local needed_stack = ItemStack(needed_item)
|
||||
if player_inv:contains_item("main", needed_stack) then
|
||||
local count = (craft_item and craft_item:get_count() or 0) + 1
|
||||
if count <= needed_stack:get_definition().stack_max then
|
||||
local stack = ItemStack({name=needed_item, count=count})
|
||||
craft_list[craft_index] = stack
|
||||
player_inv:remove_item("main", needed_stack)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
index = index + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
player_inv:set_list("craft", craft_list)
|
||||
|
||||
unified_inventory.set_inventory_formspec(player, "craft")
|
||||
end)
|
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 688 B |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 1.8 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 143 B |
After Width: | Height: | Size: 4.5 KiB |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 17 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 17 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 6.3 KiB |
After Width: | Height: | Size: 17 KiB |
After Width: | Height: | Size: 4.9 KiB |
After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 7.6 KiB |
After Width: | Height: | Size: 7.5 KiB |
After Width: | Height: | Size: 9.1 KiB |
After Width: | Height: | Size: 15 KiB |
After Width: | Height: | Size: 6.9 KiB |
After Width: | Height: | Size: 4.6 KiB |
After Width: | Height: | Size: 6.7 KiB |
After Width: | Height: | Size: 7.7 KiB |
After Width: | Height: | Size: 4.5 KiB |
After Width: | Height: | Size: 7.8 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 15 KiB |
After Width: | Height: | Size: 9.6 KiB |
After Width: | Height: | Size: 9.6 KiB |
After Width: | Height: | Size: 19 KiB |
After Width: | Height: | Size: 15 KiB |
After Width: | Height: | Size: 4.7 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 2.6 KiB |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 2.6 KiB |
|
@ -0,0 +1,214 @@
|
|||
unified_inventory.hud_colors = {
|
||||
{"#FFFFFF", 0xFFFFFF, "White"},
|
||||
{"#DBBB00", 0xf1d32c, "Yellow"},
|
||||
{"#DD0000", 0xDD0000, "Red"},
|
||||
{"#2cf136", 0x2cf136, "Green"},
|
||||
{"#2c4df1", 0x2c4df1, "Blue"},
|
||||
}
|
||||
unified_inventory.hud_colors_max = #unified_inventory.hud_colors
|
||||
|
||||
unified_inventory.register_page("waypoints", {
|
||||
get_formspec = function(player)
|
||||
local waypoints = datastorage.get_container (player, "waypoints")
|
||||
local formspec = "background[0,4.5;8,4;ui_main_inventory.png]"..
|
||||
"image[0,0;1,1;ui_waypoints_icon.png]"..
|
||||
"label[1,0;Waypoints]"
|
||||
|
||||
-- Tabs buttons:
|
||||
local i
|
||||
for i = 1, 5, 1 do
|
||||
if i == waypoints.selected then
|
||||
formspec = formspec ..
|
||||
"image_button[0.0,".. 0.2 + i*0.7 ..";.8,.8;ui_blue_icon_background.png^ui_"..
|
||||
i .."_icon.png;select_waypoint".. i .. ";]"
|
||||
else
|
||||
formspec = formspec ..
|
||||
"image_button[0.0,".. 0.2 + i*0.7 ..";.8,.8;ui_"..
|
||||
i .."_icon.png;select_waypoint".. i .. ";]"
|
||||
end
|
||||
end
|
||||
|
||||
i = waypoints.selected
|
||||
|
||||
-- Main buttons:
|
||||
formspec = formspec ..
|
||||
"image_button[4.5,3.7;.8,.8;ui_waypoint_set_icon.png;set_waypoint".. i .. ";]"
|
||||
|
||||
if waypoints[i].active then
|
||||
formspec = formspec ..
|
||||
"image_button[5.2,3.7;.8,.8;ui_on_icon.png;toggle_waypoint".. i .. ";]"
|
||||
else
|
||||
formspec = formspec ..
|
||||
"image_button[5.2,3.7;.8,.8;ui_off_icon.png;toggle_waypoint".. i .. ";]"
|
||||
end
|
||||
|
||||
if waypoints[i].display_pos then
|
||||
formspec = formspec ..
|
||||
"image_button[5.9,3.7;.8,.8;ui_green_icon_background.png^ui_xyz_icon.png;toggle_display_pos".. i .. ";]"
|
||||
else
|
||||
formspec = formspec ..
|
||||
"image_button[5.9,3.7;.8,.8;ui_red_icon_background.png^ui_xyz_icon.png;toggle_display_pos".. i .. ";]"
|
||||
end
|
||||
|
||||
formspec = formspec ..
|
||||
"image_button[6.6,3.7;.8,.8;ui_circular_arrows_icon.png;toggle_color".. i .. ";]"..
|
||||
"image_button[7.3,3.7;.8,.8;ui_pencil_icon.png;rename_waypoint".. i .. ";]"
|
||||
|
||||
-- Waypoint's info:
|
||||
if waypoints[i].active then
|
||||
formspec = formspec .. "label[1,0.8;Waypoint active]"
|
||||
else
|
||||
formspec = formspec .. "label[1,0.8;Waypoint inactive]"
|
||||
end
|
||||
|
||||
if waypoints[i].edit then
|
||||
formspec = formspec ..
|
||||
"field[1.3,3.2;6,.8;rename_box" .. i .. ";;"..waypoints[i].name.."]" ..
|
||||
"image_button[7.3,2.9;.8,.8;ui_ok_icon.png;confirm_rename".. i .. ";]"
|
||||
end
|
||||
|
||||
formspec = formspec .. "label[1,1.3;World position: " ..
|
||||
minetest.pos_to_string(waypoints[i].world_pos) .. "]" ..
|
||||
"label[1,1.8;Name: ".. waypoints[i].name .. "]" ..
|
||||
"label[1,2.3;Hud text color: " ..
|
||||
unified_inventory.hud_colors[waypoints[i].color][3] .. "]"
|
||||
|
||||
return {formspec=formspec}
|
||||
end,
|
||||
})
|
||||
|
||||
unified_inventory.register_button("waypoints", {
|
||||
type = "image",
|
||||
image = "ui_waypoints_icon.png",
|
||||
})
|
||||
|
||||
unified_inventory.update_hud = function (player, waypoint)
|
||||
local name
|
||||
if waypoint.display_pos then
|
||||
name = "("..
|
||||
waypoint.world_pos.x .. "," ..
|
||||
waypoint.world_pos.y .. "," ..
|
||||
waypoint.world_pos.z .. ")"
|
||||
if waypoint.name ~= "" then
|
||||
name = name .. ", " ..
|
||||
waypoint.name
|
||||
end
|
||||
else
|
||||
name = waypoint.name
|
||||
end
|
||||
if waypoint.hud then
|
||||
player:hud_remove(waypoint.hud)
|
||||
end
|
||||
if waypoint.active then
|
||||
waypoint.hud = player:hud_add({
|
||||
hud_elem_type = "waypoint",
|
||||
number = unified_inventory.hud_colors[waypoint.color][2] ,
|
||||
name = name,
|
||||
text = "m",
|
||||
world_pos = waypoint.world_pos
|
||||
})
|
||||
else
|
||||
waypoint.hud = nil
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
if formname ~= "" then
|
||||
return
|
||||
end
|
||||
|
||||
local update_formspec = false
|
||||
local update_hud = false
|
||||
|
||||
local waypoints = datastorage.get_container (player, "waypoints")
|
||||
for i = 1, 5, 1 do
|
||||
|
||||
if fields["select_waypoint"..i] then
|
||||
waypoints.selected = i
|
||||
update_formspec = true
|
||||
end
|
||||
|
||||
if fields["toggle_waypoint"..i] then
|
||||
waypoints[i].active = not (waypoints[i].active)
|
||||
update_hud = true
|
||||
update_formspec = true
|
||||
end
|
||||
|
||||
if fields["set_waypoint"..i] then
|
||||
local pos = player:getpos()
|
||||
pos.x = math.floor(pos.x)
|
||||
pos.y = math.floor(pos.y)
|
||||
pos.z = math.floor(pos.z)
|
||||
waypoints[i].world_pos = pos
|
||||
update_hud = true
|
||||
update_formspec = true
|
||||
end
|
||||
|
||||
if fields["rename_waypoint"..i] then
|
||||
waypoints[i].edit = true
|
||||
update_formspec = true
|
||||
end
|
||||
|
||||
if fields["toggle_display_pos"..i] then
|
||||
waypoints[i].display_pos = not waypoints[i].display_pos
|
||||
update_hud = true
|
||||
update_formspec = true
|
||||
end
|
||||
|
||||
if fields["toggle_color"..i] then
|
||||
local color = waypoints[i].color
|
||||
color = color + 1
|
||||
if color > unified_inventory.hud_colors_max then
|
||||
color = 1
|
||||
end
|
||||
waypoints[i].color = color
|
||||
update_hud = true
|
||||
update_formspec = true
|
||||
end
|
||||
|
||||
if fields["confirm_rename"..i] then
|
||||
waypoints[i].edit = false
|
||||
waypoints[i].name = fields["rename_box"..i]
|
||||
update_hud = true
|
||||
update_formspec = true
|
||||
end
|
||||
|
||||
if update_hud then
|
||||
unified_inventory.update_hud (player, waypoints[i])
|
||||
end
|
||||
|
||||
if update_formspec then
|
||||
unified_inventory.set_inventory_formspec(player, "waypoints")
|
||||
end
|
||||
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
local waypoints = datastorage.get_container (player, "waypoints")
|
||||
local need_save = false
|
||||
-- Create new waypoints data
|
||||
for i = 1, 5, 1 do
|
||||
if waypoints[i] == nil then
|
||||
need_save = true
|
||||
waypoints[i] = {
|
||||
edit = false,
|
||||
active = false,
|
||||
display_pos = true,
|
||||
color = 1,
|
||||
name = "Waypoint ".. i,
|
||||
world_pos = {x = 0, y = 0, z = 0},
|
||||
}
|
||||
end
|
||||
end
|
||||
if need_save then datastorage.save_container (player) end
|
||||
|
||||
-- Initialize waypoints
|
||||
minetest.after(0.5, function()
|
||||
waypoints.selected = 1
|
||||
for i = 1, 5, 1 do
|
||||
waypoints[i].edit = false
|
||||
unified_inventory.update_hud (player, waypoints[i])
|
||||
end
|
||||
end)
|
||||
end)
|