Search in sources :

Example 1 with ServerChunkCache

use of net.minecraft.server.level.ServerChunkCache in project Denizen-For-Bukkit by DenizenScript.

the class ChunkHelperImpl method changeChunkServerThread.

@Override
public void changeChunkServerThread(World world) {
    if (DenizenCoreImplementation.tagThread == null) {
        return;
    }
    if (resetServerThread != null) {
        return;
    }
    ServerLevel nmsWorld = ((CraftWorld) world).getHandle();
    ServerChunkCache provider = nmsWorld.getChunkProvider();
    try {
        resetServerThread = (Thread) chunkProviderServerThreadField.get(provider);
        chunkProviderServerThreadFieldSetter.invoke(provider, Thread.currentThread());
        worldThreadFieldSetter.invoke(nmsWorld, Thread.currentThread());
    } catch (Throwable ex) {
        Debug.echoError(ex);
    }
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) ServerChunkCache(net.minecraft.server.level.ServerChunkCache) CraftWorld(org.bukkit.craftbukkit.v1_17_R1.CraftWorld)

Example 2 with ServerChunkCache

use of net.minecraft.server.level.ServerChunkCache in project Denizen-For-Bukkit by DenizenScript.

the class ChunkHelperImpl method changeChunkServerThread.

@Override
public void changeChunkServerThread(World world) {
    if (DenizenCoreImplementation.tagThread == null) {
        return;
    }
    if (resetServerThread != null) {
        return;
    }
    ServerLevel nmsWorld = ((CraftWorld) world).getHandle();
    ServerChunkCache provider = nmsWorld.getChunkSource();
    try {
        resetServerThread = (Thread) chunkProviderServerThreadField.get(provider);
        chunkProviderServerThreadFieldSetter.invoke(provider, Thread.currentThread());
        worldThreadFieldSetter.invoke(nmsWorld, Thread.currentThread());
    } catch (Throwable ex) {
        Debug.echoError(ex);
    }
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) ServerChunkCache(net.minecraft.server.level.ServerChunkCache) CraftWorld(org.bukkit.craftbukkit.v1_18_R1.CraftWorld)

Example 3 with ServerChunkCache

use of net.minecraft.server.level.ServerChunkCache in project Denizen-For-Bukkit by DenizenScript.

the class ChunkHelperImpl method restoreServerThread.

@Override
public void restoreServerThread(World world) {
    if (DenizenCoreImplementation.tagThread == null) {
        return;
    }
    if (resetServerThread == null) {
        return;
    }
    ServerLevel nmsWorld = ((CraftWorld) world).getHandle();
    ServerChunkCache provider = nmsWorld.getChunkSource();
    try {
        chunkProviderServerThreadFieldSetter.invoke(provider, resetServerThread);
        worldThreadFieldSetter.invoke(nmsWorld, resetServerThread);
        resetServerThread = null;
    } catch (Throwable ex) {
        Debug.echoError(ex);
    }
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) ServerChunkCache(net.minecraft.server.level.ServerChunkCache) CraftWorld(org.bukkit.craftbukkit.v1_18_R1.CraftWorld)

Example 4 with ServerChunkCache

use of net.minecraft.server.level.ServerChunkCache in project MyPet by xXKeyleXx.

the class PlatformHelper method getBlockBBsInBB.

public List getBlockBBsInBB(net.minecraft.world.level.Level world, AABB axisalignedbb) {
    UnsafeList unsafeList = new UnsafeList();
    int minX = Mth.floor(axisalignedbb.minX);
    int maxX = (int) Math.ceil(axisalignedbb.maxX);
    int minY = Mth.floor(axisalignedbb.minY);
    int maxY = (int) Math.ceil(axisalignedbb.maxY);
    int minZ = Mth.floor(axisalignedbb.minZ);
    int maxZ = (int) Math.ceil(axisalignedbb.maxZ);
    VoxelShape vec3d;
    boolean isEmpty;
    for (int x = minX; x <= maxX; x++) {
        for (int z = minZ; z <= maxZ; z++) {
            if (((ServerChunkCache) world.getChunkSource()).hasChunk(x >> 4, z >> 4)) {
                for (int y = minY - 1; y <= maxY; y++) {
                    BlockPos bp = new BlockPos(x, y, z);
                    BlockState blockData = world.getBlockState(bp);
                    if (blockData != null && blockData.getMaterial().isSolid()) {
                        vec3d = blockData.getCollisionShape(world, bp);
                        isEmpty = vec3d.isEmpty();
                        if (!isEmpty) {
                            for (AABB bb : vec3d.toAabbs()) {
                                if (bb.move(bp).intersects(axisalignedbb)) {
                                    unsafeList.add(bb);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return unsafeList;
}
Also used : VoxelShape(net.minecraft.world.phys.shapes.VoxelShape) BlockState(net.minecraft.world.level.block.state.BlockState) BlockPos(net.minecraft.core.BlockPos) UnsafeList(org.bukkit.craftbukkit.v1_18_R1.util.UnsafeList) ServerChunkCache(net.minecraft.server.level.ServerChunkCache) AABB(net.minecraft.world.phys.AABB)

Example 5 with ServerChunkCache

use of net.minecraft.server.level.ServerChunkCache in project Denizen-For-Bukkit by DenizenScript.

the class BlockLightImpl method sendSingleChunkUpdate.

public static void sendSingleChunkUpdate(LevelChunk chunk) {
    doNotCheck = true;
    LevelLightEngine lightEngine = chunk.getLevel().getChunkSource().getLightEngine();
    ChunkPos pos = chunk.getPos();
    // TODO: 1.16: should 'trust edges' be true here?
    ClientboundLightUpdatePacket packet = new ClientboundLightUpdatePacket(pos, lightEngine, null, null, true);
    ((ServerChunkCache) chunk.getLevel().getChunkSource()).chunkMap.getPlayers(pos, false).forEach((player) -> {
        player.connection.send(packet);
    });
    doNotCheck = false;
}
Also used : ThreadedLevelLightEngine(net.minecraft.server.level.ThreadedLevelLightEngine) LevelLightEngine(net.minecraft.world.level.lighting.LevelLightEngine) ClientboundLightUpdatePacket(net.minecraft.network.protocol.game.ClientboundLightUpdatePacket) ChunkPos(net.minecraft.world.level.ChunkPos) ServerChunkCache(net.minecraft.server.level.ServerChunkCache)

Aggregations

ServerChunkCache (net.minecraft.server.level.ServerChunkCache)8 ServerLevel (net.minecraft.server.level.ServerLevel)4 BlockPos (net.minecraft.core.BlockPos)2 ClientboundLightUpdatePacket (net.minecraft.network.protocol.game.ClientboundLightUpdatePacket)2 ThreadedLevelLightEngine (net.minecraft.server.level.ThreadedLevelLightEngine)2 ChunkPos (net.minecraft.world.level.ChunkPos)2 BlockState (net.minecraft.world.level.block.state.BlockState)2 LevelLightEngine (net.minecraft.world.level.lighting.LevelLightEngine)2 AABB (net.minecraft.world.phys.AABB)2 VoxelShape (net.minecraft.world.phys.shapes.VoxelShape)2 CraftWorld (org.bukkit.craftbukkit.v1_17_R1.CraftWorld)2 CraftWorld (org.bukkit.craftbukkit.v1_18_R1.CraftWorld)2 UnsafeList (org.bukkit.craftbukkit.v1_17_R1.util.UnsafeList)1 UnsafeList (org.bukkit.craftbukkit.v1_18_R1.util.UnsafeList)1