fix client methods in biome, fixes #870

This commit is contained in:
gnembon committed 2021-05-21 04:22:18 -03:00
1 parent 4466c77780
commit 7fd49e0f04
4 files changed
+81 -5

No files matched your search

@@ -1,12 +1,15 @@
package carpet.script.utils;
import carpet.fakes.BiomeEffectsInterface;
import carpet.script.value.BlockValue;
import carpet.script.value.ListValue;
import carpet.script.value.NumericValue;
import carpet.script.value.StringValue;
import carpet.script.value.Value;
import carpet.script.value.ValueConversions;
import net.minecraft.client.color.world.FoliageColors;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.gen.feature.ConfiguredFeature;
@@ -18,16 +21,23 @@ import java.util.function.BiFunction;
public class BiomeInfo
{
// copy of from Biome.getDefaultFoliageColor
private static int getDefaultFoliageColor(Biome b) {
double d = MathHelper.clamp(b.getTemperature(), 0.0F, 1.0F);
double e = MathHelper.clamp(b.getDownfall(), 0.0F, 1.0F);
return FoliageColors.getColor(d, e);
}
public final static Map<String, BiFunction<ServerWorld, Biome, Value>> biomeFeatures = new HashMap<String, BiFunction<ServerWorld, Biome, Value>>(){{
put("top_material", (w, b) -> new BlockValue( b.getGenerationSettings().getSurfaceConfig().getTopMaterial(), null, null));
put("under_material", (w, b) -> new BlockValue( b.getGenerationSettings().getSurfaceConfig().getUnderMaterial(), null, null));
put("category", (w, b) -> StringValue.of(b.getCategory().getName()));
put("temperature", (w, b) -> NumericValue.of(b.getTemperature()));
put("fog_color", (w, b) -> ValueConversions.ofRGB(b.getFogColor()));
put("foliage_color", (w, b) -> ValueConversions.ofRGB(b.getFoliageColor()));
put("sky_color", (w, b) -> ValueConversions.ofRGB(b.getSkyColor()));
put("water_color", (w, b) -> ValueConversions.ofRGB(b.getWaterColor()));
put("water_fog_color", (w, b) -> ValueConversions.ofRGB(b.getWaterFogColor()));
put("fog_color", (w, b) -> ValueConversions.ofRGB(((BiomeEffectsInterface)b.getEffects()).getCMFogColor()));
put("foliage_color", (w, b) -> ValueConversions.ofRGB(((BiomeEffectsInterface)b.getEffects()).getCMFoliageColor().orElseGet(() -> getDefaultFoliageColor(b))));
put("sky_color", (w, b) -> ValueConversions.ofRGB(((BiomeEffectsInterface)b.getEffects()).getCMSkyColor()));
put("water_color", (w, b) -> ValueConversions.ofRGB(((BiomeEffectsInterface)b.getEffects()).getCMWaterColor()));
put("water_fog_color", (w, b) -> ValueConversions.ofRGB(((BiomeEffectsInterface)b.getEffects()).getCMWaterFogColor()));
put("humidity", (w, b) -> NumericValue.of(b.getDownfall()));
put("precipitation", (w, b) -> StringValue.of(b.getPrecipitation().getName()));
put("depth", (w, b) -> NumericValue.of(b.getDepth()));