Skip to content

Commit

Permalink
Tabs are bad
Browse files Browse the repository at this point in the history
  • Loading branch information
Adubbz committed Mar 23, 2024
1 parent 7c2c522 commit 228844c
Showing 1 changed file with 66 additions and 66 deletions.
132 changes: 66 additions & 66 deletions common/src/main/java/sereneseasons/season/SeasonColorHandlers.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,74 +28,74 @@

public class SeasonColorHandlers
{
private static final Multimap<ResolverType, ColorOverride> resolverOverrides = HashMultimap.create();
private static final Multimap<ResolverType, ColorOverride> resolverOverrides = HashMultimap.create();

public static void setup()
public static void setup()
{
registerGrassAndFoliageColorHandlers();
registerGrassAndFoliageColorHandlers();
}

public static void registerResolverOverride(ResolverType type, ColorOverride override)
{
resolverOverrides.put(type, override);
}

private static ColorResolver originalGrassColorResolver;
private static ColorResolver originalFoliageColorResolver;

private static void registerGrassAndFoliageColorHandlers()
{
originalGrassColorResolver = BiomeColors.GRASS_COLOR_RESOLVER;
originalFoliageColorResolver = BiomeColors.FOLIAGE_COLOR_RESOLVER;

BiomeColors.GRASS_COLOR_RESOLVER = (biome, x, z) -> resolveColors(ResolverType.GRASS, biome, x, z);
BiomeColors.FOLIAGE_COLOR_RESOLVER = (biome, x, z) -> resolveColors(ResolverType.FOLIAGE, biome, x, z);
}

private static int resolveColors(ResolverType type, Biome biome, double x, double z)
{
int originalColor = switch (type) {
case GRASS -> originalGrassColorResolver.getColor(biome, x, z);
case FOLIAGE -> originalFoliageColorResolver.getColor(biome, x, z);
};

Minecraft minecraft = Minecraft.getInstance();
Level level = minecraft.level;

if (level == null) return originalColor;

Registry<Biome> biomeRegistry = level.registryAccess().registryOrThrow(Registries.BIOME);
Holder<Biome> biomeHolder = biomeRegistry.getResourceKey(biome).flatMap(biomeRegistry::getHolder).orElse(null);

if (biomeHolder != null)
{
ISeasonState calendar = SeasonHelper.getSeasonState(level);
ISeasonColorProvider colorProvider = biomeHolder.is(ModTags.Biomes.TROPICAL_BIOMES) ? calendar.getTropicalSeason() : calendar.getSubSeason();

int seasonalColor = switch (type) {
case GRASS -> SeasonColorUtil.applySeasonalGrassColouring(colorProvider, biomeHolder, originalColor);
case FOLIAGE -> SeasonColorUtil.applySeasonalFoliageColouring(colorProvider, biomeHolder, originalColor);
};

int currentColor = seasonalColor;
for (ColorOverride override : resolverOverrides.get(type))
{
currentColor = override.apply(originalColor, seasonalColor, currentColor, biomeHolder, x, z);
}

return currentColor;
}

return originalColor;
}

public interface ColorOverride
{
int apply(int originalColor, int seasonalColor, int currentColor, Holder<Biome> biome, double x, double z);
}

public enum ResolverType
{
GRASS, FOLIAGE
}
public static void registerResolverOverride(ResolverType type, ColorOverride override)
{
resolverOverrides.put(type, override);
}

private static ColorResolver originalGrassColorResolver;
private static ColorResolver originalFoliageColorResolver;

private static void registerGrassAndFoliageColorHandlers()
{
originalGrassColorResolver = BiomeColors.GRASS_COLOR_RESOLVER;
originalFoliageColorResolver = BiomeColors.FOLIAGE_COLOR_RESOLVER;

BiomeColors.GRASS_COLOR_RESOLVER = (biome, x, z) -> resolveColors(ResolverType.GRASS, biome, x, z);
BiomeColors.FOLIAGE_COLOR_RESOLVER = (biome, x, z) -> resolveColors(ResolverType.FOLIAGE, biome, x, z);
}

private static int resolveColors(ResolverType type, Biome biome, double x, double z)
{
int originalColor = switch (type) {
case GRASS -> originalGrassColorResolver.getColor(biome, x, z);
case FOLIAGE -> originalFoliageColorResolver.getColor(biome, x, z);
};

Minecraft minecraft = Minecraft.getInstance();
Level level = minecraft.level;

if (level == null) return originalColor;

Registry<Biome> biomeRegistry = level.registryAccess().registryOrThrow(Registries.BIOME);
Holder<Biome> biomeHolder = biomeRegistry.getResourceKey(biome).flatMap(biomeRegistry::getHolder).orElse(null);

if (biomeHolder != null)
{
ISeasonState calendar = SeasonHelper.getSeasonState(level);
ISeasonColorProvider colorProvider = biomeHolder.is(ModTags.Biomes.TROPICAL_BIOMES) ? calendar.getTropicalSeason() : calendar.getSubSeason();

int seasonalColor = switch (type) {
case GRASS -> SeasonColorUtil.applySeasonalGrassColouring(colorProvider, biomeHolder, originalColor);
case FOLIAGE -> SeasonColorUtil.applySeasonalFoliageColouring(colorProvider, biomeHolder, originalColor);
};

int currentColor = seasonalColor;
for (ColorOverride override : resolverOverrides.get(type))
{
currentColor = override.apply(originalColor, seasonalColor, currentColor, biomeHolder, x, z);
}

return currentColor;
}

return originalColor;
}

public interface ColorOverride
{
int apply(int originalColor, int seasonalColor, int currentColor, Holder<Biome> biome, double x, double z);
}

public enum ResolverType
{
GRASS, FOLIAGE
}
}

0 comments on commit 228844c

Please sign in to comment.