Skip to content

Commit

Permalink
Add support for 1.20.2 and 1.20.4
Browse files Browse the repository at this point in the history
Slightly tentative, Fabric API's Block View API probably needs at least another mixin on `ChunkCacheOF` to fully support it
Mod support beyond Fabric API is essentially untested
  • Loading branch information
Chocohead committed Jan 12, 2024
1 parent 9d0ee2e commit d9a13f3
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 6 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ fabric_version=0.42.0+1.16
tiny_remapper_version=0.8.11
fabric_asm_version=v2.3

mod_version = 1.14.2
mod_version = 1.14.3
maven_group = me.modmuss50
archives_base_name = optifabric
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package me.modmuss50.optifabric.compat.fabricblockview;

import org.objectweb.asm.tree.ClassNode;

import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
import org.spongepowered.asm.mixin.transformer.ClassInfo;

import me.modmuss50.optifabric.compat.InterceptingMixinPlugin;
import me.modmuss50.optifabric.util.MixinUtils;

public class BlockViewMixinPlugin extends InterceptingMixinPlugin {
@Override
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
if ("ChunkRendererRegionBuilderMixin".equals(mixinInfo.getName())) {
ClassInfo info = ClassInfo.forName(targetClassName);
MixinUtils.completeClassInfo(info, targetClass.methods);
}

super.preApply(targetClassName, targetClass, mixinClassName, mixinInfo);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package me.modmuss50.optifabric.compat.fabricblockview.mixin;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

import net.minecraft.class_6850;
import net.minecraft.class_6850.class_6851;
import net.minecraft.client.render.chunk.ChunkRendererRegion;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

import me.modmuss50.optifabric.compat.InterceptingMixin;
import me.modmuss50.optifabric.compat.PlacatingSurrogate;
import me.modmuss50.optifabric.compat.Shim;

@Mixin(class_6850.class)
@InterceptingMixin("net/fabricmc/fabric/mixin/blockview/client/ChunkRendererRegionBuilderMixin")
abstract class ChunkRendererRegionBuilderMixin {
@PlacatingSurrogate
private void createDataMap(World world, BlockPos startPos, BlockPos endPos, int chunkRadius, CallbackInfoReturnable<ChunkRendererRegion> call) {
}

@Inject(at = @At("RETURN"), method = "createRegion", remap = false, locals = LocalCapture.CAPTURE_FAILHARD)
private void createOF(World world, BlockPos startPos, BlockPos endPos, int offset, boolean checkEmpty, CallbackInfoReturnable<ChunkRendererRegion> call, int startX, int startZ, int endX, int endZ, class_6851[][] chunks) {
createDataMap(world, startPos, endPos, offset, call, startX, endX, startZ, endZ, chunks);
}

@Shim
private native void createDataMap(World world, BlockPos startPos, BlockPos endPos, int offset, CallbackInfoReturnable<ChunkRendererRegion> call, int startX, int startZ, int endX, int endZ, class_6851[][] chunks);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
@InterceptingMixin("net/fabricmc/fabric/mixin/client/rendering/WorldRendererMixin")
abstract class WorldRendererNewMixin {
@Inject(method = "render(Lnet/minecraft/client/util/math/MatrixStack;FJZLnet/minecraft/client/render/Camera;Lnet/minecraft/client/render/GameRenderer;Lnet/minecraft/client/render/LightmapTextureManager;Lorg/joml/Matrix4f;)V", require = 2,
at = @At(value = "INVOKE",
target = "Lnet/minecraft/client/particle/ParticleManager;render(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider$Immediate;Lnet/minecraft/client/render/LightmapTextureManager;Lnet/minecraft/client/render/Camera;FLnet/minecraft/client/render/Frustum;)V"))
at = {@At(value = "INVOKE",
target = "Lnet/minecraft/client/particle/ParticleManager;renderParticles(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider$Immediate;Lnet/minecraft/client/render/LightmapTextureManager;Lnet/minecraft/client/render/Camera;FLnet/minecraft/client/render/Frustum;)V"),
@At(value = "INVOKE",
target = "Lnet/minecraft/client/particle/ParticleManager;render(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider$Immediate;Lnet/minecraft/client/render/LightmapTextureManager;Lnet/minecraft/client/render/Camera;FLnet/minecraft/client/render/Frustum;)V")})
private void onReallyRenderParticles(CallbackInfo call) {
onRenderParticles(call);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package me.modmuss50.optifabric.compat.fabricscreenapi.mixin;

import me.modmuss50.optifabric.compat.InterceptingMixin;
import me.modmuss50.optifabric.compat.PlacatingSurrogate;
import me.modmuss50.optifabric.compat.Shim;
import net.minecraft.client.gui.DrawableHelper;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.util.Window;
import net.minecraft.client.util.math.MatrixStack;
import org.joml.Matrix4f;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.At.Shift;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

@Mixin(GameRenderer.class)
@InterceptingMixin("net/fabricmc/fabric/mixin/screen/GameRendererMixin")
abstract class GameRendererNew5erMixin {
@Shim
private native void onBeforeRenderScreen(float tickDelta, long startTime, boolean tick, CallbackInfo call, boolean loaded, int mouseX, int mouseY, MatrixStack matrixstack, DrawableHelper drawContext);

@PlacatingSurrogate
private void onBeforeRenderScreen(float tickDelta, long startTime, boolean tick, CallbackInfo call, boolean loaded, int mouseX, int mouseY, Window window, float idk) {
}

@Inject(method = "render(FJZ)V",
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/Screen;renderWithTooltip(Lnet/minecraft/class_332;IIF)V", ordinal = 0),
locals = LocalCapture.CAPTURE_FAILHARD,
cancellable = true)
private void onBeforeRenderScreen(float tickDelta, long startTime, boolean tick, CallbackInfo call, boolean loaded, int mouseX, int mouseY, Window window, float guiFarPlane, Matrix4f projection, MatrixStack matrixstack, float idk, DrawableHelper drawContext) {
onBeforeRenderScreen(tickDelta, startTime, tick, call, loaded, mouseX, mouseY, matrixstack, drawContext);
}

@Shim
private native void onAfterRenderScreen(float tickDelta, long startTime, boolean tick, CallbackInfo call, boolean loaded, int mouseX, int mouseY, MatrixStack matrixstack, DrawableHelper drawContext);

@PlacatingSurrogate
private void onAfterRenderScreen(float tickDelta, long startTime, boolean tick, CallbackInfo call, boolean loaded, int mouseX, int mouseY, Window window, float idk) {
}

@Inject(method = "render(FJZ)V",
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/Screen;renderWithTooltip(Lnet/minecraft/class_332;IIF)V", shift = Shift.AFTER, ordinal = 0),
locals = LocalCapture.CAPTURE_FAILHARD)
private void onAfterRenderScreen(float tickDelta, long startTime, boolean tick, CallbackInfo call, boolean loaded, int mouseX, int mouseY, Window window, float guiFarPlane, Matrix4f projection, MatrixStack matrixstack, float idk, DrawableHelper drawContext) {
onAfterRenderScreen(tickDelta, startTime, tick, call, loaded, mouseX, mouseY, matrixstack, drawContext);
}
}
14 changes: 12 additions & 2 deletions src/main/java/me/modmuss50/optifabric/mod/OptifabricSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,13 @@ protected boolean isPresent() {
Mixins.addConfiguration("optifabric.compat.fabric-rendering.extra-mixins.json");
}

if (isPresent("fabric-rendering-data-attachment-v1")) {
if (isPresent("fabric-block-view-api-v2")) {
Mixins.addConfiguration("optifabric.compat.fabric-block-view-api.mixins.json");

if (isPresent("fabric-rendering-data-attachment-v1")) {
Mixins.addConfiguration("optifabric.compat.fabric-rendering-data.mixins.json");
}
} else if (isPresent("fabric-rendering-data-attachment-v1")) {
Mixins.addConfiguration("optifabric.compat.fabric-rendering-data.mixins.json");

if (isPresent("fabric-rendering-data-attachment-v1", ">0.3.0")) {
Expand Down Expand Up @@ -210,7 +216,11 @@ protected boolean isPresent() {
}

if (isPresent("fabric-screen-api-v1")) {
if (isPresent("minecraft", ">=1.20")) {
if (isPresent("fabric-screen-api-v1", ">=2.0.16")) {
//0.92.1 moved to use Mixin Extra so no longer an issue
} else if (isPresent("minecraft", ">=1.20.2")) {
Mixins.addConfiguration("optifabric.compat.fabric-screen-api.new5er-mixins.json");
} else if (isPresent("minecraft", ">=1.20")) {
Mixins.addConfiguration("optifabric.compat.fabric-screen-api.new4er-mixins.json");
} else if (isPresent("fabric-api", ">=0.81.0")) {
Mixins.addConfiguration("optifabric.compat.fabric-screen-api.new3er-mixins.json");
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 @@ -36,7 +36,7 @@
},
"depends": {
"fabricloader": ">=0.8.0",
"minecraft": ["1.16.1", "1.16.2", "1.16.3", "1.16.4", "1.16.5", "1.17-alpha.21.8.b", "1.17-beta.4", "1.17", "1.17.1", "1.18-beta.1", "1.18", "1.18.1", "1.18.2", "1.19", "1.19.1", "1.19.2", "1.19.3", "1.19.4", "1.20", "1.20.1"],
"minecraft": ["1.16.1", "1.16.2", "1.16.3", "1.16.4", "1.16.5", "1.17-alpha.21.8.b", "1.17-beta.4", "1.17", "1.17.1", "1.18-beta.1", "1.18", "1.18.1", "1.18.2", "1.19", "1.19.1", "1.19.2", "1.19.3", "1.19.4", "1.20", "1.20.1", "1.20.2", "1.20.4"],
"mm": ">=2.0"
},
"conflicts": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"parent": "optifabric.mixins.json",
"package": "me.modmuss50.optifabric.compat.fabricblockview.mixin",
"plugin": "me.modmuss50.optifabric.compat.fabricblockview.BlockViewMixinPlugin",
"mixins": [
"ChunkRendererRegionBuilderMixin"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"parent": "optifabric.mixins.json",
"package": "me.modmuss50.optifabric.compat.fabricscreenapi.mixin",
"plugin": "me.modmuss50.optifabric.compat.InterceptingMixinPlugin",
"mixins": [
"GameRendererNew5erMixin"
]
}

0 comments on commit d9a13f3

Please sign in to comment.