Search in sources :

Example 86 with ItemStack

use of net.minecraft.server.v1_14_R1.ItemStack 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_14_R1.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_14_R1.inventory.CraftItemStack) NBTTagCompound(net.minecraft.server.v1_14_R1.NBTTagCompound) Material(org.bukkit.Material) ItemStack(org.bukkit.inventory.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 87 with ItemStack

use of net.minecraft.server.v1_14_R1.ItemStack in project SilkSpawners by timbru31.

the class NMSHandler method getSilkSpawnersNBTEntityID.

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

Example 88 with ItemStack

use of net.minecraft.server.v1_14_R1.ItemStack in project SilkSpawners by timbru31.

the class NMSHandler method getVanillaNBTEntityID.

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

Example 89 with ItemStack

use of net.minecraft.server.v1_14_R1.ItemStack 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;
    }
    String prefixedEntity;
    if (!entity.startsWith("minecraft:")) {
        prefixedEntity = "minecraft:" + entity;
    } else {
        prefixedEntity = entity;
    }
    net.minecraft.server.v1_14_R1.ItemStack itemStack = null;
    final CraftItemStack craftStack = CraftItemStack.asCraftCopy(item);
    itemStack = CraftItemStack.asNMSCopy(craftStack);
    NBTTagCompound tag = itemStack.getOrCreateTag();
    // Check for SilkSpawners key
    if (!tag.hasKey("SilkSpawners")) {
        tag.set("SilkSpawners", new NBTTagCompound());
    }
    tag.getCompound("SilkSpawners").setString("entity", entity);
    // Check for Vanilla keys
    if (!tag.hasKey("BlockEntityTag")) {
        tag.set("BlockEntityTag", new NBTTagCompound());
    }
    tag = tag.getCompound("BlockEntityTag");
    // EntityId - Deprecated in 1.9
    tag.setString("EntityId", entity);
    tag.setString("id", TileEntityTypes.a(TileEntityTypes.MOB_SPAWNER).getKey());
    // SpawnData
    if (!tag.hasKey("SpawnData")) {
        tag.set("SpawnData", new NBTTagCompound());
    }
    tag.getCompound("SpawnData").setString("id", prefixedEntity);
    if (!tag.hasKey("SpawnPotentials")) {
        tag.set("SpawnPotentials", new NBTTagCompound());
    }
    // SpawnEgg data
    if (!tag.hasKey("EntityTag")) {
        tag.set("EntityTag", new NBTTagCompound());
    }
    tag.getCompound("EntityTag").setString("id", prefixedEntity);
    return CraftItemStack.asCraftMirror(itemStack);
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack) NBTTagCompound(net.minecraft.server.v1_14_R1.NBTTagCompound)

Example 90 with ItemStack

use of net.minecraft.server.v1_14_R1.ItemStack in project MyPet by xXKeyleXx.

the class EntityMyBlaze method handlePlayerInteraction.

public boolean handlePlayerInteraction(EntityHuman entityhuman) {
    if (super.handlePlayerInteraction(entityhuman)) {
        return true;
    }
    ItemStack itemStack = entityhuman.inventory.getItemInHand();
    if (getOwner().equals(entityhuman) && itemStack != null && canUseItem()) {
        if (getMyPet().isOnFire() && itemStack.getItem() == Items.GLASS_BOTTLE && itemStack.getData() == 0 && getOwner().getPlayer().isSneaking()) {
            getMyPet().setOnFire(false);
            makeSound("random.fizz", 1.0F, 1.0F);
            if (!entityhuman.abilities.canInstantlyBuild) {
                if (--itemStack.count <= 0) {
                    entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, new ItemStack(Items.GLASS_BOTTLE));
                } else {
                    if (!entityhuman.inventory.pickup(new ItemStack(Items.GLASS_BOTTLE))) {
                        entityhuman.drop(new ItemStack(Items.GLASS_BOTTLE), true);
                    }
                }
            }
            return true;
        } else if (!getMyPet().isOnFire() && itemStack.getItem() == Items.FLINT_AND_STEEL && getOwner().getPlayer().isSneaking()) {
            getMyPet().setOnFire(true);
            makeSound("fire.ignite", 1.0F, 1.0F);
            if (!entityhuman.abilities.canInstantlyBuild) {
                itemStack.damage(1, entityhuman);
            }
            return true;
        }
    }
    return false;
}
Also used : ItemStack(net.minecraft.server.v1_8_R3.ItemStack)

Aggregations

ItemStack (net.minecraft.server.v1_8_R3.ItemStack)26 ItemStack (net.minecraft.server.v1_12_R1.ItemStack)24 CraftItemStack (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack)20 ItemStack (net.minecraft.server.v1_16_R3.ItemStack)19 IconMenuItem (de.Keyle.MyPet.api.gui.IconMenuItem)18 CraftItemStack (org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack)17 CraftItemStack (org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack)16 ItemStack (net.minecraft.server.v1_11_R1.ItemStack)13 ItemStack (net.minecraft.server.v1_7_R4.ItemStack)12 NBTTagCompound (net.minecraft.server.v1_12_R1.NBTTagCompound)11 ItemStack (net.minecraft.server.v1_10_R1.ItemStack)10 NBTTagCompound (net.minecraft.server.v1_8_R3.NBTTagCompound)10 CraftItemStack (org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack)10 TagCompound (de.keyle.knbt.TagCompound)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 NBTTagCompound (net.minecraft.server.v1_16_R3.NBTTagCompound)9 Field (java.lang.reflect.Field)8 ItemStack (net.minecraft.server.v1_13_R2.ItemStack)8 ItemStack (net.minecraft.server.v1_15_R1.ItemStack)8 ItemStack (net.minecraft.server.v1_9_R2.ItemStack)8