Search in sources :

Example 31 with MinecraftKey

use of net.minecraft.server.v1_14_R1.MinecraftKey in project Citizens2 by CitizensDev.

the class NMSImpl method registerEntityClass.

@Override
public void registerEntityClass(Class<?> clazz) {
    if (ENTITY_REGISTRY == null)
        return;
    Class<?> search = clazz;
    while ((search = search.getSuperclass()) != null && Entity.class.isAssignableFrom(search)) {
        MinecraftKey key = ENTITY_REGISTRY.b(search);
        if (key == null)
            continue;
        int code = ENTITY_REGISTRY.a(search);
        ENTITY_REGISTRY.put(code, key, (Class<? extends Entity>) clazz);
        return;
    }
    throw new IllegalArgumentException("unable to find valid entity superclass for class " + clazz.toString());
}
Also used : PathEntity(net.minecraft.server.v1_12_R1.PathEntity) LivingEntity(org.bukkit.entity.LivingEntity) SkinnableEntity(net.citizensnpcs.npc.skin.SkinnableEntity) CraftEntity(org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity) Entity(net.minecraft.server.v1_12_R1.Entity) MinecraftKey(net.minecraft.server.v1_12_R1.MinecraftKey) PathPoint(net.minecraft.server.v1_12_R1.PathPoint)

Example 32 with MinecraftKey

use of net.minecraft.server.v1_14_R1.MinecraftKey in project RoseStacker by Rosewood-Development.

the class StackedSpawnerTileImpl method getSpawnedType.

@Override
public EntityType getSpawnedType() {
    MinecraftKey resourceLocation = MinecraftKey.a(this.spawnData.getEntity().getString("id"));
    if (resourceLocation != null) {
        NamespacedKey namespacedKey = CraftNamespacedKey.fromMinecraft(resourceLocation);
        EntityType entityType = this.fromKey(namespacedKey);
        if (entityType != null)
            return entityType;
    }
    return EntityType.PIG;
}
Also used : EntityType(org.bukkit.entity.EntityType) CraftNamespacedKey(org.bukkit.craftbukkit.v1_16_R2.util.CraftNamespacedKey) NamespacedKey(org.bukkit.NamespacedKey) MinecraftKey(net.minecraft.server.v1_16_R2.MinecraftKey)

Example 33 with MinecraftKey

use of net.minecraft.server.v1_14_R1.MinecraftKey in project SilkSpawners by timbru31.

the class NMSHandler method setMobNameOfSpawner.

@Override
public boolean setMobNameOfSpawner(final BlockState blockState, final String mobID) {
    // Prevent ResourceKeyInvalidException: Non [a-z0-9/._-] character in path of location
    final String safeMobID = caseFormatOf(mobID.replace(" ", "_")).to(CaseFormat.LOWER_UNDERSCORE, mobID.replace(" ", "_")).toLowerCase(Locale.ENGLISH);
    final CraftCreatureSpawner spawner = (CraftCreatureSpawner) blockState;
    try {
        final TileEntityMobSpawner tile = (TileEntityMobSpawner) tileField.get(spawner);
        tile.getSpawner().setMobName(new MinecraftKey(safeMobID));
        return true;
    } catch (IllegalArgumentException | IllegalAccessException e) {
        Bukkit.getLogger().warning("[SilkSpawners] Reflection failed: " + e.getMessage());
        e.printStackTrace();
    }
    return false;
}
Also used : CraftCreatureSpawner(org.bukkit.craftbukkit.v1_11_R1.block.CraftCreatureSpawner) TileEntityMobSpawner(net.minecraft.server.v1_11_R1.TileEntityMobSpawner) MinecraftKey(net.minecraft.server.v1_11_R1.MinecraftKey)

Example 34 with MinecraftKey

use of net.minecraft.server.v1_14_R1.MinecraftKey in project SilkSpawners by timbru31.

the class NMSHandler method legacyRawEntityMap.

@Override
public SortedMap<Integer, String> legacyRawEntityMap() {
    // This bypasses Bukkit's wrappers, so it works with mods
    try {
        // TODO Needs 1.11 source
        final Field field = EntityTypes.class.getDeclaredField("g");
        final Field field2 = EntityTypes.class.getDeclaredField("b");
        field.setAccessible(true);
        @SuppressWarnings("unchecked") final List<String> list = (List<String>) field.get(null);
        @SuppressWarnings("unchecked") final RegistryMaterials<MinecraftKey, Class<? extends Entity>> registry = (RegistryMaterials<MinecraftKey, Class<? extends Entity>>) field2.get(null);
        // For each entry in our name -- ID map but it into the sortedMap
        for (int entityID = 0; entityID < list.size(); entityID++) {
            final String displayName = list.get(entityID);
            if (displayName == null) {
                continue;
            }
            final Class<? extends Entity> entity = registry.getId(entityID);
            if (entity == null) {
                Bukkit.getLogger().severe("[SilkSpawners] Failed to dump entity map: entity is null, entityID: " + entityID);
                continue;
            }
            MinecraftKey minecraftKey = null;
            try {
                minecraftKey = registry.b(entity);
            } catch (@SuppressWarnings("unused") final ClassCastException e) {
                Bukkit.getLogger().severe("[SilkSpawners] Failed to dump entity map: entity is invalid, entityID: " + entityID);
                Bukkit.getLogger().severe("[SilkSpawners] Failed to dump entity map: entity is invalid, entity: " + entity.getSimpleName());
                continue;
            }
            if (minecraftKey == null) {
                Bukkit.getLogger().severe("[SilkSpawners] Failed to dump entity map: minecraftKey is null, entityID: " + entityID);
                Bukkit.getLogger().severe("[SilkSpawners] Failed to dump entity map: minecraftKey is null, entity: " + entity.getSimpleName());
                continue;
            }
            final String a = minecraftKey.a();
            sortedMap.put(entityID, a);
        }
    } catch (SecurityException | NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
        Bukkit.getLogger().severe("[SilkSpawners] Failed to dump entity map: " + e.getMessage());
        e.printStackTrace();
    }
    return sortedMap;
}
Also used : Entity(net.minecraft.server.v1_11_R1.Entity) RegistryMaterials(net.minecraft.server.v1_11_R1.RegistryMaterials) MinecraftKey(net.minecraft.server.v1_11_R1.MinecraftKey) Field(java.lang.reflect.Field) List(java.util.List)

Example 35 with MinecraftKey

use of net.minecraft.server.v1_14_R1.MinecraftKey in project SilkSpawners by timbru31.

the class NMSHandler method getVanillaEggNBTEntityID.

@Override
public String getVanillaEggNBTEntityID(final ItemStack item) {
    net.minecraft.server.v1_14_R1.ItemStack itemStack = null;
    final CraftItemStack craftStack = CraftItemStack.asCraftCopy(item);
    itemStack = CraftItemStack.asNMSCopy(craftStack);
    NBTTagCompound tag = itemStack.getTag();
    if (tag == null || !tag.hasKey("EntityTag")) {
        final MinecraftKey vanillaKey = IRegistry.ITEM.getKey(itemStack.getItem());
        if (vanillaKey != null) {
            return vanillaKey.getKey().replace("minecraft:", "").replace("_spawn_egg", "");
        }
    } else {
        tag = tag.getCompound("EntityTag");
        if (tag.hasKey("id")) {
            return tag.getString("id").replace("minecraft:", "");
        }
    }
    return null;
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack) NBTTagCompound(net.minecraft.server.v1_14_R1.NBTTagCompound) MinecraftKey(net.minecraft.server.v1_14_R1.MinecraftKey)

Aggregations

MinecraftKey (net.minecraft.server.v1_16_R3.MinecraftKey)9 Field (java.lang.reflect.Field)8 SkinnableEntity (net.citizensnpcs.npc.skin.SkinnableEntity)6 MinecraftKey (net.minecraft.server.v1_12_R1.MinecraftKey)6 MinecraftKey (net.minecraft.server.v1_15_R1.MinecraftKey)6 MinecraftKey (net.minecraft.server.v1_16_R2.MinecraftKey)6 LivingEntity (org.bukkit.entity.LivingEntity)6 MinecraftKey (net.minecraft.server.v1_13_R2.MinecraftKey)5 MinecraftKey (net.minecraft.server.v1_14_R1.MinecraftKey)5 MinecraftKey (net.minecraft.server.v1_11_R1.MinecraftKey)4 MinecraftKey (net.minecraft.server.v1_16_R1.MinecraftKey)4 NamespacedKey (org.bukkit.NamespacedKey)3 EntityType (org.bukkit.entity.EntityType)3 MobSpawningMethod (dev.rosewood.rosestacker.spawner.spawning.MobSpawningMethod)2 SpawnerStackSettings (dev.rosewood.rosestacker.stack.settings.SpawnerStackSettings)2 List (java.util.List)2 Entity (net.minecraft.server.v1_11_R1.Entity)2 TileEntityMobSpawner (net.minecraft.server.v1_11_R1.TileEntityMobSpawner)2 Entity (net.minecraft.server.v1_12_R1.Entity)2 TileEntityMobSpawner (net.minecraft.server.v1_12_R1.TileEntityMobSpawner)2