Skip to content

Commit

Permalink
Update to latest MCPL changes, fix issues with the force-player-inven…
Browse files Browse the repository at this point in the history
…tory workaround
  • Loading branch information
onebeastchris committed Feb 19, 2025
1 parent 7448a99 commit 4a88117
Show file tree
Hide file tree
Showing 61 changed files with 346 additions and 340 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
package org.geysermc.geyser.entity;

import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import java.util.List;
import java.util.Locale;
import java.util.function.BiConsumer;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.geysermc.geyser.GeyserImpl;
Expand All @@ -41,6 +38,10 @@
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.MetadataType;
import org.geysermc.mcprotocollib.protocol.data.game.entity.type.EntityType;

import java.util.List;
import java.util.Locale;
import java.util.function.BiConsumer;

/**
* Represents data for an entity. This includes properties such as height and width, as well as the list of entity
* metadata translators needed to translate the properties sent from the server. The translators are structured in such
Expand Down
314 changes: 157 additions & 157 deletions core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void setFireworkItem(EntityMetadata<ItemStack, ?> entityMetadata) {
if (item == null) {
return;
}
DataComponents components = item.getDataComponents();
DataComponents components = item.getDataComponentsPatch();
if (components == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public void setItemInFrame(EntityMetadata<ItemStack, ?> entityMetadata) {
NbtMap itemDataTag = itemData.getTag();
if (itemDataTag != null) {
// Remove custom name that Geyser sets for items due to translating non-"custom_name" components
String customName = ItemTranslator.getCustomName(session, heldItem.getDataComponents(),
String customName = ItemTranslator.getCustomName(session, heldItem.getDataComponentsPatch(),
session.getItemMappings().getMapping(heldItem), 'f', true, false);
if (customName == null) {
// No custom name found, must modify tag if custom name exists
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ObjectEntityMetadata;
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand;
import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentType;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentTypes;
import org.geysermc.mcprotocollib.protocol.data.game.level.particle.EntityEffectParticleData;
import org.geysermc.mcprotocollib.protocol.data.game.level.particle.Particle;
import org.geysermc.mcprotocollib.protocol.data.game.level.particle.ParticleType;
Expand Down Expand Up @@ -344,7 +344,7 @@ public void setBoundingBoxWidth(float width) {
*/
// Implementation note for 1.20.5: this code was moved to the NameTag item.
protected final InteractionResult checkInteractWithNameTag(GeyserItemStack itemStack) {
if (itemStack.getComponent(DataComponentType.CUSTOM_NAME) != null) {
if (itemStack.getComponent(DataComponentTypes.CUSTOM_NAME) != null) {
// The mob shall be named
return InteractionResult.SUCCESS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata;
import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentType;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentTypes;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponents;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.PotionContents;

Expand All @@ -59,9 +59,9 @@ public void setItem(EntityMetadata<ItemStack, ?> entityMetadata) {
setFlag(EntityFlag.LINGERING, false);
} else {
// As of Java 1.19.3, the server/client doesn't seem to care of the item is actually a potion?
DataComponents components = itemStack.getDataComponents();
DataComponents components = itemStack.getDataComponentsPatch();
if (components != null) {
PotionContents potionContents = components.get(DataComponentType.POTION_CONTENTS);
PotionContents potionContents = components.get(DataComponentTypes.POTION_CONTENTS);
if (potionContents != null) {
Potion potion = Potion.getByJavaId(potionContents.getPotionId());
if (potion != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.GameMode;
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand;
import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentType;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentTypes;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.HolderSet;

import java.util.Collections;
Expand Down Expand Up @@ -129,7 +129,7 @@ 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);
repairableItems = GeyserItemStack.from(stack).getComponent(DataComponentTypes.REPAIRABLE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.translator.text.MessageTranslator;
import org.geysermc.mcprotocollib.protocol.data.game.inventory.ContainerType;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentType;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentTypes;
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.inventory.ServerboundRenameItemPacket;

/**
Expand Down Expand Up @@ -73,7 +73,7 @@ public String checkForRename(GeyserSession session, String rename) {
String correctRename;
newName = rename;

Component originalName = getInput().getComponent(DataComponentType.CUSTOM_NAME);
Component originalName = getInput().getComponent(DataComponentTypes.CUSTOM_NAME);

String plainOriginalName = MessageTranslator.convertToPlainText(originalName, session.locale());
String plainNewName = MessageTranslator.convertToPlainText(rename);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.geysermc.geyser.translator.item.ItemTranslator;
import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentType;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentTypes;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponents;
import org.geysermc.mcprotocollib.protocol.data.game.recipe.display.slot.EmptySlotDisplay;
import org.geysermc.mcprotocollib.protocol.data.game.recipe.display.slot.ItemSlotDisplay;
Expand Down Expand Up @@ -89,7 +90,7 @@ private GeyserItemStack(int javaId, int amount, DataComponents components, int n
}

public static @NonNull GeyserItemStack from(@Nullable ItemStack itemStack) {
return itemStack == null ? EMPTY : new GeyserItemStack(itemStack.getId(), itemStack.getAmount(), itemStack.getDataComponents());
return itemStack == null ? EMPTY : new GeyserItemStack(itemStack.getId(), itemStack.getAmount(), itemStack.getDataComponentsPatch());
}

public static @NonNull GeyserItemStack from(@NonNull SlotDisplay slotDisplay) {
Expand Down Expand Up @@ -217,11 +218,11 @@ public ItemStack getItemStack() {
// Not fresh from server? Then we have changes to apply!~
if (bundleData != null && !bundleData.freshFromServer()) {
if (!bundleData.contents().isEmpty()) {
getOrCreateComponents().put(DataComponentType.BUNDLE_CONTENTS, bundleData.toComponent());
getOrCreateComponents().put(DataComponentTypes.BUNDLE_CONTENTS, bundleData.toComponent());
} else {
if (components != null) {
// Empty list = no component = should delete
components.getDataComponents().remove(DataComponentType.BUNDLE_CONTENTS);
components.getDataComponents().remove(DataComponentTypes.BUNDLE_CONTENTS);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.translator.item.ItemTranslator;
import org.geysermc.mcprotocollib.protocol.data.game.inventory.ContainerType;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentType;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentTypes;
import org.jetbrains.annotations.Range;

import java.util.Arrays;
Expand Down Expand Up @@ -135,7 +135,7 @@ public void setItem(int slot, @NonNull GeyserItemStack newItem, GeyserSession se

// Lodestone caching
if (newItem.asItem() == Items.COMPASS) {
var tracker = newItem.getComponent(DataComponentType.LODESTONE_TRACKER);
var tracker = newItem.getComponent(DataComponentTypes.LODESTONE_TRACKER);
if (tracker != null) {
session.getLodestoneCache().cacheInventoryItem(newItem, tracker);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import org.geysermc.geyser.translator.inventory.InventoryTranslator;
import org.geysermc.geyser.translator.text.MessageTranslator;
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.GameMode;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentType;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentTypes;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.HolderSet;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.ItemEnchantments;
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.inventory.ServerboundRenameItemPacket;
Expand Down Expand Up @@ -117,7 +117,7 @@ private void updateInventoryState(GeyserSession session, AnvilContainer anvilCon

// Changing the item in the input slot resets the name field on Bedrock, but
// does not result in a FilterTextPacket
String originalName = MessageTranslator.convertToPlainText(input.getComponent(DataComponentType.CUSTOM_NAME), session.locale());
String originalName = MessageTranslator.convertToPlainText(input.getComponent(DataComponentTypes.CUSTOM_NAME), session.locale());
ServerboundRenameItemPacket renameItemPacket = new ServerboundRenameItemPacket(originalName);
session.sendDownstreamGamePacket(renameItemPacket);

Expand Down Expand Up @@ -367,9 +367,9 @@ private int calcMergeEnchantmentCost(GeyserSession session, GeyserItemStack inpu
private Object2IntMap<Enchantment> getEnchantments(GeyserSession session, GeyserItemStack itemStack) {
ItemEnchantments enchantmentComponent;
if (isEnchantedBook(itemStack)) {
enchantmentComponent = itemStack.getComponent(DataComponentType.STORED_ENCHANTMENTS);
enchantmentComponent = itemStack.getComponent(DataComponentTypes.STORED_ENCHANTMENTS);
} else {
enchantmentComponent = itemStack.getComponent(DataComponentType.ENCHANTMENTS);
enchantmentComponent = itemStack.getComponent(DataComponentTypes.ENCHANTMENTS);
}
if (enchantmentComponent != null) {
Object2IntMap<Enchantment> enchantments = new Object2IntOpenHashMap<>();
Expand All @@ -395,7 +395,7 @@ private boolean isCombining(GeyserItemStack input, GeyserItemStack material) {
}

private boolean isRepairing(GeyserItemStack input, GeyserItemStack material, GeyserSession session) {
HolderSet repairable = input.getComponent(DataComponentType.REPAIRABLE);
HolderSet repairable = input.getComponent(DataComponentTypes.REPAIRABLE);
if (repairable == null) {
return false;
}
Expand All @@ -409,27 +409,27 @@ private boolean isRenaming(GeyserSession session, AnvilContainer anvilContainer,
}
// This should really check the name field in all cases, but that requires the localized name
// of the item which can change depending on NBT and Minecraft Edition
Component originalName = anvilContainer.getInput().getComponent(DataComponentType.CUSTOM_NAME);
Component originalName = anvilContainer.getInput().getComponent(DataComponentTypes.CUSTOM_NAME);
if (bedrock && originalName != null && anvilContainer.getNewName() != null) {
// Check text and formatting
String legacyOriginalName = MessageTranslator.convertMessage(originalName, session.locale());
return !legacyOriginalName.equals(anvilContainer.getNewName());
}
return !Objects.equals(originalName, anvilContainer.getResult().getComponent(DataComponentType.CUSTOM_NAME));
return !Objects.equals(originalName, anvilContainer.getResult().getComponent(DataComponentTypes.CUSTOM_NAME));
}

private int getRepairCost(GeyserItemStack itemStack) {
return itemStack.getComponentElseGet(DataComponentType.REPAIR_COST, () -> 0);
return itemStack.getComponentElseGet(DataComponentTypes.REPAIR_COST, () -> 0);
}

private boolean hasDurability(GeyserItemStack itemStack) {
if (itemStack.asItem().defaultMaxDamage() > 0) {
return itemStack.getComponent(DataComponentType.UNBREAKABLE) != null;
return itemStack.getComponent(DataComponentTypes.UNBREAKABLE) != null;
}
return false;
}

private int getDamage(GeyserItemStack itemStack) {
return itemStack.getComponentElseGet(DataComponentType.DAMAGE, () -> 0);
return itemStack.getComponentElseGet(DataComponentTypes.DAMAGE, () -> 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.translator.item.BedrockItemBuilder;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.ArmorTrim;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentType;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentTypes;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponents;

public class ArmorItem extends Item {
Expand All @@ -46,7 +46,7 @@ public ArmorItem(String javaIdentifier, Builder builder) {
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponents components, @NonNull BedrockItemBuilder builder) {
super.translateComponentsToBedrock(session, components, builder);

ArmorTrim trim = components.get(DataComponentType.TRIM);
ArmorTrim trim = components.get(DataComponentTypes.TRIM);
if (trim != null) {
TrimMaterial material = session.getRegistryCache().trimMaterials().byId(trim.material().id());
TrimPattern pattern = session.getRegistryCache().trimPatterns().byId(trim.pattern().id());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.geysermc.geyser.registry.type.ItemMapping;
import org.geysermc.geyser.registry.type.ItemMappings;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentType;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentTypes;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.PotionContents;

public class ArrowItem extends Item {
Expand All @@ -48,7 +48,7 @@ public ArrowItem(String javaIdentifier, Builder builder) {
if (potion != null) {
itemStack = Items.TIPPED_ARROW.newItemStack(itemStack.getAmount(), itemStack.getComponents());
PotionContents contents = potion.toComponent();
itemStack.getOrCreateComponents().put(DataComponentType.POTION_CONTENTS, contents);
itemStack.getOrCreateComponents().put(DataComponentTypes.POTION_CONTENTS, contents);
}
return itemStack;
}
Expand Down
10 changes: 5 additions & 5 deletions core/src/main/java/org/geysermc/geyser/item/type/BannerItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import org.geysermc.geyser.util.MinecraftKey;
import org.geysermc.mcprotocollib.protocol.data.game.Holder;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.BannerPatternLayer;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentType;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentTypes;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponents;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.Unit;

Expand Down Expand Up @@ -206,7 +206,7 @@ public BannerItem(Builder builder, Block block, Block... otherBlocks) {
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponents components, @NonNull BedrockItemBuilder builder) {
super.translateComponentsToBedrock(session, components, builder);

List<BannerPatternLayer> patterns = components.get(DataComponentType.BANNER_PATTERNS);
List<BannerPatternLayer> patterns = components.get(DataComponentTypes.BANNER_PATTERNS);
if (patterns != null) {
convertBannerPattern(session, patterns, builder);
}
Expand All @@ -225,9 +225,9 @@ public void translateNbtToJava(@NonNull GeyserSession session, @NonNull NbtMap b
pair.right().ordinal()));
}

components.put(DataComponentType.BANNER_PATTERNS, patternLayers);
components.put(DataComponentType.HIDE_ADDITIONAL_TOOLTIP, Unit.INSTANCE);
components.put(DataComponentType.ITEM_NAME, Component
components.put(DataComponentTypes.BANNER_PATTERNS, patternLayers);
components.put(DataComponentTypes.HIDE_ADDITIONAL_TOOLTIP, Unit.INSTANCE);
components.put(DataComponentTypes.ITEM_NAME, Component
.translatable("block.minecraft.ominous_banner")
.style(Style.style(TextColor.color(16755200)))
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.geysermc.geyser.registry.type.ItemMappings;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.translator.item.BedrockItemBuilder;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentType;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentTypes;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponents;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.LodestoneTracker;

Expand Down Expand Up @@ -62,7 +62,7 @@ public ItemMapping toBedrockDefinition(DataComponents components, ItemMappings m
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponents components, @NonNull BedrockItemBuilder builder) {
super.translateComponentsToBedrock(session, components, builder);

LodestoneTracker tracker = components.get(DataComponentType.LODESTONE_TRACKER);
LodestoneTracker tracker = components.get(DataComponentTypes.LODESTONE_TRACKER);
if (tracker != null) {
int trackId = session.getLodestoneCache().store(tracker);
// Set the bedrock tracking id - will return 0 if invalid
Expand All @@ -72,7 +72,7 @@ public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNul

private boolean isLodestoneCompass(@Nullable DataComponents components) {
if (components != null) {
return components.getDataComponents().containsKey(DataComponentType.LODESTONE_TRACKER);
return components.getDataComponents().containsKey(DataComponentTypes.LODESTONE_TRACKER);
}
return false;
}
Expand Down
Loading

0 comments on commit 4a88117

Please sign in to comment.