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);
}
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);
}
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<>());
}
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);
}
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);
}
Aggregations