Skip to content

Commit

Permalink
make mixins forge compatible
Browse files Browse the repository at this point in the history
fix fabric resource loading in release
modloader name in window title
  • Loading branch information
fayer3 committed Sep 2, 2022
1 parent 18270df commit d72dfc5
Show file tree
Hide file tree
Showing 22 changed files with 66 additions and 49 deletions.
1 change: 0 additions & 1 deletion .architectury-transformer/debug.log

This file was deleted.

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ classes/
.metadata
.vscode
.settings
*.launch
*.launch
.architectury-transformer/
5 changes: 2 additions & 3 deletions common/src/main/java/org/vivecraft/CommonDataHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ public class CommonDataHolder {
public boolean resourcePacksChanged;
public final String minecriftVerString;

//TODO add loader name
public CommonDataHolder() {
if (VRState.checkVR()) {
minecriftVerString = "Vivecraft 1.18.2 jrbudda-VR-fabric-a1";
minecriftVerString = "Vivecraft 1.18.2 jrbudda-VR-" + Xplat.getModloader() + "-a1";
} else {
minecriftVerString = "Vivecraft 1.18.2 jrbudda-NONVR-fabric-a1";
minecriftVerString = "Vivecraft 1.18.2 jrbudda-NONVR-" + Xplat.getModloader() + "-a1";
}
}

Expand Down
5 changes: 5 additions & 0 deletions common/src/main/java/org/vivecraft/Xplat.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,9 @@ static Path getConfigPath(String fileName) {
static boolean isDedicatedServer() {
return false;
}

@ExpectPlatform
static String getModloader() {
return "";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ private static int size(int i) {
}

//Change the limit of textures to 32
@ModifyConstant(constant = @Constant(intValue = 12),method = "_getTextureId", remap = false)
@ModifyConstant(constant = @Constant(intValue = 12),method = "_getTextureId")
private static int properId(int i) {
return RenderSystemAccessor.getShaderTextures().length;
}
Expand All @@ -29,7 +29,8 @@ private static int properId(int i) {
* @author
* @reason
*/
@Overwrite(remap = false)
// do remap because of forge
@Overwrite
public static void _blendFuncSeparate(int i, int j, int k, int l) {
RenderSystem.assertOnRenderThread();
if (j == GlStateManager.SourceFactor.SRC_ALPHA.value && j == GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA.value && k == GlStateManager.SourceFactor.ONE.value && l == GlStateManager.DestFactor.ZERO.value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ public abstract class WindowVRMixin {
public abstract int getScreenHeight();

@Redirect(at = @At(value = "INVOKE", target = "Lorg/lwjgl/glfw/GLFW;glfwSetFramebufferSizeCallback(JLorg/lwjgl/glfw/GLFWFramebufferSizeCallbackI;)Lorg/lwjgl/glfw/GLFWFramebufferSizeCallback;", remap = false),
method = "<init>(Lcom/mojang/blaze3d/platform/WindowEventHandler;Lcom/mojang/blaze3d/platform/ScreenManager;Lcom/mojang/blaze3d/platform/DisplayData;Ljava/lang/String;Ljava/lang/String;)V", remap = false)
method = "<init>(Lcom/mojang/blaze3d/platform/WindowEventHandler;Lcom/mojang/blaze3d/platform/ScreenManager;Lcom/mojang/blaze3d/platform/DisplayData;Ljava/lang/String;Ljava/lang/String;)V")
public GLFWFramebufferSizeCallback removebuffer(long l, GLFWFramebufferSizeCallbackI cl) {
return null;
}

@Redirect(method = "updateVsync", at = @At(value = "INVOKE", target = "Lorg/lwjgl/glfw/GLFW;glfwSwapInterval(I)V"), remap = false)
@Redirect(method = "updateVsync", at = @At(value = "INVOKE", target = "Lorg/lwjgl/glfw/GLFW;glfwSwapInterval(I)V"))
public void disableSwap(int interval) {
GLFW.glfwSwapInterval(0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@

@Mixin(RenderSystem.class)
public interface RenderSystemAccessor {
@Accessor(remap = false)
static int[] getShaderTextures() {

// needs remap because of forge
@Accessor
public static int[] getShaderTextures(){
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
@Mixin(RenderSystem.class)
public class RenderSystemVRMixin {

@Inject(at = @At("HEAD"), method = "defaultBlendFunc", cancellable = true, remap = false)
// do remap because of forge
@Inject(at = @At("HEAD"), method = "defaultBlendFunc", cancellable = true)
private static void defaultBlendFunc(CallbackInfo ci) {
blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
ci.cancel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ public void renderVRHotbarRight(Gui instance, PoseStack poseStack, int x, int y,
}
}

@Inject(at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderSystem;disableBlend()V", remap = false), method = "renderHotbar")
// do remap because of forge
@Inject(at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderSystem;disableBlend()V"), method = "renderHotbar")
public void renderVive(float f, PoseStack poseStack, CallbackInfo ci){
this.renderViveHudIcons(poseStack);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ public void login(ClientboundLoginPacket p_105030_, CallbackInfo callback) {
ClientDataHolder.getInstance().vrPlayer.teleportWarningTimer = 200;
}

@Redirect(at = @At(value = "NEW", target = "Lnet/minecraft/client/player/KeyboardInput;<init>(Lnet/minecraft/client/Options;)V"), method = "handleLogin")
public KeyboardInput login(Options options) {
return null;
}

@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/MultiPlayerGameMode;adjustPlayer(Lnet/minecraft/world/entity/player/Player;)V"), method = "handleLogin")
public void readdInput(ClientboundLoginPacket clientboundLoginPacket, CallbackInfo ci) {
this.minecraft.player.input = new VivecraftMovementInput(this.minecraft.options);
Expand Down Expand Up @@ -105,19 +100,14 @@ public void chat(ClientboundChatPacket clientboundChatPacket, CallbackInfo ci) {
@Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/player/LocalPlayer;resetPos()V"), method = "handleRespawn")
public void sync(LocalPlayer instance) {
instance.resetPos();
((PlayerExtension)instance).updateSyncFields(this.minecraft.player);
// ((PlayerExtension)instance).updateSyncFields(this.minecraft.player);
}

@Redirect(at = @At(value = "NEW", target = "Lnet/minecraft/client/player/KeyboardInput;<init>(Lnet/minecraft/client/Options;)V"), method = "handleRespawn")
public KeyboardInput respawn(Options options) {
@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/MultiPlayerGameMode;adjustPlayer(Lnet/minecraft/world/entity/player/Player;)V", shift = At.Shift.BEFORE), method = "handleRespawn")
public void readdInput2(ClientboundRespawnPacket clientboundRespawnPacket, CallbackInfo ci) {
ClientNetworkHelper.resetServerSettings();
ClientNetworkHelper.sendVersionInfo();
ClientDataHolder.getInstance().vrPlayer.teleportWarningTimer = 200;
return null;
}

@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/MultiPlayerGameMode;adjustPlayer(Lnet/minecraft/world/entity/player/Player;)V", shift = At.Shift.BEFORE), method = "handleRespawn")
public void readdInput2(ClientboundRespawnPacket clientboundRespawnPacket, CallbackInfo ci) {
this.minecraft.player.input = new VivecraftMovementInput(this.minecraft.options);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,13 @@ public void overridePose(CallbackInfo ci) {
ClientDataHolder.getInstance().vrPlayer.doPermanantLookOverride((LocalPlayer) (Object) this, ClientDataHolder.getInstance().vrPlayer.vrdata_world_pre);
}

/* TODO: not working, is this needed?
//TODO verify
@ModifyVariable(at = @At("STORE"), ordinal = 3, method = "sendPosition")
public boolean changeFlag(boolean b) {
return this.teleported || b;
}
*/

@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/player/LocalPlayer;isPassenger()Z", shift = At.Shift.BEFORE), method = "sendPosition")
public void passenger(CallbackInfo ci) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ public long active() {
return this.lastActiveTime;
}

@Inject(at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderSystem;viewport(IIII)V", shift = Shift.AFTER, remap = false), method = "Lnet/minecraft/client/renderer/GameRenderer;render(FJZ)V")
@Inject(at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderSystem;viewport(IIII)V", shift = Shift.AFTER), method = "Lnet/minecraft/client/renderer/GameRenderer;render(FJZ)V")
public void matrix(float partialTicks, long nanoTime, boolean renderWorldIn, CallbackInfo info) {
this.resetProjectionMatrix(this.getProjectionMatrix(minecraft.options.fov));
RenderSystem.getModelViewStack().setIdentity();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public void interactOutline(PoseStack poseStack, float f, long l, boolean bl, Ca
}
}

@Inject(at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderSystem;applyModelViewMatrix()V", ordinal = 1, remap = false), method = "renderLevel")
@Inject(at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderSystem;applyModelViewMatrix()V", ordinal = 1), method = "renderLevel")
public void renderBukkake(PoseStack poseStack, float f, long l, boolean bl, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f matrix4f, CallbackInfo ci) {
this.level.getProfiler().popPush("render bukkake");
}
Expand Down
1 change: 0 additions & 1 deletion common/src/main/resources/vivecraft.nonvr.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"blaze3d.pipeline.RenderTargetMixin",
"blaze3d.systems.RenderSystemAccessor",
"client.MinecraftMixin",
"client.OptionMixin",
"client.main.MainMixin",
"client.multiplayer.ClientPacketListenerMixin",
"client.player.AbstractClientPlayerMixin",
Expand Down
4 changes: 3 additions & 1 deletion fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ dependencies {
modRuntimeOnly(fabricApi.module("fabric-key-binding-api-v1", rootProject.fabric_api_version))//temp sodium
modRuntimeOnly(fabricApi.module("fabric-rendering-fluids-v1", rootProject.fabric_api_version))//temp sodium
modRuntimeOnly(fabricApi.module("fabric-rendering-data-attachment-v1", rootProject.fabric_api_version))//temp sodium
modRuntimeOnly(fabricApi.module("fabric-resource-loader-v0", rootProject.fabric_api_version))//temp sodium

modRuntimeOnly 'org.anarres:jcpp:1.4.14'//temp iris

modCompileOnly 'com.github.2No2Name:McTester:v0.2.4' //temp lithium
modCompileOnly 'com.github.astei:lazydfu:0.1.2' //temp lithium

// needed for resource loading
include(modImplementation(fabricApi.module("fabric-resource-loader-v0", rootProject.fabric_api_version)))

include "com.github.Fallen-Breath:conditional-mixin:v0.3.1"

include("org.lwjgl:lwjgl-ovr:3.2.2:natives-windows")
Expand Down
4 changes: 4 additions & 0 deletions fabric/src/main/java/org/vivecraft/fabric/XplatImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ public static Path getConfigPath(String fileName) {
public static boolean isDedicatedServer() {
return FabricLoader.getInstance().getEnvironmentType().equals(EnvType.SERVER);
}

public static String getModloader() {
return "fabric";
}
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,17 @@
package org.vivecraft.mixin.client;
package org.vivecraft.fabric.mixin.client;

import org.vivecraft.ClientDataHolder;
import net.minecraft.client.*;
import net.minecraft.network.chat.Component;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;


@Mixin(Option.class)
public abstract class OptionMixin {
public abstract class FabricOptionVRMixin {

@Final
@Shadow
private static Component GRAPHICS_TOOLTIP_FAST;

@Final
@Shadow
private static Component GRAPHICS_TOOLTIP_FANCY;

@Final
@Shadow
private static Component GRAPHICS_TOOLTIP_FABULOUS;

@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/LevelRenderer;allChanged()V"), method = "method_32552", remap = false)
@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/LevelRenderer;allChanged()V", remap = true), method = "method_32552", remap = false)
private static void reinit(Options options, Option option, GraphicsStatus graphicsStatus, CallbackInfo ci) {
ClientDataHolder.getInstance().vrRenderer.reinitFrameBuffers("gfx setting change");
}
Expand Down
1 change: 1 addition & 0 deletions fabric/src/main/resources/vivecraft.vr.fabric.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

],
"client": [
"client.FabricOptionVRMixin",
"FabricMinecraftVRMixin",
"FabricLevelRendererVRMixin",
"FabricGameRendererVRMixin"
Expand Down
4 changes: 4 additions & 0 deletions forge/src/main/java/org/vivecraft/forge/XplatImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ public static Path getConfigPath(String fileName) {
public static boolean isDedicatedServer() {
return FMLEnvironment.dist == Dist.DEDICATED_SERVER;
}

public static String getModloader() {
return "forge";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@Mixin(ForgeIngameGui.class)
public abstract class ForgeIngameGuiVRMixin {

@Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;useFancyGraphics()Z"), method = "lambda$static$0", remap = false)
@Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;useFancyGraphics()Z", remap = true), method = "lambda$static$0", remap = false)
private static boolean noVignette() {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.vivecraft.forge.mixin.client;

import net.minecraft.client.GraphicsStatus;
import net.minecraft.client.Option;
import net.minecraft.client.Options;
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.CallbackInfo;
import org.vivecraft.ClientDataHolder;

@Mixin(Option.class)
public class ForgeOptionVRMixin {

@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/LevelRenderer;allChanged()V", remap = true), method = "m_193661_", remap = false)
private static void reinit(Options options, Option option, GraphicsStatus graphicsStatus, CallbackInfo ci) {
ClientDataHolder.getInstance().vrRenderer.reinitFrameBuffers("gfx setting change");
}

}
1 change: 1 addition & 0 deletions forge/src/main/resources/vivecraft.vr.forge.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

],
"client": [
"client.ForgeOptionVRMixin",
"ForgeMinecraftVRMixin",
"ForgeLevelRendererVRMixin",
"ForgeIngameGuiVRMixin",
Expand Down

0 comments on commit d72dfc5

Please sign in to comment.