Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite biome coloring to not require rendering mod patches #2773

Merged
merged 1 commit into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading