]> git.lizzy.rs Git - dragonfireclient.git/commitdiff
Lua API: Particle callbacks; Add NoWeather
authorElias Fleckenstein <eliasfleckenstein@web.de>
Mon, 30 Nov 2020 10:20:07 +0000 (11:20 +0100)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Mon, 30 Nov 2020 10:20:07 +0000 (11:20 +0100)
builtin/client/cheats/init.lua
builtin/client/cheats/render.lua
builtin/client/register.lua
builtin/settingtypes.txt
doc/client_lua_api.txt
src/defaultsettings.cpp
src/network/clientpackethandler.cpp
src/script/common/c_content.cpp
src/script/common/c_content.h
src/script/cpp_api/s_client.cpp
src/script/cpp_api/s_client.h

index 31657e9ed96d433c14b6ddfc5a4ce916c11bda13..30c3fe2085c77b8e0f50ead62d721af0a290efa4 100644 (file)
@@ -39,6 +39,7 @@ core.cheats = {
                ["PlayerTracers"] = "enable_player_tracers",
                ["NodeESP"] = "enable_node_esp",
                ["NodeTracers"] = "enable_node_tracers",
+               ["NoWeather"] = "noweather",
        },
        ["World"] = {
                ["FastDig"] = "fastdig",
index 6402246f3ca8a47639f45fe0f01b2aef02efbe41..dc3f712471098b6f345f929b746a1b1e63f101bf 100644 (file)
@@ -1,2 +1,14 @@
 core.register_list_command("xray", "Configure X-Ray", "xray_nodes") 
 core.register_list_command("search", "Configure NodeESP", "node_esp_nodes") 
+
+core.register_on_spawn_particle(function(particle)
+       if core.settings:get_bool("noweather") and particle.texture:sub(1, 12) == "weather_pack" then
+               return true
+       end
+end)
+
+core.register_on_play_sound(function(sound)
+       if core.settings:get_bool("noweather") and sound.name == "weather_rain" then
+               return true
+       end
+end)
index 03dc41f71d383f8ffa3ba2e9ff2baac851c8595a..669ef134e0f3631157f647b509a1c21040235a5e 100644 (file)
@@ -104,3 +104,4 @@ core.registered_on_modchannel_signal, core.register_on_modchannel_signal = make_
 core.registered_on_inventory_open, core.register_on_inventory_open = make_registration()
 core.registered_on_recieve_physics_override, core.register_on_recieve_physics_override = make_registration()
 core.registered_on_play_sound, core.register_on_play_sound = make_registration()
+core.registered_on_spawn_particle, core.register_on_spawn_particle = make_registration()
index b66ac3538691ba3b2f8b9f6cec50e5270cbac473..45f20a99d959b8d23bdfb2ee534e6dad98ea033e 100644 (file)
@@ -2366,3 +2366,5 @@ enable_node_tracers (NodeTracers) bool false
 entity_esp_color (EntityESP Color) v3f 255, 255, 255
 
 player_esp_color (PlayerESP Color) v3f 0, 255, 0
+
+noweather (NoWeather) bool false
index 9ce553ca14ac73994cfde5805dd55513958055ff..5618c7a6f62dd501f088c119730a957a392f439b 100644 (file)
@@ -755,10 +755,14 @@ Call these functions only at load time!
     * Called when recieving physics_override from server
     * Newest functions are called first
     * If any function returns true, the physics override does not change
-* `minetest.register_on_sound_play(function(SimpleSoundSpec))`
+* `minetest.register_on_play_sound(function(SimpleSoundSpec))`
     * Called when recieving a play sound command from server
     * Newest functions are called first
     * If any function returns true, the sound does not play
+* `minetest.register_on_spawn_partice(function(particle definition))`
+    * Called when recieving a spawn particle command from server
+    * Newest functions are called first
+    * If any function returns true, the particel does not spawn
 
 ### Setting-related
 * `minetest.settings`: Settings object containing all of the settings from the
index 1410700032053d8962aa4a932ae01f8aeacafd39..bcf5012a97131944982db4cde703a0fe130ed48f 100644 (file)
@@ -146,6 +146,7 @@ void set_default_settings(Settings *settings)
        settings->setDefault("enable_node_tracers", "false");
        settings->setDefault("entity_esp_color", "(255, 255, 255)");
        settings->setDefault("player_esp_color", "(0, 255, 0)");        
+       settings->setDefault("noweather", "false");     
 
        // Keymap
        settings->setDefault("remote_port", "30000");
index c39586f2c3eae5115c318541b01a3e1c80baf9d2..55f85571d3bbe0972e48373f2df370d463730e68 100644 (file)
@@ -988,9 +988,8 @@ void Client::handleCommand_SpawnParticle(NetworkPacket* pkt)
        event->type           = CE_SPAWN_PARTICLE;
        event->spawn_particle = new ParticleParameters(p);
        
-       if (g_settings->getBool("log_particles")) {
-               std::cout << p.pos.X << " " << p.pos.Y << " " << p.pos.Z << std::endl;
-       }
+       if (m_mods_loaded && m_script->on_spawn_particle(*event->spawn_particle))
+               return;
        
        m_client_event_queue.push(event);
 }
index 04f4c335c6d211c9828c50534ea47815ff095107..72361bdb528b98f45c154e3e4d8d5f31caef01b3 100644 (file)
@@ -1324,20 +1324,6 @@ void push_inventory(lua_State *L, Inventory *inventory)
        }
 }
 
-/******************************************************************************/
-void push_inventory_list(lua_State *L, Inventory *inv, const char *name)
-{
-       InventoryList *invlist = inv->getList(name);
-       if(invlist == NULL){
-               lua_pushnil(L);
-               return;
-       }
-       std::vector<ItemStack> items;
-       for(u32 i=0; i<invlist->getSize(); i++)
-               items.push_back(invlist->getItem(i));
-       push_items(L, items);
-}
-
 /******************************************************************************/
 void read_inventory_list(lua_State *L, int tableindex,
                Inventory *inv, const char *name, Server* srv, int forcesize)
@@ -1367,6 +1353,19 @@ void read_inventory_list(lua_State *L, int tableindex,
        }
 }
 
+void push_inventory_list(lua_State *L, Inventory *inv, const char *name)
+{
+       InventoryList *invlist = inv->getList(name);
+       if(invlist == NULL){
+               lua_pushnil(L);
+               return;
+       }
+       std::vector<ItemStack> items;
+       for(u32 i=0; i<invlist->getSize(); i++)
+               items.push_back(invlist->getItem(i));
+       push_items(L, items);
+}
+
 /******************************************************************************/
 struct TileAnimationParams read_animation_definition(lua_State *L, int index)
 {
@@ -1402,6 +1401,29 @@ struct TileAnimationParams read_animation_definition(lua_State *L, int index)
        return anim;
 }
 
+void push_animation_definition(lua_State *L, struct TileAnimationParams anim)
+{
+       switch (anim.type) {
+       case TAT_NONE:
+               lua_pushnil(L);
+               break;
+       case TAT_VERTICAL_FRAMES:
+               lua_newtable(L);
+               setstringfield(L, -1, "type", "vertical_frames");
+               setfloatfield(L, -1, "aspect_w", anim.vertical_frames.aspect_w);
+               setfloatfield(L, -1, "aspect_h", anim.vertical_frames.aspect_h);
+               setfloatfield(L, -1, "length", anim.vertical_frames.length);
+               break;
+       case TAT_SHEET_2D:
+               lua_newtable(L);
+               setstringfield(L, -1, "type", "sheet_2d");
+               setintfield(L, -1, "frames_w", anim.sheet_2d.frames_w);
+               setintfield(L, -1, "frames_h", anim.sheet_2d.frames_h);
+               setintfield(L, -1, "frame_length", anim.sheet_2d.frame_length);
+               break;
+       }
+}
+
 /******************************************************************************/
 ToolCapabilities read_tool_capabilities(
                lua_State *L, int table)
@@ -2103,6 +2125,7 @@ void push_collision_move_result(lua_State *L, const collisionMoveResult &res)
        /**/
 }
 
+/******************************************************************************/
 void push_physics_override(lua_State *L, float speed, float jump, float gravity, bool sneak, bool sneak_glitch, bool new_move)
 {
        lua_createtable(L, 0, 6);
index 08c74c292400d124048a4444c274c3aa6f980bf4..10b77a116eeda9814af797a6a87d5dd9b7956051 100644 (file)
@@ -98,6 +98,7 @@ void               push_hit_params           (lua_State *L,
 ItemStack          read_item                 (lua_State *L, int index, IItemDefManager *idef);
 
 struct TileAnimationParams read_animation_definition(lua_State *L, int index);
+void push_animation_definition(lua_State *L, struct TileAnimationParams anim);
 
 ToolCapabilities   read_tool_capabilities    (lua_State *L, int table);
 void               push_tool_capabilities    (lua_State *L,
index cf7df5b5d759948faee016bb640df0a3023037a8..200a449eedda2a7568a0ab0dde531583b01ae96f 100644 (file)
@@ -253,6 +253,43 @@ bool ScriptApiClient::on_play_sound(SimpleSoundSpec spec)
        return readParam<bool>(L, -1);
 }
 
+bool ScriptApiClient::on_spawn_particle(struct ParticleParameters param)
+{
+       SCRIPTAPI_PRECHECKHEADER
+
+       // Get core.registered_on_play_sound
+       
+       lua_getglobal(L, "core");
+       lua_getfield(L, -1, "registered_on_spawn_particle");
+
+       // Push data
+       lua_newtable(L);
+       push_v3f(L, param.pos);
+       lua_setfield(L, -2, "pos");
+       push_v3f(L, param.vel);
+       lua_setfield(L, -2, "velocity");
+       push_v3f(L, param.acc);
+       lua_setfield(L, -2, "acceleration");
+       setfloatfield(L, -1, "expirationtime", param.expirationtime);
+       setboolfield(L, -1, "collisiondetection", param.collisiondetection);
+       setboolfield(L, -1, "collision_removal", param.collision_removal);
+       setboolfield(L, -1, "object_collision", param.object_collision);
+       setboolfield(L, -1, "vertical", param.vertical);
+       push_animation_definition(L, param.animation);
+       lua_setfield(L, -2, "animation");
+       setstringfield(L, -1, "texture", param.texture);
+       setintfield(L, -1, "glow", param.glow);
+       if (param.node.getContent() != CONTENT_IGNORE) {
+               pushnode(L, param.node, getGameDef()->ndef());
+               lua_setfield(L, -2, "node");
+       }
+       setintfield(L, -1, "node_tile", param.node_tile);       
+       
+       // Call functions
+       runCallbacks(1, RUN_CALLBACKS_MODE_OR);
+       return readParam<bool>(L, -1);
+}
+
 bool ScriptApiClient::on_inventory_open(Inventory *inventory)
 {
        SCRIPTAPI_PRECHECKHEADER
index 8db253d5650c3e9dccdcb178437dc7f29b3a79d0..ff1c473aec55ae72975066918eda58c0d40f377c 100644 (file)
@@ -27,6 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "util/string.h"
 #include "util/pointedthing.h"
 #include "lua_api/l_item.h"
+#include "particles.h"
 
 #ifdef _CRT_MSVCP_CURRENT
 #include <cstdint>
@@ -59,6 +60,7 @@ class ScriptApiClient : virtual public ScriptApiBase
        bool on_item_use(const ItemStack &item, const PointedThing &pointed);
        bool on_recieve_physics_override(float override_speed, float override_jump, float override_gravity, bool sneak, bool sneak_glitch, bool new_move);
        bool on_play_sound(SimpleSoundSpec spec);
+       bool on_spawn_particle(struct ParticleParameters param);
 
        bool on_inventory_open(Inventory *inventory);
        void open_enderchest();