Search in sources :

Example 71 with CraftItemStack

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

the class NMSHandler method getVanillaNBTEntityID.

@Override
@Nullable
public String getVanillaNBTEntityID(final ItemStack item) {
    net.minecraft.server.v1_8_R1.ItemStack itemStack = null;
    final CraftItemStack craftStack = CraftItemStack.asCraftCopy(item);
    itemStack = CraftItemStack.asNMSCopy(craftStack);
    final NBTTagCompound tag = itemStack.getTag();
    if (tag == null || !tag.hasKey("BlockEntityTag")) {
        return null;
    }
    return tag.getCompound("BlockEntityTag").getString("EntityId");
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack) NBTTagCompound(net.minecraft.server.v1_8_R1.NBTTagCompound) Nullable(javax.annotation.Nullable)

Example 72 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_R1.ItemStack itemStack = null;
    final CraftItemStack craftStack = CraftItemStack.asCraftCopy(item);
    itemStack = CraftItemStack.asNMSCopy(craftStack);
    NBTTagCompound tag = itemStack.getTag();
    // Create tag if necessary
    if (tag == null) {
        tag = new NBTTagCompound();
        itemStack.setTag(tag);
    }
    // Check for SilkSpawners key
    if (!tag.hasKey("SilkSpawners")) {
        tag.set("SilkSpawners", new NBTTagCompound());
    }
    tag.getCompound("SilkSpawners").setString("entity", entity);
    // Check for Vanilla key
    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_R1.inventory.CraftItemStack) NBTTagCompound(net.minecraft.server.v1_8_R1.NBTTagCompound)

Example 73 with CraftItemStack

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

the class NMSHandler method getSilkSpawnersNBTEntityID.

@Override
@Nullable
public String getSilkSpawnersNBTEntityID(final ItemStack item) {
    net.minecraft.server.v1_8_R1.ItemStack itemStack = null;
    final CraftItemStack craftStack = CraftItemStack.asCraftCopy(item);
    itemStack = CraftItemStack.asNMSCopy(craftStack);
    final NBTTagCompound tag = itemStack.getTag();
    if (tag == null || !tag.hasKey("SilkSpawners")) {
        return null;
    }
    final NBTTagCompound silkSpawnersTag = tag.getCompound("SilkSpawners");
    if (silkSpawnersTag.hasKey("entity")) {
        return silkSpawnersTag.getString("entity");
    }
    if (silkSpawnersTag.hasKey("entityID")) {
        return getEntityFromNumericalID(silkSpawnersTag.getShort("entityID"));
    }
    return null;
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack) NBTTagCompound(net.minecraft.server.v1_8_R1.NBTTagCompound) Nullable(javax.annotation.Nullable)

Example 74 with CraftItemStack

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

the class NMSHandler method getVanillaNBTEntityID.

@Override
@Nullable
public String getVanillaNBTEntityID(final ItemStack item) {
    net.minecraft.server.v1_16_R2.ItemStack itemStack = null;
    final CraftItemStack craftStack = CraftItemStack.asCraftCopy(item);
    itemStack = CraftItemStack.asNMSCopy(craftStack);
    NBTTagCompound tag = itemStack.getTag();
    if (tag == null || !tag.hasKey("BlockEntityTag")) {
        return null;
    }
    tag = tag.getCompound("BlockEntityTag");
    if (tag.hasKey("EntityId")) {
        return tag.getString("EntityId");
    } else if (tag.hasKey("SpawnData") && tag.getCompound("SpawnData").hasKey("id")) {
        return tag.getCompound("SpawnData").getString("id");
    } else if (tag.hasKey("SpawnPotentials") && !tag.getList("SpawnPotentials", 8).isEmpty()) {
        return tag.getList("SpawnPotentials", 8).getCompound(0).getCompound("Entity").getString("id");
    } else {
        return null;
    }
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_16_R2.inventory.CraftItemStack) NBTTagCompound(net.minecraft.server.v1_16_R2.NBTTagCompound) Nullable(javax.annotation.Nullable)

Example 75 with CraftItemStack

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

the class NMSHandler method getSilkSpawnersNBTEntityID.

@Override
@Nullable
public String getSilkSpawnersNBTEntityID(final ItemStack item) {
    net.minecraft.server.v1_16_R3.ItemStack itemStack = null;
    final CraftItemStack craftStack = CraftItemStack.asCraftCopy(item);
    itemStack = CraftItemStack.asNMSCopy(craftStack);
    final NBTTagCompound tag = itemStack.getTag();
    if (tag == null || !tag.hasKey("SilkSpawners")) {
        return null;
    }
    return tag.getCompound("SilkSpawners").getString("entity");
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack) NBTTagCompound(net.minecraft.server.v1_16_R3.NBTTagCompound) Nullable(javax.annotation.Nullable)

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