mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-12-29 15:49:09 +01:00
Partially implement handling of "hide_tooltip" and fix attribute modifiers in "Armor" category not showing (#4731)
* Skip lore creation if hide tooltips exists * Fix not showing attributes for "Armor" category * Minor refactor --------- Co-authored-by: chris <github@onechris.mozmail.com>
This commit is contained in:
parent
d9f9fcf39a
commit
6cda7c2202
2 changed files with 17 additions and 4 deletions
|
@ -125,7 +125,7 @@ public class Item {
|
||||||
*/
|
*/
|
||||||
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponents components, @NonNull BedrockItemBuilder builder) {
|
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponents components, @NonNull BedrockItemBuilder builder) {
|
||||||
List<Component> loreComponents = components.get(DataComponentType.LORE);
|
List<Component> loreComponents = components.get(DataComponentType.LORE);
|
||||||
if (loreComponents != null) {
|
if (loreComponents != null && components.get(DataComponentType.HIDE_TOOLTIP) == null) {
|
||||||
List<String> lore = builder.getOrCreateLore();
|
List<String> lore = builder.getOrCreateLore();
|
||||||
for (Component loreComponent : loreComponents) {
|
for (Component loreComponent : loreComponents) {
|
||||||
lore.add(MessageTranslator.convertMessage(loreComponent, session.locale()));
|
lore.add(MessageTranslator.convertMessage(loreComponent, session.locale()));
|
||||||
|
|
|
@ -65,6 +65,12 @@ public final class ItemTranslator {
|
||||||
* The order of these slots is their display order on Java Edition clients
|
* The order of these slots is their display order on Java Edition clients
|
||||||
*/
|
*/
|
||||||
private static final EnumMap<ItemAttributeModifiers.EquipmentSlotGroup, String> SLOT_NAMES;
|
private static final EnumMap<ItemAttributeModifiers.EquipmentSlotGroup, String> SLOT_NAMES;
|
||||||
|
private static final ItemAttributeModifiers.EquipmentSlotGroup[] ARMOR_SLOT_NAMES = new ItemAttributeModifiers.EquipmentSlotGroup[] {
|
||||||
|
ItemAttributeModifiers.EquipmentSlotGroup.HEAD,
|
||||||
|
ItemAttributeModifiers.EquipmentSlotGroup.CHEST,
|
||||||
|
ItemAttributeModifiers.EquipmentSlotGroup.LEGS,
|
||||||
|
ItemAttributeModifiers.EquipmentSlotGroup.FEET
|
||||||
|
};
|
||||||
private static final DecimalFormat ATTRIBUTE_FORMAT = new DecimalFormat("0.#####");
|
private static final DecimalFormat ATTRIBUTE_FORMAT = new DecimalFormat("0.#####");
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
@ -132,8 +138,10 @@ public final class ItemTranslator {
|
||||||
private static ItemData.@NonNull Builder translateToBedrock(GeyserSession session, Item javaItem, ItemMapping bedrockItem, int count, @Nullable DataComponents components) {
|
private static ItemData.@NonNull Builder translateToBedrock(GeyserSession session, Item javaItem, ItemMapping bedrockItem, int count, @Nullable DataComponents components) {
|
||||||
BedrockItemBuilder nbtBuilder = new BedrockItemBuilder();
|
BedrockItemBuilder nbtBuilder = new BedrockItemBuilder();
|
||||||
|
|
||||||
|
boolean hideTooltips = false;
|
||||||
if (components != null) {
|
if (components != null) {
|
||||||
javaItem.translateComponentsToBedrock(session, components, nbtBuilder);
|
javaItem.translateComponentsToBedrock(session, components, nbtBuilder);
|
||||||
|
if (components.get(DataComponentType.HIDE_TOOLTIP) != null) hideTooltips = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
String customName = getCustomName(session, components, bedrockItem);
|
String customName = getCustomName(session, components, bedrockItem);
|
||||||
|
@ -143,13 +151,13 @@ public final class ItemTranslator {
|
||||||
|
|
||||||
if (components != null) {
|
if (components != null) {
|
||||||
ItemAttributeModifiers attributeModifiers = components.get(DataComponentType.ATTRIBUTE_MODIFIERS);
|
ItemAttributeModifiers attributeModifiers = components.get(DataComponentType.ATTRIBUTE_MODIFIERS);
|
||||||
if (attributeModifiers != null && attributeModifiers.isShowInTooltip()) {
|
if (attributeModifiers != null && attributeModifiers.isShowInTooltip() && !hideTooltips) {
|
||||||
// only add if attribute modifiers do not indicate to hide them
|
// only add if attribute modifiers do not indicate to hide them
|
||||||
addAttributeLore(attributeModifiers, nbtBuilder, session.locale());
|
addAttributeLore(attributeModifiers, nbtBuilder, session.locale());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (session.isAdvancedTooltips()) {
|
if (session.isAdvancedTooltips() && !hideTooltips) {
|
||||||
addAdvancedTooltips(components, nbtBuilder, javaItem, session.locale());
|
addAdvancedTooltips(components, nbtBuilder, javaItem, session.locale());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,7 +215,12 @@ public final class ItemTranslator {
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemAttributeModifiers.EquipmentSlotGroup slotGroup = entry.getSlot();
|
ItemAttributeModifiers.EquipmentSlotGroup slotGroup = entry.getSlot();
|
||||||
if (slotGroup == ItemAttributeModifiers.EquipmentSlotGroup.ANY) {
|
if (slotGroup == ItemAttributeModifiers.EquipmentSlotGroup.ARMOR) {
|
||||||
|
// modifier applies to all armor slots
|
||||||
|
for (ItemAttributeModifiers.EquipmentSlotGroup slot : ARMOR_SLOT_NAMES) {
|
||||||
|
slotsToModifiers.computeIfAbsent(slot, s -> new ArrayList<>()).add(loreEntry);
|
||||||
|
}
|
||||||
|
} else if (slotGroup == ItemAttributeModifiers.EquipmentSlotGroup.ANY) {
|
||||||
// modifier applies to all slots implicitly
|
// modifier applies to all slots implicitly
|
||||||
for (var slot : SLOT_NAMES.keySet()) {
|
for (var slot : SLOT_NAMES.keySet()) {
|
||||||
slotsToModifiers.computeIfAbsent(slot, s -> new ArrayList<>()).add(loreEntry);
|
slotsToModifiers.computeIfAbsent(slot, s -> new ArrayList<>()).add(loreEntry);
|
||||||
|
|
Loading…
Reference in a new issue