Search in sources :

Example 1 with BrewingRecipe

use of de.siphalor.nbtcrafting.recipe.BrewingRecipe in project nbt-crafting by Siphalor.

the class MixinBrewingSlotPotion 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() || matches(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).getBase().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) Mixin(org.spongepowered.asm.mixin.Mixin) Map(java.util.Map) EnvType(net.fabricmc.api.EnvType) Identifier(net.minecraft.util.Identifier) Shadow(org.spongepowered.asm.mixin.Shadow) 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 2 with BrewingRecipe

use of de.siphalor.nbtcrafting.recipe.BrewingRecipe 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 3 with BrewingRecipe

use of de.siphalor.nbtcrafting.recipe.BrewingRecipe in project nbt-crafting by Siphalor.

the class MixinBrewingStandBlockEntity method craft.

@Inject(method = "craft", at = @At("HEAD"), cancellable = true)
private void craft(CallbackInfo callbackInfo) {
    Optional<BrewingRecipe> recipe = world.getRecipeManager().getFirstMatch(NbtCrafting.BREWING_RECIPE_TYPE, (BrewingStandBlockEntity) (Object) this, world);
    if (recipe.isPresent()) {
        BrewingStandBlockEntity inv = (BrewingStandBlockEntity) (Object) this;
        DefaultedList<ItemStack> remainingStacks = recipe.get().getRemainingStacks(inv);
        ItemStack[] results = recipe.get().craftAll(inv);
        getInvStack(3).decrement(1);
        for (int i = 0; i < 3; i++) {
            if (results[i] != null) {
                setInvStack(i, results[i]);
            }
        }
        RecipeUtil.putRemainders(remainingStacks, inv, world, pos);
        world.playLevelEvent(1035, pos, 0);
        callbackInfo.cancel();
    }
}
Also used : ItemStack(net.minecraft.item.ItemStack) BrewingRecipe(de.siphalor.nbtcrafting.recipe.BrewingRecipe) BrewingStandBlockEntity(net.minecraft.block.entity.BrewingStandBlockEntity) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

BrewingRecipe (de.siphalor.nbtcrafting.recipe.BrewingRecipe)3 BrewingStandBlockEntity (net.minecraft.block.entity.BrewingStandBlockEntity)3 ItemStack (net.minecraft.item.ItemStack)3 Inject (org.spongepowered.asm.mixin.injection.Inject)3 NbtCrafting (de.siphalor.nbtcrafting.NbtCrafting)2 NbtCraftingClient (de.siphalor.nbtcrafting.client.NbtCraftingClient)2 RecipeManagerAccessor (de.siphalor.nbtcrafting.mixin.RecipeManagerAccessor)2 Map (java.util.Map)2 EnvType (net.fabricmc.api.EnvType)2 FabricLoader (net.fabricmc.loader.api.FabricLoader)2 Slot (net.minecraft.container.Slot)2 Inventory (net.minecraft.inventory.Inventory)2 Recipe (net.minecraft.recipe.Recipe)2 Identifier (net.minecraft.util.Identifier)2 Mixin (org.spongepowered.asm.mixin.Mixin)2 At (org.spongepowered.asm.mixin.injection.At)2 CallbackInfoReturnable (org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable)2 BrewingRecipeRegistry (net.minecraft.recipe.BrewingRecipeRegistry)1 Shadow (org.spongepowered.asm.mixin.Shadow)1