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())));
}
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);
}
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);
}
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);
}
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());
}
Aggregations