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
+36 -9
View File
@@ -12,19 +12,46 @@ plugins {
id "dev.architectury.loom" version "0.10.0-SNAPSHOT" apply false
}
def writeBuildGradlePredefine() {
def excapedMCVersion = rootProject.minecraft_version.replace(".", "_")
new File(projectDir, "build.properties").text = "MC_VERSION_${excapedMCVersion}=\n"
def writeBuildGradlePredefine(List<String> mcVers, int mcIndex) {
ArrayList<String> redefineList = new ArrayList<String>()
for (int i=0; i<mcVers.size(); i++) {
String mcStr = mcVers.get(i).replace(".", "_")
if (mcIndex<i) {
redefineList.add("PRE_MC_"+mcStr)
}
if (mcIndex==i) {
redefineList.add("MC_"+mcStr)
}
if (mcIndex>=i) {
redefineList.add("POST_MC_"+mcStr)
}
}
StringBuilder sb = new StringBuilder()
for (String s : redefineList) {
sb.append(s)
sb.append("=\n")
}
new File(projectDir, "build.properties").text = sb.toString()
}
// Sets up the variables for Manifold in the code
def loadProperties() {
def defaultMcVersion = '1.18.2'
if (!project.hasProperty("mcVer")) {
println "No mcVer set! Defaulting to ${defaultMcVersion}."
println "Tip: Use -PmcVer='${defaultMcVersion}' in cmd arg to set mcVer."
def defaultMcVersion = "1.18.2"
def mcVersion = ""
def mcVers = mcVersions.split(",")
int mcIndex = -1
println "Avalible MC versions: ${mcVersions}"
if (project.hasProperty("mcVer")) {
mcVersion = mcVer
mcIndex = Arrays.asList(mcVers).indexOf(mcVer)
}
if (mcIndex == -1) {
println "No mcVer set or the set mcVer is invalid! Defaulting to ${defaultMcVersion}."
println "Tip: Use -PmcVer='${defaultMcVersion}' in cmd arg to set mcVer."
mcVersion = defaultMcVersion
mcIndex = Arrays.asList(mcVers).indexOf(defaultMcVersion)
assert mcIndex != -1
}
def mcVersion = project.hasProperty("mcVer") ? mcVer : defaultMcVersion
println "Loading properties file at " + mcVersion + ".properties"
def props = new Properties()
@@ -34,7 +61,7 @@ def loadProperties() {
rootProject.ext.set(prop.key, prop.value)
// println "Added prop [key:" + prop.key + ", value:" + prop.value + "]"
}
writeBuildGradlePredefine()
writeBuildGradlePredefine(Arrays.asList(mcVers), mcIndex)
// Stuff for access wideners
def mcVersionToAcsessWidenerVersion = [
@@ -266,7 +266,7 @@ public class BlockDetailWrapper extends IBlockDetailWrapper
needShade = quads.get(0).isShade();
tintIndex = quads.get(0).getTintIndex();
baseColor = calculateColorFromTexture(
#if MC_VERSION_1_16_5 quads.get(0).sprite,
#if PRE_MC_1_17_1 quads.get(0).sprite,
#else quads.get(0).getSprite(), #endif
ColorMode.getColorMode(state.getBlock()));
} else { // Backup method.
@@ -37,7 +37,7 @@ public class TextureAtlasSpriteWrapper {
* The code has been modified to use TextureAtlasSprite
*/
public static int getPixelRGBA(TextureAtlasSprite sprite, int frameIndex, int x, int y) {
#if MC_VERSION_1_16_5
#if PRE_MC_1_17_1
return sprite.mainImage[0].getPixelRGBA(
x + sprite.framesX[frameIndex] * sprite.getWidth(),
y + sprite.framesY[frameIndex] * sprite.getHeight());
@@ -53,7 +53,7 @@ public class TintGetterOverrideFast implements BlockAndTintGetter {
}
private Biome _getBiome(BlockPos pos) {
#if MC_VERSION_1_18_2
#if POST_MC_1_18_2
return parent.getBiome(pos).value();
#else
return parent.getBiome(pos);
@@ -153,7 +153,7 @@ public class TintGetterOverrideFast implements BlockAndTintGetter {
return parent.getMaxBuildHeight();
}
#if !MC_VERSION_1_16_5
#if POST_MC_1_17_1
@Override
public <T extends BlockEntity> Optional<T> getBlockEntity(BlockPos blockPos, BlockEntityType<T> blockEntityType) {
return parent.getBlockEntity(blockPos, blockEntityType);
@@ -54,7 +54,7 @@ public class TintGetterOverrideSmooth implements BlockAndTintGetter {
}
private Biome _getBiome(BlockPos pos) {
#if MC_VERSION_1_18_2
#if POST_MC_1_18_2
return parent.getBiome(pos).value();
#else
return parent.getBiome(pos);
@@ -177,7 +177,7 @@ public class TintGetterOverrideSmooth implements BlockAndTintGetter {
return parent.getMaxBuildHeight();
}
#if !MC_VERSION_1_16_5
#if POST_MC_1_17_1
@Override
public <T extends BlockEntity> Optional<T> getBlockEntity(BlockPos blockPos, BlockEntityType<T> blockEntityType) {
return parent.getBlockEntity(blockPos, blockEntityType);
@@ -148,10 +148,10 @@ public class ChunkPosWrapper extends AbstractChunkPosWrapper
public AbstractBlockPosWrapper getWorldPosition()
{
// the parameter here is the y position
#if MC_VERSION_1_17_1 || MC_VERSION_1_18_1 || MC_VERSION_1_18_2
BlockPos blockPos = chunkPos.getMiddleBlockPosition(0);
#elif MC_VERSION_1_16_5
#if PRE_MC_1_17_1
BlockPos blockPos = chunkPos.getWorldPosition();
#else
BlockPos blockPos = chunkPos.getMiddleBlockPosition(0);
#endif
return new BlockPosWrapper(blockPos.getX(), blockPos.getY(), blockPos.getZ());
}
@@ -33,7 +33,7 @@ import com.seibel.lod.common.wrappers.world.BiomeWrapper;
import com.seibel.lod.common.wrappers.worldGeneration.mimicObject.LightedWorldGenRegion;
import net.minecraft.core.BlockPos;
#if MC_VERSION_1_17_1 || MC_VERSION_1_18_1 || MC_VERSION_1_18_2
#if POST_MC_1_17_1
import net.minecraft.core.QuartPos;
#endif
import net.minecraft.world.level.LevelReader;
@@ -66,20 +66,20 @@ public class ChunkWrapper implements IChunkWrapper
@Override
public int getHeight(){
#if MC_VERSION_1_17_1 || MC_VERSION_1_18_1 || MC_VERSION_1_18_2
return chunk.getHeight();
#elif MC_VERSION_1_16_5
#if PRE_MC_1_17_1
return 255;
#else
return chunk.getHeight();
#endif
}
@Override
public int getMinBuildHeight()
{
#if MC_VERSION_1_17_1 || MC_VERSION_1_18_1 || MC_VERSION_1_18_2
#if PRE_MC_1_17_1
return 255;
#else
return chunk.getMinBuildHeight();
#elif MC_VERSION_1_16_5
return 0;
#endif
}
@Override
@@ -97,19 +97,19 @@ public class ChunkWrapper implements IChunkWrapper
@Override
public IBiomeWrapper getBiome(int x, int y, int z)
{
#if MC_VERSION_1_18_2
return BiomeWrapper.getBiomeWrapper(chunk.getNoiseBiome(
QuartPos.fromBlock(x), QuartPos.fromBlock(y), QuartPos.fromBlock(z)).value());
#elif MC_VERSION_1_18_1
return BiomeWrapper.getBiomeWrapper(chunk.getNoiseBiome(
QuartPos.fromBlock(x), QuartPos.fromBlock(y), QuartPos.fromBlock(z)));
#elif MC_VERSION_1_17_1
return BiomeWrapper.getBiomeWrapper(chunk.getBiomes().getNoiseBiome(
QuartPos.fromBlock(x), QuartPos.fromBlock(y), QuartPos.fromBlock(z)));
#elif MC_VERSION_1_16_5
#if PRE_MC_1_17_1
return BiomeWrapper.getBiomeWrapper(chunk.getBiomes().getNoiseBiome(
x >> 2, y >> 2, z >> 2));
#endif
#elif PRE_MC_1_18_1
return BiomeWrapper.getBiomeWrapper(chunk.getBiomes().getNoiseBiome(
QuartPos.fromBlock(x), QuartPos.fromBlock(y), QuartPos.fromBlock(z)));
#elif PRE_MC_1_18_2
return BiomeWrapper.getBiomeWrapper(chunk.getNoiseBiome(
QuartPos.fromBlock(x), QuartPos.fromBlock(y), QuartPos.fromBlock(z)));
#else
return BiomeWrapper.getBiomeWrapper(chunk.getNoiseBiome(
QuartPos.fromBlock(x), QuartPos.fromBlock(y), QuartPos.fromBlock(z)).value());
#endif
}
@Override
@@ -189,9 +189,9 @@ public class ChunkWrapper implements IChunkWrapper
@Override
public boolean isLightCorrect(){
#if MC_VERSION_1_16_5 || MC_VERSION_1_17_1
#if PRE_MC_1_18_1
return true;
#elif MC_VERSION_1_18_2 || MC_VERSION_1_18_1
#else
if (chunk instanceof LevelChunk) {
return ((LevelChunk) chunk).isClientLightReady();
}
@@ -50,7 +50,7 @@ import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.client.resources.language.I18n; // translation
#if MC_VERSION_1_17_1 || MC_VERSION_1_18_1 || MC_VERSION_1_18_2
#if POST_MC_1_17_1
import net.minecraft.client.gui.narration.NarratableEntry;
#endif
@@ -530,6 +530,17 @@ public abstract class ConfigGui
Objects.requireNonNull(minecraft).setScreen(this.parent);
}
// addRenderableWidget in 1.17 and over
// addButton in 1.16 and below
private Button addBtn(Button button) {
#if PRE_MC_1_17_1
this.addButton(button);
#else
this.addRenderableWidget(button);
#endif
return button;
}
@Override
protected void init()
{
@@ -537,31 +548,14 @@ public abstract class ConfigGui
if (!reload)
loadFromFile();
// addRenderableWidget in 1.17 and over
// addButton in 1.16 and below
#if MC_VERSION_1_17_1 || MC_VERSION_1_18_1 || MC_VERSION_1_18_2
this.addRenderableWidget(new Button(this.width / 2 - 154, this.height - 28, 150, 20, CommonComponents.GUI_CANCEL, button -> {
addBtn(new Button(this.width / 2 - 154, this.height - 28, 150, 20, CommonComponents.GUI_CANCEL, button -> {
loadFromFile();
Objects.requireNonNull(minecraft).setScreen(parent);
}));
#elif MC_VERSION_1_16_5
this.addButton(new Button(this.width / 2 - 154, this.height - 28, 150, 20, CommonComponents.GUI_CANCEL, button -> {
loadFromFile();
Objects.requireNonNull(minecraft).setScreen(parent);
}));
#endif
#if MC_VERSION_1_17_1 || MC_VERSION_1_18_1 || MC_VERSION_1_18_2
Button done = this.addRenderableWidget(new Button(this.width / 2 + 4, this.height - 28, 150, 20, CommonComponents.GUI_DONE, (button) -> {
Button done = addBtn(new Button(this.width / 2 + 4, this.height - 28, 150, 20, CommonComponents.GUI_DONE, (button) -> {
saveToFile();
Objects.requireNonNull(minecraft).setScreen(parent);
}));
#elif MC_VERSION_1_16_5
Button done = this.addButton(new Button(this.width / 2 + 4, this.height - 28, 150, 20, CommonComponents.GUI_DONE, (button) -> {
saveToFile();
Objects.requireNonNull(minecraft).setScreen(parent);
}));
#endif
this.list = new ConfigListWidget(this.minecraft, this.width * 2, this.height, 32, this.height - 32, 25);
if (this.minecraft != null && this.minecraft.level != null)
@@ -769,7 +763,7 @@ public abstract class ConfigGui
// Only for 1.17 and over
// Remove in 1.16 and below
#if MC_VERSION_1_17_1 || MC_VERSION_1_18_1 || MC_VERSION_1_18_2
#if POST_MC_1_17_1
@Override
public List<? extends NarratableEntry> narratables()
{
@@ -31,7 +31,7 @@ import net.minecraft.resources.ResourceLocation;
* Creates a button with a texture on it
*/
public class TexturedButtonWidget extends ImageButton {
#if MC_VERSION_1_17_1 || MC_VERSION_1_18_1 || MC_VERSION_1_18_2
#if POST_MC_1_17_1
public TexturedButtonWidget(int x, int y, int width, int height, int u, int v, ResourceLocation texture, OnPress pressAction) {
super(x, y, width, height, u, v, texture, pressAction);
}
@@ -51,13 +51,13 @@ public class TexturedButtonWidget extends ImageButton {
@Override
public void renderButton(PoseStack matrices, int mouseX, int mouseY, float delta) {
#if MC_VERSION_1_17_1 || MC_VERSION_1_18_1 || MC_VERSION_1_18_2
#if PRE_MC_1_17_1
Minecraft.getInstance().getTextureManager().bind(WIDGETS_LOCATION);
RenderSystem.color4f(1.0F, 1.0F, 1.0F, this.alpha);
#else
RenderSystem.setShader(GameRenderer::getPositionTexShader);
RenderSystem.setShaderTexture(0, WIDGETS_LOCATION);
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, this.alpha);
#elif MC_VERSION_1_16_5
Minecraft.getInstance().getTextureManager().bind(WIDGETS_LOCATION);
RenderSystem.color4f(1.0F, 1.0F, 1.0F, this.alpha);
#endif
int i = this.getYImage(this.isHovered);
@@ -188,10 +188,10 @@ public class MinecraftClientWrapper implements IMinecraftClientWrapper
@Override
public ChunkPosWrapper getPlayerChunkPos()
{
#if MC_VERSION_1_17_1 || MC_VERSION_1_18_1 || MC_VERSION_1_18_2
ChunkPos playerPos = getPlayer().chunkPosition();
#elif MC_VERSION_1_16_5
#if PRE_MC_1_17_1
ChunkPos playerPos = new ChunkPos(getPlayer().blockPosition());
#else
ChunkPos playerPos = getPlayer().chunkPosition();
#endif
return new ChunkPosWrapper(playerPos.x, playerPos.z);
}
@@ -61,11 +61,11 @@ import net.minecraft.core.BlockPos;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
#if MC_VERSION_1_17_1 || MC_VERSION_1_18_1 || MC_VERSION_1_18_2
import net.minecraft.world.level.material.FogType;
#elif MC_VERSION_1_16_5
#if PRE_MC_1_17_1
import net.minecraft.tags.FluidTags;
import net.minecraft.world.level.material.FluidState;
#else
import net.minecraft.world.level.material.FogType;
#endif
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
@@ -123,10 +123,10 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
@Override
public Mat4f getDefaultProjectionMatrix(float partialTicks)
{
#if MC_VERSION_1_17_1 || MC_VERSION_1_18_1 || MC_VERSION_1_18_2
return McObjectConverter.Convert(GAME_RENDERER.getProjectionMatrix(GAME_RENDERER.getFov(GAME_RENDERER.getMainCamera(), partialTicks, true)));
#elif MC_VERSION_1_16_5
#if PRE_MC_1_17_1
return McObjectConverter.Convert(GAME_RENDERER.getProjectionMatrix(GAME_RENDERER.getMainCamera(), partialTicks, true));
#else
return McObjectConverter.Convert(GAME_RENDERER.getProjectionMatrix(GAME_RENDERER.getFov(GAME_RENDERER.getMainCamera(), partialTicks, true)));
#endif
}
@@ -138,12 +138,13 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
@Override
public Color getFogColor(float partialTicks) {
#if MC_VERSION_1_17_1 || MC_VERSION_1_18_1 || MC_VERSION_1_18_2
FogRenderer.setupColor(GAME_RENDERER.getMainCamera(), partialTicks, MC.level, 1, GAME_RENDERER.getDarkenWorldAmount(partialTicks));
float[] colorValues = RenderSystem.getShaderFogColor();
#elif MC_VERSION_1_16_5
#if PRE_MC_1_17_1
float[] colorValues = new float[4];
GL15.glGetFloatv(GL15.GL_FOG_COLOR, colorValues);
#else
FogRenderer.setupColor(GAME_RENDERER.getMainCamera(), partialTicks, MC.level, 1, GAME_RENDERER.getDarkenWorldAmount(partialTicks));
float[] colorValues = RenderSystem.getShaderFogColor();
#endif
return new Color(colorValues[0], colorValues[1], colorValues[2], colorValues[3]);
}
@@ -152,10 +153,10 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
@Override
public Color getSkyColor() {
if (MC.level.dimensionType().hasSkyLight()) {
#if MC_VERSION_1_17_1 || MC_VERSION_1_18_1 || MC_VERSION_1_18_2
Vec3 colorValues = MC.level.getSkyColor(MC.gameRenderer.getMainCamera().getPosition(), MC.getFrameTime());
#elif MC_VERSION_1_16_5
#if PRE_MC_1_17_1
Vec3 colorValues = MC.level.getSkyColor(MC.gameRenderer.getMainCamera().getBlockPosition(), MC.getFrameTime());
#else
Vec3 colorValues = MC.level.getSkyColor(MC.gameRenderer.getMainCamera().getPosition(), MC.getFrameTime());
#endif
return new Color((float) colorValues.x, (float) colorValues.y, (float) colorValues.z);
} else
@@ -172,10 +173,11 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
@Override
public int getRenderDistance()
{
#if MC_VERSION_1_18_2 || MC_VERSION_1_18_1
return MC.options.getEffectiveRenderDistance();
#elif MC_VERSION_1_16_5 || MC_VERSION_1_17_1
#if PRE_MC_1_18_1
//FIXME: How to resolve this?
return MC.options.renderDistance;
#else
return MC.options.getEffectiveRenderDistance();
#endif
}
@@ -233,24 +235,16 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
if (!usingBackupGetVanillaRenderedChunks) {
try {
LevelRenderer levelRenderer = MC.levelRenderer;
#if MC_VERSION_1_18_2 || MC_VERSION_1_18_1
LinkedHashSet<LevelRenderer.RenderChunkInfo> chunks = levelRenderer.renderChunkStorage.get().renderChunks;
#elif MC_VERSION_1_16_5 || MC_VERSION_1_17_1
Collection<LevelRenderer.RenderChunkInfo> chunks = levelRenderer.renderChunks;
#endif
Collection<LevelRenderer.RenderChunkInfo> chunks =
#if PRE_MC_1_18_1 levelRenderer.renderChunks;
#else levelRenderer.renderChunkStorage.get().renderChunks; #endif
return (chunks.stream().map((chunk) -> {
#if MC_VERSION_1_18_2
AABB chunkBoundingBox = chunk.chunk.getBoundingBox();
#elif MC_VERSION_1_16_5 || MC_VERSION_1_17_1 || MC_VERSION_1_18_1
AABB chunkBoundingBox = chunk.chunk.bb;
#endif
#if MC_VERSION_1_18_2 || MC_VERSION_1_18_1
AABB chunkBoundingBox =
#if PRE_MC_1_18_2 chunk.chunk.bb;
#else chunk.chunk.getBoundingBox(); #endif
return FACTORY.createChunkPos(Math.floorDiv((int) chunkBoundingBox.minX, 16),
Math.floorDiv((int) chunkBoundingBox.minZ, 16));
#elif MC_VERSION_1_16_5 || MC_VERSION_1_17_1
return FACTORY.createChunkPos(Math.floorDiv((int) chunkBoundingBox.minX, 16),
Math.floorDiv((int) chunkBoundingBox.minZ, 16));
#endif
}).collect(Collectors.toCollection(HashSet::new)));
} catch (LinkageError e) {
try {
@@ -275,11 +269,7 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
@Override
public boolean isFogStateSpecial() {
#if MC_VERSION_1_17_1 || MC_VERSION_1_18_1 || MC_VERSION_1_18_2
Entity entity = GAME_RENDERER.getMainCamera().getEntity();
boolean isBlind = (entity instanceof LivingEntity) && ((LivingEntity)entity).hasEffect(MobEffects.BLINDNESS);
return GAME_RENDERER.getMainCamera().getFluidInCamera() != FogType.NONE || isBlind;
#elif MC_VERSION_1_16_5
#if PRE_MC_1_17_1
Camera camera = GAME_RENDERER.getMainCamera();
FluidState fluidState = camera.getFluidInCamera();
Entity entity = camera.getEntity();
@@ -287,6 +277,10 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
isUnderWater |= fluidState.is(FluidTags.WATER);
isUnderWater |= fluidState.is(FluidTags.LAVA);
return isUnderWater;
#else
Entity entity = GAME_RENDERER.getMainCamera().getEntity();
boolean isBlind = (entity instanceof LivingEntity) && ((LivingEntity)entity).hasEffect(MobEffects.BLINDNESS);
return GAME_RENDERER.getMainCamera().getFluidInCamera() != FogType.NONE || isBlind;
#endif
}
@@ -138,10 +138,10 @@ public class WorldWrapper implements IWorldWrapper
@Override
public short getMinHeight()
{
#if MC_VERSION_1_17_1 || MC_VERSION_1_18_1 || MC_VERSION_1_18_2
return (short) world.getMinBuildHeight();
#elif MC_VERSION_1_16_5
#if PRE_MC_1_17_1
return (short) 0;
#else
return (short) world.getMinBuildHeight();
#endif
}
@@ -186,6 +186,4 @@ public class WorldWrapper implements IWorldWrapper
ChunkSource source = world.getChunkSource();
return source.hasChunk(chunkX, chunkZ);
}
}
@@ -376,8 +376,8 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv
if (chunkData == null)
{
return new ProtoChunk(chunkPos, UpgradeData.EMPTY
#if MC_VERSION_1_17_1 || MC_VERSION_1_18_1 || MC_VERSION_1_18_2, level #endif
#if MC_VERSION_1_18_1 || MC_VERSION_1_18_2, level.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY), null #endif
#if POST_MC_1_17_1, level #endif
#if POST_MC_1_18_1, level.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY), null #endif
);
}
else
@@ -387,8 +387,8 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv
} catch (Exception e) {
LOAD_LOGGER.error("DistantHorizons: Couldn't load chunk {}", chunkPos, e);
return new ProtoChunk(chunkPos, UpgradeData.EMPTY
#if MC_VERSION_1_17_1 || MC_VERSION_1_18_1 || MC_VERSION_1_18_2, level #endif
#if MC_VERSION_1_18_1 || MC_VERSION_1_18_2, level.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY), null #endif
#if POST_MC_1_17_1, level #endif
#if POST_MC_1_18_1, level.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY), null #endif
);
}
}
@@ -428,8 +428,8 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv
}
if (target == null)
target = new ProtoChunk(chunkPos, UpgradeData.EMPTY
#if MC_VERSION_1_17_1 || MC_VERSION_1_18_1 || MC_VERSION_1_18_2, params.level #endif
#if MC_VERSION_1_18_1 || MC_VERSION_1_18_2, params.biomes, null #endif
#if POST_MC_1_17_1, params.level #endif
#if POST_MC_1_18_1, params.biomes, null #endif
);
return target;
};
@@ -489,7 +489,7 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv
}
boolean isFull = target.getStatus() == ChunkStatus.FULL || target instanceof LevelChunk;
#if MC_VERSION_1_18_2 || MC_VERSION_1_18_1
#if POST_MC_1_18_1
boolean isPartial = target.isOldNoiseGeneration();
#endif
if (isFull)
@@ -498,7 +498,7 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv
params.lodBuilder.generateLodNodeFromChunk(params.lodDim, wrappedChunk,
new LodBuilderConfig(DistanceGenerationMode.FULL), true, e.genAllDetails);
}
#if MC_VERSION_1_18_2 || MC_VERSION_1_18_1
#if POST_MC_1_18_1
else if (isPartial)
{
LOAD_LOGGER.info("Detected old existing chunk at {}", target.getPos());
@@ -590,7 +590,7 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv
{
if (p instanceof ProtoChunk)
((ProtoChunk) p).setLightCorrect(true);
#if MC_VERSION_1_18_1 || MC_VERSION_1_18_2
#if POST_MC_1_18_1
if (p instanceof LevelChunk) {
((LevelChunk) p).setLightCorrect(true);
((LevelChunk) p).setClientLightReady(true);
@@ -31,7 +31,7 @@ import net.minecraft.server.level.ThreadedLevelLightEngine;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.BiomeManager;
import net.minecraft.world.level.chunk.ChunkGenerator;
#if MC_VERSION_1_18_2 || MC_VERSION_1_18_1
#if POST_MC_1_18_1
import net.minecraft.world.level.chunk.storage.ChunkScanAccess;
#endif
import net.minecraft.world.level.levelgen.WorldGenSettings;
@@ -42,9 +42,6 @@ public final class GlobalParameters
{
public final ChunkGenerator generator;
public final StructureManager structures;
#if MC_VERSION_1_18_2 || MC_VERSION_1_18_1
public final BiomeManager biomeManager;
#endif
public final WorldGenSettings worldGenSettings;
public final ThreadedLevelLightEngine lightEngine;
public final LodBuilder lodBuilder;
@@ -52,11 +49,12 @@ public final class GlobalParameters
public final Registry<Biome> biomes;
public final RegistryAccess registry;
public final long worldSeed;
#if MC_VERSION_1_18_2 || MC_VERSION_1_18_1
public final ChunkScanAccess chunkScanner;
#endif
public final ServerLevel level; // TODO: Figure out a way to remove this. Maybe ClientLevel also works?
public final DataFixer fixerUpper;
#if POST_MC_1_18_1
public final BiomeManager biomeManager;
public final ChunkScanAccess chunkScanner; // FIXME: Figure out if this is actually needed
#endif
public GlobalParameters(ServerLevel level, LodBuilder lodBuilder, LodDimension lodDim)
{
@@ -70,14 +68,12 @@ public final class GlobalParameters
registry = server.registryAccess();
biomes = registry.registryOrThrow(Registry.BIOME_REGISTRY);
worldSeed = worldGenSettings.seed();
#if MC_VERSION_1_18_2 || MC_VERSION_1_18_1
#if POST_MC_1_18_1
biomeManager = new BiomeManager(level, BiomeManager.obfuscateSeed(worldSeed));
chunkScanner = level.getChunkSource().chunkScanner();
#endif
structures = server.getStructureManager();
generator = level.getChunkSource().getGenerator();
#if MC_VERSION_1_18_2 || MC_VERSION_1_18_1
chunkScanner = level.getChunkSource().chunkScanner();
#endif
fixerUpper = server.getFixerUpper();
}
}
@@ -26,7 +26,7 @@ import com.seibel.lod.common.wrappers.worldGeneration.mimicObject.WorldGenStruct
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.levelgen.WorldGenSettings;
#if MC_VERSION_1_18_2 || MC_VERSION_1_18_1
#if POST_MC_1_18_1
import net.minecraft.world.level.levelgen.structure.StructureCheck;
#endif
@@ -34,11 +34,9 @@ public final class ThreadedParameters
{
private static final ThreadLocal<ThreadedParameters> localParam = new ThreadLocal<ThreadedParameters>();
final ServerLevel level;
#if MC_VERSION_1_18_2 || MC_VERSION_1_18_1
public WorldGenStructFeatManager structFeat = null;
#if POST_MC_1_18_1
public final StructureCheck structCheck;
#elif MC_VERSION_1_17_1 || MC_VERSION_1_16_5
public WorldGenStructFeatManager structFeat;
#endif
boolean isValid = true;
public final PerfCalculator perf = new PerfCalculator();
@@ -60,23 +58,18 @@ public final class ThreadedParameters
private ThreadedParameters(GlobalParameters param)
{
#if MC_VERSION_1_18_2 || MC_VERSION_1_18_1
level = param.level;
#if PRE_MC_1_18_1
structFeat = new WorldGenStructFeatManager(param.worldGenSettings, level);
#else
structCheck = new StructureCheck(param.chunkScanner, param.registry, param.structures,
param.level.dimension(), param.generator, level, param.generator.getBiomeSource(), param.worldSeed,
param.fixerUpper);
#elif MC_VERSION_1_17_1 || MC_VERSION_1_16_5
level = param.level;
structFeat = new WorldGenStructFeatManager(param.worldGenSettings, level);
#endif
}
public void makeStructFeat(WorldGenLevel genLevel, GlobalParameters param)
{
#if MC_VERSION_1_18_2 || MC_VERSION_1_18_1
structFeat = new WorldGenStructFeatManager(param.worldGenSettings, genLevel, structCheck);
#elif MC_VERSION_1_17_1
structFeat = new WorldGenStructFeatManager(param.worldGenSettings, genLevel);
#endif
structFeat = new WorldGenStructFeatManager(param.worldGenSettings, genLevel #if POST_MC_1_18_1, structCheck #endif);
}
}
@@ -34,11 +34,6 @@ import java.util.Locale;
import java.util.Map;
import java.util.Objects;
#if MC_VERSION_1_18_2
import net.minecraft.core.Holder;
import net.minecraft.core.RegistryAccess;
import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature;
#endif
import net.minecraft.core.Registry;
import net.minecraft.core.SectionPos;
@@ -55,13 +50,19 @@ import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.*;
import net.minecraft.world.level.chunk.storage.ChunkSerializer;
import net.minecraft.world.level.levelgen.Heightmap;
#if MC_VERSION_1_18_2 || MC_VERSION_1_18_1
#if POST_MC_1_18_1
import net.minecraft.world.level.levelgen.blending.BlendingData;
import net.minecraft.world.level.levelgen.feature.StructureFeature;
import net.minecraft.world.level.levelgen.structure.StructureStart;
import net.minecraft.world.level.levelgen.structure.pieces.StructurePieceSerializationContext;
import net.minecraft.world.ticks.LevelChunkTicks;
#endif
#if POST_MC_1_18_2
import net.minecraft.core.Holder;
import net.minecraft.core.RegistryAccess;
import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature;
#endif
import net.minecraft.world.level.lighting.LevelLightEngine;
import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.level.material.Fluids;
@@ -69,7 +70,7 @@ import org.apache.logging.log4j.Logger;
public class ChunkLoader
{
#if MC_VERSION_1_18_2 || MC_VERSION_1_18_1
#if POST_MC_1_18_1
private static final Codec<PalettedContainer<BlockState>> BLOCK_STATE_CODEC = PalettedContainer.codec(Block.BLOCK_STATE_REGISTRY, BlockState.CODEC, PalettedContainer.Strategy.SECTION_STATES, Blocks.AIR.defaultBlockState());
#endif
private static final String TAG_UPGRADE_DATA = "UpgradeData";
@@ -79,7 +80,7 @@ public class ChunkLoader
private static final String FLUID_TICKS_TAG_PRE18 = "LiquidTicks";
private static final ConfigBasedLogger LOGGER = BatchGenerationEnvironment.LOAD_LOGGER;
#if MC_VERSION_1_18_2 || MC_VERSION_1_18_1
#if POST_MC_1_18_1
private static BlendingData readBlendingData(CompoundTag chunkData)
{
BlendingData blendingData = null;
@@ -95,17 +96,17 @@ public class ChunkLoader
private static LevelChunkSection[] readSections(LevelAccessor level, LevelLightEngine lightEngine, ChunkPos chunkPos, CompoundTag chunkData)
{
#if MC_VERSION_1_18_2 || MC_VERSION_1_18_1
#if POST_MC_1_18_1
Registry<Biome> biomes = level.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY);
#if MC_VERSION_1_18_1
#if PRE_MC_1_18_2
Codec<PalettedContainer<Biome>> biomeCodec = PalettedContainer.codec(
biomes, biomes.byNameCodec(), PalettedContainer.Strategy.SECTION_BIOMES, biomes.getOrThrow(Biomes.PLAINS));
#elif MC_VERSION_1_18_2
#else
Codec<PalettedContainer<Holder<Biome>>> biomeCodec = PalettedContainer.codec(
biomes.asHolderIdMap(), biomes.holderByNameCodec(), PalettedContainer.Strategy.SECTION_BIOMES, biomes.getHolderOrThrow(Biomes.PLAINS));
#endif
#endif
int i = #if MC_VERSION_1_16_5 16; #else level.getSectionsCount(); #endif
int i = #if PRE_MC_1_17_1 16; #else level.getSectionsCount(); #endif
LevelChunkSection[] chunkSections = new LevelChunkSection[i];
boolean isLightOn = chunkData.getBoolean("isLightOn");
@@ -118,14 +119,24 @@ public class ChunkLoader
CompoundTag tagSection = tagSections.getCompound(j);
int sectionYPos = tagSection.getByte("Y");
#if MC_VERSION_1_18_2 || MC_VERSION_1_18_1
#if PRE_MC_1_18_1
if (tagSection.contains("Palette", 9) && tagSection.contains("BlockStates", 12)) {
LevelChunkSection levelChunkSection = new LevelChunkSection(sectionYPos << 4);
levelChunkSection.getStates().read(tagSection.getList("Palette", 10),
tagSection.getLongArray("BlockStates"));
levelChunkSection.recalcBlockCounts();
if (!levelChunkSection.isEmpty())
chunkSections[#if PRE_MC_1_17_1 sectionYPos #else level.getSectionIndexFromSectionY(sectionYPos) #endif]
= levelChunkSection;
}
#else
int sectionId = level.getSectionIndexFromSectionY(sectionYPos);
if (sectionId >= 0 && sectionId < chunkSections.length)
{
PalettedContainer<BlockState> blockStateContainer;
#if MC_VERSION_1_18_1
#if PRE_MC_1_18_2
PalettedContainer<Biome> biomeContainer;
#elif MC_VERSION_1_18_2
#else
PalettedContainer<Holder<Biome>> biomeContainer;
#endif
@@ -133,28 +144,19 @@ public class ChunkLoader
? BLOCK_STATE_CODEC.parse(NbtOps.INSTANCE, tagSection.getCompound("block_states")).promotePartial(string -> logErrors(chunkPos, sectionYPos, string)).getOrThrow(false, LOGGER::error)
: new PalettedContainer<BlockState>(Block.BLOCK_STATE_REGISTRY, Blocks.AIR.defaultBlockState(), PalettedContainer.Strategy.SECTION_STATES);
#if MC_VERSION_1_18_1
#if PRE_MC_1_18_2
biomeContainer = tagSection.contains("biomes", 10)
? biomeCodec.parse(NbtOps.INSTANCE, tagSection.getCompound("biomes")).promotePartial(string -> logErrors(chunkPos, sectionYPos, string)).getOrThrow(false, LOGGER::error)
: new PalettedContainer<Biome>(biomes, biomes.getOrThrow(Biomes.PLAINS), PalettedContainer.Strategy.SECTION_BIOMES);
#elif MC_VERSION_1_18_2
#else
biomeContainer = tagSection.contains("biomes", 10)
? biomeCodec.parse(NbtOps.INSTANCE, tagSection.getCompound("biomes")).promotePartial(string -> logErrors(chunkPos, i, (String) string)).getOrThrow(false, LOGGER::error)
: new PalettedContainer<Holder<Biome>>(biomes.asHolderIdMap(), biomes.getHolderOrThrow(Biomes.PLAINS), PalettedContainer.Strategy.SECTION_BIOMES);
#endif
chunkSections[sectionId] = new LevelChunkSection(sectionYPos, blockStateContainer, biomeContainer);
}
#elif MC_VERSION_1_16_5 || MC_VERSION_1_17_1
if (tagSection.contains("Palette", 9) && tagSection.contains("BlockStates", 12)) {
LevelChunkSection levelChunkSection = new LevelChunkSection(sectionYPos << 4);
levelChunkSection.getStates().read(tagSection.getList("Palette", 10),
tagSection.getLongArray("BlockStates"));
levelChunkSection.recalcBlockCounts();
if (!levelChunkSection.isEmpty())
chunkSections[#if MC_VERSION_1_16_5 sectionYPos #else level.getSectionIndexFromSectionY(sectionYPos) #endif]
= levelChunkSection;
}
#endif
if (!isLightOn) continue;
if (tagSection.contains("BlockLight", 7))
lightEngine.queueSectionData(LightLayer.BLOCK, SectionPos.of(chunkPos, sectionYPos),
@@ -202,7 +204,7 @@ public class ChunkLoader
public static LevelChunk read(WorldGenLevel level, LevelLightEngine lightEngine, ChunkPos chunkPos, CompoundTag chunkData)
{
#if MC_VERSION_1_16_5 || MC_VERSION_1_17_1
#if PRE_MC_1_18_1
CompoundTag tagLevel = chunkData.getCompound("Level");
#else
CompoundTag tagLevel = chunkData;
@@ -215,12 +217,12 @@ public class ChunkLoader
}
ChunkStatus.ChunkType chunkType = readChunkType(tagLevel);
#if MC_VERSION_1_18_1 || MC_VERSION_1_18_2
BlendingData blendingData = readBlendingData(tagLevel);
if (chunkType == ChunkStatus.ChunkType.PROTOCHUNK && (blendingData == null || !blendingData.oldNoise()))
#if PRE_MC_1_18_1
if (chunkType != ChunkStatus.ChunkType.LEVELCHUNK)
return null;
#else
if (chunkType != ChunkStatus.ChunkType.LEVELCHUNK)
BlendingData blendingData = readBlendingData(tagLevel);
if (chunkType == ChunkStatus.ChunkType.PROTOCHUNK && (blendingData == null || !blendingData.oldNoise()))
return null;
#endif
@@ -228,47 +230,43 @@ public class ChunkLoader
//================== Read params for making the LevelChunk ==================
UpgradeData upgradeData = tagLevel.contains(TAG_UPGRADE_DATA, 10)
? new UpgradeData(tagLevel.getCompound(TAG_UPGRADE_DATA)#if !MC_VERSION_1_16_5, level #endif)
? new UpgradeData(tagLevel.getCompound(TAG_UPGRADE_DATA)#if POST_MC_1_17_1, level #endif)
: UpgradeData.EMPTY;
boolean isLightOn = tagLevel.getBoolean("isLightOn");
if (isLightOn) lightEngine.retainData(chunkPos, true);
#if MC_VERSION_1_18_1 || MC_VERSION_1_18_2
LevelChunkTicks<Block> blockTicks = LevelChunkTicks.load(tagLevel.getList(BLOCK_TICKS_TAG_18, 10),
string -> Registry.BLOCK.getOptional(ResourceLocation.tryParse(string)), chunkPos);
LevelChunkTicks<Fluid> fluidTicks = LevelChunkTicks.load(tagLevel.getList(FLUID_TICKS_TAG_18, 10),
string -> Registry.FLUID.getOptional(ResourceLocation.tryParse(string)), chunkPos);
#elif MC_VERSION_1_16_5 || MC_VERSION_1_17_1
#if PRE_MC_1_18_1
ChunkBiomeContainer chunkBiomeContainer = new ChunkBiomeContainer(
level.getLevel().registryAccess().registryOrThrow(Registry.BIOME_REGISTRY)#if !MC_VERSION_1_16_5, level #endif,
level.getLevel().registryAccess().registryOrThrow(Registry.BIOME_REGISTRY)#if POST_MC_1_17_1, level #endif,
chunkPos, level.getLevel().getChunkSource().getGenerator().getBiomeSource(),
tagLevel.contains("Biomes", 11) ? tagLevel.getIntArray("Biomes") : null);
TickList<Block> blockTicks = tagLevel.contains(BLOCK_TICKS_TAG_PRE18, 9)
? ChunkTickList.create(tagLevel.getList(BLOCK_TICKS_TAG_PRE18, 10), Registry.BLOCK::getKey, Registry.BLOCK::get)
: new ProtoTickList<Block>(block -> (block == null || block.defaultBlockState().isAir()), chunkPos,
tagLevel.getList("ToBeTicked", 9)#if !MC_VERSION_1_16_5, level #endif);
tagLevel.getList("ToBeTicked", 9)#if POST_MC_1_17_1, level #endif);
TickList<Fluid> fluidTicks = tagLevel.contains(FLUID_TICKS_TAG_PRE18, 9)
? ChunkTickList.create(tagLevel.getList(FLUID_TICKS_TAG_PRE18, 10), Registry.FLUID::getKey, Registry.FLUID::get)
: new ProtoTickList<Fluid>(fluid -> (fluid == null || fluid == Fluids.EMPTY), chunkPos,
tagLevel.getList("LiquidsToBeTicked", 9)#if !MC_VERSION_1_16_5, level #endif);
tagLevel.getList("LiquidsToBeTicked", 9)#if POST_MC_1_17_1, level #endif);
#else
LevelChunkTicks<Block> blockTicks = LevelChunkTicks.load(tagLevel.getList(BLOCK_TICKS_TAG_18, 10),
string -> Registry.BLOCK.getOptional(ResourceLocation.tryParse(string)), chunkPos);
LevelChunkTicks<Fluid> fluidTicks = LevelChunkTicks.load(tagLevel.getList(FLUID_TICKS_TAG_18, 10),
string -> Registry.FLUID.getOptional(ResourceLocation.tryParse(string)), chunkPos);
#endif
LevelChunkSection[] levelChunkSections = readSections(level, lightEngine, chunkPos, tagLevel);
// ======================== Make the chunk
// ===========================================
#if MC_VERSION_1_18_1 || MC_VERSION_1_18_2
LevelChunk chunk = new LevelChunk((Level) level, chunkPos, upgradeData, blockTicks,
fluidTicks, inhabitedTime, levelChunkSections, null, blendingData);
#else
// ====================== Make the chunk =========================
#if PRE_MC_1_18_1
LevelChunk chunk = new LevelChunk((Level) level.getLevel(), chunkPos, chunkBiomeContainer, upgradeData, blockTicks,
fluidTicks, inhabitedTime, levelChunkSections, null);
#else
LevelChunk chunk = new LevelChunk((Level) level, chunkPos, upgradeData, blockTicks,
fluidTicks, inhabitedTime, levelChunkSections, null, blendingData);
#endif
// Set some states after object creation
chunk.setLightCorrect(isLightOn);
readHeightmaps(chunk, chunkData);
@@ -23,7 +23,7 @@ import com.seibel.lod.core.handlers.dependencyInjection.ModAccessorHandler;
import com.seibel.lod.core.wrapperInterfaces.modAccessor.IStarlightAccessor;
import net.minecraft.world.level.BlockGetter;
#if MC_VERSION_1_17_1 || MC_VERSION_1_18_1 || MC_VERSION_1_18_2
#if POST_MC_1_17_1
import net.minecraft.world.level.LevelHeightAccessor;
#endif
import net.minecraft.world.level.chunk.ChunkStatus;
@@ -56,7 +56,7 @@ public class LightGetterAdaptor implements LightChunkGetter {
return shouldReturnNull ? null : (genRegion != null ? genRegion : heightGetter);
}
#if MC_VERSION_1_17_1 || MC_VERSION_1_18_1 || MC_VERSION_1_18_2
#if POST_MC_1_17_1
public LevelHeightAccessor getLevelHeightAccessor() {
return heightGetter;
}
@@ -42,7 +42,7 @@ import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.ColorResolver;
#if MC_VERSION_1_17_1 || MC_VERSION_1_18_1 || MC_VERSION_1_18_2
#if POST_MC_1_17_1
import net.minecraft.world.level.LevelHeightAccessor;
#endif
import net.minecraft.world.level.LightLayer;
@@ -69,34 +69,30 @@ public class LightedWorldGenRegion extends WorldGenRegion {
private final ChunkPos firstPos;
private final List<ChunkAccess> cache;
Long2ObjectOpenHashMap<ChunkAccess> chunkMap = new Long2ObjectOpenHashMap<ChunkAccess>();
#if MC_VERSION_1_17_1
#if PRE_MC_1_18_1
private ChunkPos overrideCenterPos = null;
public void setOverrideCenter(ChunkPos pos) {overrideCenterPos = pos;}
@Override
public ChunkPos getCenter() {
return overrideCenterPos==null ? super.getCenter() : overrideCenterPos;
}
#elif MC_VERSION_1_16_5
private ChunkPos overrideCenterPos = null;
public void setOverrideCenter(ChunkPos pos) {overrideCenterPos = pos;}
@Override
public int getCenterX() {
return overrideCenterPos==null ? super.getCenterX() : overrideCenterPos.x;
}
@Override
public int getCenterZ() {
return overrideCenterPos==null ? super.getCenterX() : overrideCenterPos.z;
}
#if PRE_MC_1_17_1
@Override
public int getCenterX() {
return overrideCenterPos==null ? super.getCenterX() : overrideCenterPos.x;
}
@Override
public int getCenterZ() {
return overrideCenterPos==null ? super.getCenterX() : overrideCenterPos.z;
}
#else
@Override
public ChunkPos getCenter() {
return overrideCenterPos==null ? super.getCenter() : overrideCenterPos;
}
#endif
#endif
public LightedWorldGenRegion(ServerLevel serverLevel, WorldGenLevelLightEngine lightEngine,
List<ChunkAccess> list, ChunkStatus chunkStatus, int i,
LightGenerationMode lightMode, EmptyChunkGenerator generator) {
#if MC_VERSION_1_17_1 || MC_VERSION_1_18_1 || MC_VERSION_1_18_2
super(serverLevel, list, chunkStatus, i);
#elif MC_VERSION_1_16_5
super(serverLevel, list);
#endif
super(serverLevel, list #if POST_MC_1_17_1, chunkStatus, i #endif);
this.lightMode = lightMode;
this.firstPos = list.get(0).getPos();
this.generator = generator;
@@ -106,7 +102,7 @@ public class LightedWorldGenRegion extends WorldGenRegion {
size = Mth.floor(Math.sqrt(list.size()));
}
#if MC_VERSION_1_17_1 || MC_VERSION_1_18_1 || MC_VERSION_1_18_2
#if POST_MC_1_17_1
// Bypass BCLib mixin overrides.
@Override
public boolean ensureCanWrite(BlockPos blockPos) {
@@ -119,7 +115,7 @@ public class LightedWorldGenRegion extends WorldGenRegion {
if (k > this.writeRadius || l > this.writeRadius) {
return false;
}
#if MC_VERSION_1_18_1 || MC_VERSION_1_18_2
#if POST_MC_1_18_1
if (center.isUpgrading()) {
LevelHeightAccessor levelHeightAccessor = center.getHeightAccessorForGeneration();
if (blockPos.getY() < levelHeightAccessor.getMinBuildHeight() || blockPos.getY() >= levelHeightAccessor.getMaxBuildHeight()) {
@@ -214,7 +210,7 @@ public class LightedWorldGenRegion extends WorldGenRegion {
public ChunkAccess getChunk(int i, int j, ChunkStatus chunkStatus, boolean bl) {
ChunkAccess chunk = getChunkAccess(i, j, chunkStatus, bl);
if (chunk instanceof LevelChunk) {
chunk = new ImposterProtoChunk((LevelChunk) chunk #if MC_VERSION_1_18_1 || MC_VERSION_1_18_2, true #endif);
chunk = new ImposterProtoChunk((LevelChunk) chunk #if POST_MC_1_18_1, true #endif);
}
return chunk;
}
@@ -285,7 +281,7 @@ public class LightedWorldGenRegion extends WorldGenRegion {
}
private Biome _getBiome(BlockPos pos) {
#if MC_VERSION_1_18_2
#if POST_MC_1_18_2
return getBiome(pos).value();
#else
return getBiome(pos);
@@ -24,7 +24,7 @@ import org.jetbrains.annotations.Nullable;
import net.minecraft.core.BlockPos;
import net.minecraft.core.SectionPos;
import net.minecraft.world.level.ChunkPos;
#if MC_VERSION_1_17_1 || MC_VERSION_1_18_1 || MC_VERSION_1_18_2
#if POST_MC_1_17_1
import net.minecraft.world.level.LevelHeightAccessor;
#endif
import net.minecraft.world.level.LightLayer;
@@ -39,7 +39,7 @@ import net.minecraft.world.level.lighting.SkyLightEngine;
public class WorldGenLevelLightEngine extends LevelLightEngine {
public static final int MAX_SOURCE_LEVEL = 15;
public static final int LIGHT_SECTION_PADDING = 1;
#if MC_VERSION_1_17_1 || MC_VERSION_1_18_1 || MC_VERSION_1_18_2
#if POST_MC_1_17_1
protected final LevelHeightAccessor levelHeightAccessor;
#endif
@Nullable
@@ -49,7 +49,7 @@ public class WorldGenLevelLightEngine extends LevelLightEngine {
public WorldGenLevelLightEngine(LightGetterAdaptor genRegion) {
super(genRegion, false, false);
#if MC_VERSION_1_17_1 || MC_VERSION_1_18_1 || MC_VERSION_1_18_2
#if POST_MC_1_17_1
this.levelHeightAccessor = genRegion.getLevelHeightAccessor();
#endif
this.blockEngine = new BlockLightEngine(genRegion);
@@ -149,23 +149,23 @@ public class WorldGenLevelLightEngine extends LevelLightEngine {
LevelChunkSection[] levelChunkSections = chunkAccess.getSections();
for (int i = 0; i <
#if MC_VERSION_1_17_1 || MC_VERSION_1_18_1 || MC_VERSION_1_18_2
#if POST_MC_1_17_1
chunkAccess.getSectionsCount()
#elif MC_VERSION_1_16_5
#else
16
#endif
; ++i) {
LevelChunkSection levelChunkSection = levelChunkSections[i];
#if MC_VERSION_1_16_5
#if PRE_MC_1_17_1
if (!LevelChunkSection.isEmpty(levelChunkSection)) {
updateSectionStatus(SectionPos.of(chunkPos, i), false);
}
#elif MC_VERSION_1_17_1
#elif PRE_MC_1_18_1
if (!LevelChunkSection.isEmpty(levelChunkSection)) {
int j = this.levelHeightAccessor.getSectionYFromSectionIndex(i);
updateSectionStatus(SectionPos.of(chunkPos, j), false);
}
#elif MC_VERSION_1_18_1 || MC_VERSION_1_18_2
#else
if (levelChunkSection.hasOnlyAir()) continue;
int j = this.levelHeightAccessor.getSectionYFromSectionIndex(i);
updateSectionStatus(SectionPos.of(chunkPos, j), false);
@@ -204,7 +204,7 @@ public class WorldGenLevelLightEngine extends LevelLightEngine {
}
}
#if MC_VERSION_1_17_1 || MC_VERSION_1_18_1 || MC_VERSION_1_18_2
#if POST_MC_1_17_1
@Override
public int getLightSectionCount() {
throw new UnsupportedOperationException("This should never be used!");
@@ -44,7 +44,7 @@ import net.minecraft.world.level.chunk.ChunkStatus;
import net.minecraft.world.level.levelgen.WorldGenSettings;
import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature;
import net.minecraft.world.level.levelgen.feature.StructureFeature;
#if MC_VERSION_1_18_2 || MC_VERSION_1_18_1
#if POST_MC_1_18_1
import net.minecraft.world.level.levelgen.structure.StructureCheck;
#endif
import net.minecraft.world.level.levelgen.structure.StructureStart;
@@ -52,34 +52,22 @@ import net.minecraft.world.level.levelgen.structure.StructureStart;
public class WorldGenStructFeatManager extends StructureFeatureManager {
final WorldGenLevel genLevel;
WorldGenSettings worldGenSettings;
#if MC_VERSION_1_18_2 || MC_VERSION_1_18_1
#if POST_MC_1_18_1
StructureCheck structureCheck;
public WorldGenStructFeatManager(WorldGenSettings worldGenSettings,
WorldGenLevel genLevel, StructureCheck structureCheck) {
super(genLevel, worldGenSettings, structureCheck);
this.genLevel = genLevel;
this.worldGenSettings = worldGenSettings;
}
#elif MC_VERSION_1_17_1 || MC_VERSION_1_16_5
public WorldGenStructFeatManager(WorldGenSettings worldGenSettings,
WorldGenLevel genLevel) {
super(genLevel, worldGenSettings);
this.genLevel = genLevel;
this.worldGenSettings = worldGenSettings;
}
#endif
public WorldGenStructFeatManager(WorldGenSettings worldGenSettings,
WorldGenLevel genLevel #if POST_MC_1_18_1, StructureCheck structureCheck #endif) {
super(genLevel, worldGenSettings #if POST_MC_1_18_1, structureCheck #endif);
this.genLevel = genLevel;
this.worldGenSettings = worldGenSettings;
}
@Override
public WorldGenStructFeatManager forWorldGenRegion(WorldGenRegion worldGenRegion) {
if (worldGenRegion == genLevel)
return this;
#if MC_VERSION_1_18_2 || MC_VERSION_1_18_1
return new WorldGenStructFeatManager(worldGenSettings, worldGenRegion, structureCheck);
#elif MC_VERSION_1_16_5 || MC_VERSION_1_17_1
return new WorldGenStructFeatManager(worldGenSettings, worldGenRegion);
#endif
return new WorldGenStructFeatManager(worldGenSettings, worldGenRegion #if POST_MC_1_18_1, structureCheck #endif);
}
private ChunkAccess _getChunk(int x, int z, ChunkStatus status) {
@@ -87,18 +75,7 @@ public class WorldGenStructFeatManager extends StructureFeatureManager {
return genLevel.getChunk(x, z, status, false);
}
#if MC_VERSION_1_18_2 || MC_VERSION_1_18_1
@Override
public boolean hasAnyStructureAt(BlockPos blockPos) {
SectionPos sectionPos = SectionPos.of(blockPos);
ChunkAccess chunk = _getChunk(sectionPos.x(), sectionPos.z(), ChunkStatus.STRUCTURE_REFERENCES);
if (chunk == null) return false;
return chunk.hasAnyStructureReferences();
}
#endif
#if MC_VERSION_1_16_5 || MC_VERSION_1_17_1
#if PRE_MC_1_18_1
@Override
public Stream<? extends StructureStart<?>> startsForFeature(SectionPos sectionPos2,
StructureFeature<?> structureFeature) {
@@ -112,76 +89,83 @@ public class WorldGenStructFeatManager extends StructureFeatureManager {
return this.getStartForFeature(sectPos, structureFeature, startChunk);
}).filter(structureStart -> structureStart != null && structureStart.isValid());
}
#elif MC_VERSION_1_18_1
#else
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public List<? extends StructureStart<?>> startsForFeature(SectionPos sectionPos,
StructureFeature<?> structureFeature) {
ChunkAccess chunk = _getChunk(sectionPos.x(), sectionPos.z(), ChunkStatus.STRUCTURE_REFERENCES);
if (chunk == null) return List.of();
// Copied from StructureFeatureManager::startsForFeature(...) with slight tweaks
LongSet longSet = chunk.getReferencesForFeature(structureFeature);
ImmutableList.Builder builder = ImmutableList.builder();
LongIterator longIterator = longSet.iterator();
while (longIterator.hasNext()) {
long l = (Long)longIterator.next();
SectionPos sectPos = SectionPos.of(new ChunkPos(l), genLevel.getMinSection());
ChunkAccess startChunk = _getChunk(sectPos.x(), sectPos.z(), ChunkStatus.STRUCTURE_STARTS);
if (startChunk == null) continue;
StructureStart<?> structureStart = this.getStartForFeature(sectPos, structureFeature, startChunk);
if (structureStart == null || !structureStart.isValid()) continue;
builder.add(structureStart);
}
return builder.build();
}
#elif MC_VERSION_1_18_2
@Override
public List<StructureStart> startsForFeature(SectionPos sectionPos, Predicate<ConfiguredStructureFeature<?, ?>> predicate) {
ChunkAccess chunk = _getChunk(sectionPos.x(), sectionPos.z(), ChunkStatus.STRUCTURE_REFERENCES);
if (chunk == null) return List.of();
// Copied from StructureFeatureManager::startsForFeature(...)
Map<ConfiguredStructureFeature<?, ?>, LongSet> map = chunk.getAllReferences();
ImmutableList.Builder<StructureStart> builder = ImmutableList.builder();
Iterator<Map.Entry<ConfiguredStructureFeature<?, ?>, LongSet>> var5 = map.entrySet().iterator();
while(var5.hasNext()) {
Map.Entry<ConfiguredStructureFeature<?, ?>, LongSet> entry = var5.next();
ConfiguredStructureFeature<?, ?> configuredStructureFeature = entry.getKey();
if (predicate.test(configuredStructureFeature)) {
LongSet var10002 = (LongSet)entry.getValue();
Objects.requireNonNull(builder);
this.fillStartsForFeature(configuredStructureFeature, var10002, builder::add);
}
}
return builder.build();
}
@Override
public List<StructureStart> startsForFeature(SectionPos sectionPos, ConfiguredStructureFeature<?, ?> configuredStructureFeature) {
ChunkAccess chunk = _getChunk(sectionPos.x(), sectionPos.z(), ChunkStatus.STRUCTURE_REFERENCES);
if (chunk == null) return (List<StructureStart>) Stream.empty();
// Copied from StructureFeatureManager::startsForFeature(...)
LongSet longSet = chunk.getReferencesForFeature(configuredStructureFeature);
ImmutableList.Builder<StructureStart> builder = ImmutableList.builder();
Objects.requireNonNull(builder);
this.fillStartsForFeature(configuredStructureFeature, longSet, builder::add);
return builder.build();
}
@Override
public Map<ConfiguredStructureFeature<?, ?>, LongSet> getAllStructuresAt(BlockPos blockPos) {
public boolean hasAnyStructureAt(BlockPos blockPos) {
SectionPos sectionPos = SectionPos.of(blockPos);
ChunkAccess chunk = _getChunk(sectionPos.x(), sectionPos.z(), ChunkStatus.STRUCTURE_REFERENCES);
if (chunk == null) return (Map<ConfiguredStructureFeature<?, ?>, LongSet>) Stream.empty();
return chunk.getAllReferences();
if (chunk == null) return false;
return chunk.hasAnyStructureReferences();
}
#endif
#if MC_1_18_1
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public List<? extends StructureStart<?>> startsForFeature(SectionPos sectionPos,
StructureFeature<?> structureFeature) {
ChunkAccess chunk = _getChunk(sectionPos.x(), sectionPos.z(), ChunkStatus.STRUCTURE_REFERENCES);
if (chunk == null) return List.of();
// Copied from StructureFeatureManager::startsForFeature(...) with slight tweaks
LongSet longSet = chunk.getReferencesForFeature(structureFeature);
ImmutableList.Builder builder = ImmutableList.builder();
LongIterator longIterator = longSet.iterator();
while (longIterator.hasNext()) {
long l = (Long)longIterator.next();
SectionPos sectPos = SectionPos.of(new ChunkPos(l), genLevel.getMinSection());
ChunkAccess startChunk = _getChunk(sectPos.x(), sectPos.z(), ChunkStatus.STRUCTURE_STARTS);
if (startChunk == null) continue;
StructureStart<?> structureStart = this.getStartForFeature(sectPos, structureFeature, startChunk);
if (structureStart == null || !structureStart.isValid()) continue;
builder.add(structureStart);
}
return builder.build();
}
#else
@Override
public List<StructureStart> startsForFeature(SectionPos sectionPos, Predicate<ConfiguredStructureFeature<?, ?>> predicate) {
ChunkAccess chunk = _getChunk(sectionPos.x(), sectionPos.z(), ChunkStatus.STRUCTURE_REFERENCES);
if (chunk == null) return List.of();
// Copied from StructureFeatureManager::startsForFeature(...)
Map<ConfiguredStructureFeature<?, ?>, LongSet> map = chunk.getAllReferences();
ImmutableList.Builder<StructureStart> builder = ImmutableList.builder();
Iterator<Map.Entry<ConfiguredStructureFeature<?, ?>, LongSet>> var5 = map.entrySet().iterator();
while(var5.hasNext()) {
Map.Entry<ConfiguredStructureFeature<?, ?>, LongSet> entry = var5.next();
ConfiguredStructureFeature<?, ?> configuredStructureFeature = entry.getKey();
if (predicate.test(configuredStructureFeature)) {
LongSet var10002 = (LongSet)entry.getValue();
Objects.requireNonNull(builder);
this.fillStartsForFeature(configuredStructureFeature, var10002, builder::add);
}
}
return builder.build();
}
@Override
public List<StructureStart> startsForFeature(SectionPos sectionPos, ConfiguredStructureFeature<?, ?> configuredStructureFeature) {
ChunkAccess chunk = _getChunk(sectionPos.x(), sectionPos.z(), ChunkStatus.STRUCTURE_REFERENCES);
if (chunk == null) return (List<StructureStart>) Stream.empty();
// Copied from StructureFeatureManager::startsForFeature(...)
LongSet longSet = chunk.getReferencesForFeature(configuredStructureFeature);
ImmutableList.Builder<StructureStart> builder = ImmutableList.builder();
Objects.requireNonNull(builder);
this.fillStartsForFeature(configuredStructureFeature, longSet, builder::add);
return builder.build();
}
@Override
public Map<ConfiguredStructureFeature<?, ?>, LongSet> getAllStructuresAt(BlockPos blockPos) {
SectionPos sectionPos = SectionPos.of(blockPos);
ChunkAccess chunk = _getChunk(sectionPos.x(), sectionPos.z(), ChunkStatus.STRUCTURE_REFERENCES);
if (chunk == null) return (Map<ConfiguredStructureFeature<?, ?>, LongSet>) Stream.empty();
return chunk.getAllReferences();
}
#endif
#endif
}
@@ -36,7 +36,7 @@ import net.minecraft.world.level.chunk.ProtoChunk;
import net.minecraft.world.level.levelgen.DebugLevelSource;
import net.minecraft.world.level.levelgen.FlatLevelSource;
import net.minecraft.world.level.levelgen.NoiseBasedChunkGenerator;
#if MC_VERSION_1_18_2 || MC_VERSION_1_18_1
#if POST_MC_1_18_1
import net.minecraft.world.level.levelgen.blending.Blender;
#endif
@@ -69,11 +69,11 @@ public final class StepBiomes {
for (ChunkAccess chunk : chunksToDo) {
// System.out.println("StepBiomes: "+chunk.getPos());
#if MC_VERSION_1_18_2 || MC_VERSION_1_18_1
#if PRE_MC_1_18_1
environment.params.generator.createBiomes(environment.params.biomes, chunk);
#else
chunk = environment.joinSync(environment.params.generator.createBiomes(environment.params.biomes, Runnable::run, Blender.of(worldGenRegion),
tParams.structFeat.forWorldGenRegion(worldGenRegion), chunk));
#elif MC_VERSION_1_17_1 || MC_VERSION_1_16_5
environment.params.generator.createBiomes(environment.params.biomes, chunk);
#endif
}
}
@@ -32,7 +32,7 @@ import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.chunk.ChunkStatus;
import net.minecraft.world.level.chunk.ProtoChunk;
import net.minecraft.world.level.levelgen.Heightmap;
#if MC_VERSION_1_18_2 || MC_VERSION_1_18_1
#if POST_MC_1_18_1
import net.minecraft.world.level.levelgen.blending.Blender;
#endif
@@ -64,26 +64,20 @@ public final class StepFeatures {
for (ChunkAccess chunk : chunksToDo) {
try {
#if MC_VERSION_1_18_2 || MC_VERSION_1_18_1
environment.params.generator.applyBiomeDecoration(worldGenRegion, chunk,
tParams.structFeat.forWorldGenRegion(worldGenRegion));
Blender.generateBorderTicks(worldGenRegion, chunk);
#elif MC_VERSION_1_17_1 || MC_VERSION_1_16_5
#if PRE_MC_1_18_1
worldGenRegion.setOverrideCenter(chunk.getPos());
Heightmap.primeHeightmaps(chunk, STATUS.heightmapsAfter());
environment.params.generator.applyBiomeDecoration(worldGenRegion, tParams.structFeat);
#else
Heightmap.primeHeightmaps(chunk, STATUS.heightmapsAfter());
environment.params.generator.applyBiomeDecoration(worldGenRegion, chunk,
tParams.structFeat.forWorldGenRegion(worldGenRegion));
#endif
} catch (ReportedException e) {
e.printStackTrace();
// FIXME: Features concurrent modification issue. Something about cocobeans just
// aren't happy
// For now just retry.
// FIXME: Features concurrent modification issue. Something about cocobeans might just
// error out. For now just retry.
}
}/*
for (ChunkAccess chunk : chunks) {
Heightmap.primeHeightmaps(chunk,
EnumSet.of(Heightmap.Types.MOTION_BLOCKING, Heightmap.Types.MOTION_BLOCKING_NO_LEAVES,
Heightmap.Types.OCEAN_FLOOR, Heightmap.Types.WORLD_SURFACE));
}*/
}
}
}
@@ -48,7 +48,7 @@ public final class StepLight {
public final ChunkStatus STATUS = ChunkStatus.LIGHT;
public void generateGroup(
#if MC_VERSION_1_16_5 LevelLightEngine lightEngine,
#if PRE_MC_1_17_1 LevelLightEngine lightEngine,
#else LightEventListener lightEngine, #endif
ArrayGridList<ChunkAccess> chunks) {
@@ -73,7 +73,7 @@ public final class StepLight {
} catch (Exception e) {
e.printStackTrace();
}
#if MC_VERSION_1_18_1 || MC_VERSION_1_18_2
#if POST_MC_1_18_1
if (chunk instanceof LevelChunk) ((LevelChunk)chunk).setClientLightReady(true);
#endif
chunk.setLightCorrect(true);
@@ -30,7 +30,7 @@ import com.seibel.lod.common.wrappers.worldGeneration.ThreadedParameters;
import net.minecraft.server.level.WorldGenRegion;
import net.minecraft.util.Mth;
#if MC_VERSION_1_18_2 || MC_VERSION_1_18_1 || MC_VERSION_1_17_1
#if POST_MC_1_17_1
import net.minecraft.world.level.LevelHeightAccessor;
#endif
import net.minecraft.world.level.StructureFeatureManager;
@@ -40,7 +40,7 @@ import net.minecraft.world.level.chunk.LevelChunkSection;
import net.minecraft.world.level.chunk.ProtoChunk;
import net.minecraft.world.level.levelgen.NoiseBasedChunkGenerator;
import net.minecraft.world.level.levelgen.NoiseSettings;
#if MC_VERSION_1_18_2 || MC_VERSION_1_18_1
#if POST_MC_1_18_1
import net.minecraft.world.level.levelgen.blending.Blender;
#endif
@@ -73,14 +73,14 @@ public final class StepNoise {
for (ChunkAccess chunk : chunksToDo) {
// System.out.println("StepNoise: "+chunk.getPos());
#if MC_VERSION_1_18_2 || MC_VERSION_1_18_1
chunk = environment.joinSync(environment.params.generator.fillFromNoise(Runnable::run, Blender.of(worldGenRegion),
tParams.structFeat.forWorldGenRegion(worldGenRegion), chunk));
#elif MC_VERSION_1_17_1
#if PRE_MC_1_17_1
environment.params.generator.fillFromNoise(worldGenRegion, tParams.structFeat, chunk);
#elif PRE_MC_1_18_1
chunk = environment.joinSync(environment.params.generator.fillFromNoise(Runnable::run,
tParams.structFeat.forWorldGenRegion(worldGenRegion), chunk));
#elif MC_VERSION_1_16_5
environment.params.generator.fillFromNoise(worldGenRegion, tParams.structFeat, chunk);
#else
chunk = environment.joinSync(environment.params.generator.fillFromNoise(Runnable::run, Blender.of(worldGenRegion),
tParams.structFeat.forWorldGenRegion(worldGenRegion), chunk));
#endif
}
}
@@ -73,7 +73,7 @@ public final class StepStructureStart {
environment.params.generator.createStructures(environment.params.registry, tParams.structFeat, chunk, environment.params.structures,
environment.params.worldSeed);
#if MC_VERSION_1_18_1 || MC_VERSION_1_18_2
#if POST_MC_1_18_1
try {
tParams.structCheck.onStructureLoad(chunk.getPos(), chunk.getAllStarts());
} catch (ArrayIndexOutOfBoundsException e) {
@@ -58,9 +58,10 @@ public final class StepSurface {
for (ChunkAccess chunk : chunksToDo) {
// System.out.println("StepSurface: "+chunk.getPos());
#if MC_VERSION_1_17_1 || MC_VERSION_1_16_5
#if PRE_MC_1_18_1
environment.params.generator.buildSurfaceAndBedrock(worldGenRegion, chunk);
#elif MC_VERSION_1_18_1 || MC_VERSION_1_18_2
#else
environment.params.generator.buildSurface(worldGenRegion, tParams.structFeat.forWorldGenRegion(worldGenRegion), chunk);
#endif
}
@@ -78,7 +78,7 @@ public class ClientProxy
/* World Events */
//ServerChunkEvents.CHUNK_LOAD.register(this::chunkLoadEvent);
#if MC_VERSION_1_16_5 || MC_VERSION_1_17_1
#if PRE_MC_1_18_1 // in 1.18+, we use mixin hook in setClientLightReady(true)
ClientChunkEvents.CHUNK_LOAD.register(this::chunkLoadEvent);
#endif
@@ -22,7 +22,7 @@ package com.seibel.lod.fabric.mixins;
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;
@@ -50,7 +50,7 @@ public class MixinFogRenderer {
@Inject(at = @At("RETURN"), method = "setupFog(Lnet/minecraft/client/Camera;Lnet/minecraft/client/renderer/FogRenderer$FogMode;FZ)V")
private static void disableSetupFog(Camera camera, FogMode fogMode, float f, boolean bl, CallbackInfo callback) {
#if MC_VERSION_1_16_5
#if PRE_MC_1_17_1
FluidState fluidState = camera.getFluidInCamera();
boolean cameraNotInFluid = fluidState.isEmpty();
#else
@@ -63,7 +63,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,
@@ -35,8 +35,17 @@ import net.minecraft.Util;
@Mixin(Util.class)
public class MixinUtilBackgroudThread
{
@Inject(method = "backgroundExecutor", at = @At("HEAD"), cancellable = true)
private static void overrideUtil$backgroundExecutor(CallbackInfoReturnable<ExecutorService> ci)
{
if (ClientProxy.isGenerationThreadChecker != null && ClientProxy.isGenerationThreadChecker.get())
{
//ApiShared.LOGGER.info("util backgroundExecutor triggered");
ci.setReturnValue(new DummyRunExecutorService());
}
}
#if !MC_VERSION_1_16_5
#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)
@@ -48,7 +57,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)
@@ -60,14 +69,5 @@ public class MixinUtilBackgroudThread
}
}
#endif
@Inject(method = "backgroundExecutor", at = @At("HEAD"), cancellable = true)
private static void overrideUtil$backgroundExecutor(CallbackInfoReturnable<ExecutorService> ci)
{
if (ClientProxy.isGenerationThreadChecker != null && ClientProxy.isGenerationThreadChecker.get())
{
//ApiShared.LOGGER.info("util backgroundExecutor triggered");
ci.setReturnValue(new DummyRunExecutorService());
}
}
}
@@ -59,7 +59,7 @@ public class MixinWorldRenderer
// Inject rendering at first call to renderChunkLayer
// HEAD or RETURN
#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)
{
@@ -23,7 +23,7 @@ import com.seibel.lod.fabric.Main;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.multiplayer.ClientPacketListener;
import net.minecraft.client.renderer.LevelRenderer;
#if MC_VERSION_1_18_2
#if POST_MC_1_18_2
import net.minecraft.core.Holder;
#endif
import net.minecraft.resources.ResourceKey;
@@ -41,28 +41,20 @@ import java.util.function.Supplier;
/**
* This class is used for world loading events
* @author Ran
*
* FIXME: Why does forge not have the 1.18+ onChunkLightReady mixin?
*/
@Mixin(ClientLevel.class)
public class MixinClientLevel {
#if MC_VERSION_1_18_2
@Inject(method = "<init>", at = @At("TAIL"))
private void loadWorldEvent(ClientPacketListener clientPacketListener, ClientLevel.ClientLevelData clientLevelData, ResourceKey resourceKey, Holder holder, int i, int j, Supplier supplier, LevelRenderer levelRenderer, boolean bl, long l, CallbackInfo ci) {
private void loadWorldEvent(ClientPacketListener clientPacketListener, ClientLevel.ClientLevelData clientLevelData, ResourceKey resourceKey,
#if POST_MC_1_18_2 Holder holder, #else DimensionType dimensionType, #endif int i,
#if POST_MC_1_18_1 int j, #endif Supplier supplier, LevelRenderer levelRenderer, boolean bl, long l, CallbackInfo ci) {
Main.client_proxy.worldLoadEvent((ClientLevel) (Object) this);
}
#elif MC_VERSION_1_18_1
@Inject(method = "<init>", at = @At("TAIL"))
private void loadWorldEvent(ClientPacketListener clientPacketListener, ClientLevel.ClientLevelData clientLevelData, ResourceKey resourceKey, DimensionType dimensionType, int i, int j, Supplier supplier, LevelRenderer levelRenderer, boolean bl, long l, CallbackInfo ci) {
Main.client_proxy.worldLoadEvent((ClientLevel) (Object) this);
}
#elif MC_VERSION_1_17_1
@Inject(method = "<init>", at = @At("TAIL"))
private void loadWorldEvent(ClientPacketListener clientPacketListener, ClientLevel.ClientLevelData clientLevelData, ResourceKey<Level> resourceKey, DimensionType dimensionType, int i, Supplier<ProfilerFiller> supplier, LevelRenderer levelRenderer, boolean bl, long l, CallbackInfo ci) {
Main.client_proxy.worldLoadEvent((ClientLevel) (Object) this);
}
#endif
#if MC_VERSION_1_18_1 || MC_VERSION_1_18_2
#if POST_MC_1_18_1
@Inject(method = "setLightReady", at = @At("HEAD"))
private void onChunkLightReady(int x, int z, CallbackInfo ci) {
ClientLevel l = (ClientLevel) (Object) this;
@@ -33,19 +33,16 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
*/
@Mixin(ServerLevel.class)
public class MixinServerLevel {
#if MC_VERSION_1_16_5
#if PRE_MC_1_17_1
@Inject(method = "save", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerChunkCache;save(Z)V", shift = At.Shift.AFTER))
private void saveWorldEvent(ProgressListener progressListener, boolean bl, boolean bl2, CallbackInfo ci) {
Main.client_proxy.worldSaveEvent();
}
#else
@Inject(method = "save", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/entity/PersistentEntitySectionManager;saveAll()V", shift = At.Shift.AFTER))
private void saveWorldEvent_sA(ProgressListener progressListener, boolean bl, boolean bl2, CallbackInfo ci) {
Main.client_proxy.worldSaveEvent();
}
@Inject(method = "save", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/entity/PersistentEntitySectionManager;autoSave()V", shift = At.Shift.AFTER))
private void saveWorldEvent_aS(ProgressListener progressListener, boolean bl, boolean bl2, CallbackInfo ci) {
Main.client_proxy.worldSaveEvent();
@@ -22,7 +22,7 @@ package com.seibel.lod.fabric.mixins.unsafe;
import net.minecraft.server.level.ServerLevel;
import org.spongepowered.asm.mixin.Mixin;
#if MC_VERSION_1_18_1 || MC_VERSION_1_18_2
#if POST_MC_1_18_1
import net.minecraft.util.ThreadingDetector;
import org.spongepowered.asm.mixin.Mutable;
@@ -31,7 +31,7 @@ import com.seibel.lod.core.wrapperInterfaces.modAccessor.ISodiumAccessor;
import me.jellysquid.mods.sodium.client.render.SodiumWorldRenderer;
import net.minecraft.client.Minecraft;
#if MC_VERSION_1_16_5
#if PRE_MC_1_17_1
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.protocol.Packet;
import net.minecraft.world.entity.Entity;
@@ -51,13 +51,13 @@ public class SodiumAccessor implements ISodiumAccessor {
return "Sodium-Fabric";
}
#if !MC_VERSION_1_16_5
#if POST_MC_1_17_1
@Override
public HashSet<AbstractChunkPosWrapper> getNormalRenderedChunks() {
SodiumWorldRenderer renderer = SodiumWorldRenderer.instance();
LevelHeightAccessor height = Minecraft.getInstance().level;
#if MC_VERSION_1_18_1 || MC_VERSION_1_18_2
#if POST_MC_1_18_1
// 0b11 = Lighted chunk & loaded chunk
return renderer.getChunkTracker().getChunks(0b00).filter(
(long l) -> {
@@ -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
+1
View File
@@ -16,6 +16,7 @@ mod_issues=https://gitlab.com/jeseibel/minecraft-lod-mod/-/issues
# Global Plugin versions
toml_version=3.6.4
manifold_version=2022.1.7
mcVersions=1.16.5,1.17.1,1.18.1,1.18.2
##### FOR IDE SUPPORT AND TELL IDE TO USE CERTIAN MC VERSION: SWITCH THIS:
mcVer=1.18.1