1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-09-10 18:51:05 +00:00

Item meta pointing range (#14347)

This commit is contained in:
cx384 2024-03-17 15:55:38 +01:00 committed by GitHub
parent e3b9828f24
commit 234b01a8c2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 38 additions and 10 deletions

View file

@ -1384,7 +1384,7 @@ void Game::copyServerClientCache()
{
// It would be possible to let the client directly read the media files
// from where the server knows they are. But aside from being more complicated
// it would also *not* fill the media cache and cause slower joining of
// it would also *not* fill the media cache and cause slower joining of
// remote servers.
// (Imagine that you launch a game once locally and then connect to a server.)
@ -3233,7 +3233,7 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud)
const ItemStack &tool_item = player->getWieldedItem(&selected_item, &hand_item);
const ItemDefinition &selected_def = selected_item.getDefinition(itemdef_manager);
f32 d = getToolRange(selected_def, hand_item.getDefinition(itemdef_manager));
f32 d = getToolRange(selected_item, hand_item, itemdef_manager);
core::line3d<f32> shootline;

View file

@ -895,8 +895,7 @@ bool Server::checkInteractDistance(RemotePlayer *player, const f32 d, const std:
{
ItemStack selected_item, hand_item;
player->getWieldedItem(&selected_item, &hand_item);
f32 max_d = BS * getToolRange(selected_item.getDefinition(m_itemdef),
hand_item.getDefinition(m_itemdef));
f32 max_d = BS * getToolRange(selected_item, hand_item, m_itemdef);
// Cube diagonal * 1.5 for maximal supported node extents:
// sqrt(3) * 1.5 ≅ 2.6

View file

@ -29,7 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "util/hex.h"
#include "common/c_content.h"
#include <json/json.h>
void ToolGroupCap::toJson(Json::Value &object) const
{
@ -246,7 +246,7 @@ std::optional<WearBarParams> WearBarParams::deserializeJson(std::istream &is)
blend = static_cast<WearBarParams::BlendMode>(blendInt);
else
return std::nullopt;
const Json::Value &color_stops_object = root["color_stops"];
std::map<f32, video::SColor> colorStops;
for (const std::string &key : color_stops_object.getMemberNames()) {
@ -491,10 +491,16 @@ PunchDamageResult getPunchDamage(
return result;
}
f32 getToolRange(const ItemDefinition &def_selected, const ItemDefinition &def_hand)
f32 getToolRange(const ItemStack &wielded_item, const ItemStack &hand_item,
const IItemDefManager *itemdef_manager)
{
float max_d = def_selected.range;
float max_d_hand = def_hand.range;
const std::string &wielded_meta_range = wielded_item.metadata.getString("range");
const std::string &hand_meta_range = hand_item.metadata.getString("range");
f32 max_d = wielded_meta_range.empty() ? wielded_item.getDefinition(itemdef_manager).range :
stof(wielded_meta_range);
f32 max_d_hand = hand_meta_range.empty() ? hand_item.getDefinition(itemdef_manager).range :
stof(hand_meta_range);
if (max_d < 0 && max_d_hand >= 0)
max_d = max_d_hand;

View file

@ -31,6 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <optional>
struct ItemDefinition;
class IItemDefManager;
struct ToolGroupCap
{
@ -179,4 +180,5 @@ PunchDamageResult getPunchDamage(
);
u32 calculateResultWear(const u32 uses, const u16 initial_wear);
f32 getToolRange(const ItemDefinition &def_selected, const ItemDefinition &def_hand);
f32 getToolRange(const ItemStack &wielded_item, const ItemStack &hand_item,
const IItemDefManager *itemdef_manager);