2020-07-22 06:23:34 +01:00
|
|
|
package net.minecraft.world.level.newbiome.area;
|
|
|
|
|
|
|
|
import net.minecraft.world.level.ChunkPos;
|
|
|
|
import it.unimi.dsi.fastutil.longs.Long2IntLinkedOpenHashMap;
|
|
|
|
import net.minecraft.world.level.newbiome.layer.traits.PixelTransformer;
|
|
|
|
|
|
|
|
public final class LazyArea implements Area {
|
|
|
|
private final PixelTransformer transformer;
|
|
|
|
private final Long2IntLinkedOpenHashMap cache;
|
|
|
|
private final int maxCache;
|
|
|
|
|
2020-07-22 06:25:47 +01:00
|
|
|
public LazyArea(final Long2IntLinkedOpenHashMap long2IntLinkedOpenHashMap, final int integer, final PixelTransformer cqf) {
|
2020-07-22 06:23:34 +01:00
|
|
|
this.cache = long2IntLinkedOpenHashMap;
|
|
|
|
this.maxCache = integer;
|
2020-07-22 06:25:47 +01:00
|
|
|
this.transformer = cqf;
|
2020-07-22 06:23:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int get(final int integer1, final int integer2) {
|
|
|
|
final long long4 = ChunkPos.asLong(integer1, integer2);
|
|
|
|
synchronized (this.cache) {
|
|
|
|
final int integer3 = this.cache.get(long4);
|
|
|
|
if (integer3 != Integer.MIN_VALUE) {
|
|
|
|
return integer3;
|
|
|
|
}
|
|
|
|
final int integer4 = this.transformer.apply(integer1, integer2);
|
|
|
|
this.cache.put(long4, integer4);
|
|
|
|
if (this.cache.size() > this.maxCache) {
|
|
|
|
for (int integer5 = 0; integer5 < this.maxCache / 16; ++integer5) {
|
|
|
|
this.cache.removeFirstInt();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return integer4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getMaxCache() {
|
|
|
|
return this.maxCache;
|
|
|
|
}
|
|
|
|
}
|