Search in sources :

Example 21 with Item

use of net.minecraft.server.v1_11_R1.Item in project MechanicsMain by WeaponMechanics.

the class NonNullList_1_12_R1 method set.

@Override
public ItemStack set(int index, ItemStack newItem) {
    ItemStack oldItem = get(index);
    Item item = (Item) ReflectionUtil.invokeField(itemField, newItem);
    if (newItem.getCount() == 0 && item != null) {
        newItem.setCount(1);
        consumer.accept(CraftItemStack.asBukkitCopy(oldItem), CraftItemStack.asBukkitCopy(newItem), index);
        newItem.setCount(0);
    } else if (!ItemStack.matches(oldItem, newItem)) {
        consumer.accept(CraftItemStack.asBukkitCopy(oldItem), CraftItemStack.asBukkitCopy(newItem), index);
    }
    return super.set(index, newItem);
}
Also used : Item(net.minecraft.server.v1_12_R1.Item) CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack) ItemStack(net.minecraft.server.v1_12_R1.ItemStack)

Example 22 with Item

use of net.minecraft.server.v1_11_R1.Item in project SilkSpawners by timbru31.

the class NMSHandler method newEggItem.

@Override
public ItemStack newEggItem(final String entityID, final int amount, final String displayName) {
    final ItemStack item = new ItemStack(Material.MONSTER_EGG, amount);
    net.minecraft.server.v1_11_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);
    }
    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_11_R1.inventory.CraftItemStack) NBTTagCompound(net.minecraft.server.v1_11_R1.NBTTagCompound) CraftItemStack(org.bukkit.craftbukkit.v1_11_R1.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack)

Example 23 with Item

use of net.minecraft.server.v1_11_R1.Item in project SilkSpawners by timbru31.

the class NMSHandler method getSilkSpawnersNBTEntityID.

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

Example 24 with Item

use of net.minecraft.server.v1_11_R1.Item in project SilkSpawners by timbru31.

the class NMSHandler method setSpawnersUnstackable.

@Override
public void setSpawnersUnstackable() {
    try {
        final Item spawner = IRegistry.ITEM.get(new MinecraftKey(NAMESPACED_SPAWNER_ID));
        final Field maxStackSize = Item.class.getDeclaredField("maxStackSize");
        maxStackSize.setAccessible(true);
        maxStackSize.set(spawner, 1);
    } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
        e.printStackTrace();
    }
}
Also used : Item(net.minecraft.server.v1_13_R2.Item) Field(java.lang.reflect.Field) MinecraftKey(net.minecraft.server.v1_13_R2.MinecraftKey)

Example 25 with Item

use of net.minecraft.server.v1_11_R1.Item in project SilkSpawners by timbru31.

the class NMSHandler method setSpawnersUnstackable.

@Override
public void setSpawnersUnstackable() {
    try {
        final Item spawner = IRegistry.ITEM.get(new MinecraftKey(NAMESPACED_SPAWNER_ID));
        final Field maxStackSize = Item.class.getDeclaredField("maxStackSize");
        maxStackSize.setAccessible(true);
        maxStackSize.set(spawner, 1);
    } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
        e.printStackTrace();
    }
}
Also used : Item(net.minecraft.server.v1_14_R1.Item) Field(java.lang.reflect.Field) MinecraftKey(net.minecraft.server.v1_14_R1.MinecraftKey)

Aggregations

Item (org.orcid.jaxb.model.notification.permission_v2.Item)19 CraftItemStack (org.bukkit.craftbukkit.v1_11_R1.inventory.CraftItemStack)17 ItemStack (org.bukkit.inventory.ItemStack)13 NBTTagCompound (net.minecraft.server.v1_11_R1.NBTTagCompound)12 Test (org.junit.Test)7 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)7 Field (java.lang.reflect.Field)6 ItemStack (net.minecraft.server.v1_11_R1.ItemStack)5 Item (net.minecraft.server.v1_12_R1.Item)5 Items (org.orcid.jaxb.model.notification.permission_v2.Items)5 ArrayList (java.util.ArrayList)4 Container (net.minecraft.server.v1_11_R1.Container)3 NBTTagList (net.minecraft.server.v1_11_R1.NBTTagList)3 NBTTagString (net.minecraft.server.v1_11_R1.NBTTagString)3 ItemMeta (org.bukkit.inventory.meta.ItemMeta)3 CompoundTag (com.wasteofplastic.org.jnbt.CompoundTag)2 ListTag (com.wasteofplastic.org.jnbt.ListTag)2 StringTag (com.wasteofplastic.org.jnbt.StringTag)2 Tag (com.wasteofplastic.org.jnbt.Tag)2 IconMenuItem (de.Keyle.MyPet.api.gui.IconMenuItem)2