Merge branch 'main' of gitlab.com:jeseibel/minecraft-lod-mod

This commit is contained in:
James Seibel
2023-05-12 22:15:03 -05:00
17 changed files with 122 additions and 32 deletions
@@ -73,6 +73,8 @@ public class ClientLevelWrapper implements IClientLevelWrapper
ServerLevelWrapper foundLevelWrapper = null;
for (ServerLevel serverLevel : serverLevels)
{
// FIXME: This check is incorrect, even if there are more not "More than 1 level exists for a given dimension", it would still say it is
// This happens when both the overworld and end gets passed
if (foundLevelWrapper != null)
{
LOGGER.warn("More than 1 level exists for a given dimension. Defaulting to the first level.");
@@ -74,5 +74,4 @@ public class MixinFogRenderer {
#endif
}
}
}
@@ -16,6 +16,8 @@ import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
/**
* At the moment this is only used for the auto updater
*
* @author coolGi
*/
@Mixin(Minecraft.class)
@@ -35,10 +35,14 @@ import net.minecraft.Util;
@Mixin(Util.class)
public class MixinUtilBackgroundThread
{
private static boolean shouldApplyOverride() {
return FabricServerProxy.isGenerationThreadChecker != null && FabricServerProxy.isGenerationThreadChecker.get();
}
@Inject(method = "backgroundExecutor", at = @At("HEAD"), cancellable = true)
private static void overrideUtil$backgroundExecutor(CallbackInfoReturnable<ExecutorService> ci)
{
if (FabricServerProxy.isGenerationThreadChecker != null && FabricServerProxy.isGenerationThreadChecker.get())
if (shouldApplyOverride())
{
//ApiShared.LOGGER.info("util backgroundExecutor triggered");
ci.setReturnValue(new DummyRunExecutorService());
@@ -50,7 +54,7 @@ public class MixinUtilBackgroundThread
at = @At("HEAD"), cancellable = true)
private static void overrideUtil$wrapThreadWithTaskName(String string, Runnable r, CallbackInfoReturnable<Runnable> ci)
{
if (FabricServerProxy.isGenerationThreadChecker != null && FabricServerProxy.isGenerationThreadChecker.get())
if (shouldApplyOverride())
{
//ApiShared.LOGGER.info("util wrapThreadWithTaskName(Runnable) triggered");
ci.setReturnValue(r);
@@ -62,7 +66,7 @@ public class MixinUtilBackgroundThread
at = @At("HEAD"), cancellable = true)
private static void overrideUtil$wrapThreadWithTaskNameForSupplier(String string, Supplier<?> r, CallbackInfoReturnable<Supplier<?>> ci)
{
if (FabricServerProxy.isGenerationThreadChecker != null && FabricServerProxy.isGenerationThreadChecker.get())
if (shouldApplyOverride())
{
//ApiShared.LOGGER.info("util wrapThreadWithTaskName(Supplier) triggered");
ci.setReturnValue(r);
@@ -19,9 +19,11 @@
"client.MixinOptionsScreen",
"client.MixinMinecraft",
"client.MixinTextureUtil",
"mods.sodium.MixinSodiumChunkRenderer",
"mods.imm_ptl_core.MixinImmersivePortalsGameRenderer"
],
"server": [],
"injectors": {
"defaultRequire": 1
},
@@ -34,7 +34,7 @@ import com.seibel.lod.core.logging.DhLoggerBuilder;
import com.seibel.lod.core.wrapperInterfaces.modAccessor.IOptifineAccessor;
import com.seibel.lod.forge.wrappers.ForgeDependencySetup;
import com.seibel.lod.forge.modAccessor.OptifineAccessor;
import com.seibel.lod.forge.wrappers.modAccessor.OptifineAccessor;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.core.Direction;
@@ -46,7 +46,7 @@ public class ForgeServerProxy {
// ServerTickEvent (at end)
@SubscribeEvent
private void serverTickEvent(TickEvent.ServerTickEvent event) {
public void serverTickEvent(TickEvent.ServerTickEvent event) {
if (event.phase == TickEvent.Phase.END) {
if (isValidTime()) serverApi.serverTickEvent();
}
@@ -54,19 +54,19 @@ public class ForgeServerProxy {
// ServerWorldLoadEvent
@SubscribeEvent
private void dedicatedWorldLoadEvent(ServerStartedEvent event) {
public void dedicatedWorldLoadEvent(ServerStartedEvent event) {
if (isValidTime()) serverApi.serverLoadEvent(isDedicated);
}
// ServerWorldUnloadEvent
@SubscribeEvent
private void serverWorldUnloadEvent(ServerStoppingEvent event) {
public void serverWorldUnloadEvent(ServerStoppingEvent event) {
if (isValidTime()) serverApi.serverUnloadEvent();
}
// ServerLevelLoadEvent
@SubscribeEvent
private void serverLevelLoadEvent(WorldEvent.Load event) {
public void serverLevelLoadEvent(WorldEvent.Load event) {
if (isValidTime()) {
if (event.getWorld() instanceof ServerLevel) {
serverApi.serverLevelLoadEvent(getLevelWrapper((ServerLevel) event.getWorld()));
@@ -76,7 +76,7 @@ public class ForgeServerProxy {
// ServerLevelUnloadEvent
@SubscribeEvent
private void serverLevelUnloadEvent(WorldEvent.Unload event) {
public void serverLevelUnloadEvent(WorldEvent.Unload event) {
if (isValidTime()) {
if (event.getWorld() instanceof ServerLevel) {
serverApi.serverLevelUnloadEvent(getLevelWrapper((ServerLevel) event.getWorld()));
@@ -0,0 +1,51 @@
package com.seibel.lod.forge.mixins.client;
import com.seibel.lod.common.wrappers.world.ClientLevelWrapper;
import com.seibel.lod.core.api.internal.ClientApi;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.multiplayer.ClientPacketListener;
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(ClientPacketListener.class)
public class MixinClientPacketListener
{
@Shadow
private ClientLevel level;
/** THIS EXPLANATION IS WRITTEN BY FABRIC.
* An explanation why we unload entities during onGameJoin: (On in our remapping name case, handleLogin(TODO: CHECK))
* Proxies such as Waterfall may send another Game Join packet if entity meta rewrite is disabled, so we will cover ourselves.
* Velocity by default will send a Game Join packet when the player changes servers, which will create a new client world.
* Also anyone can send another GameJoinPacket at any time, so we need to watch out.
*/
@Inject(method = "handleLogin", at = @At("HEAD"))
void onHandleLoginStart(CallbackInfo ci)
{
// not the best way to notify Core that we are no longer in the previous world, but it will have to do for now
ClientApi.INSTANCE.onClientOnlyDisconnected();
}
@Inject(method = "handleLogin", at = @At("RETURN"))
void onHandleLoginEnd(CallbackInfo ci) { ClientApi.INSTANCE.onClientOnlyConnected(); }
@Inject(method = "handleRespawn", at = @At("HEAD"))
void onHandleRespawnStart(CallbackInfo ci) { ClientApi.INSTANCE.clientLevelUnloadEvent(ClientLevelWrapper.getWrapper(level)); }
@Inject(method = "handleRespawn", at = @At("RETURN"))
void onHandleRespawnEnd(CallbackInfo ci) { ClientApi.INSTANCE.clientLevelLoadEvent(ClientLevelWrapper.getWrapper(level)); }
@Inject(method = "cleanup", at = @At("HEAD"))
void onCleanupStart(CallbackInfo ci)
{
// TODO which unload method should be used? do we need both?
if (level != null)
{
ClientApi.INSTANCE.clientLevelUnloadEvent(ClientLevelWrapper.getWrapper(level));
}
}
}
@@ -42,13 +42,12 @@ import net.minecraft.world.level.material.FogType;
@Mixin(FogRenderer.class)
public class MixinFogRenderer
{
// Using this instead of Float.MAX_VALUE because Sodium don't like it. (and copy paste in case someone in forge don't like it)
public class MixinFogRenderer {
// Using this instead of Float.MAX_VALUE because Sodium don't like it.
private static final float A_REALLY_REALLY_BIG_VALUE = 420694206942069.F;
private static final float A_EVEN_LARGER_VALUE = 42069420694206942069.F;
@Inject(at = @At("RETURN"),
method = "setupFog(Lnet/minecraft/client/Camera;Lnet/minecraft/client/renderer/FogRenderer$FogMode;FZF)V",
remap = #if MC_1_16_5 true #else false #endif) // Remap messiness due to this being added by forge.
@@ -61,7 +60,7 @@ public class MixinFogRenderer
FogType fogTypes = camera.getFluidInCamera();
boolean cameraNotInFluid = fogTypes == FogType.NONE;
#endif
Entity entity = camera.getEntity();
boolean isSpecialFog = (entity instanceof LivingEntity) && ((LivingEntity) entity).hasEffect(MobEffects.BLINDNESS);
if (!isSpecialFog && cameraNotInFluid && fogMode == FogMode.FOG_TERRAIN
@@ -54,10 +54,10 @@ public class MixinLevelRenderer
{
@Shadow
private ClientLevel level;
@Unique
private static float previousPartialTicks = 0;
// TODO: Is there any reason why this is here? Can it be deleted?
public MixinLevelRenderer() {
throw new NullPointerException("Null cannot be cast to non-null type.");
}
@@ -100,6 +100,7 @@ public class MixinLevelRenderer
previousPartialTicks = tickDelta;
}
// TODO: Can we move this o forge's client proxy simmilar to how fabric does it
@Inject(at = @At("HEAD"),
method = "renderChunkLayer(Lnet/minecraft/client/renderer/RenderType;Lcom/mojang/blaze3d/vertex/PoseStack;DDDLcom/mojang/math/Matrix4f;)V",
cancellable = true)
@@ -16,6 +16,8 @@ import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
/**
* At the moment this is only used for the auto updater
*
* @author coolGi
*/
@Mixin(Minecraft.class)
@@ -0,0 +1,27 @@
package com.seibel.lod.forge.mixins.client;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.platform.TextureUtil;
import com.seibel.lod.core.config.Config;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
/**
* Sets Minecraft's LOD Bias (looks similar to mipmaps)
*
* @author coolGi
*/
@Mixin(TextureUtil.class)
public class MixinTextureUtil {
@Redirect(method = "Lcom/mojang/blaze3d/platform/TextureUtil;prepareImage(Lcom/mojang/blaze3d/platform/NativeImage$InternalGlFormat;IIII)V",
at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/platform/GlStateManager;_texParameter(IIF)V", remap=false))
private static void setLodBias(int target, int pname, float param) {
float biasValue = Config.Client.Graphics.AdvancedGraphics.lodBias.get().floatValue();
if (biasValue != 0) {
// The target is GL11.GL_TEXTURE_2D
// And the pname is GL14.GL_TEXTURE_LOD_BIAS
GlStateManager._texParameter(target, pname, biasValue);
}
}
}
@@ -35,15 +35,14 @@ import net.minecraft.Util;
@Mixin(Util.class)
public class MixinUtilBackgroundThread
{
private static boolean shouldApplyOverride() {
return DependencySetupDoneCheck.getIsCurrentThreadDistantGeneratorThread.get();
return DependencySetupDoneCheck.isDone && DependencySetupDoneCheck.getIsCurrentThreadDistantGeneratorThread.get();
}
@Inject(method = "backgroundExecutor", at = @At("HEAD"), cancellable = true)
private static void overrideUtil$backgroundExecutor(CallbackInfoReturnable<ExecutorService> ci)
{
if (DependencySetupDoneCheck.isDone && shouldApplyOverride())
if (shouldApplyOverride())
{
//ApiShared.LOGGER.info("util backgroundExecutor triggered");
ci.setReturnValue(new DummyRunExecutorService());
@@ -55,7 +54,7 @@ public class MixinUtilBackgroundThread
at = @At("HEAD"), cancellable = true)
private static void overrideUtil$wrapThreadWithTaskName(String string, Runnable r, CallbackInfoReturnable<Runnable> ci)
{
if (DependencySetupDoneCheck.isDone && shouldApplyOverride())
if (shouldApplyOverride())
{
//ApiShared.LOGGER.info("util wrapThreadWithTaskName(Runnable) triggered");
ci.setReturnValue(r);
@@ -67,7 +66,7 @@ public class MixinUtilBackgroundThread
at = @At("HEAD"), cancellable = true)
private static void overrideUtil$wrapThreadWithTaskNameForSupplier(String string, Supplier<?> r, CallbackInfoReturnable<Supplier<?>> ci)
{
if (DependencySetupDoneCheck.isDone && shouldApplyOverride())
if (shouldApplyOverride())
{
//ApiShared.LOGGER.info("util wrapThreadWithTaskName(Supplier) triggered");
ci.setReturnValue(r);
@@ -21,7 +21,7 @@ package com.seibel.lod.forge.wrappers;
import com.seibel.lod.core.dependencyInjection.SingletonInjector;
import com.seibel.lod.core.wrapperInterfaces.modAccessor.IModChecker;
import com.seibel.lod.forge.modAccessor.ModChecker;
import com.seibel.lod.forge.wrappers.modAccessor.ModChecker;
/**
* Binds all necessary dependencies so we
@@ -17,7 +17,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.seibel.lod.forge.modAccessor;
package com.seibel.lod.forge.wrappers.modAccessor;
import com.seibel.lod.core.wrapperInterfaces.modAccessor.IModChecker;
import net.minecraftforge.fml.ModList;
@@ -17,7 +17,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.seibel.lod.forge.modAccessor;
package com.seibel.lod.forge.wrappers.modAccessor;
import java.util.HashSet;
@@ -3,18 +3,20 @@
"minVersion": "0.8",
"package": "com.seibel.lod.forge.mixins",
"mixins": [
"server.unsafe.MixinThreadingDetector",
"server.unsafe.MixinThreadingDetector",
"server.MixinUtilBackgroundThread",
"server.MixinChunkGenerator",
"server.MixinTFChunkGenerator"
],
"client": [
"client.MixinDebugScreenOverlay",
"client.MixinFogRenderer",
"client.MixinGameRenderer",
"client.MixinLevelRenderer",
"client.MixinLightmap",
"client.MixinOptionsScreen"
"client.MixinClientPacketListener",
"client.MixinDebugScreenOverlay",
"client.MixinFogRenderer",
"client.MixinGameRenderer",
"client.MixinLevelRenderer",
"client.MixinLightmap",
"client.MixinOptionsScreen",
"client.MixinTextureUtil"
],
"server": [],
"plugin": "com.seibel.lod.forge.mixins.ForgeMixinPlugin"