Search in sources :

Example 1 with SpeedLevel

use of com.simibubi.create.content.contraptions.base.IRotate.SpeedLevel in project Create by Creators-of-Create.

the class KineticEffectHandler method spawnRotationIndicators.

public void spawnRotationIndicators() {
    float speed = kte.getSpeed();
    if (speed == 0)
        return;
    BlockState state = kte.getBlockState();
    Block block = state.getBlock();
    if (!(block instanceof KineticBlock))
        return;
    KineticBlock kb = (KineticBlock) block;
    float radius1 = kb.getParticleInitialRadius();
    float radius2 = kb.getParticleTargetRadius();
    Axis axis = kb.getRotationAxis(state);
    BlockPos pos = kte.getBlockPos();
    Level world = kte.getLevel();
    if (axis == null)
        return;
    if (world == null)
        return;
    char axisChar = axis.name().charAt(0);
    Vec3 vec = VecHelper.getCenterOf(pos);
    SpeedLevel speedLevel = SpeedLevel.of(speed);
    int color = speedLevel.getColor();
    int particleSpeed = speedLevel.getParticleSpeed();
    particleSpeed *= Math.signum(speed);
    if (world instanceof ServerLevel) {
        AllTriggers.triggerForNearbyPlayers(AllTriggers.ROTATION, world, pos, 5);
        RotationIndicatorParticleData particleData = new RotationIndicatorParticleData(color, particleSpeed, radius1, radius2, 10, axisChar);
        ((ServerLevel) world).sendParticles(particleData, vec.x, vec.y, vec.z, 20, 0, 0, 0, 1);
    }
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) SpeedLevel(com.simibubi.create.content.contraptions.base.IRotate.SpeedLevel) BlockState(net.minecraft.world.level.block.state.BlockState) Vec3(net.minecraft.world.phys.Vec3) Block(net.minecraft.world.level.block.Block) BlockPos(net.minecraft.core.BlockPos) ServerLevel(net.minecraft.server.level.ServerLevel) SpeedLevel(com.simibubi.create.content.contraptions.base.IRotate.SpeedLevel) Level(net.minecraft.world.level.Level) Axis(net.minecraft.core.Direction.Axis) RotationIndicatorParticleData(com.simibubi.create.content.contraptions.particle.RotationIndicatorParticleData)

Example 2 with SpeedLevel

use of com.simibubi.create.content.contraptions.base.IRotate.SpeedLevel in project Create by Creators-of-Create.

the class GeneratingKineticTileEntity method updateGeneratedRotation.

public void updateGeneratedRotation() {
    float speed = getGeneratedSpeed();
    float prevSpeed = this.speed;
    if (level.isClientSide)
        return;
    if (prevSpeed != speed) {
        if (!hasSource()) {
            SpeedLevel levelBefore = SpeedLevel.of(this.speed);
            SpeedLevel levelafter = SpeedLevel.of(speed);
            if (levelBefore != levelafter)
                effects.queueRotationIndicators();
        }
        applyNewSpeed(prevSpeed, speed);
    }
    if (hasNetwork() && speed != 0) {
        KineticNetwork network = getOrCreateNetwork();
        notifyStressCapacityChange(calculateAddedStressCapacity());
        getOrCreateNetwork().updateStressFor(this, calculateStressApplied());
        network.updateStress();
    }
    onSpeedChanged(prevSpeed);
    sendData();
}
Also used : SpeedLevel(com.simibubi.create.content.contraptions.base.IRotate.SpeedLevel) KineticNetwork(com.simibubi.create.content.contraptions.KineticNetwork)

Example 3 with SpeedLevel

use of com.simibubi.create.content.contraptions.base.IRotate.SpeedLevel in project Create by Creators-of-Create.

the class ItemDescription method getKineticStats.

public static List<Component> getKineticStats(Block block) {
    List<Component> list = new ArrayList<>();
    CKinetics config = AllConfigs.SERVER.kinetics;
    Component rpmUnit = Lang.translate("generic.unit.rpm");
    boolean hasGoggles = AllItems.GOGGLES.isIn(Minecraft.getInstance().player.getItemBySlot(EquipmentSlot.HEAD));
    SpeedLevel minimumRequiredSpeedLevel;
    boolean showStressImpact;
    if (!(block instanceof IRotate)) {
        minimumRequiredSpeedLevel = SpeedLevel.NONE;
        showStressImpact = true;
    } else {
        minimumRequiredSpeedLevel = ((IRotate) block).getMinimumRequiredSpeedLevel();
        showStressImpact = !((IRotate) block).hideStressImpact();
    }
    boolean hasSpeedRequirement = minimumRequiredSpeedLevel != SpeedLevel.NONE;
    boolean hasStressImpact = StressImpact.isEnabled() && showStressImpact && BlockStressValues.getImpact(block) > 0;
    boolean hasStressCapacity = StressImpact.isEnabled() && BlockStressValues.hasCapacity(block);
    if (hasSpeedRequirement) {
        List<Component> speedLevels = Lang.translatedOptions("tooltip.speedRequirement", "none", "medium", "high");
        int index = minimumRequiredSpeedLevel.ordinal();
        MutableComponent level = new TextComponent(makeProgressBar(3, index)).withStyle(minimumRequiredSpeedLevel.getTextColor());
        if (hasGoggles)
            level.append(String.valueOf(minimumRequiredSpeedLevel.getSpeedValue())).append(rpmUnit).append("+");
        else
            level.append(speedLevels.get(index));
        list.add(Lang.translate("tooltip.speedRequirement").withStyle(GRAY));
        list.add(level);
    }
    if (hasStressImpact) {
        List<Component> stressLevels = Lang.translatedOptions("tooltip.stressImpact", "low", "medium", "high");
        double impact = BlockStressValues.getImpact(block);
        StressImpact impactId = impact >= config.highStressImpact.get() ? StressImpact.HIGH : (impact >= config.mediumStressImpact.get() ? StressImpact.MEDIUM : StressImpact.LOW);
        int index = impactId.ordinal();
        MutableComponent level = new TextComponent(makeProgressBar(3, index)).withStyle(impactId.getAbsoluteColor());
        if (hasGoggles)
            level.append(impact + "x ").append(rpmUnit);
        else
            level.append(stressLevels.get(index));
        list.add(Lang.translate("tooltip.stressImpact").withStyle(GRAY));
        list.add(level);
    }
    if (hasStressCapacity) {
        List<Component> stressCapacityLevels = Lang.translatedOptions("tooltip.capacityProvided", "low", "medium", "high");
        double capacity = BlockStressValues.getCapacity(block);
        StressImpact impactId = capacity >= config.highCapacity.get() ? StressImpact.LOW : (capacity >= config.mediumCapacity.get() ? StressImpact.MEDIUM : StressImpact.HIGH);
        int index = StressImpact.values().length - 2 - impactId.ordinal();
        MutableComponent level = new TextComponent(makeProgressBar(3, index)).withStyle(impactId.getAbsoluteColor());
        if (hasGoggles)
            level.append(capacity + "x ").append(rpmUnit);
        else
            level.append(stressCapacityLevels.get(index));
        // if (!isEngine && ((IRotate) block).showCapacityWithAnnotation())
        // level +=
        // " " + DARK_GRAY + TextFormatting.ITALIC + Lang.translate("tooltip.capacityProvided.asGenerator");
        list.add(Lang.translate("tooltip.capacityProvided").withStyle(GRAY));
        list.add(level);
        MutableComponent genSpeed = generatorSpeed(block, rpmUnit);
        if (!genSpeed.getString().isEmpty())
            list.add(new TextComponent(" ").append(genSpeed).withStyle(DARK_GRAY));
    }
    // add(linesOnShift, "");
    return list;
}
Also used : TooltipHelper.cutStringTextComponent(com.simibubi.create.foundation.item.TooltipHelper.cutStringTextComponent) TooltipHelper.cutTextComponent(com.simibubi.create.foundation.item.TooltipHelper.cutTextComponent) TextComponent(net.minecraft.network.chat.TextComponent) SpeedLevel(com.simibubi.create.content.contraptions.base.IRotate.SpeedLevel) IRotate(com.simibubi.create.content.contraptions.base.IRotate) MutableComponent(net.minecraft.network.chat.MutableComponent) CKinetics(com.simibubi.create.foundation.config.CKinetics) ArrayList(java.util.ArrayList) TooltipHelper.cutStringTextComponent(com.simibubi.create.foundation.item.TooltipHelper.cutStringTextComponent) TooltipHelper.cutTextComponent(com.simibubi.create.foundation.item.TooltipHelper.cutTextComponent) MutableComponent(net.minecraft.network.chat.MutableComponent) Component(net.minecraft.network.chat.Component) TextComponent(net.minecraft.network.chat.TextComponent) StressImpact(com.simibubi.create.content.contraptions.base.IRotate.StressImpact)

Example 4 with SpeedLevel

use of com.simibubi.create.content.contraptions.base.IRotate.SpeedLevel in project Create by Creators-of-Create.

the class KineticTileEntity method isSpeedRequirementFulfilled.

public boolean isSpeedRequirementFulfilled() {
    BlockState state = getBlockState();
    if (!(getBlockState().getBlock() instanceof IRotate))
        return true;
    IRotate def = (IRotate) state.getBlock();
    SpeedLevel minimumRequiredSpeedLevel = def.getMinimumRequiredSpeedLevel();
    if (minimumRequiredSpeedLevel == null)
        return true;
    if (minimumRequiredSpeedLevel == SpeedLevel.MEDIUM)
        return Math.abs(getSpeed()) >= AllConfigs.SERVER.kinetics.mediumSpeed.get();
    if (minimumRequiredSpeedLevel == SpeedLevel.FAST)
        return Math.abs(getSpeed()) >= AllConfigs.SERVER.kinetics.fastSpeed.get();
    return true;
}
Also used : SpeedLevel(com.simibubi.create.content.contraptions.base.IRotate.SpeedLevel) BlockState(net.minecraft.world.level.block.state.BlockState)

Aggregations

SpeedLevel (com.simibubi.create.content.contraptions.base.IRotate.SpeedLevel)4 BlockState (net.minecraft.world.level.block.state.BlockState)2 KineticNetwork (com.simibubi.create.content.contraptions.KineticNetwork)1 IRotate (com.simibubi.create.content.contraptions.base.IRotate)1 StressImpact (com.simibubi.create.content.contraptions.base.IRotate.StressImpact)1 RotationIndicatorParticleData (com.simibubi.create.content.contraptions.particle.RotationIndicatorParticleData)1 CKinetics (com.simibubi.create.foundation.config.CKinetics)1 TooltipHelper.cutStringTextComponent (com.simibubi.create.foundation.item.TooltipHelper.cutStringTextComponent)1 TooltipHelper.cutTextComponent (com.simibubi.create.foundation.item.TooltipHelper.cutTextComponent)1 ArrayList (java.util.ArrayList)1 BlockPos (net.minecraft.core.BlockPos)1 Axis (net.minecraft.core.Direction.Axis)1 Component (net.minecraft.network.chat.Component)1 MutableComponent (net.minecraft.network.chat.MutableComponent)1 TextComponent (net.minecraft.network.chat.TextComponent)1 ServerLevel (net.minecraft.server.level.ServerLevel)1 Level (net.minecraft.world.level.Level)1 Block (net.minecraft.world.level.block.Block)1 Vec3 (net.minecraft.world.phys.Vec3)1