Merge branch 'master' into 1.17

This commit is contained in:
gnembon committed 2020-11-28 19:03:39 -04:00
commit 2552887340
5 files changed
+101 -26

No files matched your search

@@ -1061,16 +1061,22 @@ public class WorldAccess {
expression.addLazyFunction("biome", -1, (c, t, lv) -> {
CarpetContext cc = (CarpetContext)c;
ServerWorld world = cc.s.getWorld();
if (lv.size() == 0)
{
Value ret = ListValue.wrap(world.getRegistryManager().get(Registry.BIOME_KEY).getIds().stream().map(ValueConversions::of));
return (_c, _t) -> ret;
}
BlockArgument locator = BlockArgument.findIn(cc, lv, 0, false, false, true);
Biome biome;
if (locator.replacement != null)
{
biome = cc.s.getMinecraftServer().getRegistryManager().get(Registry.BIOME_KEY).get(new Identifier(locator.replacement));
if (biome == null) throw new InternalExpressionException("Unknown biome: "+locator.replacement);
biome = world.getRegistryManager().get(Registry.BIOME_KEY).get(new Identifier(locator.replacement));
if (biome == null) return LazyValue.NULL;
}
else
{
ServerWorld world = cc.s.getWorld();
BlockPos pos = locator.block.getPos();
biome = world.getBiome(pos);
}
@@ -1082,9 +1088,9 @@ public class WorldAccess {
return (_c, _t) -> res;
}
String biomeFeature = lv.get(locator.offset).evalValue(c).getString();
Function<Biome, Value> featureProvider = BiomeInfo.biomeFeatures.get(biomeFeature);
BiFunction<ServerWorld, Biome, Value> featureProvider = BiomeInfo.biomeFeatures.get(biomeFeature);
if (featureProvider == null) throw new InternalExpressionException("Unknown biome feature: "+biomeFeature);
Value ret = featureProvider.apply(biome);
Value ret = featureProvider.apply(world, biome);
return (_c, _t) -> ret;
});
@@ -1,32 +1,51 @@
package carpet.script.utils;
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.server.world.ServerWorld;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.gen.feature.ConfiguredFeature;
import net.minecraft.world.gen.feature.ConfiguredStructureFeature;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
import java.util.function.BiFunction;
public class BiomeInfo
{
public final static Map<String, Function<Biome, Value>> biomeFeatures = new HashMap<String, Function<Biome, Value>>(){{
put("top_material", b -> new BlockValue( b.getGenerationSettings().getSurfaceConfig().getTopMaterial(), null, null));
put("under_material", b -> new BlockValue( b.getGenerationSettings().getSurfaceConfig().getUnderMaterial(), null, null));
put("category", b -> StringValue.of(b.getCategory().getName()));
put("temperature", b -> NumericValue.of(b.getTemperature()));
put("fog_color", b -> ValueConversions.ofRGB(b.getFogColor()));
put("foliage_color", b -> ValueConversions.ofRGB(b.getFoliageColor()));
put("sky_color", b -> ValueConversions.ofRGB(b.getSkyColor()));
put("water_color", b -> ValueConversions.ofRGB(b.getWaterColor()));
put("water_fog_color", b -> ValueConversions.ofRGB(b.getWaterFogColor()));
put("humidity", b -> NumericValue.of(b.getDownfall()));
put("precipitation", b -> StringValue.of(b.getPrecipitation().getName()));
put("depth", b -> NumericValue.of(b.getDepth()));
put("scale", b -> NumericValue.of(b.getScale()));
//put("features", b -> b.getGenerationSettings().getFeatures())
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("humidity", (w, b) -> NumericValue.of(b.getDownfall()));
put("precipitation", (w, b) -> StringValue.of(b.getPrecipitation().getName()));
put("depth", (w, b) -> NumericValue.of(b.getDepth()));
put("scale", (w, b) -> NumericValue.of(b.getScale()));
put("features", (w, b) -> {
Registry<ConfiguredFeature<?,?>> registry = w.getRegistryManager().get(Registry.CONFIGURED_FEATURE_WORLDGEN);
return ListValue.wrap(
b.getGenerationSettings().getFeatures().stream().map(step ->
ListValue.wrap(step.stream().map(cfp ->
ValueConversions.of(registry.getId(cfp.get()))
))
)
);
});
put("structures", (w, b) -> {
Registry<ConfiguredStructureFeature<?,?>> registry = w.getRegistryManager().get(Registry.CONFIGURED_STRUCTURE_FEATURE_WORLDGEN);
return ListValue.wrap(b.getGenerationSettings().getStructureFeatures().stream().map(str -> ValueConversions.of(registry.getId(str.get()))));
});
}};
}
@@ -22,6 +22,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import static java.lang.Math.abs;
@@ -91,7 +92,10 @@ public class ListValue extends AbstractListValue implements ContainerValueInterf
}
public static ListValue wrap(Stream<Value> stream)
{
return wrap(stream.collect(Collectors.toList()));
}
public static ListValue wrap(List<Value> list)
{