mirror of
https://github.com/GeyserMC/Geyser.git
synced 2025-12-31 12:46:39 +00:00
Fix custom skulls (#5338)
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
package org.geysermc.geyser.item.components;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
@Getter
|
||||
public enum Rarity {
|
||||
@@ -44,8 +45,7 @@ public enum Rarity {
|
||||
|
||||
private static final Rarity[] VALUES = values();
|
||||
|
||||
public static Rarity fromId(int id) {
|
||||
public static @NonNull Rarity fromId(Integer id) {
|
||||
return VALUES.length > id ? VALUES[id] : VALUES[0];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,7 +37,6 @@ import org.geysermc.geyser.GeyserImpl;
|
||||
import org.geysermc.geyser.inventory.GeyserItemStack;
|
||||
import org.geysermc.geyser.inventory.item.BedrockEnchantment;
|
||||
import org.geysermc.geyser.item.Items;
|
||||
import org.geysermc.geyser.item.components.Rarity;
|
||||
import org.geysermc.geyser.item.enchantment.Enchantment;
|
||||
import org.geysermc.geyser.level.block.type.Block;
|
||||
import org.geysermc.geyser.registry.Registries;
|
||||
@@ -95,10 +94,6 @@ public class Item {
|
||||
return baseComponents.getOrDefault(DataComponentType.MAX_STACK_SIZE, 1);
|
||||
}
|
||||
|
||||
public Rarity defaultRarity() {
|
||||
return Rarity.fromId(baseComponents.getOrDefault(DataComponentType.RARITY, 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an unmodifiable {@link DataComponents} view containing known data components.
|
||||
* Optionally, additional components can be provided to replace (or add to)
|
||||
|
||||
@@ -25,13 +25,14 @@
|
||||
|
||||
package org.geysermc.geyser.item.type;
|
||||
|
||||
import org.geysermc.mcprotocollib.auth.GameProfile;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.geysermc.geyser.item.components.Rarity;
|
||||
import org.geysermc.geyser.level.block.type.Block;
|
||||
import org.geysermc.geyser.session.GeyserSession;
|
||||
import org.geysermc.geyser.text.ChatColor;
|
||||
import org.geysermc.geyser.text.MinecraftLocale;
|
||||
import org.geysermc.geyser.translator.item.BedrockItemBuilder;
|
||||
import org.geysermc.mcprotocollib.auth.GameProfile;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentType;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponents;
|
||||
|
||||
@@ -44,24 +45,21 @@ public class PlayerHeadItem extends BlockItem {
|
||||
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponents components, @NonNull BedrockItemBuilder builder) {
|
||||
super.translateComponentsToBedrock(session, components, builder);
|
||||
|
||||
// TODO verify
|
||||
// Also - ChatColor.YELLOW + ChatColor.ITALIC + MessageTranslator.convertMessageLenient(nameTag.getValue(), session.locale())) this code existed if a custom name was already present.
|
||||
// But I think we would always overwrite that because translateDisplayProperties runs after this method.
|
||||
String customName = builder.getCustomName();
|
||||
if (customName == null) {
|
||||
GameProfile profile = components.get(DataComponentType.PROFILE);
|
||||
if (profile != null) {
|
||||
String name = profile.getName();
|
||||
if (name != null) {
|
||||
// Add correct name of player skull
|
||||
String displayName = ChatColor.RESET + ChatColor.YELLOW +
|
||||
MinecraftLocale.getLocaleString("block.minecraft.player_head.named", session.locale()).replace("%s", name);
|
||||
builder.setCustomName(displayName);
|
||||
} else {
|
||||
// No name found so default to "Player Head"
|
||||
builder.setCustomName(ChatColor.RESET + ChatColor.YELLOW +
|
||||
MinecraftLocale.getLocaleString("block.minecraft.player_head", session.locale()));
|
||||
}
|
||||
// Use the correct color, determined by the rarity of the item
|
||||
char rarity = Rarity.fromId(components.get(DataComponentType.RARITY)).getColor();
|
||||
|
||||
GameProfile profile = components.get(DataComponentType.PROFILE);
|
||||
if (profile != null) {
|
||||
String name = profile.getName();
|
||||
if (name != null) {
|
||||
// Add correct name of player skull
|
||||
String displayName = ChatColor.RESET + ChatColor.ESCAPE + rarity +
|
||||
MinecraftLocale.getLocaleString("block.minecraft.player_head.named", session.locale()).replace("%s", name);
|
||||
builder.setCustomName(displayName);
|
||||
} else {
|
||||
// No name found so default to "Player Head"
|
||||
builder.setCustomName(ChatColor.RESET + ChatColor.ESCAPE + rarity +
|
||||
MinecraftLocale.getLocaleString("block.minecraft.player_head", session.locale()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +67,6 @@ import org.geysermc.geyser.api.item.custom.NonVanillaCustomItemData;
|
||||
import org.geysermc.geyser.inventory.item.StoredItemMappings;
|
||||
import org.geysermc.geyser.item.GeyserCustomMappingData;
|
||||
import org.geysermc.geyser.item.Items;
|
||||
import org.geysermc.geyser.item.components.Rarity;
|
||||
import org.geysermc.geyser.item.type.BlockItem;
|
||||
import org.geysermc.geyser.item.type.Item;
|
||||
import org.geysermc.geyser.level.block.property.Properties;
|
||||
@@ -491,9 +490,8 @@ public class ItemRegistryPopulator {
|
||||
mappingBuilder = mappingBuilder.toolType(mappingItem.getToolType().intern());
|
||||
}
|
||||
|
||||
if (javaOnlyItems.contains(javaItem) || javaItem.defaultRarity() != Rarity.COMMON) {
|
||||
if (javaOnlyItems.contains(javaItem)) {
|
||||
// These items don't exist on Bedrock, so set up a variable that indicates they should have custom names
|
||||
// Or, ensure that we are translating these at all times to account for rarity colouring
|
||||
mappingBuilder = mappingBuilder.translationString((javaItem instanceof BlockItem ? "block." : "item.") + entry.getKey().replace(":", "."));
|
||||
GeyserImpl.getInstance().getLogger().debug("Adding " + entry.getKey() + " as an item that needs to be translated.");
|
||||
}
|
||||
@@ -665,8 +663,7 @@ public class ItemRegistryPopulator {
|
||||
int customProtocolId = nextFreeBedrockId++;
|
||||
String identifier = customBlock.identifier();
|
||||
|
||||
// TODO verify
|
||||
final ItemDefinition definition = new SimpleItemDefinition(identifier, customProtocolId, ItemVersion.DATA_DRIVEN, false, null);
|
||||
final ItemDefinition definition = new SimpleItemDefinition(identifier, customProtocolId, ItemVersion.NONE, false, null);
|
||||
registry.put(customProtocolId, definition);
|
||||
customBlockItemDefinitions.put(customBlock, definition);
|
||||
customIdMappings.put(customProtocolId, identifier);
|
||||
|
||||
@@ -64,8 +64,6 @@ public class SkullCache {
|
||||
|
||||
private Vector3f lastPlayerPosition;
|
||||
|
||||
private long lastCleanup = System.currentTimeMillis();
|
||||
|
||||
public SkullCache(GeyserSession session) {
|
||||
this.session = session;
|
||||
this.maxVisibleSkulls = session.getGeyser().getConfig().getMaxVisibleCustomSkulls();
|
||||
|
||||
@@ -174,7 +174,7 @@ public final class ItemTranslator {
|
||||
// Translate item-specific components
|
||||
javaItem.translateComponentsToBedrock(session, components, nbtBuilder);
|
||||
|
||||
Rarity rarity = Rarity.fromId(components.getOrDefault(DataComponentType.RARITY, 0));
|
||||
Rarity rarity = Rarity.fromId(components.get(DataComponentType.RARITY));
|
||||
String customName = getCustomName(session, customComponents, bedrockItem, rarity.getColor(), false, false);
|
||||
if (customName != null) {
|
||||
PotionContents potionContents = components.get(DataComponentType.POTION_CONTENTS);
|
||||
@@ -611,6 +611,7 @@ public final class ItemTranslator {
|
||||
}
|
||||
|
||||
if (textures == null || textures.isEmpty()) {
|
||||
// TODO the java client looks up the texture properties here and updates the item
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user