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

+25 -2
View File
@@ -2262,9 +2262,32 @@ poi(x,y,z,5) => [] // nothing around
poi(x,y,z,5) => [['nether_portal',0,[7,8,9]],['nether_portal',0,[7,9,9]]] // two portal blocks in the range poi(x,y,z,5) => [['nether_portal',0,[7,8,9]],['nether_portal',0,[7,9,9]]] // two portal blocks in the range
</pre> </pre>
### `biome(pos)` ### `biome()` `biome(name)` `biome(block)` `biome(block/name, feature)`
Returns the biome at that block position. Without arguments, returns the list of biomes in the world.
With block, or name, returns the name of the biome in that position, or null, if provided biome is not valid.
With an optional feature, it returns value for the specified attribute for that biome. Available and querable features include:
* `'top_material'`: unlocalized block representing the top surface material
* `'under_material'`: unlocalized block representing what sits below topsoil
* `'category'`: the parent biome this biome is derived from. Possible values include:
`'none'`, `'taiga'`, `'extreme_hills'`, `'jungle'`, `'mesa'`, `'plains'`, `'savanna'`,
`'icy'`, `'the_end'`, `'beach'`, `'forest'`, `'ocean'`, `'desert'`, `'river'`,
`'swamp'`, `'mushroom'` and `'nether'`.
* `'temperature'`: temperature from 0 to 1
* `'fog_color'`: RGBA color value of fog
* `'foliage_color'`: RGBA color value of foliage
* `'sky_color'`: RGBA color value of sky
* `'water_color'`: RGBA color value of water
* `'water_fog_color'`: RGBA color value of water fog
* `'humidity'`: value from 0 to 1 indicating how wet is the biome
* `'precipitation'`: value from 0 to 1 indicating if the biome has precipitation
* `'depth'`: value from -2 to 2 indicating how high or low the terrain should generate. Values > 0 indicate generation above sea level
and values < 0, below sea level.
* `'scale'`: value from -2 to 2 indicating how flat is the terrain.
* `'features'`: list of features that generate in the biome, grouped by generation steps
* `'structures'`: list of structures that generate in the biome.
### `solid(pos)` ### `solid(pos)`
+25 -2
View File
@@ -306,9 +306,32 @@ poi(x,y,z,5) => [] // nothing around
poi(x,y,z,5) => [['nether_portal',0,[7,8,9]],['nether_portal',0,[7,9,9]]] // two portal blocks in the range poi(x,y,z,5) => [['nether_portal',0,[7,8,9]],['nether_portal',0,[7,9,9]]] // two portal blocks in the range
</pre> </pre>
### `biome(pos)` ### `biome()` `biome(name)` `biome(block)` `biome(block/name, feature)`
Returns the biome at that block position. Without arguments, returns the list of biomes in the world.
With block, or name, returns the name of the biome in that position, or null, if provided biome is not valid.
With an optional feature, it returns value for the specified attribute for that biome. Available and querable features include:
* `'top_material'`: unlocalized block representing the top surface material
* `'under_material'`: unlocalized block representing what sits below topsoil
* `'category'`: the parent biome this biome is derived from. Possible values include:
`'none'`, `'taiga'`, `'extreme_hills'`, `'jungle'`, `'mesa'`, `'plains'`, `'savanna'`,
`'icy'`, `'the_end'`, `'beach'`, `'forest'`, `'ocean'`, `'desert'`, `'river'`,
`'swamp'`, `'mushroom'` and `'nether'`.
* `'temperature'`: temperature from 0 to 1
* `'fog_color'`: RGBA color value of fog
* `'foliage_color'`: RGBA color value of foliage
* `'sky_color'`: RGBA color value of sky
* `'water_color'`: RGBA color value of water
* `'water_fog_color'`: RGBA color value of water fog
* `'humidity'`: value from 0 to 1 indicating how wet is the biome
* `'precipitation'`: value from 0 to 1 indicating if the biome has precipitation
* `'depth'`: value from -2 to 2 indicating how high or low the terrain should generate. Values > 0 indicate generation above sea level
and values < 0, below sea level.
* `'scale'`: value from -2 to 2 indicating how flat is the terrain.
* `'features'`: list of features that generate in the biome, grouped by generation steps
* `'structures'`: list of structures that generate in the biome.
### `solid(pos)` ### `solid(pos)`
@@ -1061,16 +1061,22 @@ public class WorldAccess {
expression.addLazyFunction("biome", -1, (c, t, lv) -> { expression.addLazyFunction("biome", -1, (c, t, lv) -> {
CarpetContext cc = (CarpetContext)c; 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); BlockArgument locator = BlockArgument.findIn(cc, lv, 0, false, false, true);
Biome biome; Biome biome;
if (locator.replacement != null) if (locator.replacement != null)
{ {
biome = cc.s.getMinecraftServer().getRegistryManager().get(Registry.BIOME_KEY).get(new Identifier(locator.replacement)); biome = world.getRegistryManager().get(Registry.BIOME_KEY).get(new Identifier(locator.replacement));
if (biome == null) throw new InternalExpressionException("Unknown biome: "+locator.replacement); if (biome == null) return LazyValue.NULL;
} }
else else
{ {
ServerWorld world = cc.s.getWorld();
BlockPos pos = locator.block.getPos(); BlockPos pos = locator.block.getPos();
biome = world.getBiome(pos); biome = world.getBiome(pos);
} }
@@ -1082,9 +1088,9 @@ public class WorldAccess {
return (_c, _t) -> res; return (_c, _t) -> res;
} }
String biomeFeature = lv.get(locator.offset).evalValue(c).getString(); 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); 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; return (_c, _t) -> ret;
}); });
@@ -1,32 +1,51 @@
package carpet.script.utils; package carpet.script.utils;
import carpet.script.value.BlockValue; import carpet.script.value.BlockValue;
import carpet.script.value.ListValue;
import carpet.script.value.NumericValue; import carpet.script.value.NumericValue;
import carpet.script.value.StringValue; import carpet.script.value.StringValue;
import carpet.script.value.Value; import carpet.script.value.Value;
import carpet.script.value.ValueConversions; 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.biome.Biome;
import net.minecraft.world.gen.feature.ConfiguredFeature;
import net.minecraft.world.gen.feature.ConfiguredStructureFeature;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.function.Function; import java.util.function.BiFunction;
public class BiomeInfo public class BiomeInfo
{ {
public final static Map<String, Function<Biome, Value>> biomeFeatures = new HashMap<String, Function<Biome, Value>>(){{ public final static Map<String, BiFunction<ServerWorld, Biome, Value>> biomeFeatures = new HashMap<String, BiFunction<ServerWorld, Biome, Value>>(){{
put("top_material", b -> new BlockValue( b.getGenerationSettings().getSurfaceConfig().getTopMaterial(), null, null)); put("top_material", (w, b) -> new BlockValue( b.getGenerationSettings().getSurfaceConfig().getTopMaterial(), null, null));
put("under_material", b -> new BlockValue( b.getGenerationSettings().getSurfaceConfig().getUnderMaterial(), null, null)); put("under_material", (w, b) -> new BlockValue( b.getGenerationSettings().getSurfaceConfig().getUnderMaterial(), null, null));
put("category", b -> StringValue.of(b.getCategory().getName())); put("category", (w, b) -> StringValue.of(b.getCategory().getName()));
put("temperature", b -> NumericValue.of(b.getTemperature())); put("temperature", (w, b) -> NumericValue.of(b.getTemperature()));
put("fog_color", b -> ValueConversions.ofRGB(b.getFogColor())); put("fog_color", (w, b) -> ValueConversions.ofRGB(b.getFogColor()));
put("foliage_color", b -> ValueConversions.ofRGB(b.getFoliageColor())); put("foliage_color", (w, b) -> ValueConversions.ofRGB(b.getFoliageColor()));
put("sky_color", b -> ValueConversions.ofRGB(b.getSkyColor())); put("sky_color", (w, b) -> ValueConversions.ofRGB(b.getSkyColor()));
put("water_color", b -> ValueConversions.ofRGB(b.getWaterColor())); put("water_color", (w, b) -> ValueConversions.ofRGB(b.getWaterColor()));
put("water_fog_color", b -> ValueConversions.ofRGB(b.getWaterFogColor())); put("water_fog_color", (w, b) -> ValueConversions.ofRGB(b.getWaterFogColor()));
put("humidity", b -> NumericValue.of(b.getDownfall())); put("humidity", (w, b) -> NumericValue.of(b.getDownfall()));
put("precipitation", b -> StringValue.of(b.getPrecipitation().getName())); put("precipitation", (w, b) -> StringValue.of(b.getPrecipitation().getName()));
put("depth", b -> NumericValue.of(b.getDepth())); put("depth", (w, b) -> NumericValue.of(b.getDepth()));
put("scale", b -> NumericValue.of(b.getScale())); put("scale", (w, b) -> NumericValue.of(b.getScale()));
//put("features", b -> b.getGenerationSettings().getFeatures()) 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.List;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport; import java.util.stream.StreamSupport;
import static java.lang.Math.abs; 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) public static ListValue wrap(List<Value> list)
{ {