Search in sources :

Example 1 with ICADColorizer

use of vazkii.psi.api.cad.ICADColorizer in project Materialis by RCXcrafter.

the class ColorizerModifierRecipe method getValidatedResult.

@Override
public ValidatedResult getValidatedResult(ITinkerStationInventory inv) {
    ToolStack tool = ToolStack.from(inv.getTinkerableStack());
    // if the tool has the modifier already, can skip most requirements
    Modifier modifier = result.getModifier();
    ValidatedResult commonError;
    boolean needsModifier;
    if (tool.getUpgrades().getLevel(modifier) == 0) {
        needsModifier = true;
        commonError = validatePrerequisites(tool);
    } else {
        needsModifier = false;
        commonError = validateRequirements(tool);
    }
    if (commonError.hasError()) {
        return commonError;
    }
    // consume slots
    tool = tool.copy();
    ModDataNBT persistentData = tool.getPersistentData();
    if (needsModifier) {
        SlotCount slots = getSlots();
        if (slots != null) {
            persistentData.addSlots(slots.getType(), -slots.getCount());
        }
    }
    // set the new value to the modifier
    persistentData.putString(modifier.getId(), value);
    // add modifier if needed
    if (needsModifier) {
        tool.addModifier(result.getModifier(), 1);
    } else {
        tool.rebuildStats();
    }
    // ensure no modifier problems
    ValidatedResult toolValidation = tool.validate();
    if (toolValidation.hasError()) {
        return toolValidation;
    }
    // add colorizer information
    if (enabled) {
        for (int i = 0; i < inv.getInputCount(); i++) {
            Item item = inv.getInput(i).getItem();
            if (item instanceof ICADColorizer) {
                persistentData.put(ColorizedModifier.COLORIZER, inv.getInput(i).serializeNBT());
                break;
            }
        }
    }
    return ValidatedResult.success(tool.createStack());
}
Also used : Item(net.minecraft.item.Item) ModDataNBT(slimeknights.tconstruct.library.tools.nbt.ModDataNBT) SlotCount(slimeknights.tconstruct.library.tools.SlotType.SlotCount) ICADColorizer(vazkii.psi.api.cad.ICADColorizer) ValidatedResult(slimeknights.tconstruct.library.recipe.tinkerstation.ValidatedResult) ToolStack(slimeknights.tconstruct.library.tools.nbt.ToolStack) ColorizedModifier(com.rcx.materialis.modifiers.ColorizedModifier) Modifier(slimeknights.tconstruct.library.modifiers.Modifier)

Aggregations

ColorizedModifier (com.rcx.materialis.modifiers.ColorizedModifier)1 Item (net.minecraft.item.Item)1 Modifier (slimeknights.tconstruct.library.modifiers.Modifier)1 ValidatedResult (slimeknights.tconstruct.library.recipe.tinkerstation.ValidatedResult)1 SlotCount (slimeknights.tconstruct.library.tools.SlotType.SlotCount)1 ModDataNBT (slimeknights.tconstruct.library.tools.nbt.ModDataNBT)1 ToolStack (slimeknights.tconstruct.library.tools.nbt.ToolStack)1 ICADColorizer (vazkii.psi.api.cad.ICADColorizer)1