Search in sources :

Example 36 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_17_R1.inventory.CraftItemStack) Item(net.minecraft.world.item.Item) ResourceLocation(net.minecraft.resources.ResourceLocation) CompoundTag(net.minecraft.nbt.CompoundTag)

Example 37 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.world.item.ItemStack itemStack = null;
    final CraftItemStack craftStack = CraftItemStack.asCraftCopy(item);
    itemStack = CraftItemStack.asNMSCopy(craftStack);
    final CompoundTag tag = itemStack.getTag();
    if (tag == null || !tag.contains("SilkSpawners")) {
        return null;
    }
    return tag.getCompound("SilkSpawners").getString("entity");
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack) CompoundTag(net.minecraft.nbt.CompoundTag) Nullable(javax.annotation.Nullable)

Example 38 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_15_R1.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_15_R1.inventory.CraftItemStack) NBTTagCompound(net.minecraft.server.v1_15_R1.NBTTagCompound) Nullable(javax.annotation.Nullable)

Example 39 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_15_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;
    }
    return tag.getCompound("SilkSpawners").getString("entity");
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack) NBTTagCompound(net.minecraft.server.v1_15_R1.NBTTagCompound) Nullable(javax.annotation.Nullable)

Example 40 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_15_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_15_R1.inventory.CraftItemStack) NBTTagCompound(net.minecraft.server.v1_15_R1.NBTTagCompound) MinecraftKey(net.minecraft.server.v1_15_R1.MinecraftKey)

Aggregations

ItemStack (org.bukkit.inventory.ItemStack)35 Nullable (javax.annotation.Nullable)27 CraftItemStack (org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack)25 CraftItemStack (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack)20 CraftItemStack (org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack)17 CompoundTag (net.minecraft.nbt.CompoundTag)15 Material (org.bukkit.Material)14 Block (org.bukkit.block.Block)13 Field (java.lang.reflect.Field)11 SneakyThrows (lombok.SneakyThrows)11 ItemMeta (org.bukkit.inventory.meta.ItemMeta)10 Player (org.bukkit.entity.Player)9 BlockFace (org.bukkit.block.BlockFace)8 CraftItemStack (org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack)8 CraftItemStack (org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack)8 ArrayList (java.util.ArrayList)7 NBTTagCompound (net.minecraft.server.v1_8_R1.NBTTagCompound)7 CraftWorld (org.bukkit.craftbukkit.v1_16_R3.CraftWorld)7 CraftLivingEntity (org.bukkit.craftbukkit.v1_16_R3.entity.CraftLivingEntity)7 CraftItemStack (org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack)6