Search in sources :

Example 1 with CraftingMenu

use of net.minecraft.world.inventory.CraftingMenu in project SpongeCommon by SpongePowered.

the class RecipeManagerMixin_API method findMatchingRecipe.

@Override
@SuppressWarnings("unchecked")
public Optional<Recipe> findMatchingRecipe(final Inventory inventory, final ServerWorld world) {
    Preconditions.checkNotNull(inventory);
    Preconditions.checkNotNull(world);
    if (inventory instanceof AbstractFurnaceBlockEntity) {
        final net.minecraft.world.item.crafting.RecipeType<? extends AbstractCookingRecipe> type = ((AbstractFurnaceBlockEntityAccessor) inventory).accessor$recipeType();
        return this.<Container, AbstractCookingRecipe>shadow$getRecipeFor((net.minecraft.world.item.crafting.RecipeType<AbstractCookingRecipe>) type, (Container) inventory, (net.minecraft.world.level.Level) world).map(Recipe.class::cast);
    }
    if (inventory instanceof CampfireBlockEntity) {
        return this.shadow$getRecipeFor(net.minecraft.world.item.crafting.RecipeType.CAMPFIRE_COOKING, (Container) inventory, (net.minecraft.world.level.Level) world).map(Recipe.class::cast);
    }
    if (inventory instanceof CraftingMenu) {
        final CraftingContainer craftingInventory = ((CraftingMenuAccessor) inventory).accessor$craftSlots();
        return this.shadow$getRecipeFor(net.minecraft.world.item.crafting.RecipeType.CRAFTING, craftingInventory, (net.minecraft.world.level.Level) world).map(Recipe.class::cast);
    }
    if (inventory instanceof InventoryMenu) {
        final CraftingContainer craftingInventory = ((InventoryMenuAccessor) inventory).accessor$craftSlots();
        return this.shadow$getRecipeFor(net.minecraft.world.item.crafting.RecipeType.CRAFTING, craftingInventory, (net.minecraft.world.level.Level) world).map(Recipe.class::cast);
    }
    if (inventory instanceof StonecutterMenu) {
        final Container stonecutterInventory = ((StonecutterMenu) inventory).container;
        return this.shadow$getRecipeFor(net.minecraft.world.item.crafting.RecipeType.STONECUTTING, stonecutterInventory, (net.minecraft.world.level.Level) world).map(Recipe.class::cast);
    }
    return Optional.empty();
}
Also used : Recipe(org.spongepowered.api.item.recipe.Recipe) CookingRecipe(org.spongepowered.api.item.recipe.cooking.CookingRecipe) AbstractCookingRecipe(net.minecraft.world.item.crafting.AbstractCookingRecipe) CraftingMenu(net.minecraft.world.inventory.CraftingMenu) StonecutterMenu(net.minecraft.world.inventory.StonecutterMenu) InventoryMenuAccessor(org.spongepowered.common.accessor.world.inventory.InventoryMenuAccessor) Container(net.minecraft.world.Container) CraftingContainer(net.minecraft.world.inventory.CraftingContainer) CraftingContainer(net.minecraft.world.inventory.CraftingContainer) InventoryMenu(net.minecraft.world.inventory.InventoryMenu) RecipeType(org.spongepowered.api.item.recipe.RecipeType) AbstractFurnaceBlockEntity(net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity) CampfireBlockEntity(net.minecraft.world.level.block.entity.CampfireBlockEntity) CraftingMenuAccessor(org.spongepowered.common.accessor.world.inventory.CraftingMenuAccessor) AbstractFurnaceBlockEntityAccessor(org.spongepowered.common.accessor.world.level.block.entity.AbstractFurnaceBlockEntityAccessor)

Aggregations

Container (net.minecraft.world.Container)1 CraftingContainer (net.minecraft.world.inventory.CraftingContainer)1 CraftingMenu (net.minecraft.world.inventory.CraftingMenu)1 InventoryMenu (net.minecraft.world.inventory.InventoryMenu)1 StonecutterMenu (net.minecraft.world.inventory.StonecutterMenu)1 AbstractCookingRecipe (net.minecraft.world.item.crafting.AbstractCookingRecipe)1 AbstractFurnaceBlockEntity (net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity)1 CampfireBlockEntity (net.minecraft.world.level.block.entity.CampfireBlockEntity)1 Recipe (org.spongepowered.api.item.recipe.Recipe)1 RecipeType (org.spongepowered.api.item.recipe.RecipeType)1 CookingRecipe (org.spongepowered.api.item.recipe.cooking.CookingRecipe)1 CraftingMenuAccessor (org.spongepowered.common.accessor.world.inventory.CraftingMenuAccessor)1 InventoryMenuAccessor (org.spongepowered.common.accessor.world.inventory.InventoryMenuAccessor)1 AbstractFurnaceBlockEntityAccessor (org.spongepowered.common.accessor.world.level.block.entity.AbstractFurnaceBlockEntityAccessor)1