Search in sources :

Example 16 with Item

use of net.minecraft.server.v1_16_R2.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 17 with Item

use of net.minecraft.server.v1_16_R2.Item in project RoseStacker by Rosewood-Development.

the class NMSHandlerImpl method updateEntityNameTagForPlayer.

@Override
public void updateEntityNameTagForPlayer(Player player, org.bukkit.entity.Entity entity, String customName, boolean customNameVisible) {
    try {
        List<Item<?>> dataWatchers = new ArrayList<>();
        Optional<IChatBaseComponent> nameComponent = Optional.ofNullable(CraftChatMessage.fromStringOrNull(customName));
        dataWatchers.add(new DataWatcher.Item<>(DataWatcherRegistry.f.a(2), nameComponent));
        dataWatchers.add(new DataWatcher.Item<>(DataWatcherRegistry.i.a(3), customNameVisible));
        PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata();
        field_PacketPlayOutEntityMetadata_a.set(packetPlayOutEntityMetadata, entity.getEntityId());
        field_PacketPlayOutEntityMetadata_b.set(packetPlayOutEntityMetadata, dataWatchers);
        ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityMetadata);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Item(net.minecraft.server.v1_16_R2.DataWatcher.Item) ArrayList(java.util.ArrayList) PacketPlayOutEntityMetadata(net.minecraft.server.v1_16_R2.PacketPlayOutEntityMetadata) IChatBaseComponent(net.minecraft.server.v1_16_R2.IChatBaseComponent) CraftPlayer(org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer) DataWatcher(net.minecraft.server.v1_16_R2.DataWatcher)

Example 18 with Item

use of net.minecraft.server.v1_16_R2.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 19 with Item

use of net.minecraft.server.v1_16_R2.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)

Example 20 with Item

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

the class NMSHandler method getSilkSpawnersNBTEntityID.

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

Aggregations

Item (org.orcid.jaxb.model.notification.permission_v2.Item)19 CraftItemStack (org.bukkit.craftbukkit.v1_16_R2.inventory.CraftItemStack)9 ItemStack (org.bukkit.inventory.ItemStack)9 Test (org.junit.Test)7 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)7 Field (java.lang.reflect.Field)6 Item (net.minecraft.server.v1_12_R1.Item)5 NBTTagCompound (net.minecraft.server.v1_16_R2.NBTTagCompound)5 Items (org.orcid.jaxb.model.notification.permission_v2.Items)5 CraftPlayer (org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer)4 ArrayList (java.util.ArrayList)3 Container (net.minecraft.server.v1_16_R2.Container)3 Font (java.awt.Font)2 Point (java.awt.Point)2 Nullable (javax.annotation.Nullable)2 Block (net.minecraft.server.v1_12_R1.Block)2 Item (net.minecraft.server.v1_13_R2.Item)2 Item (net.minecraft.server.v1_14_R1.Item)2 Item (net.minecraft.server.v1_15_R1.Item)2 ContainerAnvil (net.minecraft.server.v1_16_R2.ContainerAnvil)2