渲染 Minecraft Fabric 错误:找不到符号

问题描述 投票:0回答:1

我想为我的世界模组创建我自己的ClickGUI,由于某种原因它输出一个错误。我按照指南进行操作https://fabric.moddedmc.wiki/rendering/.

我的代码:

package org.sgx.nihao.ui.screen.clickgui;

import com.mojang.blaze3d.systems.RenderSystem;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.minecraft.client.render.*;
import net.minecraft.util.Identifier;
import org.joml.Matrix4f;

public class ClickGUI {
    public void onInitializeClient(){
        HudRenderCallback.EVENT.register((drawContext, tickDelta) -> {
            Matrix4f positionMatrix = drawContext.getMatrices().peek().getPositionMatrix();
            Tessellator tessellator = Tessellator.getInstance();
            BufferBuilder buffer = tessellator.getBuffer();
            buffer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR_TEXTURE);
            buffer.vertex(positionMatrix, 20, 20, 0).color(1f, 1f, 1f, 1f).texture(0f, 0f).next();
            buffer.vertex(positionMatrix, 20, 60, 0).color(1f, 0f, 0f, 1f).texture(0f, 1f).next();
            buffer.vertex(positionMatrix, 60, 60, 0).color(0f, 1f, 0f, 1f).texture(1f, 1f).next();
            buffer.vertex(positionMatrix, 60, 20, 0).color(0f, 0f, 1f, 1f).texture(1f, 0f).next();

            RenderSystem.setShader(GameRenderer::getPositionColorTexProgram);
            RenderSystem.setShaderTexture(0, new Identifier("nihao_mod", "icon.png"));
            RenderSystem.setShaderColor(1f, 1f, 1f, 1f);

            tessellator.draw();

        });
    }

}

错误:

*path*\ClickGUI.java:12: error: cannot find symbol
            Matrix4f positionMatrix = drawContext.getMatrices().peek().getPositionMatrix();
                                                 ^
  symbol:   method getMatrices()
  location: variable drawContext of type MatrixStack

它可能有用:我有一年半的 Python 经验,1 周的 Java 经验

我不知道该尝试什么,我试图找到问题的解决方案,但没有成功。我们需要以下结果:https://fabric.moddedmc.wiki/assets/basics_0.hRPTS0c9.png

java minecraft fabric
1个回答
0
投票

我找到了解决问题的方法。谁在乎呢,我只是改变了矩阵调用。

Matrix4f positionMatrix = drawContext.peek().getPositionMatrix();

© www.soinside.com 2019 - 2024. All rights reserved.