Merge branch 'master' into 1.15
# Conflicts: # src/main/java/carpet/script/CarpetExpression.java
This commit is contained in:
commit
797894c662
7 files changed
+147
-26
No files matched your search
@@ -148,11 +148,11 @@ public class FeatureGenerator
|
||||
{
|
||||
structureToFeature.put("Monument", Collections.singletonList("monument"));
|
||||
structureToFeature.put("EndCity", Collections.singletonList("end_city"));
|
||||
structureToFeature.put("Ocean_Ruin", Arrays.asList("oceanruin", "oceanruin_warm", "oceanruin_small", "oceanruin_warm_small", "oceanruin_tall", "oceanruin_warm_tall"));
|
||||
structureToFeature.put("Ocean_Ruin", Arrays.asList("ocean_ruin", "ocean_ruin_warm", "ocean_ruin_small", "ocean_ruin_warm_small", "ocean_ruin_tall", "ocean_ruin_warm_tall"));
|
||||
structureToFeature.put("Village", Arrays.asList("village", "village_desert", "village_savanna", "village_taiga", "village_snowy"));
|
||||
structureToFeature.put("Mansion", Collections.singletonList("mansion"));
|
||||
structureToFeature.put("Buried_Treasure", Collections.singletonList("treasure"));
|
||||
structureToFeature.put("Swamp_Hut", Collections.singletonList("witchhut"));
|
||||
structureToFeature.put("Swamp_Hut", Collections.singletonList("witch_hut"));
|
||||
structureToFeature.put("Stronghold", Collections.singletonList("stronghold"));
|
||||
structureToFeature.put("Desert_Pyramid", Collections.singletonList("desert_temple"));
|
||||
structureToFeature.put("Jungle_Pyramid", Collections.singletonList("jungle_temple"));
|
||||
@@ -175,20 +175,20 @@ public class FeatureGenerator
|
||||
put("igloo", ((StructureFeatureInterface)Feature.IGLOO)::gridAnywhere);
|
||||
put("shipwreck", gridCustomStructure(Feature.SHIPWRECK, new ShipwreckFeatureConfig(true), Biomes.PLAINS));
|
||||
put("shipwreck2", gridCustomStructure(Feature.SHIPWRECK, new ShipwreckFeatureConfig(false), Biomes.PLAINS));
|
||||
put("witchhut", ((StructureFeatureInterface)Feature.SWAMP_HUT)::gridAnywhere);
|
||||
put("witch_hut", ((StructureFeatureInterface)Feature.SWAMP_HUT)::gridAnywhere);
|
||||
put("stronghold", ((StructureFeatureInterface)Feature.STRONGHOLD)::gridAnywhere);
|
||||
|
||||
put("oceanruin_small", gridCustomStructure(Feature.OCEAN_RUIN,
|
||||
put("ocean_ruin_small", gridCustomStructure(Feature.OCEAN_RUIN,
|
||||
new OceanRuinFeatureConfig(OceanRuinFeature.BiomeType.COLD, 0.0F, 0.5F), Biomes.PLAINS));
|
||||
put("oceanruin_warm_small", gridCustomStructure(Feature.OCEAN_RUIN,
|
||||
put("ocean_ruin_warm_small", gridCustomStructure(Feature.OCEAN_RUIN,
|
||||
new OceanRuinFeatureConfig(OceanRuinFeature.BiomeType.WARM, 0.0F, 0.5F), Biomes.PLAINS));
|
||||
put("oceanruin_tall", gridCustomStructure(Feature.OCEAN_RUIN,
|
||||
put("ocean_ruin_tall", gridCustomStructure(Feature.OCEAN_RUIN,
|
||||
new OceanRuinFeatureConfig(OceanRuinFeature.BiomeType.COLD, 1.0F, 0.0F), Biomes.PLAINS));
|
||||
put("oceanruin_warm_tall", gridCustomStructure(Feature.OCEAN_RUIN,
|
||||
put("ocean_ruin_warm_tall", gridCustomStructure(Feature.OCEAN_RUIN,
|
||||
new OceanRuinFeatureConfig(OceanRuinFeature.BiomeType.WARM, 1.0F, 0.0F), Biomes.PLAINS));
|
||||
put("oceanruin", gridCustomStructure(Feature.OCEAN_RUIN,
|
||||
put("ocean_ruin", gridCustomStructure(Feature.OCEAN_RUIN,
|
||||
new OceanRuinFeatureConfig(OceanRuinFeature.BiomeType.COLD, 1.0F, 1.0F), Biomes.PLAINS));
|
||||
put("oceanruin_warm", gridCustomStructure(Feature.OCEAN_RUIN,
|
||||
put("ocean_ruin_warm", gridCustomStructure(Feature.OCEAN_RUIN,
|
||||
new OceanRuinFeatureConfig(OceanRuinFeature.BiomeType.WARM, 1.0F, 1.0F), Biomes.PLAINS));
|
||||
put("treasure", ((StructureFeatureInterface)Feature.BURIED_TREASURE)::gridAnywhere);
|
||||
|
||||
@@ -291,20 +291,20 @@ public class FeatureGenerator
|
||||
put("igloo", ((StructureFeatureInterface)Feature.IGLOO)::plopAnywhere);
|
||||
put("shipwreck", spawnCustomStructure(Feature.SHIPWRECK, new ShipwreckFeatureConfig(true), Biomes.PLAINS));
|
||||
put("shipwreck2", spawnCustomStructure(Feature.SHIPWRECK, new ShipwreckFeatureConfig(false), Biomes.PLAINS));
|
||||
put("witchhut", ((StructureFeatureInterface)Feature.SWAMP_HUT)::plopAnywhere);
|
||||
put("witch_hut", ((StructureFeatureInterface)Feature.SWAMP_HUT)::plopAnywhere);
|
||||
put("stronghold", ((StructureFeatureInterface)Feature.STRONGHOLD)::plopAnywhere);
|
||||
|
||||
put("oceanruin_small", spawnCustomStructure(Feature.OCEAN_RUIN,
|
||||
put("ocean_ruin_small", spawnCustomStructure(Feature.OCEAN_RUIN,
|
||||
new OceanRuinFeatureConfig(OceanRuinFeature.BiomeType.COLD, 0.0F, 0.5F), Biomes.PLAINS));
|
||||
put("oceanruin_warm_small", spawnCustomStructure(Feature.OCEAN_RUIN,
|
||||
put("ocean_ruin_warm_small", spawnCustomStructure(Feature.OCEAN_RUIN,
|
||||
new OceanRuinFeatureConfig(OceanRuinFeature.BiomeType.WARM, 0.0F, 0.5F), Biomes.PLAINS));
|
||||
put("oceanruin_tall", spawnCustomStructure(Feature.OCEAN_RUIN,
|
||||
put("ocean_ruin_tall", spawnCustomStructure(Feature.OCEAN_RUIN,
|
||||
new OceanRuinFeatureConfig(OceanRuinFeature.BiomeType.COLD, 1.0F, 0.0F), Biomes.PLAINS));
|
||||
put("oceanruin_warm_tall", spawnCustomStructure(Feature.OCEAN_RUIN,
|
||||
put("ocean_ruin_warm_tall", spawnCustomStructure(Feature.OCEAN_RUIN,
|
||||
new OceanRuinFeatureConfig(OceanRuinFeature.BiomeType.WARM, 1.0F, 0.0F), Biomes.PLAINS));
|
||||
put("oceanruin", spawnCustomStructure(Feature.OCEAN_RUIN,
|
||||
put("ocean_ruin", spawnCustomStructure(Feature.OCEAN_RUIN,
|
||||
new OceanRuinFeatureConfig(OceanRuinFeature.BiomeType.COLD, 1.0F, 1.0F), Biomes.PLAINS));
|
||||
put("oceanruin_warm", spawnCustomStructure(Feature.OCEAN_RUIN,
|
||||
put("ocean_ruin_warm", spawnCustomStructure(Feature.OCEAN_RUIN,
|
||||
new OceanRuinFeatureConfig(OceanRuinFeature.BiomeType.WARM, 1.0F, 1.0F), Biomes.PLAINS));
|
||||
put("treasure", ((StructureFeatureInterface)Feature.BURIED_TREASURE)::plopAnywhere);
|
||||
|
||||
|
||||
@@ -103,6 +103,7 @@ import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.chunk.ChunkStatus;
|
||||
import net.minecraft.world.chunk.WorldChunk;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
import net.minecraft.world.gen.ChunkRandom;
|
||||
import net.minecraft.loot.context.LootContext;
|
||||
import net.minecraft.loot.context.LootContextParameters;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
@@ -608,6 +609,8 @@ public class CarpetExpression
|
||||
* <p>Numeric function, indicating hardness of a block.</p>
|
||||
* <h3><code>blast_resistance(pos)</code></h3>
|
||||
* <p>Numeric function, indicating blast_resistance of a block.</p>
|
||||
* <h3><code>in_slime_chunk(pos)</code></h3>
|
||||
* <p>Boolean indicating if the given block position is in a slime chunk.</p>
|
||||
|
||||
* <h3><code>top(type, pos)</code></h3>
|
||||
* <p>Returns the Y value of the topmost block at given x, z coords (y value of a block is not important), according to the
|
||||
@@ -624,7 +627,7 @@ public class CarpetExpression
|
||||
* top('ocean_floor', x, y, z) => 41
|
||||
* </pre>
|
||||
* <h3><code>loaded(pos)</code></h3>
|
||||
* <p>Boolean function, true if the block is accessible forthe game mechanics.
|
||||
* <p>Boolean function, true if the block is accessible for the game mechanics.
|
||||
* Normally <code>scarpet</code> doesn't check if operates on
|
||||
* loaded area - the game will automatically load missing blocks. We see this as advantage.
|
||||
* Vanilla <code>fill/clone</code> commands only check the specified corners for loadness.</p>
|
||||
@@ -1019,6 +1022,19 @@ public class CarpetExpression
|
||||
this.expr.addLazyFunction("blast_resistance", -1, (c, t, lv) ->
|
||||
genericStateTest(c, "blast_resistance", lv, (s, p, w) -> new NumericValue(s.getBlock().getBlastResistance())));
|
||||
|
||||
this.expr.addLazyFunction("in_slime_chunk", -1, (c, t, lv) ->
|
||||
{
|
||||
BlockPos pos = BlockValue.fromParams((CarpetContext)c, lv, 0).block.getPos();
|
||||
ChunkPos chunkPos = new ChunkPos(pos);
|
||||
Value ret = new NumericValue(ChunkRandom.create(
|
||||
chunkPos.x, chunkPos.z,
|
||||
((CarpetContext)c).s.getWorld().getSeed(),
|
||||
987234911L
|
||||
).nextInt(10) == 0);
|
||||
return (_c, _t) -> ret;
|
||||
});
|
||||
|
||||
|
||||
this.expr.addLazyFunction("top", -1, (c, t, lv) ->
|
||||
{
|
||||
String type = lv.get(0).evalValue(c).getString().toLowerCase(Locale.ROOT);
|
||||
@@ -2959,6 +2975,8 @@ public class CarpetExpression
|
||||
* loop(1000,game_tick()) // runs the game as fast as it can for 1000 ticks
|
||||
* loop(1000,game_tick(100)) // runs the game twice as slow for 1000 ticks
|
||||
* </pre>
|
||||
* <h3><code>seed()</code></h3>
|
||||
* <p>Returns current world seed.</p>
|
||||
* <h3><code>current_dimension()</code></h3>
|
||||
* <p>Returns current dimension that the script runs in.</p>
|
||||
* <h3><code>in_dimension(smth, expr)</code></h3>
|
||||
@@ -3018,9 +3036,9 @@ public class CarpetExpression
|
||||
* <li><code>igloo</code>: Igloo</li>
|
||||
* <li><code>shipwreck</code>: Shipwreck, version1?</li>
|
||||
* <li><code>shipwreck2</code>: Shipwreck, version2?</li>
|
||||
* <li><code>witchhut</code></li>
|
||||
* <li><code>oceanruin, oceanruin_small, oceanruin_tall</code>: Stone variants of ocean ruins.</li>
|
||||
* <li><code>oceanruin_warm, oceanruin_warm_small, oceanruin_warm_tall</code>: Sandstone variants of ocean ruins.</li>
|
||||
* <li><code>witch_hut</code></li>
|
||||
* <li><code>ocean_ruin, ocean_ruin_small, ocean_ruin_tall</code>: Stone variants of ocean ruins.</li>
|
||||
* <li><code>ocean_ruin_warm, ocean_ruin_warm_small, ocean_ruin_warm_tall</code>: Sandstone variants of ocean ruins.</li>
|
||||
* <li><code>treasure</code>: A treasure chest. Yes, its a whole structure.</li>
|
||||
* <li><code>pillager_outpost</code>: A pillager outpost.</li>
|
||||
* <li><code>mineshaft</code>: A mineshaft.</li>
|
||||
@@ -3401,6 +3419,12 @@ public class CarpetExpression
|
||||
return (cc, tt) -> Value.TRUE;
|
||||
});
|
||||
|
||||
this.expr.addLazyFunction("seed", -1, (c, t, lv) -> {
|
||||
ServerCommandSource s = ((CarpetContext)c).s;
|
||||
Value ret = new NumericValue(s.getWorld().getSeed());
|
||||
return (cc, tt) -> ret;
|
||||
});
|
||||
|
||||
this.expr.addLazyFunction("current_dimension", 0, (c, t, lv) -> {
|
||||
ServerCommandSource s = ((CarpetContext)c).s;
|
||||
Value retval = new StringValue(NBTSerializableValue.nameFromRegistryId(Registry.DIMENSION_TYPE.getId(s.getWorld().dimension.getType())));
|
||||
|
||||
@@ -43,6 +43,7 @@ public class CarpetScriptServer
|
||||
|
||||
private static final List<Module> bundledModuleData = new ArrayList<Module>(){{
|
||||
add(new BundledModule("camera", false));
|
||||
add(new BundledModule("structures", false));
|
||||
add(new BundledModule("event_test", false));
|
||||
add(new BundledModule("stats_test", false));
|
||||
add(new BundledModule("math", true));
|
||||
|
||||
@@ -1312,7 +1312,7 @@ public class Expression
|
||||
LazyValue boundedLHS;
|
||||
if (v1 instanceof ListValue || v1 instanceof MapValue)
|
||||
{
|
||||
((ListValue) v1).append(v2);
|
||||
((AbstractListValue) v1).append(v2);
|
||||
boundedLHS = (cc, tt)-> v1;
|
||||
}
|
||||
else
|
||||
@@ -1626,7 +1626,7 @@ public class Expression
|
||||
* With <code>break</code> and <code>continue</code> statements, the supplied value can be used as a boolean check instead.</p>
|
||||
* <pre>
|
||||
* filter(range(100), !(_%5), _*_>1000) => [0, 5, 10, 15, 20, 25, 30]
|
||||
* map(filter(entities_list('all'),_=='Witch'), query(_,'pos') ) => [[1082.5, 57, 1243.5]]
|
||||
* map(filter(entity_list('*'),_=='Witch'), query(_,'pos') ) => [[1082.5, 57, 1243.5]]
|
||||
* </pre>
|
||||
*
|
||||
* <h3><code>first(list,expr(_,_i))</code></h3>
|
||||
@@ -2720,12 +2720,15 @@ public class Expression
|
||||
* length('foo') => 3
|
||||
* </pre>
|
||||
*
|
||||
* <h3><code>rand(expr)</code></h3>
|
||||
* <h3><code>rand(expr), rand(expr, seed)</code></h3>
|
||||
* <p>returns a random number from <code>0.0</code>
|
||||
* (inclusive) to <code>expr</code> (exclusive).
|
||||
* In boolean context (in conditions, boolean functions, or <code>bool</code>), returns
|
||||
* false if the randomly selected value is less than 1. This means that <code>rand(2)</code> returns true half
|
||||
* of the time and <code>rand(5)</code> returns true for 80% (4/5) of the time</p>
|
||||
* of the time and <code>rand(5)</code> returns true for 80% (4/5) of the time. If seed is not provided, uses a random seed.
|
||||
* If seed is provided, each consecutive call to rand() will act like 'next' call to the same random object.
|
||||
* Scarpet keeps track of up to 1024 custom random number generators, so if you exceed this number (per app), then your
|
||||
* random sequence will revert to the beginning.</p>
|
||||
* <pre>
|
||||
* map(range(10), floor(rand(10))) => [5, 8, 0, 6, 9, 3, 9, 9, 1, 8]
|
||||
* map(range(10), bool(rand(2))) => [1, 1, 1, 0, 0, 1, 1, 0, 0, 0]
|
||||
@@ -2982,7 +2985,12 @@ public class Expression
|
||||
addUnaryFunction("type", v -> new StringValue(v.getTypeString()));
|
||||
|
||||
addUnaryFunction("length", v -> new NumericValue(v.length()));
|
||||
addLazyFunction("rand", 1, (c, t, lv) -> {
|
||||
addLazyFunction("rand", -1, (c, t, lv) -> {
|
||||
int argsize = lv.size();
|
||||
Random randomizer = Expression.randomizer;
|
||||
if (argsize != 1 && argsize != 2)
|
||||
throw new InternalExpressionException("'rand' takes one (range) or two arguments (range and seed)");
|
||||
if (argsize == 2) randomizer = c.host.getRandom(NumericValue.asNumber(lv.get(1).evalValue(c)).getLong());
|
||||
Value argument = lv.get(0).evalValue(c);
|
||||
if (argument instanceof ListValue)
|
||||
{
|
||||
|
||||
@@ -4,11 +4,13 @@ import carpet.script.bundled.Module;
|
||||
import carpet.script.exception.InternalExpressionException;
|
||||
import carpet.script.value.FunctionValue;
|
||||
import carpet.script.value.Value;
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Stream;
|
||||
@@ -16,6 +18,14 @@ import java.util.stream.Stream;
|
||||
public abstract class ScriptHost
|
||||
{
|
||||
public static Map<Value, Value> systemGlobals = new ConcurrentHashMap<>();
|
||||
private static Map<Long, Random> randomizers = new Long2ObjectOpenHashMap<>();
|
||||
|
||||
public Random getRandom(long aLong)
|
||||
{
|
||||
if (randomizers.size() > 1024)
|
||||
randomizers.clear();
|
||||
return randomizers.computeIfAbsent(aLong, Random::new);
|
||||
}
|
||||
|
||||
|
||||
public static class ModuleData
|
||||
|
||||
@@ -124,7 +124,7 @@ public class MapValue extends AbstractListValue implements ContainerValueInterfa
|
||||
@Override
|
||||
public void append(Value v)
|
||||
{
|
||||
put(v);
|
||||
map.put(v, Value.NULL);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user