added biome query to biome
This commit is contained in:
1 parent
f01518a543
commit
54d306d9bc
5 files changed
+75
-11
No files matched your search
@@ -307,7 +307,7 @@ public class Auxiliary {
|
||||
pointLocator = Vector3Argument.findIn(cc, lv, 1, true);
|
||||
if (lv.size()>pointLocator.offset)
|
||||
{
|
||||
BlockArgument blockLocator = BlockArgument.findIn(cc, lv, pointLocator.offset, true, true);
|
||||
BlockArgument blockLocator = BlockArgument.findIn(cc, lv, pointLocator.offset, true, true, false);
|
||||
if (blockLocator.block != null) targetBlock = blockLocator.block.getBlockState();
|
||||
if (lv.size() > blockLocator.offset)
|
||||
{
|
||||
|
||||
@@ -18,6 +18,7 @@ import carpet.script.LazyValue;
|
||||
import carpet.script.argument.BlockArgument;
|
||||
import carpet.script.argument.Vector3Argument;
|
||||
import carpet.script.exception.InternalExpressionException;
|
||||
import carpet.script.utils.BiomeInfo;
|
||||
import carpet.script.utils.WorldTools;
|
||||
import carpet.script.value.BlockValue;
|
||||
import carpet.script.value.EntityValue;
|
||||
@@ -102,6 +103,7 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
@@ -1059,14 +1061,31 @@ public class WorldAccess {
|
||||
|
||||
expression.addLazyFunction("biome", -1, (c, t, lv) -> {
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
BlockArgument locator = BlockArgument.findIn(cc, lv, 0);
|
||||
ServerWorld world = cc.s.getWorld();
|
||||
BlockPos pos = locator.block.getPos();
|
||||
Biome biome = world.getBiome(pos);
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
ServerWorld world = cc.s.getWorld();
|
||||
BlockPos pos = locator.block.getPos();
|
||||
biome = world.getBiome(pos);
|
||||
}
|
||||
// in locatebiome
|
||||
Identifier biomeId = cc.s.getMinecraftServer().getRegistryManager().get(Registry.BIOME_KEY).getId(biome);
|
||||
Value res = new StringValue(NBTSerializableValue.nameFromRegistryId(biomeId));
|
||||
return (_c, _t) -> res;
|
||||
if (locator.offset == lv.size())
|
||||
{
|
||||
Identifier biomeId = cc.s.getMinecraftServer().getRegistryManager().get(Registry.BIOME_KEY).getId(biome);
|
||||
Value res = new StringValue(NBTSerializableValue.nameFromRegistryId(biomeId));
|
||||
return (_c, _t) -> res;
|
||||
}
|
||||
String biomeFeature = lv.get(locator.offset).evalValue(c).getString();
|
||||
Function<Biome, Value> featureProvider = BiomeInfo.biomeFeatures.get(biomeFeature);
|
||||
if (featureProvider == null) throw new InternalExpressionException("Unknown biome feature: "+biomeFeature);
|
||||
Value ret = featureProvider.apply(biome);
|
||||
return (_c, _t) -> ret;
|
||||
});
|
||||
|
||||
expression.addLazyFunction("set_biome", -1, (c, t, lv) ->
|
||||
|
||||
@@ -16,22 +16,30 @@ import java.util.List;
|
||||
public class BlockArgument extends Argument
|
||||
{
|
||||
public final BlockValue block;
|
||||
public final String replacement;
|
||||
private BlockArgument(BlockValue b, int o)
|
||||
{
|
||||
super(o);
|
||||
block = b;
|
||||
replacement = null;
|
||||
}
|
||||
private BlockArgument(BlockValue b, int o, String replacement)
|
||||
{
|
||||
super(o);
|
||||
block = b;
|
||||
this.replacement = replacement;
|
||||
}
|
||||
public static BlockArgument findIn(CarpetContext c, List<LazyValue> params, int offset)
|
||||
{
|
||||
return findIn(c, params,offset, false, false);
|
||||
return findIn(c, params,offset, false, false, false);
|
||||
}
|
||||
|
||||
public static BlockArgument findIn(CarpetContext c, List<LazyValue> params, int offset, boolean acceptString)
|
||||
{
|
||||
return findIn(c, params,offset, acceptString, false);
|
||||
return findIn(c, params,offset, acceptString, false, false);
|
||||
}
|
||||
|
||||
public static BlockArgument findIn(CarpetContext c, List<LazyValue> params, int offset, boolean acceptString, boolean optional)
|
||||
public static BlockArgument findIn(CarpetContext c, List<LazyValue> params, int offset, boolean acceptString, boolean optional, boolean anyString)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -41,6 +49,10 @@ public class BlockArgument extends Argument
|
||||
{
|
||||
return new BlockArgument(null, 1+offset);
|
||||
}
|
||||
if (anyString && v1 instanceof StringValue)
|
||||
{
|
||||
return new BlockArgument(null, 1+offset, v1.getString());
|
||||
}
|
||||
if (acceptString && v1 instanceof StringValue)
|
||||
{
|
||||
return new BlockArgument(BlockValue.fromString(v1.getString()), 1+offset);
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package carpet.script.utils;
|
||||
|
||||
import carpet.script.value.BlockValue;
|
||||
import carpet.script.value.NumericValue;
|
||||
import carpet.script.value.StringValue;
|
||||
import carpet.script.value.Value;
|
||||
import carpet.script.value.ValueConversions;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
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())
|
||||
}};
|
||||
}
|
||||
@@ -41,6 +41,7 @@ public class NumericValue extends Value
|
||||
{
|
||||
if (value == null) return Value.NULL;
|
||||
if (value.doubleValue() == value.longValue()) return new NumericValue(value.longValue());
|
||||
if (value instanceof Float) return new NumericValue(0.000_001D * Math.round(1_000_000.0D*value.doubleValue()));
|
||||
return new NumericValue(value.doubleValue());
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user