Search in sources :

Example 41 with MinecraftClient

use of net.minecraft.client.MinecraftClient in project ImmersivePortalsMod by qouteall.

the class OFInterfaceInitializer method init.

public static void init() {
    Validate.isTrue(OFInterface.isOptifinePresent);
    OFInterface.isShaders = Config::isShaders;
    OFInterface.isShadowPass = () -> Config.isShaders() && Shaders.isShadowPass;
    OFInterface.bindToShaderFrameBuffer = () -> {
        EXTFramebufferObject.glBindFramebufferEXT(36160, OFGlobal.getDfb.get());
        GlStateManager.viewport(0, 0, Shaders.renderWidth, Shaders.renderHeight);
    };
    OFInterface.beforeRenderCenter = (partialTicks) -> {
        if (Config.isShaders()) {
            MinecraftClient mc = MinecraftClient.getInstance();
            Shaders.activeProgram = Shaders.ProgramNone;
            Shaders.beginRender(mc, mc.gameRenderer.getCamera(), partialTicks, 0);
        }
    };
    OFInterface.afterRenderCenter = () -> Shaders.activeProgram = Shaders.ProgramNone;
    OFInterface.resetViewport = () -> {
        if (OFInterface.isShaders.getAsBoolean()) {
            GlStateManager.viewport(0, 0, Shaders.renderWidth, Shaders.renderHeight);
        }
    };
    OFInterface.onPlayerTraveled = (fromDimension1, toDimension1) -> {
        if (OFInterface.isShaders.getAsBoolean()) {
            OFGlobal.shaderContextManager.onPlayerTraveled(fromDimension1, toDimension1);
        }
    };
    OFInterface.shouldDisableFog = () -> {
        GameRenderer gameRenderer = MinecraftClient.getInstance().gameRenderer;
        if (gameRenderer_fogStandard == null) {
            try {
                gameRenderer_fogStandard = GameRenderer.class.getDeclaredField("fogStandard");
            } catch (NoSuchFieldException e) {
                throw new IllegalStateException(e);
            }
        }
        try {
            boolean fogStandard = gameRenderer_fogStandard.getBoolean(gameRenderer);
            return Config.isFogOff() && fogStandard;
        } catch (IllegalAccessException e) {
            throw new IllegalStateException(e);
        }
    };
    OFInterface.createNewRenderInfosNormal = newWorldRenderer1 -> {
        /**
         *{@link WorldRenderer#chunkInfos}
         */
        // in vanilla it will create new chunkInfos object every frame
        // but with optifine it will always use one object
        // we need to switch chunkInfos correctly
        // if we do not put it a new object, it will clear the original chunkInfos
        ((IEOFWorldRenderer) newWorldRenderer1).createNewRenderInfosNormal();
    };
    OFInterface.initShaderCullingManager = ShaderCullingManager::init;
}
Also used : Config(net.optifine.Config) IEOFWorldRenderer(com.qouteall.immersive_portals.IEOFWorldRenderer) MinecraftClient(net.minecraft.client.MinecraftClient) GameRenderer(net.minecraft.client.render.GameRenderer)

Example 42 with MinecraftClient

use of net.minecraft.client.MinecraftClient in project quilt-standard-libraries by QuiltMC.

the class ClientCommandInternals method executeCommand.

/**
 * Executes a client-sided command from a message.
 *
 * @param  message the command message
 *
 * @return {@code true} if the message was executed as a command client-side (and therefore should not be sent to the
 *         server), {@code false} otherwise
 */
public static boolean executeCommand(String message) {
    if (message.isEmpty()) {
        // Nothing to process
        return false;
    }
    if (message.charAt(0) != PREFIX) {
        // Incorrect prefix, won't execute anything.
        return false;
    }
    MinecraftClient client = MinecraftClient.getInstance();
    // The interface is implemented on ClientCommandSource with a mixin.
    // noinspection ConstantConditions
    QuiltClientCommandSource commandSource = (QuiltClientCommandSource) client.getNetworkHandler().getCommandSource();
    client.getProfiler().push(message);
    try {
        // Only run client commands if there are no matching server-side commands.
        String command = message.substring(1);
        CommandDispatcher<CommandSource> serverDispatcher = client.getNetworkHandler().getCommandDispatcher();
        ParseResults<CommandSource> serverResults = serverDispatcher.parse(command, client.getNetworkHandler().getCommandSource());
        if (serverResults.getReader().canRead() || isCommandInvalidOrDummy(serverResults)) {
            DISPATCHER.execute(command, commandSource);
            return true;
        } else {
            return false;
        }
    } catch (CommandSyntaxException e) {
        boolean ignored = shouldIgnore(e.getType());
        if (ignored) {
            LOGGER.debug("Syntax exception for client-side command '{}'", message, e);
        } else {
            LOGGER.warn("Syntax exception for client-side command '{}'", message, e);
        }
        if (ignored) {
            return false;
        }
        commandSource.sendError(getErrorMessage(e));
        return true;
    } catch (CommandException e) {
        LOGGER.warn("Error while executing client-side command '{}'", message, e);
        commandSource.sendError(e.getTextMessage());
        return true;
    } catch (RuntimeException e) {
        LOGGER.warn("Error while executing client-side command '{}'", message, e);
        commandSource.sendError(Text.of(e.getMessage()));
        return true;
    } finally {
        client.getProfiler().pop();
    }
}
Also used : QuiltClientCommandSource(org.quiltmc.qsl.command.api.client.QuiltClientCommandSource) MinecraftClient(net.minecraft.client.MinecraftClient) CommandException(net.minecraft.command.CommandException) QuiltClientCommandSource(org.quiltmc.qsl.command.api.client.QuiltClientCommandSource) CommandSource(net.minecraft.command.CommandSource) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException)

Example 43 with MinecraftClient

use of net.minecraft.client.MinecraftClient in project friends-and-foes by Faboslav.

the class MoobloomFlowerFeatureRenderer method render.

public void render(MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int light, T moobloomEntity, float f, float g, float h, float j, float k, float l) {
    if (!moobloomEntity.isBaby() && !moobloomEntity.isInvisible()) {
        BlockRenderManager blockRenderManager = MinecraftClient.getInstance().getBlockRenderManager();
        BlockState blockState = ModBlocks.BUTTERCUP.get().getDefaultState();
        int overlay = LivingEntityRenderer.getOverlay(moobloomEntity, 0.0F);
        MinecraftClient minecraftClient = MinecraftClient.getInstance();
        boolean renderAsModel = minecraftClient.hasOutline(moobloomEntity) && moobloomEntity.isInvisible();
        BakedModel bakedModel = blockRenderManager.getModel(blockState);
        // Head
        matrixStack.push();
        this.getContextModel().getHead().rotate(matrixStack);
        matrixStack.translate(0.09D, -0.6D, -0.185D);
        matrixStack.scale(-0.8F, -0.8F, 0.8F);
        matrixStack.translate(-0.5D, -0.5D, -0.5D);
        this.renderFlower(matrixStack, vertexConsumerProvider, light, renderAsModel, blockRenderManager, blockState, overlay, bakedModel);
        matrixStack.pop();
        // Body
        matrixStack.push();
        matrixStack.translate(0.22D, -0.28D, -0.06D);
        matrixStack.scale(-0.8F, -0.8F, 0.8F);
        matrixStack.translate(-0.5D, -0.5D, -0.5D);
        this.renderFlower(matrixStack, vertexConsumerProvider, light, renderAsModel, blockRenderManager, blockState, overlay, bakedModel);
        matrixStack.pop();
        matrixStack.push();
        matrixStack.translate(-0.2D, -0.22D, 0.01D);
        matrixStack.scale(-0.8F, -0.8F, 0.8F);
        matrixStack.translate(-0.5D, -0.5D, -0.5D);
        this.renderFlower(matrixStack, vertexConsumerProvider, light, renderAsModel, blockRenderManager, blockState, overlay, bakedModel);
        matrixStack.pop();
        matrixStack.push();
        matrixStack.translate(0.03D, -0.28D, 0.47D);
        matrixStack.scale(-0.8F, -0.8F, 0.8F);
        matrixStack.translate(-0.5D, -0.5D, -0.5D);
        this.renderFlower(matrixStack, vertexConsumerProvider, light, renderAsModel, blockRenderManager, blockState, overlay, bakedModel);
        matrixStack.pop();
    }
}
Also used : BlockState(net.minecraft.block.BlockState) BlockRenderManager(net.minecraft.client.render.block.BlockRenderManager) MinecraftClient(net.minecraft.client.MinecraftClient) BakedModel(net.minecraft.client.render.model.BakedModel)

Example 44 with MinecraftClient

use of net.minecraft.client.MinecraftClient in project isometric-renders by gliscowo.

the class IsoRenderCommand method executeBlockTarget.

private static int executeBlockTarget(FabricClientCommandSource source) {
    final MinecraftClient client = MinecraftClient.getInstance();
    IsometricRenderScreen screen = new IsometricRenderScreen();
    if (client.crosshairTarget.getType() != HitResult.Type.BLOCK) {
        source.sendError(Text.of("You're not looking at a block"));
        return 0;
    }
    final BlockPos hitPos = ((BlockHitResult) client.crosshairTarget).getBlockPos();
    BlockState state = client.world.getBlockState(hitPos);
    BlockEntity be = null;
    if (state.getBlock() instanceof BlockWithEntity) {
        CompoundTag tag = client.world.getBlockEntity(hitPos).toTag(new CompoundTag());
        be = ((BlockWithEntity) state.getBlock()).createBlockEntity(client.world);
        ((BlockEntityAccessor) be).setCachedState(state);
        be.setLocation(client.world, MinecraftClient.getInstance().player.getBlockPos());
        CompoundTag copyTag = tag.copy();
        copyTag.putInt("x", 0);
        copyTag.putInt("y", 0);
        copyTag.putInt("z", 0);
        be.fromTag(be.getCachedState(), copyTag);
        be.setLocation(client.world, MinecraftClient.getInstance().player.getBlockPos());
    }
    if (be != null) {
        IsometricRenderPresets.setupBlockEntityRender(screen, be);
    } else {
        IsometricRenderPresets.setupBlockStateRender(screen, state);
    }
    IsometricRenderHelper.scheduleScreen(screen);
    return 0;
}
Also used : IsometricRenderScreen(com.glisco.isometricrenders.client.gui.IsometricRenderScreen) AreaIsometricRenderScreen(com.glisco.isometricrenders.client.gui.AreaIsometricRenderScreen) BlockWithEntity(net.minecraft.block.BlockWithEntity) BlockState(net.minecraft.block.BlockState) MinecraftClient(net.minecraft.client.MinecraftClient) BlockPos(net.minecraft.util.math.BlockPos) BlockHitResult(net.minecraft.util.hit.BlockHitResult) CompoundTag(net.minecraft.nbt.CompoundTag) BlockEntity(net.minecraft.block.entity.BlockEntity) BlockEntityAccessor(com.glisco.isometricrenders.mixin.BlockEntityAccessor)

Example 45 with MinecraftClient

use of net.minecraft.client.MinecraftClient in project isometric-renders by gliscowo.

the class IsometricRendersClient method onInitializeClient.

@Override
public void onInitializeClient() {
    IsoRenderCommand.register(ClientCommandManager.DISPATCHER);
    ImageExporter.init();
    HudRenderCallback.EVENT.register((matrixStack, tickDelta) -> {
        final MinecraftClient client = MinecraftClient.getInstance();
        if (ImageExporter.getJobCount() < 1 || client.currentScreen != null)
            return;
        DrawableHelper.fill(matrixStack, 20, 20, 140, 60, 0x90000000);
        client.textRenderer.draw(matrixStack, ImageExporter.getProgressBarText(), 30, 30, 0xFFFFFF);
        RenderScreen.drawExportProgressBar(matrixStack, 30, 45, 100, 50, 10);
    });
}
Also used : MinecraftClient(net.minecraft.client.MinecraftClient)

Aggregations

MinecraftClient (net.minecraft.client.MinecraftClient)84 ItemStack (net.minecraft.item.ItemStack)12 Text (net.minecraft.text.Text)7 Identifier (net.minecraft.util.Identifier)7 Inject (org.spongepowered.asm.mixin.injection.Inject)7 BlockPos (net.minecraft.util.math.BlockPos)6 BlockEntity (net.minecraft.block.entity.BlockEntity)5 TextRenderer (net.minecraft.client.font.TextRenderer)5 ClientPlayNetworkHandler (net.minecraft.client.network.ClientPlayNetworkHandler)5 BlockHitResult (net.minecraft.util.hit.BlockHitResult)5 List (java.util.List)4 BlockState (net.minecraft.block.BlockState)4 MatrixStack (net.minecraft.client.util.math.MatrixStack)4 Entity (net.minecraft.entity.Entity)4 PlayerEntity (net.minecraft.entity.player.PlayerEntity)4 NbtCompound (net.minecraft.nbt.NbtCompound)4 AreaIsometricRenderScreen (com.glisco.isometricrenders.client.gui.AreaIsometricRenderScreen)3 IsometricRenderScreen (com.glisco.isometricrenders.client.gui.IsometricRenderScreen)3 GameRenderer (net.minecraft.client.render.GameRenderer)3 VertexConsumerProvider (net.minecraft.client.render.VertexConsumerProvider)3