Refactor code to use ListValue.wrap(Stream)
Simplifies code (improving readability) and unifies `Stream<Value>` to `ListValue` handling
This commit is contained in:
1 parent
dd1dc3756a
commit
17249c3c77
15 files changed
+66
-85
No files matched your search
@@ -42,17 +42,14 @@ import net.minecraft.SharedConstants;
|
|||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Holder;
|
import net.minecraft.core.Holder;
|
||||||
import net.minecraft.core.RegistryAccess;
|
|
||||||
import net.minecraft.core.Rotations;
|
import net.minecraft.core.Rotations;
|
||||||
import net.minecraft.core.particles.ParticleOptions;
|
import net.minecraft.core.particles.ParticleOptions;
|
||||||
import net.minecraft.core.registries.BuiltInRegistries;
|
|
||||||
import net.minecraft.core.registries.Registries;
|
import net.minecraft.core.registries.Registries;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.nbt.NbtIo;
|
import net.minecraft.nbt.NbtIo;
|
||||||
import net.minecraft.nbt.NbtUtils;
|
import net.minecraft.nbt.NbtUtils;
|
||||||
import net.minecraft.nbt.StringTag;
|
import net.minecraft.nbt.StringTag;
|
||||||
import net.minecraft.nbt.Tag;
|
import net.minecraft.nbt.Tag;
|
||||||
import net.minecraft.network.chat.MutableComponent;
|
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.network.protocol.Packet;
|
import net.minecraft.network.protocol.Packet;
|
||||||
import net.minecraft.network.protocol.game.ClientboundClearTitlesPacket;
|
import net.minecraft.network.protocol.game.ClientboundClearTitlesPacket;
|
||||||
@@ -572,7 +569,7 @@ public class Auxiliary {
|
|||||||
});
|
});
|
||||||
else
|
else
|
||||||
targetList.forEach(target -> {
|
targetList.forEach(target -> {
|
||||||
map.put(target.getScoreboardName(), (MutableComponent) title);
|
map.put(target.getScoreboardName(), title);
|
||||||
total.getAndIncrement();
|
total.getAndIncrement();
|
||||||
});
|
});
|
||||||
HUDController.update_hud(((CarpetContext)c).server(), targetList);
|
HUDController.update_hud(((CarpetContext)c).server(), targetList);
|
||||||
@@ -621,7 +618,7 @@ public class Auxiliary {
|
|||||||
);
|
);
|
||||||
return ListValue.of(
|
return ListValue.of(
|
||||||
retval,
|
retval,
|
||||||
ListValue.wrap(output.stream().map(FormattedTextValue::new).collect(Collectors.toList())),
|
ListValue.wrap(output.stream().map(FormattedTextValue::new)),
|
||||||
FormattedTextValue.of(error[0])
|
FormattedTextValue.of(error[0])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -757,19 +754,19 @@ public class Auxiliary {
|
|||||||
Map<Value, Value> plopData = new HashMap<>();
|
Map<Value, Value> plopData = new HashMap<>();
|
||||||
CarpetContext cc = (CarpetContext)c;
|
CarpetContext cc = (CarpetContext)c;
|
||||||
plopData.put(StringValue.of("scarpet_custom"),
|
plopData.put(StringValue.of("scarpet_custom"),
|
||||||
ListValue.wrap(FeatureGenerator.featureMap.keySet().stream().sorted().map(StringValue::of).collect(Collectors.toList()))
|
ListValue.wrap(FeatureGenerator.featureMap.keySet().stream().sorted().map(StringValue::of))
|
||||||
);
|
);
|
||||||
plopData.put(StringValue.of("features"),
|
plopData.put(StringValue.of("features"),
|
||||||
ListValue.wrap(cc.registry(Registries.FEATURE).keySet().stream().sorted().map(ValueConversions::of).collect(Collectors.toList()))
|
ListValue.wrap(cc.registry(Registries.FEATURE).keySet().stream().sorted().map(ValueConversions::of))
|
||||||
);
|
);
|
||||||
plopData.put(StringValue.of("configured_features"),
|
plopData.put(StringValue.of("configured_features"),
|
||||||
ListValue.wrap(cc.registry(Registries.CONFIGURED_FEATURE).keySet().stream().sorted().map(ValueConversions::of).collect(Collectors.toList()))
|
ListValue.wrap(cc.registry(Registries.CONFIGURED_FEATURE).keySet().stream().sorted().map(ValueConversions::of))
|
||||||
);
|
);
|
||||||
plopData.put(StringValue.of("structure_types"),
|
plopData.put(StringValue.of("structure_types"),
|
||||||
ListValue.wrap(cc.registry(Registries.STRUCTURE_TYPE).keySet().stream().sorted().map(ValueConversions::of).collect(Collectors.toList()))
|
ListValue.wrap(cc.registry(Registries.STRUCTURE_TYPE).keySet().stream().sorted().map(ValueConversions::of))
|
||||||
);
|
);
|
||||||
plopData.put(StringValue.of("structures"),
|
plopData.put(StringValue.of("structures"),
|
||||||
ListValue.wrap(cc.registry(Registries.STRUCTURE).keySet().stream().sorted().map(ValueConversions::of).collect(Collectors.toList()))
|
ListValue.wrap(cc.registry(Registries.STRUCTURE).keySet().stream().sorted().map(ValueConversions::of))
|
||||||
);
|
);
|
||||||
return MapValue.wrap(plopData);
|
return MapValue.wrap(plopData);
|
||||||
}
|
}
|
||||||
@@ -841,7 +838,7 @@ public class Auxiliary {
|
|||||||
FileArgument fdesc = FileArgument.from(lv,true, FileArgument.Reason.READ);
|
FileArgument fdesc = FileArgument.from(lv,true, FileArgument.Reason.READ);
|
||||||
Stream<String> files = ((CarpetScriptHost) c.host).listFolder(fdesc);
|
Stream<String> files = ((CarpetScriptHost) c.host).listFolder(fdesc);
|
||||||
if (files == null) return Value.NULL;
|
if (files == null) return Value.NULL;
|
||||||
return ListValue.wrap(files.map(StringValue::of).collect(Collectors.toList()));
|
return ListValue.wrap(files.map(StringValue::of));
|
||||||
});
|
});
|
||||||
|
|
||||||
expression.addContextFunction("read_file", 2, (c, t, lv) ->
|
expression.addContextFunction("read_file", 2, (c, t, lv) ->
|
||||||
@@ -868,7 +865,7 @@ public class Auxiliary {
|
|||||||
{
|
{
|
||||||
List<String> content = ((CarpetScriptHost) c.host).readTextResource(fdesc);
|
List<String> content = ((CarpetScriptHost) c.host).readTextResource(fdesc);
|
||||||
if (content == null) return Value.NULL;
|
if (content == null) return Value.NULL;
|
||||||
retVal = ListValue.wrap(content.stream().map(StringValue::new).collect(Collectors.toList()));
|
retVal = ListValue.wrap(content.stream().map(StringValue::new));
|
||||||
}
|
}
|
||||||
return retVal;
|
return retVal;
|
||||||
});
|
});
|
||||||
@@ -1015,7 +1012,7 @@ public class Auxiliary {
|
|||||||
CarpetContext cc = (CarpetContext) c;
|
CarpetContext cc = (CarpetContext) c;
|
||||||
CommandStorage storage = cc.server().getCommandStorage();
|
CommandStorage storage = cc.server().getCommandStorage();
|
||||||
if (lv.size() == 0)
|
if (lv.size() == 0)
|
||||||
return ListValue.wrap(storage.keys().map(i -> new StringValue(nameFromRegistryId(i))).collect(Collectors.toList()));
|
return ListValue.wrap(storage.keys().map(i -> new StringValue(nameFromRegistryId(i))));
|
||||||
String key = lv.get(0).getString();
|
String key = lv.get(0).getString();
|
||||||
CompoundTag old_nbt = storage.get(InputValidator.identifierOf(key));
|
CompoundTag old_nbt = storage.get(InputValidator.identifierOf(key));
|
||||||
if (lv.size() == 2) {
|
if (lv.size() == 2) {
|
||||||
|
|||||||
@@ -23,9 +23,7 @@ import java.util.Locale;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.core.registries.BuiltInRegistries;
|
|
||||||
import net.minecraft.core.registries.Registries;
|
import net.minecraft.core.registries.Registries;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
@@ -157,7 +155,7 @@ public class Entities {
|
|||||||
CommandSourceStack source = ((CarpetContext)c).source();
|
CommandSourceStack source = ((CarpetContext)c).source();
|
||||||
EntityValue.EntityClassDescriptor eDesc = EntityValue.getEntityDescriptor(who, source.getServer());
|
EntityValue.EntityClassDescriptor eDesc = EntityValue.getEntityDescriptor(who, source.getServer());
|
||||||
List<? extends Entity> entityList = source.getLevel().getEntities(eDesc.directType, eDesc.filteringPredicate);
|
List<? extends Entity> entityList = source.getLevel().getEntities(eDesc.directType, eDesc.filteringPredicate);
|
||||||
return ListValue.wrap(entityList.stream().map(EntityValue::new).collect(Collectors.toList()));
|
return ListValue.wrap(entityList.stream().map(EntityValue::new));
|
||||||
});
|
});
|
||||||
|
|
||||||
expression.addContextFunction("entity_area", -1, (c, t, lv) ->
|
expression.addContextFunction("entity_area", -1, (c, t, lv) ->
|
||||||
@@ -185,7 +183,7 @@ public class Entities {
|
|||||||
AABB area = centerBox.inflate(range.x, range.y, range.z);
|
AABB area = centerBox.inflate(range.x, range.y, range.z);
|
||||||
EntityValue.EntityClassDescriptor eDesc = EntityValue.getEntityDescriptor(who, cc.server());
|
EntityValue.EntityClassDescriptor eDesc = EntityValue.getEntityDescriptor(who, cc.server());
|
||||||
List<? extends Entity> entityList = cc.level().getEntities(eDesc.directType, area,eDesc.filteringPredicate);
|
List<? extends Entity> entityList = cc.level().getEntities(eDesc.directType, area,eDesc.filteringPredicate);
|
||||||
return ListValue.wrap(entityList.stream().map(EntityValue::new).collect(Collectors.toList()));
|
return ListValue.wrap(entityList.stream().map(EntityValue::new));
|
||||||
});
|
});
|
||||||
|
|
||||||
expression.addContextFunction("entity_selector", -1, (c, t, lv) ->
|
expression.addContextFunction("entity_selector", -1, (c, t, lv) ->
|
||||||
@@ -253,7 +251,7 @@ public class Entities {
|
|||||||
if (lv.size() < 2) throw new InternalExpressionException("'entity_load_handler' required the entity type, and a function to call");
|
if (lv.size() < 2) throw new InternalExpressionException("'entity_load_handler' required the entity type, and a function to call");
|
||||||
Value entityValue = lv.get(0);
|
Value entityValue = lv.get(0);
|
||||||
List<String> descriptors = (entityValue instanceof ListValue)
|
List<String> descriptors = (entityValue instanceof ListValue)
|
||||||
? ((ListValue) entityValue).getItems().stream().map(Value::getString).collect(Collectors.toList())
|
? ((ListValue) entityValue).getItems().stream().map(Value::getString).toList()
|
||||||
: Collections.singletonList(entityValue.getString());
|
: Collections.singletonList(entityValue.getString());
|
||||||
Set<EntityType<? extends Entity>> types = new HashSet<>();
|
Set<EntityType<? extends Entity>> types = new HashSet<>();
|
||||||
descriptors.forEach(s -> types.addAll(EntityValue.getEntityDescriptor(s, ((CarpetContext) c).server()).types));
|
descriptors.forEach(s -> types.addAll(EntityValue.getEntityDescriptor(s, ((CarpetContext) c).server()).types));
|
||||||
|
|||||||
@@ -26,12 +26,10 @@ import java.util.Collection;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import net.minecraft.commands.arguments.item.ItemInput;
|
import net.minecraft.commands.arguments.item.ItemInput;
|
||||||
import net.minecraft.core.HolderSet;
|
import net.minecraft.core.HolderSet;
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
import net.minecraft.core.RegistryAccess;
|
import net.minecraft.core.RegistryAccess;
|
||||||
import net.minecraft.core.registries.BuiltInRegistries;
|
|
||||||
import net.minecraft.core.registries.Registries;
|
import net.minecraft.core.registries.Registries;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
@@ -70,17 +68,17 @@ public class Inventories {
|
|||||||
CarpetContext cc = (CarpetContext)c;
|
CarpetContext cc = (CarpetContext)c;
|
||||||
Registry<Item> items = cc.registry(Registries.ITEM);
|
Registry<Item> items = cc.registry(Registries.ITEM);
|
||||||
if (lv.size() == 0)
|
if (lv.size() == 0)
|
||||||
return ListValue.wrap(items.keySet().stream().map(ValueConversions::of).collect(Collectors.toList()));
|
return ListValue.wrap(items.keySet().stream().map(ValueConversions::of));
|
||||||
String tag = lv.get(0).getString();
|
String tag = lv.get(0).getString();
|
||||||
Optional<HolderSet.Named<Item>> itemTag = items.getTag(TagKey.create(Registries.ITEM, InputValidator.identifierOf(tag)));
|
Optional<HolderSet.Named<Item>> itemTag = items.getTag(TagKey.create(Registries.ITEM, InputValidator.identifierOf(tag)));
|
||||||
if (itemTag.isEmpty()) return Value.NULL;
|
if (itemTag.isEmpty()) return Value.NULL;
|
||||||
return ListValue.wrap(itemTag.get().stream().map(b -> ValueConversions.of(items.getKey(b.value()))).collect(Collectors.toList()));
|
return ListValue.wrap(itemTag.get().stream().map(b -> ValueConversions.of(items.getKey(b.value()))));
|
||||||
/*
|
/*
|
||||||
TagContainer tagManager = cc.s.getServer(). getTags();
|
TagContainer tagManager = cc.s.getServer(). getTags();
|
||||||
String tag = lv.get(0).getString();
|
String tag = lv.get(0).getString();
|
||||||
net.minecraft.tags.Tag<Item> itemTag = tagManager.getOrEmpty(Registry.ITEM_REGISTRY).getTag(InputValidator.identifierOf(tag));
|
net.minecraft.tags.Tag<Item> itemTag = tagManager.getOrEmpty(Registry.ITEM_REGISTRY).getTag(InputValidator.identifierOf(tag));
|
||||||
if (itemTag == null) return Value.NULL;
|
if (itemTag == null) return Value.NULL;
|
||||||
return ListValue.wrap(itemTag.getValues().stream().map(b -> ValueConversions.of(Registry.ITEM.getKey(b))).collect(Collectors.toList()));
|
return ListValue.wrap(itemTag.getValues().stream().map(b -> ValueConversions.of(Registry.ITEM.getKey(b))));
|
||||||
*/
|
*/
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -90,11 +88,11 @@ public class Inventories {
|
|||||||
|
|
||||||
Registry<Item> blocks = cc.registry(Registries.ITEM);
|
Registry<Item> blocks = cc.registry(Registries.ITEM);
|
||||||
if (lv.size() == 0)
|
if (lv.size() == 0)
|
||||||
return ListValue.wrap(blocks.getTagNames().map(ValueConversions::of).collect(Collectors.toList()));
|
return ListValue.wrap(blocks.getTagNames().map(ValueConversions::of));
|
||||||
Item item = NBTSerializableValue.parseItem(lv.get(0).getString(), cc.registryAccess()).getItem();
|
Item item = NBTSerializableValue.parseItem(lv.get(0).getString(), cc.registryAccess()).getItem();
|
||||||
if (lv.size() == 1)
|
if (lv.size() == 1)
|
||||||
{
|
{
|
||||||
return ListValue.wrap( blocks.getTags().filter(e -> e.getSecond().stream().anyMatch(h -> (h.value() == item))).map(e -> ValueConversions.of(e.getFirst())).collect(Collectors.toList()));
|
return ListValue.wrap( blocks.getTags().filter(e -> e.getSecond().stream().anyMatch(h -> (h.value() == item))).map(e -> ValueConversions.of(e.getFirst())));
|
||||||
}
|
}
|
||||||
String tag = lv.get(1).getString();
|
String tag = lv.get(1).getString();
|
||||||
Optional<HolderSet.Named<Item>> tagSet = blocks.getTag(TagKey.create(Registries.ITEM, InputValidator.identifierOf(tag)));
|
Optional<HolderSet.Named<Item>> tagSet = blocks.getTag(TagKey.create(Registries.ITEM, InputValidator.identifierOf(tag)));
|
||||||
@@ -106,10 +104,10 @@ public class Inventories {
|
|||||||
/*
|
/*
|
||||||
TagContainer tagManager = cc.s.getServer().getTags();
|
TagContainer tagManager = cc.s.getServer().getTags();
|
||||||
if (lv.size() == 0)
|
if (lv.size() == 0)
|
||||||
return ListValue.wrap(tagManager.getOrEmpty(Registry.ITEM_REGISTRY).getAvailableTags().stream().map(ValueConversions::of).collect(Collectors.toList()));
|
return ListValue.wrap(tagManager.getOrEmpty(Registry.ITEM_REGISTRY).getAvailableTags().stream().map(ValueConversions::of));
|
||||||
Item item = NBTSerializableValue.parseItem(lv.get(0).getString()).getItem();
|
Item item = NBTSerializableValue.parseItem(lv.get(0).getString()).getItem();
|
||||||
if (lv.size() == 1)
|
if (lv.size() == 1)
|
||||||
return ListValue.wrap(tagManager.getOrEmpty(Registry.ITEM_REGISTRY).getAllTags().entrySet().stream().filter(e -> e.getValue().contains(item)).map(e -> ValueConversions.of(e.getKey())).collect(Collectors.toList()));
|
return ListValue.wrap(tagManager.getOrEmpty(Registry.ITEM_REGISTRY).getAllTags().entrySet().stream().filter(e -> e.getValue().contains(item)).map(e -> ValueConversions.of(e.getKey())));
|
||||||
String tag = lv.get(1).getString();
|
String tag = lv.get(1).getString();
|
||||||
net.minecraft.tags.Tag<Item> itemTag = tagManager.getOrEmpty(Registry.ITEM_REGISTRY).getTag(InputValidator.identifierOf(tag));
|
net.minecraft.tags.Tag<Item> itemTag = tagManager.getOrEmpty(Registry.ITEM_REGISTRY).getTag(InputValidator.identifierOf(tag));
|
||||||
if (itemTag == null) return Value.NULL;
|
if (itemTag == null) return Value.NULL;
|
||||||
@@ -398,7 +396,7 @@ public class Inventories {
|
|||||||
else if (owner instanceof LivingEntity villager)
|
else if (owner instanceof LivingEntity villager)
|
||||||
{
|
{
|
||||||
// stolen from LookTargetUtil.give((VillagerEntity)owner, droppedStack, (LivingEntity) owner);
|
// stolen from LookTargetUtil.give((VillagerEntity)owner, droppedStack, (LivingEntity) owner);
|
||||||
double double_1 = villager.getY() - 0.30000001192092896D + (double)villager.getEyeHeight();
|
double double_1 = villager.getY() - 0.30000001192092896D + villager.getEyeHeight();
|
||||||
item = new ItemEntity(villager.level, villager.getX(), double_1, villager.getZ(), droppedStack);
|
item = new ItemEntity(villager.level, villager.getX(), double_1, villager.getZ(), droppedStack);
|
||||||
Vec3 vec3d_1 = villager.getViewVector(1.0F).normalize().scale(0.3);// new Vec3d(0, 0.3, 0);
|
Vec3 vec3d_1 = villager.getViewVector(1.0F).normalize().scale(0.3);// new Vec3d(0, 0.3, 0);
|
||||||
item.setDeltaMovement(vec3d_1);
|
item.setDeltaMovement(vec3d_1);
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ import carpet.script.value.Value;
|
|||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import net.minecraft.ChatFormatting;
|
import net.minecraft.ChatFormatting;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
@@ -66,12 +65,12 @@ public class Scoreboards {
|
|||||||
CarpetContext cc = (CarpetContext)c;
|
CarpetContext cc = (CarpetContext)c;
|
||||||
Scoreboard scoreboard = cc.server().getScoreboard();
|
Scoreboard scoreboard = cc.server().getScoreboard();
|
||||||
if (lv.size()==0)
|
if (lv.size()==0)
|
||||||
return ListValue.wrap(scoreboard.getObjectiveNames().stream().map(StringValue::new).collect(Collectors.toList()));
|
return ListValue.wrap(scoreboard.getObjectiveNames().stream().map(StringValue::new));
|
||||||
String objectiveName = lv.get(0).getString();
|
String objectiveName = lv.get(0).getString();
|
||||||
Objective objective = scoreboard.getOrCreateObjective(objectiveName);
|
Objective objective = scoreboard.getOrCreateObjective(objectiveName);
|
||||||
if (objective == null) return Value.NULL;
|
if (objective == null) return Value.NULL;
|
||||||
if (lv.size()==1)
|
if (lv.size()==1)
|
||||||
return ListValue.wrap(scoreboard.getPlayerScores(objective).stream().map(s -> new StringValue(s.getOwner())).collect(Collectors.toList()));
|
return ListValue.wrap(scoreboard.getPlayerScores(objective).stream().map(s -> new StringValue(s.getOwner())));
|
||||||
String key = getScoreboardKeyFromValue(lv.get(1));
|
String key = getScoreboardKeyFromValue(lv.get(1));
|
||||||
if(lv.size()==2)
|
if(lv.size()==2)
|
||||||
{
|
{
|
||||||
@@ -246,11 +245,11 @@ public class Scoreboards {
|
|||||||
CarpetContext cc = (CarpetContext)c;
|
CarpetContext cc = (CarpetContext)c;
|
||||||
ServerScoreboard scoreboard = cc.server().getScoreboard();
|
ServerScoreboard scoreboard = cc.server().getScoreboard();
|
||||||
if(lv.size() == 0)
|
if(lv.size() == 0)
|
||||||
return ListValue.wrap(scoreboard.getTeamNames().stream().map(StringValue::of).collect(Collectors.toList()));
|
return ListValue.wrap(scoreboard.getTeamNames().stream().map(StringValue::of));
|
||||||
if (lv.size() != 1) return Value.NULL;
|
if (lv.size() != 1) return Value.NULL;
|
||||||
PlayerTeam team = scoreboard.getPlayerTeam(lv.get(0).getString());
|
PlayerTeam team = scoreboard.getPlayerTeam(lv.get(0).getString());
|
||||||
if(team == null) return Value.NULL;
|
if(team == null) return Value.NULL;
|
||||||
return ListValue.wrap(team.getPlayers().stream().map(StringValue::of).collect(Collectors.toList()));
|
return ListValue.wrap(team.getPlayers().stream().map(StringValue::of));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@@ -398,7 +397,7 @@ public class Scoreboards {
|
|||||||
CustomBossEvents bossBarManager = ((CarpetContext)c).server().getCustomBossEvents();
|
CustomBossEvents bossBarManager = ((CarpetContext)c).server().getCustomBossEvents();
|
||||||
if(lv.size() > 3) throw new InternalExpressionException("'bossbar' accepts max three arguments");
|
if(lv.size() > 3) throw new InternalExpressionException("'bossbar' accepts max three arguments");
|
||||||
|
|
||||||
if(lv.size() == 0) return ListValue.wrap(bossBarManager.getEvents().stream().map(CustomBossEvent::getTextId).map(ResourceLocation::toString).map(StringValue::of).collect(Collectors.toList()));
|
if(lv.size() == 0) return ListValue.wrap(bossBarManager.getEvents().stream().map(CustomBossEvent::getTextId).map(ResourceLocation::toString).map(StringValue::of));
|
||||||
|
|
||||||
String id = lv.get(0).getString();
|
String id = lv.get(0).getString();
|
||||||
ResourceLocation identifier;
|
ResourceLocation identifier;
|
||||||
@@ -458,7 +457,7 @@ public class Scoreboards {
|
|||||||
}
|
}
|
||||||
return Value.FALSE;
|
return Value.FALSE;
|
||||||
case "players":
|
case "players":
|
||||||
if (propertyValue == null) return ListValue.wrap(bossBar.getPlayers().stream().map(EntityValue::new).collect(Collectors.toList()));
|
if (propertyValue == null) return ListValue.wrap(bossBar.getPlayers().stream().map(EntityValue::new));
|
||||||
if(propertyValue instanceof ListValue)
|
if(propertyValue instanceof ListValue)
|
||||||
{
|
{
|
||||||
bossBar.removeAllPlayers();
|
bossBar.removeAllPlayers();
|
||||||
|
|||||||
@@ -44,7 +44,6 @@ import net.minecraft.core.Holder;
|
|||||||
import net.minecraft.core.HolderSet;
|
import net.minecraft.core.HolderSet;
|
||||||
import net.minecraft.core.QuartPos;
|
import net.minecraft.core.QuartPos;
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
import net.minecraft.core.registries.BuiltInRegistries;
|
|
||||||
import net.minecraft.core.registries.Registries;
|
import net.minecraft.core.registries.Registries;
|
||||||
import net.minecraft.resources.ResourceKey;
|
import net.minecraft.resources.ResourceKey;
|
||||||
import net.minecraft.tags.TagKey;
|
import net.minecraft.tags.TagKey;
|
||||||
@@ -342,7 +341,7 @@ public class WorldAccess {
|
|||||||
new NumericValue(p.getPoiType().value().maxTickets() - ((PoiRecord_scarpetMixin)p).getFreeTickets()),
|
new NumericValue(p.getPoiType().value().maxTickets() - ((PoiRecord_scarpetMixin)p).getFreeTickets()),
|
||||||
ValueConversions.of(p.getPos())
|
ValueConversions.of(p.getPos())
|
||||||
)
|
)
|
||||||
).collect(Collectors.toList()));
|
));
|
||||||
});
|
});
|
||||||
|
|
||||||
//poi_set(pos, null) poi_set(pos, type, occupied?,
|
//poi_set(pos, null) poi_set(pos, type, occupied?,
|
||||||
@@ -1104,7 +1103,7 @@ public class WorldAccess {
|
|||||||
BlockState state = locator.block.getBlockState();
|
BlockState state = locator.block.getBlockState();
|
||||||
StateDefinition<Block, BlockState> states = state.getBlock().getStateDefinition();
|
StateDefinition<Block, BlockState> states = state.getBlock().getStateDefinition();
|
||||||
return ListValue.wrap(states.getProperties().stream().map(
|
return ListValue.wrap(states.getProperties().stream().map(
|
||||||
p -> new StringValue(p.getName())).collect(Collectors.toList())
|
p -> new StringValue(p.getName()))
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1136,12 +1135,12 @@ public class WorldAccess {
|
|||||||
CarpetContext cc = (CarpetContext)c;
|
CarpetContext cc = (CarpetContext)c;
|
||||||
Registry<Block> blocks = cc.registry(Registries.BLOCK);
|
Registry<Block> blocks = cc.registry(Registries.BLOCK);
|
||||||
if (lv.size() == 0)
|
if (lv.size() == 0)
|
||||||
return ListValue.wrap(blocks.keySet().stream().map(ValueConversions::of).collect(Collectors.toList()));
|
return ListValue.wrap(blocks.keySet().stream().map(ValueConversions::of));
|
||||||
ResourceLocation tag = InputValidator.identifierOf(lv.get(0).getString());
|
ResourceLocation tag = InputValidator.identifierOf(lv.get(0).getString());
|
||||||
|
|
||||||
Optional<HolderSet.Named<Block>> tagset = blocks.getTag(TagKey.create(Registries.BLOCK, tag));
|
Optional<HolderSet.Named<Block>> tagset = blocks.getTag(TagKey.create(Registries.BLOCK, tag));
|
||||||
if (tagset.isEmpty()) return Value.NULL;
|
if (tagset.isEmpty()) return Value.NULL;
|
||||||
return ListValue.wrap(tagset.get().stream().map(b -> ValueConversions.of(blocks.getKey(b.value()))).collect(Collectors.toList()));
|
return ListValue.wrap(tagset.get().stream().map(b -> ValueConversions.of(blocks.getKey(b.value()))));
|
||||||
});
|
});
|
||||||
|
|
||||||
expression.addContextFunction("block_tags", -1, (c, t, lv) ->
|
expression.addContextFunction("block_tags", -1, (c, t, lv) ->
|
||||||
@@ -1149,12 +1148,12 @@ public class WorldAccess {
|
|||||||
CarpetContext cc = (CarpetContext)c;
|
CarpetContext cc = (CarpetContext)c;
|
||||||
Registry<Block> blocks = cc.registry(Registries.BLOCK);
|
Registry<Block> blocks = cc.registry(Registries.BLOCK);
|
||||||
if (lv.size() == 0)
|
if (lv.size() == 0)
|
||||||
return ListValue.wrap(blocks.getTagNames().map(ValueConversions::of).collect(Collectors.toList()));
|
return ListValue.wrap(blocks.getTagNames().map(ValueConversions::of));
|
||||||
BlockArgument blockLocator = BlockArgument.findIn(cc, lv, 0, true);
|
BlockArgument blockLocator = BlockArgument.findIn(cc, lv, 0, true);
|
||||||
if (blockLocator.offset == lv.size())
|
if (blockLocator.offset == lv.size())
|
||||||
{
|
{
|
||||||
Block target = blockLocator.block.getBlockState().getBlock();
|
Block target = blockLocator.block.getBlockState().getBlock();
|
||||||
return ListValue.wrap( blocks.getTags().filter(e -> e.getSecond().stream().anyMatch(h -> (h.value() == target))).map(e -> ValueConversions.of(e.getFirst())).collect(Collectors.toList()));
|
return ListValue.wrap( blocks.getTags().filter(e -> e.getSecond().stream().anyMatch(h -> (h.value() == target))).map(e -> ValueConversions.of(e.getFirst())));
|
||||||
}
|
}
|
||||||
String tag = lv.get(blockLocator.offset).getString();
|
String tag = lv.get(blockLocator.offset).getString();
|
||||||
Optional<HolderSet.Named<Block>> tagSet = blocks.getTag(TagKey.create(Registries.BLOCK, InputValidator.identifierOf(tag)));
|
Optional<HolderSet.Named<Block>> tagSet = blocks.getTag(TagKey.create(Registries.BLOCK, InputValidator.identifierOf(tag)));
|
||||||
@@ -1165,12 +1164,12 @@ public class WorldAccess {
|
|||||||
/* before
|
/* before
|
||||||
TagContainer tagManager = cc.s.getServer().getTags();
|
TagContainer tagManager = cc.s.getServer().getTags();
|
||||||
if (lv.size() == 0)
|
if (lv.size() == 0)
|
||||||
return ListValue.wrap(tagManager.getOrEmpty(Registry.BLOCK_REGISTRY).getAvailableTags().stream().map(ValueConversions::of).collect(Collectors.toList()));
|
return ListValue.wrap(tagManager.getOrEmpty(Registry.BLOCK_REGISTRY).getAvailableTags().stream().map(ValueConversions::of));
|
||||||
BlockArgument blockLocator = BlockArgument.findIn(cc, lv, 0, true);
|
BlockArgument blockLocator = BlockArgument.findIn(cc, lv, 0, true);
|
||||||
if (blockLocator.offset == lv.size())
|
if (blockLocator.offset == lv.size())
|
||||||
{
|
{
|
||||||
Block target = blockLocator.block.getBlockState().getBlock();
|
Block target = blockLocator.block.getBlockState().getBlock();
|
||||||
return ListValue.wrap(tagManager.getOrEmpty(Registry.BLOCK_REGISTRY).getAllTags().entrySet().stream().filter(e -> e.getValue().contains(target)).map(e -> ValueConversions.of(e.getKey())).collect(Collectors.toList()));
|
return ListValue.wrap(tagManager.getOrEmpty(Registry.BLOCK_REGISTRY).getAllTags().entrySet().stream().filter(e -> e.getValue().contains(target)).map(e -> ValueConversions.of(e.getKey())));
|
||||||
}
|
}
|
||||||
String tag = lv.get(blockLocator.offset).getString();
|
String tag = lv.get(blockLocator.offset).getString();
|
||||||
net.minecraft.tags.Tag<Block> blockTag = tagManager.getOrEmpty(Registry.BLOCK_REGISTRY).getTag(InputValidator.identifierOf(tag));
|
net.minecraft.tags.Tag<Block> blockTag = tagManager.getOrEmpty(Registry.BLOCK_REGISTRY).getTag(InputValidator.identifierOf(tag));
|
||||||
@@ -1303,7 +1302,7 @@ public class WorldAccess {
|
|||||||
if (lv.size() == locator.offset)
|
if (lv.size() == locator.offset)
|
||||||
return ListValue.wrap(references.entrySet().stream().
|
return ListValue.wrap(references.entrySet().stream().
|
||||||
filter(e -> e.getValue()!= null && !e.getValue().isEmpty()).
|
filter(e -> e.getValue()!= null && !e.getValue().isEmpty()).
|
||||||
map(e -> new StringValue(NBTSerializableValue.nameFromRegistryId(reg.getKey(e.getKey())))).collect(Collectors.toList())
|
map(e -> new StringValue(NBTSerializableValue.nameFromRegistryId(reg.getKey(e.getKey()))))
|
||||||
);
|
);
|
||||||
String simpleStructureName = lv.get(locator.offset).getString().toLowerCase(Locale.ROOT);
|
String simpleStructureName = lv.get(locator.offset).getString().toLowerCase(Locale.ROOT);
|
||||||
Structure structureName = reg.get(InputValidator.identifierOf(simpleStructureName));
|
Structure structureName = reg.get(InputValidator.identifierOf(simpleStructureName));
|
||||||
@@ -1313,7 +1312,7 @@ public class WorldAccess {
|
|||||||
return ListValue.wrap(structureReferences.longStream().mapToObj(l -> ListValue.of(
|
return ListValue.wrap(structureReferences.longStream().mapToObj(l -> ListValue.of(
|
||||||
new NumericValue(16*ChunkPos.getX(l)),
|
new NumericValue(16*ChunkPos.getX(l)),
|
||||||
Value.ZERO,
|
Value.ZERO,
|
||||||
new NumericValue(16*ChunkPos.getZ(l)))).collect(Collectors.toList()));
|
new NumericValue(16*ChunkPos.getZ(l)))));
|
||||||
});
|
});
|
||||||
|
|
||||||
expression.addContextFunction("structure_eligibility", -1, (c, t, lv) ->
|
expression.addContextFunction("structure_eligibility", -1, (c, t, lv) ->
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package carpet.script.command;
|
|||||||
|
|
||||||
import carpet.CarpetServer;
|
import carpet.CarpetServer;
|
||||||
import carpet.fakes.BlockStateArgumentInterface;
|
import carpet.fakes.BlockStateArgumentInterface;
|
||||||
import carpet.script.CarpetContext;
|
|
||||||
import carpet.script.CarpetScriptHost;
|
import carpet.script.CarpetScriptHost;
|
||||||
import carpet.script.argument.FunctionArgument;
|
import carpet.script.argument.FunctionArgument;
|
||||||
import carpet.script.value.BlockValue;
|
import carpet.script.value.BlockValue;
|
||||||
@@ -96,7 +95,6 @@ import net.minecraft.core.Direction;
|
|||||||
import net.minecraft.core.Holder;
|
import net.minecraft.core.Holder;
|
||||||
import net.minecraft.core.HolderSet;
|
import net.minecraft.core.HolderSet;
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
import net.minecraft.core.registries.BuiltInRegistries;
|
|
||||||
import net.minecraft.core.registries.Registries;
|
import net.minecraft.core.registries.Registries;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.resources.ResourceKey;
|
import net.minecraft.resources.ResourceKey;
|
||||||
@@ -613,7 +611,7 @@ public abstract class CommandArgument
|
|||||||
protected Value getValueFromContext(CommandContext<CommandSourceStack> context, String param) throws CommandSyntaxException
|
protected Value getValueFromContext(CommandContext<CommandSourceStack> context, String param) throws CommandSyntaxException
|
||||||
{
|
{
|
||||||
Collection<? extends Entity> founds = net.minecraft.commands.arguments.EntityArgument.getOptionalEntities(context, param);
|
Collection<? extends Entity> founds = net.minecraft.commands.arguments.EntityArgument.getOptionalEntities(context, param);
|
||||||
if (!single) return ListValue.wrap(founds.stream().map(EntityValue::new).collect(Collectors.toList()));
|
if (!single) return ListValue.wrap(founds.stream().map(EntityValue::new));
|
||||||
if (founds.size() == 0) return Value.NULL;
|
if (founds.size() == 0) return Value.NULL;
|
||||||
if (founds.size() == 1) return new EntityValue(founds.iterator().next());
|
if (founds.size() == 1) return new EntityValue(founds.iterator().next());
|
||||||
throw new SimpleCommandExceptionType(Component.literal("Multiple entities returned while only one was requested"+" for custom type "+suffix)).create();
|
throw new SimpleCommandExceptionType(Component.literal("Multiple entities returned while only one was requested"+" for custom type "+suffix)).create();
|
||||||
@@ -653,7 +651,7 @@ public abstract class CommandArgument
|
|||||||
protected Value getValueFromContext(CommandContext<CommandSourceStack> context, String param) throws CommandSyntaxException
|
protected Value getValueFromContext(CommandContext<CommandSourceStack> context, String param) throws CommandSyntaxException
|
||||||
{
|
{
|
||||||
Collection<GameProfile> profiles = GameProfileArgument.getGameProfiles(context, param);
|
Collection<GameProfile> profiles = GameProfileArgument.getGameProfiles(context, param);
|
||||||
if (!single) return ListValue.wrap(profiles.stream().map(p -> StringValue.of(p.getName())).collect(Collectors.toList()));
|
if (!single) return ListValue.wrap(profiles.stream().map(p -> StringValue.of(p.getName())));
|
||||||
int size = profiles.size();
|
int size = profiles.size();
|
||||||
if (size == 0) return Value.NULL;
|
if (size == 0) return Value.NULL;
|
||||||
if (size == 1) return StringValue.of(profiles.iterator().next().getName());
|
if (size == 1) return StringValue.of(profiles.iterator().next().getName());
|
||||||
@@ -694,7 +692,7 @@ public abstract class CommandArgument
|
|||||||
protected Value getValueFromContext(CommandContext<CommandSourceStack> context, String param) throws CommandSyntaxException
|
protected Value getValueFromContext(CommandContext<CommandSourceStack> context, String param) throws CommandSyntaxException
|
||||||
{
|
{
|
||||||
Collection<String> holders = ScoreHolderArgument.getNames(context, param);
|
Collection<String> holders = ScoreHolderArgument.getNames(context, param);
|
||||||
if (!single) return ListValue.wrap(holders.stream().map(StringValue::of).collect(Collectors.toList()));
|
if (!single) return ListValue.wrap(holders.stream().map(StringValue::of));
|
||||||
int size = holders.size();
|
int size = holders.size();
|
||||||
if (size == 0) return Value.NULL;
|
if (size == 0) return Value.NULL;
|
||||||
if (size == 1) return StringValue.of(holders.iterator().next());
|
if (size == 1) return StringValue.of(holders.iterator().next());
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ public class ControlFlow {
|
|||||||
StringValue.of(f.getString()),
|
StringValue.of(f.getString()),
|
||||||
NumericValue.of(f.getToken().lineno+1),
|
NumericValue.of(f.getToken().lineno+1),
|
||||||
NumericValue.of(f.getToken().linepos+1)
|
NumericValue.of(f.getToken().linepos+1)
|
||||||
)).collect(Collectors.toList())),
|
))),
|
||||||
|
|
||||||
StringValue.of("locals"), MapValue.wrap(ret.context.variables.entrySet().stream().filter(e -> !e.getKey().equals("_trace")).collect(Collectors.toMap(
|
StringValue.of("locals"), MapValue.wrap(ret.context.variables.entrySet().stream().filter(e -> !e.getKey().equals("_trace")).collect(Collectors.toMap(
|
||||||
e -> StringValue.of(e.getKey()),
|
e -> StringValue.of(e.getKey()),
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ 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 com.google.gson.JsonParseException;
|
import com.google.gson.JsonParseException;
|
||||||
import com.google.gson.JsonParser;
|
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -186,7 +185,7 @@ public class DataStructures {
|
|||||||
if (v instanceof MapValue)
|
if (v instanceof MapValue)
|
||||||
return ListValue.wrap(((MapValue) v).getMap().entrySet().stream().map(
|
return ListValue.wrap(((MapValue) v).getMap().entrySet().stream().map(
|
||||||
(p) -> ListValue.of(p.getKey(), p.getValue())
|
(p) -> ListValue.of(p.getKey(), p.getValue())
|
||||||
).collect(Collectors.toList()));
|
));
|
||||||
return Value.NULL;
|
return Value.NULL;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ import carpet.script.value.Value;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class Functions {
|
public class Functions {
|
||||||
public static void apply(Expression expression) // public just to get the javadoc right
|
public static void apply(Expression expression) // public just to get the javadoc right
|
||||||
@@ -31,10 +30,10 @@ public class Functions {
|
|||||||
c.host.importModule(c, moduleName);
|
c.host.importModule(c, moduleName);
|
||||||
moduleName = moduleName.toLowerCase(Locale.ROOT);
|
moduleName = moduleName.toLowerCase(Locale.ROOT);
|
||||||
if (lv.size() > 1)
|
if (lv.size() > 1)
|
||||||
c.host.importNames(c, expression.module, moduleName, lv.subList(1, lv.size()).stream().map(Value::getString).collect(Collectors.toList()));
|
c.host.importNames(c, expression.module, moduleName, lv.subList(1, lv.size()).stream().map(Value::getString).toList());
|
||||||
if (t == Context.VOID)
|
if (t == Context.VOID)
|
||||||
return Value.NULL;
|
return Value.NULL;
|
||||||
return ListValue.wrap(c.host.availableImports(moduleName).map(StringValue::new).collect(Collectors.toList()));
|
return ListValue.wrap(c.host.availableImports(moduleName).map(StringValue::new));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import java.util.HashMap;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
@@ -25,7 +24,7 @@ public class BiomeInfo
|
|||||||
//put("top_material", (w, 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", (w, b) -> new BlockValue( b.getGenerationSettings().getSurfaceConfig().getUnderMaterial(), null, null));
|
//put("under_material", (w, b) -> new BlockValue( b.getGenerationSettings().getSurfaceConfig().getUnderMaterial(), null, null));
|
||||||
//put("category", (w, b) -> StringValue.of(Biome.getBiomeCategory(Holder.direct(b)).getName()));
|
//put("category", (w, b) -> StringValue.of(Biome.getBiomeCategory(Holder.direct(b)).getName()));
|
||||||
put("tags", (w, b) -> ListValue.wrap(w.registryAccess().registryOrThrow(Registries.BIOME).getTags().filter(p -> p.getSecond().stream().anyMatch(h -> h.value() == b)).map(p -> p.getFirst().location()).map(ValueConversions::of).collect(Collectors.toList())));
|
put("tags", (w, b) -> ListValue.wrap(w.registryAccess().registryOrThrow(Registries.BIOME).getTags().filter(p -> p.getSecond().stream().anyMatch(h -> h.value() == b)).map(p -> p.getFirst().location()).map(ValueConversions::of)));
|
||||||
|
|
||||||
put("temperature", (w, b) -> NumericValue.of(b.getBaseTemperature()));
|
put("temperature", (w, b) -> NumericValue.of(b.getBaseTemperature()));
|
||||||
put("fog_color", (w, b) -> ValueConversions.ofRGB(b.getSpecialEffects().getFogColor()));
|
put("fog_color", (w, b) -> ValueConversions.ofRGB(b.getSpecialEffects().getFogColor()));
|
||||||
|
|||||||
@@ -35,18 +35,17 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class SystemInfo {
|
public class SystemInfo {
|
||||||
private static final Map<String, Function<CarpetContext,Value>> options = new HashMap<String, Function<CarpetContext,Value>>(){{
|
private static final Map<String, Function<CarpetContext,Value>> options = new HashMap<>(){{
|
||||||
put("app_name", c ->
|
put("app_name", c ->
|
||||||
{
|
{
|
||||||
String name = c.host.getName();
|
String name = c.host.getName();
|
||||||
return name == null?Value.NULL:new StringValue(name);
|
return name == null?Value.NULL:new StringValue(name);
|
||||||
});
|
});
|
||||||
put("app_list", c -> ListValue.wrap(((CarpetScriptHost)c.host).scriptServer().modules.keySet().stream().filter(Objects::nonNull).map(StringValue::new).collect(Collectors.toList())));
|
put("app_list", c -> ListValue.wrap(((CarpetScriptHost)c.host).scriptServer().modules.keySet().stream().filter(Objects::nonNull).map(StringValue::new)));
|
||||||
put("app_scope", c -> StringValue.of((c.host).isPerUser()?"player":"global"));
|
put("app_scope", c -> StringValue.of((c.host).isPerUser()?"player":"global"));
|
||||||
put("app_players", c -> ListValue.wrap(c.host.getUserList().stream().map(StringValue::new).collect(Collectors.toList())));
|
put("app_players", c -> ListValue.wrap(c.host.getUserList().stream().map(StringValue::new)));
|
||||||
|
|
||||||
put("world_name", c -> new StringValue(c.server().getWorldData().getLevelName()));
|
put("world_name", c -> new StringValue(c.server().getWorldData().getLevelName()));
|
||||||
put("world_seed", c -> new NumericValue(c.level().getSeed()));
|
put("world_seed", c -> new NumericValue(c.level().getSeed()));
|
||||||
@@ -59,7 +58,7 @@ public class SystemInfo {
|
|||||||
String tlf = serverPath.getName(nodeCount-2).toString();
|
String tlf = serverPath.getName(nodeCount-2).toString();
|
||||||
return StringValue.of(tlf);
|
return StringValue.of(tlf);
|
||||||
});
|
});
|
||||||
put("world_dimensions", c -> ListValue.wrap(c.server().levelKeys().stream().map(k -> ValueConversions.of(k.location())).collect(Collectors.toList())));
|
put("world_dimensions", c -> ListValue.wrap(c.server().levelKeys().stream().map(k -> ValueConversions.of(k.location()))));
|
||||||
put("world_spawn_point", c -> {
|
put("world_spawn_point", c -> {
|
||||||
LevelData prop = c.server().overworld().getLevelData();
|
LevelData prop = c.server().overworld().getLevelData();
|
||||||
return ListValue.of(NumericValue.of(prop.getXSpawn()), NumericValue.of(prop.getYSpawn()), NumericValue.of(prop.getZSpawn()));
|
return ListValue.of(NumericValue.of(prop.getXSpawn()), NumericValue.of(prop.getYSpawn()), NumericValue.of(prop.getZSpawn()));
|
||||||
@@ -143,7 +142,7 @@ public class SystemInfo {
|
|||||||
final long[] tickArray = c.server().tickTimes;
|
final long[] tickArray = c.server().tickTimes;
|
||||||
for (int i=currentReportedTick+100; i > currentReportedTick; i--)
|
for (int i=currentReportedTick+100; i > currentReportedTick; i--)
|
||||||
{
|
{
|
||||||
ticks.add(new NumericValue(((double)tickArray[i % 100])/1000000.0));
|
ticks.add(new NumericValue((tickArray[i % 100])/1000000.0));
|
||||||
}
|
}
|
||||||
return ListValue.wrap(ticks);
|
return ListValue.wrap(ticks);
|
||||||
});
|
});
|
||||||
@@ -219,7 +218,7 @@ public class SystemInfo {
|
|||||||
}
|
}
|
||||||
public static Value getAll()
|
public static Value getAll()
|
||||||
{
|
{
|
||||||
return ListValue.wrap(options.keySet().stream().map(StringValue::of).collect(Collectors.toList()));
|
return ListValue.wrap(options.keySet().stream().map(StringValue::of));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -456,16 +456,16 @@ public class EntityValue extends Value
|
|||||||
put("type", (e, a) -> new StringValue(nameFromRegistryId(e.getLevel().registryAccess().registryOrThrow(Registries.ENTITY_TYPE).getKey(e.getType()))));
|
put("type", (e, a) -> new StringValue(nameFromRegistryId(e.getLevel().registryAccess().registryOrThrow(Registries.ENTITY_TYPE).getKey(e.getType()))));
|
||||||
put("is_riding", (e, a) -> BooleanValue.of(e.isPassenger()));
|
put("is_riding", (e, a) -> BooleanValue.of(e.isPassenger()));
|
||||||
put("is_ridden", (e, a) -> BooleanValue.of(e.isVehicle()));
|
put("is_ridden", (e, a) -> BooleanValue.of(e.isVehicle()));
|
||||||
put("passengers", (e, a) -> ListValue.wrap(e.getPassengers().stream().map(EntityValue::new).collect(Collectors.toList())));
|
put("passengers", (e, a) -> ListValue.wrap(e.getPassengers().stream().map(EntityValue::new)));
|
||||||
put("mount", (e, a) -> (e.getVehicle()!=null)?new EntityValue(e.getVehicle()):Value.NULL);
|
put("mount", (e, a) -> (e.getVehicle()!=null)?new EntityValue(e.getVehicle()):Value.NULL);
|
||||||
put("unmountable", (e, a) -> BooleanValue.of(((EntityInterface)e).isPermanentVehicle()));
|
put("unmountable", (e, a) -> BooleanValue.of(((EntityInterface)e).isPermanentVehicle()));
|
||||||
// deprecated
|
// deprecated
|
||||||
put("tags", (e, a) -> ListValue.wrap(e.getTags().stream().map(StringValue::new).collect(Collectors.toList())));
|
put("tags", (e, a) -> ListValue.wrap(e.getTags().stream().map(StringValue::new)));
|
||||||
|
|
||||||
put("scoreboard_tags", (e, a) -> ListValue.wrap(e.getTags().stream().map(StringValue::new).collect(Collectors.toList())));
|
put("scoreboard_tags", (e, a) -> ListValue.wrap(e.getTags().stream().map(StringValue::new)));
|
||||||
put("entity_tags", (e, a) -> {
|
put("entity_tags", (e, a) -> {
|
||||||
EntityType<?> type = e.getType();
|
EntityType<?> type = e.getType();
|
||||||
return ListValue.wrap(e.getServer().registryAccess().registryOrThrow(Registries.ENTITY_TYPE).getTags().filter(entry -> entry.getSecond().stream().anyMatch(h -> h.value()==type)).map(entry -> ValueConversions.of(entry.getFirst())).collect(Collectors.toList()));
|
return ListValue.wrap(e.getServer().registryAccess().registryOrThrow(Registries.ENTITY_TYPE).getTags().filter(entry -> entry.getSecond().stream().anyMatch(h -> h.value()==type)).map(entry -> ValueConversions.of(entry.getFirst())));
|
||||||
});
|
});
|
||||||
// deprecated
|
// deprecated
|
||||||
put("has_tag", (e, a) -> BooleanValue.of(e.getTags().contains(a.getString())));
|
put("has_tag", (e, a) -> BooleanValue.of(e.getTags().contains(a.getString())));
|
||||||
@@ -558,7 +558,7 @@ public class EntityValue extends Value
|
|||||||
put("home", (e, a) -> {
|
put("home", (e, a) -> {
|
||||||
if (e instanceof Mob)
|
if (e instanceof Mob)
|
||||||
{
|
{
|
||||||
return (((Mob) e).getRestrictRadius () > 0)?new BlockValue(null, (ServerLevel) e.getCommandSenderWorld(), ((PathfinderMob) e).getRestrictCenter()):Value.FALSE;
|
return (((Mob) e).getRestrictRadius () > 0)?new BlockValue(null, e.getCommandSenderWorld(), ((PathfinderMob) e).getRestrictCenter()):Value.FALSE;
|
||||||
}
|
}
|
||||||
return Value.NULL;
|
return Value.NULL;
|
||||||
});
|
});
|
||||||
@@ -840,7 +840,7 @@ public class EntityValue extends Value
|
|||||||
ServerPlayerInteractionManagerInterface manager = (ServerPlayerInteractionManagerInterface) (((ServerPlayer) e).gameMode);
|
ServerPlayerInteractionManagerInterface manager = (ServerPlayerInteractionManagerInterface) (((ServerPlayer) e).gameMode);
|
||||||
BlockPos pos = manager.getCurrentBreakingBlock();
|
BlockPos pos = manager.getCurrentBreakingBlock();
|
||||||
if (pos == null) return Value.NULL;
|
if (pos == null) return Value.NULL;
|
||||||
return new BlockValue(null, (ServerLevel) e.level, pos);
|
return new BlockValue(null, e.level, pos);
|
||||||
}
|
}
|
||||||
return Value.NULL;
|
return Value.NULL;
|
||||||
});
|
});
|
||||||
@@ -926,7 +926,7 @@ public class EntityValue extends Value
|
|||||||
switch (hitres.getType())
|
switch (hitres.getType())
|
||||||
{
|
{
|
||||||
case MISS: return Value.NULL;
|
case MISS: return Value.NULL;
|
||||||
case BLOCK: return new BlockValue(null, (ServerLevel) e.getCommandSenderWorld(), ((BlockHitResult)hitres).getBlockPos() );
|
case BLOCK: return new BlockValue(null, e.getCommandSenderWorld(), ((BlockHitResult)hitres).getBlockPos() );
|
||||||
case ENTITY: return new EntityValue(((EntityHitResult)hitres).getEntity());
|
case ENTITY: return new EntityValue(((EntityHitResult)hitres).getEntity());
|
||||||
}
|
}
|
||||||
return Value.NULL;
|
return Value.NULL;
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import java.util.Map;
|
|||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import net.minecraft.commands.arguments.NbtPathArgument;
|
import net.minecraft.commands.arguments.NbtPathArgument;
|
||||||
import net.minecraft.commands.arguments.item.ItemInput;
|
import net.minecraft.commands.arguments.item.ItemInput;
|
||||||
import net.minecraft.commands.arguments.item.ItemParser;
|
import net.minecraft.commands.arguments.item.ItemParser;
|
||||||
@@ -609,7 +608,7 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
|||||||
return Value.NULL;
|
return Value.NULL;
|
||||||
if (tags.size()==1 && !valString.endsWith("[]"))
|
if (tags.size()==1 && !valString.endsWith("[]"))
|
||||||
return NBTSerializableValue.decodeTag(tags.get(0));
|
return NBTSerializableValue.decodeTag(tags.get(0));
|
||||||
return ListValue.wrap(tags.stream().map(NBTSerializableValue::decodeTag).collect(Collectors.toList()));
|
return ListValue.wrap(tags.stream().map(NBTSerializableValue::decodeTag));
|
||||||
}
|
}
|
||||||
catch (CommandSyntaxException ignored) { }
|
catch (CommandSyntaxException ignored) { }
|
||||||
return Value.NULL;
|
return Value.NULL;
|
||||||
@@ -696,8 +695,7 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
|||||||
|
|
||||||
public static class IncompatibleTypeException extends RuntimeException
|
public static class IncompatibleTypeException extends RuntimeException
|
||||||
{
|
{
|
||||||
private IncompatibleTypeException() {}
|
public final Value val;
|
||||||
public Value val;
|
|
||||||
public IncompatibleTypeException(Value val)
|
public IncompatibleTypeException(Value val)
|
||||||
{
|
{
|
||||||
this.val = val;
|
this.val = val;
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import java.util.List;
|
|||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.regex.PatternSyntaxException;
|
import java.util.regex.PatternSyntaxException;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import net.minecraft.nbt.Tag;
|
import net.minecraft.nbt.Tag;
|
||||||
|
|
||||||
public abstract class Value implements Comparable<Value>, Cloneable
|
public abstract class Value implements Comparable<Value>, Cloneable
|
||||||
@@ -179,7 +178,7 @@ public abstract class Value implements Comparable<Value>, Cloneable
|
|||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return ListValue.wrap(Arrays.stream(getString().split(delimiter.getString())).map(StringValue::new).collect(Collectors.toList()));
|
return ListValue.wrap(Arrays.stream(getString().split(delimiter.getString())).map(StringValue::new));
|
||||||
}
|
}
|
||||||
catch (PatternSyntaxException pse)
|
catch (PatternSyntaxException pse)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -54,7 +54,6 @@ import java.util.Map;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.stream.StreamSupport;
|
import java.util.stream.StreamSupport;
|
||||||
|
|
||||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
@@ -274,12 +273,12 @@ public class ValueConversions
|
|||||||
}
|
}
|
||||||
if (v instanceof PositionTracker)
|
if (v instanceof PositionTracker)
|
||||||
{
|
{
|
||||||
return new BlockValue(null, (ServerLevel) e.getCommandSenderWorld(), ((PositionTracker)v).currentBlockPosition());
|
return new BlockValue(null, e.getCommandSenderWorld(), ((PositionTracker)v).currentBlockPosition());
|
||||||
}
|
}
|
||||||
if (v instanceof WalkTarget)
|
if (v instanceof WalkTarget)
|
||||||
{
|
{
|
||||||
return ListValue.of(
|
return ListValue.of(
|
||||||
new BlockValue(null, (ServerLevel) e.getCommandSenderWorld(), ((WalkTarget)v).getTarget().currentBlockPosition()),
|
new BlockValue(null, e.getCommandSenderWorld(), ((WalkTarget)v).getTarget().currentBlockPosition()),
|
||||||
new NumericValue(((WalkTarget) v).getSpeedModifier()),
|
new NumericValue(((WalkTarget) v).getSpeedModifier()),
|
||||||
new NumericValue(((WalkTarget) v).getCloseEnoughDist())
|
new NumericValue(((WalkTarget) v).getCloseEnoughDist())
|
||||||
);
|
);
|
||||||
@@ -297,11 +296,11 @@ public class ValueConversions
|
|||||||
Object el = l.get(0);
|
Object el = l.get(0);
|
||||||
if (el instanceof Entity)
|
if (el instanceof Entity)
|
||||||
{
|
{
|
||||||
return ListValue.wrap(l.stream().map(o -> new EntityValue((Entity)o)).collect(Collectors.toList()));
|
return ListValue.wrap(l.stream().map(o -> new EntityValue((Entity)o)));
|
||||||
}
|
}
|
||||||
if (el instanceof GlobalPos)
|
if (el instanceof GlobalPos)
|
||||||
{
|
{
|
||||||
return ListValue.wrap(l.stream().map(o -> of((GlobalPos) o)).collect(Collectors.toList()));
|
return ListValue.wrap(l.stream().map(o -> of((GlobalPos) o)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Value.NULL;
|
return Value.NULL;
|
||||||
@@ -480,7 +479,7 @@ public class ValueConversions
|
|||||||
if (o == null)
|
if (o == null)
|
||||||
return Value.NULL;
|
return Value.NULL;
|
||||||
if (o instanceof List)
|
if (o instanceof List)
|
||||||
return ListValue.wrap(((List<?>) o).stream().map(oo -> guess(serverWorld, oo)).collect(Collectors.toList()));
|
return ListValue.wrap(((List<?>) o).stream().map(oo -> guess(serverWorld, oo)));
|
||||||
if (o instanceof BlockPos)
|
if (o instanceof BlockPos)
|
||||||
return new BlockValue(null, serverWorld, (BlockPos)o);
|
return new BlockValue(null, serverWorld, (BlockPos)o);
|
||||||
if (o instanceof Entity)
|
if (o instanceof Entity)
|
||||||
|
|||||||
Reference in new issue
Block a user