preprocessor cleanup

This commit is contained in:
James Seibel
2026-05-13 07:49:18 -05:00
parent e087dbc878
commit 5ab6bfb663
10 changed files with 159 additions and 55 deletions
+6 -3
View File
@@ -413,9 +413,12 @@ if (isNotCommonProject) {
modsDir.mkdirs() modsDir.mkdirs()
// Remove any stale DH jars before copying the fresh one // Remove any stale DH jars before copying the fresh one
modsDir.listFiles()?.each { file -> modsDir.listFiles()?.each({ file ->
if (file.name.startsWith(rootProject.mod_name)) file.delete() if (file.name.startsWith(rootProject.mod_name))
} {
file.delete()
}
});
// Copy shadow jar into mods folder so (Neo)Forge discovers it properly // Copy shadow jar into mods folder so (Neo)Forge discovers it properly
copy { copy {
@@ -71,28 +71,23 @@ import net.minecraft.core.BlockPos;
import net.minecraft.client.color.block.BlockTintSource; import net.minecraft.client.color.block.BlockTintSource;
#endif #endif
#if MC_VER <= MC_1_12_2
/** /**
* This stores and calculates the colors * This stores and calculates the colors
* the given {@link IBlockState} should have based * the given BlockState should have based
* on the given {@link IClientLevelWrapper}. * on the given {@link IClientLevelWrapper}.
* *
* @see ColorUtil * @see ColorUtil
*/ */
#else
/**
* This stores and calculates the colors
* the given {@link BlockState} should have based
* on the given {@link IClientLevelWrapper}.
*
* @see ColorUtil
*/
#endif
public class ClientBlockStateColorCache public class ClientBlockStateColorCache
{ {
private static final DhLogger LOGGER = new DhLoggerBuilder().build(); private static final DhLogger LOGGER = new DhLoggerBuilder().build();
private static final Minecraft MC = Minecraft.#if MC_VER <= MC_1_12_2 getMinecraft() #else getInstance() #endif; #if MC_VER <= MC_1_12_2
private static final Minecraft MC = Minecraft.getMinecraft();
#else
private static final Minecraft MC = Minecraft.getInstance();
#endif
#if MC_VER <= MC_1_12_2 #if MC_VER <= MC_1_12_2
#else #else
@@ -115,15 +110,17 @@ public class ClientBlockStateColorCache
/** This is the order each direction on a block is processed when attempting to get the texture/color */ /** This is the order each direction on a block is processed when attempting to get the texture/color */
private static final @Nullable #if MC_VER <= MC_1_12_2 EnumFacing #else Direction #endif[] COLOR_RESOLUTION_DIRECTION_ORDER = private static final @Nullable
#if MC_VER <= MC_1_12_2 EnumFacing[] #else Direction[] #endif
COLOR_RESOLUTION_DIRECTION_ORDER =
{ {
#if MC_VER <= MC_1_12_2 EnumFacing #else Direction #endif.UP, #if MC_VER <= MC_1_12_2 EnumFacing.UP #else Direction.UP #endif,
null, // null represents "unculled" faces, IE the top of farmland null, // null represents "unculled" faces, IE the top of farmland
#if MC_VER <= MC_1_12_2 EnumFacing #else Direction #endif.NORTH, #if MC_VER <= MC_1_12_2 EnumFacing.NORTH #else Direction.NORTH #endif,
#if MC_VER <= MC_1_12_2 EnumFacing #else Direction #endif.EAST, #if MC_VER <= MC_1_12_2 EnumFacing.EAST #else Direction.EAST #endif,
#if MC_VER <= MC_1_12_2 EnumFacing #else Direction #endif.WEST, #if MC_VER <= MC_1_12_2 EnumFacing.WEST #else Direction.WEST #endif,
#if MC_VER <= MC_1_12_2 EnumFacing #else Direction #endif.SOUTH, #if MC_VER <= MC_1_12_2 EnumFacing.SOUTH #else Direction.SOUTH #endif,
#if MC_VER <= MC_1_12_2 EnumFacing #else Direction #endif.DOWN #if MC_VER <= MC_1_12_2 EnumFacing.DOWN #else Direction.DOWN #endif
}; };
private static final int FLOWER_COLOR_SCALE = 5; private static final int FLOWER_COLOR_SCALE = 5;
@@ -281,8 +278,16 @@ public class ClientBlockStateColorCache
{ {
// look for the first non-empty direction // look for the first non-empty direction
List<BakedQuad> quads = null; List<BakedQuad> quads = null;
for (#if MC_VER <= MC_1_12_2 EnumFacing #else Direction #endif direction : COLOR_RESOLUTION_DIRECTION_ORDER)
#if MC_VER <= MC_1_12_2
EnumFacing direction;
#else
Direction direction;
#endif
for (int i = 0; i < COLOR_RESOLUTION_DIRECTION_ORDER.length; i++)
{ {
direction = COLOR_RESOLUTION_DIRECTION_ORDER[i];
quads = this.getQuadsForDirection(direction); quads = this.getQuadsForDirection(direction);
if (quads != null && !quads.isEmpty() if (quads != null && !quads.isEmpty()
&& !( && !(
@@ -74,7 +74,8 @@ import net.minecraft.world.level.chunk.LevelChunkSection;
import net.minecraft.world.level.chunk.LevelChunkSection; import net.minecraft.world.level.chunk.LevelChunkSection;
#endif #endif
#if MC_VER <= MC_1_20_4 && MC_VER > MC_1_12_2 #if MC_VER <= MC_1_12_2
#elif MC_VER <= MC_1_20_4
import net.minecraft.world.level.chunk.ChunkStatus; import net.minecraft.world.level.chunk.ChunkStatus;
#elif MC_VER > MC_1_12_2 #elif MC_VER > MC_1_12_2
import net.minecraft.world.level.chunk.status.ChunkStatus; import net.minecraft.world.level.chunk.status.ChunkStatus;
@@ -93,8 +94,12 @@ public class ChunkWrapper implements IChunkWrapper
private static boolean heightmapThreadWarningLogged = false; private static boolean heightmapThreadWarningLogged = false;
#if MC_VER <= MC_1_12_2
private final Chunk chunk;
#else
private final ChunkAccess chunk;
#endif
private final #if MC_VER <= MC_1_12_2 Chunk #else ChunkAccess #endif chunk;
private final DhChunkPos chunkPos; private final DhChunkPos chunkPos;
private final ILevelWrapper wrappedLevel; private final ILevelWrapper wrappedLevel;
@@ -125,7 +130,9 @@ public class ChunkWrapper implements IChunkWrapper
* fast since it will be called frequently on the MC * fast since it will be called frequently on the MC
* server thread and a slow method will cause server lag. * server thread and a slow method will cause server lag.
*/ */
public ChunkWrapper(#if MC_VER <= MC_1_12_2 Chunk #else ChunkAccess #endif chunk, ILevelWrapper wrappedLevel) public ChunkWrapper(
#if MC_VER <= MC_1_12_2 Chunk #else ChunkAccess #endif chunk,
ILevelWrapper wrappedLevel)
{ {
this.chunk = chunk; this.chunk = chunk;
this.wrappedLevel = wrappedLevel; this.wrappedLevel = wrappedLevel;
@@ -257,7 +264,9 @@ public class ChunkWrapper implements IChunkWrapper
return this.maxNonEmptyHeight; return this.maxNonEmptyHeight;
} }
private static boolean isChunkSectionEmpty(#if MC_VER <= MC_1_12_2 ExtendedBlockStorage #else LevelChunkSection #endif section) private static boolean isChunkSectionEmpty(
#if MC_VER <= MC_1_12_2 ExtendedBlockStorage #else LevelChunkSection #endif section
)
{ {
#if MC_VER <= MC_1_17_1 #if MC_VER <= MC_1_17_1
return section.isEmpty(); return section.isEmpty();
@@ -373,8 +382,12 @@ public class ChunkWrapper implements IChunkWrapper
public IBiomeWrapper getBiome(int relX, int relY, int relZ) public IBiomeWrapper getBiome(int relX, int relY, int relZ)
{ {
#if MC_VER <= MC_1_12_2 #if MC_VER <= MC_1_12_2
BlockPos.MutableBlockPos blockPos = MUTABLE_BLOCK_POS_REF.get();
blockPos.setPos(relX, relY, relZ);
World world = (World) this.wrappedLevel.getWrappedMcObject(); World world = (World) this.wrappedLevel.getWrappedMcObject();
return BiomeWrapper.getBiomeWrapper(this.chunk.getBiome(new BlockPos(relX, relY, relZ), world.getBiomeProvider()), wrappedLevel);
return BiomeWrapper.getBiomeWrapper(this.chunk.getBiome(blockPos, world.getBiomeProvider()), wrappedLevel);
#elif MC_VER < MC_1_17_1 #elif MC_VER < MC_1_17_1
return BiomeWrapper.getBiomeWrapper(this.chunk.getBiomes().getNoiseBiome( return BiomeWrapper.getBiomeWrapper(this.chunk.getBiomes().getNoiseBiome(
relX >> 2, relY >> 2, relZ >> 2), relX >> 2, relY >> 2, relZ >> 2),
@@ -572,13 +585,41 @@ public class ChunkWrapper implements IChunkWrapper
#endif #endif
@Override @Override
public int getMaxBlockX() { return this.chunk.getPos().#if MC_VER <= MC_1_12_2 getXEnd() #else getMaxBlockX() #endif; } public int getMaxBlockX()
{
#if MC_VER <= MC_1_12_2
return this.chunk.getPos().getXEnd();
#else
return this.chunk.getPos().getMaxBlockX();
#endif
}
@Override @Override
public int getMaxBlockZ() { return this.chunk.getPos().#if MC_VER <= MC_1_12_2 getZEnd() #else getMaxBlockZ() #endif; } public int getMaxBlockZ()
{
#if MC_VER <= MC_1_12_2
return this.chunk.getPos().getZEnd();
#else
return this.chunk.getPos().getMaxBlockZ();
#endif
}
@Override @Override
public int getMinBlockX() { return this.chunk.getPos().#if MC_VER <= MC_1_12_2 getXStart() #else getMinBlockX() #endif; } public int getMinBlockX()
{
#if MC_VER <= MC_1_12_2
return this.chunk.getPos().getXStart();
#else
return this.chunk.getPos().getMinBlockX();
#endif
}
@Override @Override
public int getMinBlockZ() { return this.chunk.getPos().#if MC_VER <= MC_1_12_2 getZStart() #else getMinBlockZ() #endif; } public int getMinBlockZ()
{
#if MC_VER <= MC_1_12_2
return this.chunk.getPos().getZStart();
#else
return this.chunk.getPos().getMinBlockZ();
#endif
}
@@ -76,28 +76,29 @@ public class GuiHelper
#endif #endif
} }
public static void SetX(#if MC_VER <= MC_1_12_2 GuiButton #else AbstractWidget #endif w, int x) #if MC_VER <= MC_1_12_2
public static void SetX(GuiButton widget, int x)
#else
public static void SetX(AbstractWidget widget, int x)
#endif
{ {
#if MC_VER < MC_1_19_4 #if MC_VER < MC_1_19_4
w.x = x; widget.x = x;
#else #else
w.setX(x); widget.setX(x);
#endif #endif
} }
#if MC_VER <= MC_1_12_2 #if MC_VER <= MC_1_12_2
public static void SetY(GuiTextField w, int y) public static void SetY(GuiTextField textField, int y) { textField.y = y; }
{
w.y = y;
}
#endif #endif
public static void SetY(#if MC_VER <= MC_1_12_2 GuiButton #else AbstractWidget #endif w, int y) public static void SetY(#if MC_VER <= MC_1_12_2 GuiButton #else AbstractWidget #endif widget, int y)
{ {
#if MC_VER < MC_1_19_4 #if MC_VER < MC_1_19_4
w.y = y; widget.y = y;
#else #else
w.setY(y); widget.setY(y);
#endif #endif
} }
@@ -101,7 +101,11 @@ public class ClassicConfigGUI
//==============// //==============//
/** if you want to get this config gui's screen call this */ /** if you want to get this config gui's screen call this */
public static #if MC_VER <= MC_1_12_2 GuiScreen #else Screen #endif getScreen(#if MC_VER <= MC_1_12_2 GuiScreen #else Screen #endif parent, String category) #if MC_VER <= MC_1_12_2
public static GuiScreen getScreen(GuiScreen parent, String category)
#else
public static Screen getScreen(Screen parent, String category)
#endif
{ return new DhConfigScreen(parent, category); } { return new DhConfigScreen(parent, category); }
@@ -110,8 +114,12 @@ public class ClassicConfigGUI
// helper classes // // helper classes //
//================// //================//
public static class ConfigListWidget extends #if MC_VER <= MC_1_12_2 GuiListExtended #else ContainerObjectSelectionList<DhButtonEntry> #endif #if MC_VER <= MC_1_12_2
{ public static class ConfigListWidget extends GuiListExtended
#else
public static class ConfigListWidget extends ContainerObjectSelectionList<DhButtonEntry>
#endif
{
#if MC_VER <= MC_1_12_2 #if MC_VER <= MC_1_12_2
public List<DhButtonEntry> children = new ArrayList<>(); public List<DhButtonEntry> children = new ArrayList<>();
#endif #endif
@@ -261,8 +269,13 @@ public class ClassicConfigGUI
private final EConfigCommentTextPosition textPosition; private final EConfigCommentTextPosition textPosition;
public final AbstractConfigBase dhConfigType; public final AbstractConfigBase dhConfigType;
public static final Map< #if MC_VER <= MC_1_12_2 Gui #else AbstractWidget #endif, #if MC_VER <= MC_1_12_2 ITextComponent #else Component #endif> TEXT_BY_WIDGET = new HashMap<>(); #if MC_VER <= MC_1_12_2
public static final Map< #if MC_VER <= MC_1_12_2 Gui #else AbstractWidget #endif, DhButtonEntry> BUTTON_BY_WIDGET = new HashMap<>(); public static final Map<Gui, ITextComponent> TEXT_BY_WIDGET = new HashMap<>();
public static final Map<Gui, DhButtonEntry> BUTTON_BY_WIDGET = new HashMap<>();
#else
public static final Map<AbstractWidget, Component> TEXT_BY_WIDGET = new HashMap<>();
public static final Map<AbstractWidget, DhButtonEntry> BUTTON_BY_WIDGET = new HashMap<>();
#endif
@@ -364,6 +377,7 @@ public class ClassicConfigGUI
if (this.resetButton != null) if (this.resetButton != null)
{ {
SetY(#if MC_VER <= MC_1_12_2 (GuiButton) #endif this.resetButton, y); SetY(#if MC_VER <= MC_1_12_2 (GuiButton) #endif this.resetButton, y);
#if MC_VER <= MC_1_12_2 #if MC_VER <= MC_1_12_2
((GuiButton) this.resetButton).drawButton(Minecraft.getMinecraft(), mouseX, mouseY, tickDelta); ((GuiButton) this.resetButton).drawButton(Minecraft.getMinecraft(), mouseX, mouseY, tickDelta);
#elif MC_VER <= MC_1_21_11 #elif MC_VER <= MC_1_21_11
@@ -42,7 +42,13 @@ public class KeyedClientLevelManager implements IKeyedClientLevelManager
@Override @Override
public IServerKeyedClientLevel setServerKeyedLevel(IClientLevelWrapper clientLevel, String serverKey, String levelKey) public IServerKeyedClientLevel setServerKeyedLevel(IClientLevelWrapper clientLevel, String serverKey, String levelKey)
{ {
IServerKeyedClientLevel keyedLevel = new ServerKeyedClientLevelWrapper(#if MC_VER <= MC_1_12_2 (WorldClient) #else (ClientLevel) #endif clientLevel.getWrappedMcObject(), serverKey, levelKey); IServerKeyedClientLevel keyedLevel;
#if MC_VER <= MC_1_12_2
keyedLevel = new ServerKeyedClientLevelWrapper((WorldClient) clientLevel.getWrappedMcObject(), serverKey, levelKey);
#else
keyedLevel = new ServerKeyedClientLevelWrapper((ClientLevel) clientLevel.getWrappedMcObject(), serverKey, levelKey);
#endif
this.serverKeyedLevel = keyedLevel; this.serverKeyedLevel = keyedLevel;
this.enabled = true; this.enabled = true;
return keyedLevel; return keyedLevel;
@@ -22,7 +22,11 @@ public class ServerKeyedClientLevelWrapper extends ClientLevelWrapper implements
// constructor // // constructor //
//=============// //=============//
public ServerKeyedClientLevelWrapper(#if MC_VER <= MC_1_12_2 WorldClient #else ClientLevel #endif level, String serverKey, String serverLevelKey) #if MC_VER <= MC_1_12_2
public ServerKeyedClientLevelWrapper(WorldClient level, String serverKey, String serverLevelKey)
#else
public ServerKeyedClientLevelWrapper(ClientLevel level, String serverKey, String serverLevelKey)
#endif
{ {
super(level); super(level);
this.serverKey = serverKey; this.serverKey = serverKey;
@@ -83,7 +83,12 @@ import net.minecraft.client.GraphicsStatus;
public class MinecraftClientWrapper implements IMinecraftClientWrapper, IMinecraftSharedWrapper public class MinecraftClientWrapper implements IMinecraftClientWrapper, IMinecraftSharedWrapper
{ {
private static final DhLogger LOGGER = new DhLoggerBuilder().build(); private static final DhLogger LOGGER = new DhLoggerBuilder().build();
private static final Minecraft MINECRAFT = Minecraft.#if MC_VER <= MC_1_12_2 getMinecraft() #else getInstance() #endif;
#if MC_VER <= MC_1_12_2
private static final Minecraft MINECRAFT = Minecraft.getMinecraft();
#else
private static final Minecraft MINECRAFT = Minecraft.getInstance();
#endif
public static final MinecraftClientWrapper INSTANCE = new MinecraftClientWrapper(); public static final MinecraftClientWrapper INSTANCE = new MinecraftClientWrapper();
@@ -98,19 +103,35 @@ public class MinecraftClientWrapper implements IMinecraftClientWrapper, IMinecra
//region //region
@Override @Override
public boolean hasSinglePlayerServer() { return MINECRAFT.#if MC_VER <= MC_1_12_2 isSingleplayer() #else hasSingleplayerServer() #endif; } public boolean hasSinglePlayerServer()
{
#if MC_VER <= MC_1_12_2
return MINECRAFT.isSingleplayer();
#else
return MINECRAFT.hasSingleplayerServer();
#endif
}
@Override @Override
public boolean clientConnectedToDedicatedServer() public boolean clientConnectedToDedicatedServer()
{ {
return MINECRAFT.#if MC_VER <= MC_1_12_2 getCurrentServerData() #else getCurrentServer() #endif != null return this.hasServerConnection()
&& !this.hasSinglePlayerServer(); && !this.hasSinglePlayerServer();
} }
@Override @Override
public boolean connectedToReplay() public boolean connectedToReplay()
{ {
return MINECRAFT.#if MC_VER <= MC_1_12_2 getCurrentServerData() #else getCurrentServer() #endif == null return !this.hasServerConnection()
&& !this.hasSinglePlayerServer() ; && !this.hasSinglePlayerServer() ;
} }
private boolean hasServerConnection()
{
#if MC_VER <= MC_1_12_2
return MINECRAFT.getCurrentServerData() != null;
#else
MINECRAFT.getCurrentServer() != null;
#endif
}
@Override @Override
@@ -114,7 +114,12 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
private static final IOptifineAccessor OPTIFINE_ACCESSOR = ModAccessorInjector.INSTANCE.get(IOptifineAccessor.class); private static final IOptifineAccessor OPTIFINE_ACCESSOR = ModAccessorInjector.INSTANCE.get(IOptifineAccessor.class);
private static final DhLogger LOGGER = new DhLoggerBuilder().build(); private static final DhLogger LOGGER = new DhLoggerBuilder().build();
private static final Minecraft MC = Minecraft.#if MC_VER <= MC_1_12_2 getMinecraft() #else getInstance() #endif;
#if MC_VER <= MC_1_12_2
private static final Minecraft MC = Minecraft.getMinecraft();
#else
private static final Minecraft MC = Minecraft.getInstance();
#endif
/** /**
* In the case of immersive portals multiple levels may be active at once, causing conflicting lightmaps. <br> * In the case of immersive portals multiple levels may be active at once, causing conflicting lightmaps. <br>
@@ -56,7 +56,11 @@ public class MinecraftServerWrapper implements IMinecraftSharedWrapper
throw new IllegalStateException("Trying to get player count before dedicated server completed initialization!"); throw new IllegalStateException("Trying to get player count before dedicated server completed initialization!");
} }
return this.dedicatedServer.#if MC_VER <= MC_1_12_2 getCurrentPlayerCount() #else getPlayerCount() #endif; #if MC_VER <= MC_1_12_2
return this.dedicatedServer.getCurrentPlayerCount();
#else
return this.dedicatedServer.getPlayerCount();
#endif
} }