Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.HashSet;
import java.util.Set;
import net.minecraft.core.Holder;
import net.minecraft.core.component.DataComponentGetter;
import net.minecraft.core.component.DataComponentMap;
import net.minecraft.core.registries.Registries;
import org.bukkit.craftbukkit.CraftRegistry;
Expand Down Expand Up @@ -32,9 +33,9 @@ public static Set<DataComponentType> minecraftToBukkit(final Set<net.minecraft.c
return Collections.unmodifiableSet(types);
}

public static <B, M> @Nullable B convertDataComponentValue(final DataComponentMap map, final PaperDataComponentType.ValuedImpl<B, M> type) {
public static <B, M> @Nullable B convertDataComponentValue(final DataComponentGetter getter, final PaperDataComponentType.ValuedImpl<B, M> type) {
final net.minecraft.core.component.DataComponentType<M> nms = bukkitToMinecraft(type);
final M nmsValue = map.get(nms);
final M nmsValue = getter.get(nms);
if (nmsValue == null) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.google.common.collect.Lists;
import com.mojang.logging.LogUtils;
import io.papermc.paper.datacomponent.DataComponentType;
import io.papermc.paper.datacomponent.PaperDataComponentType;
import io.papermc.paper.entity.LookAnchor;
import io.papermc.paper.entity.TeleportFlag;
import java.util.EnumSet;
Expand Down Expand Up @@ -1324,19 +1325,21 @@ public void broadcastHurtAnimation(java.util.Collection<Player> players) {
((CraftPlayer) player).sendHurtAnimation(0, this);
}
}

@Override
public <T> @Nullable T getData(@NotNull final DataComponentType.Valued<T> type) {
return this.entity.get(io.papermc.paper.datacomponent.PaperDataComponentType.bukkitToMinecraft(type));
return PaperDataComponentType.convertDataComponentValue(this.getHandle(), (PaperDataComponentType.ValuedImpl<T, ?>) type);
}

@Override
public <T> @Nullable T getDataOrDefault(@NotNull final DataComponentType.Valued<? extends T> type, @Nullable final T fallback) {
return this.entity.getOrDefault(io.papermc.paper.datacomponent.PaperDataComponentType.bukkitToMinecraft(type), fallback);
final T value = this.getData((DataComponentType.Valued<T>) type);
return (value != null) ? value : fallback;
}

@Override
public boolean hasData(final @NotNull DataComponentType type) {
return this.entity.get(io.papermc.paper.datacomponent.PaperDataComponentType.bukkitToMinecraft(type)) != null;
return this.getHandle().get(io.papermc.paper.datacomponent.PaperDataComponentType.bukkitToMinecraft(type)) != null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ public <T> T getData(final io.papermc.paper.datacomponent.DataComponentType.Valu
if (this.isEmpty()) {
return null;
}
return PaperDataComponentType.convertDataComponentValue(this.handle.getComponents(), (PaperDataComponentType.ValuedImpl<T, ?>) type);
return PaperDataComponentType.convertDataComponentValue(this.handle, (PaperDataComponentType.ValuedImpl<T, ?>) type);
}

@Override
Expand Down
Loading