Search in sources :

Example 11 with IRotate

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

the class EncasedCogInstance method init.

@Override
public void init() {
    rotatingModel = setup(getCogModel().createInstance());
    Block block = blockState.getBlock();
    if (!(block instanceof IRotate))
        return;
    IRotate def = (IRotate) block;
    rotatingTopShaft = Optional.empty();
    rotatingBottomShaft = Optional.empty();
    for (Direction d : Iterate.directionsInAxis(axis)) {
        if (!def.hasShaftTowards(blockEntity.getLevel(), blockEntity.getBlockPos(), blockState, d))
            continue;
        RotatingData data = setup(getRotatingMaterial().getModel(AllBlockPartials.SHAFT_HALF, blockState, d).createInstance());
        if (d.getAxisDirection() == AxisDirection.POSITIVE)
            rotatingTopShaft = Optional.of(data);
        else
            rotatingBottomShaft = Optional.of(data);
    }
}
Also used : IRotate(com.simibubi.create.content.contraptions.base.IRotate) Block(net.minecraft.world.level.block.Block) Direction(net.minecraft.core.Direction) AxisDirection(net.minecraft.core.Direction.AxisDirection) RotatingData(com.simibubi.create.content.contraptions.base.flwdata.RotatingData)

Example 12 with IRotate

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

the class GaugeBlock method getStateForPlacement.

@Override
public BlockState getStateForPlacement(BlockPlaceContext context) {
    Level world = context.getLevel();
    Direction face = context.getClickedFace();
    BlockPos placedOnPos = context.getClickedPos().relative(context.getClickedFace().getOpposite());
    BlockState placedOnState = world.getBlockState(placedOnPos);
    Block block = placedOnState.getBlock();
    if (block instanceof IRotate && ((IRotate) block).hasShaftTowards(world, placedOnPos, placedOnState, face)) {
        BlockState toPlace = defaultBlockState();
        Direction horizontalFacing = context.getHorizontalDirection();
        Direction nearestLookingDirection = context.getNearestLookingDirection();
        boolean lookPositive = nearestLookingDirection.getAxisDirection() == AxisDirection.POSITIVE;
        if (face.getAxis() == Axis.X) {
            toPlace = toPlace.setValue(FACING, lookPositive ? Direction.NORTH : Direction.SOUTH).setValue(AXIS_ALONG_FIRST_COORDINATE, true);
        } else if (face.getAxis() == Axis.Y) {
            toPlace = toPlace.setValue(FACING, horizontalFacing.getOpposite()).setValue(AXIS_ALONG_FIRST_COORDINATE, horizontalFacing.getAxis() == Axis.X);
        } else {
            toPlace = toPlace.setValue(FACING, lookPositive ? Direction.WEST : Direction.EAST).setValue(AXIS_ALONG_FIRST_COORDINATE, false);
        }
        return toPlace;
    }
    return super.getStateForPlacement(context);
}
Also used : IRotate(com.simibubi.create.content.contraptions.base.IRotate) BlockState(net.minecraft.world.level.block.state.BlockState) DirectionalAxisKineticBlock(com.simibubi.create.content.contraptions.base.DirectionalAxisKineticBlock) Block(net.minecraft.world.level.block.Block) Level(net.minecraft.world.level.Level) BlockPos(net.minecraft.core.BlockPos) Direction(net.minecraft.core.Direction) AxisDirection(net.minecraft.core.Direction.AxisDirection)

Example 13 with IRotate

use of com.simibubi.create.content.contraptions.base.IRotate 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 14 with IRotate

use of com.simibubi.create.content.contraptions.base.IRotate 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)

Example 15 with IRotate

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

the class AbstractPulleyRenderer method renderSafe.

@Override
protected void renderSafe(KineticTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light, int overlay) {
    if (Backend.canUseInstancing(te.getLevel()))
        return;
    super.renderSafe(te, partialTicks, ms, buffer, light, overlay);
    float offset = getOffset(te, partialTicks);
    boolean running = isRunning(te);
    Axis rotationAxis = ((IRotate) te.getBlockState().getBlock()).getRotationAxis(te.getBlockState());
    kineticRotationTransform(getRotatedCoil(te), te, rotationAxis, AngleHelper.rad(offset * 180), light).renderInto(ms, buffer.getBuffer(RenderType.solid()));
    Level world = te.getLevel();
    BlockState blockState = te.getBlockState();
    BlockPos pos = te.getBlockPos();
    SuperByteBuffer halfMagnet = CachedBufferer.partial(this.halfMagnet, blockState);
    SuperByteBuffer halfRope = CachedBufferer.partial(this.halfRope, blockState);
    SuperByteBuffer magnet = renderMagnet(te);
    SuperByteBuffer rope = renderRope(te);
    VertexConsumer vb = buffer.getBuffer(RenderType.solid());
    if (running || offset == 0)
        renderAt(world, offset > .25f ? magnet : halfMagnet, offset, pos, ms, vb);
    float f = offset % 1;
    if (offset > .75f && (f < .25f || f > .75f))
        renderAt(world, halfRope, f > .75f ? f - 1 : f, pos, ms, vb);
    if (!running)
        return;
    for (int i = 0; i < offset - 1.25f; i++) renderAt(world, rope, offset - i - 1, pos, ms, vb);
}
Also used : IRotate(com.simibubi.create.content.contraptions.base.IRotate) BlockState(net.minecraft.world.level.block.state.BlockState) SuperByteBuffer(com.simibubi.create.foundation.render.SuperByteBuffer) Level(net.minecraft.world.level.Level) BlockPos(net.minecraft.core.BlockPos) VertexConsumer(com.mojang.blaze3d.vertex.VertexConsumer) Axis(net.minecraft.core.Direction.Axis)

Aggregations

IRotate (com.simibubi.create.content.contraptions.base.IRotate)21 BlockState (net.minecraft.world.level.block.state.BlockState)12 Direction (net.minecraft.core.Direction)10 BlockPos (net.minecraft.core.BlockPos)9 Axis (net.minecraft.core.Direction.Axis)9 Block (net.minecraft.world.level.block.Block)6 AxisDirection (net.minecraft.core.Direction.AxisDirection)4 Level (net.minecraft.world.level.Level)4 KineticTileEntity (com.simibubi.create.content.contraptions.base.KineticTileEntity)3 SuperByteBuffer (com.simibubi.create.foundation.render.SuperByteBuffer)3 VertexConsumer (com.mojang.blaze3d.vertex.VertexConsumer)2 SpeedControllerBlock (com.simibubi.create.content.contraptions.relays.advanced.SpeedControllerBlock)2 CogWheelBlock (com.simibubi.create.content.contraptions.relays.elementary.CogWheelBlock)2 EncasedBeltBlock (com.simibubi.create.content.contraptions.relays.encased.EncasedBeltBlock)2 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 BlockState (net.minecraft.block.BlockState)2 Component (net.minecraft.network.chat.Component)2 TextComponent (net.minecraft.network.chat.TextComponent)2 Direction (net.minecraft.util.Direction)2