Search in sources :

Example 6 with KineticTileEntity

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

the class KineticNetwork method calculateStress.

public float calculateStress() {
    float presentStress = 0;
    for (Iterator<KineticTileEntity> iterator = members.keySet().iterator(); iterator.hasNext(); ) {
        KineticTileEntity te = iterator.next();
        if (te.getLevel().getBlockEntity(te.getBlockPos()) != te) {
            iterator.remove();
            continue;
        }
        presentStress += getActualStressOf(te);
    }
    float newStress = presentStress + unloadedStress;
    return newStress;
}
Also used : KineticTileEntity(com.simibubi.create.content.contraptions.base.KineticTileEntity)

Example 7 with KineticTileEntity

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

the class KineticNetwork method calculateCapacity.

public float calculateCapacity() {
    float presentCapacity = 0;
    containsFlywheel = false;
    for (Iterator<KineticTileEntity> iterator = sources.keySet().iterator(); iterator.hasNext(); ) {
        KineticTileEntity te = iterator.next();
        if (te.getLevel().getBlockEntity(te.getBlockPos()) != te) {
            iterator.remove();
            continue;
        }
        containsFlywheel |= te instanceof FlywheelTileEntity;
        presentCapacity += getActualCapacityOf(te);
    }
    float newMaxStress = presentCapacity + unloadedCapacity;
    return newMaxStress;
}
Also used : KineticTileEntity(com.simibubi.create.content.contraptions.base.KineticTileEntity) FlywheelTileEntity(com.simibubi.create.content.contraptions.components.flywheel.FlywheelTileEntity)

Example 8 with KineticTileEntity

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

the class RotationPropagator method findConnectedNeighbour.

private static KineticTileEntity findConnectedNeighbour(KineticTileEntity currentTE, BlockPos neighbourPos) {
    BlockState neighbourState = currentTE.getLevel().getBlockState(neighbourPos);
    if (!(neighbourState.getBlock() instanceof IRotate))
        return null;
    if (!neighbourState.hasBlockEntity())
        return null;
    BlockEntity neighbourTE = currentTE.getLevel().getBlockEntity(neighbourPos);
    if (!(neighbourTE instanceof KineticTileEntity))
        return null;
    KineticTileEntity neighbourKTE = (KineticTileEntity) neighbourTE;
    if (!(neighbourKTE.getBlockState().getBlock() instanceof IRotate))
        return null;
    if (!isConnected(currentTE, neighbourKTE) && !isConnected(neighbourKTE, currentTE))
        return null;
    return neighbourKTE;
}
Also used : IRotate(com.simibubi.create.content.contraptions.base.IRotate) BlockState(net.minecraft.world.level.block.state.BlockState) KineticTileEntity(com.simibubi.create.content.contraptions.base.KineticTileEntity) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 9 with KineticTileEntity

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

the class RotationPropagator method propagateNewSource.

/**
 * Search for sourceless networks attached to the given entity and update them.
 *
 * @param currentTE
 */
private static void propagateNewSource(KineticTileEntity currentTE) {
    BlockPos pos = currentTE.getBlockPos();
    Level world = currentTE.getLevel();
    for (KineticTileEntity neighbourTE : getConnectedNeighbours(currentTE)) {
        float speedOfCurrent = currentTE.getTheoreticalSpeed();
        float speedOfNeighbour = neighbourTE.getTheoreticalSpeed();
        float newSpeed = getConveyedSpeed(currentTE, neighbourTE);
        float oppositeSpeed = getConveyedSpeed(neighbourTE, currentTE);
        if (newSpeed == 0 && oppositeSpeed == 0)
            continue;
        boolean incompatible = Math.signum(newSpeed) != Math.signum(speedOfNeighbour) && (newSpeed != 0 && speedOfNeighbour != 0);
        boolean tooFast = Math.abs(newSpeed) > AllConfigs.SERVER.kinetics.maxRotationSpeed.get();
        boolean speedChangedTooOften = currentTE.getFlickerScore() > MAX_FLICKER_SCORE;
        if (tooFast || speedChangedTooOften) {
            world.destroyBlock(pos, true);
            return;
        }
        // Opposite directions
        if (incompatible) {
            world.destroyBlock(pos, true);
            return;
        // Same direction: overpower the slower speed
        } else {
            // Neighbour faster, overpower the incoming tree
            if (Math.abs(oppositeSpeed) > Math.abs(speedOfCurrent)) {
                float prevSpeed = currentTE.getSpeed();
                currentTE.setSource(neighbourTE.getBlockPos());
                currentTE.setSpeed(getConveyedSpeed(neighbourTE, currentTE));
                currentTE.onSpeedChanged(prevSpeed);
                currentTE.sendData();
                propagateNewSource(currentTE);
                return;
            }
            // Current faster, overpower the neighbours' tree
            if (Math.abs(newSpeed) >= Math.abs(speedOfNeighbour)) {
                // Do not overpower you own network -> cycle
                if (!currentTE.hasNetwork() || currentTE.network.equals(neighbourTE.network)) {
                    float epsilon = Math.abs(speedOfNeighbour) / 256f / 256f;
                    if (Math.abs(newSpeed) > Math.abs(speedOfNeighbour) + epsilon)
                        world.destroyBlock(pos, true);
                    continue;
                }
                if (currentTE.hasSource() && currentTE.source.equals(neighbourTE.getBlockPos()))
                    currentTE.removeSource();
                float prevSpeed = neighbourTE.getSpeed();
                neighbourTE.setSource(currentTE.getBlockPos());
                neighbourTE.setSpeed(getConveyedSpeed(currentTE, neighbourTE));
                neighbourTE.onSpeedChanged(prevSpeed);
                neighbourTE.sendData();
                propagateNewSource(neighbourTE);
                continue;
            }
        }
        if (neighbourTE.getTheoreticalSpeed() == newSpeed)
            continue;
        float prevSpeed = neighbourTE.getSpeed();
        neighbourTE.setSpeed(newSpeed);
        neighbourTE.setSource(currentTE.getBlockPos());
        neighbourTE.onSpeedChanged(prevSpeed);
        neighbourTE.sendData();
        propagateNewSource(neighbourTE);
    }
}
Also used : KineticTileEntity(com.simibubi.create.content.contraptions.base.KineticTileEntity) BlockPos(net.minecraft.core.BlockPos) Level(net.minecraft.world.level.Level)

Example 10 with KineticTileEntity

use of com.simibubi.create.content.contraptions.base.KineticTileEntity in project Multiblocked by Low-Drag-MC.

the class CreateKineticSourceTileEntity method setSource.

public void setSource(BlockPos source) {
    super.setSource(source);
    if (!definition.isOutput)
        return;
    TileEntity tileEntity = this.level.getBlockEntity(source);
    if (tileEntity instanceof KineticTileEntity) {
        KineticTileEntity sourceTe = (KineticTileEntity) tileEntity;
        if (this.reActivateSource && Math.abs(sourceTe.getSpeed()) >= Math.abs(this.getGeneratedSpeed())) {
            this.reActivateSource = false;
        }
    }
}
Also used : KineticTileEntity(com.simibubi.create.content.contraptions.base.KineticTileEntity) ControllerTileEntity(com.lowdragmc.multiblocked.api.tile.ControllerTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) KineticTileEntity(com.simibubi.create.content.contraptions.base.KineticTileEntity)

Aggregations

KineticTileEntity (com.simibubi.create.content.contraptions.base.KineticTileEntity)23 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)11 BlockPos (net.minecraft.core.BlockPos)8 BlockState (net.minecraft.world.level.block.state.BlockState)7 Level (net.minecraft.world.level.Level)5 IRotate (com.simibubi.create.content.contraptions.base.IRotate)4 TileEntity (net.minecraft.tileentity.TileEntity)4 SplitShaftTileEntity (com.simibubi.create.content.contraptions.relays.encased.SplitShaftTileEntity)3 Iterator (java.util.Iterator)3 Axis (net.minecraft.core.Direction.Axis)3 LinkedList (java.util.LinkedList)2 ClientLevel (net.minecraft.client.multiplayer.ClientLevel)2 Direction (net.minecraft.core.Direction)2 BlockPos (net.minecraft.util.math.BlockPos)2 Vec3 (net.minecraft.world.phys.Vec3)2 ControllerTileEntity (com.lowdragmc.multiblocked.api.tile.ControllerTileEntity)1 AllBlocks (com.simibubi.create.AllBlocks)1 AllInteractionBehaviours (com.simibubi.create.AllInteractionBehaviours)1 AllMovementBehaviours (com.simibubi.create.AllMovementBehaviours)1 SeatBlock (com.simibubi.create.content.contraptions.components.actors.SeatBlock)1