Class DataHelper
java.lang.Object
net.darkhax.bookshelf.common.api.util.DataHelper
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic net.minecraft.nbt.ListTagcontainerSubList(net.minecraft.nbt.ListTag list, Predicate<Integer> slots) Creates a sublist of an inventory tag based on a predicate on the slot indexes.static <T> net.minecraft.core.HolderSet<T> getTagOrEmpty(net.minecraft.core.HolderLookup.Provider provider, net.minecraft.resources.ResourceKey<net.minecraft.core.Registry<T>> registryKey, net.minecraft.tags.TagKey<T> tag) static <B extends io.netty.buffer.ByteBuf,V>
net.minecraft.network.codec.StreamCodec<B, Optional<V>> optionalStream(net.minecraft.network.codec.StreamCodec<B, V> streamCodec) Creates a new stream codec for an optional value.static <T extends net.minecraft.world.item.crafting.Recipe<?>>
net.minecraft.world.item.crafting.RecipeSerializer<T> recipeSerializer(com.mojang.serialization.MapCodec<T> codec, net.minecraft.network.codec.StreamCodec<net.minecraft.network.RegistryFriendlyByteBuf, T> stream) Creates a new recipe serializer.static net.minecraft.nbt.ListTagsubList(net.minecraft.nbt.ListTag list, int from, int to) Creates a sublist of a ListTag.
-
Constructor Details
-
DataHelper
public DataHelper()
-
-
Method Details
-
getTagOrEmpty
public static <T> net.minecraft.core.HolderSet<T> getTagOrEmpty(@Nullable net.minecraft.core.HolderLookup.Provider provider, net.minecraft.resources.ResourceKey<net.minecraft.core.Registry<T>> registryKey, net.minecraft.tags.TagKey<T> tag) -
subList
public static net.minecraft.nbt.ListTag subList(net.minecraft.nbt.ListTag list, int from, int to) Creates a sublist of a ListTag. UnlikeAbstractList.subList(int, int), the sublist is a new list instance and changes to the original will not be propagated.- Parameters:
list- The list to create a sublist from.from- The starting index.to- The ending index.- Returns:
- A sublist created from the input list.
-
containerSubList
public static net.minecraft.nbt.ListTag containerSubList(net.minecraft.nbt.ListTag list, Predicate<Integer> slots) Creates a sublist of an inventory tag based on a predicate on the slot indexes.- Parameters:
list- The inventory list tag.slots- A predicate for which item slots should be included in the sublist.- Returns:
- A sublist created from the input list.
-
optionalStream
public static <B extends io.netty.buffer.ByteBuf,V> net.minecraft.network.codec.StreamCodec<B,Optional<V>> optionalStream(net.minecraft.network.codec.StreamCodec<B, V> streamCodec) Creates a new stream codec for an optional value.- Type Parameters:
B- The type of the byte buffer.V- The content type of the stream.- Parameters:
streamCodec- A codec that can serialize the content type.- Returns:
- An optional stream codec.
-
recipeSerializer
public static <T extends net.minecraft.world.item.crafting.Recipe<?>> net.minecraft.world.item.crafting.RecipeSerializer<T> recipeSerializer(com.mojang.serialization.MapCodec<T> codec, net.minecraft.network.codec.StreamCodec<net.minecraft.network.RegistryFriendlyByteBuf, T> stream) Creates a new recipe serializer.- Type Parameters:
T- The type of the recipe.- Parameters:
codec- A codec for JSON/NBT data.stream- A codec for networking.- Returns:
- A recipe serializer object.
-