Merge branch 'master' into 1.17
This commit is contained in:
commit
4f7ebdd9ff
23 files changed
+306
-172
No files matched your search
@@ -24,6 +24,7 @@ import carpet.script.value.EntityValue;
|
||||
import carpet.script.value.FormattedTextValue;
|
||||
import carpet.script.value.FunctionValue;
|
||||
import carpet.script.value.ListValue;
|
||||
import carpet.script.value.MapValue;
|
||||
import carpet.script.value.NBTSerializableValue;
|
||||
import carpet.script.value.NullValue;
|
||||
import carpet.script.value.NumericValue;
|
||||
@@ -60,6 +61,7 @@ import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.util.math.EulerAngle;
|
||||
import net.minecraft.util.math.Vec2f;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.registry.DynamicRegistryManager;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.world.World;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
@@ -67,6 +69,7 @@ import org.apache.commons.lang3.tuple.Pair;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
@@ -304,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)
|
||||
{
|
||||
@@ -619,6 +622,29 @@ public class Auxiliary {
|
||||
});
|
||||
|
||||
expression.addLazyFunction("plop", -1, (c, t, lv) ->{
|
||||
if (lv.size() == 0)
|
||||
{
|
||||
Map<Value, Value> plopData = new HashMap<>();
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
DynamicRegistryManager registryManager = cc.s.getWorld().getRegistryManager();
|
||||
plopData.put(StringValue.of("scarpet_custom"),
|
||||
ListValue.wrap(FeatureGenerator.featureMap.keySet().stream().sorted().map(StringValue::of).collect(Collectors.toList()))
|
||||
);
|
||||
plopData.put(StringValue.of("features"),
|
||||
ListValue.wrap(Registry.FEATURE.getIds().stream().sorted().map(ValueConversions::of).collect(Collectors.toList()))
|
||||
);
|
||||
plopData.put(StringValue.of("configured_features"),
|
||||
ListValue.wrap(registryManager.get(Registry.CONFIGURED_FEATURE_WORLDGEN).getIds().stream().sorted().map(ValueConversions::of).collect(Collectors.toList()))
|
||||
);
|
||||
plopData.put(StringValue.of("structures"),
|
||||
ListValue.wrap(Registry.STRUCTURE_FEATURE.getIds().stream().sorted().map(ValueConversions::of).collect(Collectors.toList()))
|
||||
);
|
||||
plopData.put(StringValue.of("configured_structures"),
|
||||
ListValue.wrap(registryManager.get(Registry.CONFIGURED_STRUCTURE_FEATURE_WORLDGEN).getIds().stream().sorted().map(ValueConversions::of).collect(Collectors.toList()))
|
||||
);
|
||||
Value ret = MapValue.wrap(plopData);
|
||||
return (_c, _t) -> ret;
|
||||
}
|
||||
BlockArgument locator = BlockArgument.findIn((CarpetContext)c, lv, 0);
|
||||
if (lv.size() <= locator.offset)
|
||||
throw new InternalExpressionException("'plop' needs extra argument indicating what to plop");
|
||||
@@ -656,23 +682,7 @@ public class Auxiliary {
|
||||
|
||||
expression.addLazyFunction("logger", -1, (c, t, lv) ->
|
||||
{
|
||||
//CarpetSettings.LOG.error("Standard Structures:");
|
||||
//CarpetSettings.LOG.error(Registry.STRUCTURE_FEATURE.getIds().stream().map(i -> "`'"+NBTSerializableValue.nameFromRegistryId(i)+"'`").sorted(). collect(Collectors.joining(", ")));
|
||||
//CarpetSettings.LOG.error("");
|
||||
//CarpetSettings.LOG.error("Configured Structures:");
|
||||
//CarpetSettings.LOG.error(BuiltinRegistries.CONFIGURED_STRUCTURE_FEATURE.getIds().stream().map(i -> "`'"+NBTSerializableValue.nameFromRegistryId(i)+"'`").sorted().collect(Collectors.joining(", ")));
|
||||
//CarpetSettings.LOG.error("");
|
||||
//CarpetSettings.LOG.error("Features:");
|
||||
//CarpetSettings.LOG.error(Registry.FEATURE.getIds().stream().map(i -> "`'"+NBTSerializableValue.nameFromRegistryId(i)+"'`").sorted().collect(Collectors.joining(", ")));
|
||||
//CarpetSettings.LOG.error("");
|
||||
//CarpetSettings.LOG.error("Configured Features:");
|
||||
//CarpetSettings.LOG.error(BuiltinRegistries.CONFIGURED_FEATURE.getIds().stream().map(i -> "`'"+NBTSerializableValue.nameFromRegistryId(i)+"'`").sorted().collect(Collectors.joining(", ")));
|
||||
//CarpetSettings.LOG.error("");
|
||||
//CarpetSettings.LOG.error("Custom:");
|
||||
//CarpetSettings.LOG.error(FeatureGenerator.featureMap.keySet().stream().map(i -> "`'"+i+"'`").sorted().collect(Collectors.joining(", ")));
|
||||
|
||||
//CarpetSettings.LOG.error(Registry.ENTITY_TYPE.getIds().stream().sorted().map(ValueConversions::simplify).collect(Collectors.joining("`, `")));
|
||||
|
||||
Value res;
|
||||
|
||||
if(lv.size()==1)
|
||||
|
||||
@@ -262,7 +262,7 @@ public class Scoreboards {
|
||||
if(!(propertyVal instanceof StringValue)) throw new InternalExpressionException("'team_property' requires a string as the second argument");
|
||||
|
||||
switch (propertyVal.getString()) {
|
||||
case "collision_rule":
|
||||
case "collisionRule":
|
||||
if(!modifying) {
|
||||
Value ret = new StringValue(team.getCollisionRule().name);
|
||||
return (_c, _t) -> ret;
|
||||
@@ -287,7 +287,7 @@ public class Scoreboards {
|
||||
team.setColor(color);
|
||||
|
||||
break;
|
||||
case "death_message_visibility":
|
||||
case "deathMessageVisibility":
|
||||
if(!modifying) {
|
||||
Value ret = new StringValue(team.getDeathMessageVisibilityRule().name);
|
||||
return (_c, _t) -> ret;
|
||||
@@ -300,7 +300,7 @@ public class Scoreboards {
|
||||
team.setDeathMessageVisibilityRule(deathMessageVisibility);
|
||||
|
||||
break;
|
||||
case "display_name":
|
||||
case "displayName":
|
||||
if(!modifying) {
|
||||
Value ret = new FormattedTextValue(team.getDisplayName());
|
||||
return (_c, _t) -> ret;
|
||||
@@ -319,7 +319,7 @@ public class Scoreboards {
|
||||
team.setDisplayName(displayName);
|
||||
|
||||
break;
|
||||
case "friendly_fire":
|
||||
case "friendlyFire":
|
||||
if(!modifying) {
|
||||
Value ret = new NumericValue(team.isFriendlyFireAllowed());
|
||||
return (_c, _t) -> ret;
|
||||
@@ -330,7 +330,7 @@ public class Scoreboards {
|
||||
boolean friendlyFire = settingVal.getBoolean();
|
||||
team.setFriendlyFireAllowed(friendlyFire);
|
||||
break;
|
||||
case "nametag_visibility":
|
||||
case "nametagVisibility":
|
||||
if(!modifying) {
|
||||
Value ret = new StringValue(team.getNameTagVisibilityRule().name);
|
||||
return (_c, _t) -> ret;
|
||||
@@ -361,7 +361,7 @@ public class Scoreboards {
|
||||
|
||||
team.setPrefix(prefix);
|
||||
break;
|
||||
case "see_friendly_invisibles":
|
||||
case "seeFriendlyInvisibles":
|
||||
if(!modifying) {
|
||||
Value ret = new NumericValue(team.shouldShowFriendlyInvisibles());
|
||||
return (_c, _t) -> ret;
|
||||
|
||||
@@ -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;
|
||||
@@ -66,6 +67,7 @@ import net.minecraft.sound.SoundCategory;
|
||||
import net.minecraft.state.StateManager;
|
||||
import net.minecraft.state.property.Property;
|
||||
import net.minecraft.structure.StructureStart;
|
||||
import net.minecraft.tag.TagManager;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Clearable;
|
||||
import net.minecraft.util.Identifier;
|
||||
@@ -101,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;
|
||||
@@ -997,7 +1000,7 @@ public class WorldAccess {
|
||||
// block_state(block, property)
|
||||
expression.addLazyFunction("block_state", -1, (c, t, lv) ->
|
||||
{
|
||||
BlockArgument locator = BlockArgument.findIn((CarpetContext) c, lv, 0);
|
||||
BlockArgument locator = BlockArgument.findIn((CarpetContext) c, lv, 0, true);
|
||||
BlockState state = locator.block.getBlockState();
|
||||
StateManager<Block, BlockState> states = state.getBlock().getStateManager();
|
||||
if (locator.offset == lv.size())
|
||||
@@ -1018,16 +1021,71 @@ public class WorldAccess {
|
||||
return (_c, _t) -> retval;
|
||||
});
|
||||
|
||||
expression.addLazyFunction("block_list", -1, (c, t, lv) ->
|
||||
{
|
||||
if (lv.size() == 0)
|
||||
{
|
||||
Value ret = ListValue.wrap(Registry.BLOCK.getIds().stream().map(ValueConversions::of).collect(Collectors.toList()));
|
||||
return (_c, _t) -> ret;
|
||||
}
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
TagManager tagManager = cc.s.getMinecraftServer().getTagManager();
|
||||
String tag = lv.get(0).evalValue(c).getString();
|
||||
net.minecraft.tag.Tag<Block> blockTag = tagManager.getBlocks().getTag(new Identifier(tag));
|
||||
if (blockTag == null) return LazyValue.NULL;
|
||||
Value ret = ListValue.wrap(blockTag.values().stream().map(b -> ValueConversions.of(Registry.BLOCK.getId(b))).collect(Collectors.toList()));
|
||||
return (_c, _t) -> ret;
|
||||
});
|
||||
|
||||
expression.addLazyFunction("block_tags", -1, (c, t, lv) ->
|
||||
{
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
TagManager tagManager = cc.s.getMinecraftServer().getTagManager();
|
||||
if (lv.size() == 0)
|
||||
{
|
||||
Value ret = ListValue.wrap(tagManager.getBlocks().getTagIds().stream().map(ValueConversions::of).collect(Collectors.toList()));
|
||||
return (_c, _t) -> ret;
|
||||
}
|
||||
BlockArgument blockLocator = BlockArgument.findIn(cc, lv, 0, true);
|
||||
if (blockLocator.offset == lv.size())
|
||||
{
|
||||
Value ret = ListValue.wrap(tagManager.getBlocks().getTagsFor(blockLocator.block.getBlockState().getBlock()).stream().map(ValueConversions::of).collect(Collectors.toList()));
|
||||
return (_c, _t) -> ret;
|
||||
}
|
||||
String tag = lv.get(blockLocator.offset).evalValue(c).getString();
|
||||
net.minecraft.tag.Tag<Block> blockTag = tagManager.getBlocks().getTag(new Identifier(tag));
|
||||
if (blockTag == null) return LazyValue.NULL;
|
||||
return blockLocator.block.getBlockState().isIn(blockTag)?LazyValue.TRUE:LazyValue.FALSE;
|
||||
});
|
||||
|
||||
|
||||
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) ->
|
||||
@@ -1128,7 +1186,17 @@ public class WorldAccess {
|
||||
Map<Value, Value> ret = new HashMap<>();
|
||||
for(StructureFeature<?> str : StructureFeature.STRUCTURES.values())
|
||||
{
|
||||
StructureStart start = FeatureGenerator.shouldStructureStartAt(world, pos, str, needSize);
|
||||
StructureStart<?> start;
|
||||
try
|
||||
{
|
||||
start = FeatureGenerator.shouldStructureStartAt(world, pos, str, needSize);
|
||||
}
|
||||
catch (NullPointerException npe)
|
||||
{
|
||||
CarpetSettings.LOG.error("Failed to detect structure: "+str.getName());
|
||||
start = null;
|
||||
}
|
||||
|
||||
if (start == null) continue;
|
||||
|
||||
Value key = new StringValue(NBTSerializableValue.nameFromRegistryId(Registry.STRUCTURE_FEATURE.getId(str)));
|
||||
|
||||
Reference in new issue
Block a user