Improved X-Ray, added AutoEject

pull/10/head
Elias Fleckenstein 2020-10-05 22:25:36 +02:00
parent faa32610e3
commit 43ee069dbf
11 changed files with 148 additions and 27 deletions

View File

@ -16,8 +16,9 @@
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
--------------------------------------------------------------------------------
local hackers = {
"Elias Fleckenstein <eliasfleckenstein@web.de>"
local dragonfire_team = {
"Elias Fleckenstein <eliasfleckenstein@web.de> [Main Developer]",
"DerZombiiie [Bots, User Support]",
}
local core_developers = {
@ -109,8 +110,8 @@ return {
"tablecolumns[color;text]" ..
"tableoptions[background=#00000000;highlight=#00000000;border=false]" ..
"table[3.5,-0.25;8.5,6.05;list_credits;" ..
"#FFFF00," .. fgettext("Hackers") .. ",," ..
buildCreditList(hackers) .. ",,," ..
"#FFFF00," .. fgettext("Dragonfire Team") .. ",," ..
buildCreditList(dragonfire_team) .. ",,," ..
"#FFFF00," .. fgettext("Core Developers") .. ",," ..
buildCreditList(core_developers) .. ",,," ..
"#FFFF00," .. fgettext("Active Contributors") .. ",," ..

View File

@ -0,0 +1,28 @@
local old_index
minetest.register_globalstep(function()
if inventory_mod.nodrop then
inventory_mod.nodrop = false
return
end
local player = minetest.localplayer
if old_index then
player:set_wield_index(old_index)
minetest.set_keypress("drop", false)
old_index = nil
elseif minetest.settings:get_bool("autoeject") then
local list = (minetest.settings:get("eject_items") or ""):split(",")
local inventory = minetest.get_inventory("current_player")
for index, stack in pairs(inventory.main) do
if table.indexof(list, stack:get_name()) ~= -1 then
old_index = player:get_wield_index()
player:set_wield_index(index - 1)
minetest.set_keypress("drop", true) -- causes to drop tools selected using autotool sometimes, just
return
end
end
end
end)
minetest.register_chatcommand("eject", list.new("Configure AutoEject", "eject_items"))
minetest.register_cheat("AutoEject", "Player", "autoeject")

View File

@ -1,8 +1,11 @@
inventory_mod = {}
local modname = minetest.get_current_modname()
local modpath = minetest.get_modpath(modname)
dofile(modpath .. "/invhack.lua")
dofile(modpath .. "/enderchest.lua")
dofile(modpath .. "/next_item.lua")
dofile(modpath .. "/enderchest.lua")
dofile(modpath .. "/hand.lua")
dofile(modpath .. "/next_item.lua")
dofile(modpath .. "/autotool.lua")
dofile(modpath .. "/hand.lua")
dofile(modpath .. "/autoeject.lua")

View File

@ -1,3 +1,4 @@
name = inventory
author = Fleckenstein
description = The inventory cheats for Dragonfireclient
dependencies = list

View File

@ -1,2 +1,4 @@
next_item (NextItem) bool false
autotool (AutoTool) bool false
autoeject (AutoEject) bool false
eject_items (AutoEject Items) string

View File

@ -0,0 +1,47 @@
list = {}
function list.new(desc, setting)
local def = {}
def.description = desc
def.params = "del <item> | add <item> | list"
function def.func(param)
local list = (minetest.settings:get(setting) or ""):split(",")
if param == "list" then
return true, table.concat(list, ", ")
else
local sparam = param:split(" ")
local cmd = sparam[1]
local item = sparam[2]
if cmd == "del" then
if not item then
return false, "Missing item."
end
local i = table.indexof(list, item)
if i == -1 then
return false, item .. " is not on the list."
else
table.remove(list, i)
minetest.settings:set(setting, table.concat(list, ","))
return true, "Removed " .. item .. " from the list."
end
elseif cmd == "add" then
if not item then
return false, "Missing item."
end
local i = table.indexof(list, item)
if i ~= -1 then
return false, item .. " is already on the list."
else
table.insert(list, item)
minetest.settings:set(setting, table.concat(list, ","))
return true, "Added " .. item .. " to the list."
end
end
end
return false, "Invalid usage. (See /help <command>)"
end
return def
end
minetest.register_chatcommand("xray", list.new("Configure X-Ray", "xray_nodes"))
--minetest.register_chatcommand("Configure Search Nodes", "search_nodes")

View File

@ -9,3 +9,4 @@ load_mod_pathfinding = true
load_mod_autoeat = true
load_mod_perlin = true
load_mod_autosneak = true
load_mod_list = true

View File

@ -1664,9 +1664,12 @@ void Client::addUpdateMeshTaskForNode(v3s16 nodepos, bool ack_to_server, bool ur
void Client::updateAllMapBlocks()
{
v3s16 currentBlock = getNodeBlockPos(floatToInt(m_env.getLocalPlayer()->getPosition(), BS));
addUpdateMeshTaskWithEdge(currentBlock, false, true);
for (s16 X = currentBlock.X - 2; X <= currentBlock.X + 2; X++)
for (s16 Y = currentBlock.Y - 2; Y <= currentBlock.Y + 2; Y++)
for (s16 Z = currentBlock.Z - 2; Z <= currentBlock.Z + 2; Z++)
addUpdateMeshTask(v3s16(X, Y, Z), false, true);
std::map<v2s16, MapSector*> *sectors = m_env.getMap().getSectorsPtr();

View File

@ -112,7 +112,7 @@ Game::Game() :
&freecamChangedCallback, this);
g_settings->registerChangedCallback("xray",
&updateAllMapBlocksCallback, this);
g_settings->registerChangedCallback("xray_node",
g_settings->registerChangedCallback("xray_nodes",
&updateAllMapBlocksCallback, this);
g_settings->registerChangedCallback("fullbright",
&updateAllMapBlocksCallback, this);
@ -178,7 +178,7 @@ Game::~Game()
&freecamChangedCallback, this);
g_settings->deregisterChangedCallback("xray",
&updateAllMapBlocksCallback, this);
g_settings->deregisterChangedCallback("xray_node",
g_settings->deregisterChangedCallback("xray_nodes",
&updateAllMapBlocksCallback, this);
g_settings->deregisterChangedCallback("fullbright",
&updateAllMapBlocksCallback, this);

View File

@ -788,6 +788,24 @@ void getNodeTile(MapNode mn, const v3s16 &p, const v3s16 &dir, MeshMakeData *dat
tile.rotation = tile.world_aligned ? 0 : dir_to_tile[tile_index + 1];
}
std::set<content_t> splitToContentT(std::string str, const NodeDefManager *ndef)
{
str += "\n";
std::set<content_t> dat;
std::string buf;
for (char c : str) {
if (c == ',' || c == '\n') {
if (! buf.empty()) {
dat.insert(ndef->getId(buf));
}
buf.clear();
} else if (c != ' ') {
buf += c;
}
}
return dat;
}
static void getTileInfo(
// Input:
MeshMakeData *data,
@ -799,19 +817,19 @@ static void getTileInfo(
v3s16 &face_dir_corrected,
u16 *lights,
u8 &waving,
TileSpec &tile
TileSpec &tile,
bool xray,
std::set<content_t> xraySet
)
{
VoxelManipulator &vmanip = data->m_vmanip;
const NodeDefManager *ndef = data->m_client->ndef();
v3s16 blockpos_nodes = data->m_blockpos * MAP_BLOCKSIZE;
content_t cXray = ndef->getId(g_settings->get("xray_node"));
bool xray = g_settings->getBool("xray");
const MapNode &n0 = vmanip.getNodeRefUnsafe(blockpos_nodes + p);
content_t c0 = n0.getContent();
if (xray && c0 == cXray)
if (xray && xraySet.find(c0) != xraySet.end())
c0 = CONTENT_AIR;
// Don't even try to get n1 if n0 is already CONTENT_IGNORE
@ -823,7 +841,7 @@ static void getTileInfo(
const MapNode &n1 = vmanip.getNodeRefUnsafeCheckFlags(blockpos_nodes + p + face_dir);
content_t c1 = n1.getContent();
if (xray && c1 == cXray)
if (xray && xraySet.find(c1) != xraySet.end())
c1 = CONTENT_AIR;
if (c1 == CONTENT_IGNORE) {
@ -889,7 +907,9 @@ static void updateFastFaceRow(
v3s16 translate_dir,
const v3f &&translate_dir_f,
const v3s16 &&face_dir,
std::vector<FastFace> &dest)
std::vector<FastFace> &dest,
bool xray,
std::set<content_t> xraySet)
{
static thread_local const bool waving_liquids =
g_settings->getBool("enable_shaders") &&
@ -909,7 +929,7 @@ static void updateFastFaceRow(
// Get info of first tile
getTileInfo(data, p, face_dir,
makes_face, p_corrected, face_dir_corrected,
lights, waving, tile);
lights, waving, tile, xray, xraySet);
// Unroll this variable which has a significant build cost
TileSpec next_tile;
@ -931,7 +951,9 @@ static void updateFastFaceRow(
next_makes_face, next_p_corrected,
next_face_dir_corrected, next_lights,
waving,
next_tile);
next_tile,
xray,
xraySet);
if (next_makes_face == makes_face
&& next_p_corrected == p_corrected + translate_dir
@ -981,7 +1003,7 @@ static void updateFastFaceRow(
}
static void updateAllFastFaceRows(MeshMakeData *data,
std::vector<FastFace> &dest)
std::vector<FastFace> &dest, bool xray, std::set<content_t> xraySet)
{
/*
Go through every y,z and get top(y+) faces in rows of x+
@ -993,7 +1015,9 @@ static void updateAllFastFaceRows(MeshMakeData *data,
v3s16(1, 0, 0), //dir
v3f (1, 0, 0),
v3s16(0, 1, 0), //face dir
dest);
dest,
xray,
xraySet);
/*
Go through every x,y and get right(x+) faces in rows of z+
@ -1005,7 +1029,9 @@ static void updateAllFastFaceRows(MeshMakeData *data,
v3s16(0, 0, 1), //dir
v3f (0, 0, 1),
v3s16(1, 0, 0), //face dir
dest);
dest,
xray,
xraySet);
/*
Go through every y,z and get back(z+) faces in rows of x+
@ -1017,7 +1043,9 @@ static void updateAllFastFaceRows(MeshMakeData *data,
v3s16(1, 0, 0), //dir
v3f (1, 0, 0),
v3s16(0, 0, 1), //face dir
dest);
dest,
xray,
xraySet);
}
static void applyTileColor(PreMeshBuffer &pmb)
@ -1064,18 +1092,25 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
std::vector<FastFace> fastfaces_new;
fastfaces_new.reserve(512);
/*
X-Ray
*/
bool xray = g_settings->getBool("xray");
std::set<content_t> xraySet;
if (xray)
xraySet = splitToContentT(g_settings->get("xray_nodes"), data->m_client->ndef());
/*
We are including the faces of the trailing edges of the block.
This means that when something changes, the caller must
also update the meshes of the blocks at the leading edges.
NOTE: This is the slowest part of this method.
*/
*/
{
// 4-23ms for MAP_BLOCKSIZE=16 (NOTE: probably outdated)
//TimeTaker timer2("updateAllFastFaceRows()");
updateAllFastFaceRows(data, fastfaces_new);
updateAllFastFaceRows(data, fastfaces_new, xray, xraySet);
}
// End of slow part

View File

@ -66,7 +66,7 @@ void set_default_settings(Settings *settings)
// Cheats
settings->setDefault("xray", "false");
settings->setDefault("xray_node", "default:stone");
settings->setDefault("xray_nodes", "default:stone,mcl_core:stone");
settings->setDefault("fullbright", "false");
settings->setDefault("priv_bypass", "true");
settings->setDefault("fastdig", "false");