Skip to content

Commit

Permalink
clean up iris compat, bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
gliscowo committed May 18, 2024
1 parent c9a953a commit 8335d3b
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 24 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ org.gradle.jvmargs=-Xmx1G
loader_version=0.15.9

# Mod Properties
mod_version = 0.1.8-pre.1
mod_version = 0.1.8
maven_group = io.wispforest
archives_base_name = lavender

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import net.minecraft.resource.ResourceManager;
import net.minecraft.util.Arm;
import net.minecraft.util.math.RotationAxis;
import org.jetbrains.annotations.Nullable;

import java.util.function.Supplier;

Expand All @@ -27,12 +28,12 @@ public class OffhandBookRenderer {
var window = MinecraftClient.getInstance().getWindow();

var framebuffer = new SimpleFramebuffer(window.getFramebufferWidth(), window.getFramebufferHeight(), true, MinecraftClient.IS_SYSTEM_MAC);
((LavenderFramebufferExtension)framebuffer).lavender$setUseCutoutBlit();
framebuffer.setClearColor(0f, 0f, 0f, 0f);
((LavenderFramebufferExtension)framebuffer).lavender$setBlitProgram(LavenderClient.BLIT_CUTOUT_PROGRAM::program);
return framebuffer;
});

private static final Supplier<Framebuffer> FRAMEBUFFER = Suppliers.memoize(() -> {
private static final Supplier<Framebuffer> DISPLAY_BUFFER = Suppliers.memoize(() -> {
var window = MinecraftClient.getInstance().getWindow();

var framebuffer = new SimpleFramebuffer(window.getFramebufferWidth(), window.getFramebufferHeight(), true, MinecraftClient.IS_SYSTEM_MAC);
Expand All @@ -45,17 +46,16 @@ public class OffhandBookRenderer {

public static void initialize() {
WindowResizeCallback.EVENT.register((client, window) -> {
FRAMEBUFFER.get().resize(window.getFramebufferWidth(), window.getFramebufferHeight(), MinecraftClient.IS_SYSTEM_MAC);
DISPLAY_BUFFER.get().resize(window.getFramebufferWidth(), window.getFramebufferHeight(), MinecraftClient.IS_SYSTEM_MAC);
BACK_BUFFER.get().resize(window.getFramebufferWidth(), window.getFramebufferHeight(), MinecraftClient.IS_SYSTEM_MAC);
cachedScreen = null;
});
}

public static void beginFrame() {
public static void beginFrame(@Nullable Book book) {
cacheExpired = true;
}

public static void prepareTexture(Book book) {
if (book == null) return;
var client = MinecraftClient.getInstance();

rendering = true;
Expand Down Expand Up @@ -90,9 +90,9 @@ public static void prepareTexture(Book book) {
modelView.pop();
RenderSystem.applyModelViewMatrix();

var frontBuffer = FRAMEBUFFER.get();
frontBuffer.clear(MinecraftClient.IS_SYSTEM_MAC);
frontBuffer.beginWrite(false);
var displayBuffer = DISPLAY_BUFFER.get();
displayBuffer.clear(MinecraftClient.IS_SYSTEM_MAC);
displayBuffer.beginWrite(false);

backBuffer.draw(backBuffer.textureWidth, backBuffer.textureHeight, false);

Expand All @@ -108,7 +108,7 @@ public static void render(MatrixStack matrices, int light) {

// --- draw color attachment in place of map texture ---

var framebuffer = FRAMEBUFFER.get();
var framebuffer = DISPLAY_BUFFER.get();

var texture = new FramebufferTexture(framebuffer.getColorAttachment());
client.getTextureManager().registerTexture(Lavender.id("offhand_book_framebuffer"), texture);
Expand All @@ -120,7 +120,7 @@ public static void render(MatrixStack matrices, int light) {
matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(-10));

matrices.scale(1 * (framebuffer.textureWidth / (float) framebuffer.textureHeight), 1f, 1f);
matrices.translate(rightHanded ? -.4f : -.6f, -.35f, -.2f);
matrices.translate(rightHanded ? -.4f : -.6f, -.35f, -.165f);

var buffer = client.getBufferBuilders().getEntityVertexConsumers().getBuffer(RenderLayer.getText(Lavender.id("offhand_book_framebuffer")));
var matrix = matrices.peek().getPositionMatrix();
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/io/wispforest/lavender/mixin/FramebufferMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.mojang.blaze3d.platform.GlStateManager;
import io.wispforest.lavender.client.LavenderClient;
import io.wispforest.lavender.pond.LavenderFramebufferExtension;
import net.minecraft.client.gl.Framebuffer;
import net.minecraft.client.gl.ShaderProgram;
Expand All @@ -13,18 +14,18 @@
@Mixin(Framebuffer.class)
public class FramebufferMixin implements LavenderFramebufferExtension {

private Supplier<ShaderProgram> blitProgram;
private boolean useCutoutBlit = false;

@Override
public void lavender$setBlitProgram(Supplier<ShaderProgram> program) {
this.blitProgram = program;
public void lavender$setUseCutoutBlit() {
this.useCutoutBlit = true;
}

@ModifyExpressionValue(method = "drawInternal", at = @At(value = "FIELD", target = "Lnet/minecraft/client/render/GameRenderer;blitScreenProgram:Lnet/minecraft/client/gl/ShaderProgram;"))
private ShaderProgram applyBlitProgram(ShaderProgram original) {
if (this.blitProgram == null) return original;
if (!this.useCutoutBlit) return original;

GlStateManager._colorMask(true, true, true, true);
return this.blitProgram.get();
return LavenderClient.BLIT_CUTOUT_PROGRAM.program();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.wispforest.lavender.mixin;

import io.wispforest.lavender.book.Book;
import io.wispforest.lavender.book.LavenderBookItem;
import io.wispforest.lavender.client.LavenderBookScreen;
import io.wispforest.lavender.client.OffhandBookRenderer;
Expand All @@ -26,17 +27,20 @@ public class MinecraftClientMixin {

@Inject(method = "render", at = @At("HEAD"))
private void onFrameStart(boolean tick, CallbackInfo ci) {
OffhandBookRenderer.beginFrame();
if (this.player == null) return;

Book bookToRender = null;
var offhandStack = this.player.getOffHandStack();
if (offhandStack.getItem() instanceof LavenderBookItem && LavenderBookItem.bookOf(offhandStack) != null && !(this.currentScreen instanceof LavenderBookScreen)) {
OffhandBookRenderer.prepareTexture(LavenderBookItem.bookOf(offhandStack));
bookToRender = LavenderBookItem.bookOf(offhandStack);
}

OffhandBookRenderer.beginFrame(bookToRender);
}

@Inject(method = "render", at = @At("TAIL"))
private void onFrameEnd(boolean tick, CallbackInfo ci) {
if (this.player == null) return;
OffhandBookRenderer.endFrame();
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package io.wispforest.lavender.pond;

import net.minecraft.client.gl.ShaderProgram;

import java.util.function.Supplier;

public interface LavenderFramebufferExtension {
void lavender$setBlitProgram(Supplier<ShaderProgram> program);
void lavender$setUseCutoutBlit();
}

0 comments on commit 8335d3b

Please sign in to comment.