Search in sources :

Example 16 with IMixinChunk

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

the class MixinWorld method getChunkNearIntersections.

private IMixinChunk getChunkNearIntersections(int xChunk, int zChunk, double xCurrent, double zCurrent, double xNext, double zNext) {
    final int chunkWidth = SpongeChunkLayout.CHUNK_SIZE.getX();
    // Chunk corner coordinates
    final Vector2d c1 = new Vector2d(xChunk, zChunk);
    final Vector2d c2 = new Vector2d(xChunk + chunkWidth, zChunk);
    final Vector2d c3 = new Vector2d(xChunk, zChunk + chunkWidth);
    final Vector2d c4 = new Vector2d(xChunk + chunkWidth, zChunk + chunkWidth);
    // The square of the distance we consider as being near
    final int nearDistance2 = 2 * 2;
    // Under the assumption that both intersections aren't on the same face
    // Look for two intersection being near the same corner
    final boolean d11 = c1.distanceSquared(xCurrent, zCurrent) <= nearDistance2;
    final boolean d21 = c1.distanceSquared(xNext, zNext) <= nearDistance2;
    if (d11 && d21) {
        // Near corner -x, -z
        return (IMixinChunk) getChunkAtBlock(xChunk - chunkWidth, 0, zChunk - chunkWidth).orElse(null);
    }
    final boolean d12 = c2.distanceSquared(xCurrent, zCurrent) <= nearDistance2;
    final boolean d22 = c2.distanceSquared(xNext, zNext) <= nearDistance2;
    if (d12 && d22) {
        // Near corner +x, -z
        return (IMixinChunk) getChunkAtBlock(xChunk + chunkWidth, 0, zChunk - chunkWidth).orElse(null);
    }
    final boolean d13 = c3.distanceSquared(xCurrent, zCurrent) <= nearDistance2;
    final boolean d23 = c3.distanceSquared(xNext, zNext) <= nearDistance2;
    if (d13 && d23) {
        // Near corner -x, +z
        return (IMixinChunk) getChunkAtBlock(xChunk - chunkWidth, 0, zChunk + chunkWidth).orElse(null);
    }
    final boolean d14 = c4.distanceSquared(xCurrent, zCurrent) <= nearDistance2;
    final boolean d24 = c4.distanceSquared(xNext, zNext) <= nearDistance2;
    if (d14 && d24) {
        // Near corner +x, +z
        return (IMixinChunk) getChunkAtBlock(xChunk + chunkWidth, 0, zChunk + chunkWidth).orElse(null);
    }
    // Look for two intersections being near the corners on the same face
    if (d11 && d23 || d21 && d13) {
        // Near face -x
        return (IMixinChunk) getChunkAtBlock(xChunk - chunkWidth, 0, zChunk).orElse(null);
    }
    if (d11 && d22 || d21 && d12) {
        // Near face -z
        return (IMixinChunk) getChunkAtBlock(xChunk, 0, zChunk - chunkWidth).orElse(null);
    }
    if (d14 && d22 || d24 && d12) {
        // Near face +x
        return (IMixinChunk) getChunkAtBlock(xChunk + chunkWidth, 0, zChunk).orElse(null);
    }
    if (d14 && d23 || d24 && d13) {
        // Near face +z
        return (IMixinChunk) getChunkAtBlock(xChunk, 0, zChunk + chunkWidth).orElse(null);
    }
    return null;
}
Also used : Vector2d(com.flowpowered.math.vector.Vector2d) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk)

Example 17 with IMixinChunk

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

the class MixinWorldEntitySpawner method getRandomChunkPosition.

/**
 * @author aikar - February 20th, 2017 - Optimizes light level check.
 * @author blood - February 20th, 2017 - Avoids checking unloaded chunks and chunks with pending light updates.
 *
 * @reason Avoids checking unloaded chunks and chunks with pending light updates.
 */
@Overwrite
private static BlockPos getRandomChunkPosition(World worldIn, int x, int z) {
    // Sponge start
    final Chunk chunk = ((IMixinChunkProviderServer) worldIn.getChunkProvider()).getLoadedChunkWithoutMarkingActive(x, z);
    if (chunk == null || (chunk.unloadQueued && !((IMixinChunk) chunk).isPersistedChunk())) {
        // Don't attempt to spawn in an unloaded chunk
        return null;
    }
    // Sponge end
    int i = x * 16 + worldIn.rand.nextInt(16);
    int j = z * 16 + worldIn.rand.nextInt(16);
    int k = MathHelper.roundUp(chunk.getHeight(new BlockPos(i, 0, j)) + 1, 16);
    int l = worldIn.rand.nextInt(k > 0 ? k : chunk.getTopFilledSegment() + 16 - 1);
    return new BlockPos(i, l, j);
}
Also used : IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) BlockPos(net.minecraft.util.math.BlockPos) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) Chunk(net.minecraft.world.chunk.Chunk) IMixinChunkProviderServer(org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 18 with IMixinChunk

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

the class MixinWorldServer method doChunkGC.

// Chunk GC
@Override
public void doChunkGC() {
    this.chunkGCTickCount++;
    ChunkProviderServer chunkProviderServer = this.getChunkProvider();
    int chunkLoadCount = this.getChunkProvider().getLoadedChunkCount();
    if (chunkLoadCount >= this.chunkGCLoadThreshold && this.chunkGCLoadThreshold > 0) {
        chunkLoadCount = 0;
    } else if (this.chunkGCTickCount >= this.chunkGCTickInterval && this.chunkGCTickInterval > 0) {
        this.chunkGCTickCount = 0;
    } else {
        return;
    }
    for (net.minecraft.world.chunk.Chunk chunk : chunkProviderServer.getLoadedChunks()) {
        IMixinChunk spongeChunk = (IMixinChunk) chunk;
        if (chunk.unloadQueued || spongeChunk.isPersistedChunk() || !this.provider.canDropChunk(chunk.x, chunk.z)) {
            continue;
        }
        // If a player is currently using the chunk, skip it
        if (((IMixinPlayerChunkMap) this.getPlayerChunkMap()).isChunkInUse(chunk.x, chunk.z)) {
            continue;
        }
        // If we reach this point the chunk leaked so queue for unload
        chunkProviderServer.queueUnload(chunk);
        SpongeHooks.logChunkGCQueueUnload(chunkProviderServer.world, chunk);
    }
}
Also used : IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) IMixinChunkProviderServer(org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer) ChunkProviderServer(net.minecraft.world.gen.ChunkProviderServer) Chunk(net.minecraft.world.chunk.Chunk) IMixinPlayerChunkMap(org.spongepowered.common.interfaces.server.management.IMixinPlayerChunkMap)

Example 19 with IMixinChunk

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

the class MixinPlayerChunkMapEntry method markChunkUsed.

// delay chunk unloads
public final void markChunkUsed() {
    if (this.chunk == null) {
        return;
    }
    IMixinChunk spongeChunk = (IMixinChunk) this.chunk;
    spongeChunk.setScheduledForUnload(-1);
    this.loading = false;
}
Also used : IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk)

Example 20 with IMixinChunk

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

the class MixinBlockRailBase method onMinecartRailPass.

// Used to transfer tracking information from minecarts to block positions
@Inject(method = "onMinecartPass", at = @At(value = "HEAD"))
public void onMinecartRailPass(World world, net.minecraft.entity.item.EntityMinecart cart, BlockPos pos, CallbackInfo ci) {
    IMixinEntity spongeEntity = (IMixinEntity) cart;
    Optional<User> notifier = spongeEntity.getNotifierUser();
    Optional<User> owner = spongeEntity.getCreatorUser();
    if (owner.isPresent() || notifier.isPresent()) {
        IMixinChunk spongeChunk = (IMixinChunk) world.getChunkFromBlockCoords(pos);
        if (notifier.isPresent()) {
            spongeChunk.addTrackedBlockPosition(world.getBlockState(pos).getBlock(), pos, notifier.get(), PlayerTracker.Type.NOTIFIER);
        } else {
            spongeChunk.addTrackedBlockPosition(world.getBlockState(pos).getBlock(), pos, owner.get(), PlayerTracker.Type.NOTIFIER);
        }
    }
}
Also used : User(org.spongepowered.api.entity.living.player.User) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) IMixinEntity(org.spongepowered.common.interfaces.entity.IMixinEntity) Inject(org.spongepowered.asm.mixin.injection.Inject)

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