Search in sources :

Example 16 with IRotate

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

the class EncasedCogRenderer method renderSafe.

@Override
protected void renderSafe(KineticTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light, int overlay) {
    super.renderSafe(te, partialTicks, ms, buffer, light, overlay);
    if (Backend.canUseInstancing(te.getLevel()))
        return;
    BlockState blockState = te.getBlockState();
    Block block = blockState.getBlock();
    if (!(block instanceof IRotate))
        return;
    IRotate def = (IRotate) block;
    for (Direction d : Iterate.directionsInAxis(getRotationAxisOf(te))) {
        if (!def.hasShaftTowards(te.getLevel(), te.getBlockPos(), blockState, d))
            continue;
        renderRotatingBuffer(te, CachedBufferer.partialFacing(AllBlockPartials.SHAFT_HALF, te.getBlockState(), d), ms, buffer.getBuffer(RenderType.solid()), light);
    }
}
Also used : IRotate(com.simibubi.create.content.contraptions.base.IRotate) BlockState(net.minecraft.world.level.block.state.BlockState) Block(net.minecraft.world.level.block.Block) Direction(net.minecraft.core.Direction) AxisDirection(net.minecraft.core.Direction.AxisDirection)

Example 17 with IRotate

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

the class SplitShaftInstance method update.

@Override
public void update() {
    Block block = blockState.getBlock();
    final Direction.Axis boxAxis = ((IRotate) block).getRotationAxis(blockState);
    Direction[] directions = Iterate.directionsInAxis(boxAxis);
    for (int i : Iterate.zeroAndOne) {
        updateRotation(keys.get(i), blockEntity.getSpeed() * blockEntity.getRotationSpeedModifier(directions[i]));
    }
}
Also used : IRotate(com.simibubi.create.content.contraptions.base.IRotate) Block(net.minecraft.world.level.block.Block) Direction(net.minecraft.core.Direction)

Example 18 with IRotate

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

the class SplitShaftRenderer method renderSafe.

@Override
protected void renderSafe(KineticTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light, int overlay) {
    if (Backend.canUseInstancing(te.getLevel()))
        return;
    Block block = te.getBlockState().getBlock();
    final Axis boxAxis = ((IRotate) block).getRotationAxis(te.getBlockState());
    final BlockPos pos = te.getBlockPos();
    float time = AnimationTickHolder.getRenderTime(te.getLevel());
    for (Direction direction : Iterate.directions) {
        Axis axis = direction.getAxis();
        if (boxAxis != axis)
            continue;
        float offset = getRotationOffsetForPosition(te, pos, axis);
        float angle = (time * te.getSpeed() * 3f / 10) % 360;
        float modifier = 1;
        if (te instanceof SplitShaftTileEntity)
            modifier = ((SplitShaftTileEntity) te).getRotationSpeedModifier(direction);
        angle *= modifier;
        angle += offset;
        angle = angle / 180f * (float) Math.PI;
        SuperByteBuffer superByteBuffer = CachedBufferer.partialFacing(AllBlockPartials.SHAFT_HALF, te.getBlockState(), direction);
        kineticRotationTransform(superByteBuffer, te, axis, angle, light);
        superByteBuffer.renderInto(ms, buffer.getBuffer(RenderType.solid()));
    }
}
Also used : IRotate(com.simibubi.create.content.contraptions.base.IRotate) SuperByteBuffer(com.simibubi.create.foundation.render.SuperByteBuffer) Block(net.minecraft.world.level.block.Block) BlockPos(net.minecraft.core.BlockPos) Direction(net.minecraft.core.Direction) Axis(net.minecraft.core.Direction.Axis)

Example 19 with IRotate

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

the class DeployerRenderer method renderInContraption.

public static void renderInContraption(MovementContext context, VirtualRenderWorld renderWorld, ContraptionMatrices matrices, MultiBufferSource buffer) {
    VertexConsumer builder = buffer.getBuffer(RenderType.solid());
    BlockState blockState = context.state;
    Mode mode = NBTHelper.readEnum(context.tileData, "Mode", Mode.class);
    PartialModel handPose = getHandPose(mode);
    float speed = (float) context.getAnimationSpeed();
    if (context.contraption.stalled)
        speed = 0;
    SuperByteBuffer shaft = CachedBufferer.block(AllBlocks.SHAFT.getDefaultState());
    SuperByteBuffer pole = CachedBufferer.partial(AllBlockPartials.DEPLOYER_POLE, blockState);
    SuperByteBuffer hand = CachedBufferer.partial(handPose, blockState);
    double factor;
    if (context.contraption.stalled || context.position == null || context.data.contains("StationaryTimer")) {
        factor = Mth.sin(AnimationTickHolder.getRenderTime() * .5f) * .25f + .25f;
    } else {
        Vec3 center = VecHelper.getCenterOf(new BlockPos(context.position));
        double distance = context.position.distanceTo(center);
        double nextDistance = context.position.add(context.motion).distanceTo(center);
        factor = .5f - Mth.clamp(Mth.lerp(AnimationTickHolder.getPartialTicks(), distance, nextDistance), 0, 1);
    }
    Vec3 offset = Vec3.atLowerCornerOf(blockState.getValue(FACING).getNormal()).scale(factor);
    PoseStack m = matrices.getModel();
    m.pushPose();
    m.pushPose();
    Axis axis = Axis.Y;
    if (context.state.getBlock() instanceof IRotate) {
        IRotate def = (IRotate) context.state.getBlock();
        axis = def.getRotationAxis(context.state);
    }
    float time = AnimationTickHolder.getRenderTime(context.world) / 20;
    float angle = (time * speed) % 360;
    TransformStack.cast(m).centre().rotateY(axis == Axis.Z ? 90 : 0).rotateZ(axis.isHorizontal() ? 90 : 0).unCentre();
    shaft.transform(m);
    shaft.rotateCentered(Direction.get(AxisDirection.POSITIVE, Axis.Y), angle);
    m.popPose();
    m.translate(offset.x, offset.y, offset.z);
    pole.transform(m);
    hand.transform(m);
    transform(pole, blockState, true);
    transform(hand, blockState, false);
    shaft.light(matrices.getWorld(), ContraptionRenderDispatcher.getContraptionWorldLight(context, renderWorld)).renderInto(matrices.getViewProjection(), builder);
    pole.light(matrices.getWorld(), ContraptionRenderDispatcher.getContraptionWorldLight(context, renderWorld)).renderInto(matrices.getViewProjection(), builder);
    hand.light(matrices.getWorld(), ContraptionRenderDispatcher.getContraptionWorldLight(context, renderWorld)).renderInto(matrices.getViewProjection(), builder);
    m.popPose();
}
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) PoseStack(com.mojang.blaze3d.vertex.PoseStack) Mode(com.simibubi.create.content.contraptions.components.deployer.DeployerTileEntity.Mode) Vec3(net.minecraft.world.phys.Vec3) VertexConsumer(com.mojang.blaze3d.vertex.VertexConsumer) BlockPos(net.minecraft.core.BlockPos) PartialModel(com.jozufozu.flywheel.core.PartialModel) Axis(net.minecraft.core.Direction.Axis)

Example 20 with IRotate

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

the class ClientEvents method addToItemTooltip.

@SubscribeEvent
public static void addToItemTooltip(ItemTooltipEvent event) {
    if (!AllConfigs.CLIENT.tooltips.get())
        return;
    if (event.getPlayer() == null)
        return;
    ItemStack stack = event.getItemStack();
    String translationKey = stack.getItem().getDescriptionId(stack);
    if (translationKey.startsWith(ITEM_PREFIX) || translationKey.startsWith(BLOCK_PREFIX))
        if (TooltipHelper.hasTooltip(stack, event.getPlayer())) {
            List<Component> itemTooltip = event.getToolTip();
            List<Component> toolTip = new ArrayList<>();
            toolTip.add(itemTooltip.remove(0));
            TooltipHelper.getTooltip(stack).addInformation(toolTip);
            itemTooltip.addAll(0, toolTip);
        }
    if (stack.getItem() instanceof BlockItem) {
        BlockItem item = (BlockItem) stack.getItem();
        if (item.getBlock() instanceof IRotate || item.getBlock() instanceof EngineBlock) {
            List<Component> kineticStats = ItemDescription.getKineticStats(item.getBlock());
            if (!kineticStats.isEmpty()) {
                event.getToolTip().add(new TextComponent(""));
                event.getToolTip().addAll(kineticStats);
            }
        }
    }
    PonderTooltipHandler.addToTooltip(event.getToolTip(), stack);
    SequencedAssemblyRecipe.addToTooltip(event.getToolTip(), stack);
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) IRotate(com.simibubi.create.content.contraptions.base.IRotate) EngineBlock(com.simibubi.create.content.contraptions.components.flywheel.engine.EngineBlock) ModList(net.minecraftforge.fml.ModList) List(java.util.List) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.world.item.ItemStack) TextComponent(net.minecraft.network.chat.TextComponent) Component(net.minecraft.network.chat.Component) BlockItem(net.minecraft.world.item.BlockItem) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

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