Skip to content

Commit

Permalink
FUCK MOJANG
Browse files Browse the repository at this point in the history
  • Loading branch information
KrLite committed Jul 12, 2024
1 parent 6a9b0dc commit e72c464
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 35 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
Move to client only.
### Maintenance Update

- **Supported** `1.21+`.
8 changes: 4 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ archives-name = "poemofstarwars"
mod = "1.0.1"
loader = "fabric"

minecraft = "1.20.2"
yarn = "1.20.2+build.4"
minecraft = "1.21"
yarn = "1.21+build.9"
fabric-loader = "0.16.0"
fabric-api = "0.91.6+1.20.2"
fabric-api = "0.100.6+1.21"
fabric-loom = "1.6-SNAPSHOT"
modpublisher = "2.1.0"

Expand All @@ -18,7 +18,7 @@ id-curseforge = "1006177"
# display
display-name = "Poem o' Star Wars"
display-loader = "Fabric"
display-version = "1.20.2~1.20.6"
display-version = "1.21+"

[libraries]
minecraft = { group = "com.mojang", name = "minecraft", version.ref = "minecraft" }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package band.kessokuteatime.poemofstarwars;

import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.systems.VertexSorter;
import net.fabricmc.api.ClientModInitializer;
Expand All @@ -13,6 +14,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Objects;

public class PoemOfStarWars implements ClientModInitializer {
public static final String NAME = "Poem o' Star Wars", ID = "poemofstarwars";
public static final Logger LOGGER = LoggerFactory.getLogger(ID);
Expand All @@ -23,60 +26,70 @@ public void onInitializeClient() {
}

public static void drawTilted(Framebuffer framebuffer) {
int width = MinecraftClient.getInstance().getFramebuffer().textureWidth, height = MinecraftClient.getInstance().getFramebuffer().textureHeight;
MinecraftClient minecraftClient = MinecraftClient.getInstance();
int width = minecraftClient.getFramebuffer().textureWidth, height = MinecraftClient.getInstance().getFramebuffer().textureHeight;
ShaderProgram shaderProgram = minecraftClient.gameRenderer.blitScreenProgram;
if (shaderProgram == null) return;

RenderSystem.assertOnRenderThread();
RenderSystem.colorMask(true, true, true, true);
RenderSystem.disableCull();
RenderSystem.disableDepthTest();
//RenderSystem.disableDepthTest();
RenderSystem.enableBlend();
RenderSystem.depthMask(false);
//RenderSystem.depthMask(false);
RenderSystem.viewport(0, 0, width, height);
RenderSystem.setShader(GameRenderer::getPositionTexColorProgram);

MinecraftClient minecraftClient = MinecraftClient.getInstance();
ShaderProgram shaderProgram = minecraftClient.gameRenderer.blitScreenProgram;
shaderProgram.addSampler("DiffuseSampler", framebuffer.getColorAttachment());

Matrix4f matrix = new Matrix4f().setOrtho(0, width, height, 0, 1000.0F, 3000.0F);
Matrix4f matrix = new Matrix4f().setOrtho(0, width, height, 0, 1000.0F, 21000.0F);
RenderSystem.setProjectionMatrix(matrix, VertexSorter.BY_Z);

if (shaderProgram.modelViewMat != null) {
shaderProgram.modelViewMat.set((new Matrix4f()).translation(0, 0, -2000.0F));
shaderProgram.modelViewMat.set((new Matrix4f()).translation(0, 0, -11000.0F));
}

if (shaderProgram.projectionMat != null) {
shaderProgram.projectionMat.set(matrix);
}

shaderProgram.addSampler("DiffuseSampler", framebuffer.getColorAttachment());
shaderProgram.bind();


/*
Tessellator tessellator = RenderSystem.renderThreadTesselator();
BufferBuilder builder = tessellator.getBuffer();
builder.begin(VertexFormat.DrawMode.TRIANGLE_STRIP, VertexFormats.POSITION_TEXTURE_COLOR);
BufferBuilder builder = tessellator.begin(VertexFormat.DrawMode.TRIANGLE_STRIP, VertexFormats.POSITION_TEXTURE_COLOR);
double cameraDepth = 300, furthestDepth = 1080;
double levitation = furthestDepth / cameraDepth * 0.85, difference = furthestDepth - cameraDepth;
for (float y = 0; y < height; y++) {
float factor = y / height, opacity = (float) Math.pow(Math.min(1, 2 * (1 - factor)), 2);
Vector2d
projectionLeft = perspectiveProjection(cameraDepth, -width * 0.65, y * levitation, factor * difference)
.add(width / 2.0, 0),
projectionRight = perspectiveProjection(cameraDepth, width * 0.65, y * levitation, factor * difference)
.add(width / 2.0, 0);

whiteVertex(builder, projectionLeft.x(), height - projectionLeft.y(), 0, factor, opacity);
whiteVertex(builder, projectionRight.x(), height - projectionRight.y(), 1, factor, opacity);
Vector2d projectionLeft = perspectiveProjection(cameraDepth, -width * 0.65, y * levitation, factor * difference)
.add(width / 2.0, 0);
Vector2d projectionRight = perspectiveProjection(cameraDepth, width * 0.65, y * levitation, factor * difference)
.add(width / 2.0, 0);
whiteVertex(builder, (float) projectionLeft.x(), (float) (height - projectionLeft.y()), 0, factor, opacity);
whiteVertex(builder, (float) projectionRight.x(), (float) (height - projectionRight.y()), 1, factor, opacity);
}
BufferRenderer.draw(builder.end());
*/

BufferBuilder builder = RenderSystem.renderThreadTesselator().begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR);
builder.vertex(0.0F, 0.0F, 0.0F).texture(0, 0).color(1, 1, 1, 1F);
builder.vertex(width, 0.0F, 0.0F).texture(1, 0).color(1, 1, 1, 1F);
builder.vertex(width, height, 0.0F).texture(1, 1).color(1, 1, 1, 1F);
builder.vertex(0.0F, height, 0.0F).texture(0, 1).color(1, 1, 1, 1F);

BufferRenderer.drawWithGlobalProgram(builder.end());

shaderProgram.unbind();
framebuffer.endRead();

RenderSystem.depthMask(true);
}

private static void whiteVertex(BufferBuilder builder, double x, double y, float u, float v, float opacity) {
builder.vertex(x, y, 0).texture(u, v).color(1, 1, 1, opacity).next();
private static void whiteVertex(BufferBuilder builder, float x, float y, float u, float v, float opacity) {
builder.vertex(x, y, 0).texture(u, v).color(1, 1, 1, opacity);
}

private static Vector2d perspectiveProjection(double cameraDepth, double x, double y, double depth) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
package band.kessokuteatime.poemofstarwars.mixin;

import band.kessokuteatime.poemofstarwars.PoemOfStarWars;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.systems.VertexSorter;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gl.Framebuffer;
import net.minecraft.client.gl.SimpleFramebuffer;
import net.minecraft.client.gl.WindowFramebuffer;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.LogoDrawer;
import net.minecraft.client.gui.screen.CreditsScreen;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RotationAxis;
import org.joml.Matrix4f;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"depends": {
"fabricloader": "*",
"fabric-api": "*",
"minecraft": ["~1.20.2", "~1.20.3", "~1.20.4", "~1.20.5", "~1.20.6"]
"minecraft": "1.21.x"
},
"suggests": {
}
Expand Down

0 comments on commit e72c464

Please sign in to comment.