mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-11 17:51:04 +00:00
Add minetest.swap_node
This commit is contained in:
parent
752e11e114
commit
d879a539cd
12 changed files with 82 additions and 29 deletions
|
@ -1582,16 +1582,16 @@ void Server::AsyncRunStep()
|
|||
// for them.
|
||||
std::list<u16> far_players;
|
||||
|
||||
if(event->type == MEET_ADDNODE)
|
||||
if(event->type == MEET_ADDNODE || event->type == MEET_SWAPNODE)
|
||||
{
|
||||
//infostream<<"Server: MEET_ADDNODE"<<std::endl;
|
||||
prof.add("MEET_ADDNODE", 1);
|
||||
if(disable_single_change_sending)
|
||||
sendAddNode(event->p, event->n, event->already_known_by_peer,
|
||||
&far_players, 5);
|
||||
&far_players, 5, event->type == MEET_ADDNODE);
|
||||
else
|
||||
sendAddNode(event->p, event->n, event->already_known_by_peer,
|
||||
&far_players, 30);
|
||||
&far_players, 30, event->type == MEET_ADDNODE);
|
||||
}
|
||||
else if(event->type == MEET_REMOVENODE)
|
||||
{
|
||||
|
@ -4070,7 +4070,8 @@ void Server::sendRemoveNode(v3s16 p, u16 ignore_id,
|
|||
}
|
||||
|
||||
void Server::sendAddNode(v3s16 p, MapNode n, u16 ignore_id,
|
||||
std::list<u16> *far_players, float far_d_nodes)
|
||||
std::list<u16> *far_players, float far_d_nodes,
|
||||
bool remove_metadata)
|
||||
{
|
||||
float maxd = far_d_nodes*BS;
|
||||
v3f p_f = intToFloat(p, BS);
|
||||
|
@ -4106,13 +4107,23 @@ void Server::sendAddNode(v3s16 p, MapNode n, u16 ignore_id,
|
|||
}
|
||||
|
||||
// Create packet
|
||||
u32 replysize = 8 + MapNode::serializedLength(client->serialization_version);
|
||||
u32 replysize = 9 + MapNode::serializedLength(client->serialization_version);
|
||||
SharedBuffer<u8> reply(replysize);
|
||||
writeU16(&reply[0], TOCLIENT_ADDNODE);
|
||||
writeS16(&reply[2], p.X);
|
||||
writeS16(&reply[4], p.Y);
|
||||
writeS16(&reply[6], p.Z);
|
||||
n.serialize(&reply[8], client->serialization_version);
|
||||
u32 index = 8 + MapNode::serializedLength(client->serialization_version);
|
||||
writeU8(&reply[index], remove_metadata ? 0 : 1);
|
||||
|
||||
if (!remove_metadata) {
|
||||
if (client->net_proto_version <= 21) {
|
||||
// Old clients always clear metadata; fix it
|
||||
// by sending the full block again.
|
||||
client->SetBlockNotSent(p);
|
||||
}
|
||||
}
|
||||
|
||||
// Send as reliable
|
||||
m_con.Send(client->peer_id, 0, reply, true);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue