22w06a
This commit is contained in:
1 parent
695b569977
commit
212814f46d
27 files changed
+264
-144
No files matched your search
@@ -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