Search in sources :

Example 11 with KineticTileEntity

use of com.simibubi.create.content.contraptions.base.KineticTileEntity in project Create_Aeronautics by Eriksonnaren.

the class TorsionSpringTileEntity method setSource.

public void setSource(BlockPos source) {
    super.setSource(source);
    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 : SplitShaftTileEntity(com.simibubi.create.content.contraptions.relays.encased.SplitShaftTileEntity) KineticTileEntity(com.simibubi.create.content.contraptions.base.KineticTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) KineticTileEntity(com.simibubi.create.content.contraptions.base.KineticTileEntity)

Example 12 with KineticTileEntity

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

the class RotationPropagator method handleRemoved.

/**
 * Remove the given entity from the network.
 *
 * @param worldIn
 * @param pos
 * @param removedTE
 */
public static void handleRemoved(Level worldIn, BlockPos pos, KineticTileEntity removedTE) {
    if (worldIn.isClientSide)
        return;
    if (removedTE == null)
        return;
    if (removedTE.getTheoreticalSpeed() == 0)
        return;
    for (BlockPos neighbourPos : getPotentialNeighbourLocations(removedTE)) {
        BlockState neighbourState = worldIn.getBlockState(neighbourPos);
        if (!(neighbourState.getBlock() instanceof IRotate))
            continue;
        BlockEntity tileEntity = worldIn.getBlockEntity(neighbourPos);
        if (!(tileEntity instanceof KineticTileEntity))
            continue;
        final KineticTileEntity neighbourTE = (KineticTileEntity) tileEntity;
        if (!neighbourTE.hasSource() || !neighbourTE.source.equals(pos))
            continue;
        propagateMissingSource(neighbourTE);
    }
}
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) BlockPos(net.minecraft.core.BlockPos) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 13 with KineticTileEntity

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

the class RotationPropagator method propagateMissingSource.

/**
 * Clear the entire subnetwork depending on the given entity and find a new
 * source
 *
 * @param updateTE
 */
private static void propagateMissingSource(KineticTileEntity updateTE) {
    final Level world = updateTE.getLevel();
    List<KineticTileEntity> potentialNewSources = new LinkedList<>();
    List<BlockPos> frontier = new LinkedList<>();
    frontier.add(updateTE.getBlockPos());
    BlockPos missingSource = updateTE.hasSource() ? updateTE.source : null;
    while (!frontier.isEmpty()) {
        final BlockPos pos = frontier.remove(0);
        BlockEntity tileEntity = world.getBlockEntity(pos);
        if (!(tileEntity instanceof KineticTileEntity))
            continue;
        final KineticTileEntity currentTE = (KineticTileEntity) tileEntity;
        currentTE.removeSource();
        currentTE.sendData();
        for (KineticTileEntity neighbourTE : getConnectedNeighbours(currentTE)) {
            if (neighbourTE.getBlockPos().equals(missingSource))
                continue;
            if (!neighbourTE.hasSource())
                continue;
            if (!neighbourTE.source.equals(pos)) {
                potentialNewSources.add(neighbourTE);
                continue;
            }
            if (neighbourTE.isSource())
                potentialNewSources.add(neighbourTE);
            frontier.add(neighbourTE.getBlockPos());
        }
    }
    for (KineticTileEntity newSource : potentialNewSources) {
        if (newSource.hasSource() || newSource.isSource()) {
            propagateNewSource(newSource);
            return;
        }
    }
}
Also used : KineticTileEntity(com.simibubi.create.content.contraptions.base.KineticTileEntity) Level(net.minecraft.world.level.Level) BlockPos(net.minecraft.core.BlockPos) LinkedList(java.util.LinkedList) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 14 with KineticTileEntity

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

the class RotationPropagator method getConnectedNeighbours.

private static List<KineticTileEntity> getConnectedNeighbours(KineticTileEntity te) {
    List<KineticTileEntity> neighbours = new LinkedList<>();
    for (BlockPos neighbourPos : getPotentialNeighbourLocations(te)) {
        final KineticTileEntity neighbourTE = findConnectedNeighbour(te, neighbourPos);
        if (neighbourTE == null)
            continue;
        neighbours.add(neighbourTE);
    }
    return neighbours;
}
Also used : KineticTileEntity(com.simibubi.create.content.contraptions.base.KineticTileEntity) BlockPos(net.minecraft.core.BlockPos) LinkedList(java.util.LinkedList)

Example 15 with KineticTileEntity

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

the class KineticDebugger method tick.

public static void tick() {
    if (!isActive()) {
        if (KineticTileEntityRenderer.rainbowMode) {
            KineticTileEntityRenderer.rainbowMode = false;
            CreateClient.BUFFER_CACHE.invalidate();
        }
        return;
    }
    KineticTileEntity te = getSelectedTE();
    if (te == null)
        return;
    Level world = Minecraft.getInstance().level;
    BlockPos toOutline = te.hasSource() ? te.source : te.getBlockPos();
    BlockState state = te.getBlockState();
    VoxelShape shape = world.getBlockState(toOutline).getBlockSupportShape(world, toOutline);
    if (te.getTheoreticalSpeed() != 0 && !shape.isEmpty())
        CreateClient.OUTLINER.chaseAABB("kineticSource", shape.bounds().move(toOutline)).lineWidth(1 / 16f).colored(te.hasSource() ? Color.generateFromLong(te.network).getRGB() : 0xffcc00);
    if (state.getBlock() instanceof IRotate) {
        Axis axis = ((IRotate) state.getBlock()).getRotationAxis(state);
        Vec3 vec = Vec3.atLowerCornerOf(Direction.get(AxisDirection.POSITIVE, axis).getNormal());
        Vec3 center = VecHelper.getCenterOf(te.getBlockPos());
        CreateClient.OUTLINER.showLine("rotationAxis", center.add(vec), center.subtract(vec)).lineWidth(1 / 16f);
    }
}
Also used : IRotate(com.simibubi.create.content.contraptions.base.IRotate) BlockState(net.minecraft.world.level.block.state.BlockState) VoxelShape(net.minecraft.world.phys.shapes.VoxelShape) KineticTileEntity(com.simibubi.create.content.contraptions.base.KineticTileEntity) Vec3(net.minecraft.world.phys.Vec3) ClientLevel(net.minecraft.client.multiplayer.ClientLevel) Level(net.minecraft.world.level.Level) BlockPos(net.minecraft.core.BlockPos) Axis(net.minecraft.core.Direction.Axis)

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