diff --git a/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeePlugin.java b/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeePlugin.java index 7adfd488f..290bf2a4e 100644 --- a/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeePlugin.java +++ b/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeePlugin.java @@ -83,7 +83,7 @@ public class GeyserBungeePlugin extends Plugin implements GeyserBootstrap { // Copied from ViaVersion. // https://github.com/ViaVersion/ViaVersion/blob/b8072aad86695cc8ec6f5e4103e43baf3abf6cc5/bungee/src/main/java/us/myles/ViaVersion/BungeePlugin.java#L43 try { - ProtocolConstants.class.getField("MINECRAFT_1_21"); + ProtocolConstants.class.getField("MINECRAFT_1_21_4"); } catch (NoSuchFieldException e) { geyserLogger.error(" / \\"); geyserLogger.error(" / \\"); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/WolfEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/WolfEntity.java index 1b06f3860..b108c9fbe 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/WolfEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/WolfEntity.java @@ -128,6 +128,7 @@ public class WolfEntity extends TameableEntity { public void setBody(ItemStack stack) { super.setBody(stack); isCurseOfBinding = ItemUtils.hasEffect(session, stack, EnchantmentComponent.PREVENT_ARMOR_CHANGE); + // Not using ItemStack#getDataComponents as that wouldn't include default item components repairableItems = GeyserItemStack.from(stack).getComponent(DataComponentType.REPAIRABLE); } diff --git a/core/src/main/java/org/geysermc/geyser/inventory/GeyserItemStack.java b/core/src/main/java/org/geysermc/geyser/inventory/GeyserItemStack.java index c595ea1b5..4ddff305e 100644 --- a/core/src/main/java/org/geysermc/geyser/inventory/GeyserItemStack.java +++ b/core/src/main/java/org/geysermc/geyser/inventory/GeyserItemStack.java @@ -125,6 +125,10 @@ public class GeyserItemStack { return isEmpty() ? null : components; } + /** + * @return whether this GeyserItemStack has any additional components on top of + * the base item components. + */ public boolean hasNonBaseComponents() { return components != null; } @@ -137,6 +141,15 @@ public class GeyserItemStack { return components; } + /** + * Returns the stored data component for a given {@link DataComponentType}, or null. + *

+ * This method will first check the additional components that may exist, + * and fallback to the item's default (or, "base") components if need be. + * @param type the {@link DataComponentType} to query + * @return the value for said type, or null. + * @param the value's type + */ @Nullable public T getComponent(@NonNull DataComponentType type) { if (components == null) { diff --git a/core/src/main/java/org/geysermc/geyser/item/type/Item.java b/core/src/main/java/org/geysermc/geyser/item/type/Item.java index c5dff3ad0..19789e086 100644 --- a/core/src/main/java/org/geysermc/geyser/item/type/Item.java +++ b/core/src/main/java/org/geysermc/geyser/item/type/Item.java @@ -100,21 +100,33 @@ public class Item { } /** - * Returns a modifiable DataComponents map. Should only be used when it must be modified. - * Otherwise, prefer using GeyserItemStack's getComponent + * Returns an unmodifiable {@link DataComponents} view containing known data components. + * Optionally, additional components can be provided to replace (or add to) + * the items' base components. + * To add data components, use {@link GeyserItemStack#getOrCreateComponents()}. */ @NonNull @UnmodifiableView - public DataComponents gatherComponents(DataComponents others) { + public DataComponents gatherComponents(@Nullable DataComponents others) { if (others == null) { return baseComponents; } + // Start with the base components that always exist DataComponents components = baseComponents.clone(); + // Add all additional components; these can override base components! + // e.g. custom stack size components.getDataComponents().putAll(others.getDataComponents()); + + // Return an unmodified map of the merged components return new DataComponents(ImmutableMap.copyOf(components.getDataComponents())); } + /** + * Returns this items value (or null) for a specific {@link DataComponentType}. + * Prefer using {@link GeyserItemStack#getComponent(DataComponentType)} + * to also query additional components that would override the default ones. + */ @Nullable public T getComponent(@NonNull DataComponentType type) { return baseComponents.get(type);