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;
}
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);
}
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);
}
}
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;
}
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);
}
}
}
Aggregations