Search in sources :

Example 1 with BrewModifier

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);
}
Also used : ArrayList(java.util.ArrayList) BrewModifier(com.witchworks.api.recipe.BrewModifier) Item(net.minecraft.item.Item) EntityItem(net.minecraft.entity.item.EntityItem) IFluidHandlerItem(net.minecraftforge.fluids.capability.IFluidHandlerItem) ItemValidator(com.witchworks.api.recipe.ItemValidator) ItemStack(net.minecraft.item.ItemStack) Nullable(javax.annotation.Nullable)

Aggregations

BrewModifier (com.witchworks.api.recipe.BrewModifier)1 ItemValidator (com.witchworks.api.recipe.ItemValidator)1 ArrayList (java.util.ArrayList)1 Nullable (javax.annotation.Nullable)1 EntityItem (net.minecraft.entity.item.EntityItem)1 Item (net.minecraft.item.Item)1 ItemStack (net.minecraft.item.ItemStack)1 IFluidHandlerItem (net.minecraftforge.fluids.capability.IFluidHandlerItem)1