MC 1.12.2 refactoring and cleanup

This commit is contained in:
James Seibel
2026-05-12 21:38:07 -05:00
parent 7448483f84
commit fbf812091d
24 changed files with 458 additions and 175 deletions
@@ -566,6 +566,7 @@ if (isNotCommonProject) {
outputs.file(output)
doLast {
output.withWriter("UTF-8") { writer ->
writer.writeLine("#PARSE_ESCAPES")
new JsonSlurper()
.parse(input)
.each { key, value ->
+2
View File
@@ -44,3 +44,5 @@ sourcesJar {
dependsOn commonSources
from commonSources.archiveFile.map { zipTree(it) }
}
@@ -59,13 +59,6 @@ import org.lwjgl.opengl.GL32;
import java.util.concurrent.AbstractExecutorService;
/**
* This handles all events sent to the client,
* and is the starting point for most of the mod.
*
* @author James_Seibel
* @version 2023-7-27
*/
public class CleanroomClientProxy implements AbstractModInitializer.IEventProxy
{
private static final IMinecraftClientWrapper MC = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class);
@@ -124,6 +117,7 @@ public class CleanroomClientProxy implements AbstractModInitializer.IEventProxy
//==============//
// chunk events //
//==============//
//region
@SubscribeEvent
public void rightClickBlockEvent(PlayerInteractEvent.RightClickBlock event)
@@ -185,11 +179,14 @@ public class CleanroomClientProxy implements AbstractModInitializer.IEventProxy
}
}
//endregion
//==============//
// key bindings //
//==============//
//region
@SubscribeEvent
public void registerKeyBindings(InputEvent.KeyInputEvent event)
@@ -206,10 +203,14 @@ public class CleanroomClientProxy implements AbstractModInitializer.IEventProxy
ClientApi.INSTANCE.keyPressedEvent(event.getKey());*/
}
//endregion
//===========//
// rendering //
//===========//
//region
@SubscribeEvent
public void afterLevelRenderEvent(TickEvent.RenderTickEvent event)
@@ -231,11 +232,20 @@ public class CleanroomClientProxy implements AbstractModInitializer.IEventProxy
}
@SubscribeEvent
public void onRenderOverlay(RenderGameOverlayEvent.Text event) {
public void onRenderOverlay(RenderGameOverlayEvent.Text event)
{
Minecraft mc = Minecraft.getMinecraft();
if (event.isCanceled() || !mc.gameSettings.showDebugInfo) return;
if (event.isCanceled()
|| !mc.gameSettings.showDebugInfo)
{
return;
}
F3Screen.addStringToDisplay(event.getRight());
}
//endregion
}
@@ -82,15 +82,18 @@ public class CleanroomServerProxy implements AbstractModInitializer.IEventProxy
//=============//
// constructor //
//=============//
//region
public CleanroomServerProxy(boolean isDedicated) { this.isDedicated = isDedicated; }
//endregion
//========//
// events //
//========//
//region
// ServerLevelLoadEvent
@SubscribeEvent
@@ -132,9 +135,11 @@ public class CleanroomServerProxy implements AbstractModInitializer.IEventProxy
@SubscribeEvent
public void playerLoggedInEvent(PlayerEvent.PlayerLoggedInEvent event)
{ this.serverApi.serverPlayerJoinEvent(getServerPlayerWrapper(event)); }
@SubscribeEvent
public void playerLoggedOutEvent(PlayerEvent.PlayerLoggedOutEvent event)
{ this.serverApi.serverPlayerDisconnectEvent(getServerPlayerWrapper(event)); }
@SubscribeEvent
public void playerChangedDimensionEvent(PlayerEvent.PlayerChangedDimensionEvent event)
{
@@ -145,15 +150,17 @@ public class CleanroomServerProxy implements AbstractModInitializer.IEventProxy
);
}
//endregion
//================//
// helper methods //
//================//
//region
private static ServerLevelWrapper getServerLevelWrapper(WorldServer level) { return ServerLevelWrapper.getWrapper(level); }
private static ServerLevelWrapper getServerLevelWrapper(int dimensionId, PlayerEvent event)
{
MinecraftServer server = event.player.getServer();
@@ -166,8 +173,9 @@ public class CleanroomServerProxy implements AbstractModInitializer.IEventProxy
}
private static ServerPlayerWrapper getServerPlayerWrapper(PlayerEvent event)
{
return ServerPlayerWrapper.getWrapper((EntityPlayerMP) event.player);
}
{ return ServerPlayerWrapper.getWrapper((EntityPlayerMP) event.player); }
//endregion
}
@@ -46,23 +46,21 @@ public abstract class MixinEntityPlayerMP implements IMixinServerPlayer
@Nullable
private volatile WorldServer distantHorizons$dimensionChangeDestination;
@Override
@Nullable
public WorldServer distantHorizons$getDimensionChangeDestination()
{
return this.distantHorizons$dimensionChangeDestination;
}
{ return this.distantHorizons$dimensionChangeDestination; }
@Inject(at = @At("HEAD"), method = "changeDimension(ILnet/minecraftforge/common/util/ITeleporter;)Lnet/minecraft/entity/Entity;")
public void setDimensionChangeDestination(int destinationDimensionID, ITeleporter teleporter, CallbackInfoReturnable<Entity> cir)
{
this.distantHorizons$dimensionChangeDestination = this.server.getWorld(destinationDimensionID);
}
{ this.distantHorizons$dimensionChangeDestination = this.server.getWorld(destinationDimensionID); }
@Inject(at = @At("RETURN"), method = "clearInvulnerableDimensionChange")
public void clearDimensionChangeDestination(CallbackInfo ci)
{
this.distantHorizons$dimensionChangeDestination = null;
}
{ this.distantHorizons$dimensionChangeDestination = null; }
}
@@ -1,6 +1,9 @@
package com.seibel.distanthorizons.common.commands;
#if MC_VER > MC_1_12_2
#if MC_VER <= MC_1_12_2
public abstract class AbstractCommand {}
#else
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import com.seibel.distanthorizons.common.wrappers.misc.ServerPlayerWrapper;
@@ -38,6 +38,8 @@ public class CommandInitializer
private static final PermissionCheck COMMAND_PERMISSION_CHECK = new PermissionCheck.Require(Permissions.COMMANDS_OWNER);
#endif
#if MC_VER <= MC_1_12_2
public static ICommand initCommands()
{
@@ -98,7 +100,9 @@ public class CommandInitializer
};
}
#else
/**
* A received command dispatcher, which is held until the server is ready to initialize the commands.
*/
@@ -33,7 +33,7 @@ import java.util.function.ToIntBiFunction;
/**
* Command for managing config.
*/
public class ConfigCommand #if MC_VER > MC_1_12_2 extends AbstractCommand #endif
public class ConfigCommand extends AbstractCommand
{
#if MC_VER <= MC_1_12_2
@SuppressWarnings({"unchecked", "rawtypes"})
@@ -94,7 +94,9 @@ public class ConfigCommand #if MC_VER > MC_1_12_2 extends AbstractCommand #endif
}
}
}
#else
private static final List<CommandArgumentData<?>> commandArguments = Arrays.asList(
new CommandArgumentData<>(Integer.class, configEntry -> integer(configEntry.getMin(), configEntry.getMax()), IntegerArgumentType::getInteger),
new CommandArgumentData<>(Double.class, configEntry -> doubleArg(configEntry.getMin(), configEntry.getMax()), DoubleArgumentType::getDouble),
@@ -17,7 +17,7 @@ import static net.minecraft.commands.Commands.literal;
#endif
public class CrashCommand #if MC_VER > MC_1_12_2 extends AbstractCommand #endif
public class CrashCommand extends AbstractCommand
{
#if MC_VER <= MC_1_12_2
public void execute(ICommandSender sender, String[] args)
@@ -16,7 +16,7 @@ import java.util.ArrayList;
import java.util.List;
public class DebugCommand #if MC_VER > MC_1_12_2 extends AbstractCommand #endif
public class DebugCommand extends AbstractCommand
{
private static String getDebugString()
{
@@ -32,7 +32,7 @@ import java.util.concurrent.CancellationException;
import java.util.concurrent.CompletableFuture;
public class PregenCommand #if MC_VER > MC_1_12_2 extends AbstractCommand #endif
public class PregenCommand extends AbstractCommand
{
private PregenManager getPregenManager()
{
@@ -18,8 +18,11 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
public class MixinChunkMapCommon
{
public static void onChunkSave(#if MC_VER <= MC_1_12_2 WorldServer #else ServerLevel #endif level, #if MC_VER <= MC_1_12_2 Chunk #else ChunkAccess #endif chunk #if MC_VER > MC_1_12_2, CallbackInfoReturnable<Boolean> ci #endif)
#if MC_VER <= MC_1_12_2
public static void onChunkSave(WorldServer level, Chunk chunk)
#else
public static void onChunkSave(ServerLevel level, ChunkAccess chunk, CallbackInfoReturnable<Boolean> ci)
#endif
{
IServerLevelWrapper levelWrapper = ServerLevelWrapper.getWrapper(level);
@@ -77,8 +80,13 @@ public class MixinChunkMapCommon
// biome validation //
// some chunks may be missing their biomes, which cause issues when attempting to save them
#if MC_VER <= MC_1_17_1
if (chunk.#if MC_VER <= MC_1_12_2 getBiomeArray() #else getBiomes() #endif == null)
#if MC_VER <= MC_1_12_2
if (chunk. getBiomeArray() == null)
{
return;
}
#elif MC_VER <= MC_1_17_1
if (chunk.getBiomes() == null)
{
return;
}
@@ -182,13 +182,20 @@ public class GLState implements AutoCloseable
if (frameBufferSet)
{
if (GL32.glIsTexture(this.frameBufferTexture0))
{
GL32.glFramebufferTexture2D(GL32.GL_FRAMEBUFFER, GL32.GL_COLOR_ATTACHMENT0, GL32.GL_TEXTURE_2D, this.frameBufferTexture0, 0);
}
if (this.frameBufferTexture1 != 0 && GL32.glIsTexture(this.frameBufferTexture1))
{
GL32.glFramebufferTexture2D(GL32.GL_FRAMEBUFFER, GL32.GL_COLOR_ATTACHMENT1, GL32.GL_TEXTURE_2D, this.frameBufferTexture1, 0);
}
if (GL32.glIsTexture(this.frameBufferDepthTexture))
{
GL32.glFramebufferTexture2D(GL32.GL_FRAMEBUFFER, GL32.GL_DEPTH_ATTACHMENT, GL32.GL_TEXTURE_2D, this.frameBufferDepthTexture, 0);
}
}
GL32.glBindVertexArray(GL32.glIsVertexArray(this.vao) ? this.vao : 0);
@@ -34,16 +34,22 @@ import net.minecraft.world.level.LevelAccessor;
public class ProxyUtil
{
public static ILevelWrapper getLevelWrapper(#if MC_VER <= MC_1_12_2 World #else LevelAccessor #endif level)
public static ILevelWrapper getLevelWrapper(
#if MC_VER <= MC_1_12_2 World #else LevelAccessor #endif level
)
{
ILevelWrapper levelWrapper;
if (level instanceof #if MC_VER <= MC_1_12_2 WorldServer #else ServerLevel #endif)
{
levelWrapper = ServerLevelWrapper.getWrapper(#if MC_VER <= MC_1_12_2 (WorldServer) #else (ServerLevel) #endif level);
levelWrapper = ServerLevelWrapper.getWrapper(
#if MC_VER <= MC_1_12_2 (WorldServer) #else (ServerLevel) #endif level
);
}
else
{
levelWrapper = ClientLevelWrapper.getWrapper(#if MC_VER <= MC_1_12_2 (WorldClient) #else (ClientLevel) #endif level);
levelWrapper = ClientLevelWrapper.getWrapper(
#if MC_VER <= MC_1_12_2 (WorldClient) #else (ClientLevel) #endif level
);
}
return levelWrapper;
@@ -49,8 +49,6 @@ public abstract class AbstractDhTintGetter implements BlockAndTintGetter
#endif
private static final ConcurrentHashMap<BlockBiomeWrapperPair, Integer> COLOR_BY_BLOCK_BIOME_PAIR = new ConcurrentHashMap<>();
/** returned if the color cache is incomplete */
public static final int INVALID_COLOR = -1;
protected BiomeWrapper biomeWrapper;
@@ -102,7 +100,7 @@ public abstract class AbstractDhTintGetter implements BlockAndTintGetter
* Can be called by DH directly, skipping some of MC's logic
* to speed up tint getting slightly.
*
* @return {@link AbstractDhTintGetter#INVALID_COLOR} if any of the biomes needed for this position
* @return {@link ClientBlockStateColorCache#INVALID_COLOR} if any of the biomes needed for this position
* were not cached. In that case calling {@link AbstractDhTintGetter#getBlockTint(BlockPos, ColorResolver)}
* will need to be called by MC's ColorResolver so we can
* populate the color cache.
@@ -163,9 +161,9 @@ public abstract class AbstractDhTintGetter implements BlockAndTintGetter
int id = FullDataPointUtil.getId(dataPoint);
BiomeWrapper biomeWrapper = (BiomeWrapper) this.fullDataSource.mapping.getBiomeWrapper(id);
int color = this.tryGetClientBiomeColor(colorResolver, biomeWrapper);
if (color == INVALID_COLOR)
if (color == ClientBlockStateColorCache.INVALID_COLOR)
{
return INVALID_COLOR;
return ClientBlockStateColorCache.INVALID_COLOR;
}
@@ -214,7 +212,7 @@ public abstract class AbstractDhTintGetter implements BlockAndTintGetter
// no color resolver is present,
// the cache needs to be populated before
// we can use the fast path
return INVALID_COLOR;
return ClientBlockStateColorCache.INVALID_COLOR;
}
@@ -342,7 +342,9 @@ public class BiomeWrapper implements IBiomeWrapper
}
}
public static BiomeDeserializeResult deserializeBiome(String resourceLocationString #if MC_VER > MC_1_12_2, net.minecraft.core.RegistryAccess registryAccess #endif) throws IOException
public static BiomeDeserializeResult deserializeBiome(String resourceLocationString
#if MC_VER > MC_1_12_2, net.minecraft.core.RegistryAccess registryAccess #endif
) throws IOException
{
// parse the resource location
int separatorIndex = resourceLocationString.indexOf(":");
@@ -373,10 +375,10 @@ public class BiomeWrapper implements IBiomeWrapper
boolean success;
#if MC_VER == MC_1_12_2
#if MC_VER <= MC_1_12_2
Biome biome = Biome.REGISTRY.getObject(resourceLocation);
success = (biome != null);
#elif MC_VER == MC_1_16_5 || MC_VER == MC_1_17_1
#elif MC_VER <= MC_1_17_1
Biome biome = registryAccess.registryOrThrow(Registry.BIOME_REGISTRY).get(resourceLocation);
success = (biome != null);
#elif MC_VER <= MC_1_19_2
@@ -153,33 +153,58 @@ public class BlockStateWrapper implements IBlockStateWrapper
// constructors //
//==============//
//region
#if MC_VER <= MC_1_12_2
/**
* Can be faster than {@link BlockStateWrapper#fromBlockState(IBlockState, ILevelWrapper)}
* Can be faster than BlockStateWrapper#fromBlockState(BlockState, ILevelWrapper)
* in cases where the same block state is expected to be referenced multiple times.
*/
#else
/**
* Can be faster than {@link BlockStateWrapper#fromBlockState(BlockState, ILevelWrapper)}
* in cases where the same block state is expected to be referenced multiple times.
*/
#endif
public static BlockStateWrapper fromBlockState(#if MC_VER <= MC_1_12_2 IBlockState #else BlockState #endif blockState, ILevelWrapper levelWrapper, IBlockStateWrapper guess)
public static BlockStateWrapper fromBlockState(
#if MC_VER <= MC_1_12_2 IBlockState #else BlockState #endif blockState,
ILevelWrapper levelWrapper, IBlockStateWrapper guess)
{
#if MC_VER <= MC_1_12_2 IBlockState #else BlockState #endif guessBlockState = (guess == null || guess.isAir()) ? null : (#if MC_VER <= MC_1_12_2 IBlockState #else BlockState #endif) guess.getWrappedMcObject();
#if MC_VER <= MC_1_12_2 IBlockState #else BlockState #endif inputBlockState = (blockState == null || #if MC_VER <= MC_1_12_2 blockState.getBlock() == Blocks.AIR #else blockState.isAir() #endif) ? null : blockState;
if (guess instanceof BlockStateWrapper
&& guessBlockState == inputBlockState)
{
return (BlockStateWrapper) guess;
}
else
if (guess == null)
{
return fromBlockState(blockState, levelWrapper);
}
// guess block state
BlockStateWrapper wrapperGuess = (BlockStateWrapper) guess;
#if MC_VER <= MC_1_12_2 IBlockState #else BlockState #endif guessBlockState;
if(isAir(wrapperGuess.blockState))
{
guessBlockState = null;
}
else
{
#if MC_VER <= MC_1_12_2
guessBlockState = (IBlockState) guess.getWrappedMcObject();
#else
guessBlockState = (BlockState) guess.getWrappedMcObject();
#endif
}
// input block state
#if MC_VER <= MC_1_12_2 IBlockState #else BlockState #endif inputBlockState;
if (isAir(blockState))
{
inputBlockState = null;
}
else
{
inputBlockState = blockState;
}
if (guessBlockState == inputBlockState)
{
return (BlockStateWrapper) guess;
}
return fromBlockState(blockState, levelWrapper);
}
public static BlockStateWrapper fromBlockState(@Nullable #if MC_VER <= MC_1_12_2 IBlockState #else BlockState #endif blockState, ILevelWrapper levelWrapper)
public static BlockStateWrapper fromBlockState(
@Nullable #if MC_VER <= MC_1_12_2 IBlockState #else BlockState #endif blockState,
ILevelWrapper levelWrapper)
{
// air is a special case
if (isAir(blockState))
@@ -248,13 +273,13 @@ public class BlockStateWrapper implements IBlockStateWrapper
}
else
{
#if MC_VER <= MC_1_12_2
this.isLiquid = this.blockState.getMaterial().isLiquid() || this.blockState.getBlock() instanceof IFluidBlock;
#elif MC_VER < MC_1_20_1
this.isLiquid = this.blockState.getMaterial().isLiquid() || !this.blockState.getFluidState().isEmpty();
#else
this.isLiquid = !this.blockState.getFluidState().isEmpty();
#endif
#if MC_VER <= MC_1_12_2
this.isLiquid = this.blockState.getMaterial().isLiquid() || this.blockState.getBlock() instanceof IFluidBlock;
#elif MC_VER < MC_1_20_1
this.isLiquid = this.blockState.getMaterial().isLiquid() || !this.blockState.getFluidState().isEmpty();
#else
this.isLiquid = !this.blockState.getFluidState().isEmpty();
#endif
}
}
@@ -349,7 +374,7 @@ public class BlockStateWrapper implements IBlockStateWrapper
// beacon tint color
Color beaconTintColor = null;
// 1.12.2 doesn't have block for beacon beam
// 1.12.2 doesn't support changing the beacon beam color
#if MC_VER > MC_1_12_2
if (this.blockState != null
// beacon blocks also show up here, but since they block the beacon beam we don't want their color
@@ -462,71 +487,188 @@ public class BlockStateWrapper implements IBlockStateWrapper
@Nullable #if MC_VER <= MC_1_12_2 IBlockState #else BlockState #endif blockState,
String lowercaseSerialString,
boolean isLiquid
)
)
{
if (blockState == null)
if (isAir(blockState))
{
return EDhApiBlockMaterial.AIR;
}
if (#if MC_VER <= MC_1_12_2 blockState.getBlock() instanceof BlockLeaves #else blockState.is(BlockTags.LEAVES) #endif
//========//
// leaves //
//========//
//region
boolean isLeafBlock;
#if MC_VER <= MC_1_12_2
isLeafBlock = blockState.getBlock() instanceof BlockLeaves;
#else
isLeafBlock = blockState.is(BlockTags.LEAVES);
#endif
if (isLeafBlock
|| lowercaseSerialString.contains("bamboo")
|| lowercaseSerialString.contains("cactus")
|| lowercaseSerialString.contains("chorus_flower")
|| lowercaseSerialString.contains("mushroom")
)
)
{
return EDhApiBlockMaterial.LEAVES;
}
else if (#if MC_VER <= MC_1_12_2 blockState.getBlock() == Blocks.LAVA || blockState.getBlock() == Blocks.FLOWING_LAVA #else blockState.is(Blocks.LAVA) #endif)
//endregion
//======//
// lava //
//======//
//region
boolean isLavaBlock;
#if MC_VER <= MC_1_12_2
isLavaBlock = blockState.getBlock() == Blocks.LAVA || blockState.getBlock() == Blocks.FLOWING_LAVA;
#else
isLavaBlock = blockState.is(Blocks.LAVA);
#endif
if (isLavaBlock)
{
return EDhApiBlockMaterial.LAVA;
}
else if (isLiquid || #if MC_VER <= MC_1_12_2 blockState.getBlock() == Blocks.WATER || blockState.getBlock() == Blocks.FLOWING_WATER #else blockState.is(Blocks.WATER) #endif)
//endregion
//=======//
// water //
//=======//
//region
boolean isWaterBlock;
#if MC_VER <= MC_1_12_2
isWaterBlock = blockState.getBlock() == Blocks.WATER || blockState.getBlock() == Blocks.FLOWING_WATER;
#else
isWaterBlock = blockState.is(Blocks.WATER);
#endif
if (isLiquid
|| isWaterBlock)
{
return EDhApiBlockMaterial.WATER;
}
else if (#if MC_VER <= MC_1_12_2 blockState.getBlock().getSoundType() #else blockState.getSoundType() #endif == SoundType.WOOD
//endregion
//======//
// wood //
//======//
//region
boolean isWoodSoundingBlock;
#if MC_VER <= MC_1_12_2
isWoodSoundingBlock = blockState.getBlock().getSoundType() == SoundType.WOOD;
#else
isWoodSoundingBlock = blockState.getSoundType() == SoundType.WOOD;
#endif
boolean isCherryWood;
#if MC_VER <= MC_1_19_2
isCherryWood = false;
#else
isWoodSoundingBlock = blockState.getSoundType() == SoundType.CHERRY_WOOD;
#endif
if (isWoodSoundingBlock
|| lowercaseSerialString.contains("root")
#if MC_VER >= MC_1_19_4
|| blockState.getSoundType() == SoundType.CHERRY_WOOD
#endif
)
|| isCherryWood
)
{
return EDhApiBlockMaterial.WOOD;
}
else if (#if MC_VER <= MC_1_12_2 blockState.getBlock().getSoundType() #else blockState.getSoundType() #endif == SoundType.METAL
#if MC_VER >= MC_1_19_2
|| blockState.getSoundType() == SoundType.COPPER
#endif
#if MC_VER >= MC_1_20_4
|| blockState.getSoundType() == SoundType.COPPER_BULB
|| blockState.getSoundType() == SoundType.COPPER_GRATE
#endif
)
//endregion
//=======//
// metal //
//=======//
//region
boolean isMetalSoundingBlock;
#if MC_VER <= MC_1_12_2
isMetalSoundingBlock = blockState.getBlock().getSoundType() == SoundType.METAL;
#else
isMetalSoundingBlock = blockState.getSoundType() == SoundType.METAL;
#endif
boolean isCopperSounding;
#if MC_VER <= MC_1_18_2
isCopperSounding = false;
#elif MC_VER <= MC_1_20_2
isCopperSounding = blockState.getSoundType() == SoundType.COPPER
#else
isCopperSounding
= blockState.getSoundType() == SoundType.COPPER
|| blockState.getSoundType() == SoundType.COPPER_BULB
|| blockState.getSoundType() == SoundType.COPPER_GRATE;
#endif
if (isMetalSoundingBlock
|| isCopperSounding)
{
return EDhApiBlockMaterial.METAL;
}
else if (
lowercaseSerialString.contains("grass_block")
|| lowercaseSerialString.contains("grass_slab")
)
//endregion
//=======//
// grass //
//=======//
//region
if (lowercaseSerialString.contains("grass_block")
|| lowercaseSerialString.contains("grass_slab")
)
{
return EDhApiBlockMaterial.GRASS;
}
else if (
//endregion
//======//
// dirt //
//======//
//region
if (
lowercaseSerialString.contains("dirt")
|| lowercaseSerialString.contains("gravel")
|| lowercaseSerialString.contains("mud")
|| lowercaseSerialString.contains("podzol")
|| lowercaseSerialString.contains("mycelium")
)
|| lowercaseSerialString.contains("gravel")
|| lowercaseSerialString.contains("mud")
|| lowercaseSerialString.contains("podzol")
|| lowercaseSerialString.contains("mycelium")
)
{
return EDhApiBlockMaterial.DIRT;
}
//endregion
//===========//
// deepslate //
//===========//
//region
#if MC_VER >= MC_1_17_1
else if (blockState.getSoundType() == SoundType.DEEPSLATE
if (blockState.getSoundType() == SoundType.DEEPSLATE
|| blockState.getSoundType() == SoundType.DEEPSLATE_BRICKS
|| blockState.getSoundType() == SoundType.DEEPSLATE_TILES
|| blockState.getSoundType() == SoundType.POLISHED_DEEPSLATE
@@ -535,35 +677,68 @@ public class BlockStateWrapper implements IBlockStateWrapper
return EDhApiBlockMaterial.DEEPSLATE;
}
#endif
else if (lowercaseSerialString.contains("snow"))
{
return EDhApiBlockMaterial.SNOW;
}
else if (lowercaseSerialString.contains("sand"))
{
return EDhApiBlockMaterial.SAND;
}
else if (lowercaseSerialString.contains("terracotta"))
{
return EDhApiBlockMaterial.TERRACOTTA;
}
else if (#if MC_VER <= MC_1_12_2 blockState.getBlock() == Blocks.NETHERRACK #else blockState.is(BlockTags.BASE_STONE_NETHER) #endif)
//endregion
//============//
// netherrack //
//============//
//region
boolean isNetherRack;
#if MC_VER <= MC_1_12_2
isNetherRack = blockState.getBlock() == Blocks.NETHERRACK;
#else
isNetherRack = blockState.is(BlockTags.BASE_STONE_NETHER);
#endif
if (isNetherRack)
{
return EDhApiBlockMaterial.NETHER_STONE;
}
else if (lowercaseSerialString.contains("stone")
//endregion
//=============//
// misc/simple //
//=============//
//region
if (lowercaseSerialString.contains("snow"))
{
return EDhApiBlockMaterial.SNOW;
}
if (lowercaseSerialString.contains("sand"))
{
return EDhApiBlockMaterial.SAND;
}
if (lowercaseSerialString.contains("terracotta"))
{
return EDhApiBlockMaterial.TERRACOTTA;
}
if (lowercaseSerialString.contains("stone")
|| lowercaseSerialString.contains("ore"))
{
return EDhApiBlockMaterial.STONE;
}
else if (#if MC_VER <= MC_1_12_2 blockState.getLightValue() #else blockState.getLightEmission() #endif > 0)
if (getLightEmission(blockState) > 0)
{
return EDhApiBlockMaterial.ILLUMINATED;
}
else
{
return EDhApiBlockMaterial.UNKNOWN;
}
//endregion
return EDhApiBlockMaterial.UNKNOWN;
}
private static int calculateOpacity(
@@ -691,8 +866,10 @@ public class BlockStateWrapper implements IBlockStateWrapper
return waterSurfaceReplacementBlocks;
}
ObjectOpenHashSet<String> baseIgnoredBlock = new ObjectOpenHashSet<>();
waterSurfaceReplacementBlocks = getAllBlockWrappers(Config.Client.Advanced.Graphics.Culling.waterSurfaceBlockReplacementCsv, baseIgnoredBlock, levelWrapper);
ObjectOpenHashSet<String> baseIgnoredBlockResourceSet = new ObjectOpenHashSet<>();
waterSurfaceReplacementBlocks = getAllBlockWrappers(Config.Client.Advanced.Graphics.Culling.waterSurfaceBlockReplacementCsv, baseIgnoredBlockResourceSet, levelWrapper);
waterSubsurfaceReplacementBlocks.remove(AIR);
return waterSurfaceReplacementBlocks;
}
public static ObjectOpenHashSet<IBlockStateWrapper> getWaterSubsurfaceReplacementBlocks(ILevelWrapper levelWrapper)
@@ -703,8 +880,10 @@ public class BlockStateWrapper implements IBlockStateWrapper
return waterSubsurfaceReplacementBlocks;
}
ObjectOpenHashSet<String> baseIgnoredBlock = new ObjectOpenHashSet<>();
waterSubsurfaceReplacementBlocks = getAllBlockWrappers(Config.Client.Advanced.Graphics.Culling.waterSubSurfaceBlockReplacementCsv, baseIgnoredBlock, levelWrapper);
ObjectOpenHashSet<String> baseIgnoredBlockResourceSet = new ObjectOpenHashSet<>();
waterSubsurfaceReplacementBlocks = getAllBlockWrappers(Config.Client.Advanced.Graphics.Culling.waterSubSurfaceBlockReplacementCsv, baseIgnoredBlockResourceSet, levelWrapper);
// air will be present if any invalid resource locations are present
// but we don't want to replace air with water, that'll cause monoliths
waterSubsurfaceReplacementBlocks.remove(AIR);
return waterSubsurfaceReplacementBlocks;
@@ -826,7 +1005,21 @@ public class BlockStateWrapper implements IBlockStateWrapper
public int getOpacity() { return this.opacity; }
@Override
public int getLightEmission() { return (this.blockState != null) ? #if MC_VER <= MC_1_12_2 this.blockState.getLightValue() #else this.blockState.getLightEmission() #endif : 0; }
public int getLightEmission() { return getLightEmission(this.blockState); }
public static int getLightEmission(#if MC_VER <= MC_1_12_2 IBlockState #else BlockState #endif blockState)
{
if (blockState == null)
{
return 0;
}
#if MC_VER <= MC_1_12_2
return blockState.getLightValue();
#else
return blockState.getLightEmission();
#endif
}
@Override
public String getSerialString() { return this.serialString; }
@@ -836,7 +1029,19 @@ public class BlockStateWrapper implements IBlockStateWrapper
@Override
public boolean isAir() { return isAir(this.blockState); }
public static boolean isAir(#if MC_VER <= MC_1_12_2 IBlockState #else BlockState #endif blockState) { return blockState == null || #if MC_VER <= MC_1_12_2 blockState.getBlock() == Blocks.AIR #else blockState.isAir() #endif; }
public static boolean isAir(#if MC_VER <= MC_1_12_2 IBlockState #else BlockState #endif blockState)
{
if (blockState == null)
{
return true;
}
#if MC_VER <= MC_1_12_2
return blockState.getBlock() == Blocks.AIR;
#else
return blockState.isAir();
#endif
}
@Override
public boolean isSolid() { return this.isSolid; }
@@ -1056,7 +1261,12 @@ public class BlockStateWrapper implements IBlockStateWrapper
}
}
foundState = #if MC_VER <= MC_1_12_2 block.getDefaultState() #else block.defaultBlockState() #endif;
#if MC_VER <= MC_1_12_2
foundState = block.getDefaultState();
#else
foundState = block.defaultBlockState();
#endif
}
foundWrapper = fromBlockState(foundState, levelWrapper);
@@ -1086,12 +1296,13 @@ public class BlockStateWrapper implements IBlockStateWrapper
// get the property list for this block (doesn't contain this block state's values, just the names and possible values)
#if MC_VER <= MC_1_12_2
java.util.Collection<IProperty<?>> blockPropertyCollection = blockState.getPropertyKeys();
List<IProperty<?>> sortedBlockPropteryList = new ArrayList<>(blockPropertyCollection);
#else
java.util.Collection<net.minecraft.world.level.block.state.properties.Property<?>> blockPropertyCollection = blockState.getProperties();;
List<net.minecraft.world.level.block.state.properties.Property<?>> sortedBlockPropteryList = new ArrayList<>(blockPropertyCollection);
#endif
// alphabetically sort the list so they are always in the same order
List<#if MC_VER <= MC_1_12_2 IProperty<?> #else net.minecraft.world.level.block.state.properties.Property<?> #endif> sortedBlockPropteryList = new ArrayList<>(blockPropertyCollection);
sortedBlockPropteryList.sort((a, b) -> a.getName().compareTo(b.getName()));
@@ -94,7 +94,11 @@ public class ClientBlockStateColorCache
private static final Minecraft MC = Minecraft.#if MC_VER <= MC_1_12_2 getMinecraft() #else getInstance() #endif;
private static final HashSet<#if MC_VER <= MC_1_12_2 IBlockState #else BlockState #endif> BLOCK_STATES_THAT_NEED_LEVEL = new HashSet<>();
#if MC_VER <= MC_1_12_2
#else
private static final HashSet<BlockState> BLOCK_STATES_THAT_NEED_LEVEL = new HashSet<>();
#endif
private static final HashSet<#if MC_VER <= MC_1_12_2 IBlockState #else BlockState #endif> BROKEN_BLOCK_STATES = new HashSet<>();
/**
@@ -107,6 +111,8 @@ public class ClientBlockStateColorCache
*/
private static final ReentrantLock RESOLVE_LOCK = new ReentrantLock();
public static final int INVALID_COLOR = -1;
/** 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 =
@@ -225,7 +231,9 @@ public class ClientBlockStateColorCache
//=============//
//region
public ClientBlockStateColorCache(#if MC_VER <= MC_1_12_2 IBlockState #else BlockState #endif blockState, IClientLevelWrapper clientLevelWrapper)
public ClientBlockStateColorCache(
#if MC_VER <= MC_1_12_2 IBlockState #else BlockState #endif blockState,
IClientLevelWrapper clientLevelWrapper)
{
this.blockState = blockState;
this.blockStateWrapper = BlockStateWrapper.fromBlockState(blockState, clientLevelWrapper);
@@ -241,6 +249,7 @@ public class ClientBlockStateColorCache
//===================//
// color calculation //
//===================//
//region
private void resolveColors()
{
@@ -268,11 +277,7 @@ public class ClientBlockStateColorCache
}
#endif
#if MC_VER <= MC_1_12_2
if (!this.blockState.getMaterial().isLiquid())
#else
if (this.blockState.getFluidState().isEmpty())
#endif
if (!this.blockStateWrapper.isLiquid())
{
// look for the first non-empty direction
List<BakedQuad> quads = null;
@@ -593,6 +598,8 @@ public class ClientBlockStateColorCache
EColorMode.getColorMode(this.blockState.getBlock()));
}
//endregion
//===============//
@@ -602,11 +609,7 @@ public class ClientBlockStateColorCache
public int getColor(BiomeWrapper biomeWrapper, FullDataSourceV2 fullDataSource, DhBlockPos blockPos)
{
// only get the tint if the block needs to be tinted
#if MC_VER <= MC_1_12_2
int tintColor = -1;
#else
int tintColor = AbstractDhTintGetter.INVALID_COLOR;
#endif
int tintColor = INVALID_COLOR;
if (this.needPostTinting)
{
@@ -624,8 +627,10 @@ public class ClientBlockStateColorCache
// 1.12.2 doesn't have BlockAndTintGetter -> get tintColor from biome
WorldClient world = (WorldClient) this.clientLevelWrapper.getWrappedMcObject();
BlockPos mcPos = new BlockPos(blockPos.getX(), blockPos.getY(), blockPos.getZ());
Block block = this.blockState.getBlock();
if (block instanceof BlockGrass || block instanceof BlockBush)
if (block instanceof BlockGrass
|| block instanceof BlockBush)
{
tintColor = biomeWrapper.biome.getGrassColorAtPos(mcPos);
}
@@ -635,7 +640,8 @@ public class ClientBlockStateColorCache
}
else if (block instanceof BlockLiquid) // We don't want lava to fall into the else block
{
if(block == Blocks.WATER || block == Blocks.FLOWING_WATER)
if(block == Blocks.WATER
|| block == Blocks.FLOWING_WATER)
{
tintColor = biomeWrapper.biome.getWaterColor();
}
@@ -721,29 +727,32 @@ public class ClientBlockStateColorCache
}
}
#endif
// level-specific logic is only needed for MC 1.21.11 and older
#if MC_VER <= MC_1_21_11 && MC_VER > MC_1_12_2
// use the level logic only if requested
if (BLOCK_STATES_THAT_NEED_LEVEL.contains(this.blockState))
{
// the level shouldn't be used all the time due to it breaking some blocks tinting
// specifically oceans don't render correctly
TintGetterOverride tintOverride = TintOverrideGetter.get();
tintOverride.update(biomeWrapper, this.blockStateWrapper, fullDataSource, this.clientLevelWrapper);
tintColor = tintOverride.tryGetBlockTint(new DhBlockPosMutable(blockPos));
if (tintColor == AbstractDhTintGetter.INVALID_COLOR)
// level-specific logic is only needed for MC 1.21.11 and older
#if MC_VER <= MC_1_21_11 && MC_VER > MC_1_12_2
// use the level logic only if requested
if (BLOCK_STATES_THAT_NEED_LEVEL.contains(this.blockState))
{
tintColor = Minecraft.getInstance()
.getBlockColors()
.getColor(this.blockState,
tintOverride,
McObjectConverter.Convert(blockPos),
this.tintIndex);
// the level shouldn't be used all the time due to it breaking some blocks tinting
// specifically oceans don't render correctly
TintGetterOverride tintOverride = TintOverrideGetter.get();
tintOverride.update(biomeWrapper, this.blockStateWrapper, fullDataSource, this.clientLevelWrapper);
tintColor = tintOverride.tryGetBlockTint(new DhBlockPosMutable(blockPos));
if (tintColor == AbstractDhTintGetter.INVALID_COLOR)
{
tintColor = Minecraft.getInstance()
.getBlockColors()
.getColor(this.blockState,
tintOverride,
McObjectConverter.Convert(blockPos),
this.tintIndex);
}
}
}
#endif
#endif
}
catch (Exception e)
{
@@ -758,11 +767,7 @@ public class ClientBlockStateColorCache
int returnColor;
#if MC_VER <= MC_1_12_2
if (tintColor != -1)
#else
if (tintColor != AbstractDhTintGetter.INVALID_COLOR)
#endif
if (tintColor != INVALID_COLOR)
{
returnColor = ColorUtil.multiplyARGBwithRGB(this.baseColor, tintColor);
}
@@ -15,7 +15,11 @@ public class GetConfigScreen
{
protected static final DhLogger LOGGER = new DhLoggerBuilder().build();
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)
#if MC_VER <= MC_1_12_2
public static GuiScreen getScreen(GuiScreen parent)
#else
public static Screen getScreen(Screen parent)
#endif
{
if (ModInfo.IS_DEV_BUILD)
{
@@ -34,7 +34,11 @@ import java.util.*;
public class MinecraftScreen
{
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, AbstractScreen screen, String translationName)
#if MC_VER <= MC_1_12_2
public static GuiScreen getScreen(GuiScreen parent, AbstractScreen screen, String translationName)
#else
public static Screen getScreen(Screen parent, AbstractScreen screen, String translationName)
#endif
{
return new ConfigScreenRenderer(parent, screen, translationName);
}
@@ -56,7 +60,9 @@ public class MinecraftScreen
{ return net.minecraft.network.chat.Component.translatable(str, args); }
#endif
protected ConfigScreenRenderer(#if MC_VER <= MC_1_12_2 GuiScreen #else Screen #endif parent, AbstractScreen screen, String translationName)
protected ConfigScreenRenderer(
#if MC_VER <= MC_1_12_2 GuiScreen #else Screen #endif parent,
AbstractScreen screen, String translationName)
{
super(translate(translationName));
#if MC_VER <= MC_1_12_2
@@ -77,7 +83,13 @@ public class MinecraftScreen
protected void init()
#endif
{
super.#if MC_VER <= MC_1_12_2 initGui(); #else init(); #endif // Init Minecraft's screen
#if MC_VER <= MC_1_12_2
super.initGui();
#else
super.init();
#endif
#if MC_VER <= MC_1_12_2
this.screen.width = Display.getWidth();
this.screen.height = Display.getHeight();
@@ -1,4 +1,5 @@
package com.seibel.distanthorizons.common.wrappers.gui;
#if MC_VER <= MC_1_12_2
import net.minecraft.client.gui.GuiButton;
@@ -85,7 +85,8 @@ public class ClientLevelWrapper implements IClientLevelWrapper
private final ConcurrentHashMap<#if MC_VER <= MC_1_12_2 IBlockState #else BlockState #endif, ClientBlockStateColorCache> blockColorCacheByBlockState = new ConcurrentHashMap<>();
/** cached method reference to reduce GC overhead */
private final Function<#if MC_VER <= MC_1_12_2 IBlockState #else BlockState #endif, ClientBlockStateColorCache> createCachedBlockColorCacheFunc = (blockState) -> new ClientBlockStateColorCache(blockState, this);
private final Function<#if MC_VER <= MC_1_12_2 IBlockState #else BlockState #endif, ClientBlockStateColorCache> createCachedBlockColorCacheFunc
= (blockState) -> new ClientBlockStateColorCache(blockState, this);
private boolean cloudColorFailLogged = false;
+1 -1
View File
@@ -48,7 +48,7 @@ versionStr=
# This defines what MC version Intellij will use for the preprocessor
# and what version is used automatically by build and run commands
mcVer=26.1.2
mcVer=1.12.2
# Defines the maximum amount of memory Minecraft is allowed when run in a development environment
minecraftMemoryJavaArg=-Xmx6G
+1 -1
View File
@@ -8,7 +8,7 @@ builds_for=cleanroom
embed_joml=true
# Netty
netty_version=4.2.9.Final
netty_version=4.1.9.Final
# LWJGL
lwjgl_version=3.3.6