Skip to content

Commit

Permalink
Fix biome uniforms
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 committed Oct 7, 2023
1 parent 6a48094 commit 6c12a0e
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 36 deletions.
20 changes: 20 additions & 0 deletions src/main/java/net/coderbot/iris/mixin/MixinBiomes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package net.coderbot.iris.mixin;

import net.coderbot.iris.uniforms.BiomeParameters;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.Biomes;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(Biomes.class)
public class MixinBiomes {
private static int currentId = 0;

@Inject(method = "register", at = @At("TAIL"))
private static void iris$registerBiome(String string, CallbackInfoReturnable<ResourceKey<Biome>> cir) {
BiomeParameters.getBiomeMap().put(cir.getReturnValue(), currentId++);
}
}
75 changes: 39 additions & 36 deletions src/main/java/net/coderbot/iris/uniforms/BiomeParameters.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package net.coderbot.iris.uniforms;

import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import net.coderbot.iris.gl.uniform.FloatSupplier;
import net.coderbot.iris.gl.uniform.UniformHolder;
import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.data.BuiltinRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.core.Holder;
import net.minecraft.resources.ResourceKey;
import net.minecraft.tags.BiomeTags;
import net.minecraft.world.level.biome.Biome;

import java.util.Locale;
Expand All @@ -16,33 +19,40 @@
import static net.coderbot.iris.gl.uniform.UniformUpdateFrequency.PER_TICK;

public class BiomeParameters {
private static final Minecraft client = Minecraft.getInstance();
private static final Object2IntMap<ResourceKey<Biome>> biomeMap = new Object2IntOpenHashMap<>();

public static Object2IntMap<ResourceKey<Biome>> getBiomeMap() {
return biomeMap;
}

public static void addBiomeUniforms(UniformHolder uniforms) {

uniforms
.uniform1i(PER_TICK, "biome", playerI(player ->
BuiltinRegistries.BIOME.getId(player.level.getBiome(player.blockPosition()).value())))
.uniform1i(PER_TICK, "biome_category", playerI(player ->
Biome.getBiomeCategory(player.level.getBiome(player.blockPosition())).ordinal()))
.uniform1i(PER_TICK, "biome_precipitation", playerI(player -> {
Biome.Precipitation precipitation = player.level.getBiome(player.blockPosition()).value().getPrecipitation();
switch (precipitation){
case NONE: return 0;
case RAIN: return 1;
case SNOW: return 2;
}
throw new IllegalStateException("Unknown precipitation type:" + precipitation);
}))
.uniform1f(PER_TICK, "rainfall", playerF(player ->
player.level.getBiome(player.blockPosition()).value().getDownfall()))
.uniform1f(PER_TICK, "temperature", playerF(player ->
player.level.getBiome(player.blockPosition()).value().getBaseTemperature()))


.uniform1i(ONCE, "PPT_NONE", () -> 0)
.uniform1i(ONCE, "PPT_RAIN", () -> 1)
.uniform1i(ONCE, "PPT_SNOW", () -> 2);
.uniform1i(PER_TICK, "biome", playerI(player ->
biomeMap.getInt(player.level.getBiome(player.blockPosition()).unwrapKey().orElse(null))))
.uniform1i(PER_TICK, "biome_category", playerI(player -> {
return Biome.getBiomeCategory(player.level.getBiome(player.blockPosition())).ordinal();
}))
.uniform1i(PER_TICK, "biome_precipitation", playerI(player -> {
Biome.Precipitation precipitation = player.level.getBiome(player.blockPosition()).value().getPrecipitation();
switch (precipitation){
case NONE: return 0;
case RAIN: return 1;
case SNOW: return 2;
}
throw new IllegalStateException("Unknown precipitation type:" + precipitation);
}))
.uniform1f(PER_TICK, "rainfall", playerF(player ->
(player.level.getBiome(player.blockPosition()).value()).getDownfall()))
.uniform1f(PER_TICK, "temperature", playerF(player ->
player.level.getBiome(player.blockPosition()).value().getBaseTemperature()))


.uniform1i(ONCE, "PPT_NONE", () -> 0)
.uniform1i(ONCE, "PPT_RAIN", () -> 1)
.uniform1i(ONCE, "PPT_SNOW", () -> 2)
// Temporary fix for Sildur's Vibrant
.uniform1i(ONCE, "BIOME_SWAMP_HILLS", () -> -1);



Expand All @@ -52,15 +62,8 @@ public static void addBiomeUniforms(UniformHolder uniforms) {

}

public static void addBiomes(UniformHolder uniforms) {
for (Biome biome : BuiltinRegistries.BIOME) {
ResourceLocation id = BuiltinRegistries.BIOME.getKey(biome);
if (id == null || !id.getNamespace().equals("minecraft")) {
continue; // TODO: What should we do with non-standard biomes?
}
int rawId = BuiltinRegistries.BIOME.getId(biome);
uniforms.uniform1i(ONCE, "BIOME_" + id.getPath().toUpperCase(Locale.ROOT), () -> rawId);
}
private static void addBiomes(UniformHolder uniforms) {
biomeMap.forEach((biome, id) -> uniforms.uniform1i(ONCE, "BIOME_" + biome.location().getPath().toUpperCase(Locale.ROOT), () -> id));
}

public static void addCategories(UniformHolder uniforms) {
Expand All @@ -73,7 +76,7 @@ public static void addCategories(UniformHolder uniforms) {

static IntSupplier playerI(ToIntFunction<LocalPlayer> function) {
return () -> {
LocalPlayer player = client.player;
LocalPlayer player = Minecraft.getInstance().player;
if (player == null) {
return 0; // TODO: I'm not sure what I'm supposed to do here?
} else {
Expand All @@ -84,7 +87,7 @@ static IntSupplier playerI(ToIntFunction<LocalPlayer> function) {

static FloatSupplier playerF(ToFloatFunction<LocalPlayer> function) {
return () -> {
LocalPlayer player = client.player;
LocalPlayer player = Minecraft.getInstance().player;
if (player == null) {
return 0.0f; // TODO: I'm not sure what I'm supposed to do here?
} else {
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/mixins.iris.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"ProgramTypeAccessor",
"MixinBlockStateBehavior",
"MixinBooleanState",
"MixinBiomes",
"MixinClientLanguage",
"MixinClientPacketListener",
"MixinDebugScreenOverlay",
Expand Down

0 comments on commit 6c12a0e

Please sign in to comment.