Skip to content

Commit

Permalink
git commit -m "make it fancy"
Browse files Browse the repository at this point in the history
  • Loading branch information
SmallJoker committed Sep 11, 2023
1 parent 852a103 commit 86f8f48
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 18 deletions.
8 changes: 4 additions & 4 deletions src/client/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3627,10 +3627,10 @@ bool Game::nodePlacement(const ItemDefinition &selected_def,
// Compare core.item_place_node() for what the server does with param2
MapNode predicted_node(id, 0, 0);

const s16 place_param2 = selected_def.place_param2;
const auto place_param2 = selected_def.place_param2;

if (place_param2 >= 0) {
predicted_node.setParam2(place_param2);
if (place_param2) {
predicted_node.setParam2(place_param2.value());
} else if (predicted_f.param_type_2 == CPT2_WALLMOUNTED ||
predicted_f.param_type_2 == CPT2_COLORED_WALLMOUNTED) {
v3s16 dir = nodepos - neighborpos;
Expand Down Expand Up @@ -3689,7 +3689,7 @@ bool Game::nodePlacement(const ItemDefinition &selected_def,
}

// Apply color
if (place_param2 < 0 && (predicted_f.param_type_2 == CPT2_COLOR
if (!place_param2 && (predicted_f.param_type_2 == CPT2_COLOR
|| predicted_f.param_type_2 == CPT2_COLORED_FACEDIR
|| predicted_f.param_type_2 == CPT2_COLORED_4DIR
|| predicted_f.param_type_2 == CPT2_COLORED_WALLMOUNTED)) {
Expand Down
8 changes: 4 additions & 4 deletions src/client/wieldmesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,8 @@ void WieldMeshSceneNode::setItem(const ItemStack &item, Client *client, bool che
default: {
// Render non-trivial drawtypes like the actual node
MapNode n(id);
if (def.place_param2 >= 0)
n.setParam2(def.place_param2);
if (def.place_param2)
n.setParam2(def.place_param2.value());

mesh = createSpecialNodeMesh(client, n, &m_colors, f);
changeToMesh(mesh);
Expand Down Expand Up @@ -639,8 +639,8 @@ void getItemMesh(Client *client, const ItemStack &item, ItemMesh *result)
default: {
// Render non-trivial drawtypes like the actual node
MapNode n(id);
if (def.place_param2 >= 0)
n.setParam2(def.place_param2);
if (def.place_param2)
n.setParam2(def.place_param2.value());

mesh = createSpecialNodeMesh(client, n, &result->buffer_colors, f);
scaleMesh(mesh, v3f(0.12, 0.12, 0.12));
Expand Down
17 changes: 11 additions & 6 deletions src/itemdef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void ItemDefinition::reset()
sound_use_air = SoundSpec();
range = -1;
node_placement_prediction.clear();
place_param2 = -1;
place_param2.reset();
}

void ItemDefinition::serialize(std::ostream &os, u16 protocol_version) const
Expand Down Expand Up @@ -171,14 +171,18 @@ void ItemDefinition::serialize(std::ostream &os, u16 protocol_version) const

if (protocol_version <= 43) {
// Uncertainity whether 0 is the specified prediction or means disabled
const u8 place_param2_legacy = rangelim(place_param2, 0, U8_MAX);
os << place_param2_legacy;
if (place_param2)
os << place_param2.value();
else
os << (u8)0;
}

sound_use.serializeSimple(os, protocol_version);
sound_use_air.serializeSimple(os, protocol_version);

os << place_param2; // protocol_version >= 43
os << (u8)place_param2.has_value(); // protocol_version >= 43
if (place_param2)
os << place_param2.value();
}

void ItemDefinition::deSerialize(std::istream &is, u16 protocol_version)
Expand Down Expand Up @@ -236,7 +240,7 @@ void ItemDefinition::deSerialize(std::istream &is, u16 protocol_version)
place_param2 = readU8(is);
// assume disabled prediction
if (place_param2 == 0)
place_param2 = -1;
place_param2.reset();
}

sound_use.deSerializeSimple(is, protocol_version);
Expand All @@ -245,7 +249,8 @@ void ItemDefinition::deSerialize(std::istream &is, u16 protocol_version)
if (is.eof())
throw SerializationError("");

place_param2 = readS16(is); // protocol_version >= 43
if (readU8(is)) // protocol_version >= 43
place_param2 = readU8(is);
} catch(SerializationError &e) {};
}

Expand Down
3 changes: 2 additions & 1 deletion src/itemdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "irrlichttypes_extrabloated.h"
#include <string>
#include <iostream>
#include <optional>
#include <set>
#include "itemgroup.h"
#include "sound.h"
Expand Down Expand Up @@ -87,7 +88,7 @@ struct ItemDefinition
// Server will update the precise end result a moment later.
// "" = no prediction
std::string node_placement_prediction;
s16 place_param2; // -1: not defined, >= 0: hardcoded prediction
std::optional<u8> place_param2;

/*
Some helpful methods
Expand Down
2 changes: 1 addition & 1 deletion src/network/networkprotocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
[scheduled bump for 5.7.0]
PROTOCOL VERSION 43:
"start_time" added to TOCLIENT_PLAY_SOUND
place_param2 type change u8 -> s16
place_param2 type change u8 -> optional<u8>
[scheduled bump for 5.8.0]
*/

Expand Down
5 changes: 3 additions & 2 deletions src/script/common/c_content.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,9 @@ void read_item_definition(lua_State* L, int index,
getstringfield(L, index, "node_placement_prediction",
def.node_placement_prediction);

int place_param2 = getintfield_default(L, index, "place_param2", -1);
def.place_param2 = rangelim(place_param2, -1, U8_MAX);
int place_param2;
if (getintfield(L, index, "place_param2", place_param2))
def.place_param2 = rangelim(place_param2, 0, U8_MAX);
}

/******************************************************************************/
Expand Down

0 comments on commit 86f8f48

Please sign in to comment.