Search in sources :

Example 11 with MinecraftKey

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

the class NMSHandler method getMobNameOfSpawner.

@Override
public String getMobNameOfSpawner(final BlockState blockState) {
    final CraftCreatureSpawner spawner = (CraftCreatureSpawner) blockState;
    try {
        final TileEntityMobSpawner tile = (TileEntityMobSpawner) tileField.get(spawner);
        final MinecraftKey minecraftKey = tile.getSpawner().getMobName();
        return minecraftKey != null ? minecraftKey.getKey() : "";
    } catch (IllegalArgumentException | IllegalAccessException e) {
        Bukkit.getLogger().warning("[SilkSpawners] Reflection failed: " + e.getMessage());
        e.printStackTrace();
    }
    return "";
}
Also used : CraftCreatureSpawner(org.bukkit.craftbukkit.v1_13_R2.block.CraftCreatureSpawner) TileEntityMobSpawner(net.minecraft.server.v1_13_R2.TileEntityMobSpawner) MinecraftKey(net.minecraft.server.v1_13_R2.MinecraftKey)

Example 12 with MinecraftKey

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

the class NMSHandler method setSpawnersUnstackable.

@Override
public void setSpawnersUnstackable() {
    try {
        final Item spawner = IRegistry.ITEM.get(new MinecraftKey(NAMESPACED_SPAWNER_ID));
        final Field maxStackSize = Item.class.getDeclaredField("maxStackSize");
        maxStackSize.setAccessible(true);
        maxStackSize.set(spawner, 1);
    } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
        e.printStackTrace();
    }
}
Also used : Item(net.minecraft.server.v1_13_R2.Item) Field(java.lang.reflect.Field) MinecraftKey(net.minecraft.server.v1_13_R2.MinecraftKey)

Example 13 with MinecraftKey

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

the class NMSHandler method getVanillaEggNBTEntityID.

@Override
public String getVanillaEggNBTEntityID(final ItemStack item) {
    net.minecraft.server.v1_13_R2.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_13_R2.inventory.CraftItemStack) NBTTagCompound(net.minecraft.server.v1_13_R2.NBTTagCompound) MinecraftKey(net.minecraft.server.v1_13_R2.MinecraftKey)

Example 14 with MinecraftKey

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

the class NMSHandler method setSpawnersUnstackable.

@Override
public void setSpawnersUnstackable() {
    try {
        final Item spawner = IRegistry.ITEM.get(new MinecraftKey(NAMESPACED_SPAWNER_ID));
        final Field maxStackSize = Item.class.getDeclaredField("maxStackSize");
        maxStackSize.setAccessible(true);
        maxStackSize.set(spawner, 1);
    } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
        e.printStackTrace();
    }
}
Also used : Item(net.minecraft.server.v1_14_R1.Item) Field(java.lang.reflect.Field) MinecraftKey(net.minecraft.server.v1_14_R1.MinecraftKey)

Example 15 with MinecraftKey

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

the class NMSHandler method getMobNameOfSpawner.

@Override
public String getMobNameOfSpawner(final BlockState blockState) {
    final CraftCreatureSpawner spawner = (CraftCreatureSpawner) blockState;
    try {
        final TileEntityMobSpawner tile = (TileEntityMobSpawner) tileField.get(spawner);
        final MinecraftKey minecraftKey = tile.getSpawner().getMobName();
        return minecraftKey != null ? minecraftKey.getKey() : "";
    } catch (IllegalArgumentException | IllegalAccessException e) {
        Bukkit.getLogger().warning("[SilkSpawners] Reflection failed: " + e.getMessage());
        e.printStackTrace();
    }
    return "";
}
Also used : CraftCreatureSpawner(org.bukkit.craftbukkit.v1_15_R1.block.CraftCreatureSpawner) TileEntityMobSpawner(net.minecraft.server.v1_15_R1.TileEntityMobSpawner) MinecraftKey(net.minecraft.server.v1_15_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_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_12_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