This revert commit 21144a7c

This commit is contained in:
coolGi
2023-08-16 19:38:49 +09:30
parent cc2340d1b9
commit c047996592
6 changed files with 219 additions and 105 deletions
@@ -31,7 +31,10 @@ import com.seibel.distanthorizons.core.dependencyInjection.ModAccessorInjector;
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.ISodiumAccessor;
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
import com.seibel.distanthorizons.coreapi.ModInfo;
import com.seibel.distanthorizons.fabric.wrappers.modAccessor.SodiumAccessor;
//import io.netty.buffer.ByteBuf;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
@@ -62,7 +65,7 @@ import org.lwjgl.opengl.GL15;
/**
* This handles all events sent to the client,
* and is the starting point for most of the mod.
*
*
* @author coolGi
* @author Ran
* @version 2023-7-27
@@ -75,7 +78,7 @@ public class FabricClientProxy
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
// TODO we shouldn't be filtering keys on the Forge/Fabric side, only in ClientApi
private static final int[] KEY_TO_CHECK_FOR = {GLFW.GLFW_KEY_F6, GLFW.GLFW_KEY_F8, GLFW.GLFW_KEY_P};
private static final int[] KEY_TO_CHECK_FOR = { GLFW.GLFW_KEY_F6, GLFW.GLFW_KEY_F8, GLFW.GLFW_KEY_P};
HashSet<Integer> previouslyPressKeyCodes = new HashSet<>();
@@ -83,7 +86,6 @@ public class FabricClientProxy
/**
* Registers Fabric Events
*
* @author Ran
*/
public void registerEvents()
@@ -91,6 +93,14 @@ public class FabricClientProxy
LOGGER.info("Registering Fabric Client Events");
//========================//
// register mod accessors //
//========================//
SodiumAccessor sodiumAccessor = (SodiumAccessor) ModAccessorInjector.INSTANCE.get(ISodiumAccessor.class);
//=============//
// tick events //
//=============//
@@ -135,7 +145,7 @@ public class FabricClientProxy
});
// (kinda) block place event
UseBlockCallback.EVENT.register((player, level, hand, hitResult) ->
UseBlockCallback.EVENT.register((player, level, hand, hitResult) ->
{
// if we have access to the server, use the chunk save event instead
if (MC.clientConnectedToDedicatedServer())
@@ -179,7 +189,6 @@ public class FabricClientProxy
//Define this in the MixinLevelRenderer so that it works with sodium without any changes to the code
// TODO: If all else is fine, can we remove these commented code
// Client Render Level
/*
WorldRenderEvents.AFTER_SETUP.register((renderContext) ->
{
if (sodiumAccessor != null)
@@ -212,11 +221,10 @@ public class FabricClientProxy
}
}
});
*/
// Debug keyboard event
// FIXME: Use better hooks so it doesn't trigger key press events in text boxes
ClientTickEvents.END_CLIENT_TICK.register(client ->
ClientTickEvents.END_CLIENT_TICK.register(client ->
{
if (client.player != null && !(Minecraft.getInstance().screen instanceof TitleScreen))
{
@@ -229,7 +237,7 @@ public class FabricClientProxy
//==================//
// networking event //
//==================//
// ClientPlayNetworking.registerGlobalReceiver(new ResourceLocation(ModInfo.NETWORKING_RESOURCE_NAMESPACE, ModInfo.MULTIVERSE_PLUGIN_NAMESPACE),
// (Minecraft client, ClientPacketListener handler, FriendlyByteBuf friendlyByteBuf, PacketSender responseSender) ->
// {
@@ -23,20 +23,19 @@ import com.mojang.blaze3d.vertex.PoseStack;
#if PRE_MC_1_19_4
import com.mojang.math.Matrix4f;
#else
import org.joml.Matrix4f;
#endif
import com.seibel.distanthorizons.common.wrappers.chunk.ChunkWrapper;
import com.seibel.distanthorizons.common.rendering.SeamlessOverdraw;
import com.seibel.distanthorizons.common.wrappers.McObjectConverter;
import com.seibel.distanthorizons.common.wrappers.world.ClientLevelWrapper;
import com.seibel.distanthorizons.core.api.internal.ClientApi;
import com.seibel.distanthorizons.coreapi.util.math.Mat4f;
import org.joml.Matrix4f;
#endif
import com.seibel.distanthorizons.common.wrappers.chunk.ChunkWrapper;
import com.seibel.distanthorizons.core.config.Config;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.renderer.LevelRenderer;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.world.level.lighting.LevelLightEngine;
import org.lwjgl.opengl.GL15;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
@@ -45,8 +44,6 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.nio.FloatBuffer;
/**
* This class is used to mix in my rendering code
* before Minecraft starts rendering blocks.
@@ -63,13 +60,13 @@ import java.nio.FloatBuffer;
@Mixin(LevelRenderer.class)
public class MixinLevelRenderer
{
@Shadow
private ClientLevel level;
@Unique
private static float previousPartialTicks = 0;
@Shadow
private ClientLevel level;
@Unique
private static float previousPartialTicks = 0;
// Inject rendering at first call to renderChunkLayer
// HEAD or RETURN
// Inject rendering at first call to renderChunkLayer
// HEAD or RETURN
#if PRE_MC_1_17_1
@Inject(at = @At("RETURN"), method = "renderSky(Lcom/mojang/blaze3d/vertex/PoseStack;F)V")
private void renderSky(PoseStack matrixStackIn, float partialTicks, CallbackInfo callback)
@@ -79,13 +76,12 @@ public class MixinLevelRenderer
previousPartialTicks = partialTicks;
}
#else
@Inject(method = "renderClouds", at = @At("HEAD"), cancellable = true)
public void renderClouds(PoseStack poseStack, Matrix4f projectionMatrix, float tickDelta, double cameraX, double cameraY, double cameraZ, CallbackInfo ci)
{
// get the partial ticks since renderChunkLayer doesn't
// have access to them
previousPartialTicks = tickDelta;
}
@Inject(method = "renderClouds", at = @At("HEAD"), cancellable = true)
public void renderClouds(PoseStack poseStack, Matrix4f projectionMatrix, float tickDelta, double cameraX, double cameraY, double cameraZ, CallbackInfo ci) {
// get the partial ticks since renderChunkLayer doesn't
// have access to them
previousPartialTicks = tickDelta;
}
#endif
#if PRE_MC_1_17_1
@@ -94,92 +90,56 @@ public class MixinLevelRenderer
cancellable = true)
private void renderChunkLayer(RenderType renderType, PoseStack matrixStackIn, double xIn, double yIn, double zIn, CallbackInfo callback)
#elif PRE_MC_1_19_4
@Inject(at = @At("HEAD"),
method = "renderChunkLayer(Lnet/minecraft/client/renderer/RenderType;Lcom/mojang/blaze3d/vertex/PoseStack;DDDLcom/mojang/math/Matrix4f;)V",
cancellable = true)
private void renderChunkLayer(RenderType renderType, PoseStack modelViewMatrixStack, double cameraXBlockPos, double cameraYBlockPos, double cameraZBlockPos, Matrix4f projectionMatrix, CallbackInfo callback)
@Inject(at = @At("HEAD"),
method = "renderChunkLayer(Lnet/minecraft/client/renderer/RenderType;Lcom/mojang/blaze3d/vertex/PoseStack;DDDLcom/mojang/math/Matrix4f;)V",
cancellable = true)
private void renderChunkLayer(RenderType renderType, PoseStack modelViewMatrixStack, double cameraXBlockPos, double cameraYBlockPos, double cameraZBlockPos, Matrix4f projectionMatrix, CallbackInfo callback)
#else
@Inject(at = @At("HEAD"),
method = "renderChunkLayer(Lnet/minecraft/client/renderer/RenderType;Lcom/mojang/blaze3d/vertex/PoseStack;DDDLorg/joml/Matrix4f;)V",
cancellable = true)
private void renderChunkLayer(RenderType renderType, PoseStack modelViewMatrixStack, double cameraXBlockPos, double cameraYBlockPos, double cameraZBlockPos, Matrix4f projectionMatrix, CallbackInfo callback)
@Inject(at = @At("HEAD"),
method = "renderChunkLayer(Lnet/minecraft/client/renderer/RenderType;Lcom/mojang/blaze3d/vertex/PoseStack;DDDLorg/joml/Matrix4f;)V",
cancellable = true)
private void renderChunkLayer(RenderType renderType, PoseStack modelViewMatrixStack, double cameraXBlockPos, double cameraYBlockPos, double cameraZBlockPos, Matrix4f projectionMatrix, CallbackInfo callback)
#endif
{
// get MC's model view and projection matrices
#if MC_1_16_5
// get the matrices from the OpenGL fixed pipeline
float[] mcProjMatrixRaw = new float[16];
GL15.glGetFloatv(GL15.GL_PROJECTION_MATRIX, mcProjMatrixRaw);
Mat4f mcProjectionMatrix = new Mat4f(mcProjMatrixRaw);
mcProjectionMatrix.transpose();
Mat4f mcModelViewMatrix = McObjectConverter.Convert(matrixStackIn.last().pose());
#else
// get the matrices directly from MC
Mat4f mcModelViewMatrix = McObjectConverter.Convert(modelViewMatrixStack.last().pose());
Mat4f mcProjectionMatrix = McObjectConverter.Convert(projectionMatrix);
#endif
// only render before solid blocks
if (renderType.equals(RenderType.solid()))
{
ClientApi.INSTANCE.renderLods(ClientLevelWrapper.getWrapper(level), mcModelViewMatrix, mcProjectionMatrix, previousPartialTicks);
// experimental proof-of-concept option
if (Config.Client.Advanced.Graphics.AdvancedGraphics.seamlessOverdraw.get())
{
float[] matrixFloatArray = SeamlessOverdraw.overwriteMinecraftNearFarClipPlanes(mcProjectionMatrix, previousPartialTicks);
#if MC_1_16_5
SeamlessOverdraw.applyLegacyProjectionMatrix(matrixFloatArray);
#elif PRE_MC_1_19_4
projectionMatrix.load(FloatBuffer.wrap(matrixFloatArray));
#else
projectionMatrix.set(matrixFloatArray);
#endif
}
}
// FIXME completely disables rendering when sodium is installed
if (Config.Client.Advanced.Debugging.lodOnlyMode.get())
{
callback.cancel();
callback.cancel();
}
}
}
@Redirect(method =
"Lnet/minecraft/client/renderer/LevelRenderer;" +
"renderLevel(Lcom/mojang/blaze3d/vertex/PoseStack;" +
"FJZLnet/minecraft/client/Camera;" +
"Lnet/minecraft/client/renderer/GameRenderer;" +
"Lnet/minecraft/client/renderer/LightTexture;" +
@Redirect(method =
"Lnet/minecraft/client/renderer/LevelRenderer;" +
"renderLevel(Lcom/mojang/blaze3d/vertex/PoseStack;" +
"FJZLnet/minecraft/client/Camera;" +
"Lnet/minecraft/client/renderer/GameRenderer;" +
"Lnet/minecraft/client/renderer/LightTexture;" +
#if PRE_MC_1_19_4
"Lcom/mojang/math/Matrix4f;)V"
#else
"Lorg/joml/Matrix4f;)V"
#endif
,
at = @At(
value = "INVOKE",
#if PRE_MC_1_20_1
target = "Lnet/minecraft/world/level/lighting/LevelLightEngine;runUpdates(IZZ)I"
#else
target = "Lnet/minecraft/world/level/lighting/LevelLightEngine;runLightUpdates()I"
#endif
))
private int callAfterRunUpdates(LevelLightEngine light #if PRE_MC_1_20_1 , int pos, boolean isQueueEmpty, boolean updateBlockLight #endif )
{
"Lcom/mojang/math/Matrix4f;)V"
#else
"Lorg/joml/Matrix4f;)V"
#endif
,
at = @At(
value = "INVOKE",
#if PRE_MC_1_20_1
target = "Lnet/minecraft/world/level/lighting/LevelLightEngine;runUpdates(IZZ)I"
#else
target = "Lnet/minecraft/world/level/lighting/LevelLightEngine;runLightUpdates()I"
#endif
))
private int callAfterRunUpdates(LevelLightEngine light #if PRE_MC_1_20_1 , int pos, boolean isQueueEmpty, boolean updateBlockLight #endif)
{
#if PRE_MC_1_20_1
int r = light.runUpdates(pos, isQueueEmpty, updateBlockLight);
int r = light.runUpdates(pos, isQueueEmpty, updateBlockLight);
#else
int r = light.runLightUpdates();
int r = light.runLightUpdates();
#endif
ChunkWrapper.syncedUpdateClientLightStatus();
return r;
}
ChunkWrapper.syncedUpdateClientLightStatus();
return r;
}
}
@@ -0,0 +1,138 @@
package com.seibel.distanthorizons.fabric.mixins.mods.sodium;
#if POST_MC_1_20_1
// Sodium 0.5
import com.mojang.blaze3d.vertex.PoseStack;
import com.seibel.distanthorizons.core.api.internal.ClientApi;
import com.seibel.distanthorizons.core.dependencyInjection.ModAccessorInjector;
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.ISodiumAccessor;
import com.seibel.distanthorizons.fabric.wrappers.modAccessor.SodiumAccessor;
import me.jellysquid.mods.sodium.client.gl.device.CommandList;
import me.jellysquid.mods.sodium.client.render.SodiumWorldRenderer;
import me.jellysquid.mods.sodium.client.render.chunk.ChunkRenderMatrices;
import me.jellysquid.mods.sodium.client.render.chunk.RenderSectionManager;
import me.jellysquid.mods.sodium.client.render.chunk.lists.SortedRenderLists;
import me.jellysquid.mods.sodium.client.render.chunk.region.RenderRegionManager;
import me.jellysquid.mods.sodium.client.render.chunk.terrain.DefaultTerrainRenderPasses;
import me.jellysquid.mods.sodium.client.render.chunk.terrain.TerrainRenderPass;
import net.minecraft.client.renderer.RenderType;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(RenderSectionManager.class)
public class MixinSodiumRenderer
{
@Unique SodiumAccessor accessor = null;
@Inject(remap = false, method = "renderLayer", at = @At(value = "INVOKE", target = "Lme/jellysquid/mods/sodium/client/render/chunk/ChunkRenderer;render(Lme/jellysquid/mods/sodium/client/render/chunk/ChunkRenderMatrices;Lme/jellysquid/mods/sodium/client/gl/device/CommandList;Lme/jellysquid/mods/sodium/client/render/chunk/lists/ChunkRenderListIterable;Lme/jellysquid/mods/sodium/client/render/chunk/terrain/TerrainRenderPass;Lme/jellysquid/mods/sodium/client/render/viewport/CameraTransform;)V", shift = At.Shift.AFTER))
private void injectDHLoDRendering(ChunkRenderMatrices matrices, TerrainRenderPass pass, double x, double y, double z, CallbackInfo ci)
{
if (accessor == null)
{
accessor = (SodiumAccessor)ModAccessorInjector.INSTANCE.get(ISodiumAccessor.class);
}
if (pass.equals(DefaultTerrainRenderPasses.SOLID))
{
//TODO: use matrices.modelView() and matrices.projection() instead of
// SodiumAccessor.mcModelViewMatrix,
// SodiumAccessor.mcProjectionMatrix,
ClientApi.INSTANCE.renderLods(accessor.levelWrapper,
accessor.mcModelViewMatrix,
accessor.mcProjectionMatrix,
accessor.partialTicks);
}
}
}
#elif POST_MC_1_17_1
// Sodium 0.3 to 0.4
import com.seibel.distanthorizons.core.api.internal.ClientApi;
import com.seibel.distanthorizons.core.dependencyInjection.ModAccessorInjector;
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.ISodiumAccessor;
import com.seibel.distanthorizons.fabric.wrappers.modAccessor.SodiumAccessor;
import me.jellysquid.mods.sodium.client.gl.device.CommandList;
import me.jellysquid.mods.sodium.client.render.SodiumWorldRenderer;
import me.jellysquid.mods.sodium.client.render.chunk.ChunkCameraContext;
import me.jellysquid.mods.sodium.client.render.chunk.ChunkRenderList;
import me.jellysquid.mods.sodium.client.render.chunk.ChunkRenderMatrices;
import me.jellysquid.mods.sodium.client.render.chunk.RegionChunkRenderer;
import me.jellysquid.mods.sodium.client.render.chunk.passes.BlockRenderPass;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(RegionChunkRenderer.class)
public class MixinSodiumRenderer
{
@Unique SodiumAccessor accessor = null;
@Inject(remap = false, method = "render", at = @At(value = "INVOKE", target = "Lme/jellysquid/mods/sodium/client/render/chunk/ShaderChunkRenderer;begin(Lme/jellysquid/mods/sodium/client/render/chunk/passes/BlockRenderPass;)V", shift = At.Shift.AFTER))
private void injectDHLoDRendering(ChunkRenderMatrices matrices, CommandList commandList, ChunkRenderList list, BlockRenderPass pass, ChunkCameraContext camera, CallbackInfo ci)
{
if (accessor == null)
{
accessor = (SodiumAccessor)ModAccessorInjector.INSTANCE.get(ISodiumAccessor.class);
}
if (pass.equals(BlockRenderPass.SOLID))
{
//TODO: use matrices.modelView() and matrices.projection() instead of
// SodiumAccessor.mcModelViewMatrix,
// SodiumAccessor.mcProjectionMatrix,
ClientApi.INSTANCE.renderLods(accessor.levelWrapper,
accessor.mcModelViewMatrix,
accessor.mcProjectionMatrix,
accessor.partialTicks);
}
}
}
#else
// Sodium 0.2 and under
import com.mojang.blaze3d.vertex.PoseStack;
import com.seibel.distanthorizons.core.api.internal.ClientApi;
import com.seibel.distanthorizons.core.config.Config;
import com.seibel.distanthorizons.core.dependencyInjection.ModAccessorInjector;
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.ISodiumAccessor;
import com.seibel.distanthorizons.fabric.wrappers.modAccessor.SodiumAccessor;
import me.jellysquid.mods.sodium.client.render.SodiumWorldRenderer;
import net.minecraft.client.renderer.RenderType;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(SodiumWorldRenderer.class)
public class MixinSodiumRenderer
{
@Unique SodiumAccessor accessor = null;
@Inject(method="drawChunkLayer", remap = false, at = @At("HEAD"))
private void drawChunkLayer(RenderType renderLayer, PoseStack matrixStack, double x, double y, double z, CallbackInfo callback)
{
if (this.accessor == null)
{
this.accessor = (SodiumAccessor) ModAccessorInjector.INSTANCE.get(ISodiumAccessor.class);
}
if (renderLayer == RenderType.solid())
{
ClientApi.INSTANCE.renderLods(this.accessor.levelWrapper,
this.accessor.mcModelViewMatrix,
this.accessor.mcProjectionMatrix,
this.accessor.partialTicks);
}
}
}
#endif
@@ -49,6 +49,11 @@ public class SodiumAccessor implements ISodiumAccessor
private final IWrapperFactory factory = SingletonInjector.INSTANCE.get(IWrapperFactory.class);
private final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
public IClientLevelWrapper levelWrapper;
public Mat4f mcModelViewMatrix;
public Mat4f mcProjectionMatrix;
public float partialTicks;
@Override
public String getModName()
{
@@ -125,7 +130,7 @@ public class SodiumAccessor implements ISodiumAccessor
#endif
/** A temporary overwrite for a config in sodium 0.5 to fix their terrain from showing, will be removed once a proper fix is added */
// TODO: This is fixed in the upcoming sodium 0.5.2, so remove it once it gets released
// FIXME
@Override
public void setFogOcclusion(boolean b)
{
@@ -18,7 +18,9 @@
"client.MixinLightmap",
"client.MixinOptionsScreen",
"client.MixinMinecraft",
"client.MixinTextureUtil"
"client.MixinTextureUtil",
"mods.sodium.MixinSodiumRenderer"
],
"server": [],
"injectors": {
@@ -91,7 +91,8 @@ public class MixinLevelRenderer
previousPartialTicks = partialTicks;
}
// TODO: Can we move this to forge's client proxy similarly to how fabric does it
#if PRE_MC_1_17_1
@Inject(at = @At("HEAD"),
method = "renderChunkLayer(Lnet/minecraft/client/renderer/RenderType;Lcom/mojang/blaze3d/vertex/PoseStack;DDD)V",