diff --git a/build.gradle.kts b/build.gradle.kts index a492f94d36..8d3c6dd626 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,13 +3,14 @@ plugins { id("fabric-loom") version ("1.7.3") apply (false) } -val MINECRAFT_VERSION by extra { "1.21" } -val NEOFORGE_VERSION by extra { "21.0.163" } -val FABRIC_LOADER_VERSION by extra { "0.16.0" } -val FABRIC_API_VERSION by extra { "0.101.0+1.21" } +val MINECRAFT_VERSION by extra { "1.21.1" } +val NEOFORGE_VERSION by extra { "21.1.46" } +val FABRIC_LOADER_VERSION by extra { "0.16.4" } +val FABRIC_API_VERSION by extra { "0.103.0+1.21.1" } // This value can be set to null to disable Parchment. -val PARCHMENT_VERSION by extra { "2024.07.28" } +// TODO: Re-add Parchment +val PARCHMENT_VERSION by extra { null } // https://semver.org/ val MOD_VERSION by extra { "0.6.0-beta.1" } diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/client/world/biome/BiomeColorMaps.java b/common/src/main/java/net/caffeinemc/mods/sodium/client/world/biome/BiomeColorMaps.java index 42807ed6cf..a06dab7bd1 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/client/world/biome/BiomeColorMaps.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/client/world/biome/BiomeColorMaps.java @@ -8,11 +8,10 @@ public class BiomeColorMaps { private static final int HEIGHT = 256; private static final int INVALID_INDEX = -1; - private static final int DEFAULT_COLOR = 0xffff00ff; public static int getGrassColor(int index) { if (index == INVALID_INDEX || index >= GrassColor.pixels.length) { - return DEFAULT_COLOR; + return GrassColor.getDefaultColor(); } return GrassColor.pixels[index]; @@ -20,7 +19,7 @@ public static int getGrassColor(int index) { public static int getFoliageColor(int index) { if (index == INVALID_INDEX || index >= FoliageColor.pixels.length) { - return DEFAULT_COLOR; + return FoliageColor.getDefaultColor(); } return FoliageColor.pixels[index]; diff --git a/common/src/main/resources/sodium.mixins.json b/common/src/main/resources/sodium.mixins.json index 905a341a79..ade970e0c0 100644 --- a/common/src/main/resources/sodium.mixins.json +++ b/common/src/main/resources/sodium.mixins.json @@ -87,7 +87,6 @@ "features.textures.mipmaps.MipmapGeneratorMixin", "features.textures.mipmaps.SpriteContentsMixin", "features.textures.scan.SpriteContentsMixin", - "features.world.biome.BiomeMixin", "workarounds.context_creation.WindowMixin", "workarounds.event_loop.RenderSystemMixin" ] diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/world/biome/BiomeMixin.java b/fabric/src/main/java/net/caffeinemc/mods/sodium/mixin/fabric/features/world/biome/BiomeMixin.java similarity index 87% rename from common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/world/biome/BiomeMixin.java rename to fabric/src/main/java/net/caffeinemc/mods/sodium/mixin/fabric/features/world/biome/BiomeMixin.java index 5e2434b188..87acb700be 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/world/biome/BiomeMixin.java +++ b/fabric/src/main/java/net/caffeinemc/mods/sodium/mixin/fabric/features/world/biome/BiomeMixin.java @@ -1,4 +1,4 @@ -package net.caffeinemc.mods.sodium.mixin.features.world.biome; +package net.caffeinemc.mods.sodium.mixin.fabric.features.world.biome; import net.caffeinemc.mods.sodium.client.world.biome.BiomeColorMaps; import net.minecraft.util.Mth; @@ -13,12 +13,11 @@ public abstract class BiomeMixin { @Shadow @Final - private BiomeSpecialEffects specialEffects; + private Biome.ClimateSettings climateSettings; @Shadow @Final - private Biome.ClimateSettings climateSettings; - + private BiomeSpecialEffects specialEffects; @Unique private boolean hasCustomGrassColor; @@ -46,18 +45,22 @@ private void onInit(CallbackInfo ci) { private void setupColors() { this.cachedSpecialEffects = specialEffects; - var grassColor = this.specialEffects.getGrassColorOverride(); + var grassColor = this.cachedSpecialEffects.getGrassColorOverride(); if (grassColor.isPresent()) { this.hasCustomGrassColor = true; this.customGrassColor = grassColor.get(); + } else { + this.hasCustomGrassColor = false; } - var foliageColor = this.specialEffects.getFoliageColorOverride(); + var foliageColor = this.cachedSpecialEffects.getFoliageColorOverride(); if (foliageColor.isPresent()) { this.hasCustomFoliageColor = true; this.customFoliageColor = foliageColor.get(); + } else { + this.hasCustomFoliageColor = false; } this.defaultColorIndex = this.getDefaultColorIndex(); @@ -81,7 +84,7 @@ public int getGrassColor(double x, double z) { color = BiomeColorMaps.getGrassColor(this.defaultColorIndex); } - var modifier = this.specialEffects.getGrassColorModifier(); + var modifier = this.cachedSpecialEffects.getGrassColorModifier(); if (modifier != BiomeSpecialEffects.GrassColorModifier.NONE) { color = modifier.modifyColor(x, z, color); diff --git a/fabric/src/main/resources/sodium-fabric.mixins.json b/fabric/src/main/resources/sodium-fabric.mixins.json index f27a82fd62..512c9ca954 100644 --- a/fabric/src/main/resources/sodium-fabric.mixins.json +++ b/fabric/src/main/resources/sodium-fabric.mixins.json @@ -13,6 +13,7 @@ "core.model.quad.BakedQuadMixin", "features.model.MultiPartBakedModelMixin", "features.model.WeightedBakedModelMixin", - "features.render.model.block.ModelBlockRendererMixin" + "features.render.model.block.ModelBlockRendererMixin", + "features.world.biome.BiomeMixin" ] } \ No newline at end of file diff --git a/neoforge/build.gradle.kts b/neoforge/build.gradle.kts index 49a8a4a9bc..6d6002ec18 100644 --- a/neoforge/build.gradle.kts +++ b/neoforge/build.gradle.kts @@ -145,7 +145,7 @@ dependencies { compileOnly(project.project(":common").sourceSets.getByName("api").output) includeDep("org.sinytra.forgified-fabric-api:fabric-api-base:0.4.42+d1308dedd1") includeDep("org.sinytra.forgified-fabric-api:fabric-renderer-api-v1:3.4.0+acb05a39d1") - includeDep("net.fabricmc:fabric_rendering_data_attachment_v1:0.3.46+${MINECRAFT_VERSION}") { + includeDep("net.fabricmc:fabric_rendering_data_attachment_v1:0.3.46+1.21") { isTransitive = false } includeDep("org.sinytra.forgified-fabric-api:fabric-block-view-api-v2:1.0.10+9afaaf8cd1") diff --git a/neoforge/src/main/java/net/caffeinemc/mods/sodium/neoforge/mixin/features/world/biome/BiomeMixin.java b/neoforge/src/main/java/net/caffeinemc/mods/sodium/neoforge/mixin/features/world/biome/BiomeMixin.java new file mode 100644 index 0000000000..2786ca5993 --- /dev/null +++ b/neoforge/src/main/java/net/caffeinemc/mods/sodium/neoforge/mixin/features/world/biome/BiomeMixin.java @@ -0,0 +1,124 @@ +package net.caffeinemc.mods.sodium.neoforge.mixin.features.world.biome; + +import net.caffeinemc.mods.sodium.client.world.biome.BiomeColorMaps; +import net.minecraft.util.Mth; +import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.biome.BiomeSpecialEffects; +import org.spongepowered.asm.mixin.*; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(Biome.class) +public abstract class BiomeMixin { + @Shadow + public abstract BiomeSpecialEffects getModifiedSpecialEffects(); + + @Shadow + @Final + private Biome.ClimateSettings climateSettings; + + @Unique + private boolean hasCustomGrassColor; + + @Unique + private int customGrassColor; + + @Unique + private boolean hasCustomFoliageColor; + + @Unique + private int customFoliageColor; + + @Unique + private int defaultColorIndex; + + @Unique + private BiomeSpecialEffects cachedSpecialEffects; + + @Inject(method = "", at = @At("RETURN")) + private void onInit(CallbackInfo ci) { + setupColors(); + } + + @Unique + private void setupColors() { + this.cachedSpecialEffects = getModifiedSpecialEffects(); + + var grassColor = this.cachedSpecialEffects.getGrassColorOverride(); + + if (grassColor.isPresent()) { + this.hasCustomGrassColor = true; + this.customGrassColor = grassColor.get(); + } else { + this.hasCustomGrassColor = false; + } + + var foliageColor = this.cachedSpecialEffects.getFoliageColorOverride(); + + if (foliageColor.isPresent()) { + this.hasCustomFoliageColor = true; + this.customFoliageColor = foliageColor.get(); + } else { + this.hasCustomFoliageColor = false; + } + + this.defaultColorIndex = this.getDefaultColorIndex(); + } + + /** + * @author JellySquid + * @reason Avoid unnecessary pointer de-references and allocations + */ + @Overwrite + public int getGrassColor(double x, double z) { + if (this.getModifiedSpecialEffects() != this.cachedSpecialEffects) { + setupColors(); + } + + int color; + + if (this.hasCustomGrassColor) { + color = this.customGrassColor; + } else { + color = BiomeColorMaps.getGrassColor(this.defaultColorIndex); + } + + var modifier = this.cachedSpecialEffects.getGrassColorModifier(); + + if (modifier != BiomeSpecialEffects.GrassColorModifier.NONE) { + color = modifier.modifyColor(x, z, color); + } + + return color; + } + + /** + * @author JellySquid + * @reason Avoid unnecessary pointer de-references and allocations + */ + @Overwrite + public int getFoliageColor() { + if (this.getModifiedSpecialEffects() != this.cachedSpecialEffects) { + setupColors(); + } + + int color; + + if (this.hasCustomFoliageColor) { + color = this.customFoliageColor; + } else { + color = BiomeColorMaps.getFoliageColor(this.defaultColorIndex); + } + + return color; + } + + @Unique + private int getDefaultColorIndex() { + double temperature = Mth.clamp(this.climateSettings.temperature(), 0.0F, 1.0F); + double humidity = Mth.clamp(this.climateSettings.downfall(), 0.0F, 1.0F); + + return BiomeColorMaps.getIndex(temperature, humidity); + } +} diff --git a/neoforge/src/main/resources/sodium-forge.mixins.json b/neoforge/src/main/resources/sodium-forge.mixins.json index f57ceb17a1..ae9a7b4754 100644 --- a/neoforge/src/main/resources/sodium-forge.mixins.json +++ b/neoforge/src/main/resources/sodium-forge.mixins.json @@ -14,6 +14,7 @@ "features.model.MultiPartBakedModelMixin", "features.model.WeightedBakedModelMixin", "features.render.model.block.ModelBlockRendererMixin", + "features.world.biome.BiomeMixin", "AbstractBlockRenderContextMixin", "AuxiliaryLightManagerMixin", "ChunkRenderTypeSetAccessor",