Make correct inventory cubes
This commit is contained in:
parent
eb5a0a68de
commit
40a8c548ab
1
init.lua
1
init.lua
|
@ -38,7 +38,6 @@ i3 = {
|
||||||
fuel_cache = {},
|
fuel_cache = {},
|
||||||
usages_cache = {},
|
usages_cache = {},
|
||||||
recipes_cache = {},
|
recipes_cache = {},
|
||||||
content_ids = {},
|
|
||||||
cubes = {},
|
cubes = {},
|
||||||
|
|
||||||
tabs = {},
|
tabs = {},
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
local replacements = {fuel = {}}
|
local replacements = {fuel = {}}
|
||||||
|
|
||||||
local ItemStack = ItemStack
|
local ItemStack = ItemStack
|
||||||
|
local draw_cube = core.inventorycube
|
||||||
local fmt, reg_items, reg_aliases, reg_nodes = i3.get("fmt", "reg_items", "reg_aliases", "reg_nodes")
|
local fmt, reg_items, reg_aliases, reg_nodes = i3.get("fmt", "reg_items", "reg_aliases", "reg_nodes")
|
||||||
local maxn, copy, insert, sort, match, sub = i3.get("maxn", "copy", "insert", "sort", "match", "sub")
|
local maxn, copy, insert, sort, match, sub = i3.get("maxn", "copy", "insert", "sort", "match", "sub")
|
||||||
|
|
||||||
local is_group, extract_groups, item_has_groups, groups_to_items =
|
local is_group, extract_groups, item_has_groups, groups_to_items =
|
||||||
i3.get("is_group", "extract_groups", "item_has_groups", "groups_to_items")
|
i3.get("is_group", "extract_groups", "item_has_groups", "groups_to_items")
|
||||||
local true_str, is_table, valid_item, table_merge, table_replace, rcp_eq =
|
local true_str, true_table, is_table, valid_item, table_merge, table_replace, rcp_eq =
|
||||||
i3.get("true_str", "is_table", "valid_item", "table_merge", "table_replace", "rcp_eq")
|
i3.get("true_str", "true_table", "is_table", "valid_item", "table_merge", "table_replace", "rcp_eq")
|
||||||
|
|
||||||
local function get_burntime(item)
|
local function get_burntime(item)
|
||||||
return core.get_craft_result{method = "fuel", items = {item}}.time
|
return core.get_craft_result{method = "fuel", items = {item}}.time
|
||||||
|
@ -286,18 +287,40 @@ local function init_recipes()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function get_cube(tiles)
|
||||||
|
if not true_table(tiles) then
|
||||||
|
return "i3_blank.png"
|
||||||
|
end
|
||||||
|
|
||||||
|
local t = copy(tiles)
|
||||||
|
local texture
|
||||||
|
|
||||||
|
for k, v in pairs(t) do
|
||||||
|
if type(v) == "table" then
|
||||||
|
t[k] = v.name
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Tiles: up, down, right, left, back, front
|
||||||
|
-- Inventory cube: up, front, right
|
||||||
|
if #t <= 2 then
|
||||||
|
texture = draw_cube(t[1], t[1], t[1])
|
||||||
|
elseif #t <= 5 then
|
||||||
|
texture = draw_cube(t[1], t[3], t[3])
|
||||||
|
else -- Full tileset
|
||||||
|
texture = draw_cube(t[1], t[6], t[3])
|
||||||
|
end
|
||||||
|
|
||||||
|
return texture
|
||||||
|
end
|
||||||
|
|
||||||
local function init_cubes()
|
local function init_cubes()
|
||||||
for name, def in pairs(reg_nodes) do
|
for name, def in pairs(reg_nodes) do
|
||||||
if def and def.drawtype == "normal" or def.drawtype == "liquid" or
|
if def and def.drawtype == "normal" or def.drawtype == "liquid" or
|
||||||
sub(def.drawtype, 1, 9) == "glasslike" or
|
sub(def.drawtype, 1, 9) == "glasslike" or
|
||||||
sub(def.drawtype, 1, 8) == "allfaces" then
|
sub(def.drawtype, 1, 8) == "allfaces" then
|
||||||
local id = core.get_content_id(name)
|
local id = core.get_content_id(name)
|
||||||
i3.content_ids[id] = name
|
i3.cubes[id] = get_cube(def.tiles)
|
||||||
|
|
||||||
local tile = def.tiles[1].name or def.tiles[1]
|
|
||||||
local cube = core.inventorycube(tile, tile, tile)
|
|
||||||
|
|
||||||
i3.cubes[name] = cube
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,7 +5,7 @@ local ItemStack = ItemStack
|
||||||
local S, min, random = i3.get("S", "min", "random")
|
local S, min, random = i3.get("S", "min", "random")
|
||||||
local reg_items, reg_aliases = i3.get("reg_items", "reg_aliases")
|
local reg_items, reg_aliases = i3.get("reg_items", "reg_aliases")
|
||||||
local fmt, find, match, sub, lower, split = i3.get("fmt", "find", "match", "sub", "lower", "split")
|
local fmt, find, match, sub, lower, split = i3.get("fmt", "find", "match", "sub", "lower", "split")
|
||||||
local vec_new, vec_eq, vec_round = i3.get("vec_new", "vec_eq", "vec_round")
|
local vec_eq, vec_round = i3.get("vec_eq", "vec_round")
|
||||||
local sort, copy, insert, remove, indexof = i3.get("sort", "copy", "insert", "remove", "indexof")
|
local sort, copy, insert, remove, indexof = i3.get("sort", "copy", "insert", "remove", "indexof")
|
||||||
|
|
||||||
local msg, is_fav, pos_to_str, str_to_pos, add_hud_waypoint, play_sound, spawn_item =
|
local msg, is_fav, pos_to_str, str_to_pos, add_hud_waypoint, play_sound, spawn_item =
|
||||||
|
@ -93,7 +93,7 @@ i3.new_tab("inventory", {
|
||||||
remove(data.waypoints, id)
|
remove(data.waypoints, id)
|
||||||
|
|
||||||
elseif action == "teleport" then
|
elseif action == "teleport" then
|
||||||
local pos = vec_new(str_to_pos(waypoint.pos))
|
local pos = str_to_pos(waypoint.pos)
|
||||||
safe_teleport(player, pos)
|
safe_teleport(player, pos)
|
||||||
msg(name, S("Teleported to: @1", waypoint.name))
|
msg(name, S("Teleported to: @1", waypoint.name))
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
local ItemStack = ItemStack
|
local ItemStack = ItemStack
|
||||||
local loadstring = loadstring
|
local loadstring = loadstring
|
||||||
|
|
||||||
local vec_add, vec_mul = vector.add, vector.multiply
|
local vec_new, vec_add, vec_mul = vector.new, vector.add, vector.multiply
|
||||||
local sort, concat, insert = table.sort, table.concat, table.insert
|
local sort, concat, insert = table.sort, table.concat, table.insert
|
||||||
local min, floor, ceil = math.min, math.floor, math.ceil
|
local min, floor, ceil = math.min, math.floor, math.ceil
|
||||||
local fmt, find, match, gmatch, sub, split, lower =
|
local fmt, find, match, gmatch, sub, split, lower =
|
||||||
|
@ -410,10 +410,11 @@ local function safe_teleport(player, pos)
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
play_sound(name, "i3_teleport", 0.8)
|
play_sound(name, "i3_teleport", 0.8)
|
||||||
|
|
||||||
pos.y = pos.y + 0.5
|
local p = vec_new(pos)
|
||||||
|
p.y = p.y + 0.25
|
||||||
local vel = player:get_velocity()
|
local vel = player:get_velocity()
|
||||||
player:add_velocity(vec_mul(vel, -1))
|
player:add_velocity(vec_mul(vel, -1))
|
||||||
player:set_pos(pos)
|
player:set_pos(p)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_sorting_idx(name)
|
local function get_sorting_idx(name)
|
||||||
|
|
13
src/gui.lua
13
src/gui.lua
|
@ -241,17 +241,8 @@ local function get_isometric_view(fs, pos, X, Y)
|
||||||
local area = VoxelArea:new{MinEdge = emin, MaxEdge = emax}
|
local area = VoxelArea:new{MinEdge = emin, MaxEdge = emax}
|
||||||
local data = vm:get_data()
|
local data = vm:get_data()
|
||||||
|
|
||||||
local t = {}
|
|
||||||
data[0] = #data
|
|
||||||
|
|
||||||
for i = 1, data[0] do
|
|
||||||
local id = data[i]
|
|
||||||
t[i] = i3.content_ids[id]
|
|
||||||
end
|
|
||||||
|
|
||||||
for idx in area:iterp(pos1, pos2) do
|
for idx in area:iterp(pos1, pos2) do
|
||||||
local name = t[idx]
|
local cube = i3.cubes[data[idx]]
|
||||||
local cube = i3.cubes[name]
|
|
||||||
|
|
||||||
if cube then
|
if cube then
|
||||||
local p = area:position(idx)
|
local p = area:position(idx)
|
||||||
|
@ -342,7 +333,7 @@ local function get_waypoint_fs(fs, data, player, yextra, ctn_len)
|
||||||
fs("image_button", 4.65, y - 3.25, 0.25, 0.25,
|
fs("image_button", 4.65, y - 3.25, 0.25, 0.25,
|
||||||
PNG.cancel_hover .. "^\\[brighten", "close_preview", "")
|
PNG.cancel_hover .. "^\\[brighten", "close_preview", "")
|
||||||
|
|
||||||
local pos = vec_new(str_to_pos(data.waypoints[i].pos))
|
local pos = str_to_pos(data.waypoints[i].pos)
|
||||||
get_isometric_view(fs, pos, 0.6, y - 2.5)
|
get_isometric_view(fs, pos, 0.6, y - 2.5)
|
||||||
fs("image", 2.7, y - 1.5, 0.3, 0.3, PNG.flag)
|
fs("image", 2.7, y - 1.5, 0.3, 0.3, PNG.flag)
|
||||||
end
|
end
|
||||||
|
|
Ŝarĝante…
Reference in New Issue