Search in sources :

Example 1 with IntAttached

use of com.simibubi.create.foundation.utility.IntAttached in project Create by Creators-of-Create.

the class EjectorTileEntity method tick.

@Override
public void tick() {
    super.tick();
    boolean doLogic = !level.isClientSide || isVirtual();
    State prevState = state;
    float totalTime = Math.max(3, (float) launcher.getTotalFlyingTicks());
    if (scanCooldown > 0)
        scanCooldown--;
    if (launch) {
        launch = false;
        activateDeferred();
    }
    for (Iterator<IntAttached<ItemStack>> iterator = launchedItems.iterator(); iterator.hasNext(); ) {
        IntAttached<ItemStack> intAttached = iterator.next();
        boolean hit = false;
        if (intAttached.getSecond() == trackedItem)
            hit = scanTrajectoryForObstacles(intAttached.getFirst());
        float maxTime = earlyTarget != null ? Math.min(earlyTargetTime, totalTime) : totalTime;
        if (hit || intAttached.exceeds((int) maxTime)) {
            placeItemAtTarget(doLogic, maxTime, intAttached);
            iterator.remove();
        }
        intAttached.increment();
    }
    if (state == State.LAUNCHING) {
        lidProgress.chase(1, .8f, Chaser.EXP);
        lidProgress.tickChaser();
        if (lidProgress.getValue() > 1 - 1 / 16f && doLogic) {
            state = State.RETRACTING;
            lidProgress.setValue(1);
        }
    }
    if (state == State.CHARGED) {
        lidProgress.setValue(0);
        lidProgress.updateChaseSpeed(0);
        if (doLogic)
            ejectIfTriggered();
    }
    if (state == State.RETRACTING) {
        if (lidProgress.getChaseTarget() == 1 && !lidProgress.settled()) {
            lidProgress.tickChaser();
        } else {
            lidProgress.updateChaseTarget(0);
            lidProgress.updateChaseSpeed(0);
            if (lidProgress.getValue() == 0 && doLogic) {
                state = State.CHARGED;
                lidProgress.setValue(0);
                sendData();
            }
            float value = Mth.clamp(lidProgress.getValue() - getWindUpSpeed(), 0, 1);
            lidProgress.setValue(value);
            int soundRate = (int) (1 / (getWindUpSpeed() * 5)) + 1;
            float volume = .125f;
            float pitch = 1.5f - lidProgress.getValue();
            if (((int) level.getGameTime()) % soundRate == 0 && doLogic)
                level.playSound(null, worldPosition, SoundEvents.WOODEN_BUTTON_CLICK_OFF, SoundSource.BLOCKS, volume, pitch);
        }
    }
    if (state != prevState)
        notifyUpdate();
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) ItemStack(net.minecraft.world.item.ItemStack) TransportedItemStack(com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack) IntAttached(com.simibubi.create.foundation.utility.IntAttached)

Aggregations

TransportedItemStack (com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack)1 IntAttached (com.simibubi.create.foundation.utility.IntAttached)1 ItemStack (net.minecraft.world.item.ItemStack)1 BlockState (net.minecraft.world.level.block.state.BlockState)1