Search in sources :

Example 1 with RecipeManager

use of net.minecraft.recipe.RecipeManager in project nbt-crafting by Siphalor.

the class NbtCraftingClient method onInitializeClient.

@Override
public void onInitializeClient() {
    ClientLoginNetworking.registerGlobalReceiver(NbtCrafting.PRESENCE_CHANNEL, (client, handler, buf, listenerAdder) -> {
        return CompletableFuture.completedFuture(new PacketByteBuf(Unpooled.buffer()));
    });
    ClientSidePacketRegistry.INSTANCE.register(NbtCrafting.UPDATE_ANVIL_TEXT_S2C_PACKET_ID, (packetContext, packetByteBuf) -> {
        if (MinecraftClient.getInstance().currentScreen instanceof AnvilScreen) {
            ((AnvilScreenAccessor) MinecraftClient.getInstance().currentScreen).getNameField().setText(packetByteBuf.readString());
        } else
            packetByteBuf.readString();
    });
    ClientPlayNetworking.registerGlobalReceiver(NbtCrafting.UPDATE_ADVANCED_RECIPES_PACKET_ID, (client, handler, buf, responseSender) -> {
        RecipeManager recipeManager = handler.getRecipeManager();
        Map<RecipeType<?>, Map<Identifier, Recipe<?>>> recipeMap = ((RecipeManagerAccessor) recipeManager).getRecipes();
        recipeMap = new HashMap<>(recipeMap);
        int recipeCount = buf.readVarInt();
        NbtCrafting.advancedIngredientSerializationEnabled.set(true);
        for (int i = 0; i < recipeCount; i++) {
            RecipeSerializer<?> serializer = Registry.RECIPE_SERIALIZER.get(buf.readIdentifier());
            Identifier id = buf.readIdentifier();
            Recipe<?> recipe = serializer.read(id, buf);
            Map<Identifier, Recipe<?>> recipeType = recipeMap.computeIfAbsent(recipe.getType(), rt -> new HashMap<>());
            recipeType.put(id, recipe);
        }
        NbtCrafting.advancedIngredientSerializationEnabled.set(false);
        ((RecipeManagerAccessor) recipeManager).setRecipes(ImmutableMap.copyOf(recipeMap));
    });
}
Also used : Recipe(net.minecraft.recipe.Recipe) AnvilScreen(net.minecraft.client.gui.screen.ingame.AnvilScreen) RecipeManagerAccessor(de.siphalor.nbtcrafting.mixin.RecipeManagerAccessor) Identifier(net.minecraft.util.Identifier) RecipeType(net.minecraft.recipe.RecipeType) PacketByteBuf(net.minecraft.util.PacketByteBuf) RecipeManager(net.minecraft.recipe.RecipeManager) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with RecipeManager

use of net.minecraft.recipe.RecipeManager in project bewitchment by MoriyaShiine.

the class OilCraftingProcessor method setup.

@Override
public void setup(IVariableProvider variables) {
    String recipeId = variables.get("recipe").asString();
    RecipeManager manager = MinecraftClient.getInstance().world.getRecipeManager();
    recipe = (OilRecipe) manager.get(new Identifier(recipeId)).filter(recipe -> recipe.getType().equals(BWRecipeTypes.OIL_RECIPE_TYPE)).orElseThrow(IllegalArgumentException::new);
}
Also used : BWRecipeTypes(moriyashiine.bewitchment.common.registry.BWRecipeTypes) IVariableProvider(vazkii.patchouli.api.IVariableProvider) ItemStack(net.minecraft.item.ItemStack) IVariable(vazkii.patchouli.api.IVariable) Identifier(net.minecraft.util.Identifier) IComponentProcessor(vazkii.patchouli.api.IComponentProcessor) MinecraftClient(net.minecraft.client.MinecraftClient) RecipeManager(net.minecraft.recipe.RecipeManager) OilRecipe(moriyashiine.bewitchment.common.recipe.OilRecipe) Identifier(net.minecraft.util.Identifier) RecipeManager(net.minecraft.recipe.RecipeManager)

Example 3 with RecipeManager

use of net.minecraft.recipe.RecipeManager in project bewitchment by MoriyaShiine.

the class RitualProcessor method setup.

@Override
public void setup(IVariableProvider variables) {
    String recipeId = variables.get("recipe").asString();
    RecipeManager manager = MinecraftClient.getInstance().world.getRecipeManager();
    recipe = (RitualRecipe) manager.get(new Identifier(recipeId)).filter(recipe -> recipe.getType().equals(BWRecipeTypes.RITUAL_RECIPE_TYPE)).orElseThrow(IllegalArgumentException::new);
}
Also used : BWRecipeTypes(moriyashiine.bewitchment.common.registry.BWRecipeTypes) IVariableProvider(vazkii.patchouli.api.IVariableProvider) ItemStack(net.minecraft.item.ItemStack) IVariable(vazkii.patchouli.api.IVariable) I18n(net.minecraft.client.resource.language.I18n) TranslatableText(net.minecraft.text.TranslatableText) RitualRecipe(moriyashiine.bewitchment.common.recipe.RitualRecipe) Identifier(net.minecraft.util.Identifier) IComponentProcessor(vazkii.patchouli.api.IComponentProcessor) MinecraftClient(net.minecraft.client.MinecraftClient) RecipeManager(net.minecraft.recipe.RecipeManager) Identifier(net.minecraft.util.Identifier) RecipeManager(net.minecraft.recipe.RecipeManager)

Example 4 with RecipeManager

use of net.minecraft.recipe.RecipeManager in project bewitchment by MoriyaShiine.

the class CurseProcessor method setup.

@Override
public void setup(IVariableProvider variables) {
    String recipeId = variables.get("recipe").asString();
    RecipeManager manager = MinecraftClient.getInstance().world.getRecipeManager();
    recipe = (CurseRecipe) manager.get(new Identifier(recipeId)).filter(recipe -> recipe.getType().equals(BWRecipeTypes.CURSE_RECIPE_TYPE)).orElseThrow(IllegalArgumentException::new);
}
Also used : BWRecipeTypes(moriyashiine.bewitchment.common.registry.BWRecipeTypes) BWRegistries(moriyashiine.bewitchment.common.registry.BWRegistries) IVariableProvider(vazkii.patchouli.api.IVariableProvider) ItemStack(net.minecraft.item.ItemStack) IVariable(vazkii.patchouli.api.IVariable) TranslatableText(net.minecraft.text.TranslatableText) Identifier(net.minecraft.util.Identifier) IComponentProcessor(vazkii.patchouli.api.IComponentProcessor) MinecraftClient(net.minecraft.client.MinecraftClient) RecipeManager(net.minecraft.recipe.RecipeManager) CurseRecipe(moriyashiine.bewitchment.common.recipe.CurseRecipe) Identifier(net.minecraft.util.Identifier) RecipeManager(net.minecraft.recipe.RecipeManager)

Example 5 with RecipeManager

use of net.minecraft.recipe.RecipeManager in project bewitchment by MoriyaShiine.

the class IncenseProcessor method setup.

@Override
public void setup(IVariableProvider variables) {
    String recipeId = variables.get("recipe").asString();
    RecipeManager manager = MinecraftClient.getInstance().world.getRecipeManager();
    recipe = (IncenseRecipe) manager.get(new Identifier(recipeId)).filter(recipe -> recipe.getType().equals(BWRecipeTypes.INCENSE_RECIPE_TYPE)).orElseThrow(IllegalArgumentException::new);
}
Also used : BWRecipeTypes(moriyashiine.bewitchment.common.registry.BWRecipeTypes) IVariableProvider(vazkii.patchouli.api.IVariableProvider) ItemStack(net.minecraft.item.ItemStack) IVariable(vazkii.patchouli.api.IVariable) IncenseRecipe(moriyashiine.bewitchment.common.recipe.IncenseRecipe) Identifier(net.minecraft.util.Identifier) IComponentProcessor(vazkii.patchouli.api.IComponentProcessor) MinecraftClient(net.minecraft.client.MinecraftClient) RecipeManager(net.minecraft.recipe.RecipeManager) Identifier(net.minecraft.util.Identifier) RecipeManager(net.minecraft.recipe.RecipeManager)

Aggregations

RecipeManager (net.minecraft.recipe.RecipeManager)6 Identifier (net.minecraft.util.Identifier)5 BWRecipeTypes (moriyashiine.bewitchment.common.registry.BWRecipeTypes)4 MinecraftClient (net.minecraft.client.MinecraftClient)4 ItemStack (net.minecraft.item.ItemStack)4 IComponentProcessor (vazkii.patchouli.api.IComponentProcessor)4 IVariable (vazkii.patchouli.api.IVariable)4 IVariableProvider (vazkii.patchouli.api.IVariableProvider)4 TranslatableText (net.minecraft.text.TranslatableText)3 ImmutableMap (com.google.common.collect.ImmutableMap)1 RecipeManagerAccessor (de.siphalor.nbtcrafting.mixin.RecipeManagerAccessor)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CurseRecipe (moriyashiine.bewitchment.common.recipe.CurseRecipe)1 IncenseRecipe (moriyashiine.bewitchment.common.recipe.IncenseRecipe)1 OilRecipe (moriyashiine.bewitchment.common.recipe.OilRecipe)1 RitualRecipe (moriyashiine.bewitchment.common.recipe.RitualRecipe)1 BWRegistries (moriyashiine.bewitchment.common.registry.BWRegistries)1