Search in sources :

Example 91 with ItemStack

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

the class NMSHandler method getVanillaEggNBTEntityID.

@Override
public String getVanillaEggNBTEntityID(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("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_16_R2.inventory.CraftItemStack) NBTTagCompound(net.minecraft.server.v1_16_R2.NBTTagCompound) MinecraftKey(net.minecraft.server.v1_16_R2.MinecraftKey)

Example 92 with ItemStack

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

Example 93 with ItemStack

use of net.minecraft.server.v1_16_R2.ItemStack in project TheAPI by TheDevTec.

the class v1_16_R2 method openGUI.

@Override
public void openGUI(Player player, Object container, String legacy, int size, String title, ItemStack[] items) {
    EntityPlayer nmsPlayer = ((CraftPlayer) player).getHandle();
    int id = ((Container) container).windowId;
    net.minecraft.server.v1_16_R2.ItemStack[] nmsItems = new net.minecraft.server.v1_16_R2.ItemStack[items.length];
    for (int i = 0; i < items.length; ++i) {
        ItemStack is = items[i];
        if (is == null || is.getType() == Material.AIR)
            continue;
        net.minecraft.server.v1_16_R2.ItemStack item = null;
        ((Container) container).setItem(i, item = (net.minecraft.server.v1_16_R2.ItemStack) asNMSItem(is));
        nmsItems[i] = item;
    }
    BukkitLoader.getPacketHandler().send(player, packetOpenWindow(id, legacy, size, title));
    int i = 0;
    for (net.minecraft.server.v1_16_R2.ItemStack o : nmsItems) BukkitLoader.getPacketHandler().send(player, packetSetSlot(id, i++, o));
    nmsPlayer.activeContainer.transferTo((Container) container, (CraftPlayer) player);
    nmsPlayer.activeContainer = (Container) container;
    ((Container) container).addSlotListener(nmsPlayer);
    ((Container) container).checkReachable = false;
}
Also used : Container(net.minecraft.server.v1_16_R2.Container) CraftContainer(org.bukkit.craftbukkit.v1_16_R2.inventory.CraftContainer) EntityPlayer(net.minecraft.server.v1_16_R2.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer) CraftItemStack(org.bukkit.craftbukkit.v1_16_R2.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack)

Example 94 with ItemStack

use of net.minecraft.server.v1_16_R2.ItemStack in project TheAPI by TheDevTec.

the class v1_16_R2 method setGUITitle.

@Override
public void setGUITitle(Player player, Object container, String legacy, int size, String title) {
    EntityPlayer nmsPlayer = ((CraftPlayer) player).getHandle();
    int id = ((Container) container).windowId;
    NonNullList<net.minecraft.server.v1_16_R2.ItemStack> nmsItems = ((Container) container).items;
    BukkitLoader.getPacketHandler().send(player, packetOpenWindow(id, legacy, size, title));
    int i = 0;
    for (net.minecraft.server.v1_16_R2.ItemStack o : nmsItems) BukkitLoader.getPacketHandler().send(player, packetSetSlot(id, i++, o));
    nmsPlayer.activeContainer = (Container) container;
    ((Container) container).addSlotListener(nmsPlayer);
    ((Container) container).checkReachable = false;
}
Also used : Container(net.minecraft.server.v1_16_R2.Container) CraftContainer(org.bukkit.craftbukkit.v1_16_R2.inventory.CraftContainer) EntityPlayer(net.minecraft.server.v1_16_R2.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer) CraftItemStack(org.bukkit.craftbukkit.v1_16_R2.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack)

Example 95 with ItemStack

use of net.minecraft.server.v1_16_R2.ItemStack in project Panilla by ds58.

the class InventoryCleaner method clean.

@Override
public void clean(IPanillaPlayer player) {
    CraftPlayer craftPlayer = (CraftPlayer) player.getHandle();
    Container container = craftPlayer.getHandle().activeContainer;
    for (int slot = 0; slot < container.slots.size(); slot++) {
        ItemStack itemStack = container.getSlot(slot).getItem();
        if (itemStack == null || !itemStack.hasTag()) {
            continue;
        }
        NBTTagCompound nmsTag = itemStack.getTag();
        INbtTagCompound tag = new NbtTagCompound(nmsTag);
        String itemName = itemStack.getItem().getName();
        if (nmsTag == null || itemName == null) {
            continue;
        }
        FailedNbt failedNbt = NbtChecks.checkAll(tag, itemName, panilla);
        if (FailedNbt.failsThreshold(failedNbt)) {
            container.getSlot(slot).getItem().setTag(null);
        } else if (FailedNbt.fails(failedNbt)) {
            nmsTag.remove(failedNbt.key);
            container.getSlot(slot).getItem().setTag(nmsTag);
        }
    }
}
Also used : Container(net.minecraft.server.v1_16_R1.Container) INbtTagCompound(com.ruinscraft.panilla.api.nbt.INbtTagCompound) NbtTagCompound(com.ruinscraft.panilla.craftbukkit.v1_16_R1.nbt.NbtTagCompound) NBTTagCompound(net.minecraft.server.v1_16_R1.NBTTagCompound) CraftPlayer(org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer) INbtTagCompound(com.ruinscraft.panilla.api.nbt.INbtTagCompound) ItemStack(net.minecraft.server.v1_16_R1.ItemStack) FailedNbt(com.ruinscraft.panilla.api.exception.FailedNbt)

Aggregations

ItemStack (net.minecraft.server.v1_12_R1.ItemStack)28 ItemStack (net.minecraft.server.v1_8_R3.ItemStack)27 CraftItemStack (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack)21 ItemStack (net.minecraft.server.v1_16_R3.ItemStack)20 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 CraftItemStack (org.bukkit.craftbukkit.v1_16_R2.inventory.CraftItemStack)13 NBTTagCompound (net.minecraft.server.v1_12_R1.NBTTagCompound)12 ItemStack (net.minecraft.server.v1_7_R4.ItemStack)12 NBTTagCompound (net.minecraft.server.v1_8_R3.NBTTagCompound)11 ItemStack (net.minecraft.server.v1_10_R1.ItemStack)10 NBTTagCompound (net.minecraft.server.v1_16_R2.NBTTagCompound)10 NBTTagCompound (net.minecraft.server.v1_16_R3.NBTTagCompound)10 TagCompound (de.keyle.knbt.TagCompound)9 Field (java.lang.reflect.Field)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 ItemStack (net.minecraft.server.v1_13_R2.ItemStack)9 ItemStack (net.minecraft.server.v1_15_R1.ItemStack)9