Redo the preprocessor Define system to support 'PRE' & 'POST'

This commit is contained in:
TomTheFurry
2022-04-09 18:37:38 +08:00
parent b7d627f0f5
commit 9fdaeed69b
45 changed files with 401 additions and 435 deletions
@@ -47,12 +47,12 @@ import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.fml.loading.FMLLoader;
#if MC_VERSION_1_18_1 || MC_VERSION_1_18_2
import net.minecraftforge.client.ConfigGuiHandler;
#elif MC_VERSION_1_17_1
import net.minecraftforge.fmlclient.ConfigGuiHandler;
#elif MC_VERSION_1_16_5
#if PRE_MC_1_17_1
import net.minecraftforge.fml.ExtensionPoint;
#elif MC_1_17_1
import net.minecraftforge.fmlclient.ConfigGuiHandler;
#else // 1.18+
import net.minecraftforge.client.ConfigGuiHandler;
#endif
import java.util.List;
@@ -96,7 +96,7 @@ public class ForgeMain implements LodForgeMethodCaller
ModAccessorHandler.finishBinding();
#if MC_VERSION_1_16_5
#if PRE_MC_1_17_1
ModLoadingContext.get().registerExtensionPoint(ExtensionPoint.CONFIGGUIFACTORY,
() -> (client, parent) -> ConfigGui.getScreen(parent, ""));
#else
@@ -115,7 +115,7 @@ public class ForgeMain implements LodForgeMethodCaller
@Override
public int colorResolverGetColor(ColorResolver resolver, Biome biome, double x, double z) {
#if MC_VERSION_1_17_1
#if MC_1_17_1
return resolver.m_130045_(biome, x, z);
#else
return resolver.getColor(biome, x, z);
@@ -23,7 +23,7 @@ import com.seibel.lod.core.api.ApiShared;
import org.spongepowered.asm.mixin.Mixin;
import net.minecraft.world.level.chunk.ChunkGenerator;
#if MC_VERSION_1_16_5 || MC_VERSION_1_17_1
#if PRE_MC_1_18_1
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@@ -34,7 +34,7 @@ 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_VERSION_1_16_5
#if PRE_MC_1_17_1
import net.minecraft.world.level.material.FluidState;
#else
import net.minecraft.world.level.material.FogType;
@@ -52,7 +52,7 @@ public class MixinFogRenderer
@Inject(at = @At("RETURN"),
method = "setupFog(Lnet/minecraft/client/Camera;Lnet/minecraft/client/renderer/FogRenderer$FogMode;FZF)V",
remap = #if MC_VERSION_1_16_5 true #else false #endif) // Remap = false messiness due to this being added by forge.
remap = #if MC_1_16_5 true #else false #endif) // Remap messiness due to this being added by forge.
private static void disableSetupFog(Camera camera, FogMode fogMode, float f, boolean bl, float partTick, CallbackInfo callback)
{
ILodConfigWrapperSingleton CONFIG;
@@ -65,7 +65,7 @@ public class MixinFogRenderer
return; // May happen due to forge for some reason haven't inited out thingy yet.
}
#if MC_VERSION_1_16_5
#if PRE_MC_1_17_1
FluidState fluidState = camera.getFluidInCamera();
boolean cameraNotInFluid = fluidState.isEmpty();
#else
@@ -78,7 +78,7 @@ public class MixinFogRenderer
if (!isSpecialFog && cameraNotInFluid && fogMode == FogMode.FOG_TERRAIN
&& CONFIG.client().graphics().fogQuality().getDisableVanillaFog())
{
#if MC_VERSION_1_16_5
#if PRE_MC_1_17_1
RenderSystem.fogStart(A_REALLY_REALLY_BIG_VALUE);
RenderSystem.fogEnd(A_EVEN_LARGER_VALUE);
#else
@@ -53,7 +53,7 @@ public class MixinOptionsScreen extends Screen {
@Inject(at = @At("HEAD"),method = "init")
private void lodconfig$init(CallbackInfo ci) {
if (SingletonHandler.get(ILodConfigWrapperSingleton.class).client().getOptionsButton())
this. #if MC_VERSION_1_16_5 addButton #else addRenderableWidget #endif
this. #if PRE_MC_1_17_1 addButton #else addRenderableWidget #endif
(new TexturedButtonWidget(
// Where the button is on the screen
this.width / 2 - 180, this.height / 6 - 12,
@@ -3,7 +3,7 @@ package com.seibel.lod.forge.mixins;
import net.minecraft.world.level.chunk.ChunkGenerator;
import org.spongepowered.asm.mixin.Mixin;
#if MC_VERSION_1_16_5
#if PRE_MC_1_17_1
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@@ -40,7 +40,17 @@ public class MixinUtilBackgroudThread
return DependencySetupDoneCheck.getIsCurrentThreadDistantGeneratorThread.get();
}
#if !MC_VERSION_1_16_5
@Inject(method = "backgroundExecutor", at = @At("HEAD"), cancellable = true)
private static void overrideUtil$backgroundExecutor(CallbackInfoReturnable<ExecutorService> ci)
{
if (DependencySetupDoneCheck.isDone && shouldApplyOverride())
{
//ApiShared.LOGGER.info("util backgroundExecutor triggered");
ci.setReturnValue(new DummyRunExecutorService());
}
}
#if POST_MC_1_17_1
@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)
@@ -52,7 +62,7 @@ public class MixinUtilBackgroudThread
}
}
#endif
#if MC_VERSION_1_18_1 || MC_VERSION_1_18_2
#if POST_MC_1_18_1
@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)
@@ -65,13 +75,4 @@ public class MixinUtilBackgroudThread
}
#endif
@Inject(method = "backgroundExecutor", at = @At("HEAD"), cancellable = true)
private static void overrideUtil$backgroundExecutor(CallbackInfoReturnable<ExecutorService> ci)
{
if (DependencySetupDoneCheck.isDone && shouldApplyOverride())
{
//ApiShared.LOGGER.info("util backgroundExecutor triggered");
ci.setReturnValue(new DummyRunExecutorService());
}
}
}
@@ -55,7 +55,7 @@ public class MixinWorldRenderer
throw new NullPointerException("Null cannot be cast to non-null type.");
}
#if MC_VERSION_1_16_5
#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)
{
@@ -18,10 +18,10 @@
*/
package com.seibel.lod.forge.mixins.unsafe;
#if MC_VERSION_1_18_1 || MC_VERSION_1_18_2
import org.spongepowered.asm.mixin.Mixin;
import net.minecraft.world.level.chunk.ChunkGenerator;
#if POST_MC_1_18_1
import net.minecraft.util.ThreadingDetector;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.Shadow;
@@ -33,6 +33,7 @@ import java.util.concurrent.Semaphore;
/**
* Why does this exist? But okay! (Will be probably removed when the experimental generator is done)
* FIXME: Recheck this
*/
@Mixin(ThreadingDetector.class)
public class MixinThreadingDectector {
@@ -47,7 +48,6 @@ public class MixinThreadingDectector {
}
#else
@Mixin(ChunkGenerator.class)
public class MixinThreadingDectector {}
#endif