Search in sources :

Example 1 with IIngredient

use of de.siphalor.nbtcrafting.ingredient.IIngredient in project nbt-crafting by Siphalor.

the class NbtCrafting method createAdvancedRecipeSyncPacket.

public static PacketByteBuf createAdvancedRecipeSyncPacket(RecipeManager recipeManager) {
    PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
    advancedIngredientSerializationEnabled.set(true);
    List<Recipe<?>> recipes = recipeManager.values().stream().filter(recipe -> {
        for (Ingredient ingredient : recipe.getPreviewInputs()) {
            if (((IIngredient) (Object) ingredient).nbtCrafting$isAdvanced()) {
                return true;
            }
        }
        return false;
    }).collect(Collectors.toList());
    buf.writeVarInt(recipes.size());
    for (Recipe<?> recipe : recipes) {
        @SuppressWarnings("rawtypes") RecipeSerializer serializer = recipe.getSerializer();
        buf.writeIdentifier(Registry.RECIPE_SERIALIZER.getId(serializer));
        buf.writeIdentifier(recipe.getId());
        // noinspection unchecked
        serializer.write(buf, recipe);
    }
    advancedIngredientSerializationEnabled.set(false);
    return buf;
}
Also used : LoadingCache(com.google.common.cache.LoadingCache) Unpooled(io.netty.buffer.Unpooled) ServerPlayConnectionEvents(net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents) CauldronRecipeSerializer(de.siphalor.nbtcrafting.recipe.cauldron.CauldronRecipeSerializer) AnvilRecipe(de.siphalor.nbtcrafting.recipe.AnvilRecipe) RecipeTypeHelper(de.siphalor.nbtcrafting.api.RecipeTypeHelper) WrappedRecipeSerializer(de.siphalor.nbtcrafting.recipe.WrappedRecipeSerializer) BrewingRecipe(de.siphalor.nbtcrafting.recipe.BrewingRecipe) it.unimi.dsi.fastutil.ints(it.unimi.dsi.fastutil.ints) net.minecraft.recipe(net.minecraft.recipe) ModInitializer(net.fabricmc.api.ModInitializer) Collectors(java.util.stream.Collectors) Pair(com.mojang.datafixers.util.Pair) Registry(net.minecraft.util.registry.Registry) IIngredient(de.siphalor.nbtcrafting.ingredient.IIngredient) ServerLoginConnectionEvents(net.fabricmc.fabric.api.networking.v1.ServerLoginConnectionEvents) StatChangedCriterion(de.siphalor.nbtcrafting.advancement.StatChangedCriterion) TimeUnit(java.util.concurrent.TimeUnit) CacheLoader(com.google.common.cache.CacheLoader) MixinCriterions(de.siphalor.nbtcrafting.mixin.advancement.MixinCriterions) List(java.util.List) CompoundTag(net.minecraft.nbt.CompoundTag) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) Logger(org.apache.logging.log4j.Logger) CauldronRecipe(de.siphalor.nbtcrafting.recipe.cauldron.CauldronRecipe) IServerPlayerEntity(de.siphalor.nbtcrafting.util.duck.IServerPlayerEntity) Identifier(net.minecraft.util.Identifier) CacheBuilder(com.google.common.cache.CacheBuilder) PacketByteBuf(net.minecraft.util.PacketByteBuf) LogManager(org.apache.logging.log4j.LogManager) ServerLoginNetworking(net.fabricmc.fabric.api.networking.v1.ServerLoginNetworking) AnvilRecipe(de.siphalor.nbtcrafting.recipe.AnvilRecipe) BrewingRecipe(de.siphalor.nbtcrafting.recipe.BrewingRecipe) CauldronRecipe(de.siphalor.nbtcrafting.recipe.cauldron.CauldronRecipe) IIngredient(de.siphalor.nbtcrafting.ingredient.IIngredient) PacketByteBuf(net.minecraft.util.PacketByteBuf) CauldronRecipeSerializer(de.siphalor.nbtcrafting.recipe.cauldron.CauldronRecipeSerializer) WrappedRecipeSerializer(de.siphalor.nbtcrafting.recipe.WrappedRecipeSerializer)

Aggregations

CacheBuilder (com.google.common.cache.CacheBuilder)1 CacheLoader (com.google.common.cache.CacheLoader)1 LoadingCache (com.google.common.cache.LoadingCache)1 Pair (com.mojang.datafixers.util.Pair)1 StatChangedCriterion (de.siphalor.nbtcrafting.advancement.StatChangedCriterion)1 RecipeTypeHelper (de.siphalor.nbtcrafting.api.RecipeTypeHelper)1 IIngredient (de.siphalor.nbtcrafting.ingredient.IIngredient)1 MixinCriterions (de.siphalor.nbtcrafting.mixin.advancement.MixinCriterions)1 AnvilRecipe (de.siphalor.nbtcrafting.recipe.AnvilRecipe)1 BrewingRecipe (de.siphalor.nbtcrafting.recipe.BrewingRecipe)1 WrappedRecipeSerializer (de.siphalor.nbtcrafting.recipe.WrappedRecipeSerializer)1 CauldronRecipe (de.siphalor.nbtcrafting.recipe.cauldron.CauldronRecipe)1 CauldronRecipeSerializer (de.siphalor.nbtcrafting.recipe.cauldron.CauldronRecipeSerializer)1 IServerPlayerEntity (de.siphalor.nbtcrafting.util.duck.IServerPlayerEntity)1 Unpooled (io.netty.buffer.Unpooled)1 it.unimi.dsi.fastutil.ints (it.unimi.dsi.fastutil.ints)1 List (java.util.List)1 TimeUnit (java.util.concurrent.TimeUnit)1 Collectors (java.util.stream.Collectors)1 ModInitializer (net.fabricmc.api.ModInitializer)1