mirror of
https://github.com/minetest/minetest.git
synced 2024-11-23 08:03:45 +01:00
Item meta pointing range (#14347)
This commit is contained in:
parent
e3b9828f24
commit
234b01a8c2
@ -38,6 +38,7 @@ core.features = {
|
|||||||
dynamic_add_media_startup = true,
|
dynamic_add_media_startup = true,
|
||||||
dynamic_add_media_filepath = true,
|
dynamic_add_media_filepath = true,
|
||||||
lsystem_decoration_type = true,
|
lsystem_decoration_type = true,
|
||||||
|
item_meta_range = true,
|
||||||
}
|
}
|
||||||
|
|
||||||
function core.has_feature(arg)
|
function core.has_feature(arg)
|
||||||
|
@ -2560,6 +2560,8 @@ Some of the values in the key-value store are handled specially:
|
|||||||
0 = default, 1 = left / up, 2 = middle, 3 = right / down
|
0 = default, 1 = left / up, 2 = middle, 3 = right / down
|
||||||
The default currently is the same as right/down.
|
The default currently is the same as right/down.
|
||||||
Example: 6 = 2 + 1*4 = middle,up
|
Example: 6 = 2 + 1*4 = middle,up
|
||||||
|
* `range`: Overrides the pointing range
|
||||||
|
Example: `meta:set_float("range", 4.2)`
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
@ -5397,6 +5399,8 @@ Utilities
|
|||||||
dynamic_add_media_filepath = true,
|
dynamic_add_media_filepath = true,
|
||||||
-- L-system decoration type (5.9.0)
|
-- L-system decoration type (5.9.0)
|
||||||
lsystem_decoration_type = true,
|
lsystem_decoration_type = true,
|
||||||
|
-- Overrideable pointing range using the itemstack meta key `"range"` (5.9.0)
|
||||||
|
item_meta_range = true,
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -8980,6 +8984,7 @@ Used by `minetest.register_node`, `minetest.register_craftitem`, and
|
|||||||
|
|
||||||
range = 4.0,
|
range = 4.0,
|
||||||
-- Range of node and object pointing that is possible with this item held
|
-- Range of node and object pointing that is possible with this item held
|
||||||
|
-- Can be overridden with itemstack meta.
|
||||||
|
|
||||||
liquids_pointable = false,
|
liquids_pointable = false,
|
||||||
-- If true, item can point to all liquid nodes (`liquidtype ~= "none"`),
|
-- If true, item can point to all liquid nodes (`liquidtype ~= "none"`),
|
||||||
|
@ -90,3 +90,18 @@ minetest.register_craftitem("testitems:image_meta", {
|
|||||||
return itemstack
|
return itemstack
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
minetest.register_craftitem("testitems:telescope_stick", {
|
||||||
|
description = S("Telescope Stick (Increases range on use.)"),
|
||||||
|
inventory_image = "testitems_telescope_stick.png",
|
||||||
|
on_use = function(itemstack, player)
|
||||||
|
local meta = itemstack:get_meta()
|
||||||
|
local range = meta:get_float("range") + 1.2
|
||||||
|
if range > 10 then
|
||||||
|
range = 0
|
||||||
|
end
|
||||||
|
meta:set_float("range", range)
|
||||||
|
minetest.chat_send_player(player:get_player_name(), "Telescope Stick range set to "..range)
|
||||||
|
return itemstack
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
Binary file not shown.
After Width: | Height: | Size: 170 B |
@ -3233,7 +3233,7 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud)
|
|||||||
const ItemStack &tool_item = player->getWieldedItem(&selected_item, &hand_item);
|
const ItemStack &tool_item = player->getWieldedItem(&selected_item, &hand_item);
|
||||||
|
|
||||||
const ItemDefinition &selected_def = selected_item.getDefinition(itemdef_manager);
|
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;
|
core::line3d<f32> shootline;
|
||||||
|
|
||||||
|
@ -895,8 +895,7 @@ bool Server::checkInteractDistance(RemotePlayer *player, const f32 d, const std:
|
|||||||
{
|
{
|
||||||
ItemStack selected_item, hand_item;
|
ItemStack selected_item, hand_item;
|
||||||
player->getWieldedItem(&selected_item, &hand_item);
|
player->getWieldedItem(&selected_item, &hand_item);
|
||||||
f32 max_d = BS * getToolRange(selected_item.getDefinition(m_itemdef),
|
f32 max_d = BS * getToolRange(selected_item, hand_item, m_itemdef);
|
||||||
hand_item.getDefinition(m_itemdef));
|
|
||||||
|
|
||||||
// Cube diagonal * 1.5 for maximal supported node extents:
|
// Cube diagonal * 1.5 for maximal supported node extents:
|
||||||
// sqrt(3) * 1.5 ≅ 2.6
|
// sqrt(3) * 1.5 ≅ 2.6
|
||||||
|
12
src/tool.cpp
12
src/tool.cpp
@ -491,10 +491,16 @@ PunchDamageResult getPunchDamage(
|
|||||||
return result;
|
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;
|
const std::string &wielded_meta_range = wielded_item.metadata.getString("range");
|
||||||
float max_d_hand = def_hand.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)
|
if (max_d < 0 && max_d_hand >= 0)
|
||||||
max_d = max_d_hand;
|
max_d = max_d_hand;
|
||||||
|
@ -31,6 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
struct ItemDefinition;
|
struct ItemDefinition;
|
||||||
|
class IItemDefManager;
|
||||||
|
|
||||||
struct ToolGroupCap
|
struct ToolGroupCap
|
||||||
{
|
{
|
||||||
@ -179,4 +180,5 @@ PunchDamageResult getPunchDamage(
|
|||||||
);
|
);
|
||||||
|
|
||||||
u32 calculateResultWear(const u32 uses, const u16 initial_wear);
|
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);
|
||||||
|
Loading…
Reference in New Issue
Block a user