Search in sources :

Example 76 with ItemStack

use of net.minecraft.world.item.ItemStack in project SpongeCommon by SpongePowered.

the class SpongeSmokingRecipe method assemble.

@Override
public ItemStack assemble(final Container container) {
    if (this.resultFunction != null) {
        final ItemStack result = this.resultFunction.apply(container);
        result.setCount(1);
        return result;
    }
    return super.assemble(container);
}
Also used : ItemStack(net.minecraft.world.item.ItemStack)

Example 77 with ItemStack

use of net.minecraft.world.item.ItemStack 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 78 with ItemStack

use of net.minecraft.world.item.ItemStack in project SpongeCommon by SpongePowered.

the class SpongeShapelessRecipe method matches.

private static boolean matches(List<ItemStack> stacks, List<Ingredient> ingredients) {
    final int elements = ingredients.size();
    if (stacks.size() != elements) {
        return false;
    }
    // find matched stack -> ingredient list
    final Map<Integer, List<Integer>> matchesMap = new HashMap<>();
    for (int i = 0; i < ingredients.size(); i++) {
        Ingredient ingredient = ingredients.get(i);
        boolean noMatch = true;
        for (int j = 0; j < stacks.size(); j++) {
            if (ingredient.test(stacks.get(j))) {
                matchesMap.computeIfAbsent(j, k -> new ArrayList<>()).add(i);
                ;
                noMatch = false;
            }
        }
        if (noMatch) {
            // one ingredient had no match recipe does not match at all
            return false;
        }
    }
    if (matchesMap.isEmpty()) {
        return false;
    }
    // Every ingredient had at least one matching stack
    // Now check if each stack matches one ingredient
    final List<Collection<Integer>> stackList = new ArrayList<>(matchesMap.values());
    stackList.sort(Comparator.comparingInt(Collection::size));
    return SpongeShapelessRecipe.matchesRecursive(stackList, 0, new HashSet<>());
}
Also used : SpongeIngredient(org.spongepowered.common.item.recipe.ingredient.SpongeIngredient) ResourceLocation(net.minecraft.resources.ResourceLocation) Collection(java.util.Collection) Set(java.util.Set) HashMap(java.util.HashMap) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Ingredient(net.minecraft.world.item.crafting.Ingredient) HashSet(java.util.HashSet) List(java.util.List) CraftingContainer(net.minecraft.world.inventory.CraftingContainer) ShapelessRecipe(net.minecraft.world.item.crafting.ShapelessRecipe) Map(java.util.Map) NonNullList(net.minecraft.core.NonNullList) ItemStack(net.minecraft.world.item.ItemStack) Comparator(java.util.Comparator) Level(net.minecraft.world.level.Level) HashMap(java.util.HashMap) SpongeIngredient(org.spongepowered.common.item.recipe.ingredient.SpongeIngredient) Ingredient(net.minecraft.world.item.crafting.Ingredient) ArrayList(java.util.ArrayList) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) NonNullList(net.minecraft.core.NonNullList)

Example 79 with ItemStack

use of net.minecraft.world.item.ItemStack in project SpongeCommon by SpongePowered.

the class SpongeCampfireCookingRecipe method assemble.

@Override
public ItemStack assemble(final Container container) {
    if (this.resultFunction != null) {
        final ItemStack result = this.resultFunction.apply(container);
        result.setCount(1);
        return result;
    }
    return super.assemble(container);
}
Also used : ItemStack(net.minecraft.world.item.ItemStack)

Example 80 with ItemStack

use of net.minecraft.world.item.ItemStack in project SpongeCommon by SpongePowered.

the class SpongeBlastingRecipe method assemble.

@Override
public ItemStack assemble(final Container container) {
    if (this.resultFunction != null) {
        final ItemStack result = this.resultFunction.apply(container);
        result.setCount(1);
        return result;
    }
    return super.assemble(container);
}
Also used : ItemStack(net.minecraft.world.item.ItemStack)

Aggregations

ItemStack (net.minecraft.world.item.ItemStack)178 Level (net.minecraft.world.level.Level)62 ItemEntity (net.minecraft.world.entity.item.ItemEntity)61 InteractionHand (net.minecraft.world.InteractionHand)58 Player (net.minecraft.world.entity.player.Player)57 Items (net.minecraft.world.item.Items)55 InvocationTargetException (java.lang.reflect.InvocationTargetException)54 InteractionResult (net.minecraft.world.InteractionResult)54 EntitySize (de.Keyle.MyPet.api.entity.EntitySize)52 MyPet (de.Keyle.MyPet.api.entity.MyPet)52 EntityDataAccessor (net.minecraft.network.syncher.EntityDataAccessor)44 EntityDataSerializers (net.minecraft.network.syncher.EntityDataSerializers)44 SynchedEntityData (net.minecraft.network.syncher.SynchedEntityData)44 ServerLevel (net.minecraft.server.level.ServerLevel)44 MyPetApi (de.Keyle.MyPet.MyPetApi)40 Pair (com.mojang.datafixers.util.Pair)39 Bukkit (org.bukkit.Bukkit)39 CraftItemStack (org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack)39 CraftItemStack (org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack)39 Util (de.Keyle.MyPet.api.Util)38