Search in sources :

Example 1 with LongHashMap

use of net.minecraft.util.LongHashMap in project RFTools by McJty.

the class WorldRefresher method refreshChunksBad.

public static void refreshChunksBad(World world) {
    try {
        ChunkProviderServer chunkServer = (ChunkProviderServer) world.getChunkProvider();
        Field u;
        try {
            // chunksToUnload
            u = ChunkProviderServer.class.getDeclaredField("field_73248_b");
        } catch (NoSuchFieldException e) {
            u = ChunkProviderServer.class.getDeclaredField("chunksToUnload");
        }
        u.setAccessible(true);
        Set<?> unloadQueue = (Set<?>) u.get(chunkServer);
        Field m;
        try {
            // loadedChunkHashMap
            m = ChunkProviderServer.class.getDeclaredField("field_73244_f");
        } catch (NoSuchFieldException e) {
            m = ChunkProviderServer.class.getDeclaredField("loadedChunkHashMap");
        }
        m.setAccessible(true);
        LongHashMap loadedMap = (LongHashMap) m.get(chunkServer);
        Field lc;
        try {
            // loadedChunkHashMap
            lc = ChunkProviderServer.class.getDeclaredField("field_73245_g");
        } catch (NoSuchFieldException e) {
            lc = ChunkProviderServer.class.getDeclaredField("loadedChunks");
        }
        lc.setAccessible(true);
        @SuppressWarnings("unchecked") List<Chunk> loaded = (List<Chunk>) lc.get(chunkServer);
        Field p;
        try {
            // currentChunkProvider
            p = ChunkProviderServer.class.getDeclaredField("field_73246_d");
        } catch (NoSuchFieldException e) {
            p = ChunkProviderServer.class.getDeclaredField("currentChunkProvider");
        }
        p.setAccessible(true);
        IChunkProvider chunkProvider = (IChunkProvider) p.get(chunkServer);
        List<ChunkCoordIntPair> toUnload = new ArrayList<ChunkCoordIntPair>();
        for (Object obj : chunkServer.loadedChunks) {
            Chunk chunk = (Chunk) obj;
            toUnload.add(chunk.getChunkCoordIntPair());
        }
        for (ChunkCoordIntPair pair : toUnload) {
            int x = pair.chunkXPos;
            int z = pair.chunkZPos;
            long pos = ChunkCoordIntPair.chunkXZ2Int(x, z);
            Chunk chunk;
            if (chunkServer.chunkExists(x, z)) {
                chunk = chunkServer.loadChunk(x, z);
                chunk.onChunkUnload();
            }
            unloadQueue.remove(pos);
            loadedMap.remove(pos);
            chunk = chunkProvider.provideChunk(x, z);
            loadedMap.add(pos, chunk);
            loaded.add(chunk);
            if (chunk != null) {
                chunk.onChunkLoad();
                chunk.populateChunk(chunkProvider, chunkProvider, x, z);
            }
        }
    } catch (Exception e) {
        Logging.logError("Failed to regenerate chunks!");
        e.printStackTrace();
    }
}
Also used : Set(java.util.Set) ChunkCoordIntPair(net.minecraft.world.ChunkCoordIntPair) ArrayList(java.util.ArrayList) Chunk(net.minecraft.world.chunk.Chunk) Field(java.lang.reflect.Field) IChunkProvider(net.minecraft.world.chunk.IChunkProvider) ChunkProviderServer(net.minecraft.world.gen.ChunkProviderServer) ArrayList(java.util.ArrayList) List(java.util.List) LongHashMap(net.minecraft.util.LongHashMap)

Aggregations

Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Set (java.util.Set)1 LongHashMap (net.minecraft.util.LongHashMap)1 ChunkCoordIntPair (net.minecraft.world.ChunkCoordIntPair)1 Chunk (net.minecraft.world.chunk.Chunk)1 IChunkProvider (net.minecraft.world.chunk.IChunkProvider)1 ChunkProviderServer (net.minecraft.world.gen.ChunkProviderServer)1