use of vazkii.psi.api.exosuit.IExosuitSensor in project Materialis by RCXcrafter.
the class SensorModifierRecipe 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 sensor information
if (enabled) {
for (int i = 0; i < inv.getInputCount(); i++) {
Item item = inv.getInput(i).getItem();
if (item instanceof IExosuitSensor) {
persistentData.put(PsionizingRadiationModifierSensor.SENSOR, inv.getInput(i).serializeNBT());
break;
}
}
}
return ValidatedResult.success(tool.createStack());
}
use of vazkii.psi.api.exosuit.IExosuitSensor in project Materialis by RCXcrafter.
the class ExosuitModelArmorItem method getColor.
@Override
@OnlyIn(Dist.CLIENT)
public int getColor(@Nonnull ItemStack stack) {
ItemStack sensor = ItemStack.of(ToolStack.copyFrom(stack).getVolatileData().getCompound(PsionizingRadiationModifierSensor.SENSOR));
if (!sensor.isEmpty() && sensor.getItem() instanceof IExosuitSensor) {
return ((IExosuitSensor) sensor.getItem()).getColor(sensor);
}
sensor = ItemStack.of(ToolStack.copyFrom(stack).getPersistentData().getCompound(PsionizingRadiationModifierSensor.SENSOR));
if (!sensor.isEmpty() && sensor.getItem() instanceof IExosuitSensor) {
return ((IExosuitSensor) sensor.getItem()).getColor(sensor);
}
return 0x82190A;
}
use of vazkii.psi.api.exosuit.IExosuitSensor in project Materialis by RCXcrafter.
the class PsionizingRadiationModifierSensor method onPsiArmorEvent.
public void onPsiArmorEvent(PsiArmorEvent event) {
if (!event.getPlayer().isSpectator()) {
for (int i = 0; i < 4; i++) {
ItemStack armor = event.getPlayer().inventory.armor.get(i);
ToolStack armorTool = ToolStack.copyFrom(armor);
if (armorTool.getDefinition() != ToolDefinition.EMPTY && !armorTool.isBroken() && armorTool.getModifierLevel(this) > 0 && armorTool.getPersistentData().contains(SENSOR, NBT.TAG_COMPOUND) && !armorTool.getVolatileData().getBoolean(PsionizingRadiationModifier.SUPPRESS_TOOLCASTING)) {
ItemStack sensor = ItemStack.of(armorTool.getPersistentData().getCompound(PsionizingRadiationModifierSensor.SENSOR));
if (sensor.isEmpty() || !(sensor.getItem() instanceof IExosuitSensor) || !((IExosuitSensor) sensor.getItem()).getEventType(sensor).equals(event.type)) {
return;
}
PlayerData data = PlayerDataHandler.get(event.getPlayer());
ItemStack playerCad = PsiAPI.getPlayerCAD(event.getPlayer());
if (!playerCad.isEmpty()) {
int timesCast = armorTool.getPersistentData().getInt(TinkerToolSocketable.TIMES_CAST);
ItemStack bullet = ISocketable.socketable(armor).getSelectedBullet();
ItemCAD.cast(event.getPlayer().getCommandSenderWorld(), event.getPlayer(), data, bullet, playerCad, 5, 0, 0.025F, (SpellContext spellContext) -> {
spellContext.tool = armor;
spellContext.loopcastIndex = timesCast;
});
armorTool.getPersistentData().putInt(TinkerToolSocketable.TIMES_CAST, timesCast + 1);
}
}
}
}
}
Aggregations