SPIGOT-6738: Add entity type tags
This commit is contained in:
parent
1492826118
commit
d3cc412075
@ -75,11 +75,13 @@ import net.minecraft.server.players.JsonListEntry;
|
|||||||
import net.minecraft.server.players.PlayerList;
|
import net.minecraft.server.players.PlayerList;
|
||||||
import net.minecraft.tags.Tags;
|
import net.minecraft.tags.Tags;
|
||||||
import net.minecraft.tags.TagsBlock;
|
import net.minecraft.tags.TagsBlock;
|
||||||
|
import net.minecraft.tags.TagsEntity;
|
||||||
import net.minecraft.tags.TagsFluid;
|
import net.minecraft.tags.TagsFluid;
|
||||||
import net.minecraft.tags.TagsItem;
|
import net.minecraft.tags.TagsItem;
|
||||||
import net.minecraft.util.datafix.DataConverterRegistry;
|
import net.minecraft.util.datafix.DataConverterRegistry;
|
||||||
import net.minecraft.world.EnumDifficulty;
|
import net.minecraft.world.EnumDifficulty;
|
||||||
import net.minecraft.world.effect.MobEffects;
|
import net.minecraft.world.effect.MobEffects;
|
||||||
|
import net.minecraft.world.entity.EntityTypes;
|
||||||
import net.minecraft.world.entity.ai.village.VillageSiege;
|
import net.minecraft.world.entity.ai.village.VillageSiege;
|
||||||
import net.minecraft.world.entity.npc.MobSpawnerCat;
|
import net.minecraft.world.entity.npc.MobSpawnerCat;
|
||||||
import net.minecraft.world.entity.npc.MobSpawnerTrader;
|
import net.minecraft.world.entity.npc.MobSpawnerTrader;
|
||||||
@ -182,6 +184,7 @@ import org.bukkit.craftbukkit.potion.CraftPotionBrewer;
|
|||||||
import org.bukkit.craftbukkit.scheduler.CraftScheduler;
|
import org.bukkit.craftbukkit.scheduler.CraftScheduler;
|
||||||
import org.bukkit.craftbukkit.scoreboard.CraftScoreboardManager;
|
import org.bukkit.craftbukkit.scoreboard.CraftScoreboardManager;
|
||||||
import org.bukkit.craftbukkit.tag.CraftBlockTag;
|
import org.bukkit.craftbukkit.tag.CraftBlockTag;
|
||||||
|
import org.bukkit.craftbukkit.tag.CraftEntityTag;
|
||||||
import org.bukkit.craftbukkit.tag.CraftFluidTag;
|
import org.bukkit.craftbukkit.tag.CraftFluidTag;
|
||||||
import org.bukkit.craftbukkit.tag.CraftItemTag;
|
import org.bukkit.craftbukkit.tag.CraftItemTag;
|
||||||
import org.bukkit.craftbukkit.util.CraftChatMessage;
|
import org.bukkit.craftbukkit.util.CraftChatMessage;
|
||||||
@ -2112,6 +2115,10 @@ public final class CraftServer implements Server {
|
|||||||
Preconditions.checkArgument(clazz == org.bukkit.Fluid.class, "Fluid namespace must have fluid type");
|
Preconditions.checkArgument(clazz == org.bukkit.Fluid.class, "Fluid namespace must have fluid type");
|
||||||
|
|
||||||
return (org.bukkit.Tag<T>) new CraftFluidTag(TagsFluid.a(), key);
|
return (org.bukkit.Tag<T>) new CraftFluidTag(TagsFluid.a(), key);
|
||||||
|
case org.bukkit.Tag.REGISTRY_ENTITY_TYPES:
|
||||||
|
Preconditions.checkArgument(clazz == org.bukkit.entity.EntityType.class, "Entity type namespace must have entity type");
|
||||||
|
|
||||||
|
return (org.bukkit.Tag<T>) new CraftEntityTag(TagsEntity.a(), key);
|
||||||
default:
|
default:
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
}
|
}
|
||||||
@ -2136,6 +2143,11 @@ public final class CraftServer implements Server {
|
|||||||
|
|
||||||
Tags<FluidType> fluidTags = TagsFluid.a();
|
Tags<FluidType> fluidTags = TagsFluid.a();
|
||||||
return fluidTags.a().keySet().stream().map(key -> (org.bukkit.Tag<T>) new CraftFluidTag(fluidTags, key)).collect(ImmutableList.toImmutableList());
|
return fluidTags.a().keySet().stream().map(key -> (org.bukkit.Tag<T>) new CraftFluidTag(fluidTags, key)).collect(ImmutableList.toImmutableList());
|
||||||
|
case org.bukkit.Tag.REGISTRY_ENTITY_TYPES:
|
||||||
|
Preconditions.checkArgument(clazz == org.bukkit.entity.EntityType.class, "Entity type namespace must have entity type");
|
||||||
|
|
||||||
|
Tags<EntityTypes<?>> entityTags = TagsEntity.a();
|
||||||
|
return entityTags.a().keySet().stream().map(key -> (org.bukkit.Tag<T>) new CraftEntityTag(entityTags, key)).collect(ImmutableList.toImmutableList());
|
||||||
default:
|
default:
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
}
|
}
|
||||||
|
29
src/main/java/org/bukkit/craftbukkit/tag/CraftEntityTag.java
Normal file
29
src/main/java/org/bukkit/craftbukkit/tag/CraftEntityTag.java
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package org.bukkit.craftbukkit.tag;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import net.minecraft.core.IRegistry;
|
||||||
|
import net.minecraft.resources.MinecraftKey;
|
||||||
|
import net.minecraft.tags.Tags;
|
||||||
|
import net.minecraft.world.entity.EntityTypes;
|
||||||
|
import org.bukkit.Registry;
|
||||||
|
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
|
|
||||||
|
public class CraftEntityTag extends CraftTag<EntityTypes<?>, EntityType> {
|
||||||
|
|
||||||
|
public CraftEntityTag(Tags<EntityTypes<?>> registry, MinecraftKey tag) {
|
||||||
|
super(registry, tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isTagged(EntityType entity) {
|
||||||
|
return getHandle().isTagged(IRegistry.ENTITY_TYPE.get(CraftNamespacedKey.toMinecraft(entity.getKey())));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<EntityType> getValues() {
|
||||||
|
return Collections.unmodifiableSet(getHandle().getTagged().stream().map((nms) -> Registry.ENTITY_TYPE.get(CraftNamespacedKey.fromMinecraft(EntityTypes.getName(nms)))).collect(Collectors.toSet()));
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user