Search in sources :

Example 81 with CraftItemStack

use of org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack in project SilkSpawners by timbru31.

the class NMSHandler method getVanillaEggNBTEntityID.

@Override
public String getVanillaEggNBTEntityID(final ItemStack item) {
    net.minecraft.world.item.ItemStack itemStack = null;
    final CraftItemStack craftStack = CraftItemStack.asCraftCopy(item);
    itemStack = CraftItemStack.asNMSCopy(craftStack);
    CompoundTag tag = itemStack.getTag();
    if (tag == null || !tag.contains("EntityTag")) {
        final Registry<Item> itemRegistry = Registry.ITEM;
        final ResourceLocation vanillaKey = itemRegistry.getKey(itemStack.getItem());
        if (vanillaKey != null) {
            return vanillaKey.getPath().replace("minecraft:", "").replace("_spawn_egg", "");
        }
    } else {
        tag = tag.getCompound("EntityTag");
        if (tag.contains("id")) {
            return tag.getString("id").replace("minecraft:", "");
        }
    }
    return null;
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack) Item(net.minecraft.world.item.Item) ResourceLocation(net.minecraft.resources.ResourceLocation) CompoundTag(net.minecraft.nbt.CompoundTag)

Example 82 with CraftItemStack

use of org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack in project SilkSpawners by timbru31.

the class NMSHandler method setNBTEntityID.

@Override
public ItemStack setNBTEntityID(final ItemStack item, final String entity) {
    if (item == null || StringUtils.isBlank(entity)) {
        Bukkit.getLogger().warning("[SilkSpawners] Skipping invalid spawner to set NBT data on.");
        return null;
    }
    net.minecraft.server.v1_8_R3.ItemStack itemStack = null;
    final CraftItemStack craftStack = CraftItemStack.asCraftCopy(item);
    itemStack = CraftItemStack.asNMSCopy(craftStack);
    NBTTagCompound tag = itemStack.getTag();
    if (tag == null) {
        tag = new NBTTagCompound();
        itemStack.setTag(tag);
    }
    if (!tag.hasKey("SilkSpawners")) {
        tag.set("SilkSpawners", new NBTTagCompound());
    }
    tag.getCompound("SilkSpawners").setString("entity", entity);
    if (!tag.hasKey("BlockEntityTag")) {
        tag.set("BlockEntityTag", new NBTTagCompound());
    }
    tag.getCompound("BlockEntityTag").setString("EntityId", entity);
    return CraftItemStack.asCraftMirror(itemStack);
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack) NBTTagCompound(net.minecraft.server.v1_8_R3.NBTTagCompound)

Example 83 with CraftItemStack

use of org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack in project SilkSpawners by timbru31.

the class NMSHandler method newEggItem.

@Override
public ItemStack newEggItem(final String entityID, final int amount, final String displayName) {
    final ItemStack item = new ItemStack(Material.MONSTER_EGG, amount, this.entitiesMaps.get(entityID).shortValue());
    net.minecraft.server.v1_8_R3.ItemStack itemStack = null;
    final CraftItemStack craftStack = CraftItemStack.asCraftCopy(item);
    itemStack = CraftItemStack.asNMSCopy(craftStack);
    NBTTagCompound tag = itemStack.getTag();
    if (tag == null) {
        tag = new NBTTagCompound();
        itemStack.setTag(tag);
    }
    if (!tag.hasKey("SilkSpawners")) {
        tag.set("SilkSpawners", new NBTTagCompound());
    }
    tag.getCompound("SilkSpawners").setString("entity", entityID);
    if (!tag.hasKey("EntityTag")) {
        tag.set("EntityTag", new NBTTagCompound());
    }
    tag.getCompound("EntityTag").setString("id", entityID);
    return CraftItemStack.asCraftMirror(itemStack);
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack) NBTTagCompound(net.minecraft.server.v1_8_R3.NBTTagCompound) CraftItemStack(org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack)

Example 84 with CraftItemStack

use of org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack in project SilkSpawners by timbru31.

the class NMSHandler method setNBTEntityID.

@Override
public ItemStack setNBTEntityID(final ItemStack item, final String entity) {
    if (item == null || StringUtils.isBlank(entity)) {
        Bukkit.getLogger().warning("[SilkSpawners] Skipping invalid spawner to set NBT data on.");
        return null;
    }
    net.minecraft.server.v1_9_R2.ItemStack itemStack = null;
    final CraftItemStack craftStack = CraftItemStack.asCraftCopy(item);
    itemStack = CraftItemStack.asNMSCopy(craftStack);
    NBTTagCompound tag = itemStack.getTag();
    if (tag == null) {
        tag = new NBTTagCompound();
        itemStack.setTag(tag);
    }
    if (!tag.hasKey("SilkSpawners")) {
        tag.set("SilkSpawners", new NBTTagCompound());
    }
    tag.getCompound("SilkSpawners").setString("entity", entity);
    if (!tag.hasKey("BlockEntityTag")) {
        tag.set("BlockEntityTag", new NBTTagCompound());
    }
    tag.getCompound("BlockEntityTag").setString("EntityId", entity);
    if (!tag.hasKey("SpawnData")) {
        tag.set("SpawnData", new NBTTagCompound());
    }
    tag.getCompound("SpawnData").setString("id", entity);
    if (!tag.getCompound("BlockEntityTag").hasKey("SpawnData")) {
        tag.getCompound("BlockEntityTag").set("SpawnData", new NBTTagCompound());
    }
    tag.getCompound("BlockEntityTag").getCompound("SpawnData").setString("id", entity);
    if (!tag.getCompound("BlockEntityTag").hasKey("SpawnPotentials")) {
        tag.getCompound("BlockEntityTag").set("SpawnPotentials", new NBTTagCompound());
    }
    final NBTTagList tagList = new NBTTagList();
    final NBTTagCompound spawnPotentials = new NBTTagCompound();
    spawnPotentials.set("Entity", new NBTTagCompound());
    spawnPotentials.getCompound("Entity").setString("id", entity);
    spawnPotentials.setInt("Weight", 1);
    tagList.add(spawnPotentials);
    tag.getCompound("BlockEntityTag").set("SpawnPotentials", tagList);
    if (!tag.hasKey("EntityTag")) {
        tag.set("EntityTag", new NBTTagCompound());
    }
    tag.getCompound("EntityTag").setString("id", entity);
    return CraftItemStack.asCraftMirror(itemStack);
}
Also used : NBTTagList(net.minecraft.server.v1_9_R2.NBTTagList) CraftItemStack(org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack) NBTTagCompound(net.minecraft.server.v1_9_R2.NBTTagCompound)

Example 85 with CraftItemStack

use of org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack in project SilkSpawners by timbru31.

the class NMSHandler method getVanillaEggNBTEntityID.

@Override
public String getVanillaEggNBTEntityID(final ItemStack item) {
    net.minecraft.server.v1_9_R2.ItemStack itemStack = null;
    final CraftItemStack craftStack = CraftItemStack.asCraftCopy(item);
    itemStack = CraftItemStack.asNMSCopy(craftStack);
    NBTTagCompound tag = itemStack.getTag();
    if (tag == null || !tag.hasKey("EntityTag")) {
        return null;
    }
    tag = tag.getCompound("EntityTag");
    if (tag.hasKey("id")) {
        return tag.getString("id");
    }
    return null;
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack) NBTTagCompound(net.minecraft.server.v1_9_R2.NBTTagCompound)

Aggregations

Nullable (javax.annotation.Nullable)27 ItemStack (org.bukkit.inventory.ItemStack)19 CompoundTag (net.minecraft.nbt.CompoundTag)15 Material (org.bukkit.Material)9 CraftItemStack (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack)9 CraftItemStack (org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack)9 ItemMeta (org.bukkit.inventory.meta.ItemMeta)9 NBTTagCompound (net.minecraft.server.v1_8_R1.NBTTagCompound)8 CraftItemStack (org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack)6 CraftItemStack (org.bukkit.craftbukkit.v1_11_R1.inventory.CraftItemStack)6 CraftItemStack (org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack)6 CraftItemStack (org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack)6 CraftItemStack (org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack)6 CraftItemStack (org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack)6 NBTTagCompound (net.minecraft.server.v1_10_R1.NBTTagCompound)5 NBTTagCompound (net.minecraft.server.v1_11_R1.NBTTagCompound)5 NBTTagCompound (net.minecraft.server.v1_12_R1.NBTTagCompound)5 NBTTagCompound (net.minecraft.server.v1_13_R2.NBTTagCompound)5 NBTTagCompound (net.minecraft.server.v1_14_R1.NBTTagCompound)5 NBTTagCompound (net.minecraft.server.v1_15_R1.NBTTagCompound)5