22w06a
This commit is contained in:
1 parent
695b569977
commit
212814f46d
27 files changed
+264
-144
No files matched your search
@@ -64,16 +64,16 @@ import net.minecraft.network.protocol.game.ClientboundSetActionBarTextPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundSetSubtitleTextPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundSetTitleTextPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundSetTitlesAnimationPacket;
|
||||
import net.minecraft.resources.RegistryReadOps;
|
||||
//import net.minecraft.resources.RegistryReadOps;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.ServerResources;
|
||||
//import net.minecraft.server.ServerResources;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.packs.repository.Pack;
|
||||
import net.minecraft.server.packs.repository.PackRepository;
|
||||
import net.minecraft.server.packs.resources.SimpleReloadableResourceManager;
|
||||
//import net.minecraft.server.packs.resources.SimpleReloadableResourceManager;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.stats.Stat;
|
||||
import net.minecraft.stats.StatType;
|
||||
@@ -1102,6 +1102,8 @@ public class Auxiliary {
|
||||
});
|
||||
|
||||
expression.addContextFunction("enable_hidden_dimensions", 0, (c, t, lv) -> {
|
||||
return Value.NULL;
|
||||
/*
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
// from minecraft.server.Main.main
|
||||
MinecraftServer server = cc.s.getServer();
|
||||
@@ -1147,6 +1149,8 @@ public class Auxiliary {
|
||||
}
|
||||
}
|
||||
return ListValue.wrap(addeds);
|
||||
|
||||
*/
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import carpet.fakes.IngredientInterface;
|
||||
import carpet.fakes.RecipeManagerInterface;
|
||||
import carpet.script.CarpetContext;
|
||||
import carpet.script.Expression;
|
||||
import carpet.script.argument.BlockArgument;
|
||||
import carpet.script.argument.FunctionArgument;
|
||||
import carpet.script.exception.InternalExpressionException;
|
||||
import carpet.script.exception.ThrowStatement;
|
||||
@@ -26,15 +27,17 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
import net.minecraft.commands.arguments.item.ItemInput;
|
||||
import net.minecraft.core.HolderSet;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.tags.TagContainer;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
@@ -48,6 +51,7 @@ import net.minecraft.world.item.crafting.RecipeType;
|
||||
import net.minecraft.world.item.crafting.ShapedRecipe;
|
||||
import net.minecraft.world.item.crafting.ShapelessRecipe;
|
||||
import net.minecraft.world.item.crafting.SingleItemRecipe;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
public class Inventories {
|
||||
@@ -68,16 +72,40 @@ public class Inventories {
|
||||
if (lv.size() == 0)
|
||||
return ListValue.wrap(Registry.ITEM.keySet().stream().map(ValueConversions::of).collect(Collectors.toList()));
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
TagContainer tagManager = cc.s.getServer().getTags();
|
||||
Registry<Item> items = cc.s.getServer().registryAccess().registryOrThrow(Registry.ITEM_REGISTRY);
|
||||
String tag = lv.get(0).getString();
|
||||
Optional<HolderSet.Named<Item>> itemTag = items.getTag(TagKey.create(Registry.ITEM_REGISTRY, InputValidator.identifierOf(tag)));
|
||||
if (itemTag.isEmpty()) return Value.NULL;
|
||||
return ListValue.wrap(itemTag.get().stream().map(b -> ValueConversions.of(items.getKey(b.value()))).collect(Collectors.toList()));
|
||||
/*
|
||||
TagContainer tagManager = cc.s.getServer(). getTags();
|
||||
String tag = lv.get(0).getString();
|
||||
net.minecraft.tags.Tag<Item> itemTag = tagManager.getOrEmpty(Registry.ITEM_REGISTRY).getTag(InputValidator.identifierOf(tag));
|
||||
if (itemTag == null) return Value.NULL;
|
||||
return ListValue.wrap(itemTag.getValues().stream().map(b -> ValueConversions.of(Registry.ITEM.getKey(b))).collect(Collectors.toList()));
|
||||
*/
|
||||
});
|
||||
|
||||
expression.addContextFunction("item_tags", -1, (c, t, lv) ->
|
||||
{
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
|
||||
Registry<Item> blocks = cc.s.getServer().registryAccess().registryOrThrow(Registry.ITEM_REGISTRY);
|
||||
if (lv.size() == 0)
|
||||
return ListValue.wrap(blocks.getTagNames().map(ValueConversions::of).collect(Collectors.toList()));
|
||||
Item item = NBTSerializableValue.parseItem(lv.get(0).getString()).getItem();
|
||||
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()));
|
||||
}
|
||||
String tag = lv.get(1).getString();
|
||||
Optional<HolderSet.Named<Item>> tagSet = blocks.getTag(TagKey.create(Registry.ITEM_REGISTRY, InputValidator.identifierOf(tag)));
|
||||
if (tagSet.isEmpty()) return Value.NULL;
|
||||
|
||||
//return BooleanValue.of(tagSet.get().contains(item.builtInRegistryHolder()));
|
||||
return BooleanValue.of(tagSet.get().stream().anyMatch(h -> h.value() == item));
|
||||
|
||||
/*
|
||||
TagContainer tagManager = cc.s.getServer().getTags();
|
||||
if (lv.size() == 0)
|
||||
return ListValue.wrap(tagManager.getOrEmpty(Registry.ITEM_REGISTRY).getAvailableTags().stream().map(ValueConversions::of).collect(Collectors.toList()));
|
||||
@@ -88,6 +116,7 @@ public class Inventories {
|
||||
net.minecraft.tags.Tag<Item> itemTag = tagManager.getOrEmpty(Registry.ITEM_REGISTRY).getTag(InputValidator.identifierOf(tag));
|
||||
if (itemTag == null) return Value.NULL;
|
||||
return BooleanValue.of(itemTag.contains(item));
|
||||
*/
|
||||
});
|
||||
|
||||
expression.addContextFunction("recipe_data", -1, (c, t, lv) ->
|
||||
|
||||
@@ -40,6 +40,14 @@ import carpet.utils.BlockInfo;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.longs.LongSet;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.HolderSet;
|
||||
import net.minecraft.core.QuartPos;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -56,11 +64,8 @@ import java.util.function.BiPredicate;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import net.minecraft.commands.arguments.item.ItemInput;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.QuartPos;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.network.protocol.game.ClientboundExplodePacket;
|
||||
@@ -70,7 +75,6 @@ import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.level.Ticket;
|
||||
import net.minecraft.server.level.TicketType;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.tags.TagContainer;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.util.SortedArraySet;
|
||||
import net.minecraft.world.Clearable;
|
||||
@@ -237,10 +241,10 @@ public class WorldAccess {
|
||||
|
||||
private static void BooYah(ChunkGenerator generator)
|
||||
{
|
||||
synchronized (generator)
|
||||
{
|
||||
((ChunkGeneratorInterface)generator).initStrongholds();
|
||||
}
|
||||
//synchronized (generator)
|
||||
//{
|
||||
// ((ChunkGeneratorInterface)generator).initStrongholds();
|
||||
//}
|
||||
}
|
||||
|
||||
public static void apply(Expression expression)
|
||||
@@ -1118,16 +1122,33 @@ public class WorldAccess {
|
||||
if (lv.size() == 0)
|
||||
return ListValue.wrap(Registry.BLOCK.keySet().stream().map(ValueConversions::of).collect(Collectors.toList()));
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
TagContainer tagManager = cc.s.getServer().getTags();
|
||||
String tag = lv.get(0).getString();
|
||||
net.minecraft.tags.Tag<Block> blockTag = tagManager.getOrEmpty(Registry.BLOCK_REGISTRY).getTag(InputValidator.identifierOf(tag));
|
||||
if (blockTag == null) return Value.NULL;
|
||||
return ListValue.wrap(blockTag.getValues().stream().map(b -> ValueConversions.of(Registry.BLOCK.getKey(b))).collect(Collectors.toList()));
|
||||
ResourceLocation tag = InputValidator.identifierOf(lv.get(0).getString());
|
||||
|
||||
Registry<Block> blocks = cc.s.getServer().registryAccess().registryOrThrow(Registry.BLOCK_REGISTRY);
|
||||
Optional<HolderSet.Named<Block>> tagset = blocks.getTag(TagKey.create(Registry.BLOCK_REGISTRY, tag));
|
||||
if (tagset.isEmpty()) return Value.NULL;
|
||||
return ListValue.wrap(tagset.get().stream().map(b -> ValueConversions.of(blocks.getKey(b.value()))).collect(Collectors.toList()));
|
||||
});
|
||||
|
||||
expression.addContextFunction("block_tags", -1, (c, t, lv) ->
|
||||
{
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
Registry<Block> blocks = cc.s.getServer().registryAccess().registryOrThrow(Registry.BLOCK_REGISTRY);
|
||||
if (lv.size() == 0)
|
||||
return ListValue.wrap(blocks.getTagNames().map(ValueConversions::of).collect(Collectors.toList()));
|
||||
BlockArgument blockLocator = BlockArgument.findIn(cc, lv, 0, true);
|
||||
if (blockLocator.offset == lv.size())
|
||||
{
|
||||
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()));
|
||||
}
|
||||
String tag = lv.get(blockLocator.offset).getString();
|
||||
Optional<HolderSet.Named<Block>> tagSet = blocks.getTag(TagKey.create(Registry.BLOCK_REGISTRY, InputValidator.identifierOf(tag)));
|
||||
if (tagSet.isEmpty()) return Value.NULL;
|
||||
return BooleanValue.of(blockLocator.block.getBlockState().is(tagSet.get()));
|
||||
|
||||
|
||||
/* before
|
||||
TagContainer tagManager = cc.s.getServer().getTags();
|
||||
if (lv.size() == 0)
|
||||
return ListValue.wrap(tagManager.getOrEmpty(Registry.BLOCK_REGISTRY).getAvailableTags().stream().map(ValueConversions::of).collect(Collectors.toList()));
|
||||
@@ -1141,6 +1162,7 @@ public class WorldAccess {
|
||||
net.minecraft.tags.Tag<Block> blockTag = tagManager.getOrEmpty(Registry.BLOCK_REGISTRY).getTag(InputValidator.identifierOf(tag));
|
||||
if (blockTag == null) return Value.NULL;
|
||||
return BooleanValue.of(blockLocator.block.getBlockState().is(blockTag));
|
||||
*/
|
||||
});
|
||||
|
||||
expression.addContextFunction("biome", -1, (c, t, lv) -> {
|
||||
@@ -1181,7 +1203,7 @@ public class WorldAccess {
|
||||
Climate.quantizeCoord(numberGetOrThrow(depth)),
|
||||
Climate.quantizeCoord(numberGetOrThrow(weirdness))
|
||||
);
|
||||
biome = mnbs.getNoiseBiome(point);
|
||||
biome = mnbs.getNoiseBiome(point).value();
|
||||
ResourceLocation biomeId = cc.s.getServer().registryAccess().registryOrThrow(Registry.BIOME_REGISTRY).getKey(biome);
|
||||
return new StringValue(NBTSerializableValue.nameFromRegistryId(biomeId));
|
||||
}
|
||||
@@ -1196,7 +1218,7 @@ public class WorldAccess {
|
||||
else
|
||||
{
|
||||
BlockPos pos = locator.block.getPos();
|
||||
biome = world.getBiome(pos);
|
||||
biome = world.getBiome(pos).value();
|
||||
}
|
||||
// in locatebiome
|
||||
if (locator.offset == lv.size())
|
||||
@@ -1219,8 +1241,10 @@ public class WorldAccess {
|
||||
throw new InternalExpressionException("'set_biome' needs a biome name as an argument");
|
||||
String biomeName = lv.get(locator.offset+0).getString();
|
||||
// from locatebiome command code
|
||||
Biome biome = cc.s.getServer().registryAccess().registryOrThrow(Registry.BIOME_REGISTRY).getOptional(InputValidator.identifierOf(biomeName))
|
||||
Holder<Biome> biome = cc.s.getServer().registryAccess().registryOrThrow(Registry.BIOME_REGISTRY).getHolder(ResourceKey.create(Registry.BIOME_REGISTRY, InputValidator.identifierOf(biomeName)))
|
||||
.orElseThrow(() -> new ThrowStatement(biomeName, Throwables.UNKNOWN_BIOME));
|
||||
|
||||
|
||||
boolean doImmediateUpdate = true;
|
||||
if (lv.size() > locator.offset+1)
|
||||
{
|
||||
|
||||
@@ -128,7 +128,7 @@ public abstract class CommandArgument
|
||||
false
|
||||
),
|
||||
new VanillaUnconfigurableArgument( "blockpredicate", BlockPredicateArgument::blockPredicate,
|
||||
(c, p) -> ValueConversions.ofBlockPredicate(c.getSource().getServer().getTags(), BlockPredicateArgument.getBlockPredicate(c, p)), false
|
||||
(c, p) -> ValueConversions.ofBlockPredicate(c.getSource().getServer().registryAccess(), BlockPredicateArgument.getBlockPredicate(c, p)), false
|
||||
),
|
||||
new VanillaUnconfigurableArgument("teamcolor", ColorArgument::color,
|
||||
(c, p) -> {
|
||||
|
||||
@@ -8,19 +8,24 @@ import carpet.script.value.StringValue;
|
||||
import carpet.script.value.Value;
|
||||
import carpet.script.value.ValueConversions;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.HolderSet;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
|
||||
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
|
||||
|
||||
public class BiomeInfo
|
||||
{
|
||||
public final static Map<String, BiFunction<ServerLevel, Biome, Value>> biomeFeatures = new HashMap<String, BiFunction<ServerLevel, Biome, Value>>(){{
|
||||
//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("category", (w, b) -> StringValue.of(b.getBiomeCategory().getName()));
|
||||
put("category", (w, b) -> StringValue.of(Biome.getBiomeCategory(Holder.direct(b)).getName()));
|
||||
put("temperature", (w, b) -> NumericValue.of(b.getBaseTemperature()));
|
||||
put("fog_color", (w, b) -> ValueConversions.ofRGB(b.getSpecialEffects().getFogColor()));
|
||||
put("foliage_color", (w, b) -> ValueConversions.ofRGB(b.getSpecialEffects().getFoliageColorOverride().orElse(4764952))); // client Biome.getDefaultFoliageColor
|
||||
@@ -37,8 +42,8 @@ public class BiomeInfo
|
||||
return ListValue.wrap(
|
||||
b.getGenerationSettings().features().stream().map(step ->
|
||||
ListValue.wrap(step.stream().map(cfp ->
|
||||
ValueConversions.of(registry.getKey(((PlacedFeatureInterface)cfp.get()).getRawFeature()))
|
||||
))
|
||||
ValueConversions.of(registry.getKey(cfp.value().feature().value())))
|
||||
)
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
@@ -5,6 +5,7 @@ import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.MappedRegistry;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket;
|
||||
@@ -92,15 +93,15 @@ public class WorldTools
|
||||
long l = generatorOptions.seed();
|
||||
long m = BiomeManager.obfuscateSeed(l);
|
||||
List<CustomSpawner> list = List.of();
|
||||
MappedRegistry<LevelStem> simpleRegistry = generatorOptions.dimensions();
|
||||
Registry<LevelStem> simpleRegistry = generatorOptions.dimensions();
|
||||
LevelStem dimensionOptions = simpleRegistry.get(LevelStem.OVERWORLD);
|
||||
ChunkGenerator chunkGenerator2;
|
||||
DimensionType dimensionType2;
|
||||
Holder<DimensionType> dimensionType2;
|
||||
if (dimensionOptions == null) {
|
||||
dimensionType2 = server.registryAccess().ownedRegistryOrThrow(Registry.DIMENSION_TYPE_REGISTRY).getOrThrow(DimensionType.OVERWORLD_LOCATION);
|
||||
dimensionType2 = server.registryAccess().registryOrThrow(Registry.DIMENSION_TYPE_REGISTRY).getOrCreateHolder(DimensionType.OVERWORLD_LOCATION);;
|
||||
chunkGenerator2 = WorldGenSettings.makeDefaultOverworld(server.registryAccess(), (new Random()).nextLong());
|
||||
} else {
|
||||
dimensionType2 = dimensionOptions.type();
|
||||
dimensionType2 = dimensionOptions.typeHolder();
|
||||
chunkGenerator2 = dimensionOptions.generator();
|
||||
}
|
||||
|
||||
@@ -113,9 +114,9 @@ public class WorldTools
|
||||
// return server.getRegistryManager().get(Registry.CHUNK_GENERATOR_SETTINGS_KEY).getOrThrow(ChunkGeneratorSettings.OVERWORLD);
|
||||
//});
|
||||
|
||||
chunkGenerator2 = new NoiseBasedChunkGenerator(server.registryAccess().registryOrThrow(Registry.NOISE_REGISTRY), MultiNoiseBiomeSource.Preset.OVERWORLD.biomeSource(server.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY)), seed, () -> {
|
||||
return server.registryAccess().registryOrThrow(Registry.NOISE_GENERATOR_SETTINGS_REGISTRY).getOrThrow(NoiseGeneratorSettings.OVERWORLD);
|
||||
});
|
||||
chunkGenerator2 = new NoiseBasedChunkGenerator(server.registryAccess().registryOrThrow(Registry.NOISE_REGISTRY), MultiNoiseBiomeSource.Preset.OVERWORLD.biomeSource(server.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY)), seed,
|
||||
Holder.direct(server.registryAccess().registryOrThrow(Registry.NOISE_GENERATOR_SETTINGS_REGISTRY).getOrThrow(NoiseGeneratorSettings.OVERWORLD))
|
||||
);
|
||||
|
||||
ServerLevel serverWorld = new ServerLevel(
|
||||
server,
|
||||
|
||||
@@ -23,6 +23,8 @@ import net.minecraft.commands.arguments.selector.EntitySelector;
|
||||
import net.minecraft.commands.arguments.selector.EntitySelectorParser;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.HolderSet;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.StringTag;
|
||||
@@ -37,6 +39,7 @@ import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.tags.Tag;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.effect.MobEffect;
|
||||
@@ -247,11 +250,15 @@ public class EntityValue extends Value
|
||||
positive = false;
|
||||
who = who.substring(1);
|
||||
}
|
||||
Tag<EntityType<?>> eTag = server.getTags().getOrEmpty(Registry.ENTITY_TYPE_REGISTRY).getTag(InputValidator.identifierOf(who));
|
||||
if (eTag == null) throw new InternalExpressionException(who+" is not a valid entity descriptor");
|
||||
String booWho = who;
|
||||
HolderSet.Named<EntityType<?>> eTagValue = server.registryAccess().registryOrThrow(Registry.ENTITY_TYPE_REGISTRY)
|
||||
.getTag(TagKey.create(Registry.ENTITY_TYPE_REGISTRY, InputValidator.identifierOf(who)))
|
||||
.orElseThrow( () -> new InternalExpressionException(booWho+" is not a valid entity descriptor"));
|
||||
Set<EntityType<?>> eTag = eTagValue.stream().map(Holder::value).collect(Collectors.toUnmodifiableSet());
|
||||
//Tag<EntityType<?>> eTag = server.getTags().getOrEmpty(Registry.ENTITY_TYPE_REGISTRY).getTag(InputValidator.identifierOf(who));
|
||||
if (positive)
|
||||
{
|
||||
return new EntityClassDescriptor(null, e -> eTag.contains(e.getType()) && e.isAlive(), eTag.getValues().stream());
|
||||
return new EntityClassDescriptor(null, e -> eTag.contains(e.getType()) && e.isAlive(), eTag.stream());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -450,15 +457,22 @@ public class EntityValue extends Value
|
||||
put("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).collect(Collectors.toList())));
|
||||
put("entity_tags", (e, a) -> ListValue.wrap(e.getServer().getTags().getOrEmpty(Registry.ENTITY_TYPE_REGISTRY).getAllTags().entrySet().stream().filter(entry -> entry.getValue().contains(e.getType())).map(entry -> ValueConversions.of(entry.getKey())).collect(Collectors.toList())));
|
||||
put("entity_tags", (e, a) -> {
|
||||
EntityType<?> type = e.getType();
|
||||
return ListValue.wrap(e.getServer().registryAccess().registryOrThrow(Registry.ENTITY_TYPE_REGISTRY).getTags().filter(entry -> entry.getSecond().stream().anyMatch(h -> h.value()==type)).map(entry -> ValueConversions.of(entry.getFirst())).collect(Collectors.toList()));
|
||||
});
|
||||
// deprecated
|
||||
put("has_tag", (e, a) -> BooleanValue.of(e.getTags().contains(a.getString())));
|
||||
|
||||
put("has_scoreboard_tag", (e, a) -> BooleanValue.of(e.getTags().contains(a.getString())));
|
||||
put("has_entity_tag", (e, a) -> {
|
||||
Tag<EntityType<?>> tag = e.getServer().getTags().getOrEmpty(Registry.ENTITY_TYPE_REGISTRY).getTag(InputValidator.identifierOf(a.getString()));
|
||||
if (tag == null) return Value.NULL;
|
||||
return BooleanValue.of(e.getType().is(tag));
|
||||
Optional<HolderSet.Named<EntityType<?>>> tag = e.getServer().registryAccess().registryOrThrow(Registry.ENTITY_TYPE_REGISTRY).getTag(TagKey.create(Registry.ENTITY_TYPE_REGISTRY, InputValidator.identifierOf(a.getString())));
|
||||
if (tag.isEmpty()) return Value.NULL;
|
||||
//Tag<EntityType<?>> tag = e.getServer().getTags().getOrEmpty(Registry.ENTITY_TYPE_REGISTRY).getTag(InputValidator.identifierOf(a.getString()));
|
||||
//if (tag == null) return Value.NULL;
|
||||
//return BooleanValue.of(e.getType().is(tag));
|
||||
EntityType<?> type = e.getType();
|
||||
return BooleanValue.of(tag.get().stream().anyMatch(h -> h.value() == type));
|
||||
});
|
||||
|
||||
put("yaw", (e, a)-> new NumericValue(e.getYRot()));
|
||||
|
||||
@@ -9,6 +9,7 @@ import net.minecraft.advancements.critereon.MinMaxBounds;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.GlobalPos;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.core.Vec3i;
|
||||
import net.minecraft.core.particles.ParticleOptions;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
@@ -16,7 +17,7 @@ import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ColumnPos;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.tags.TagContainer;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.util.StringRepresentable;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
@@ -164,11 +165,13 @@ public class ValueConversions
|
||||
}
|
||||
}
|
||||
|
||||
public static Value of(ResourceKey<Level> dim)
|
||||
public static Value of(ResourceKey<?> dim)
|
||||
{
|
||||
return of(dim.location());
|
||||
}
|
||||
|
||||
public static Value of(TagKey<?> tagKey) { return of(tagKey.location()); }
|
||||
|
||||
public static Value of(ResourceLocation id)
|
||||
{
|
||||
if (id == null) // should be Value.NULL
|
||||
@@ -392,12 +395,12 @@ public class ValueConversions
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static Value ofBlockPredicate(TagContainer tagManager, Predicate<BlockInWorld> blockPredicate)
|
||||
public static Value ofBlockPredicate(RegistryAccess registryAccess, Predicate<BlockInWorld> blockPredicate)
|
||||
{
|
||||
BlockPredicateInterface predicateData = (BlockPredicateInterface) blockPredicate;
|
||||
return ListValue.of(
|
||||
predicateData.getCMBlockState()==null?Value.NULL:of(Registry.BLOCK.getKey(predicateData.getCMBlockState().getBlock())),
|
||||
predicateData.getCMBlockTag()==null?Value.NULL:of(tagManager.getOrEmpty(Registry.BLOCK_REGISTRY).getId(predicateData.getCMBlockTag())),
|
||||
predicateData.getCMBlockTagKey()==null?Value.NULL:of(registryAccess.registryOrThrow(Registry.BLOCK_REGISTRY).getTag(predicateData.getCMBlockTagKey()).get().key()),
|
||||
MapValue.wrap(predicateData.getCMProperties()),
|
||||
predicateData.getCMDataTag() == null?Value.NULL:new NBTSerializableValue(predicateData.getCMDataTag())
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user