Search in sources :

Example 11 with net.minecraft.server.v1_13_R2

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

the class NMSHandler method newEggItem.

@SuppressWarnings("deprecation")
@Override
public ItemStack newEggItem(final String entityID, final int amount, final String displayName) {
    Material spawnEgg = Material.matchMaterial(entityID.toUpperCase() + "_SPAWN_EGG");
    if (spawnEgg == null) {
        spawnEgg = Material.LEGACY_MONSTER_EGG;
    }
    final ItemStack item = new ItemStack(spawnEgg, amount);
    if (displayName != null) {
        final ItemMeta itemMeta = item.getItemMeta();
        itemMeta.setDisplayName(displayName);
        item.setItemMeta(itemMeta);
    }
    net.minecraft.server.v1_13_R2.ItemStack itemStack = null;
    final CraftItemStack craftStack = CraftItemStack.asCraftCopy(item);
    itemStack = CraftItemStack.asNMSCopy(craftStack);
    final NBTTagCompound tag = itemStack.getOrCreateTag();
    if (!tag.hasKey("SilkSpawners")) {
        tag.set("SilkSpawners", new NBTTagCompound());
    }
    tag.getCompound("SilkSpawners").setString("entity", entityID);
    if (!tag.hasKey("EntityTag")) {
        tag.set("EntityTag", new NBTTagCompound());
    }
    String prefixedEntity;
    if (!entityID.startsWith("minecraft:")) {
        prefixedEntity = "minecraft:" + entityID;
    } else {
        prefixedEntity = entityID;
    }
    tag.getCompound("EntityTag").setString("id", prefixedEntity);
    return CraftItemStack.asCraftMirror(itemStack);
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack) NBTTagCompound(net.minecraft.server.v1_13_R2.NBTTagCompound) Material(org.bukkit.Material) ItemStack(org.bukkit.inventory.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 12 with net.minecraft.server.v1_13_R2

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

the class NMSHandler method getSilkSpawnersNBTEntityID.

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

Aggregations

NBTTagCompound (net.minecraft.server.v1_13_R2.NBTTagCompound)5 CraftItemStack (org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack)5 net.minecraft.server.v1_13_R2 (net.minecraft.server.v1_13_R2)3 CraftEntity (org.bukkit.craftbukkit.v1_13_R2.entity.CraftEntity)3 CraftPlayer (org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer)3 Player (org.bukkit.entity.Player)3 Nullable (javax.annotation.Nullable)2 VoxelShape (net.minecraft.server.v1_13_R2.VoxelShape)2 ComplexCollisionBox (cc.funkemunky.api.utils.world.types.ComplexCollisionBox)1 SimpleCollisionBox (cc.funkemunky.api.utils.world.types.SimpleCollisionBox)1 PacketType (com.comphenix.protocol.PacketType)1 PacketContainer (com.comphenix.protocol.events.PacketContainer)1 ItemSlot (com.comphenix.protocol.wrappers.EnumWrappers.ItemSlot)1 InteractionVisualizer (com.loohp.interactionvisualizer.InteractionVisualizer)1 BlockPosition (com.loohp.interactionvisualizer.objectholders.BlockPosition)1 BoundingBox (com.loohp.interactionvisualizer.objectholders.BoundingBox)1 ChunkPosition (com.loohp.interactionvisualizer.objectholders.ChunkPosition)1 NMSTileEntitySet (com.loohp.interactionvisualizer.objectholders.NMSTileEntitySet)1 TileEntity (com.loohp.interactionvisualizer.objectholders.TileEntity)1 TileEntityType (com.loohp.interactionvisualizer.objectholders.TileEntity.TileEntityType)1