Search in sources :

Example 66 with Item

use of net.minecraft.server.v1_12_R1.Item in project WildChests by BG-Software-LLC.

the class NMSAdapter_v1_12_R1 method getNearbyItems.

@Override
public Stream<Item> getNearbyItems(Location location, int range, boolean onlyChunk, KeySet blacklisted, KeySet whitelisted) {
    World world = ((CraftWorld) location.getWorld()).getHandle();
    List<Entity> entityList = new ArrayList<>();
    if (onlyChunk) {
        Chunk chunk = ((CraftChunk) location.getChunk()).getHandle();
        for (int i = 0; i < chunk.entitySlices.length; i++) entityList.addAll(chunk.entitySlices[i]);
        entityList = entityList.stream().filter(entity -> entity instanceof EntityItem).collect(Collectors.toList());
    } else {
        AxisAlignedBB boundingBox = new AxisAlignedBB(location.getX() + range, location.getY() + range, location.getZ() + range, location.getX() - range, location.getY() - range, location.getZ() - range);
        entityList = world.getEntities(null, boundingBox, entity -> entity instanceof EntityItem);
    }
    return entityList.stream().map(entity -> (Item) entity.getBukkitEntity()).filter(item -> !blacklisted.contains(item.getItemStack()) && (whitelisted.isEmpty() || whitelisted.contains(item.getItemStack())));
}
Also used : AxisAlignedBB(net.minecraft.server.v1_12_R1.AxisAlignedBB) InventoryHolder(com.bgsoftware.wildchests.objects.inventory.InventoryHolder) DataInputStream(java.io.DataInputStream) TileEntityChest(net.minecraft.server.v1_12_R1.TileEntityChest) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Item(org.bukkit.entity.Item) NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound) AxisAlignedBB(net.minecraft.server.v1_12_R1.AxisAlignedBB) Inventory(org.bukkit.inventory.Inventory) ArrayList(java.util.ArrayList) Entity(net.minecraft.server.v1_12_R1.Entity) EntityHuman(net.minecraft.server.v1_12_R1.EntityHuman) Chunk(net.minecraft.server.v1_12_R1.Chunk) World(net.minecraft.server.v1_12_R1.World) Location(org.bukkit.Location) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) BigInteger(java.math.BigInteger) ChestType(com.bgsoftware.wildchests.api.objects.ChestType) KeySet(com.bgsoftware.wildchests.key.KeySet) Material(org.bukkit.Material) HumanEntity(org.bukkit.entity.HumanEntity) CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack) DataOutput(java.io.DataOutput) CraftChunk(org.bukkit.craftbukkit.v1_12_R1.CraftChunk) NBTCompressedStreamTools(net.minecraft.server.v1_12_R1.NBTCompressedStreamTools) BlockPosition(net.minecraft.server.v1_12_R1.BlockPosition) CraftHumanEntity(org.bukkit.craftbukkit.v1_12_R1.entity.CraftHumanEntity) Collectors(java.util.stream.Collectors) Particle(org.bukkit.Particle) NBTTagList(net.minecraft.server.v1_12_R1.NBTTagList) Base64(java.util.Base64) List(java.util.List) Stream(java.util.stream.Stream) CraftWorld(org.bukkit.craftbukkit.v1_12_R1.CraftWorld) EntityItem(net.minecraft.server.v1_12_R1.EntityItem) ItemStack(net.minecraft.server.v1_12_R1.ItemStack) Entity(net.minecraft.server.v1_12_R1.Entity) HumanEntity(org.bukkit.entity.HumanEntity) CraftHumanEntity(org.bukkit.craftbukkit.v1_12_R1.entity.CraftHumanEntity) Item(org.bukkit.entity.Item) EntityItem(net.minecraft.server.v1_12_R1.EntityItem) ArrayList(java.util.ArrayList) World(net.minecraft.server.v1_12_R1.World) CraftWorld(org.bukkit.craftbukkit.v1_12_R1.CraftWorld) Chunk(net.minecraft.server.v1_12_R1.Chunk) CraftChunk(org.bukkit.craftbukkit.v1_12_R1.CraftChunk) CraftWorld(org.bukkit.craftbukkit.v1_12_R1.CraftWorld) CraftChunk(org.bukkit.craftbukkit.v1_12_R1.CraftChunk) EntityItem(net.minecraft.server.v1_12_R1.EntityItem)

Example 67 with Item

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

the class NonNullList_1_11_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_11_R1.Item) CraftItemStack(org.bukkit.craftbukkit.v1_11_R1.inventory.CraftItemStack) ItemStack(net.minecraft.server.v1_11_R1.ItemStack)

Example 68 with Item

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

the class NonNullList_1_14_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_14_R1.Item) ItemStack(net.minecraft.server.v1_14_R1.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack)

Example 69 with Item

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

the class NonNullList_1_15_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_15_R1.Item) ItemStack(net.minecraft.server.v1_15_R1.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack)

Example 70 with Item

use of net.minecraft.server.v1_12_R1.Item in project custom-items-gradle by knokko.

the class CustomItemNBT method set.

/**
 * Changes the entire custom item nbt or initializes it (if the item didn't have
 * a custom nbt yet).
 *
 * @param name The name of the custom item that is to be represented by this item
 * @param lastExportTime The time at which the current .cis file was exported/generated
 * @param maxDurability The maximum durability of the custom item, or null if it's
 * an unbreakable tool or not a tool at all
 * @param boolRepresentation The boolean representation of the custom item
 *
 * @throws UnsupportedOperationException If this custom item nbt is read-only
 */
public void set(String name, long lastExportTime, Long maxDurability, BooleanRepresentation boolRepresentation) throws UnsupportedOperationException {
    assertWrite();
    NBTTagCompound nbt = getOrCreateOurNBT();
    nbt.setString(NAME, name);
    nbt.setLong(LAST_EXPORT_TIME, lastExportTime);
    if (maxDurability != null) {
        nbt.setLong(DURABILITY, maxDurability);
    }
    nbt.setByteArray(BOOL_REPRESENTATION, boolRepresentation.getAsBytes());
}
Also used : NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound)

Aggregations

CraftItemStack (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack)30 NBTTagCompound (net.minecraft.server.v1_12_R1.NBTTagCompound)27 ItemStack (org.bukkit.inventory.ItemStack)25 Item (org.orcid.jaxb.model.notification.permission_v2.Item)19 ItemMeta (org.bukkit.inventory.meta.ItemMeta)12 ArrayList (java.util.ArrayList)10 Player (org.bukkit.entity.Player)9 Field (java.lang.reflect.Field)7 PreparedStatement (java.sql.PreparedStatement)7 ItemStack (net.minecraft.server.v1_12_R1.ItemStack)7 Test (org.junit.Test)7 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)7 ResultSet (java.sql.ResultSet)6 SQLException (java.sql.SQLException)5 SimpleDateFormat (java.text.SimpleDateFormat)5 Date (java.util.Date)5 Item (net.minecraft.server.v1_12_R1.Item)5 NBTTagList (net.minecraft.server.v1_12_R1.NBTTagList)5 Location (org.bukkit.Location)5 OfflinePlayer (org.bukkit.OfflinePlayer)5