Search in sources :

Example 36 with IMixinChunk

use of org.spongepowered.common.interfaces.IMixinChunk in project SpongeCommon by SpongePowered.

the class SpongeChunkGenerator method generateChunk.

@Override
public Chunk generateChunk(int chunkX, int chunkZ) {
    this.rand.setSeed(chunkX * 341873128712L + chunkZ * 132897987541L);
    this.cachedBiomes.reuse(new Vector3i(chunkX * 16, 0, chunkZ * 16));
    this.biomeGenerator.generateBiomes(this.cachedBiomes);
    ImmutableBiomeVolume biomeBuffer = this.cachedBiomes.getImmutableBiomeCopy();
    // Generate base terrain
    ChunkPrimer chunkprimer = new ChunkPrimer();
    MutableBlockVolume blockBuffer = new ChunkPrimerBuffer(chunkprimer, chunkX, chunkZ);
    this.baseGenerator.populate((org.spongepowered.api.world.World) this.world, blockBuffer, biomeBuffer);
    if (!(this.baseGenerator instanceof SpongeGenerationPopulator)) {
        replaceBiomeBlocks(this.world, this.rand, chunkX, chunkZ, chunkprimer, biomeBuffer);
    }
    // Apply the generator populators to complete the blockBuffer
    for (GenerationPopulator populator : this.genpop) {
        populator.populate((org.spongepowered.api.world.World) this.world, blockBuffer, biomeBuffer);
    }
    // Get unique biomes to determine what generator populators to run
    List<BiomeType> uniqueBiomes = Lists.newArrayList();
    BiomeType biome;
    for (int x = 0; x < 16; x++) {
        for (int z = 0; z < 16; z++) {
            biome = this.cachedBiomes.getBiome(chunkX * 16 + x, 0, chunkZ * 16 + z);
            if (!uniqueBiomes.contains(biome)) {
                uniqueBiomes.add(biome);
            }
        }
    }
    // run our generator populators
    for (BiomeType type : uniqueBiomes) {
        BiomeGenerationSettings settings = getBiomeSettings(type);
        for (GenerationPopulator populator : settings.getGenerationPopulators()) {
            populator.populate((org.spongepowered.api.world.World) this.world, blockBuffer, biomeBuffer);
        }
    }
    // Assemble chunk
    Chunk chunk;
    if (this.baseGenerator instanceof SpongeGenerationPopulator && ((SpongeGenerationPopulator) this.baseGenerator).getCachedChunk() != null) {
        chunk = ((SpongeGenerationPopulator) this.baseGenerator).getCachedChunk();
        ((IMixinChunk) chunk).fill(chunkprimer);
    } else {
        chunk = new Chunk(this.world, chunkprimer, chunkX, chunkZ);
        this.cachedBiomes.fill(chunk.getBiomeArray());
    }
    chunk.generateSkylightMap();
    return chunk;
}
Also used : ImmutableBiomeVolume(org.spongepowered.api.world.extent.ImmutableBiomeVolume) MutableBlockVolume(org.spongepowered.api.world.extent.MutableBlockVolume) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) ChunkPrimerBuffer(org.spongepowered.common.util.gen.ChunkPrimerBuffer) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) Chunk(net.minecraft.world.chunk.Chunk) ChunkPrimer(net.minecraft.world.chunk.ChunkPrimer) BiomeType(org.spongepowered.api.world.biome.BiomeType) ChunkGeneratorOverworld(net.minecraft.world.gen.ChunkGeneratorOverworld) IChunkProviderOverworld(org.spongepowered.common.interfaces.world.gen.IChunkProviderOverworld) GenerationPopulator(org.spongepowered.api.world.gen.GenerationPopulator) IGenerationPopulator(org.spongepowered.common.interfaces.world.gen.IGenerationPopulator) Vector3i(com.flowpowered.math.vector.Vector3i) BiomeGenerationSettings(org.spongepowered.api.world.biome.BiomeGenerationSettings) SpongeBiomeGenerationSettings(org.spongepowered.common.world.biome.SpongeBiomeGenerationSettings)

Example 37 with IMixinChunk

use of org.spongepowered.common.interfaces.IMixinChunk in project SpongeCommon by SpongePowered.

the class MixinChunk_Async_Lighting method onRelightChecksGetBlockState.

@Redirect(method = "enqueueRelightChecks", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;getBlockState(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/state/IBlockState;"))
private IBlockState onRelightChecksGetBlockState(World world, BlockPos pos) {
    Chunk chunk = ((IMixinChunkProviderServer) world.getChunkProvider()).getLoadedChunkWithoutMarkingActive(pos.getX() >> 4, pos.getZ() >> 4);
    final IMixinChunk spongeChunk = (IMixinChunk) chunk;
    if (chunk == null || chunk.unloadQueued || !spongeChunk.areNeighborsLoaded()) {
        return Blocks.AIR.getDefaultState();
    }
    return chunk.getBlockState(pos);
}
Also used : IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) Chunk(net.minecraft.world.chunk.Chunk) IMixinChunkProviderServer(org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 38 with IMixinChunk

use of org.spongepowered.common.interfaces.IMixinChunk in project SpongeCommon by SpongePowered.

the class MixinChunk_Async_Lighting method getSurroundingChunks.

/**
 * Gets surrounding chunks thread-safe.
 *
 * @return The list of surrounding chunks, empty list if not loaded
 */
private List<Chunk> getSurroundingChunks() {
    if (!this.areNeighborsLoaded()) {
        return EMPTY_LIST;
    }
    // add diagonal chunks
    final Chunk southEastChunk = ((IMixinChunk) this.getNeighborChunk(0)).getNeighborChunk(2);
    if (southEastChunk == null) {
        return EMPTY_LIST;
    }
    final Chunk southWestChunk = ((IMixinChunk) this.getNeighborChunk(0)).getNeighborChunk(3);
    if (southWestChunk == null) {
        return EMPTY_LIST;
    }
    final Chunk northEastChunk = ((IMixinChunk) this.getNeighborChunk(1)).getNeighborChunk(2);
    if (northEastChunk == null) {
        return EMPTY_LIST;
    }
    final Chunk northWestChunk = ((IMixinChunk) this.getNeighborChunk(1)).getNeighborChunk(3);
    if (northWestChunk == null) {
        return EMPTY_LIST;
    }
    List<Chunk> chunkList = new ArrayList<>();
    chunkList = this.getNeighbors();
    chunkList.add(southEastChunk);
    chunkList.add(southWestChunk);
    chunkList.add(northEastChunk);
    chunkList.add(northWestChunk);
    return chunkList;
}
Also used : IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) Chunk(net.minecraft.world.chunk.Chunk)

Example 39 with IMixinChunk

use of org.spongepowered.common.interfaces.IMixinChunk in project SpongeCommon by SpongePowered.

the class MixinWorldServer_Async_Lighting method updateLightAsync.

@Override
public boolean updateLightAsync(EnumSkyBlock lightType, BlockPos pos, @Nullable Chunk currentChunk) {
    if (this.getMinecraftServer().isServerStopped() || this.lightExecutorService.isShutdown()) {
        return false;
    }
    if (currentChunk == null) {
        currentChunk = ((IMixinChunkProviderServer) this.chunkProvider).getLoadedChunkWithoutMarkingActive(pos.getX() >> 4, pos.getZ() >> 4);
    }
    final IMixinChunk spongeChunk = (IMixinChunk) currentChunk;
    if (currentChunk == null || currentChunk.unloadQueued || !spongeChunk.areNeighborsLoaded()) {
        return false;
    }
    final short shortPos = this.blockPosToShort(pos);
    if (spongeChunk.getQueuedLightingUpdates(lightType).contains(shortPos)) {
        return false;
    }
    final Chunk chunk = currentChunk;
    spongeChunk.getQueuedLightingUpdates(lightType).add(shortPos);
    spongeChunk.getPendingLightUpdates().incrementAndGet();
    spongeChunk.setLightUpdateTime(chunk.getWorld().getTotalWorldTime());
    List<Chunk> neighbors = spongeChunk.getNeighbors();
    // add diagonal chunks
    Chunk southEastChunk = ((IMixinChunk) spongeChunk.getNeighborChunk(0)).getNeighborChunk(2);
    Chunk southWestChunk = ((IMixinChunk) spongeChunk.getNeighborChunk(0)).getNeighborChunk(3);
    Chunk northEastChunk = ((IMixinChunk) spongeChunk.getNeighborChunk(1)).getNeighborChunk(2);
    Chunk northWestChunk = ((IMixinChunk) spongeChunk.getNeighborChunk(1)).getNeighborChunk(3);
    if (southEastChunk != null) {
        neighbors.add(southEastChunk);
    }
    if (southWestChunk != null) {
        neighbors.add(southWestChunk);
    }
    if (northEastChunk != null) {
        neighbors.add(northEastChunk);
    }
    if (northWestChunk != null) {
        neighbors.add(northWestChunk);
    }
    for (net.minecraft.world.chunk.Chunk neighborChunk : neighbors) {
        final IMixinChunk neighbor = (IMixinChunk) neighborChunk;
        neighbor.getPendingLightUpdates().incrementAndGet();
        neighbor.setLightUpdateTime(chunk.getWorld().getTotalWorldTime());
    }
    // System.out.println("size = " + ((ThreadPoolExecutor) this.lightExecutorService).getQueue().size());
    if (SpongeImpl.getServer().isCallingFromMinecraftThread()) {
        this.lightExecutorService.execute(() -> {
            this.checkLightAsync(lightType, pos, chunk, neighbors);
        });
    } else {
        this.checkLightAsync(lightType, pos, chunk, neighbors);
    }
    return true;
}
Also used : IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) Chunk(net.minecraft.world.chunk.Chunk) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) Chunk(net.minecraft.world.chunk.Chunk)

Example 40 with IMixinChunk

use of org.spongepowered.common.interfaces.IMixinChunk in project SpongeCommon by SpongePowered.

the class TileEntityActivation method checkIfActive.

/**
 * Checks if the tileentity is active for this tick.
 *
 * @param tileEntity The tileentity to check for activity
 * @return Whether the given tileentity should be active
 */
public static boolean checkIfActive(TileEntity tileEntity) {
    if (tileEntity.getWorld() == null || tileEntity.getWorld().isRemote || !(tileEntity instanceof ITickable)) {
        return true;
    }
    final World world = tileEntity.getWorld();
    final IMixinChunk activeChunk = ((IMixinTileEntity) tileEntity).getActiveChunk();
    if (activeChunk == null) {
        // Should never happen but just in case for mods, always tick
        return true;
    }
    long currentTick = SpongeImpl.getServer().getTickCounter();
    IModData_Activation spongeTileEntity = (IModData_Activation) tileEntity;
    boolean isActive = activeChunk.isPersistedChunk() || spongeTileEntity.getActivatedTick() >= currentTick || spongeTileEntity.getDefaultActivationState();
    // Should this entity tick?
    if (!isActive) {
        if (spongeTileEntity.getActivatedTick() == Integer.MIN_VALUE) {
            // Has not come across a player
            return false;
        }
    }
    // check tick rate
    if (isActive && world.getWorldInfo().getWorldTotalTime() % spongeTileEntity.getSpongeTickRate() != 0L) {
        isActive = false;
    }
    return isActive;
}
Also used : IModData_Activation(org.spongepowered.common.mixin.plugin.entityactivation.interfaces.IModData_Activation) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) IMixinTileEntity(org.spongepowered.common.interfaces.block.tile.IMixinTileEntity) ITickable(net.minecraft.util.ITickable) World(net.minecraft.world.World)

Aggregations

IMixinChunk (org.spongepowered.common.interfaces.IMixinChunk)49 Chunk (net.minecraft.world.chunk.Chunk)21 BlockPos (net.minecraft.util.math.BlockPos)18 IMixinChunkProviderServer (org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer)12 User (org.spongepowered.api.entity.living.player.User)11 Inject (org.spongepowered.asm.mixin.injection.Inject)8 IBlockState (net.minecraft.block.state.IBlockState)7 World (org.spongepowered.api.world.World)7 IMixinEntity (org.spongepowered.common.interfaces.entity.IMixinEntity)7 LocatableBlock (org.spongepowered.api.world.LocatableBlock)6 Vector3i (com.flowpowered.math.vector.Vector3i)5 Block (net.minecraft.block.Block)5 StackFrame (org.spongepowered.api.event.CauseStackManager.StackFrame)5 Direction (org.spongepowered.api.util.Direction)5 PhaseTracker (org.spongepowered.common.event.tracking.PhaseTracker)5 Overwrite (org.spongepowered.asm.mixin.Overwrite)4 PhaseData (org.spongepowered.common.event.tracking.PhaseData)4 IMixinTileEntity (org.spongepowered.common.interfaces.block.tile.IMixinTileEntity)4 IMixinWorldServer (org.spongepowered.common.interfaces.world.IMixinWorldServer)4 Vector3d (com.flowpowered.math.vector.Vector3d)3