tracker

mail@pastecode.io avatar
unknown
java
4 months ago
2.9 kB
3
Indexable

    public void activateEntities(
        final int playerx, final int playery, final int playerz,
        final double playerminX, final double playermaxX,
        final double playerminZ, final double playermaxZ
    ) {
        final int minChunkX = (Mth.floor(playerminX) - 2) >> 4;
        final int minChunkZ = (Mth.floor(playerminZ) - 2) >> 4;
        final int maxChunkX = (Mth.floor(playermaxX) + 2) >> 4;
        final int maxChunkZ = (Mth.floor(playermaxZ) + 2) >> 4;

        final int minRegionX = minChunkX >> REGION_SHIFT;
        final int minRegionZ = minChunkZ >> REGION_SHIFT;
        final int maxRegionX = maxChunkX >> REGION_SHIFT;
        final int maxRegionZ = maxChunkZ >> REGION_SHIFT;
        final int currentTick = MinecraftServer.currentTick;
        final boolean tickMarkers = world.paperConfig().entities.markers.tick; // Paper - Configurable marker ticking

        for (int currRegionZ = minRegionZ; currRegionZ <= maxRegionZ; ++currRegionZ) {
            final int minZ = currRegionZ == minRegionZ ? minChunkZ & REGION_MASK : 0;
            final int maxZ = currRegionZ == maxRegionZ ? maxChunkZ & REGION_MASK : REGION_MASK;

            for (int currRegionX = minRegionX; currRegionX <= maxRegionX; ++currRegionX) {
                final ChunkSlicesRegion region = this.getRegion(currRegionX, currRegionZ);

                if (region == null) {
                    continue;
                }

                final int minX = currRegionX == minRegionX ? minChunkX & REGION_MASK : 0;
                final int maxX = currRegionX == maxRegionX ? maxChunkX & REGION_MASK : REGION_MASK;

                for (int currZ = minZ; currZ <= maxZ; ++currZ) {
                    for (int currX = minX; currX <= maxX; ++currX) {
                        final ChunkEntitySlices chunk = region.get(currX | (currZ << REGION_SHIFT));
                        if (chunk == null || !chunk.status.isOrAfter(FullChunkStatus.FULL)) {
                            continue;
                        }
                        final EntityList list = chunk.getEntityList();
                        for (final Entity entity : list) {
                            // Paper start - Configurable marker ticking
                            if (currentTick <= entity.activatedTick || (!tickMarkers && entity instanceof net.minecraft.world.entity.Marker)) {
                                continue;
                            }
                            // Paper end - Configurable marker ticking
                            if (entity.defaultActivationState) {
                                entity.activatedTick = currentTick;
                                continue;
                            }
                            ActivationRange.tryUpdate(world, entity, playerx, playery, playerz, currentTick);
                        }
                    }
                }
            }
        }
    }
Leave a Comment