Search in sources :

Example 26 with Chunk

use of net.minecraft.server.v1_16_R1.Chunk 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 27 with Chunk

use of net.minecraft.server.v1_16_R1.Chunk in project WildChests by BG-Software-LLC.

the class NMSAdapter_v1_8_R3 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.a((Entity) 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_8_R3.AxisAlignedBB) InventoryHolder(com.bgsoftware.wildchests.objects.inventory.InventoryHolder) DataInputStream(java.io.DataInputStream) NBTTagList(net.minecraft.server.v1_8_R3.NBTTagList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Item(org.bukkit.entity.Item) EntityHuman(net.minecraft.server.v1_8_R3.EntityHuman) EntityItem(net.minecraft.server.v1_8_R3.EntityItem) NBTTagCompound(net.minecraft.server.v1_8_R3.NBTTagCompound) Inventory(org.bukkit.inventory.Inventory) ArrayList(java.util.ArrayList) Effect(org.bukkit.Effect) Location(org.bukkit.Location) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) NBTCompressedStreamTools(net.minecraft.server.v1_8_R3.NBTCompressedStreamTools) CraftWorld(org.bukkit.craftbukkit.v1_8_R3.CraftWorld) BigInteger(java.math.BigInteger) ChestType(com.bgsoftware.wildchests.api.objects.ChestType) KeySet(com.bgsoftware.wildchests.key.KeySet) ItemStack(net.minecraft.server.v1_8_R3.ItemStack) CraftHumanEntity(org.bukkit.craftbukkit.v1_8_R3.entity.CraftHumanEntity) Material(org.bukkit.Material) CraftItemStack(org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack) HumanEntity(org.bukkit.entity.HumanEntity) DataOutput(java.io.DataOutput) TileEntityChest(net.minecraft.server.v1_8_R3.TileEntityChest) CraftChunk(org.bukkit.craftbukkit.v1_8_R3.CraftChunk) Collectors(java.util.stream.Collectors) World(net.minecraft.server.v1_8_R3.World) Base64(java.util.Base64) List(java.util.List) Stream(java.util.stream.Stream) Chunk(net.minecraft.server.v1_8_R3.Chunk) BlockPosition(net.minecraft.server.v1_8_R3.BlockPosition) AxisAlignedBB(net.minecraft.server.v1_8_R3.AxisAlignedBB) Entity(net.minecraft.server.v1_8_R3.Entity) CraftHumanEntity(org.bukkit.craftbukkit.v1_8_R3.entity.CraftHumanEntity) HumanEntity(org.bukkit.entity.HumanEntity) Entity(net.minecraft.server.v1_8_R3.Entity) Item(org.bukkit.entity.Item) EntityItem(net.minecraft.server.v1_8_R3.EntityItem) ArrayList(java.util.ArrayList) CraftWorld(org.bukkit.craftbukkit.v1_8_R3.CraftWorld) World(net.minecraft.server.v1_8_R3.World) CraftChunk(org.bukkit.craftbukkit.v1_8_R3.CraftChunk) Chunk(net.minecraft.server.v1_8_R3.Chunk) CraftWorld(org.bukkit.craftbukkit.v1_8_R3.CraftWorld) CraftChunk(org.bukkit.craftbukkit.v1_8_R3.CraftChunk) EntityItem(net.minecraft.server.v1_8_R3.EntityItem)

Example 28 with Chunk

use of net.minecraft.server.v1_16_R1.Chunk in project MechanicsMain by WeaponMechanics.

the class Block_1_15_R1 method getMultiBlockMaskPacket.

@Override
@NotNull
public List<Object> getMultiBlockMaskPacket(@NotNull List<Block> blocks, @Nullable BlockState mask) {
    if (blocks == null || blocks.isEmpty()) {
        throw new IllegalArgumentException("No blocks are being changed!");
    }
    Map<org.bukkit.Chunk, List<Block>> sortedBlocks = new HashMap<>();
    for (Block block : blocks) {
        List<Block> list = sortedBlocks.computeIfAbsent(block.getChunk(), chunk -> new ArrayList<>());
        list.add(block);
    }
    List<Object> packets = new ArrayList<>(sortedBlocks.size());
    IBlockData theMask = mask == null ? null : ((CraftBlockState) mask).getHandle();
    for (List<Block> entry : sortedBlocks.values()) {
        packets.add(getMultiBlockMaskPacket(entry, theMask));
    }
    return packets;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Chunk(net.minecraft.server.v1_15_R1.Chunk) CraftChunk(org.bukkit.craftbukkit.v1_15_R1.CraftChunk) IBlockData(net.minecraft.server.v1_15_R1.IBlockData) Block(org.bukkit.block.Block) ArrayList(java.util.ArrayList) List(java.util.List) NotNull(org.jetbrains.annotations.NotNull)

Example 29 with Chunk

use of net.minecraft.server.v1_16_R1.Chunk in project Movecraft by APDevTeam.

the class IWorldHandler method setBlockFast.

private void setBlockFast(@NotNull World world, @NotNull BlockPosition position, @NotNull IBlockData data) {
    Chunk chunk = world.getChunkAtWorldCoords(position);
    ChunkSection chunkSection = chunk.getSections()[position.getY() >> 4];
    if (chunkSection == null) {
        // Put a GLASS block to initialize the section. It will be replaced next with the real block.
        chunk.setType(position, Blocks.GLASS.getBlockData(), false);
        chunkSection = chunk.getSections()[position.getY() >> 4];
    }
    if (chunkSection.getType(position.getX() & 15, position.getY() & 15, position.getZ() & 15).equals(data)) {
        // Block is already of correct type and data, don't overwrite
        return;
    }
    chunkSection.setType(position.getX() & 15, position.getY() & 15, position.getZ() & 15, data);
    world.notify(position, data, data, 3);
    var engine = chunk.e();
    if (engine != null)
        engine.a(position);
    chunk.markDirty();
}
Also used : Chunk(net.minecraft.server.v1_14_R1.Chunk) ChunkSection(net.minecraft.server.v1_14_R1.ChunkSection)

Example 30 with Chunk

use of net.minecraft.server.v1_16_R1.Chunk in project Movecraft by APDevTeam.

the class IWorldHandler method setBlockFast.

private void setBlockFast(@NotNull World world, @NotNull BlockPosition position, @NotNull IBlockData data) {
    Chunk chunk = world.getChunkAtWorldCoords(position);
    ChunkSection chunkSection = chunk.getSections()[position.getY() >> 4];
    if (chunkSection == null) {
        // Put a GLASS block to initialize the section. It will be replaced next with the real block.
        chunk.setType(position, Blocks.GLASS.getBlockData(), false);
        chunkSection = chunk.getSections()[position.getY() >> 4];
    }
    if (chunkSection.getType(position.getX() & 15, position.getY() & 15, position.getZ() & 15).equals(data)) {
        // Block is already of correct type and data, don't overwrite
        return;
    }
    chunkSection.setType(position.getX() & 15, position.getY() & 15, position.getZ() & 15, data);
    world.notify(position, data, data, 3);
    var engine = chunk.e();
    if (engine != null)
        engine.a(position);
    chunk.markDirty();
}
Also used : Chunk(net.minecraft.server.v1_16_R3.Chunk) ChunkSection(net.minecraft.server.v1_16_R3.ChunkSection)

Aggregations

Location (org.bukkit.Location)13 ArrayList (java.util.ArrayList)11 List (java.util.List)11 HashMap (java.util.HashMap)10 WildLoadersPlugin (com.bgsoftware.wildloaders.WildLoadersPlugin)8 Hologram (com.bgsoftware.wildloaders.api.holograms.Hologram)8 ChunkLoader (com.bgsoftware.wildloaders.api.loaders.ChunkLoader)8 ChunkLoaderNPC (com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC)8 ITileEntityChunkLoader (com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader)8 WChunkLoader (com.bgsoftware.wildloaders.loaders.WChunkLoader)8 Collection (java.util.Collection)8 Collections (java.util.Collections)8 Map (java.util.Map)8 UUID (java.util.UUID)8 Chunk (net.minecraft.server.v1_16_R3.Chunk)8 GenericChunk (org.dynmap.common.chunk.GenericChunk)6 Chunk (net.minecraft.server.v1_15_R1.Chunk)4 DynmapChunk (org.dynmap.DynmapChunk)4 ChestType (com.bgsoftware.wildchests.api.objects.ChestType)3 KeySet (com.bgsoftware.wildchests.key.KeySet)3