Skip to content

Commit

Permalink
Rewrite biome coloring to not require rendering mod patches (#2773)
Browse files Browse the repository at this point in the history
  • Loading branch information
embeddedt authored Jan 28, 2025
1 parent 8f899bf commit 63d8c72
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 158 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import it.unimi.dsi.fastutil.floats.FloatIntPair;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@OnlyIn(Dist.CLIENT)
public class EnvironmentalHazardClientHandler {
Expand All @@ -44,8 +44,8 @@ private EnvironmentalHazardClientHandler() {
* Map of source position to a triple of (trigger, material).
*/
@Getter
private final Map<ChunkPos, EnvironmentalHazardSavedData.HazardZone> hazardZones = new HashMap<>();
private final Map<ChunkPos, FloatIntPair> chunkColorCache = new HashMap<>();
private final Map<ChunkPos, EnvironmentalHazardSavedData.HazardZone> hazardZones = new ConcurrentHashMap<>();
private final Map<ChunkPos, FloatIntPair> chunkColorCache = new ConcurrentHashMap<>();

public void onClientTick() {
if (!ConfigHolder.INSTANCE.gameplay.environmentalHazards) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.gregtechceu.gtceu.core.mixins;

import com.gregtechceu.gtceu.client.EnvironmentalHazardClientHandler;
import com.gregtechceu.gtceu.config.ConfigHolder;

import net.minecraft.client.renderer.BiomeColors;
import net.minecraft.core.SectionPos;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.ColorResolver;

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(BiomeColors.class)
public class BiomeColorsMixin {

@Shadow
@Final
@Mutable
public static ColorResolver WATER_COLOR_RESOLVER;
@Shadow
@Final
@Mutable
public static ColorResolver GRASS_COLOR_RESOLVER;
@Shadow
@Final
@Mutable
public static ColorResolver FOLIAGE_COLOR_RESOLVER;

@Unique
private static ColorResolver gtceu$wrapResolver(ColorResolver resolver) {
return (biome, x, z) -> {
var originalColor = resolver.getColor(biome, x, z);
if (!ConfigHolder.INSTANCE.gameplay.environmentalHazards) {
return originalColor;
}

var clientHandler = EnvironmentalHazardClientHandler.INSTANCE;
var chunkPos = new ChunkPos(SectionPos.posToSectionCoord(x), SectionPos.posToSectionCoord(z));
return clientHandler.colorZone(originalColor, chunkPos);
};
}

@Inject(method = "<clinit>", at = @At("RETURN"))
private static void addPollutionWrapper(CallbackInfo ci) {
WATER_COLOR_RESOLVER = gtceu$wrapResolver(WATER_COLOR_RESOLVER);
GRASS_COLOR_RESOLVER = gtceu$wrapResolver(GRASS_COLOR_RESOLVER);
FOLIAGE_COLOR_RESOLVER = gtceu$wrapResolver(FOLIAGE_COLOR_RESOLVER);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
return MixinPluginShared.isClassFound("mezz.jei.api.IModPlugin");
} else if (mixinClassName.contains("com.gregtechceu.gtceu.core.mixins.emi")) {
return MixinPluginShared.isClassFound("dev.emi.emi.api.EmiPlugin");
} else if (mixinClassName.contains("com.gregtechceu.gtceu.core.mixins.embeddium")) {
return MixinPluginShared.isClassFound("me.jellysquid.mods.sodium.client.SodiumClientMod");
}
return true;
}
Expand Down

This file was deleted.

This file was deleted.

4 changes: 1 addition & 3 deletions src/main/resources/gtceu.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"compatibilityLevel": "JAVA_17",
"plugin": "com.gregtechceu.gtceu.core.mixins.GregTechMixinPlugin",
"client": [
"BlockColorsMixin",
"BiomeColorsMixin",
"BlockModelMixin",
"ClientLevelAccessor",
"GuiGraphicsAccessor",
Expand Down Expand Up @@ -64,8 +64,6 @@
"TagManagerMixin",
"TagValueAccessor",
"ae2.GenericStackInvAccessor",
"embeddium.BiomeColorCacheMixin",
"embeddium.VanillaColorAdapterMixin",
"emi.FluidEmiStackMixin",
"jei.FluidHelperMixin",
"ldlib.SyncUtilsMixin",
Expand Down

0 comments on commit 63d8c72

Please sign in to comment.