Search in sources :

Example 6 with Recipe

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

the class MixinBrewingSlotIngredient method canInsert.

@Inject(method = "canInsert(Lnet/minecraft/item/ItemStack;)Z", at = @At("RETURN"), cancellable = true)
public void canInsert(ItemStack stack, CallbackInfoReturnable<Boolean> callbackInfoReturnable) {
    if (callbackInfoReturnable.getReturnValue() || BrewingRecipeRegistry.isValidIngredient(stack)) {
        callbackInfoReturnable.setReturnValue(true);
        return;
    }
    RecipeManagerAccessor recipeManager;
    if (inventory instanceof BrewingStandBlockEntity) {
        recipeManager = (RecipeManagerAccessor) ((BrewingStandBlockEntity) inventory).getWorld().getRecipeManager();
    } else if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
        recipeManager = (RecipeManagerAccessor) NbtCraftingClient.getClientRecipeManager();
    } else {
        NbtCrafting.logError("Failed to get recipe manager in brewing stand container class!");
        return;
    }
    Map<Identifier, Recipe<Inventory>> recipes = recipeManager.callGetAllOfType(NbtCrafting.BREWING_RECIPE_TYPE);
    callbackInfoReturnable.setReturnValue(recipes.values().stream().anyMatch(recipe -> recipe instanceof BrewingRecipe && ((BrewingRecipe) recipe).getIngredient().test(stack)));
}
Also used : FabricLoader(net.fabricmc.loader.api.FabricLoader) BrewingStandBlockEntity(net.minecraft.block.entity.BrewingStandBlockEntity) NbtCraftingClient(de.siphalor.nbtcrafting.client.NbtCraftingClient) Inject(org.spongepowered.asm.mixin.injection.Inject) Slot(net.minecraft.container.Slot) Inventory(net.minecraft.inventory.Inventory) Recipe(net.minecraft.recipe.Recipe) BrewingRecipe(de.siphalor.nbtcrafting.recipe.BrewingRecipe) CallbackInfoReturnable(org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable) RecipeManagerAccessor(de.siphalor.nbtcrafting.mixin.RecipeManagerAccessor) ItemStack(net.minecraft.item.ItemStack) BrewingRecipeRegistry(net.minecraft.recipe.BrewingRecipeRegistry) Mixin(org.spongepowered.asm.mixin.Mixin) Map(java.util.Map) EnvType(net.fabricmc.api.EnvType) Identifier(net.minecraft.util.Identifier) NbtCrafting(de.siphalor.nbtcrafting.NbtCrafting) At(org.spongepowered.asm.mixin.injection.At) RecipeManagerAccessor(de.siphalor.nbtcrafting.mixin.RecipeManagerAccessor) Identifier(net.minecraft.util.Identifier) Recipe(net.minecraft.recipe.Recipe) BrewingRecipe(de.siphalor.nbtcrafting.recipe.BrewingRecipe) BrewingStandBlockEntity(net.minecraft.block.entity.BrewingStandBlockEntity) BrewingRecipe(de.siphalor.nbtcrafting.recipe.BrewingRecipe) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 7 with Recipe

use of net.minecraft.recipe.Recipe in project Polymorph by TheIllusiveC4.

the class AbstractHighlightedRecipeData method getPacketData.

@Override
public Pair<SortedSet<RecipePair>, Identifier> getPacketData() {
    SortedSet<RecipePair> recipesList = this.getRecipesList();
    Identifier selected = null;
    if (!recipesList.isEmpty()) {
        selected = this.getSelectedRecipe().map(Recipe::getId).orElse(recipesList.first().getIdentifier());
    }
    return new Pair<>(recipesList, selected);
}
Also used : Identifier(net.minecraft.util.Identifier) RecipePair(top.theillusivec4.polymorph.api.common.base.RecipePair) Recipe(net.minecraft.recipe.Recipe) Pair(net.minecraft.util.Pair) RecipePair(top.theillusivec4.polymorph.api.common.base.RecipePair)

Aggregations

Recipe (net.minecraft.recipe.Recipe)7 Identifier (net.minecraft.util.Identifier)6 Inventory (net.minecraft.inventory.Inventory)4 ItemStack (net.minecraft.item.ItemStack)4 RecipeManagerAccessor (de.siphalor.nbtcrafting.mixin.RecipeManagerAccessor)3 List (java.util.List)3 Map (java.util.Map)3 EnvType (net.fabricmc.api.EnvType)3 RecipeType (net.minecraft.recipe.RecipeType)3 Pair (net.minecraft.util.Pair)3 Mixin (org.spongepowered.asm.mixin.Mixin)3 At (org.spongepowered.asm.mixin.injection.At)3 Inject (org.spongepowered.asm.mixin.injection.Inject)3 CallbackInfoReturnable (org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable)3 RecipePair (top.theillusivec4.polymorph.api.common.base.RecipePair)3 NbtCrafting (de.siphalor.nbtcrafting.NbtCrafting)2 NbtCraftingClient (de.siphalor.nbtcrafting.client.NbtCraftingClient)2 BrewingRecipe (de.siphalor.nbtcrafting.recipe.BrewingRecipe)2 Optional (java.util.Optional)2 Set (java.util.Set)2