use of net.minecraft.util.math.Matrix4f in project MiniMap by pl3xgaming.
the class GL method drawLine.
public static void drawLine(MatrixStack matrixStack, float x0, float y0, float x1, float y1, float width, int color) {
RenderSystem.setShader(GameRenderer::getRenderTypeLinesShader);
RenderSystem.lineWidth(width);
Matrix4f matrix4f = matrixStack.peek().getPositionMatrix();
Matrix3f matrix3f = matrixStack.peek().getNormalMatrix();
BufferBuilder buf = Tessellator.getInstance().getBuffer();
buf.begin(VertexFormat.DrawMode.LINES, VertexFormats.LINES);
buf.vertex(matrix4f, x0, y0, 0F).color(color).normal(matrix3f, 1F, 1F, 0F).next();
buf.vertex(matrix4f, x1, y1, 0F).color(color).normal(matrix3f, 1F, 1F, 0F).next();
buf.end();
BufferRenderer.draw(buf);
RenderSystem.lineWidth(1F);
}
use of net.minecraft.util.math.Matrix4f in project fabricskyboxes by AMereBagatelle.
the class AbstractSkybox method renderDecorations.
public void renderDecorations(WorldRendererAccess worldRendererAccess, MatrixStack matrices, Matrix4f matrix4f, float tickDelta, BufferBuilder bufferBuilder, float alpha) {
if (!SkyboxManager.getInstance().hasRenderedDecorations()) {
Vec3f rotationStatic = decorations.getRotation().getStatic();
Vec3f rotationAxis = decorations.getRotation().getAxis();
RenderSystem.enableTexture();
matrices.push();
matrices.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(rotationStatic.getX()));
matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(rotationStatic.getY()));
matrices.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion(rotationStatic.getZ()));
ClientWorld world = MinecraftClient.getInstance().world;
assert world != null;
RenderSystem.enableTexture();
RenderSystem.blendFuncSeparate(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE, GlStateManager.SrcFactor.ONE, GlStateManager.DstFactor.ZERO);
matrices.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(rotationAxis.getX()));
matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(rotationAxis.getY()));
matrices.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion(rotationAxis.getZ()));
matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(-90.0F));
matrices.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(world.getSkyAngle(tickDelta) * 360.0F * decorations.getRotation().getRotationSpeed()));
matrices.multiply(Vec3f.NEGATIVE_Z.getDegreesQuaternion(rotationAxis.getZ()));
matrices.multiply(Vec3f.NEGATIVE_Y.getDegreesQuaternion(rotationAxis.getY()));
matrices.multiply(Vec3f.NEGATIVE_X.getDegreesQuaternion(rotationAxis.getX()));
// sun
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, alpha);
Matrix4f matrix4f2 = matrices.peek().getPositionMatrix();
float s = 30.0F;
RenderSystem.setShader(GameRenderer::getPositionTexShader);
if (decorations.isSunEnabled()) {
RenderSystem.setShaderTexture(0, this.decorations.getSunTexture());
bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE);
bufferBuilder.vertex(matrix4f2, -s, 100.0F, -s).texture(0.0F, 0.0F).next();
bufferBuilder.vertex(matrix4f2, s, 100.0F, -s).texture(1.0F, 0.0F).next();
bufferBuilder.vertex(matrix4f2, s, 100.0F, s).texture(1.0F, 1.0F).next();
bufferBuilder.vertex(matrix4f2, -s, 100.0F, s).texture(0.0F, 1.0F).next();
bufferBuilder.end();
BufferRenderer.draw(bufferBuilder);
}
// moon
s = 20.0F;
if (decorations.isMoonEnabled()) {
RenderSystem.setShaderTexture(0, this.decorations.getMoonTexture());
int u = world.getMoonPhase();
int v = u % 4;
int w = u / 4 % 2;
float x = v / 4.0F;
float p = w / 2.0F;
float q = (v + 1) / 4.0F;
float r = (w + 1) / 2.0F;
bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE);
bufferBuilder.vertex(matrix4f2, -s, -100.0F, s).texture(q, r).next();
bufferBuilder.vertex(matrix4f2, s, -100.0F, s).texture(x, r).next();
bufferBuilder.vertex(matrix4f2, s, -100.0F, -s).texture(x, p).next();
bufferBuilder.vertex(matrix4f2, -s, -100.0F, -s).texture(q, p).next();
bufferBuilder.end();
BufferRenderer.draw(bufferBuilder);
}
// stars
if (decorations.isStarsEnabled()) {
RenderSystem.disableTexture();
float ab = world.method_23787(tickDelta) * s;
if (ab > 0.0F) {
RenderSystem.setShaderColor(ab, ab, ab, ab);
worldRendererAccess.getStarsBuffer().setShader(matrices.peek().getPositionMatrix(), matrix4f, GameRenderer.getPositionShader());
}
}
matrices.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion(rotationStatic.getZ()));
matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(rotationStatic.getY()));
matrices.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(rotationStatic.getX()));
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
RenderSystem.disableBlend();
matrices.pop();
}
}
use of net.minecraft.util.math.Matrix4f in project fabricskyboxes by AMereBagatelle.
the class SquareTexturedSkybox method renderSkybox.
@Override
public void renderSkybox(WorldRendererAccess worldRendererAccess, MatrixStack matrices, float tickDelta, Camera camera, boolean thickFog) {
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferBuilder = tessellator.getBuffer();
for (int i = 0; i < 6; ++i) {
// 0 = bottom
// 1 = north
// 2 = south
// 3 = top
// 4 = east
// 5 = west
Texture tex = this.textures.byId(i);
matrices.push();
RenderSystem.setShaderTexture(0, tex.getTextureId());
if (i == 1) {
matrices.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(90.0F));
} else if (i == 2) {
matrices.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(-90.0F));
matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(180.0F));
} else if (i == 3) {
matrices.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(180.0F));
matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(90.0F));
} else if (i == 4) {
matrices.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion(90.0F));
matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(-90.0F));
} else if (i == 5) {
matrices.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion(-90.0F));
matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(90.0F));
}
Matrix4f matrix4f = matrices.peek().getPositionMatrix();
bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR);
bufferBuilder.vertex(matrix4f, -100.0F, -100.0F, -100.0F).texture(tex.getMinU(), tex.getMinV()).color(1f, 1f, 1f, alpha).next();
bufferBuilder.vertex(matrix4f, -100.0F, -100.0F, 100.0F).texture(tex.getMinU(), tex.getMaxV()).color(1f, 1f, 1f, alpha).next();
bufferBuilder.vertex(matrix4f, 100.0F, -100.0F, 100.0F).texture(tex.getMaxU(), tex.getMaxV()).color(1f, 1f, 1f, alpha).next();
bufferBuilder.vertex(matrix4f, 100.0F, -100.0F, -100.0F).texture(tex.getMaxU(), tex.getMinV()).color(1f, 1f, 1f, alpha).next();
tessellator.draw();
matrices.pop();
}
}
use of net.minecraft.util.math.Matrix4f in project MasaGadget by plusls.
the class MixinWorldRenderer method postRender.
@Inject(method = "render", at = @At(value = "RETURN"))
private void postRender(MatrixStack matrices, float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightmapTextureManager lightmapTextureManager, Matrix4f matrix4f, CallbackInfo ci) {
MinecraftClient mc = MinecraftClient.getInstance();
World world = WorldUtils.getBestWorld(mc);
if (world == null || mc.player == null) {
return;
}
Entity cameraEntity = world.getPlayerByUuid(mc.player.getUuid());
if (cameraEntity == null) {
cameraEntity = mc.player;
}
if (FeatureToggle.TWEAK_FREE_CAMERA.getBooleanValue()) {
cameraEntity = mc.getCameraEntity();
}
if (!FeatureToggle.TWEAK_INVENTORY_PREVIEW.getBooleanValue() || !Hotkeys.INVENTORY_PREVIEW.getKeybind().isKeybindHeld() || !Configs.Tweakeroo.INVENTORY_PREVIEW_SUPPORT_COMPARATOR.getBooleanValue() || cameraEntity == null) {
return;
}
MatrixStack matrixStack = RenderSystem.getModelViewStack();
matrixStack.push();
matrixStack.multiplyPositionMatrix(matrices.peek().getPositionMatrix());
RenderSystem.applyModelViewMatrix();
// 开始渲染
HitResult trace = RayTraceUtils.getRayTraceFromEntity(world, cameraEntity, false);
if (trace.getType() == HitResult.Type.BLOCK) {
BlockPos pos = ((BlockHitResult) trace).getBlockPos();
// 绕过线程检查
BlockEntity blockEntity = world.getWorldChunk(pos).getBlockEntity(pos);
if (blockEntity instanceof ComparatorBlockEntity) {
LiteralText literalText = new LiteralText(((ComparatorBlockEntity) blockEntity).getOutputSignal() + "");
literalText.formatted(Formatting.GREEN);
// literalText.formatted(Formatting.);
VertexConsumerProvider.Immediate immediate = VertexConsumerProvider.immediate(Tessellator.getInstance().getBuffer());
// 不加 1.17 渲染会有问题
RenderSystem.disableDepthTest();
matrixStack.push();
matrixStack.translate(pos.getX() + 0.5 - camera.getPos().getX(), pos.getY() + 0.6 - camera.getPos().getY(), pos.getZ() + 0.5 - camera.getPos().getZ());
matrixStack.multiplyPositionMatrix(new Matrix4f(camera.getRotation()));
matrixStack.scale(-0.04F, -0.04F, -0.04F);
RenderSystem.applyModelViewMatrix();
Matrix4f lv = AffineTransformation.identity().getMatrix();
float xOffset = (float) (-mc.textRenderer.getWidth(literalText) / 2);
float g = mc.options.getTextBackgroundOpacity(0.25F);
int k = (int) (g * 255.0F) << 24;
mc.textRenderer.draw(literalText, xOffset, 0, 553648127, false, lv, immediate, true, k, 0xf00000);
immediate.draw();
mc.textRenderer.draw(literalText, xOffset, 0, -1, false, lv, immediate, true, 0, 0xf00000);
immediate.draw();
matrixStack.pop();
RenderSystem.applyModelViewMatrix();
RenderSystem.enableDepthTest();
}
}
// 结束渲染
matrixStack.pop();
RenderSystem.applyModelViewMatrix();
}
use of net.minecraft.util.math.Matrix4f in project Polymorph by TheIllusiveC4.
the class SelectionWidget method drawHoveringText.
public static void drawHoveringText(MatrixStack mStack, List<? extends StringVisitable> textLines, int mouseX, int mouseY, int screenWidth, int screenHeight, int maxTextWidth, int backgroundColor, int borderColorStart, int borderColorEnd, TextRenderer font) {
if (!textLines.isEmpty()) {
RenderSystem.disableDepthTest();
int tooltipTextWidth = 0;
for (StringVisitable textLine : textLines) {
int textLineWidth = font.getWidth(textLine);
if (textLineWidth > tooltipTextWidth) {
tooltipTextWidth = textLineWidth;
}
}
boolean needsWrap = false;
int titleLinesCount = 1;
int tooltipX = mouseX + 12;
if (tooltipX + tooltipTextWidth + 4 > screenWidth) {
tooltipX = mouseX - 16 - tooltipTextWidth;
if (tooltipX < 4) {
if (mouseX > screenWidth / 2) {
tooltipTextWidth = mouseX - 12 - 8;
} else {
tooltipTextWidth = screenWidth - 16 - mouseX;
}
needsWrap = true;
}
}
if (maxTextWidth > 0 && tooltipTextWidth > maxTextWidth) {
tooltipTextWidth = maxTextWidth;
needsWrap = true;
}
if (needsWrap) {
int wrappedTooltipWidth = 0;
List<StringVisitable> wrappedTextLines = new ArrayList<>();
for (int i = 0; i < textLines.size(); i++) {
StringVisitable textLine = textLines.get(i);
List<StringVisitable> wrappedLine = font.getTextHandler().wrapLines(textLine, tooltipTextWidth, Style.EMPTY);
if (i == 0) {
titleLinesCount = wrappedLine.size();
}
for (StringVisitable line : wrappedLine) {
int lineWidth = font.getWidth(line);
if (lineWidth > wrappedTooltipWidth) {
wrappedTooltipWidth = lineWidth;
}
wrappedTextLines.add(line);
}
}
tooltipTextWidth = wrappedTooltipWidth;
textLines = wrappedTextLines;
if (mouseX > screenWidth / 2) {
tooltipX = mouseX - 16 - tooltipTextWidth;
} else {
tooltipX = mouseX + 12;
}
}
int tooltipY = mouseY - 12;
int tooltipHeight = 8;
if (textLines.size() > 1) {
tooltipHeight += (textLines.size() - 1) * 10;
if (textLines.size() > titleLinesCount) {
tooltipHeight += 2;
}
}
if (tooltipY < 4) {
tooltipY = 4;
} else if (tooltipY + tooltipHeight + 4 > screenHeight) {
tooltipY = screenHeight - tooltipHeight - 4;
}
final int zLevel = 900;
mStack.push();
Matrix4f mat = mStack.peek().getPositionMatrix();
drawGradientRect(mat, zLevel, tooltipX - 3, tooltipY - 4, tooltipX + tooltipTextWidth + 3, tooltipY - 3, backgroundColor, backgroundColor);
drawGradientRect(mat, zLevel, tooltipX - 3, tooltipY + tooltipHeight + 3, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 4, backgroundColor, backgroundColor);
drawGradientRect(mat, zLevel, tooltipX - 3, tooltipY - 3, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3, backgroundColor, backgroundColor);
drawGradientRect(mat, zLevel, tooltipX - 4, tooltipY - 3, tooltipX - 3, tooltipY + tooltipHeight + 3, backgroundColor, backgroundColor);
drawGradientRect(mat, zLevel, tooltipX + tooltipTextWidth + 3, tooltipY - 3, tooltipX + tooltipTextWidth + 4, tooltipY + tooltipHeight + 3, backgroundColor, backgroundColor);
drawGradientRect(mat, zLevel, tooltipX - 3, tooltipY - 3 + 1, tooltipX - 3 + 1, tooltipY + tooltipHeight + 3 - 1, borderColorStart, borderColorEnd);
drawGradientRect(mat, zLevel, tooltipX + tooltipTextWidth + 2, tooltipY - 3 + 1, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3 - 1, borderColorStart, borderColorEnd);
drawGradientRect(mat, zLevel, tooltipX - 3, tooltipY - 3, tooltipX + tooltipTextWidth + 3, tooltipY - 3 + 1, borderColorStart, borderColorStart);
drawGradientRect(mat, zLevel, tooltipX - 3, tooltipY + tooltipHeight + 2, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3, borderColorEnd, borderColorEnd);
VertexConsumerProvider.Immediate renderType = VertexConsumerProvider.immediate(Tessellator.getInstance().getBuffer());
mStack.translate(0.0D, 0.0D, zLevel);
for (int lineNumber = 0; lineNumber < textLines.size(); ++lineNumber) {
StringVisitable line = textLines.get(lineNumber);
if (line != null) {
font.draw(Language.getInstance().reorder(line), (float) tooltipX, (float) tooltipY, -1, true, mat, renderType, false, 0, 15728880);
}
if (lineNumber + 1 == titleLinesCount) {
tooltipY += 2;
}
tooltipY += 10;
}
renderType.draw();
mStack.pop();
RenderSystem.enableDepthTest();
}
}
Aggregations