use of net.minecraft.world.item.crafting.Ingredient in project MinecraftForge by MinecraftForge.
the class CompoundIngredient method getStackingIds.
@Override
@Nonnull
public IntList getStackingIds() {
boolean childrenNeedInvalidation = false;
for (Ingredient child : children) {
childrenNeedInvalidation |= child.checkInvalidation();
}
if (childrenNeedInvalidation || this.itemIds == null || checkInvalidation()) {
this.markValid();
this.itemIds = new IntArrayList();
for (Ingredient child : children) this.itemIds.addAll(child.getStackingIds());
this.itemIds.sort(IntComparators.NATURAL_COMPARATOR);
}
return this.itemIds;
}
use of net.minecraft.world.item.crafting.Ingredient in project MinecraftForge by MinecraftForge.
the class ForgeRecipeProvider method enhance.
private FinishedRecipe enhance(ShapedRecipeBuilder.Result vanilla) {
Map<Character, Ingredient> ingredients = getField(ShapedRecipeBuilder.Result.class, vanilla, 5);
boolean modified = false;
for (Character x : ingredients.keySet()) {
Ingredient ing = enhance(vanilla.getId(), ingredients.get(x));
if (ing != null) {
ingredients.put(x, ing);
modified = true;
}
}
return modified ? vanilla : null;
}
use of net.minecraft.world.item.crafting.Ingredient in project MinecraftForge by MinecraftForge.
the class ForgeRecipeProvider method enhance.
private FinishedRecipe enhance(ShapelessRecipeBuilder.Result vanilla) {
List<Ingredient> ingredients = getField(ShapelessRecipeBuilder.Result.class, vanilla, 4);
boolean modified = false;
for (int x = 0; x < ingredients.size(); x++) {
Ingredient ing = enhance(vanilla.getId(), ingredients.get(x));
if (ing != null) {
ingredients.set(x, ing);
modified = true;
}
}
return modified ? vanilla : null;
}
use of net.minecraft.world.item.crafting.Ingredient in project MinecraftForge by MinecraftForge.
the class CraftingHelper method getIngredient.
public static Ingredient getIngredient(JsonElement json) {
if (json == null || json.isJsonNull())
throw new JsonSyntaxException("Json cannot be null");
if (json.isJsonArray()) {
List<Ingredient> ingredients = Lists.newArrayList();
List<Ingredient> vanilla = Lists.newArrayList();
json.getAsJsonArray().forEach((ele) -> {
Ingredient ing = CraftingHelper.getIngredient(ele);
if (// Vanilla, Due to how we read it splits each itemstack, so we pull out to re-merge later
ing.getClass() == Ingredient.class)
vanilla.add(ing);
else
ingredients.add(ing);
});
if (!vanilla.isEmpty())
ingredients.add(Ingredient.merge(vanilla));
if (ingredients.size() == 0)
throw new JsonSyntaxException("Item array cannot be empty, at least one item must be defined");
if (ingredients.size() == 1)
return ingredients.get(0);
return new CompoundIngredient(ingredients);
}
if (!json.isJsonObject())
throw new JsonSyntaxException("Expcted ingredient to be a object or array of objects");
JsonObject obj = (JsonObject) json;
String type = GsonHelper.getAsString(obj, "type", "minecraft:item");
if (type.isEmpty())
throw new JsonSyntaxException("Ingredient type can not be an empty string");
IIngredientSerializer<?> serializer = ingredients.get(new ResourceLocation(type));
if (serializer == null)
throw new JsonSyntaxException("Unknown ingredient type: " + type);
return serializer.parse(obj);
}
use of net.minecraft.world.item.crafting.Ingredient in project MinecraftForge by MinecraftForge.
the class CompoundIngredient method getItems.
@Override
@Nonnull
public ItemStack[] getItems() {
if (stacks == null) {
List<ItemStack> tmp = Lists.newArrayList();
for (Ingredient child : children) Collections.addAll(tmp, child.getItems());
stacks = tmp.toArray(new ItemStack[tmp.size()]);
}
return stacks;
}
Aggregations