Search in sources :

Example 36 with Chunk

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

use of net.minecraft.server.v1_8_R3.Chunk in project PGM by PGMDev.

the class NMSHacks method getBlocks.

static Set<org.bukkit.block.Block> getBlocks(Chunk bukkitChunk, Material material) {
    CraftChunk craftChunk = (CraftChunk) bukkitChunk;
    Set<org.bukkit.block.Block> blocks = new HashSet<>();
    net.minecraft.server.v1_8_R3.Block nmsBlock = CraftMagicNumbers.getBlock(material);
    net.minecraft.server.v1_8_R3.Chunk chunk = craftChunk.getHandle();
    for (ChunkSection section : chunk.getSections()) {
        // ChunkSection.a() -> true if section is empty
        if (section == null || section.a())
            continue;
        char[] blockIds = section.getIdArray();
        for (int i = 0; i < blockIds.length; i++) {
            // This does a lookup in the block registry, but does not create any objects, so should be
            // pretty efficient
            IBlockData blockData = (IBlockData) net.minecraft.server.v1_8_R3.Block.d.a(blockIds[i]);
            if (blockData != null && blockData.getBlock() == nmsBlock) {
                blocks.add(bukkitChunk.getBlock(i & 0xf, section.getYPosition() | (i >> 8), (i >> 4) & 0xf));
            }
        }
    }
    return blocks;
}
Also used : org.bukkit(org.bukkit) CraftBlock(org.bukkit.craftbukkit.v1_8_R3.block.CraftBlock) CraftChunk(org.bukkit.craftbukkit.v1_8_R3.CraftChunk) net.minecraft.server.v1_8_R3(net.minecraft.server.v1_8_R3)

Example 38 with Chunk

use of net.minecraft.server.v1_8_R3.Chunk in project PaperDev by Kamillaova.

the class ChunkIOProvider method callStage1.

// async stuff
public Chunk callStage1(QueuedChunk queuedChunk) throws RuntimeException {
    try (Timing ignored = queuedChunk.provider.world.timings.chunkIOStage1.startTimingIfSync()) {
        // Paper
        ChunkRegionLoader loader = queuedChunk.loader;
        Object[] data = loader.loadChunk(queuedChunk.world, queuedChunk.x, queuedChunk.z);
        if (data != null) {
            queuedChunk.compound = (NBTTagCompound) data[1];
            return (Chunk) data[0];
        }
        return null;
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    // Paper - Mirror vanilla by catching everything (else) rather than immediately crashing the server
    // stage2 will receive a null chunk and then load it synchronously, where vanilla MC will properly log and recover
    // stage2 will _not_ however return that instance, only load it
    } catch (Exception ex) {
        return null;
    }
}
Also used : Timing(co.aikar.timings.Timing) IOException(java.io.IOException) ChunkRegionLoader(net.minecraft.server.v1_12_R1.ChunkRegionLoader) Chunk(net.minecraft.server.v1_12_R1.Chunk) IOException(java.io.IOException)

Example 39 with Chunk

use of net.minecraft.server.v1_8_R3.Chunk in project PaperDev by Kamillaova.

the class ActivationRange method activateEntities.

/**
 * Find what entities are in range of the players in the world and set
 * active if in range.
 */
public static void activateEntities(World world) {
    MinecraftTimings.entityActivationCheckTimer.startTiming();
    final int miscActivationRange = world.spigotConfig.miscActivationRange;
    final int animalActivationRange = world.spigotConfig.animalActivationRange;
    final int monsterActivationRange = world.spigotConfig.monsterActivationRange;
    // Paper
    final int waterActivationRange = world.spigotConfig.waterActivationRange;
    int maxRange = Math.max(monsterActivationRange, animalActivationRange);
    maxRange = Math.max(maxRange, miscActivationRange);
    maxRange = Math.min((world.spigotConfig.viewDistance << 4) - 8, maxRange);
    // Paper
    Chunk chunk;
    for (EntityHuman player : world.players) {
        player.activatedTick = MinecraftServer.currentTick;
        maxBB = player.getBoundingBox().grow(maxRange, 256, maxRange);
        miscBB = player.getBoundingBox().grow(miscActivationRange, 256, miscActivationRange);
        animalBB = player.getBoundingBox().grow(animalActivationRange, 256, animalActivationRange);
        // Paper
        waterBB = player.getBoundingBox().grow(waterActivationRange, 256, waterActivationRange);
        monsterBB = player.getBoundingBox().grow(monsterActivationRange, 256, monsterActivationRange);
        int i = MathHelper.floor(maxBB.a / 16.0D);
        int j = MathHelper.floor(maxBB.d / 16.0D);
        int k = MathHelper.floor(maxBB.c / 16.0D);
        int l = MathHelper.floor(maxBB.f / 16.0D);
        for (int i1 = i; i1 <= j; ++i1) {
            for (int j1 = k; j1 <= l; ++j1) {
                if (// Paper
                (chunk = MCUtil.getLoadedChunkWithoutMarkingActive(world, i1, j1)) != null) {
                    // Paper
                    activateChunkEntities(chunk);
                }
            }
        }
    }
    MinecraftTimings.entityActivationCheckTimer.stopTiming();
}
Also used : EntityHuman(net.minecraft.server.v1_12_R1.EntityHuman) Chunk(net.minecraft.server.v1_12_R1.Chunk)

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 CraftChunk (org.bukkit.craftbukkit.v1_8_R3.CraftChunk)7 Chunk (net.minecraft.server.v1_12_R1.Chunk)6 BlockPosition (net.minecraft.server.v1_8_R3.BlockPosition)6 Chunk (net.minecraft.server.v1_15_R1.Chunk)4 IBlockData (net.minecraft.server.v1_8_R3.IBlockData)4