mirror of https://github.com/minetest/minetest.git
Add method set_node_visual and get_node_visual to player Lua object and needed logic around it to allow game to set variant_offset
This commit is contained in:
parent
f1c082cd62
commit
81db5abe5a
|
@ -8418,6 +8418,13 @@ child will follow movement and rotation of that bone.
|
||||||
|
|
||||||
* `get_lighting()`: returns the current state of lighting for the player.
|
* `get_lighting()`: returns the current state of lighting for the player.
|
||||||
* Result is a table with the same fields as `light_definition` in `set_lighting`.
|
* Result is a table with the same fields as `light_definition` in `set_lighting`.
|
||||||
|
* `set_node_visual(node_name, node_visual)`: sets `node_visual` of `node_name` for the player
|
||||||
|
* `node_name` is a name of registered node.
|
||||||
|
* `node_visual` is a table with the following optional fields:
|
||||||
|
* `variant_offset` this value is added to variant from node param2 value (default: `0`).
|
||||||
|
|
||||||
|
* `get_node_visual(node_name)`: returns the current `node_visual` of `node_name` for the player.
|
||||||
|
* Result is a table with the same fields as `node_visual` in `set_node_visual`.
|
||||||
* `respawn()`: Respawns the player using the same mechanism as the death screen,
|
* `respawn()`: Respawns the player using the same mechanism as the death screen,
|
||||||
including calling `on_respawnplayer` callbacks.
|
including calling `on_respawnplayer` callbacks.
|
||||||
|
|
||||||
|
|
|
@ -12,3 +12,4 @@ dofile(path.."/textures.lua")
|
||||||
dofile(path.."/overlays.lua")
|
dofile(path.."/overlays.lua")
|
||||||
dofile(path.."/variants.lua")
|
dofile(path.."/variants.lua")
|
||||||
dofile(path.."/commands.lua")
|
dofile(path.."/commands.lua")
|
||||||
|
dofile(path.."/node_visual.lua")
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
-- add command to change node_visual
|
||||||
|
|
||||||
|
minetest.register_chatcommand("node_visual", {
|
||||||
|
params = "nodename field [value]",
|
||||||
|
description = "Change node_visual field of actual player to value or show value of field.",
|
||||||
|
func = function(name, param)
|
||||||
|
local player = minetest.get_player_by_name(name)
|
||||||
|
if not player then
|
||||||
|
return false, "No player."
|
||||||
|
end
|
||||||
|
|
||||||
|
local splits = string.split(param, " ", false, 3)
|
||||||
|
|
||||||
|
if #splits < 2 then
|
||||||
|
return false, "Expected node name and node_visual field as parameters."
|
||||||
|
end
|
||||||
|
|
||||||
|
local node_name = splits[1]
|
||||||
|
local field_name = splits[2]
|
||||||
|
|
||||||
|
if not minetest.registered_nodes[node_name] then
|
||||||
|
return false, "Unknown node "..node_name
|
||||||
|
end
|
||||||
|
|
||||||
|
local node_visual = player:get_node_visual(node_name)
|
||||||
|
|
||||||
|
if rawequal(node_visual[field_name], nil) then
|
||||||
|
return false, "Field "..field_name.." not found in node_visual."
|
||||||
|
end
|
||||||
|
|
||||||
|
if #splits > 2 then
|
||||||
|
if type(node_visual[field_name]) == "number" then
|
||||||
|
node_visual[field_name] = tonumber(splits[3])
|
||||||
|
elseif type(node_visual[field_name]) == "table" then
|
||||||
|
node_visual[field_name] = minetest.parse_json(splits[3])
|
||||||
|
if type(node_visual[field_name]) ~= "table" then
|
||||||
|
return false, "Table in json format is expected as value."
|
||||||
|
end
|
||||||
|
else
|
||||||
|
node_visual[field_name] = splits[3]
|
||||||
|
end
|
||||||
|
player:set_node_visual(node_name, node_visual)
|
||||||
|
return true, "Node "..node_name.." node_visual field "..field_name.." set to value: "..dump(node_visual[field_name])
|
||||||
|
else
|
||||||
|
return true, "Node "..node_name.." node_visual field "..field_name.." have value: "..dump(node_visual[field_name])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
})
|
|
@ -233,6 +233,7 @@ public:
|
||||||
void handleCommand_MediaPush(NetworkPacket *pkt);
|
void handleCommand_MediaPush(NetworkPacket *pkt);
|
||||||
void handleCommand_MinimapModes(NetworkPacket *pkt);
|
void handleCommand_MinimapModes(NetworkPacket *pkt);
|
||||||
void handleCommand_SetLighting(NetworkPacket *pkt);
|
void handleCommand_SetLighting(NetworkPacket *pkt);
|
||||||
|
void handleCommand_SetNodeVisual(NetworkPacket *pkt);
|
||||||
|
|
||||||
void ProcessData(NetworkPacket *pkt);
|
void ProcessData(NetworkPacket *pkt);
|
||||||
|
|
||||||
|
|
|
@ -156,7 +156,7 @@ void PlayerDatabaseFiles::savePlayer(RemotePlayer *player)
|
||||||
std::string savedir = m_savedir + DIR_DELIM;
|
std::string savedir = m_savedir + DIR_DELIM;
|
||||||
std::string path = savedir + player->getName();
|
std::string path = savedir + player->getName();
|
||||||
bool path_found = false;
|
bool path_found = false;
|
||||||
RemotePlayer testplayer("", NULL);
|
RemotePlayer testplayer("", NULL, NULL);
|
||||||
|
|
||||||
for (u32 i = 0; i < PLAYER_FILE_ALTERNATE_TRIES && !path_found; i++) {
|
for (u32 i = 0; i < PLAYER_FILE_ALTERNATE_TRIES && !path_found; i++) {
|
||||||
if (!fs::PathExists(path)) {
|
if (!fs::PathExists(path)) {
|
||||||
|
@ -202,7 +202,7 @@ bool PlayerDatabaseFiles::removePlayer(const std::string &name)
|
||||||
std::string players_path = m_savedir + DIR_DELIM;
|
std::string players_path = m_savedir + DIR_DELIM;
|
||||||
std::string path = players_path + name;
|
std::string path = players_path + name;
|
||||||
|
|
||||||
RemotePlayer temp_player("", NULL);
|
RemotePlayer temp_player("", NULL, NULL);
|
||||||
for (u32 i = 0; i < PLAYER_FILE_ALTERNATE_TRIES; i++) {
|
for (u32 i = 0; i < PLAYER_FILE_ALTERNATE_TRIES; i++) {
|
||||||
// Open file and deserialize
|
// Open file and deserialize
|
||||||
std::ifstream is(path.c_str(), std::ios_base::binary);
|
std::ifstream is(path.c_str(), std::ios_base::binary);
|
||||||
|
@ -264,7 +264,7 @@ void PlayerDatabaseFiles::listPlayers(std::vector<std::string> &res)
|
||||||
if (!is.good())
|
if (!is.good())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
RemotePlayer player(filename.c_str(), NULL);
|
RemotePlayer player(filename.c_str(), NULL, NULL);
|
||||||
// Null env & dummy peer_id
|
// Null env & dummy peer_id
|
||||||
PlayerSAO playerSAO(NULL, &player, 15789, false);
|
PlayerSAO playerSAO(NULL, &player, 15789, false);
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,9 @@ void MapNode::getColor(const ContentFeatures &f, video::SColor *color) const
|
||||||
|
|
||||||
u16 MapNode::getVariant(const ContentFeatures &f) const
|
u16 MapNode::getVariant(const ContentFeatures &f) const
|
||||||
{
|
{
|
||||||
return f.variant_count > 1 ? f.param2_variant.get(param2) % f.variant_count : 0;
|
if (f.variant_count > 1)
|
||||||
|
return (f.param2_variant.get(param2) + f.variant_offset) % f.variant_count;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
u8 MapNode::getFaceDir(const NodeDefManager *nodemgr,
|
u8 MapNode::getFaceDir(const NodeDefManager *nodemgr,
|
||||||
|
|
|
@ -120,7 +120,7 @@ const ToClientCommandHandler toClientCommandTable[TOCLIENT_NUM_MSG_TYPES] =
|
||||||
{ "TOCLIENT_SET_MOON", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_HudSetMoon }, // 0x5b
|
{ "TOCLIENT_SET_MOON", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_HudSetMoon }, // 0x5b
|
||||||
{ "TOCLIENT_SET_STARS", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_HudSetStars }, // 0x5c
|
{ "TOCLIENT_SET_STARS", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_HudSetStars }, // 0x5c
|
||||||
{ "TOCLIENT_MOVE_PLAYER_REL", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_MovePlayerRel }, // 0x5d,
|
{ "TOCLIENT_MOVE_PLAYER_REL", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_MovePlayerRel }, // 0x5d,
|
||||||
null_command_handler,
|
{ "TOCLIENT_SET_NODE_VISUAL", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_SetNodeVisual }, // 0x5e
|
||||||
null_command_handler,
|
null_command_handler,
|
||||||
{ "TOCLIENT_SRP_BYTES_S_B", TOCLIENT_STATE_NOT_CONNECTED, &Client::handleCommand_SrpBytesSandB }, // 0x60
|
{ "TOCLIENT_SRP_BYTES_S_B", TOCLIENT_STATE_NOT_CONNECTED, &Client::handleCommand_SrpBytesSandB }, // 0x60
|
||||||
{ "TOCLIENT_FORMSPEC_PREPEND", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_FormspecPrepend }, // 0x61,
|
{ "TOCLIENT_FORMSPEC_PREPEND", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_FormspecPrepend }, // 0x61,
|
||||||
|
|
|
@ -1816,3 +1816,16 @@ void Client::handleCommand_SetLighting(NetworkPacket *pkt)
|
||||||
if (pkt->getRemainingBytes() >= 4)
|
if (pkt->getRemainingBytes() >= 4)
|
||||||
*pkt >> lighting.volumetric_light_strength;
|
*pkt >> lighting.volumetric_light_strength;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Client::handleCommand_SetNodeVisual(NetworkPacket *pkt)
|
||||||
|
{
|
||||||
|
std::string node_name;
|
||||||
|
NodeVisual node_visual;
|
||||||
|
|
||||||
|
*pkt >> node_name;
|
||||||
|
|
||||||
|
if (pkt->getRemainingBytes() >= 2)
|
||||||
|
*pkt >> node_visual.variant_offset;
|
||||||
|
|
||||||
|
m_nodedef->applyNodeVisual(node_name, node_visual);
|
||||||
|
}
|
||||||
|
|
|
@ -811,6 +811,12 @@ enum ToClientCommand : u16
|
||||||
v3f added_pos
|
v3f added_pos
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
TOCLIENT_SET_NODE_VISUAL = 0x5e,
|
||||||
|
/*
|
||||||
|
std::string nodename
|
||||||
|
u16 variant_offset
|
||||||
|
*/
|
||||||
|
|
||||||
TOCLIENT_SRP_BYTES_S_B = 0x60,
|
TOCLIENT_SRP_BYTES_S_B = 0x60,
|
||||||
/*
|
/*
|
||||||
Belonging to AUTH_MECHANISM_SRP.
|
Belonging to AUTH_MECHANISM_SRP.
|
||||||
|
|
|
@ -390,6 +390,7 @@ void ContentFeatures::reset()
|
||||||
param_type = CPT_NONE;
|
param_type = CPT_NONE;
|
||||||
param_type_2 = CPT2_NONE;
|
param_type_2 = CPT2_NONE;
|
||||||
variant_count = 1;
|
variant_count = 1;
|
||||||
|
variant_offset = 0;
|
||||||
param2_variant = BitField<u8>();
|
param2_variant = BitField<u8>();
|
||||||
is_ground_content = false;
|
is_ground_content = false;
|
||||||
light_propagates = false;
|
light_propagates = false;
|
||||||
|
@ -1098,6 +1099,22 @@ void ContentFeatures::updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
NodeVisual
|
||||||
|
*/
|
||||||
|
|
||||||
|
NodeVisual::NodeVisual() : variant_offset(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
NodeVisual::NodeVisual(const ContentFeatures &f)
|
||||||
|
{
|
||||||
|
from_contentFeature(f);
|
||||||
|
}
|
||||||
|
void NodeVisual::from_contentFeature(const ContentFeatures &f)
|
||||||
|
{
|
||||||
|
variant_offset = f.variant_offset;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
NodeDefManager
|
NodeDefManager
|
||||||
*/
|
*/
|
||||||
|
@ -1249,6 +1266,21 @@ const ContentFeatures& NodeDefManager::get(const std::string &name) const
|
||||||
return get(id);
|
return get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NodeDefManager::getNodeVisual(const std::string &name, NodeVisual &node_visual) const
|
||||||
|
{
|
||||||
|
const ContentFeatures &f = get(name);
|
||||||
|
node_visual.from_contentFeature(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void NodeDefManager::applyNodeVisual(const std::string &name, const NodeVisual &node_visual)
|
||||||
|
{
|
||||||
|
content_t c = getId(name);
|
||||||
|
if (c < m_content_features.size() && !m_content_features[c].name.empty()) {
|
||||||
|
ContentFeatures& f = m_content_features[c];
|
||||||
|
|
||||||
|
f.variant_offset = node_visual.variant_offset;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// returns CONTENT_IGNORE if no free ID found
|
// returns CONTENT_IGNORE if no free ID found
|
||||||
content_t NodeDefManager::allocateId()
|
content_t NodeDefManager::allocateId()
|
||||||
|
|
|
@ -350,6 +350,8 @@ struct ContentFeatures
|
||||||
ContentParamType2 param_type_2;
|
ContentParamType2 param_type_2;
|
||||||
// Number of node variants
|
// Number of node variants
|
||||||
u16 variant_count = 1;
|
u16 variant_count = 1;
|
||||||
|
// Node variant offset
|
||||||
|
u16 variant_offset = 0;
|
||||||
// Bit field for variant in param2
|
// Bit field for variant in param2
|
||||||
BitField<u8> param2_variant;
|
BitField<u8> param2_variant;
|
||||||
|
|
||||||
|
@ -547,6 +549,15 @@ private:
|
||||||
u8 getAlphaForLegacy() const;
|
u8 getAlphaForLegacy() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct NodeVisual {
|
||||||
|
u16 variant_offset = 0;
|
||||||
|
|
||||||
|
NodeVisual();
|
||||||
|
NodeVisual(const ContentFeatures &f);
|
||||||
|
|
||||||
|
void from_contentFeature(const ContentFeatures &f);
|
||||||
|
};
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief This class is for getting the actual properties of nodes from their
|
* @brief This class is for getting the actual properties of nodes from their
|
||||||
* content ID.
|
* content ID.
|
||||||
|
@ -642,6 +653,20 @@ public:
|
||||||
return m_selection_box_int_union;
|
return m_selection_box_int_union;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Get NodeVisual object of node
|
||||||
|
* @param name a node name
|
||||||
|
* @param node_visual NodeVisual object to be set
|
||||||
|
*/
|
||||||
|
void getNodeVisual(const std::string &name, NodeVisual &node_visual) const;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Apply NodeVisual object to node
|
||||||
|
* @param name a node name
|
||||||
|
* @param node_visual NodeVisual object to be applied to node
|
||||||
|
*/
|
||||||
|
void applyNodeVisual(const std::string &name, const NodeVisual &node_visual);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Checks whether a node connects to an adjacent node.
|
* Checks whether a node connects to an adjacent node.
|
||||||
* @param from the node to be checked
|
* @param from the node to be checked
|
||||||
|
|
|
@ -37,7 +37,7 @@ bool RemotePlayer::m_setting_cache_loaded = false;
|
||||||
float RemotePlayer::m_setting_chat_message_limit_per_10sec = 0.0f;
|
float RemotePlayer::m_setting_chat_message_limit_per_10sec = 0.0f;
|
||||||
u16 RemotePlayer::m_setting_chat_message_limit_trigger_kick = 0;
|
u16 RemotePlayer::m_setting_chat_message_limit_trigger_kick = 0;
|
||||||
|
|
||||||
RemotePlayer::RemotePlayer(const char *name, IItemDefManager *idef):
|
RemotePlayer::RemotePlayer(const char *name, IItemDefManager *idef, NodeDefManager *ndef):
|
||||||
Player(name, idef)
|
Player(name, idef)
|
||||||
{
|
{
|
||||||
if (!RemotePlayer::m_setting_cache_loaded) {
|
if (!RemotePlayer::m_setting_cache_loaded) {
|
||||||
|
@ -67,6 +67,9 @@ RemotePlayer::RemotePlayer(const char *name, IItemDefManager *idef):
|
||||||
m_sun_params = SkyboxDefaults::getSunDefaults();
|
m_sun_params = SkyboxDefaults::getSunDefaults();
|
||||||
m_moon_params = SkyboxDefaults::getMoonDefaults();
|
m_moon_params = SkyboxDefaults::getMoonDefaults();
|
||||||
m_star_params = SkyboxDefaults::getStarDefaults();
|
m_star_params = SkyboxDefaults::getStarDefaults();
|
||||||
|
|
||||||
|
// NodeDefManager forNodeDefManager for NodeVisual
|
||||||
|
m_ndef = ndef;
|
||||||
}
|
}
|
||||||
|
|
||||||
RemotePlayer::~RemotePlayer()
|
RemotePlayer::~RemotePlayer()
|
||||||
|
@ -114,6 +117,23 @@ RemotePlayerChatResult RemotePlayer::canSendChatMessage()
|
||||||
return RPLAYER_CHATRESULT_OK;
|
return RPLAYER_CHATRESULT_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RemotePlayer::setNodeVisual(const std::string &node_name, const NodeVisual &node_visual)
|
||||||
|
{
|
||||||
|
content_t c = m_ndef->getId(node_name);
|
||||||
|
|
||||||
|
m_node_visuals[c] = node_visual;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RemotePlayer::getNodeVisual(const std::string &node_name, NodeVisual &node_visual)
|
||||||
|
{
|
||||||
|
content_t c = m_ndef->getId(node_name);
|
||||||
|
|
||||||
|
if (m_node_visuals.find(c) != m_node_visuals.end())
|
||||||
|
node_visual = m_node_visuals[c];
|
||||||
|
else
|
||||||
|
node_visual.from_contentFeature(m_ndef->get(c));
|
||||||
|
}
|
||||||
|
|
||||||
void RemotePlayer::onSuccessfulSave()
|
void RemotePlayer::onSuccessfulSave()
|
||||||
{
|
{
|
||||||
setModified(false);
|
setModified(false);
|
||||||
|
|
|
@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "skyparams.h"
|
#include "skyparams.h"
|
||||||
#include "lighting.h"
|
#include "lighting.h"
|
||||||
|
#include "nodedef.h"
|
||||||
|
|
||||||
class PlayerSAO;
|
class PlayerSAO;
|
||||||
|
|
||||||
|
@ -41,7 +42,7 @@ class RemotePlayer : public Player
|
||||||
friend class PlayerDatabaseFiles;
|
friend class PlayerDatabaseFiles;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
RemotePlayer(const char *name, IItemDefManager *idef);
|
RemotePlayer(const char *name, IItemDefManager *idef, NodeDefManager *ndef);
|
||||||
virtual ~RemotePlayer();
|
virtual ~RemotePlayer();
|
||||||
|
|
||||||
PlayerSAO *getPlayerSAO() { return m_sao; }
|
PlayerSAO *getPlayerSAO() { return m_sao; }
|
||||||
|
@ -130,6 +131,10 @@ public:
|
||||||
|
|
||||||
const Lighting& getLighting() const { return m_lighting; }
|
const Lighting& getLighting() const { return m_lighting; }
|
||||||
|
|
||||||
|
void setNodeVisual(const std::string &node_name, const NodeVisual &node_visual);
|
||||||
|
|
||||||
|
void getNodeVisual(const std::string &node_name, NodeVisual &node_visual);
|
||||||
|
|
||||||
void setDirty(bool dirty) { m_dirty = true; }
|
void setDirty(bool dirty) { m_dirty = true; }
|
||||||
|
|
||||||
u16 protocol_version = 0;
|
u16 protocol_version = 0;
|
||||||
|
@ -168,5 +173,8 @@ private:
|
||||||
|
|
||||||
Lighting m_lighting;
|
Lighting m_lighting;
|
||||||
|
|
||||||
|
NodeDefManager *m_ndef;
|
||||||
|
std::map<content_t, NodeVisual> m_node_visuals;
|
||||||
|
|
||||||
session_t m_peer_id = PEER_ID_INEXISTENT;
|
session_t m_peer_id = PEER_ID_INEXISTENT;
|
||||||
};
|
};
|
||||||
|
|
|
@ -30,6 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
#include "remoteplayer.h"
|
#include "remoteplayer.h"
|
||||||
#include "server.h"
|
#include "server.h"
|
||||||
#include "hud.h"
|
#include "hud.h"
|
||||||
|
#include "nodedef.h"
|
||||||
#include "scripting_server.h"
|
#include "scripting_server.h"
|
||||||
#include "server/luaentity_sao.h"
|
#include "server/luaentity_sao.h"
|
||||||
#include "server/player_sao.h"
|
#include "server/player_sao.h"
|
||||||
|
@ -2584,6 +2585,50 @@ int ObjectRef::l_get_lighting(lua_State *L)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set_node_visual(self, node_name, node_visual)
|
||||||
|
int ObjectRef::l_set_node_visual(lua_State *L)
|
||||||
|
{
|
||||||
|
NO_MAP_LOCK_REQUIRED;
|
||||||
|
ObjectRef *ref = checkObject<ObjectRef>(L, 1);
|
||||||
|
RemotePlayer *player = getplayer(ref);
|
||||||
|
if (player == nullptr)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
std::string node_name = readParam<std::string>(L, 2);
|
||||||
|
|
||||||
|
NodeVisual node_visual;
|
||||||
|
player->getNodeVisual(node_name, node_visual);
|
||||||
|
NodeVisual new_visual = node_visual;
|
||||||
|
|
||||||
|
if (!lua_isnoneornil(L, 3)) {
|
||||||
|
luaL_checktype(L, 3, LUA_TTABLE);
|
||||||
|
new_visual.variant_offset = getfloatfield_default(L, -1, "variant_offset", node_visual.variant_offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
getServer(L)->setNodeVisual(player, node_name, new_visual);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get_node_visual(self, node_name)
|
||||||
|
int ObjectRef::l_get_node_visual(lua_State *L)
|
||||||
|
{
|
||||||
|
NO_MAP_LOCK_REQUIRED;
|
||||||
|
ObjectRef *ref = checkObject<ObjectRef>(L, 1);
|
||||||
|
RemotePlayer *player = getplayer(ref);
|
||||||
|
if (player == nullptr)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
std::string node_name = readParam<std::string>(L, 2);
|
||||||
|
|
||||||
|
NodeVisual node_visual;
|
||||||
|
player->getNodeVisual(node_name, node_visual);
|
||||||
|
|
||||||
|
lua_newtable(L); // result
|
||||||
|
lua_pushnumber(L, node_visual.variant_offset);
|
||||||
|
lua_setfield(L, -2, "variant_offset");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
// respawn(self)
|
// respawn(self)
|
||||||
int ObjectRef::l_respawn(lua_State *L)
|
int ObjectRef::l_respawn(lua_State *L)
|
||||||
{
|
{
|
||||||
|
@ -2743,6 +2788,8 @@ luaL_Reg ObjectRef::methods[] = {
|
||||||
luamethod(ObjectRef, set_minimap_modes),
|
luamethod(ObjectRef, set_minimap_modes),
|
||||||
luamethod(ObjectRef, set_lighting),
|
luamethod(ObjectRef, set_lighting),
|
||||||
luamethod(ObjectRef, get_lighting),
|
luamethod(ObjectRef, get_lighting),
|
||||||
|
luamethod(ObjectRef, set_node_visual),
|
||||||
|
luamethod(ObjectRef, get_node_visual),
|
||||||
luamethod(ObjectRef, respawn),
|
luamethod(ObjectRef, respawn),
|
||||||
|
|
||||||
{0,0}
|
{0,0}
|
||||||
|
|
|
@ -397,6 +397,12 @@ private:
|
||||||
// get_lighting(self)
|
// get_lighting(self)
|
||||||
static int l_get_lighting(lua_State *L);
|
static int l_get_lighting(lua_State *L);
|
||||||
|
|
||||||
|
// set_node_visual(self, node_name, node_visual)
|
||||||
|
static int l_set_node_visual(lua_State *L);
|
||||||
|
|
||||||
|
// get_node_visual(self, node_name)
|
||||||
|
static int l_get_node_visual(lua_State *L);
|
||||||
|
|
||||||
// respawn(self)
|
// respawn(self)
|
||||||
static int l_respawn(lua_State *L);
|
static int l_respawn(lua_State *L);
|
||||||
};
|
};
|
||||||
|
|
|
@ -1900,6 +1900,17 @@ void Server::SendSetLighting(session_t peer_id, const Lighting &lighting)
|
||||||
Send(&pkt);
|
Send(&pkt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Server::SendSetNodeVisual(session_t peer_id, const std::string &node_name, const NodeVisual &node_visual)
|
||||||
|
{
|
||||||
|
NetworkPacket pkt(TOCLIENT_SET_NODE_VISUAL,
|
||||||
|
4, peer_id);
|
||||||
|
|
||||||
|
pkt << node_name;
|
||||||
|
pkt << node_visual.variant_offset;
|
||||||
|
|
||||||
|
Send(&pkt);
|
||||||
|
}
|
||||||
|
|
||||||
void Server::SendTimeOfDay(session_t peer_id, u16 time, f32 time_speed)
|
void Server::SendTimeOfDay(session_t peer_id, u16 time, f32 time_speed)
|
||||||
{
|
{
|
||||||
NetworkPacket pkt(TOCLIENT_TIME_OF_DAY, 0, peer_id);
|
NetworkPacket pkt(TOCLIENT_TIME_OF_DAY, 0, peer_id);
|
||||||
|
@ -3542,6 +3553,13 @@ void Server::setLighting(RemotePlayer *player, const Lighting &lighting)
|
||||||
SendSetLighting(player->getPeerId(), lighting);
|
SendSetLighting(player->getPeerId(), lighting);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Server::setNodeVisual(RemotePlayer *player, const std::string &node_name, const NodeVisual &node_visual)
|
||||||
|
{
|
||||||
|
sanity_check(player);
|
||||||
|
player->setNodeVisual(node_name, node_visual);
|
||||||
|
SendSetNodeVisual(player->getPeerId(), node_name, node_visual);
|
||||||
|
}
|
||||||
|
|
||||||
void Server::notifyPlayers(const std::wstring &msg)
|
void Server::notifyPlayers(const std::wstring &msg)
|
||||||
{
|
{
|
||||||
SendChatMessage(PEER_ID_INEXISTENT, ChatMessage(msg));
|
SendChatMessage(PEER_ID_INEXISTENT, ChatMessage(msg));
|
||||||
|
@ -4047,7 +4065,7 @@ PlayerSAO* Server::emergePlayer(const char *name, session_t peer_id, u16 proto_v
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!player) {
|
if (!player) {
|
||||||
player = new RemotePlayer(name, idef());
|
player = new RemotePlayer(name, idef(), m_nodedef);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool newplayer = false;
|
bool newplayer = false;
|
||||||
|
|
|
@ -38,6 +38,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
#include "chatmessage.h"
|
#include "chatmessage.h"
|
||||||
#include "sound.h"
|
#include "sound.h"
|
||||||
#include "translation.h"
|
#include "translation.h"
|
||||||
|
#include "nodedef.h"
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
@ -359,6 +360,8 @@ public:
|
||||||
|
|
||||||
void setLighting(RemotePlayer *player, const Lighting &lighting);
|
void setLighting(RemotePlayer *player, const Lighting &lighting);
|
||||||
|
|
||||||
|
void setNodeVisual(RemotePlayer *player, const std::string &node_name, const NodeVisual &node_visual);
|
||||||
|
|
||||||
void RespawnPlayer(session_t peer_id);
|
void RespawnPlayer(session_t peer_id);
|
||||||
|
|
||||||
/* con::PeerHandler implementation. */
|
/* con::PeerHandler implementation. */
|
||||||
|
@ -519,6 +522,7 @@ private:
|
||||||
void SendCloudParams(session_t peer_id, const CloudParams ¶ms);
|
void SendCloudParams(session_t peer_id, const CloudParams ¶ms);
|
||||||
void SendOverrideDayNightRatio(session_t peer_id, bool do_override, float ratio);
|
void SendOverrideDayNightRatio(session_t peer_id, bool do_override, float ratio);
|
||||||
void SendSetLighting(session_t peer_id, const Lighting &lighting);
|
void SendSetLighting(session_t peer_id, const Lighting &lighting);
|
||||||
|
void SendSetNodeVisual(session_t peer_id, const std::string &node_name, const NodeVisual &node_visual);
|
||||||
void broadcastModChannelMessage(const std::string &channel,
|
void broadcastModChannelMessage(const std::string &channel,
|
||||||
const std::string &message, session_t from_peer);
|
const std::string &message, session_t from_peer);
|
||||||
|
|
||||||
|
|
|
@ -2381,7 +2381,7 @@ bool ServerEnvironment::migratePlayersDatabase(const GameParams &game_params,
|
||||||
for (std::vector<std::string>::const_iterator it = player_list.begin();
|
for (std::vector<std::string>::const_iterator it = player_list.begin();
|
||||||
it != player_list.end(); ++it) {
|
it != player_list.end(); ++it) {
|
||||||
actionstream << "Migrating player " << it->c_str() << std::endl;
|
actionstream << "Migrating player " << it->c_str() << std::endl;
|
||||||
RemotePlayer player(it->c_str(), NULL);
|
RemotePlayer player(it->c_str(), NULL, NULL);
|
||||||
PlayerSAO playerSAO(NULL, &player, 15000, false);
|
PlayerSAO playerSAO(NULL, &player, 15000, false);
|
||||||
|
|
||||||
srcdb->loadPlayer(&player, &playerSAO);
|
srcdb->loadPlayer(&player, &playerSAO);
|
||||||
|
|
Loading…
Reference in New Issue