Search in sources :

Example 46 with CraftChunk

use of org.bukkit.craftbukkit.v1_17_R1.CraftChunk in project WildLoaders by BG-Software-LLC.

the class NMSAdapter_v1_16_R3 method createLoader.

@Override
public ITileEntityChunkLoader createLoader(ChunkLoader chunkLoader) {
    Location loaderLoc = chunkLoader.getLocation();
    assert loaderLoc.getWorld() != null;
    WorldServer world = ((CraftWorld) loaderLoc.getWorld()).getHandle();
    BlockPosition blockPosition = new BlockPosition(loaderLoc.getX(), loaderLoc.getY(), loaderLoc.getZ());
    TileEntityChunkLoader tileEntityChunkLoader = new TileEntityChunkLoader(chunkLoader, world, blockPosition);
    world.tileEntityListTick.add(tileEntityChunkLoader);
    for (org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) {
        Chunk chunk = ((CraftChunk) bukkitChunk).getHandle();
        chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> ((TileEntityMobSpawner) tileEntity).getSpawner().requiredPlayerRange = -1);
        world.setForceLoaded(chunk.getPos().x, chunk.getPos().z, true);
    }
    return tileEntityChunkLoader;
}
Also used : NBTTagLong(net.minecraft.server.v1_16_R3.NBTTagLong) ChunkLoader(com.bgsoftware.wildloaders.api.loaders.ChunkLoader) Block(net.minecraft.server.v1_16_R3.Block) IBlockData(net.minecraft.server.v1_16_R3.IBlockData) TileEntityMobSpawner(net.minecraft.server.v1_16_R3.TileEntityMobSpawner) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) WChunkLoader(com.bgsoftware.wildloaders.loaders.WChunkLoader) Location(org.bukkit.Location) NBTTagCompound(net.minecraft.server.v1_16_R3.NBTTagCompound) Map(java.util.Map) WildLoadersPlugin(com.bgsoftware.wildloaders.WildLoadersPlugin) ITileEntityChunkLoader(com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader) Hologram(com.bgsoftware.wildloaders.api.holograms.Hologram) CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack) NBTTagList(net.minecraft.server.v1_16_R3.NBTTagList) TileEntity(net.minecraft.server.v1_16_R3.TileEntity) World(net.minecraft.server.v1_16_R3.World) NBTTagString(net.minecraft.server.v1_16_R3.NBTTagString) TileEntityTypes(net.minecraft.server.v1_16_R3.TileEntityTypes) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld) Collection(java.util.Collection) UUID(java.util.UUID) BlockPosition(net.minecraft.server.v1_16_R3.BlockPosition) ChunkCoordIntPair(net.minecraft.server.v1_16_R3.ChunkCoordIntPair) ITickable(net.minecraft.server.v1_16_R3.ITickable) ItemStack(net.minecraft.server.v1_16_R3.ItemStack) List(java.util.List) WorldServer(net.minecraft.server.v1_16_R3.WorldServer) CraftChunk(org.bukkit.craftbukkit.v1_16_R3.CraftChunk) Chunk(net.minecraft.server.v1_16_R3.Chunk) ChunkLoaderNPC(com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC) Collections(java.util.Collections) ITileEntityChunkLoader(com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader) BlockPosition(net.minecraft.server.v1_16_R3.BlockPosition) WorldServer(net.minecraft.server.v1_16_R3.WorldServer) TileEntityMobSpawner(net.minecraft.server.v1_16_R3.TileEntityMobSpawner) CraftChunk(org.bukkit.craftbukkit.v1_16_R3.CraftChunk) Chunk(net.minecraft.server.v1_16_R3.Chunk) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld) CraftChunk(org.bukkit.craftbukkit.v1_16_R3.CraftChunk) Location(org.bukkit.Location)

Example 47 with CraftChunk

use of org.bukkit.craftbukkit.v1_17_R1.CraftChunk 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 48 with CraftChunk

use of org.bukkit.craftbukkit.v1_17_R1.CraftChunk 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 49 with CraftChunk

use of org.bukkit.craftbukkit.v1_17_R1.CraftChunk in project InteractionVisualizer by LOOHP.

the class V1_11 method getTileEntities.

@Override
public NMSTileEntitySet<?, ?> getTileEntities(ChunkPosition chunk, boolean load) {
    if (!chunk.isLoaded() && !load) {
        return null;
    }
    World world = chunk.getWorld();
    return new NMSTileEntitySet<net.minecraft.server.v1_11_R1.BlockPosition, net.minecraft.server.v1_11_R1.TileEntity>(((CraftChunk) chunk.getChunk()).getHandle().tileEntities, entry -> {
        net.minecraft.server.v1_11_R1.BlockPosition pos = entry.getKey();
        Material type = CraftMagicNumbers.getMaterial(entry.getValue().getBlock());
        TileEntityType tileEntityType = TileEntity.getTileEntityType(type);
        if (tileEntityType != null) {
            return new TileEntity(world, pos.getX(), pos.getY(), pos.getZ(), tileEntityType);
        } else {
            return null;
        }
    });
}
Also used : TileEntity(com.loohp.interactionvisualizer.objectholders.TileEntity) TileEntityType(com.loohp.interactionvisualizer.objectholders.TileEntity.TileEntityType) Material(org.bukkit.Material) NMSTileEntitySet(com.loohp.interactionvisualizer.objectholders.NMSTileEntitySet) World(org.bukkit.World) CraftWorld(org.bukkit.craftbukkit.v1_11_R1.CraftWorld) CraftChunk(org.bukkit.craftbukkit.v1_11_R1.CraftChunk)

Example 50 with CraftChunk

use of org.bukkit.craftbukkit.v1_17_R1.CraftChunk in project InteractionVisualizer by LOOHP.

the class V1_12 method getTileEntities.

@Override
public NMSTileEntitySet<?, ?> getTileEntities(ChunkPosition chunk, boolean load) {
    if (!chunk.isLoaded() && !load) {
        return null;
    }
    World world = chunk.getWorld();
    return new NMSTileEntitySet<net.minecraft.server.v1_12_R1.BlockPosition, net.minecraft.server.v1_12_R1.TileEntity>(((CraftChunk) chunk.getChunk()).getHandle().tileEntities, entry -> {
        net.minecraft.server.v1_12_R1.BlockPosition pos = entry.getKey();
        Material type = CraftMagicNumbers.getMaterial(entry.getValue().getBlock());
        TileEntityType tileEntityType = TileEntity.getTileEntityType(type);
        if (tileEntityType != null) {
            return new TileEntity(world, pos.getX(), pos.getY(), pos.getZ(), tileEntityType);
        } else {
            return null;
        }
    });
}
Also used : TileEntity(com.loohp.interactionvisualizer.objectholders.TileEntity) TileEntityType(com.loohp.interactionvisualizer.objectholders.TileEntity.TileEntityType) Material(org.bukkit.Material) NMSTileEntitySet(com.loohp.interactionvisualizer.objectholders.NMSTileEntitySet) World(org.bukkit.World) CraftWorld(org.bukkit.craftbukkit.v1_12_R1.CraftWorld) CraftChunk(org.bukkit.craftbukkit.v1_12_R1.CraftChunk)

Aggregations

LevelChunk (net.minecraft.world.level.chunk.LevelChunk)17 Material (org.bukkit.Material)15 World (org.bukkit.World)13 NMSTileEntitySet (com.loohp.interactionvisualizer.objectholders.NMSTileEntitySet)12 TileEntity (com.loohp.interactionvisualizer.objectholders.TileEntity)12 TileEntityType (com.loohp.interactionvisualizer.objectholders.TileEntity.TileEntityType)12 BlockPos (net.minecraft.core.BlockPos)11 Location (org.bukkit.Location)11 ArrayList (java.util.ArrayList)9 List (java.util.List)9 CraftChunk (org.bukkit.craftbukkit.v1_17_R1.CraftChunk)9 CraftChunk (org.bukkit.craftbukkit.v1_18_R2.CraftChunk)9 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