From e1ff5b13619666e5b987ecf4faaf294400ffd979 Mon Sep 17 00:00:00 2001 From: Jeija Date: Wed, 23 Jan 2013 18:32:02 +0100 Subject: Allow spawning particles from the server, from lua Spawn single particles or make use of ParticleSpawner for many randomly spawned particles. Accessible in Lua using minetest.spawn_particle and minetest.add_particlespawner. Increase Protocol Version to 17. Conflicts: src/clientserver.h --- src/game.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) (limited to 'src/game.cpp') diff --git a/src/game.cpp b/src/game.cpp index 1ae29b13b..58ca654a0 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -2186,6 +2186,47 @@ void the_game( { update_wielded_item_trigger = true; } + else if(event.type == CE_SPAWN_PARTICLE) + { + LocalPlayer* player = client.getEnv().getLocalPlayer(); + AtlasPointer ap = + gamedef->tsrc()->getTexture(*(event.spawn_particle.texture)); + + new Particle(gamedef, smgr, player, client.getEnv(), + *event.spawn_particle.pos, + *event.spawn_particle.vel, + *event.spawn_particle.acc, + event.spawn_particle.expirationtime, + event.spawn_particle.size, + event.spawn_particle.collisiondetection, ap); + } + else if(event.type == CE_ADD_PARTICLESPAWNER) + { + LocalPlayer* player = client.getEnv().getLocalPlayer(); + AtlasPointer ap = + gamedef->tsrc()->getTexture(*(event.add_particlespawner.texture)); + + new ParticleSpawner(gamedef, smgr, player, + event.add_particlespawner.amount, + event.add_particlespawner.spawntime, + *event.add_particlespawner.minpos, + *event.add_particlespawner.maxpos, + *event.add_particlespawner.minvel, + *event.add_particlespawner.maxvel, + *event.add_particlespawner.minacc, + *event.add_particlespawner.maxacc, + event.add_particlespawner.minexptime, + event.add_particlespawner.maxexptime, + event.add_particlespawner.minsize, + event.add_particlespawner.maxsize, + event.add_particlespawner.collisiondetection, + ap, + event.add_particlespawner.id); + } + else if(event.type == CE_DELETE_PARTICLESPAWNER) + { + delete_particlespawner (event.delete_particlespawner.id); + } } } @@ -2415,7 +2456,8 @@ void the_game( const ContentFeatures &features = client.getNodeDefManager()->get(n); addPunchingParticles - (gamedef, smgr, player, nodepos, features.tiles); + (gamedef, smgr, player, client.getEnv(), + nodepos, features.tiles); } } @@ -2453,7 +2495,8 @@ void the_game( const ContentFeatures &features = client.getNodeDefManager()->get(wasnode); addDiggingParticles - (gamedef, smgr, player, nodepos, features.tiles); + (gamedef, smgr, player, client.getEnv(), + nodepos, features.tiles); } dig_time = 0; @@ -2734,6 +2777,7 @@ void the_game( */ allparticles_step(dtime, client.getEnv()); + allparticlespawners_step(dtime, client.getEnv()); /* Fog @@ -3220,6 +3264,7 @@ void the_game( clouds->drop(); if(gui_chat_console) gui_chat_console->drop(); + clear_particles (); /* Draw a "shutting down" screen, which will be shown while the map -- cgit v1.2.3 From 5e7e0347cdae0cab3b7d003fbd3b22c7f820e703 Mon Sep 17 00:00:00 2001 From: PilzAdam Date: Mon, 25 Mar 2013 23:59:17 +0100 Subject: Add different place sound for nodes --- doc/lua_api.txt | 4 ++++ games/minimal/mods/default/init.lua | 2 ++ src/clientserver.h | 1 + src/game.cpp | 8 +++----- src/itemdef.cpp | 30 +++++++++++++++++++++++++++--- src/itemdef.h | 2 ++ src/scriptapi_item.cpp | 8 ++++++++ 7 files changed, 47 insertions(+), 8 deletions(-) (limited to 'src/game.cpp') diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 42ca58239..beb70db15 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -1514,6 +1514,9 @@ Item definition (register_node, register_craftitem, register_tool) ^ Otherwise should be name of node which the client immediately places on ground when the player places the item. Server will always update actual result to client in a short moment. + sound = { + place = , + } on_place = func(itemstack, placer, pointed_thing), ^ Shall place item and return the leftover itemstack @@ -1581,6 +1584,7 @@ Node definition (register_node) footstep = , dig = , -- "__group" = group-based sound (default) dug = , + place = , }, on_construct = func(pos), diff --git a/games/minimal/mods/default/init.lua b/games/minimal/mods/default/init.lua index fbb481a0c..163998883 100644 --- a/games/minimal/mods/default/init.lua +++ b/games/minimal/mods/default/init.lua @@ -659,6 +659,8 @@ function default.node_sound_dirt_defaults(table) {name="", gain=0.5} --table.dug = table.dug or -- {name="default_dirt_break", gain=0.5} + table.place = table.place or + {name="default_grass_footstep", gain=0.5} default.node_sound_defaults(table) return table end diff --git a/src/clientserver.h b/src/clientserver.h index aba84fb31..28b579971 100644 --- a/src/clientserver.h +++ b/src/clientserver.h @@ -87,6 +87,7 @@ SharedBuffer makePacket_TOCLIENT_TIME_OF_DAY(u16 time, float time_speed); TOCLIENT_DELETE_PARTICLESPAWNER PROTOCOL_VERSION 18: damageGroups added to ToolCapabilities + sound_place added to ItemDefinition */ #define LATEST_PROTOCOL_VERSION 18 diff --git a/src/game.cpp b/src/game.cpp index 58ca654a0..5e4e06148 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -2394,11 +2394,6 @@ void the_game( } } - // We can't actually know, but assume the sound of right-clicking - // to be the sound of placing a node - soundmaker.m_player_rightpunch_sound.gain = 0.5; - soundmaker.m_player_rightpunch_sound.name = "default_place_node"; - /* Handle digging */ @@ -2617,6 +2612,9 @@ void the_game( <<") - Position not loaded"<second); } os< 17){ + //serializeSimpleSoundSpec(sound_place, os); + os< #include #include "itemgroup.h" +#include "sound.h" class IGameDef; struct ToolCapabilities; @@ -66,6 +67,7 @@ struct ItemDefinition // May be NULL. If non-NULL, deleted by destructor ToolCapabilities *tool_capabilities; ItemGroupList groups; + SimpleSoundSpec sound_place; // Client shall immediately place this node when player places the item. // Server will update the precise end result a moment later. diff --git a/src/scriptapi_item.cpp b/src/scriptapi_item.cpp index 204939f8f..b266d856d 100644 --- a/src/scriptapi_item.cpp +++ b/src/scriptapi_item.cpp @@ -96,6 +96,14 @@ ItemDefinition read_item_definition(lua_State *L, int index, read_groups(L, -1, def.groups); lua_pop(L, 1); + lua_getfield(L, index, "sounds"); + if(lua_istable(L, -1)){ + lua_getfield(L, -1, "place"); + read_soundspec(L, -1, def.sound_place); + lua_pop(L, 1); + } + lua_pop(L, 1); + // Client shall immediately place this node when player places the item. // Server will update the precise end result a moment later. // "" = no prediction -- cgit v1.2.3