Search in sources :

Example 1 with EntityClassification

use of net.minecraft.entity.EntityClassification in project Arclight by IzzelAliz.

the class ServerChunkProviderMixin method tickChunks.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
private void tickChunks() {
    long i = this.world.getGameTime();
    long j = i - this.lastGameTime;
    this.lastGameTime = i;
    WorldInfo worldinfo = this.world.getWorldInfo();
    boolean flag = worldinfo.getGenerator() == WorldType.DEBUG_ALL_BLOCK_STATES;
    boolean flag1 = this.world.getGameRules().getBoolean(GameRules.DO_MOB_SPAWNING) && !this.world.getPlayers().isEmpty();
    if (!flag) {
        this.world.getProfiler().startSection("pollingChunks");
        int k = this.world.getGameRules().getInt(GameRules.RANDOM_TICK_SPEED);
        BlockPos blockpos = this.world.getSpawnPoint();
        boolean spawnAnimal = ((WorldBridge) this.world).bridge$ticksPerAnimalSpawns() != 0 && worldinfo.getGameTime() % ((WorldBridge) this.world).bridge$ticksPerAnimalSpawns() == 0;
        boolean spawnMonster = ((WorldBridge) this.world).bridge$ticksPerMonsterSpawns() != 0 && worldinfo.getGameTime() % ((WorldBridge) this.world).bridge$ticksPerMonsterSpawns() == 0;
        boolean spawnWater = ((WorldBridge) this.world).bridge$ticksPerWaterSpawns() != 0 && worldinfo.getGameTime() % ((WorldBridge) this.world).bridge$ticksPerWaterSpawns() == 0;
        boolean spawnAmbient = ((WorldBridge) this.world).bridge$ticksPerAmbientSpawns() != 0 && worldinfo.getGameTime() % ((WorldBridge) this.world).bridge$ticksPerAmbientSpawns() == 0;
        boolean flag2 = spawnAnimal;
        this.world.getProfiler().startSection("naturalSpawnCount");
        int l = this.ticketManager.getSpawningChunksCount();
        EntityClassification[] aentityclassification = EntityClassification.values();
        Object2IntMap<EntityClassification> object2intmap = this.world.countEntities();
        this.world.getProfiler().endSection();
        ((ChunkManagerBridge) this.chunkManager).bridge$getLoadedChunksIterable().forEach((p_223434_10_) -> {
            Optional<Chunk> optional = p_223434_10_.getEntityTickingFuture().getNow(ChunkHolder.UNLOADED_CHUNK).left();
            if (optional.isPresent()) {
                Chunk chunk = optional.get();
                this.world.getProfiler().startSection("broadcast");
                p_223434_10_.sendChanges(chunk);
                this.world.getProfiler().endSection();
                ChunkPos chunkpos = p_223434_10_.getPosition();
                if (!((ChunkManagerBridge) this.chunkManager).bridge$isOutsideSpawningRadius(chunkpos)) {
                    chunk.setInhabitedTime(chunk.getInhabitedTime() + j);
                    if (flag1 && (this.spawnHostiles || this.spawnPassives) && this.world.getWorldBorder().contains(chunk.getPos())) {
                        this.world.getProfiler().startSection("spawner");
                        for (EntityClassification entityclassification : aentityclassification) {
                            boolean spawnThisTick = true;
                            int limit = entityclassification.getMaxNumberOfCreature();
                            switch(entityclassification) {
                                case MONSTER:
                                    spawnThisTick = spawnMonster;
                                    limit = ((WorldBridge) world).bridge$getWorld().getMonsterSpawnLimit();
                                    break;
                                case CREATURE:
                                    spawnThisTick = spawnAnimal;
                                    limit = ((WorldBridge) world).bridge$getWorld().getAnimalSpawnLimit();
                                    break;
                                case WATER_CREATURE:
                                    spawnThisTick = spawnWater;
                                    limit = ((WorldBridge) world).bridge$getWorld().getWaterAnimalSpawnLimit();
                                    break;
                                case AMBIENT:
                                    spawnThisTick = spawnAmbient;
                                    limit = ((WorldBridge) world).bridge$getWorld().getAmbientSpawnLimit();
                                    break;
                            }
                            if (!spawnThisTick || limit == 0) {
                                continue;
                            }
                            if (entityclassification != EntityClassification.MISC && (!entityclassification.getPeacefulCreature() || this.spawnPassives) && (entityclassification.getPeacefulCreature() || this.spawnHostiles) && (!entityclassification.getAnimal() || flag2)) {
                                int i1 = limit * l / field_217238_b;
                                if (object2intmap.getInt(entityclassification) <= i1) {
                                    this.bridge$worldNaturalSpawn(entityclassification, this.world, chunk, blockpos);
                                }
                            }
                        }
                        this.world.getProfiler().endSection();
                    }
                    this.world.tickEnvironment(chunk, k);
                }
            }
        });
        this.world.getProfiler().startSection("customSpawners");
        if (flag1) {
            this.generator.spawnMobs(this.world, this.spawnHostiles, this.spawnPassives);
        }
        this.world.getProfiler().endSection();
        this.world.getProfiler().endSection();
    }
    ((ChunkManagerBridge) this.chunkManager).bridge$tickEntityTracker();
}
Also used : Chunk(net.minecraft.world.chunk.Chunk) IChunk(net.minecraft.world.chunk.IChunk) ChunkManagerBridge(io.izzel.arclight.common.bridge.world.server.ChunkManagerBridge) EntityClassification(net.minecraft.entity.EntityClassification) WorldBridge(io.izzel.arclight.common.bridge.world.WorldBridge) WorldInfo(net.minecraft.world.storage.WorldInfo) BlockPos(net.minecraft.util.math.BlockPos) ChunkPos(net.minecraft.util.math.ChunkPos) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Aggregations

WorldBridge (io.izzel.arclight.common.bridge.world.WorldBridge)1 ChunkManagerBridge (io.izzel.arclight.common.bridge.world.server.ChunkManagerBridge)1 EntityClassification (net.minecraft.entity.EntityClassification)1 BlockPos (net.minecraft.util.math.BlockPos)1 ChunkPos (net.minecraft.util.math.ChunkPos)1 Chunk (net.minecraft.world.chunk.Chunk)1 IChunk (net.minecraft.world.chunk.IChunk)1 WorldInfo (net.minecraft.world.storage.WorldInfo)1 Overwrite (org.spongepowered.asm.mixin.Overwrite)1