use of com.witchworks.api.recipe.BrewModifier in project Witchworks by Um-Mitternacht.
the class TileKettle method getBrewData.
@Nullable
public NBTTagCompound getBrewData() {
final Map<Item, ItemValidator<Object>> brewEffect = KettleRegistry.getBrewEffect();
final Map<Item, ItemValidator<BrewModifier>> brewModifier = KettleRegistry.getBrewModifier();
List<Object> effects = new ArrayList<>();
for (int i = 0; i < ingredients.length; i++) {
ItemStack ingredient = ingredients[i];
if (ingredient.isEmpty())
break;
Item effect = ingredient.getItem();
boolean add = true;
if (!brewEffect.containsKey(effect)) {
failHorribly();
return null;
}
ItemValidator<Object> validator = brewEffect.get(effect);
Optional<Object> optional = validator.getMatchFor(ingredient);
if (!optional.isPresent()) {
failHorribly();
return null;
}
Object brew = copyBrew(optional.get());
if (i + 1 < ingredients.length) {
while (i + 1 < ingredients.length) {
ItemStack modifier = ingredients[i + 1];
if (!brewModifier.containsKey(modifier.getItem())) {
if (brewEffect.containsKey(modifier.getItem()) || modifier.isEmpty())
break;
failHorribly();
return null;
}
ItemValidator<BrewModifier> val = brewModifier.get(modifier.getItem());
Optional<BrewModifier> opt = val.getMatchFor(modifier);
if (opt.isPresent()) {
for (int j = 0, size = modifier.getCount(); j < size; j++) {
add = opt.get().apply(effects, brew);
}
} else {
failHorribly();
return null;
}
++i;
}
}
if (add)
effects.add(brew);
}
return BrewUtils.serialize(effects);
}
Aggregations