Search in sources :

Example 1 with CraftingContainer

use of net.minecraft.world.inventory.CraftingContainer 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)

Example 2 with CraftingContainer

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

the class ContainerUtil method generateAdapterLens.

@SuppressWarnings({ "unchecked", "rawtypes" })
private static Lens generateAdapterLens(final SlotLensProvider slots, final int index, final org.spongepowered.common.inventory.util.ContainerUtil.CraftingInventoryData crafting, final List<Slot> slotList, final net.minecraft.world.@Nullable Container subInventory) {
    Lens lens = ((InventoryBridge) subInventory).bridge$getAdapter().inventoryAdapter$getRootLens();
    if (lens instanceof PlayerInventoryLens) {
        if (slotList.size() == 36) {
            return new DelegatingLens(index, new PrimaryPlayerInventoryLens(0, slots, true), slots);
        }
        return lens;
    }
    // For Crafting Result we need the Slot to get Filter logic
    if (subInventory instanceof ResultContainer) {
        final Slot slot = slotList.get(0);
        if (slot instanceof ResultSlotAccessor) {
            crafting.out = index;
            if (crafting.base == null) {
                // In case we do not find the InventoryCrafting later assume it is directly after the SlotCrafting
                // e.g. for IC2 ContainerIndustrialWorkbench
                crafting.base = index + 1;
                crafting.grid = ((ResultSlotAccessor) slot).accessor$craftSlots();
            }
        }
    }
    if (subInventory instanceof CraftingContainer) {
        crafting.base = index;
        crafting.grid = ((CraftingContainer) subInventory);
    }
    return new DelegatingLens(index, slotList, lens, slots);
}
Also used : CraftingContainer(net.minecraft.world.inventory.CraftingContainer) PrimaryPlayerInventoryLens(org.spongepowered.common.inventory.lens.impl.comp.PrimaryPlayerInventoryLens) PlayerInventoryLens(org.spongepowered.common.inventory.lens.impl.minecraft.PlayerInventoryLens) PrimaryPlayerInventoryLens(org.spongepowered.common.inventory.lens.impl.comp.PrimaryPlayerInventoryLens) ResultSlotAccessor(org.spongepowered.common.accessor.world.inventory.ResultSlotAccessor) Slot(net.minecraft.world.inventory.Slot) CraftingInventoryLens(org.spongepowered.common.inventory.lens.impl.comp.CraftingInventoryLens) DelegatingLens(org.spongepowered.common.inventory.lens.impl.DelegatingLens) PrimaryPlayerInventoryLens(org.spongepowered.common.inventory.lens.impl.comp.PrimaryPlayerInventoryLens) GridInventoryLens(org.spongepowered.common.inventory.lens.impl.comp.GridInventoryLens) ContainerLens(org.spongepowered.common.inventory.lens.impl.minecraft.container.ContainerLens) CompoundLens(org.spongepowered.common.inventory.lens.impl.CompoundLens) Lens(org.spongepowered.common.inventory.lens.Lens) SingleGridLens(org.spongepowered.common.inventory.lens.impl.minecraft.SingleGridLens) PlayerInventoryLens(org.spongepowered.common.inventory.lens.impl.minecraft.PlayerInventoryLens) DelegatingLens(org.spongepowered.common.inventory.lens.impl.DelegatingLens) ResultContainer(net.minecraft.world.inventory.ResultContainer)

Example 3 with CraftingContainer

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

the class SpongeShapedCraftingRecipeSerializer method fromJson.

@Override
public ShapedRecipe fromJson(ResourceLocation recipeId, JsonObject json) {
    final String s = GsonHelper.getAsString(json, Constants.Recipe.GROUP, "");
    final JsonObject ingredientKey = GsonHelper.getAsJsonObject(json, Constants.Recipe.SHAPED_INGREDIENTS);
    final Map<String, Ingredient> map = this.deserializeIngredientKey(ingredientKey);
    final String[] astring = ShapedRecipeAccessor.invoker$shrink(ShapedRecipeAccessor.invoker$patternFromJson(GsonHelper.getAsJsonArray(json, Constants.Recipe.SHAPED_PATTERN)));
    final int i = astring[0].length();
    final int j = astring.length;
    final NonNullList<Ingredient> nonnulllist = ShapedRecipeAccessor.invoker$dissolvePattern(astring, map, i, j);
    final ItemStack itemstack = ShapedRecipe.itemFromJson(GsonHelper.getAsJsonObject(json, Constants.Recipe.RESULT));
    final ItemStack spongeStack = IngredientResultUtil.deserializeItemStack(json.getAsJsonObject(Constants.Recipe.SPONGE_RESULT));
    final Function<CraftingContainer, ItemStack> resultFunction = IngredientResultUtil.deserializeResultFunction(json);
    final Function<CraftingContainer, NonNullList<ItemStack>> remainingItemsFunction = IngredientResultUtil.deserializeRemainingItemsFunction(json);
    return new SpongeShapedRecipe(recipeId, s, i, j, nonnulllist, spongeStack == null ? itemstack : spongeStack, resultFunction, remainingItemsFunction);
}
Also used : JsonObject(com.google.gson.JsonObject) CraftingContainer(net.minecraft.world.inventory.CraftingContainer) Ingredient(net.minecraft.world.item.crafting.Ingredient) NonNullList(net.minecraft.core.NonNullList) ItemStack(net.minecraft.world.item.ItemStack)

Example 4 with CraftingContainer

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

the class SpongeShapelessCraftingRecipeSerializer method fromJson.

@Override
public ShapelessRecipe fromJson(ResourceLocation recipeId, JsonObject json) {
    final String s = GsonHelper.getAsString(json, Constants.Recipe.GROUP, "");
    final NonNullList<Ingredient> nonnulllist = this.readIngredients(GsonHelper.getAsJsonArray(json, Constants.Recipe.SHAPELESS_INGREDIENTS));
    if (nonnulllist.isEmpty()) {
        throw new JsonParseException("No ingredients for shapeless recipe");
    }
    if (nonnulllist.size() > 9) {
        throw new JsonParseException("Too many ingredients for shapeless recipe");
    }
    final ItemStack itemstack = ShapedRecipe.itemFromJson(GsonHelper.getAsJsonObject(json, Constants.Recipe.RESULT));
    final ItemStack spongeStack = IngredientResultUtil.deserializeItemStack(json.getAsJsonObject(Constants.Recipe.SPONGE_RESULT));
    final Function<CraftingContainer, ItemStack> resultFunction = IngredientResultUtil.deserializeResultFunction(json);
    final Function<CraftingContainer, NonNullList<ItemStack>> remainingItemsFunction = IngredientResultUtil.deserializeRemainingItemsFunction(json);
    return new SpongeShapelessRecipe(recipeId, s, spongeStack == null ? itemstack : spongeStack, nonnulllist, resultFunction, remainingItemsFunction);
}
Also used : CraftingContainer(net.minecraft.world.inventory.CraftingContainer) Ingredient(net.minecraft.world.item.crafting.Ingredient) NonNullList(net.minecraft.core.NonNullList) JsonParseException(com.google.gson.JsonParseException) ItemStack(net.minecraft.world.item.ItemStack)

Example 5 with CraftingContainer

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

the class LensRegistrar method generateLens.

@SuppressWarnings("unchecked")
private static Lens generateLens(Object inventory, int size, SlotLensProvider slotLensProvider) {
    if (size == 0) {
        return new DefaultEmptyLens();
    }
    LensFactory lensFactory = LensRegistrar.lensFactories.get(inventory.getClass());
    Lens lens = null;
    if (lensFactory != null) {
        lens = lensFactory.apply(inventory.getClass(), size, slotLensProvider);
        if (lens != null) {
            return lens;
        }
    }
    if (inventory instanceof CraftingContainer) {
        lens = LensRegistrar.lensCraftingInventory(size, ((CraftingContainer) inventory).getWidth(), ((CraftingContainer) inventory).getHeight(), slotLensProvider);
    } else if (inventory instanceof AbstractContainerMenu) {
        lens = ContainerUtil.generateLens(((AbstractContainerMenu) inventory), slotLensProvider);
    } else if (size == 1) {
        return slotLensProvider.getSlotLens(0);
    }
    if (lens != null) {
        return lens;
    }
    return new SingleIndexedLens(0, size, (Class<? extends Inventory>) inventory.getClass(), slotLensProvider);
}
Also used : CraftingContainer(net.minecraft.world.inventory.CraftingContainer) AbstractContainerMenu(net.minecraft.world.inventory.AbstractContainerMenu) CraftingInventoryLens(org.spongepowered.common.inventory.lens.impl.comp.CraftingInventoryLens) SlotLens(org.spongepowered.common.inventory.lens.slots.SlotLens) PrimaryPlayerInventoryLens(org.spongepowered.common.inventory.lens.impl.comp.PrimaryPlayerInventoryLens) BasicSlotLens(org.spongepowered.common.inventory.lens.impl.slot.BasicSlotLens) CraftingGridInventoryLens(org.spongepowered.common.inventory.lens.impl.comp.CraftingGridInventoryLens) ContainerLens(org.spongepowered.common.inventory.lens.impl.minecraft.container.ContainerLens) BrewingStandInventoryLens(org.spongepowered.common.inventory.lens.impl.minecraft.BrewingStandInventoryLens) FurnaceInventoryLens(org.spongepowered.common.inventory.lens.impl.minecraft.FurnaceInventoryLens) ContainerPlayerInventoryLens(org.spongepowered.common.inventory.lens.impl.minecraft.container.ContainerPlayerInventoryLens) LargeChestInventoryLens(org.spongepowered.common.inventory.lens.impl.minecraft.LargeChestInventoryLens) Lens(org.spongepowered.common.inventory.lens.Lens) SingleIndexedLens(org.spongepowered.common.inventory.lens.impl.minecraft.SingleIndexedLens) SingleGridLens(org.spongepowered.common.inventory.lens.impl.minecraft.SingleGridLens) SingleIndexedLens(org.spongepowered.common.inventory.lens.impl.minecraft.SingleIndexedLens)

Aggregations

CraftingContainer (net.minecraft.world.inventory.CraftingContainer)5 NonNullList (net.minecraft.core.NonNullList)2 ItemStack (net.minecraft.world.item.ItemStack)2 Ingredient (net.minecraft.world.item.crafting.Ingredient)2 Lens (org.spongepowered.common.inventory.lens.Lens)2 CraftingInventoryLens (org.spongepowered.common.inventory.lens.impl.comp.CraftingInventoryLens)2 PrimaryPlayerInventoryLens (org.spongepowered.common.inventory.lens.impl.comp.PrimaryPlayerInventoryLens)2 SingleGridLens (org.spongepowered.common.inventory.lens.impl.minecraft.SingleGridLens)2 ContainerLens (org.spongepowered.common.inventory.lens.impl.minecraft.container.ContainerLens)2 JsonObject (com.google.gson.JsonObject)1 JsonParseException (com.google.gson.JsonParseException)1 Container (net.minecraft.world.Container)1 AbstractContainerMenu (net.minecraft.world.inventory.AbstractContainerMenu)1 CraftingMenu (net.minecraft.world.inventory.CraftingMenu)1 InventoryMenu (net.minecraft.world.inventory.InventoryMenu)1 ResultContainer (net.minecraft.world.inventory.ResultContainer)1 Slot (net.minecraft.world.inventory.Slot)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