001 package net.minecraft.src; 002 003 import java.util.ArrayList; 004 import java.util.List; 005 006 public class BiomeCache 007 { 008 /** Reference to the WorldChunkManager */ 009 private final WorldChunkManager chunkManager; 010 011 /** The last time this BiomeCache was cleaned, in milliseconds. */ 012 private long lastCleanupTime = 0L; 013 014 /** 015 * The map of keys to BiomeCacheBlocks. Keys are based on the chunk x, z coordinates as (x | z << 32). 016 */ 017 private LongHashMap cacheMap = new LongHashMap(); 018 019 /** The list of cached BiomeCacheBlocks */ 020 private List cache = new ArrayList(); 021 022 public BiomeCache(WorldChunkManager par1WorldChunkManager) 023 { 024 this.chunkManager = par1WorldChunkManager; 025 } 026 027 /** 028 * Returns a biome cache block at location specified. 029 */ 030 public BiomeCacheBlock getBiomeCacheBlock(int par1, int par2) 031 { 032 par1 >>= 4; 033 par2 >>= 4; 034 long var3 = (long)par1 & 4294967295L | ((long)par2 & 4294967295L) << 32; 035 BiomeCacheBlock var5 = (BiomeCacheBlock)this.cacheMap.getValueByKey(var3); 036 037 if (var5 == null) 038 { 039 var5 = new BiomeCacheBlock(this, par1, par2); 040 this.cacheMap.add(var3, var5); 041 this.cache.add(var5); 042 } 043 044 var5.lastAccessTime = System.currentTimeMillis(); 045 return var5; 046 } 047 048 /** 049 * Returns the BiomeGenBase related to the x, z position from the cache. 050 */ 051 public BiomeGenBase getBiomeGenAt(int par1, int par2) 052 { 053 return this.getBiomeCacheBlock(par1, par2).getBiomeGenAt(par1, par2); 054 } 055 056 /** 057 * Removes BiomeCacheBlocks from this cache that haven't been accessed in at least 30 seconds. 058 */ 059 public void cleanupCache() 060 { 061 long var1 = System.currentTimeMillis(); 062 long var3 = var1 - this.lastCleanupTime; 063 064 if (var3 > 7500L || var3 < 0L) 065 { 066 this.lastCleanupTime = var1; 067 068 for (int var5 = 0; var5 < this.cache.size(); ++var5) 069 { 070 BiomeCacheBlock var6 = (BiomeCacheBlock)this.cache.get(var5); 071 long var7 = var1 - var6.lastAccessTime; 072 073 if (var7 > 30000L || var7 < 0L) 074 { 075 this.cache.remove(var5--); 076 long var9 = (long)var6.xPosition & 4294967295L | ((long)var6.zPosition & 4294967295L) << 32; 077 this.cacheMap.remove(var9); 078 } 079 } 080 } 081 } 082 083 /** 084 * Returns the array of cached biome types in the BiomeCacheBlock at the given location. 085 */ 086 public BiomeGenBase[] getCachedBiomes(int par1, int par2) 087 { 088 return this.getBiomeCacheBlock(par1, par2).biomes; 089 } 090 091 /** 092 * Get the world chunk manager object for a biome list. 093 */ 094 static WorldChunkManager getChunkManager(BiomeCache par0BiomeCache) 095 { 096 return par0BiomeCache.chunkManager; 097 } 098 }