From 08ee9794fbc0960a8aab1af21d34f40685809e75 Mon Sep 17 00:00:00 2001 From: JDiaz Date: Mon, 11 Jan 2021 18:03:31 +0100 Subject: Implement on_rightclickplayer callback (#10775) Co-authored-by: rubenwardy --- src/script/cpp_api/s_player.cpp | 13 +++++++++++++ src/script/cpp_api/s_player.h | 1 + 2 files changed, 14 insertions(+) (limited to 'src/script/cpp_api') diff --git a/src/script/cpp_api/s_player.cpp b/src/script/cpp_api/s_player.cpp index 712120c61..d3e6138dc 100644 --- a/src/script/cpp_api/s_player.cpp +++ b/src/script/cpp_api/s_player.cpp @@ -77,6 +77,19 @@ bool ScriptApiPlayer::on_punchplayer(ServerActiveObject *player, return readParam(L, -1); } +void ScriptApiPlayer::on_rightclickplayer(ServerActiveObject *player, + ServerActiveObject *clicker) +{ + SCRIPTAPI_PRECHECKHEADER + // Get core.registered_on_rightclickplayers + lua_getglobal(L, "core"); + lua_getfield(L, -1, "registered_on_rightclickplayers"); + // Call callbacks + objectrefGetOrCreate(L, player); + objectrefGetOrCreate(L, clicker); + runCallbacks(2, RUN_CALLBACKS_MODE_FIRST); +} + s32 ScriptApiPlayer::on_player_hpchange(ServerActiveObject *player, s32 hp_change, const PlayerHPChangeReason &reason) { diff --git a/src/script/cpp_api/s_player.h b/src/script/cpp_api/s_player.h index a337f975b..c0f141862 100644 --- a/src/script/cpp_api/s_player.h +++ b/src/script/cpp_api/s_player.h @@ -47,6 +47,7 @@ public: bool on_punchplayer(ServerActiveObject *player, ServerActiveObject *hitter, float time_from_last_punch, const ToolCapabilities *toolcap, v3f dir, s16 damage); + void on_rightclickplayer(ServerActiveObject *player, ServerActiveObject *clicker); s32 on_player_hpchange(ServerActiveObject *player, s32 hp_change, const PlayerHPChangeReason &reason); void on_playerReceiveFields(ServerActiveObject *player, -- cgit v1.2.3 From 4c76239818f5159314f30883f98b977d30aaa26c Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Fri, 22 Jan 2021 15:09:26 +0000 Subject: Remove dead code (#10845) --- src/client/client.cpp | 20 ----- src/client/client.h | 7 -- src/client/clientenvironment.cpp | 7 -- src/client/hud.cpp | 2 - src/client/mapblock_mesh.cpp | 7 -- src/client/mapblock_mesh.h | 2 - src/client/mesh_generator_thread.h | 1 - src/client/minimap.h | 1 - src/client/tile.cpp | 2 - src/emerge.cpp | 9 +-- src/exceptions.h | 5 -- src/filesys.cpp | 15 ---- src/filesys.h | 3 - src/gui/guiButtonItemImage.cpp | 1 - src/gui/guiButtonItemImage.h | 1 - src/gui/guiChatConsole.h | 2 - src/gui/guiEngine.cpp | 2 - src/gui/guiFormSpecMenu.cpp | 4 +- src/gui/guiFormSpecMenu.h | 2 +- src/map.cpp | 160 ------------------------------------- src/map.h | 8 +- src/mapblock.h | 9 --- src/mapgen/mapgen_v6.cpp | 3 +- src/network/networkexceptions.h | 8 +- src/pathfinder.cpp | 6 +- src/script/cpp_api/s_async.cpp | 29 ------- src/script/cpp_api/s_async.h | 6 -- src/server.h | 3 - src/server/player_sao.h | 1 - src/server/serveractiveobject.h | 3 - src/serverenvironment.h | 10 +-- 31 files changed, 8 insertions(+), 331 deletions(-) (limited to 'src/script/cpp_api') diff --git a/src/client/client.cpp b/src/client/client.cpp index af69d0ec9..6577c287d 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -159,20 +159,6 @@ void Client::loadMods() scanModIntoMemory(BUILTIN_MOD_NAME, getBuiltinLuaPath()); m_script->loadModFromMemory(BUILTIN_MOD_NAME); - // TODO Uncomment when server-sent CSM and verifying of builtin are complete - /* - // Don't load client-provided mods if disabled by server - if (checkCSMRestrictionFlag(CSMRestrictionFlags::CSM_RF_LOAD_CLIENT_MODS)) { - warningstream << "Client-provided mod loading is disabled by server." << - std::endl; - // If builtin integrity is wrong, disconnect user - if (!checkBuiltinIntegrity()) { - // TODO disconnect user - } - return; - } - */ - ClientModConfiguration modconf(getClientModsLuaPath()); m_mods = modconf.getMods(); // complain about mods with unsatisfied dependencies @@ -216,12 +202,6 @@ void Client::loadMods() m_script->on_minimap_ready(m_minimap); } -bool Client::checkBuiltinIntegrity() -{ - // TODO - return true; -} - void Client::scanModSubfolder(const std::string &mod_name, const std::string &mod_path, std::string mod_subpath) { diff --git a/src/client/client.h b/src/client/client.h index bffdc7ec6..25a1b97ba 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -415,11 +415,6 @@ public: return m_csm_restriction_flags & flag; } - u32 getCSMNodeRangeLimit() const - { - return m_csm_restriction_noderange; - } - inline std::unordered_map &getHUDTranslationMap() { return m_hud_server_to_client; @@ -437,7 +432,6 @@ public: } private: void loadMods(); - bool checkBuiltinIntegrity(); // Virtual methods from con::PeerHandler void peerAdded(con::Peer *peer) override; @@ -587,7 +581,6 @@ private: // Client modding ClientScripting *m_script = nullptr; - bool m_modding_enabled; std::unordered_map m_mod_storages; float m_mod_storage_save_timer = 10.0f; std::vector m_mods; diff --git a/src/client/clientenvironment.cpp b/src/client/clientenvironment.cpp index da1e6e9c7..fc7cbe254 100644 --- a/src/client/clientenvironment.cpp +++ b/src/client/clientenvironment.cpp @@ -334,13 +334,6 @@ GenericCAO* ClientEnvironment::getGenericCAO(u16 id) return NULL; } -bool isFreeClientActiveObjectId(const u16 id, - ClientActiveObjectMap &objects) -{ - return id != 0 && objects.find(id) == objects.end(); - -} - u16 ClientEnvironment::addActiveObject(ClientActiveObject *object) { // Register object. If failed return zero id diff --git a/src/client/hud.cpp b/src/client/hud.cpp index e956c2738..46736b325 100644 --- a/src/client/hud.cpp +++ b/src/client/hud.cpp @@ -571,8 +571,6 @@ void Hud::drawCompassTranslate(HudElement *e, video::ITexture *texture, void Hud::drawCompassRotate(HudElement *e, video::ITexture *texture, const core::rect &rect, int angle) { - core::dimension2di imgsize(texture->getOriginalSize()); - core::rect oldViewPort = driver->getViewPort(); core::matrix4 oldProjMat = driver->getTransform(video::ETS_PROJECTION); core::matrix4 oldViewMat = driver->getTransform(video::ETS_VIEW); diff --git a/src/client/mapblock_mesh.cpp b/src/client/mapblock_mesh.cpp index 4c43fcb61..d78a86b2d 100644 --- a/src/client/mapblock_mesh.cpp +++ b/src/client/mapblock_mesh.cpp @@ -1176,13 +1176,6 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset): } if (m_mesh[layer]) { -#if 0 - // Usually 1-700 faces and 1-7 materials - std::cout << "Updated MapBlock has " << fastfaces_new.size() - << " faces and uses " << m_mesh[layer]->getMeshBufferCount() - << " materials (meshbuffers)" << std::endl; -#endif - // Use VBO for mesh (this just would set this for ever buffer) if (m_enable_vbo) m_mesh[layer]->setHardwareMappingHint(scene::EHM_STATIC); diff --git a/src/client/mapblock_mesh.h b/src/client/mapblock_mesh.h index 0308b8161..3b17c4af9 100644 --- a/src/client/mapblock_mesh.h +++ b/src/client/mapblock_mesh.h @@ -125,8 +125,6 @@ public: m_animation_force_timer--; } - void updateCameraOffset(v3s16 camera_offset); - private: scene::IMesh *m_mesh[MAX_TILE_LAYERS]; MinimapMapblock *m_minimap_mapblock; diff --git a/src/client/mesh_generator_thread.h b/src/client/mesh_generator_thread.h index f3c5e7da8..4371b8390 100644 --- a/src/client/mesh_generator_thread.h +++ b/src/client/mesh_generator_thread.h @@ -40,7 +40,6 @@ struct QueuedMeshUpdate { v3s16 p = v3s16(-1337, -1337, -1337); bool ack_block_to_server = false; - bool urgent = false; int crack_level = -1; v3s16 crack_pos; MeshMakeData *data = nullptr; // This is generated in MeshUpdateQueue::pop() diff --git a/src/client/minimap.h b/src/client/minimap.h index 4a2c462f8..87c9668ee 100644 --- a/src/client/minimap.h +++ b/src/client/minimap.h @@ -138,7 +138,6 @@ public: size_t getMaxModeIndex() const { return m_modes.size() - 1; }; void nextMode(); - void setModesFromString(std::string modes_string); MinimapModeDef getModeDef() const { return data->mode; } video::ITexture *getMinimapTexture(); diff --git a/src/client/tile.cpp b/src/client/tile.cpp index 37836d0df..aad956ada 100644 --- a/src/client/tile.cpp +++ b/src/client/tile.cpp @@ -429,7 +429,6 @@ private: // Cached settings needed for making textures from meshes bool m_setting_trilinear_filter; bool m_setting_bilinear_filter; - bool m_setting_anisotropic_filter; }; IWritableTextureSource *createTextureSource() @@ -450,7 +449,6 @@ TextureSource::TextureSource() // for these settings to take effect m_setting_trilinear_filter = g_settings->getBool("trilinear_filter"); m_setting_bilinear_filter = g_settings->getBool("bilinear_filter"); - m_setting_anisotropic_filter = g_settings->getBool("anisotropic_filter"); } TextureSource::~TextureSource() diff --git a/src/emerge.cpp b/src/emerge.cpp index 12e407797..e0dc5628e 100644 --- a/src/emerge.cpp +++ b/src/emerge.cpp @@ -396,14 +396,7 @@ int EmergeManager::getGroundLevelAtPoint(v2s16 p) // TODO(hmmmm): Move this to ServerMap bool EmergeManager::isBlockUnderground(v3s16 blockpos) { -#if 0 - v2s16 p = v2s16((blockpos.X * MAP_BLOCKSIZE) + MAP_BLOCKSIZE / 2, - (blockpos.Y * MAP_BLOCKSIZE) + MAP_BLOCKSIZE / 2); - int ground_level = getGroundLevelAtPoint(p); - return blockpos.Y * (MAP_BLOCKSIZE + 1) <= min(water_level, ground_level); -#endif - - // Use a simple heuristic; the above method is wildly inaccurate anyway. + // Use a simple heuristic return blockpos.Y * (MAP_BLOCKSIZE + 1) <= mgparams->water_level; } diff --git a/src/exceptions.h b/src/exceptions.h index c54307653..a558adc5d 100644 --- a/src/exceptions.h +++ b/src/exceptions.h @@ -72,11 +72,6 @@ public: SettingNotFoundException(const std::string &s): BaseException(s) {} }; -class InvalidFilenameException : public BaseException { -public: - InvalidFilenameException(const std::string &s): BaseException(s) {} -}; - class ItemNotFoundException : public BaseException { public: ItemNotFoundException(const std::string &s): BaseException(s) {} diff --git a/src/filesys.cpp b/src/filesys.cpp index 28a33f4d0..eeba0c564 100644 --- a/src/filesys.cpp +++ b/src/filesys.cpp @@ -401,21 +401,6 @@ void GetRecursiveSubPaths(const std::string &path, } } -bool DeletePaths(const std::vector &paths) -{ - bool success = true; - // Go backwards to succesfully delete the output of GetRecursiveSubPaths - for(int i=paths.size()-1; i>=0; i--){ - const std::string &path = paths[i]; - bool did = DeleteSingleFileOrEmptyDirectory(path); - if(!did){ - errorstream<<"Failed to delete "< &ignore = {}); -// Tries to delete all, returns false if any failed -bool DeletePaths(const std::vector &paths); - // Only pass full paths to this one. True on success. bool RecursiveDeleteContent(const std::string &path); diff --git a/src/gui/guiButtonItemImage.cpp b/src/gui/guiButtonItemImage.cpp index d8b9042ac..39272fe37 100644 --- a/src/gui/guiButtonItemImage.cpp +++ b/src/gui/guiButtonItemImage.cpp @@ -39,7 +39,6 @@ GUIButtonItemImage::GUIButtonItemImage(gui::IGUIEnvironment *environment, item, getActiveFont(), client); sendToBack(m_image); - m_item_name = item; m_client = client; } diff --git a/src/gui/guiButtonItemImage.h b/src/gui/guiButtonItemImage.h index aad923bda..b90ac757e 100644 --- a/src/gui/guiButtonItemImage.h +++ b/src/gui/guiButtonItemImage.h @@ -42,7 +42,6 @@ public: Client *client); private: - std::string m_item_name; Client *m_client; GUIItemImage *m_image; }; diff --git a/src/gui/guiChatConsole.h b/src/gui/guiChatConsole.h index 204f9f9cc..896342ab0 100644 --- a/src/gui/guiChatConsole.h +++ b/src/gui/guiChatConsole.h @@ -68,8 +68,6 @@ public: // Irrlicht draw method virtual void draw(); - bool canTakeFocus(gui::IGUIElement* element) { return false; } - virtual bool OnEvent(const SEvent& event); virtual void setVisible(bool visible); diff --git a/src/gui/guiEngine.cpp b/src/gui/guiEngine.cpp index c5ad5c323..6e2c2b053 100644 --- a/src/gui/guiEngine.cpp +++ b/src/gui/guiEngine.cpp @@ -486,8 +486,6 @@ void GUIEngine::drawHeader(video::IVideoDriver *driver) splashrect += v2s32((screensize.Width/2)-(splashsize.X/2), ((free_space/2)-splashsize.Y/2)+10); - video::SColor bgcolor(255,50,50,50); - draw2DImageFilterScaled(driver, texture, splashrect, core::rect(core::position2d(0,0), core::dimension2di(texture->getOriginalSize())), diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp index 973fc60a8..4415bdd3a 100644 --- a/src/gui/guiFormSpecMenu.cpp +++ b/src/gui/guiFormSpecMenu.cpp @@ -3505,8 +3505,6 @@ bool GUIFormSpecMenu::getAndroidUIInput() GUIInventoryList::ItemSpec GUIFormSpecMenu::getItemAtPos(v2s32 p) const { - core::rect imgrect(0, 0, imgsize.X, imgsize.Y); - for (const GUIInventoryList *e : m_inventorylists) { s32 item_index = e->getItemIndexAtPos(p); if (item_index != -1) @@ -3837,7 +3835,7 @@ ItemStack GUIFormSpecMenu::verifySelectedItem() return ItemStack(); } -void GUIFormSpecMenu::acceptInput(FormspecQuitMode quitmode=quit_mode_no) +void GUIFormSpecMenu::acceptInput(FormspecQuitMode quitmode) { if(m_text_dst) { diff --git a/src/gui/guiFormSpecMenu.h b/src/gui/guiFormSpecMenu.h index 37106cb65..d658aba7b 100644 --- a/src/gui/guiFormSpecMenu.h +++ b/src/gui/guiFormSpecMenu.h @@ -253,7 +253,7 @@ public: void updateSelectedItem(); ItemStack verifySelectedItem(); - void acceptInput(FormspecQuitMode quitmode); + void acceptInput(FormspecQuitMode quitmode=quit_mode_no); bool preprocessEvent(const SEvent& event); bool OnEvent(const SEvent& event); bool doPause; diff --git a/src/map.cpp b/src/map.cpp index 6a7cadca5..aff545921 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -530,23 +530,6 @@ void Map::transformLiquids(std::map &modified_blocks, u32 liquid_loop_max = g_settings->getS32("liquid_loop_max"); u32 loop_max = liquid_loop_max; -#if 0 - - /* If liquid_loop_max is not keeping up with the queue size increase - * loop_max up to a maximum of liquid_loop_max * dedicated_server_step. - */ - if (m_transforming_liquid.size() > loop_max * 2) { - // "Burst" mode - float server_step = g_settings->getFloat("dedicated_server_step"); - if (m_transforming_liquid_loop_count_multiplier - 1.0 < server_step) - m_transforming_liquid_loop_count_multiplier *= 1.0 + server_step / 10; - } else { - m_transforming_liquid_loop_count_multiplier = 1.0; - } - - loop_max *= m_transforming_liquid_loop_count_multiplier; -#endif - while (m_transforming_liquid.size() != 0) { // This should be done here so that it is done when continue is used @@ -1302,18 +1285,6 @@ ServerMap::~ServerMap() */ delete dbase; delete dbase_ro; - -#if 0 - /* - Free all MapChunks - */ - core::map::Iterator i = m_chunks.getIterator(); - for(; i.atEnd() == false; i++) - { - MapChunk *chunk = i.getNode()->getValue(); - delete chunk; - } -#endif } MapgenParams *ServerMap::getMapgenParams() @@ -1402,25 +1373,6 @@ bool ServerMap::initBlockMake(v3s16 blockpos, BlockMakeData *data) data->vmanip = new MMVManip(this); data->vmanip->initialEmerge(full_bpmin, full_bpmax); - // Note: we may need this again at some point. -#if 0 - // Ensure none of the blocks to be generated were marked as - // containing CONTENT_IGNORE - for (s16 z = blockpos_min.Z; z <= blockpos_max.Z; z++) { - for (s16 y = blockpos_min.Y; y <= blockpos_max.Y; y++) { - for (s16 x = blockpos_min.X; x <= blockpos_max.X; x++) { - core::map::Node *n; - n = data->vmanip->m_loaded_blocks.find(v3s16(x, y, z)); - if (n == NULL) - continue; - u8 flags = n->getValue(); - flags &= ~VMANIP_BLOCK_CONTAINS_CIGNORE; - n->setValue(flags); - } - } - } -#endif - // Data is ready now. return true; } @@ -1431,8 +1383,6 @@ void ServerMap::finishBlockMake(BlockMakeData *data, v3s16 bpmin = data->blockpos_min; v3s16 bpmax = data->blockpos_max; - v3s16 extra_borders(1, 1, 1); - bool enable_mapgen_debug_info = m_emerge->enable_mapgen_debug_info; EMERGE_DBG_OUT("finishBlockMake(): " PP(bpmin) " - " PP(bpmax)); @@ -1525,116 +1475,6 @@ MapSector *ServerMap::createSector(v2s16 p2d) return sector; } -#if 0 -/* - This is a quick-hand function for calling makeBlock(). -*/ -MapBlock * ServerMap::generateBlock( - v3s16 p, - std::map &modified_blocks -) -{ - bool enable_mapgen_debug_info = g_settings->getBool("enable_mapgen_debug_info"); - - TimeTaker timer("generateBlock"); - - //MapBlock *block = original_dummy; - - v2s16 p2d(p.X, p.Z); - v2s16 p2d_nodes = p2d * MAP_BLOCKSIZE; - - /* - Do not generate over-limit - */ - if(blockpos_over_limit(p)) - { - infostream<makeChunk(&data); - //mapgen::make_block(&data); - - if(enable_mapgen_debug_info == false) - t.stop(true); // Hide output - } - - /* - Blit data back on map, update lighting, add mobs and whatever this does - */ - finishBlockMake(&data, modified_blocks); - - /* - Get central block - */ - MapBlock *block = getBlockNoCreateNoEx(p); - -#if 0 - /* - Check result - */ - if(block) - { - bool erroneus_content = false; - for(s16 z0=0; z0getNode(p); - if(n.getContent() == CONTENT_IGNORE) - { - infostream<<"CONTENT_IGNORE at " - <<"("<setNode(v3s16(x0,y0,z0), n); - } - } - } -#endif - - if(enable_mapgen_debug_info == false) - timer.stop(true); // Hide output - - return block; -} -#endif - MapBlock * ServerMap::createBlock(v3s16 p) { /* diff --git a/src/map.h b/src/map.h index c8bae9451..e68795c4a 100644 --- a/src/map.h +++ b/src/map.h @@ -417,13 +417,7 @@ private: bool m_map_saving_enabled; int m_map_compression_level; -#if 0 - // Chunk size in MapSectors - // If 0, chunks are disabled. - s16 m_chunksize; - // Chunks - core::map m_chunks; -#endif + std::set m_chunks_in_progress; /* diff --git a/src/mapblock.h b/src/mapblock.h index 641a1b69b..7b82301e9 100644 --- a/src/mapblock.h +++ b/src/mapblock.h @@ -340,15 +340,6 @@ public: // is not valid on this MapBlock. bool isValidPositionParent(v3s16 p); MapNode getNodeParent(v3s16 p, bool *is_valid_position = NULL); - void setNodeParent(v3s16 p, MapNode & n); - - inline void drawbox(s16 x0, s16 y0, s16 z0, s16 w, s16 h, s16 d, MapNode node) - { - for (u16 z = 0; z < d; z++) - for (u16 y = 0; y < h; y++) - for (u16 x = 0; x < w; x++) - setNode(x0 + x, y0 + y, z0 + z, node); - } // Copies data to VoxelManipulator to getPosRelative() void copyTo(VoxelManipulator &dst); diff --git a/src/mapgen/mapgen_v6.cpp b/src/mapgen/mapgen_v6.cpp index e04180f96..bce9cee81 100644 --- a/src/mapgen/mapgen_v6.cpp +++ b/src/mapgen/mapgen_v6.cpp @@ -792,7 +792,7 @@ void MapgenV6::flowMud(s16 &mudflow_minpos, s16 &mudflow_maxpos) v3s16(0, 0, -1), // Front v3s16(-1, 0, 0), // Left }; - + // Iterate twice for (s16 k = 0; k < 2; k++) { for (s16 z = mudflow_minpos; z <= mudflow_maxpos; z++) @@ -1055,7 +1055,6 @@ void MapgenV6::growGrass() // Add surface nodes MapNode n_dirt_with_grass(c_dirt_with_grass); MapNode n_dirt_with_snow(c_dirt_with_snow); MapNode n_snowblock(c_snowblock); - MapNode n_snow(c_snow); const v3s16 &em = vm->m_area.getExtent(); u32 index = 0; diff --git a/src/network/networkexceptions.h b/src/network/networkexceptions.h index f4913928c..58a3bb490 100644 --- a/src/network/networkexceptions.h +++ b/src/network/networkexceptions.h @@ -56,12 +56,6 @@ public: InvalidIncomingDataException(const char *s) : BaseException(s) {} }; -class InvalidOutgoingDataException : public BaseException -{ -public: - InvalidOutgoingDataException(const char *s) : BaseException(s) {} -}; - class NoIncomingDataException : public BaseException { public: @@ -103,4 +97,4 @@ class SendFailedException : public BaseException { public: SendFailedException(const std::string &s) : BaseException(s) {} -}; \ No newline at end of file +}; diff --git a/src/pathfinder.cpp b/src/pathfinder.cpp index 3f0b98c10..1cb84997a 100644 --- a/src/pathfinder.cpp +++ b/src/pathfinder.cpp @@ -157,9 +157,8 @@ public: ArrayGridNodeContainer(Pathfinder *pathf, v3s16 dimensions); virtual PathGridnode &access(v3s16 p); -private: - v3s16 m_dimensions; +private: int m_x_stride; int m_y_stride; std::vector m_nodes_array; @@ -306,8 +305,6 @@ private: int m_max_index_y = 0; /**< max index of search area in y direction */ int m_max_index_z = 0; /**< max index of search area in z direction */ - - int m_searchdistance = 0; /**< max distance to search in each direction */ int m_maxdrop = 0; /**< maximum number of blocks a path may drop */ int m_maxjump = 0; /**< maximum number of blocks a path may jump */ int m_min_target_distance = 0; /**< current smalest path to target */ @@ -619,7 +616,6 @@ std::vector Pathfinder::getPath(v3s16 source, std::vector retval; //initialization - m_searchdistance = searchdistance; m_maxjump = max_jump; m_maxdrop = max_drop; m_start = source; diff --git a/src/script/cpp_api/s_async.cpp b/src/script/cpp_api/s_async.cpp index 5f1f9297e..0619b32c0 100644 --- a/src/script/cpp_api/s_async.cpp +++ b/src/script/cpp_api/s_async.cpp @@ -157,35 +157,6 @@ void AsyncEngine::step(lua_State *L) lua_pop(L, 2); // Pop core and error handler } -/******************************************************************************/ -void AsyncEngine::pushFinishedJobs(lua_State* L) { - // Result Table - MutexAutoLock l(resultQueueMutex); - - unsigned int index = 1; - lua_createtable(L, resultQueue.size(), 0); - int top = lua_gettop(L); - - while (!resultQueue.empty()) { - LuaJobInfo jobDone = resultQueue.front(); - resultQueue.pop_front(); - - lua_createtable(L, 0, 2); // Pre-allocate space for two map fields - int top_lvl2 = lua_gettop(L); - - lua_pushstring(L, "jobid"); - lua_pushnumber(L, jobDone.id); - lua_settable(L, top_lvl2); - - lua_pushstring(L, "retval"); - lua_pushlstring(L, jobDone.serializedResult.data(), - jobDone.serializedResult.size()); - lua_settable(L, top_lvl2); - - lua_rawseti(L, top, index++); - } -} - /******************************************************************************/ void AsyncEngine::prepareEnvironment(lua_State* L, int top) { diff --git a/src/script/cpp_api/s_async.h b/src/script/cpp_api/s_async.h index b1f4bf45f..99a4f891c 100644 --- a/src/script/cpp_api/s_async.h +++ b/src/script/cpp_api/s_async.h @@ -98,12 +98,6 @@ public: */ void step(lua_State *L); - /** - * Push a list of finished jobs onto the stack - * @param L The Lua stack - */ - void pushFinishedJobs(lua_State *L); - protected: /** * Get a Job from queue to be processed diff --git a/src/server.h b/src/server.h index 4b3ac5cf7..a7e85d0e1 100644 --- a/src/server.h +++ b/src/server.h @@ -564,9 +564,6 @@ private: // Craft definition manager IWritableCraftDefManager *m_craftdef; - // Event manager - EventManager *m_event; - // Mods std::unique_ptr m_modmgr; diff --git a/src/server/player_sao.h b/src/server/player_sao.h index 6aee8d5aa..8e2d8803f 100644 --- a/src/server/player_sao.h +++ b/src/server/player_sao.h @@ -114,7 +114,6 @@ public: void rightClick(ServerActiveObject *clicker); void setHP(s32 hp, const PlayerHPChangeReason &reason); void setHPRaw(u16 hp) { m_hp = hp; } - s16 readDamage(); u16 getBreath() const { return m_breath; } void setBreath(const u16 breath, bool send = true); diff --git a/src/server/serveractiveobject.h b/src/server/serveractiveobject.h index 25653a1ad..51f445914 100644 --- a/src/server/serveractiveobject.h +++ b/src/server/serveractiveobject.h @@ -162,8 +162,6 @@ public: {} virtual const ItemGroupList &getArmorGroups() const { static ItemGroupList rv; return rv; } - virtual void setPhysicsOverride(float physics_override_speed, float physics_override_jump, float physics_override_gravity) - {} virtual void setAnimation(v2f frames, float frame_speed, float frame_blend, bool frame_loop) {} virtual void getAnimation(v2f *frames, float *frame_speed, float *frame_blend, bool *frame_loop) @@ -206,7 +204,6 @@ public: } std::string generateUpdateInfantCommand(u16 infant_id, u16 protocol_version); - std::string generateUpdateNametagAttributesCommand(const video::SColor &color) const; void dumpAOMessagesToQueue(std::queue &queue); diff --git a/src/serverenvironment.h b/src/serverenvironment.h index c76d34a37..a11c814ed 100644 --- a/src/serverenvironment.h +++ b/src/serverenvironment.h @@ -190,14 +190,6 @@ enum ClearObjectsMode { CLEAR_OBJECTS_MODE_QUICK, }; -/* - The server-side environment. - - This is not thread-safe. Server uses an environment mutex. -*/ - -typedef std::unordered_map ServerActiveObjectMap; - class ServerEnvironment : public Environment { public: @@ -331,7 +323,7 @@ public: { return m_ao_manager.getObjectsInsideRadius(pos, radius, objects, include_obj_cb); } - + // Find all active objects inside a box void getObjectsInArea(std::vector &objects, const aabb3f &box, std::function include_obj_cb) -- cgit v1.2.3 From 83229921e5f378625d9ef63ede3dffbe778e1798 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 17 Jan 2021 01:56:50 +0100 Subject: Rework use_texture_alpha to provide three opaque/clip/blend modes The change that turns nodeboxes and meshes opaque when possible is kept, as is the compatibility code that warns modders to adjust their nodedefs. --- builtin/game/features.lua | 1 + doc/lua_api.txt | 18 +++++-- src/nodedef.cpp | 110 ++++++++++++++++++++++++++-------------- src/nodedef.h | 56 +++++++++++++++----- src/script/common/c_content.cpp | 32 ++++++++---- src/script/cpp_api/s_node.cpp | 8 +++ src/script/cpp_api/s_node.h | 1 + src/unittest/test.cpp | 4 +- 8 files changed, 164 insertions(+), 66 deletions(-) (limited to 'src/script/cpp_api') diff --git a/builtin/game/features.lua b/builtin/game/features.lua index 4d3c90ff0..36ff1f0b0 100644 --- a/builtin/game/features.lua +++ b/builtin/game/features.lua @@ -18,6 +18,7 @@ core.features = { pathfinder_works = true, object_step_has_moveresult = true, direct_velocity_on_players = true, + use_texture_alpha_string_modes = true, } function core.has_feature(arg) diff --git a/doc/lua_api.txt b/doc/lua_api.txt index cfc150edc..8156f785a 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -4386,6 +4386,8 @@ Utilities object_step_has_moveresult = true, -- Whether get_velocity() and add_velocity() can be used on players (5.4.0) direct_velocity_on_players = true, + -- nodedef's use_texture_alpha accepts new string modes (5.4.0) + use_texture_alpha_string_modes = true, } * `minetest.has_feature(arg)`: returns `boolean, missing_features` @@ -7340,10 +7342,18 @@ Used by `minetest.register_node`. -- If the node has a palette, then this setting only has an effect in -- the inventory and on the wield item. - use_texture_alpha = false, - -- Use texture's alpha channel - -- If this is set to false, the node will be rendered fully opaque - -- regardless of any texture transparency. + use_texture_alpha = ..., + -- Specifies how the texture's alpha channel will be used for rendering. + -- possible values: + -- * "opaque": Node is rendered opaque regardless of alpha channel + -- * "clip": A given pixel is either fully see-through or opaque + -- depending on the alpha channel being below/above 50% in value + -- * "blend": The alpha channel specifies how transparent a given pixel + -- of the rendered node is + -- The default is "opaque" for drawtypes normal, liquid and flowingliquid; + -- "clip" otherwise. + -- If set to a boolean value (deprecated): true either sets it to blend + -- or clip, false sets it to clip or opaque mode depending on the drawtype. palette = "palette.png", -- The node's `param2` is used to select a pixel from the image. diff --git a/src/nodedef.cpp b/src/nodedef.cpp index b2cfd1f87..57d4c008f 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -360,7 +360,7 @@ void ContentFeatures::reset() i = TileDef(); for (auto &j : tiledef_special) j = TileDef(); - alpha = 255; + alpha = ALPHAMODE_OPAQUE; post_effect_color = video::SColor(0, 0, 0, 0); param_type = CPT_NONE; param_type_2 = CPT2_NONE; @@ -405,6 +405,31 @@ void ContentFeatures::reset() node_dig_prediction = "air"; } +void ContentFeatures::setAlphaFromLegacy(u8 legacy_alpha) +{ + // No special handling for nodebox/mesh here as it doesn't make sense to + // throw warnings when the server is too old to support the "correct" way + switch (drawtype) { + case NDT_NORMAL: + alpha = legacy_alpha == 255 ? ALPHAMODE_OPAQUE : ALPHAMODE_CLIP; + break; + case NDT_LIQUID: + case NDT_FLOWINGLIQUID: + alpha = legacy_alpha == 255 ? ALPHAMODE_OPAQUE : ALPHAMODE_BLEND; + break; + default: + alpha = legacy_alpha == 255 ? ALPHAMODE_CLIP : ALPHAMODE_BLEND; + break; + } +} + +u8 ContentFeatures::getAlphaForLegacy() const +{ + // This is so simple only because 255 and 0 mean wildly different things + // depending on drawtype... + return alpha == ALPHAMODE_OPAQUE ? 255 : 0; +} + void ContentFeatures::serialize(std::ostream &os, u16 protocol_version) const { const u8 version = CONTENTFEATURES_VERSION; @@ -433,7 +458,7 @@ void ContentFeatures::serialize(std::ostream &os, u16 protocol_version) const for (const TileDef &td : tiledef_special) { td.serialize(os, protocol_version); } - writeU8(os, alpha); + writeU8(os, getAlphaForLegacy()); writeU8(os, color.getRed()); writeU8(os, color.getGreen()); writeU8(os, color.getBlue()); @@ -489,6 +514,7 @@ void ContentFeatures::serialize(std::ostream &os, u16 protocol_version) const os << serializeString16(node_dig_prediction); writeU8(os, leveled_max); + writeU8(os, alpha); } void ContentFeatures::deSerialize(std::istream &is) @@ -524,7 +550,7 @@ void ContentFeatures::deSerialize(std::istream &is) throw SerializationError("unsupported CF_SPECIAL_COUNT"); for (TileDef &td : tiledef_special) td.deSerialize(is, version, drawtype); - alpha = readU8(is); + setAlphaFromLegacy(readU8(is)); color.setRed(readU8(is)); color.setGreen(readU8(is)); color.setBlue(readU8(is)); @@ -582,10 +608,16 @@ void ContentFeatures::deSerialize(std::istream &is) try { node_dig_prediction = deSerializeString16(is); - u8 tmp_leveled_max = readU8(is); + + u8 tmp = readU8(is); if (is.eof()) /* readU8 doesn't throw exceptions so we have to do this */ throw SerializationError(""); - leveled_max = tmp_leveled_max; + leveled_max = tmp; + + tmp = readU8(is); + if (is.eof()) + throw SerializationError(""); + alpha = static_cast(tmp); } catch(SerializationError &e) {}; } @@ -677,6 +709,7 @@ bool ContentFeatures::textureAlphaCheck(ITextureSource *tsrc, const TileDef *til video::IVideoDriver *driver = RenderingEngine::get_video_driver(); static thread_local bool long_warning_printed = false; std::set seen; + for (int i = 0; i < length; i++) { if (seen.find(tiles[i].name) != seen.end()) continue; @@ -701,20 +734,21 @@ bool ContentFeatures::textureAlphaCheck(ITextureSource *tsrc, const TileDef *til break_loop: image->drop(); - if (!ok) { - warningstream << "Texture \"" << tiles[i].name << "\" of " - << name << " has transparent pixels, assuming " - "use_texture_alpha = true." << std::endl; - if (!long_warning_printed) { - warningstream << " This warning can be a false-positive if " - "unused pixels in the texture are transparent. However if " - "it is meant to be transparent, you *MUST* update the " - "nodedef and set use_texture_alpha = true! This compatibility " - "code will be removed in a few releases." << std::endl; - long_warning_printed = true; - } - return true; + if (ok) + continue; + warningstream << "Texture \"" << tiles[i].name << "\" of " + << name << " has transparency, assuming " + "use_texture_alpha = \"clip\"." << std::endl; + if (!long_warning_printed) { + warningstream << " This warning can be a false-positive if " + "unused pixels in the texture are transparent. However if " + "it is meant to be transparent, you *MUST* update the " + "nodedef and set use_texture_alpha = \"clip\"! This " + "compatibility code will be removed in a few releases." + << std::endl; + long_warning_printed = true; } + return true; } return false; } @@ -759,14 +793,18 @@ void ContentFeatures::updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc bool is_liquid = false; - MaterialType material_type = (alpha == 255) ? - TILE_MATERIAL_BASIC : TILE_MATERIAL_ALPHA; + if (alpha == ALPHAMODE_LEGACY_COMPAT) { + // Before working with the alpha mode, resolve any legacy kludges + alpha = textureAlphaCheck(tsrc, tdef, 6) ? ALPHAMODE_CLIP : ALPHAMODE_OPAQUE; + } + + MaterialType material_type = alpha == ALPHAMODE_OPAQUE ? + TILE_MATERIAL_OPAQUE : (alpha == ALPHAMODE_CLIP ? TILE_MATERIAL_BASIC : + TILE_MATERIAL_ALPHA); switch (drawtype) { default: case NDT_NORMAL: - material_type = (alpha == 255) ? - TILE_MATERIAL_OPAQUE : TILE_MATERIAL_ALPHA; solidness = 2; break; case NDT_AIRLIKE: @@ -774,14 +812,14 @@ void ContentFeatures::updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc break; case NDT_LIQUID: if (tsettings.opaque_water) - alpha = 255; + alpha = ALPHAMODE_OPAQUE; solidness = 1; is_liquid = true; break; case NDT_FLOWINGLIQUID: solidness = 0; if (tsettings.opaque_water) - alpha = 255; + alpha = ALPHAMODE_OPAQUE; is_liquid = true; break; case NDT_GLASSLIKE: @@ -833,19 +871,16 @@ void ContentFeatures::updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc break; case NDT_MESH: case NDT_NODEBOX: - if (alpha == 255 && textureAlphaCheck(tsrc, tdef, 6)) - alpha = 0; - solidness = 0; - if (waving == 1) + if (waving == 1) { material_type = TILE_MATERIAL_WAVING_PLANTS; - else if (waving == 2) + } else if (waving == 2) { material_type = TILE_MATERIAL_WAVING_LEAVES; - else if (waving == 3) - material_type = (alpha == 255) ? TILE_MATERIAL_WAVING_LIQUID_OPAQUE : - TILE_MATERIAL_WAVING_LIQUID_BASIC; - else if (alpha == 255) - material_type = TILE_MATERIAL_OPAQUE; + } else if (waving == 3) { + material_type = alpha == ALPHAMODE_OPAQUE ? + TILE_MATERIAL_WAVING_LIQUID_OPAQUE : (alpha == ALPHAMODE_CLIP ? + TILE_MATERIAL_WAVING_LIQUID_BASIC : TILE_MATERIAL_WAVING_LIQUID_TRANSPARENT); + } break; case NDT_TORCHLIKE: case NDT_SIGNLIKE: @@ -860,10 +895,11 @@ void ContentFeatures::updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc if (is_liquid) { if (waving == 3) { - material_type = (alpha == 255) ? TILE_MATERIAL_WAVING_LIQUID_OPAQUE : - TILE_MATERIAL_WAVING_LIQUID_TRANSPARENT; + material_type = alpha == ALPHAMODE_OPAQUE ? + TILE_MATERIAL_WAVING_LIQUID_OPAQUE : (alpha == ALPHAMODE_CLIP ? + TILE_MATERIAL_WAVING_LIQUID_BASIC : TILE_MATERIAL_WAVING_LIQUID_TRANSPARENT); } else { - material_type = (alpha == 255) ? TILE_MATERIAL_LIQUID_OPAQUE : + material_type = alpha == ALPHAMODE_OPAQUE ? TILE_MATERIAL_LIQUID_OPAQUE : TILE_MATERIAL_LIQUID_TRANSPARENT; } } diff --git a/src/nodedef.h b/src/nodedef.h index 63b9474b9..6fc20518d 100644 --- a/src/nodedef.h +++ b/src/nodedef.h @@ -231,6 +231,14 @@ enum AlignStyle : u8 { ALIGN_STYLE_USER_DEFINED, }; +enum AlphaMode : u8 { + ALPHAMODE_BLEND, + ALPHAMODE_CLIP, + ALPHAMODE_OPAQUE, + ALPHAMODE_LEGACY_COMPAT, /* means either opaque or clip */ +}; + + /* Stand-alone definition of a TileSpec (basically a server-side TileSpec) */ @@ -315,9 +323,7 @@ struct ContentFeatures // These will be drawn over the base tiles. TileDef tiledef_overlay[6]; TileDef tiledef_special[CF_SPECIAL_COUNT]; // eg. flowing liquid - // If 255, the node is opaque. - // Otherwise it uses texture alpha. - u8 alpha; + AlphaMode alpha; // The color of the node. video::SColor color; std::string palette_name; @@ -418,20 +424,27 @@ struct ContentFeatures void serialize(std::ostream &os, u16 protocol_version) const; void deSerialize(std::istream &is); -#ifndef SERVER - /* - * Checks if any tile texture has any transparent pixels. - * Prints a warning and returns true if that is the case, false otherwise. - * This is supposed to be used for use_texture_alpha backwards compatibility. - */ - bool textureAlphaCheck(ITextureSource *tsrc, const TileDef *tiles, - int length); -#endif - - /* Some handy methods */ + void setDefaultAlphaMode() + { + switch (drawtype) { + case NDT_NORMAL: + case NDT_LIQUID: + case NDT_FLOWINGLIQUID: + alpha = ALPHAMODE_OPAQUE; + break; + case NDT_NODEBOX: + case NDT_MESH: + alpha = ALPHAMODE_LEGACY_COMPAT; // this should eventually be OPAQUE + break; + default: + alpha = ALPHAMODE_CLIP; + break; + } + } + bool needsBackfaceCulling() const { switch (drawtype) { @@ -465,6 +478,21 @@ struct ContentFeatures void updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc, scene::IMeshManipulator *meshmanip, Client *client, const TextureSettings &tsettings); #endif + +private: +#ifndef SERVER + /* + * Checks if any tile texture has any transparent pixels. + * Prints a warning and returns true if that is the case, false otherwise. + * This is supposed to be used for use_texture_alpha backwards compatibility. + */ + bool textureAlphaCheck(ITextureSource *tsrc, const TileDef *tiles, + int length); +#endif + + void setAlphaFromLegacy(u8 legacy_alpha); + + u8 getAlphaForLegacy() const; }; /*! diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index 5d29422af..ecab7baa1 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -618,25 +618,39 @@ void read_content_features(lua_State *L, ContentFeatures &f, int index) } lua_pop(L, 1); + /* alpha & use_texture_alpha */ + // This is a bit complicated due to compatibility + + f.setDefaultAlphaMode(); + warn_if_field_exists(L, index, "alpha", - "Obsolete, only limited compatibility provided"); + "Obsolete, only limited compatibility provided; " + "replaced by \"use_texture_alpha\""); if (getintfield_default(L, index, "alpha", 255) != 255) - f.alpha = 0; + f.alpha = ALPHAMODE_BLEND; + + lua_getfield(L, index, "use_texture_alpha"); + if (lua_isboolean(L, -1)) { + warn_if_field_exists(L, index, "use_texture_alpha", + "Boolean values are deprecated; use the new choices"); + if (lua_toboolean(L, -1)) + f.alpha = (f.drawtype == NDT_NORMAL) ? ALPHAMODE_CLIP : ALPHAMODE_BLEND; + } else if (check_field_or_nil(L, -1, LUA_TSTRING, "use_texture_alpha")) { + int result = f.alpha; + string_to_enum(ScriptApiNode::es_TextureAlphaMode, result, + std::string(lua_tostring(L, -1))); + f.alpha = static_cast(result); + } + lua_pop(L, 1); - bool usealpha = getboolfield_default(L, index, - "use_texture_alpha", false); - if (usealpha) - f.alpha = 0; + /* Other stuff */ - // Read node color. lua_getfield(L, index, "color"); read_color(L, -1, &f.color); lua_pop(L, 1); getstringfield(L, index, "palette", f.palette_name); - /* Other stuff */ - lua_getfield(L, index, "post_effect_color"); read_color(L, -1, &f.post_effect_color); lua_pop(L, 1); diff --git a/src/script/cpp_api/s_node.cpp b/src/script/cpp_api/s_node.cpp index e0f9bcd78..269ebacb2 100644 --- a/src/script/cpp_api/s_node.cpp +++ b/src/script/cpp_api/s_node.cpp @@ -93,6 +93,14 @@ struct EnumString ScriptApiNode::es_NodeBoxType[] = {0, NULL}, }; +struct EnumString ScriptApiNode::es_TextureAlphaMode[] = + { + {ALPHAMODE_OPAQUE, "opaque"}, + {ALPHAMODE_CLIP, "clip"}, + {ALPHAMODE_BLEND, "blend"}, + {0, NULL}, + }; + bool ScriptApiNode::node_on_punch(v3s16 p, MapNode node, ServerActiveObject *puncher, const PointedThing &pointed) { diff --git a/src/script/cpp_api/s_node.h b/src/script/cpp_api/s_node.h index 81b44f0f0..3f771c838 100644 --- a/src/script/cpp_api/s_node.h +++ b/src/script/cpp_api/s_node.h @@ -54,4 +54,5 @@ public: static struct EnumString es_ContentParamType2[]; static struct EnumString es_LiquidType[]; static struct EnumString es_NodeBoxType[]; + static struct EnumString es_TextureAlphaMode[]; }; diff --git a/src/unittest/test.cpp b/src/unittest/test.cpp index a783ccd32..af324e1b1 100644 --- a/src/unittest/test.cpp +++ b/src/unittest/test.cpp @@ -180,7 +180,7 @@ void TestGameDef::defineSomeNodes() "{default_water.png"; f = ContentFeatures(); f.name = itemdef.name; - f.alpha = 128; + f.alpha = ALPHAMODE_BLEND; f.liquid_type = LIQUID_SOURCE; f.liquid_viscosity = 4; f.is_ground_content = true; @@ -201,7 +201,7 @@ void TestGameDef::defineSomeNodes() "{default_lava.png"; f = ContentFeatures(); f.name = itemdef.name; - f.alpha = 128; + f.alpha = ALPHAMODE_OPAQUE; f.liquid_type = LIQUID_SOURCE; f.liquid_viscosity = 7; f.light_source = LIGHT_MAX-1; -- cgit v1.2.3 From 6e0e0324a48130376ab3c9fef03b84ee25608242 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Sun, 31 Jan 2021 18:49:51 +0000 Subject: Fix minetest.dig_node returning true when node isn't diggable (#10890) --- builtin/game/item.lua | 6 ++++-- doc/lua_api.txt | 2 ++ src/script/cpp_api/s_node.cpp | 11 ++++++++--- 3 files changed, 14 insertions(+), 5 deletions(-) (limited to 'src/script/cpp_api') diff --git a/builtin/game/item.lua b/builtin/game/item.lua index 63f8d50e5..881aff52e 100644 --- a/builtin/game/item.lua +++ b/builtin/game/item.lua @@ -557,7 +557,7 @@ function core.node_dig(pos, node, digger) log("info", diggername .. " tried to dig " .. node.name .. " which is not diggable " .. core.pos_to_string(pos)) - return + return false end if core.is_protected(pos, diggername) then @@ -566,7 +566,7 @@ function core.node_dig(pos, node, digger) .. " at protected position " .. core.pos_to_string(pos)) core.record_protection_violation(pos, diggername) - return + return false end log('action', diggername .. " digs " @@ -649,6 +649,8 @@ function core.node_dig(pos, node, digger) local node_copy = {name=node.name, param1=node.param1, param2=node.param2} callback(pos_copy, node_copy, digger) end + + return true end function core.itemstring_with_palette(item, palette_index) diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 8156f785a..df9e3f8b0 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -7628,6 +7628,8 @@ Used by `minetest.register_node`. on_dig = function(pos, node, digger), -- default: minetest.node_dig -- By default checks privileges, wears out tool and removes node. + -- return true if the node was dug successfully, false otherwise. + -- Deprecated: returning nil is the same as returning true. on_timer = function(pos, elapsed), -- default: nil diff --git a/src/script/cpp_api/s_node.cpp b/src/script/cpp_api/s_node.cpp index 269ebacb2..f23fbfbde 100644 --- a/src/script/cpp_api/s_node.cpp +++ b/src/script/cpp_api/s_node.cpp @@ -141,9 +141,14 @@ bool ScriptApiNode::node_on_dig(v3s16 p, MapNode node, push_v3s16(L, p); pushnode(L, node, ndef); objectrefGetOrCreate(L, digger); - PCALL_RES(lua_pcall(L, 3, 0, error_handler)); - lua_pop(L, 1); // Pop error handler - return true; + PCALL_RES(lua_pcall(L, 3, 1, error_handler)); + + // nil is treated as true for backwards compat + bool result = lua_isnil(L, -1) || lua_toboolean(L, -1); + + lua_pop(L, 2); // Pop error handler and result + + return result; } void ScriptApiNode::node_on_construct(v3s16 p, MapNode node) -- cgit v1.2.3