Search in sources :

Example 1 with CraftChunk

use of org.bukkit.craftbukkit.v1_19_R1.CraftChunk in project fairy by FairyProject.

the class CacheBlockSetHandler method setType.

public void setType(CacheBlockChange blockChange) {
    if (world.isChunkLoaded(blockChange.getX() >> 4, blockChange.getZ() >> 4)) {
        Chunk chunk = ((CraftChunk) world.getChunkAt(blockChange.getX() >> 4, blockChange.getZ() >> 4)).getHandle();
        final int combined = blockChange.getMaterial().getId() + (blockChange.getData() << 12);
        final IBlockData ibd = net.minecraft.server.v1_8_R3.Block.getByCombinedId(combined);
        int y = blockChange.getY().get(blockChange.getX(), blockChange.getZ(), chunk);
        BlockPosition blockPosition = new BlockPosition(blockChange.getX(), y, blockChange.getZ());
        chunk.a(blockPosition, ibd);
        chunk.world.notify(blockPosition);
        return;
    }
    long key = LongHash.toLong(blockChange.getX() >> 4, blockChange.getZ() >> 4);
    if (cachedChanges.containsKey(key)) {
        cachedChanges.get(key).add(blockChange);
        return;
    }
    CacheChunkChanges chunkChanges = new CacheChunkChanges();
    cachedChanges.put(key, chunkChanges);
    chunkChanges.add(blockChange);
}
Also used : IBlockData(net.minecraft.server.v1_8_R3.IBlockData) BlockPosition(net.minecraft.server.v1_8_R3.BlockPosition) CraftChunk(org.bukkit.craftbukkit.v1_8_R3.CraftChunk) Chunk(net.minecraft.server.v1_8_R3.Chunk) CraftChunk(org.bukkit.craftbukkit.v1_8_R3.CraftChunk)

Example 2 with CraftChunk

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

the class NMSAdapter_v1_16_R3 method removeLoader.

@Override
public void removeLoader(ChunkLoader chunkLoader, boolean spawnParticle) {
    Location loaderLoc = chunkLoader.getLocation();
    assert loaderLoc.getWorld() != null;
    WorldServer world = ((CraftWorld) loaderLoc.getWorld()).getHandle();
    BlockPosition blockPosition = new BlockPosition(loaderLoc.getX(), loaderLoc.getY(), loaderLoc.getZ());
    long tileEntityLong = ChunkCoordIntPair.pair(blockPosition.getX() >> 4, blockPosition.getZ() >> 4);
    TileEntityChunkLoader tileEntityChunkLoader = TileEntityChunkLoader.tileEntityChunkLoaderMap.remove(tileEntityLong);
    if (tileEntityChunkLoader != null) {
        tileEntityChunkLoader.holograms.forEach(EntityHolograms_v1_16_R3::removeHologram);
        tileEntityChunkLoader.removed = true;
        world.tileEntityListTick.remove(tileEntityChunkLoader);
    }
    if (spawnParticle)
        world.a(null, 2001, blockPosition, Block.getCombinedId(world.getType(blockPosition)));
    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 = 16);
        world.setForceLoaded(chunk.getPos().x, chunk.getPos().z, false);
    }
}
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) BlockPosition(net.minecraft.server.v1_16_R3.BlockPosition) WorldServer(net.minecraft.server.v1_16_R3.WorldServer) CraftChunk(org.bukkit.craftbukkit.v1_16_R3.CraftChunk) Chunk(net.minecraft.server.v1_16_R3.Chunk) ITileEntityChunkLoader(com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader) TileEntityMobSpawner(net.minecraft.server.v1_16_R3.TileEntityMobSpawner) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld) CraftChunk(org.bukkit.craftbukkit.v1_16_R3.CraftChunk) Location(org.bukkit.Location)

Example 3 with CraftChunk

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

the class NMSAdapter_v1_12_R1 method removeLoader.

@Override
public void removeLoader(ChunkLoader chunkLoader, boolean spawnParticle) {
    Location loaderLoc = chunkLoader.getLocation();
    World world = ((CraftWorld) loaderLoc.getWorld()).getHandle();
    BlockPosition blockPosition = new BlockPosition(loaderLoc.getX(), loaderLoc.getY(), loaderLoc.getZ());
    long tileEntityLong = LongHash.toLong(blockPosition.getX() >> 4, blockPosition.getZ() >> 4);
    TileEntityChunkLoader tileEntityChunkLoader = TileEntityChunkLoader.tileEntityChunkLoaderMap.remove(tileEntityLong);
    if (tileEntityChunkLoader != null) {
        tileEntityChunkLoader.holograms.forEach(EntityHolograms_v1_12_R1::removeHologram);
        tileEntityChunkLoader.removed = true;
        world.tileEntityListTick.remove(tileEntityChunkLoader);
    }
    if (spawnParticle)
        world.a(null, 2001, blockPosition, Block.getCombinedId(world.getType(blockPosition)));
    for (org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) {
        Chunk chunk = ((CraftChunk) bukkitChunk).getHandle();
        chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> {
            NBTTagCompound nbtTagCompound = new NBTTagCompound();
            tileEntity.save(nbtTagCompound);
            nbtTagCompound.setShort("RequiredPlayerRange", (short) 16);
            try {
                compoundLoadMethod.invoke(tileEntity, nbtTagCompound);
            } catch (Throwable ex) {
                tileEntity.a(nbtTagCompound);
            }
        });
    }
}
Also used : ChunkLoader(com.bgsoftware.wildloaders.api.loaders.ChunkLoader) TileEntityMobSpawner(net.minecraft.server.v1_12_R1.TileEntityMobSpawner) Block(net.minecraft.server.v1_12_R1.Block) NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound) HashMap(java.util.HashMap) NBTTagString(net.minecraft.server.v1_12_R1.NBTTagString) ArrayList(java.util.ArrayList) WChunkLoader(com.bgsoftware.wildloaders.loaders.WChunkLoader) TileEntity(net.minecraft.server.v1_12_R1.TileEntity) Chunk(net.minecraft.server.v1_12_R1.Chunk) World(net.minecraft.server.v1_12_R1.World) Location(org.bukkit.Location) NBTTagLong(net.minecraft.server.v1_12_R1.NBTTagLong) Map(java.util.Map) WildLoadersPlugin(com.bgsoftware.wildloaders.WildLoadersPlugin) ITileEntityChunkLoader(com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader) Method(java.lang.reflect.Method) Hologram(com.bgsoftware.wildloaders.api.holograms.Hologram) CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack) LongHash(org.bukkit.craftbukkit.v1_12_R1.util.LongHash) CraftChunk(org.bukkit.craftbukkit.v1_12_R1.CraftChunk) Collection(java.util.Collection) UUID(java.util.UUID) BlockPosition(net.minecraft.server.v1_12_R1.BlockPosition) NBTTagList(net.minecraft.server.v1_12_R1.NBTTagList) List(java.util.List) CraftWorld(org.bukkit.craftbukkit.v1_12_R1.CraftWorld) ITickable(net.minecraft.server.v1_12_R1.ITickable) ChunkLoaderNPC(com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC) Collections(java.util.Collections) ItemStack(net.minecraft.server.v1_12_R1.ItemStack) BlockPosition(net.minecraft.server.v1_12_R1.BlockPosition) NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound) 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) ITileEntityChunkLoader(com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader) TileEntityMobSpawner(net.minecraft.server.v1_12_R1.TileEntityMobSpawner) CraftWorld(org.bukkit.craftbukkit.v1_12_R1.CraftWorld) CraftChunk(org.bukkit.craftbukkit.v1_12_R1.CraftChunk) Location(org.bukkit.Location)

Example 4 with CraftChunk

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

the class NMSAdapter_v1_8_R3 method createLoader.

@Override
public ITileEntityChunkLoader createLoader(ChunkLoader chunkLoader) {
    Location loaderLoc = chunkLoader.getLocation();
    World world = ((CraftWorld) loaderLoc.getWorld()).getHandle();
    BlockPosition blockPosition = new BlockPosition(loaderLoc.getX(), loaderLoc.getY(), loaderLoc.getZ());
    TileEntityChunkLoader tileEntityChunkLoader = new TileEntityChunkLoader(chunkLoader, world, blockPosition);
    world.tileEntityList.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 -> {
            NBTTagCompound nbtTagCompound = new NBTTagCompound();
            tileEntity.b(nbtTagCompound);
            nbtTagCompound.setShort("RequiredPlayerRange", (short) -1);
            tileEntity.a(nbtTagCompound);
        });
    }
    return tileEntityChunkLoader;
}
Also used : ChunkLoader(com.bgsoftware.wildloaders.api.loaders.ChunkLoader) NBTTagList(net.minecraft.server.v1_8_R3.NBTTagList) NBTTagCompound(net.minecraft.server.v1_8_R3.NBTTagCompound) HashMap(java.util.HashMap) IUpdatePlayerListBox(net.minecraft.server.v1_8_R3.IUpdatePlayerListBox) ArrayList(java.util.ArrayList) WChunkLoader(com.bgsoftware.wildloaders.loaders.WChunkLoader) Location(org.bukkit.Location) CraftWorld(org.bukkit.craftbukkit.v1_8_R3.CraftWorld) Map(java.util.Map) TileEntityMobSpawner(net.minecraft.server.v1_8_R3.TileEntityMobSpawner) WildLoadersPlugin(com.bgsoftware.wildloaders.WildLoadersPlugin) LongHash(org.bukkit.craftbukkit.v1_8_R3.util.LongHash) ITileEntityChunkLoader(com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader) ItemStack(net.minecraft.server.v1_8_R3.ItemStack) TileEntity(net.minecraft.server.v1_8_R3.TileEntity) Hologram(com.bgsoftware.wildloaders.api.holograms.Hologram) CraftItemStack(org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack) NBTTagLong(net.minecraft.server.v1_8_R3.NBTTagLong) CraftChunk(org.bukkit.craftbukkit.v1_8_R3.CraftChunk) Collection(java.util.Collection) UUID(java.util.UUID) Block(net.minecraft.server.v1_8_R3.Block) World(net.minecraft.server.v1_8_R3.World) List(java.util.List) Chunk(net.minecraft.server.v1_8_R3.Chunk) ChunkLoaderNPC(com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC) BlockPosition(net.minecraft.server.v1_8_R3.BlockPosition) Collections(java.util.Collections) NBTTagString(net.minecraft.server.v1_8_R3.NBTTagString) ITileEntityChunkLoader(com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader) BlockPosition(net.minecraft.server.v1_8_R3.BlockPosition) NBTTagCompound(net.minecraft.server.v1_8_R3.NBTTagCompound) TileEntityMobSpawner(net.minecraft.server.v1_8_R3.TileEntityMobSpawner) 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) Location(org.bukkit.Location)

Example 5 with CraftChunk

use of org.bukkit.craftbukkit.v1_19_R1.CraftChunk in project WildChests by BG-Software-LLC.

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

Aggregations

LevelChunk (net.minecraft.world.level.chunk.LevelChunk)17 Material (org.bukkit.Material)14 World (org.bukkit.World)12 NMSTileEntitySet (com.loohp.interactionvisualizer.objectholders.NMSTileEntitySet)11 TileEntity (com.loohp.interactionvisualizer.objectholders.TileEntity)11 TileEntityType (com.loohp.interactionvisualizer.objectholders.TileEntity.TileEntityType)11 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