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