Search in sources :

Example 1 with IExosuitSensor

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());
}
Also used : Item(net.minecraft.item.Item) ModDataNBT(slimeknights.tconstruct.library.tools.nbt.ModDataNBT) SlotCount(slimeknights.tconstruct.library.tools.SlotType.SlotCount) ValidatedResult(slimeknights.tconstruct.library.recipe.tinkerstation.ValidatedResult) IExosuitSensor(vazkii.psi.api.exosuit.IExosuitSensor) ToolStack(slimeknights.tconstruct.library.tools.nbt.ToolStack) Modifier(slimeknights.tconstruct.library.modifiers.Modifier)

Example 2 with IExosuitSensor

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;
}
Also used : ItemStack(net.minecraft.item.ItemStack) IExosuitSensor(vazkii.psi.api.exosuit.IExosuitSensor) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn)

Example 3 with IExosuitSensor

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);
                }
            }
        }
    }
}
Also used : SpellContext(vazkii.psi.api.spell.SpellContext) ItemStack(net.minecraft.item.ItemStack) IExosuitSensor(vazkii.psi.api.exosuit.IExosuitSensor) IModifierToolStack(slimeknights.tconstruct.library.tools.nbt.IModifierToolStack) ToolStack(slimeknights.tconstruct.library.tools.nbt.ToolStack) PlayerData(vazkii.psi.common.core.handler.PlayerDataHandler.PlayerData)

Aggregations

IExosuitSensor (vazkii.psi.api.exosuit.IExosuitSensor)3 ItemStack (net.minecraft.item.ItemStack)2 ToolStack (slimeknights.tconstruct.library.tools.nbt.ToolStack)2 Item (net.minecraft.item.Item)1 OnlyIn (net.minecraftforge.api.distmarker.OnlyIn)1 Modifier (slimeknights.tconstruct.library.modifiers.Modifier)1 ValidatedResult (slimeknights.tconstruct.library.recipe.tinkerstation.ValidatedResult)1 SlotCount (slimeknights.tconstruct.library.tools.SlotType.SlotCount)1 IModifierToolStack (slimeknights.tconstruct.library.tools.nbt.IModifierToolStack)1 ModDataNBT (slimeknights.tconstruct.library.tools.nbt.ModDataNBT)1 SpellContext (vazkii.psi.api.spell.SpellContext)1 PlayerData (vazkii.psi.common.core.handler.PlayerDataHandler.PlayerData)1