Search in sources :

Example 6 with MinecraftClient

use of net.minecraft.client.MinecraftClient in project Skyblocker by LifeIsAParadox.

the class DungeonMap method render.

public static void render(MatrixStack matrices) {
    MinecraftClient client = MinecraftClient.getInstance();
    if (client.player == null && client.world == null)
        return;
    ItemStack item = client.player.getInventory().main.get(8);
    NbtCompound tag = item.getNbt();
    if (tag != null && tag.contains("map")) {
        String tag2 = tag.asString();
        tag2 = StringUtils.substringBetween(tag2, "map:", "}");
        int mapid = Integer.parseInt(tag2);
        VertexConsumerProvider.Immediate vertices = client.getBufferBuilders().getEffectVertexConsumers();
        MapRenderer map = client.gameRenderer.getMapRenderer();
        MapState state = FilledMapItem.getMapState(mapid, client.world);
        if (state == null)
            return;
        matrices.push();
        matrices.translate(2, 2, 0);
        matrices.scale(1, 1, 0);
        map.draw(matrices, vertices, mapid, state, false, 15728880);
        vertices.draw();
        matrices.pop();
    }
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound) MapRenderer(net.minecraft.client.render.MapRenderer) MinecraftClient(net.minecraft.client.MinecraftClient) MapState(net.minecraft.item.map.MapState) ItemStack(net.minecraft.item.ItemStack) VertexConsumerProvider(net.minecraft.client.render.VertexConsumerProvider)

Example 7 with MinecraftClient

use of net.minecraft.client.MinecraftClient in project MasaGadget by plusls.

the class InventoryOverlayRenderHandler method renderOrderedTooltip.

public void renderOrderedTooltip(MatrixStack matrices, ItemStack stack, int x, int y) {
    y = y + 8;
    MinecraftClient mc = MinecraftClient.getInstance();
    List<OrderedText> lines = Lists.transform(stack.getTooltip(mc.player, mc.options.advancedItemTooltips ? TooltipContext.Default.ADVANCED : TooltipContext.Default.NORMAL), Text::asOrderedText);
    List<TooltipComponent> components = lines.stream().map(TooltipComponent::of).collect(Collectors.toList());
    if (components.isEmpty())
        return;
    int k = 0;
    int l = (components.size() == 1) ? -2 : 0;
    for (TooltipComponent lv : components) {
        int m = lv.getWidth(mc.textRenderer);
        if (m > k)
            k = m;
        l += lv.getHeight();
    }
    int n = x + 12;
    int o = y - 12;
    int p = k;
    int q = l;
    if (n + k > GuiUtils.getScaledWindowWidth())
        n -= 28 + k;
    if (o + q + 6 > GuiUtils.getScaledWindowHeight())
        o = GuiUtils.getScaledWindowHeight() - q - 6;
    matrices.push();
    int r = -267386864;
    int s = 1347420415;
    int t = 1344798847;
    int u = 400;
    float f = mc.getItemRenderer().zOffset;
    mc.getItemRenderer().zOffset = 400.0F;
    Tessellator lv2 = Tessellator.getInstance();
    BufferBuilder lv3 = lv2.getBuffer();
    RenderSystem.setShader(GameRenderer::getPositionColorShader);
    lv3.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
    Matrix4f lv4 = matrices.peek().getPositionMatrix();
    fillGradient(lv4, lv3, n - 3, o - 4, n + p + 3, o - 3, 400, -267386864, -267386864);
    fillGradient(lv4, lv3, n - 3, o + q + 3, n + p + 3, o + q + 4, 400, -267386864, -267386864);
    fillGradient(lv4, lv3, n - 3, o - 3, n + p + 3, o + q + 3, 400, -267386864, -267386864);
    fillGradient(lv4, lv3, n - 4, o - 3, n - 3, o + q + 3, 400, -267386864, -267386864);
    fillGradient(lv4, lv3, n + p + 3, o - 3, n + p + 4, o + q + 3, 400, -267386864, -267386864);
    fillGradient(lv4, lv3, n - 3, o - 3 + 1, n - 3 + 1, o + q + 3 - 1, 400, 1347420415, 1344798847);
    fillGradient(lv4, lv3, n + p + 2, o - 3 + 1, n + p + 3, o + q + 3 - 1, 400, 1347420415, 1344798847);
    fillGradient(lv4, lv3, n - 3, o - 3, n + p + 3, o - 3 + 1, 400, 1347420415, 1347420415);
    fillGradient(lv4, lv3, n - 3, o + q + 2, n + p + 3, o + q + 3, 400, 1344798847, 1344798847);
    RenderSystem.enableDepthTest();
    RenderSystem.disableTexture();
    RenderSystem.enableBlend();
    RenderSystem.defaultBlendFunc();
    lv3.end();
    BufferRenderer.draw(lv3);
    RenderSystem.disableBlend();
    RenderSystem.enableTexture();
    VertexConsumerProvider.Immediate lv5 = VertexConsumerProvider.immediate(Tessellator.getInstance().getBuffer());
    matrices.translate(0.0D, 0.0D, 400.0D);
    int v = o;
    for (int w = 0; w < components.size(); w++) {
        TooltipComponent lv6 = components.get(w);
        lv6.drawText(mc.textRenderer, n, v, lv4, lv5);
        v += lv6.getHeight() + ((w == 0) ? 2 : 0);
    }
    lv5.draw();
    matrices.pop();
    v = o;
    for (int i = 0; i < components.size(); i++) {
        TooltipComponent lv7 = components.get(i);
        lv7.drawItems(mc.textRenderer, n, v, matrices, mc.getItemRenderer(), 400);
        v += lv7.getHeight() + ((i == 0) ? 2 : 0);
    }
    mc.getItemRenderer().zOffset = f;
}
Also used : OrderedText(net.minecraft.text.OrderedText) Text(net.minecraft.text.Text) Matrix4f(net.minecraft.util.math.Matrix4f) MinecraftClient(net.minecraft.client.MinecraftClient) OrderedText(net.minecraft.text.OrderedText) TooltipComponent(net.minecraft.client.gui.tooltip.TooltipComponent)

Example 8 with MinecraftClient

use of net.minecraft.client.MinecraftClient in project MasaGadget by plusls.

the class RenderUtil method renderTextOnEntity.

// 只能在 EntityRenderer.render 中调用
public static void renderTextOnEntity(MatrixStack matrixStack, Entity entity, EntityRenderDispatcher entityRenderDispatcher, VertexConsumerProvider vertexConsumerProvider, Text text, float height) {
    MinecraftClient client = MinecraftClient.getInstance();
    if (entityRenderDispatcher.getSquaredDistanceToCamera(entity) <= 4096.0D) {
        matrixStack.push();
        matrixStack.translate(0, height, 0);
        matrixStack.multiply(entityRenderDispatcher.getRotation());
        matrixStack.scale(-0.018F, -0.018F, 0.018F);
        matrixStack.translate(0, 0, -33);
        Matrix4f lv = matrixStack.peek().getPositionMatrix();
        float g = MinecraftClient.getInstance().options.getTextBackgroundOpacity(0.25F);
        int k = (int) (g * 255.0F) << 24;
        float h = (float) (-client.textRenderer.getWidth(text) / 2);
        client.textRenderer.draw(text, h, 0, 553648127, false, lv, vertexConsumerProvider, false, k, 0xf00000);
        client.textRenderer.draw(text, h, 0, -1, false, lv, vertexConsumerProvider, false, 0, 0xf00000);
        matrixStack.pop();
    }
}
Also used : Matrix4f(net.minecraft.util.math.Matrix4f) MinecraftClient(net.minecraft.client.MinecraftClient)

Example 9 with MinecraftClient

use of net.minecraft.client.MinecraftClient in project MasaGadget by plusls.

the class MasaGuiUtil method initMasaModScreenList.

private static void initMasaModScreenList() {
    initialised = true;
    MinecraftClient client = MinecraftClient.getInstance();
    if (!ModInfo.isModLoaded(ModInfo.MODMENU_MOD_ID)) {
        return;
    }
    FabricLoader.getInstance().getEntrypointContainers("modmenu", ModMenuApi.class).forEach(entrypoint -> {
        ModMetadata metadata = entrypoint.getProvider().getMetadata();
        try {
            ModMenuApi api = entrypoint.getEntrypoint();
            Screen screen = api.getModConfigScreenFactory().create(client.currentScreen);
            if (screen instanceof GuiConfigsBase) {
                ConfigScreenFactory<?> configScreenFactory = api.getModConfigScreenFactory();
                masaGuiData.put(configScreenFactory, metadata.getName());
                masaGuiClassData.put(screen.getClass(), configScreenFactory);
            }
        } catch (Throwable e) {
            ModInfo.LOGGER.error("Mod {} provides a broken implementation of ModMenuApi", metadata.getId(), e);
        }
    });
}
Also used : ModMetadata(net.fabricmc.loader.api.metadata.ModMetadata) Screen(net.minecraft.client.gui.screen.Screen) MinecraftClient(net.minecraft.client.MinecraftClient) GuiConfigsBase(fi.dy.masa.malilib.gui.GuiConfigsBase) ModMenuApi(com.terraformersmc.modmenu.api.ModMenuApi)

Example 10 with MinecraftClient

use of net.minecraft.client.MinecraftClient in project Polymorph by TheIllusiveC4.

the class OutputWidget method renderButton.

@Override
public void renderButton(MatrixStack matrixStack, int button_1, int button_2, float button_3) {
    MinecraftClient minecraft = MinecraftClient.getInstance();
    RenderSystem.setShader(GameRenderer::getPositionTexShader);
    RenderSystem.setShaderTexture(0, AbstractRecipesWidget.WIDGETS);
    int j = 0;
    if (this.x + 25 > button_1 && this.x <= button_1 && this.y + 25 > button_2 && this.y <= button_2) {
        j += 25;
    }
    this.drawTexture(matrixStack, this.x, this.y, this.highlighted ? 41 : 16, j, this.width, this.height);
    int k = 4;
    ItemRenderer renderer = minecraft.getItemRenderer();
    float zLevel = renderer.zOffset;
    renderer.zOffset = 700.0F;
    renderer.renderGuiItemIcon(this.getOutput(), this.x + k, this.y + k);
    renderer.renderGuiItemOverlay(minecraft.textRenderer, this.getOutput(), this.x + k, this.y + k);
    renderer.zOffset = zLevel;
}
Also used : MinecraftClient(net.minecraft.client.MinecraftClient) ItemRenderer(net.minecraft.client.render.item.ItemRenderer) GameRenderer(net.minecraft.client.render.GameRenderer)

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