Add MC 1.21.3 support for Neoforge (no fabric)

This commit is contained in:
James Seibel
2024-11-02 11:21:03 -05:00
parent 8eba8cb40b
commit 8be161b381
50 changed files with 1195 additions and 671 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
plugins {
id "fabric-loom" version "1.6-SNAPSHOT"
id "fabric-loom" version "1.7-SNAPSHOT"
}
loom {
@@ -23,6 +23,7 @@ import com.seibel.distanthorizons.core.config.Config;
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
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;
@@ -35,35 +36,42 @@ import net.minecraft.client.renderer.FogRenderer.FogMode;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
#if MC_VER < MC_1_17_1
import net.minecraft.world.level.material.FluidState;
#elif MC_VER < MC_1_21_3
import net.minecraft.world.level.material.FogType;
#else
import net.minecraft.world.level.material.FogType;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import com.mojang.blaze3d.shaders.FogShape;
import net.minecraft.client.renderer.FogParameters;
import org.joml.Vector4f;
#endif
@Mixin(FogRenderer.class)
public class MixinFogRenderer
{
// Using this instead of Float.MAX_VALUE because Sodium don't like it.
@Unique
private static final float A_REALLY_REALLY_BIG_VALUE = 420694206942069.F;
@Unique
private static final float A_EVEN_LARGER_VALUE = 42069420694206942069.F;
@Inject(at = @At("RETURN"), method = "setupFog")
#if MC_VER < MC_1_19_2
@Inject(at = @At("RETURN"), method = "setupFog")
private static void disableSetupFog(Camera camera, FogMode fogMode, float f, boolean bl, CallbackInfo callback)
{
#else
#elif MC_VER < MC_1_21_3
@Inject(at = @At("RETURN"), method = "setupFog")
private static void disableSetupFog(Camera camera, FogMode fogMode, float f, boolean bl, float g, CallbackInfo callback)
{
#else
@Inject(at = @At("RETURN"), method = "setupFog", cancellable = true)
private static void disableSetupFog(Camera camera, FogMode fogMode, Vector4f vector4f, float f, boolean bl, float g, CallbackInfoReturnable<FogParameters> callback)
#endif
#if MC_VER < MC_1_17_1
FluidState fluidState = camera.getFluidInCamera();
boolean cameraNotInFluid = fluidState.isEmpty();
#else
FogType fogTypes = camera.getFluidInCamera();
boolean cameraNotInFluid = fogTypes == FogType.NONE;
#endif
{
boolean cameraNotInFluid = cameraNotInFluid(camera);
Entity entity = camera.getEntity();
boolean isSpecialFog = (entity instanceof LivingEntity) && ((LivingEntity) entity).hasEffect(MobEffects.BLINDNESS);
@@ -74,11 +82,27 @@ public class MixinFogRenderer
#if MC_VER < MC_1_17_1
RenderSystem.fogStart(A_REALLY_REALLY_BIG_VALUE);
RenderSystem.fogEnd(A_EVEN_LARGER_VALUE);
#else
#elif MC_VER < MC_1_21_3
RenderSystem.setShaderFogStart(A_REALLY_REALLY_BIG_VALUE);
RenderSystem.setShaderFogEnd(A_EVEN_LARGER_VALUE);
#else
callback.setReturnValue(FogParameters.NO_FOG);
#endif
}
}
@Unique
private static boolean cameraNotInFluid(Camera camera)
{
#if MC_VER < MC_1_17_1
FluidState fluidState = camera.getFluidInCamera();
boolean cameraNotInFluid = fluidState.isEmpty();
#else
FogType fogTypes = camera.getFluidInCamera();
boolean cameraNotInFluid = fogTypes == FogType.NONE;
#endif
return cameraNotInFluid;
}
}
@@ -1,58 +0,0 @@
package com.seibel.distanthorizons.fabric.mixins.client;
import com.seibel.distanthorizons.common.wrappers.DependencySetupDoneCheck;
import com.seibel.distanthorizons.core.api.internal.ClientApi;
import net.minecraft.client.renderer.GameRenderer;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
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;
@Mixin(GameRenderer.class)
public class MixinGameRenderer
{
private static final Logger LOGGER = LogManager.getLogger(MixinGameRenderer.class.getSimpleName());
#if MC_VER >= MC_1_17_1
// FIXME: This I think will dup multiple renderStartupEvent calls...
@Inject(method = {"reloadShaders", "preloadUiShader"}, at = @At("TAIL"))
public void onStartupShaders(CallbackInfo ci)
{
LOGGER.info("Starting up renderer (fabric)");
if (!DependencySetupDoneCheck.isDone)
{
LOGGER.warn("Dependency setup is not done yet, skipping renderer this startup event!");
return;
}
ClientApi.INSTANCE.rendererStartupEvent();
}
@Inject(method = "shutdownShaders", at = @At("HEAD"))
public void onShutdownShaders(CallbackInfo ci)
{
LOGGER.info("Shutting down renderer (fabric)");
if (!DependencySetupDoneCheck.isDone)
{
LOGGER.warn("Dependency setup is not done yet, skipping renderer this shutdown event!");
return;
}
ClientApi.INSTANCE.rendererShutdownEvent();
}
#else
// FIXME: on 1.16 we dont have stuff for reloading/shutting down shaders
// FIXME: This I think will dup multiple renderStartupEvent calls...
@Inject(method = {"loadEffect"}, at = @At("TAIL"))
public void onStartupShaders(CallbackInfo ci) {
ClientApi.INSTANCE.rendererStartupEvent();
}
@Inject(method = "shutdownEffect", at = @At("HEAD"))
public void onShutdownShaders(CallbackInfo ci) {
ClientApi.INSTANCE.rendererShutdownEvent();
}
#endif
}
@@ -111,16 +111,22 @@ public class MixinLevelRenderer
mcProjectionMatrix.setIdentity();
#endif
// TODO move this into a common place
float frameTime;
#if MC_VER < MC_1_21_1
frameTime = Minecraft.getInstance().getFrameTime();
#elif MC_VER < MC_1_21_3
frameTime = Minecraft.getInstance().getTimer().getRealtimeDeltaTicks();
#else
frameTime = Minecraft.getInstance().deltaTracker.getRealtimeDeltaTicks();
#endif
if (renderType.equals(RenderType.translucent()))
{
ClientApi.INSTANCE.renderDeferredLods(ClientLevelWrapper.getWrapper(this.level),
mcModelViewMatrix,
mcProjectionMatrix,
#if MC_VER < MC_1_21_1
Minecraft.getInstance().getFrameTime()
#else
Minecraft.getInstance().getTimer().getRealtimeDeltaTicks()
#endif
frameTime
);
}
@@ -19,9 +19,6 @@
package com.seibel.distanthorizons.fabric.mixins.client;
import com.mojang.blaze3d.platform.NativeImage;
import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftRenderWrapper;
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
@@ -35,13 +32,22 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
#if MC_VER < MC_1_21_3
import com.mojang.blaze3d.platform.NativeImage;
#else
import com.mojang.blaze3d.pipeline.TextureTarget;
#endif
@Mixin(LightTexture.class)
public class MixinLightTexture
{
@Shadow
@Final
@Shadow
@Final
#if MC_VER < MC_1_21_3
private NativeImage lightPixels;
#else
private TextureTarget target;
#endif
@Inject(method = "updateLightTexture(F)V", at = @At("RETURN"))
public void updateLightTexture(float partialTicks, CallbackInfo ci)
@@ -52,8 +58,14 @@ public class MixinLightTexture
return;
}
IClientLevelWrapper clientLevel = mc.getWrappedClientLevel();
#if MC_VER < MC_1_21_3
MinecraftRenderWrapper.INSTANCE.updateLightmap(this.lightPixels, clientLevel);
#else
MinecraftRenderWrapper.INSTANCE.setLightmapId(this.target.getColorTextureId(), clientLevel);
#endif
}
}
@@ -31,8 +31,11 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
#if MC_VER >= MC_1_21_1
#if MC_VER < MC_1_21_1
#elif MC_VER < MC_1_21_3
import net.minecraft.world.level.portal.DimensionTransition;
#else
import net.minecraft.world.level.portal.TeleportTransition;
#endif
@@ -54,23 +57,29 @@ public class MixinServerPlayer implements IMixinServerPlayer
{ this.dimensionChangeDestination = dimensionChangeDestination; }
#endif
#if MC_VER < MC_1_21_1
@Inject(at = @At("HEAD"), method = "changeDimension")
public void changeDimension(ServerLevel destination, CallbackInfoReturnable<Entity> cir)
{ this.dimensionChangeDestination = destination; }
#elif MC_VER < MC_1_21_3
@Inject(at = @At("HEAD"), method = "changeDimension")
#if MC_VER >= MC_1_21_1
public void changeDimension(DimensionTransition dimensionTransition, CallbackInfoReturnable<Entity> cir)
{ this.dimensionChangeDestination = dimensionTransition.newLevel(); }
#else
public void changeDimension(ServerLevel destination, CallbackInfoReturnable<Entity> cir)
{ this.dimensionChangeDestination = destination; }
@Inject(at = @At("HEAD"), method = "teleport")
public void changeDimension(TeleportTransition teleportTransition, CallbackInfoReturnable<ServerPlayer> cir)
{ this.dimensionChangeDestination = teleportTransition.newLevel(); }
#endif
#if MC_VER >= MC_1_20_1
@Inject(at = @At("RETURN"), method = "setServerLevel")
public void setServerLevel(ServerLevel level, CallbackInfo ci)
{ this.dimensionChangeDestination = null; }
#elif MC_VER >= MC_1_17_1
#if MC_VER < MC_1_17_1
#elif MC_VER < MC_1_20_1
@Inject(at = @At("RETURN"), method = "setLevel")
public void setLevel(ServerLevel level, CallbackInfo ci)
{ this.dimensionChangeDestination = null; }
#else
@Inject(at = @At("RETURN"), method = "setServerLevel")
public void setServerLevel(ServerLevel level, CallbackInfo ci)
{ this.dimensionChangeDestination = null; }
#endif
}
@@ -0,0 +1,75 @@
/*
* This file is part of the Distant Horizons mod
* licensed under the GNU LGPL v3 License.
*
* Copyright (C) 2020-2023 James Seibel
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.seibel.distanthorizons.fabric.mixins.server;
import org.spongepowered.asm.mixin.Mixin;
#if MC_VER < MC_1_21_3
/**
* {@link MixinUtilBackgroundThread} was used for versions before 1.21.3
* This is just a dummy class/mixin to make the compiler happy.
*
* @see MixinUtilBackgroundThread
*/
@Mixin(net.minecraft.Util.class) // TODO we should allow version specific mixins so we don't have to create dummy mixins that exist for all MC versions
public class MixinTracingExecutor
{
}
#else
import com.seibel.distanthorizons.common.wrappers.DependencySetupDoneCheck;
import com.seibel.distanthorizons.core.util.objects.RunOnThisThreadExecutorService;
import net.minecraft.TracingExecutor;
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 java.util.concurrent.Executor;
/**
* This is needed for DH's world gen so we can run
* world gen on our own threads instead of using MC thread pools.
*
* @see MixinUtilBackgroundThread
* @see RunOnThisThreadExecutorService
*/
@Mixin(TracingExecutor.class)
public class MixinTracingExecutor
{
// TODO put in a common location
private static boolean isWorldGenThread()
{ return DependencySetupDoneCheck.isDone && DependencySetupDoneCheck.getIsCurrentThreadDistantGeneratorThread.get(); }
// replaced with TracingExecutor in MC 1.21.3+
@Inject(method = "forName(Ljava/lang/String;)Ljava/util/concurrent/Executor;", at = @At("HEAD"), cancellable = true)
private void forName(String executorName, CallbackInfoReturnable<Executor> ci)
{
if (isWorldGenThread())
{
// run this task on the current DH thread instead of a new MC thread
ci.setReturnValue(new RunOnThisThreadExecutorService());
}
}
}
#endif
@@ -19,60 +19,81 @@
package com.seibel.distanthorizons.fabric.mixins.server;
import java.util.concurrent.ExecutorService;
import java.util.function.Supplier;
import com.seibel.distanthorizons.fabric.FabricServerProxy;
import com.seibel.distanthorizons.common.wrappers.DependencySetupDoneCheck;
import com.seibel.distanthorizons.core.util.objects.RunOnThisThreadExecutorService;
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 com.seibel.distanthorizons.core.util.objects.DummyRunExecutorService;
import net.minecraft.Util;
import java.util.concurrent.ExecutorService;
#if MC_VER < MC_1_16_5
#elif MC_VER < MC_1_21_3
import java.util.function.Supplier;
#else
#endif
/**
* This is needed for DH's world gen so we can run
* world gen on our own threads instead of using MC thread pools.
*
* @see MixinTracingExecutor
* @see RunOnThisThreadExecutorService
*/
@Mixin(Util.class)
public class MixinUtilBackgroundThread
{
private static boolean shouldApplyOverride()
{
return FabricServerProxy.isGenerationThreadChecker != null && FabricServerProxy.isGenerationThreadChecker.get();
}
private static boolean isWorldGenThread()
{ return DependencySetupDoneCheck.isDone && DependencySetupDoneCheck.getIsCurrentThreadDistantGeneratorThread.get(); }
#if MC_VER < MC_1_21_3
@Inject(method = "backgroundExecutor", at = @At("HEAD"), cancellable = true)
private static void overrideUtil$backgroundExecutor(CallbackInfoReturnable<ExecutorService> ci)
{
if (shouldApplyOverride())
if (isWorldGenThread())
{
//ApiShared.LOGGER.info("util backgroundExecutor triggered");
ci.setReturnValue(new DummyRunExecutorService());
// run this task on the current DH thread instead of a new MC thread
ci.setReturnValue(new RunOnThisThreadExecutorService());
}
}
#else
// replaced with TracingExecutor in MC 1.21.3+
#endif
#if MC_VER >= MC_1_17_1
#if MC_VER < MC_1_17_1
#elif MC_VER < MC_1_21_3
@Inject(method = "wrapThreadWithTaskName(Ljava/lang/String;Ljava/lang/Runnable;)Ljava/lang/Runnable;",
at = @At("HEAD"), cancellable = true)
private static void overrideUtil$wrapThreadWithTaskName(String string, Runnable r, CallbackInfoReturnable<Runnable> ci)
{
if (shouldApplyOverride())
if (isWorldGenThread())
{
//ApiShared.LOGGER.info("util wrapThreadWithTaskName(Runnable) triggered");
ci.setReturnValue(r);
}
}
#else
// replaced with TracingExecutor in MC 1.21.3+
#endif
#if MC_VER >= MC_1_18_2
#if MC_VER < MC_1_18_2
#elif MC_VER < MC_1_21_3
@Inject(method = "wrapThreadWithTaskName(Ljava/lang/String;Ljava/util/function/Supplier;)Ljava/util/function/Supplier;",
at = @At("HEAD"), cancellable = true)
private static void overrideUtil$wrapThreadWithTaskNameForSupplier(String string, Supplier<?> r, CallbackInfoReturnable<Supplier<?>> ci)
{
if (shouldApplyOverride())
if (isWorldGenThread())
{
//ApiShared.LOGGER.info("util wrapThreadWithTaskName(Supplier) triggered");
ci.setReturnValue(r);
}
}
#else
// replaced with TracingExecutor in MC 1.21.3+
#endif
}
@@ -69,8 +69,8 @@ public class TestChunkWorldGenerator extends AbstractDhApiChunkWorldGenerator
ChunkAccess chunk = this.level.getChunk(chunkPosX, chunkPosZ);
int minBuildHeight = this.level.getMinBuildHeight();
int maxBuildHeight = this.level.getMaxBuildHeight();
int minBuildHeight = this.levelWrapper.getMinHeight();
int maxBuildHeight = this.levelWrapper.getMaxHeight();
DhApiChunk apiChunk = DhApiChunk.create(chunkPosX, chunkPosZ, minBuildHeight, maxBuildHeight);
for (int x = 0; x < 16; x++)
@@ -22,32 +22,50 @@ package com.seibel.distanthorizons.fabric.wrappers.modAccessor;
#if MC_VER >= MC_1_19_4
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.IIrisAccessor;
#if MC_VER <= MC_1_20_4
import net.coderbot.iris.Iris;
#else
import net.irisshaders.iris.Iris;
#endif
import net.irisshaders.iris.api.v0.IrisApi;
#elif MC_VER < MC_1_21_3
import net.irisshaders.iris.Iris;
import net.irisshaders.iris.api.v0.IrisApi;
#else
// TODO fabric/iris needs fixing for MC 1.21.3
#endif
public class IrisAccessor implements IIrisAccessor
{
@Override
public String getModName()
{
//return "Iris-Fabric";
// TODO
#if MC_VER < MC_1_21_3
return Iris.MODID;
#else
return "Iris-Fabric";
#endif
}
@Override
public boolean isShaderPackInUse()
{
// TODO
#if MC_VER < MC_1_21_3
return IrisApi.getInstance().isShaderPackInUse();
#else
return false;
#endif
}
@Override
public boolean isRenderingShadowPass()
{
// TODO
#if MC_VER < MC_1_21_3
return IrisApi.getInstance().isRenderingShadowPass();
#else
return false;
#endif
}
}
@@ -1,29 +1,29 @@
{
"required": true,
"minVersion": "0.8",
"package": "com.seibel.distanthorizons.fabric.mixins",
"mixins": [
"server.MixinChunkGenerator",
"server.MixinChunkMap",
"server.MixinUtilBackgroundThread",
"server.MixinServerPlayer",
"server.MixinEntity"
],
"client": [
"client.MixinClientLevel",
"client.MixinClientPacketListener",
"client.MixinDebugScreenOverlay",
"client.MixinFogRenderer",
"client.MixinGameRenderer",
"client.MixinLevelRenderer",
"client.MixinLightTexture",
"client.MixinOptionsScreen",
"client.MixinMinecraft",
"client.MixinTextureUtil"
],
"server": [],
"injectors": {
"defaultRequire": 1
},
"plugin": "com.seibel.distanthorizons.fabric.mixins.FabricMixinPlugin"
"required": true,
"minVersion": "0.8",
"package": "com.seibel.distanthorizons.fabric.mixins",
"mixins": [
"server.MixinChunkGenerator",
"server.MixinChunkMap",
"server.MixinEntity",
"server.MixinServerPlayer",
"server.MixinTracingExecutor",
"server.MixinUtilBackgroundThread"
],
"client": [
"client.MixinClientLevel",
"client.MixinClientPacketListener",
"client.MixinDebugScreenOverlay",
"client.MixinFogRenderer",
"client.MixinLevelRenderer",
"client.MixinLightTexture",
"client.MixinMinecraft",
"client.MixinOptionsScreen",
"client.MixinTextureUtil"
],
"server": [],
"injectors": {
"defaultRequire": 1
},
"plugin": "com.seibel.distanthorizons.fabric.mixins.FabricMixinPlugin"
}