Search in sources :

Example 11 with ChunkProviderServer

use of net.minecraft.world.gen.ChunkProviderServer in project RFTools by McJty.

the class WorldRefresher method refreshChunks.

public static void refreshChunks(World world) {
    try {
        ChunkProviderServer chunkServer = (ChunkProviderServer) world.getChunkProvider();
        List<ChunkCoordIntPair> toUnload = new ArrayList<ChunkCoordIntPair>();
        for (Object obj : chunkServer.loadedChunks) {
            Chunk chunk = (Chunk) obj;
            toUnload.add(chunk.getChunkCoordIntPair());
        }
        for (ChunkCoordIntPair pair : toUnload) {
            Chunk oldChunk = world.getChunkFromChunkCoords(pair.chunkXPos, pair.chunkZPos);
            WorldServer worldServer = (WorldServer) world;
            ChunkProviderServer chunkProviderServer = worldServer.theChunkProviderServer;
            // IChunkProvider chunkProviderGenerate = ObfuscationReflectionHelper.getPrivateValue(ChunkProviderServer.class, chunkProviderServer, "d", "field_73246_d");
            IChunkProvider chunkProviderGenerate = chunkProviderServer.currentChunkProvider;
            Chunk newChunk = chunkProviderGenerate.provideChunk(oldChunk.xPosition, oldChunk.zPosition);
            for (int x = 0; x < 16; x++) {
                for (int z = 0; z < 16; z++) {
                    for (int y = 0; y < world.getHeight(); y++) {
                        Block blockID = newChunk.getBlock(x, y, z);
                        int metadata = newChunk.getBlockMetadata(x, y, z);
                        worldServer.setBlock(x + oldChunk.xPosition * 16, y, z + oldChunk.zPosition * 16, blockID, metadata, 2);
                        TileEntity tileEntity = newChunk.getTileEntityUnsafe(x, y, z);
                        if (tileEntity != null) {
                            worldServer.setTileEntity(x + oldChunk.xPosition * 16, y, z + oldChunk.zPosition * 16, tileEntity);
                        }
                    }
                }
            }
            oldChunk.isTerrainPopulated = false;
            chunkProviderGenerate.populate(chunkProviderGenerate, oldChunk.xPosition, oldChunk.zPosition);
        }
    } catch (Exception e) {
        Logging.logError("Failed to regenerate chunks!");
        e.printStackTrace();
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ChunkCoordIntPair(net.minecraft.world.ChunkCoordIntPair) IChunkProvider(net.minecraft.world.chunk.IChunkProvider) ArrayList(java.util.ArrayList) ChunkProviderServer(net.minecraft.world.gen.ChunkProviderServer) Block(net.minecraft.block.Block) WorldServer(net.minecraft.world.WorldServer) Chunk(net.minecraft.world.chunk.Chunk)

Example 12 with ChunkProviderServer

use of net.minecraft.world.gen.ChunkProviderServer 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)

Example 13 with ChunkProviderServer

use of net.minecraft.world.gen.ChunkProviderServer in project RFTools by McJty.

the class RfToolsDimensionManager method touchSpawnChunk.

private void touchSpawnChunk(int id) {
    // Make sure world generation kicks in for at least one chunk so that our matter receiver
    // is generated and registered.
    WorldServer worldServerForDimension = MinecraftServer.getServer().worldServerForDimension(id);
    ChunkProviderServer providerServer = worldServerForDimension.theChunkProviderServer;
    if (!providerServer.chunkExists(0, 0)) {
        try {
            providerServer.loadChunk(0, 0);
            providerServer.populate(providerServer, 0, 0);
            providerServer.unloadChunksIfNotNearSpawn(0, 0);
        } catch (Exception e) {
            Logging.logError("Something went wrong during creation of the dimension!");
            e.printStackTrace();
        // We catch this exception to make sure our dimension tab is at least ok.
        }
    }
}
Also used : ChunkProviderServer(net.minecraft.world.gen.ChunkProviderServer) WorldServer(net.minecraft.world.WorldServer)

Example 14 with ChunkProviderServer

use of net.minecraft.world.gen.ChunkProviderServer in project RFTools by McJty.

the class CmdRCC method execute.

@Override
public void execute(ICommandSender sender, String[] args) {
    World world = sender.getEntityWorld();
    IChunkProvider chunkProvider = world.getChunkProvider();
    if (chunkProvider instanceof ChunkProviderServer) {
        ChunkProviderServer chunkProviderServer = (ChunkProviderServer) chunkProvider;
        for (Object o : chunkProviderServer.loadedChunks) {
            Chunk chunk = (Chunk) o;
            replaceBricks(world, chunk, 0, 0);
            replaceBricks(world, chunk, 15, 0);
            replaceBricks(world, chunk, 15, 15);
            replaceBricks(world, chunk, 0, 15);
        }
    }
}
Also used : IChunkProvider(net.minecraft.world.chunk.IChunkProvider) ChunkProviderServer(net.minecraft.world.gen.ChunkProviderServer) World(net.minecraft.world.World) Chunk(net.minecraft.world.chunk.Chunk)

Example 15 with ChunkProviderServer

use of net.minecraft.world.gen.ChunkProviderServer in project BuildCraft by BuildCraft.

the class MapManager method initialize.

public void initialize() {
    for (WorldServer ws : DimensionManager.getWorlds()) {
        MapWorld mw = getWorld(ws);
        IChunkProvider provider = ws.getChunkProvider();
        if (provider instanceof ChunkProviderServer) {
            for (Object o : ((ChunkProviderServer) provider).func_152380_a()) {
                if (o != null && o instanceof Chunk) {
                    Chunk c = (Chunk) o;
                    if (!mw.hasChunk(c.xPosition, c.zPosition)) {
                        mw.updateChunkDelayed(c, (byte) (40 + Utils.RANDOM.nextInt(20)));
                    }
                }
            }
        }
    }
}
Also used : IChunkProvider(net.minecraft.world.chunk.IChunkProvider) ChunkProviderServer(net.minecraft.world.gen.ChunkProviderServer) WorldServer(net.minecraft.world.WorldServer) Chunk(net.minecraft.world.chunk.Chunk)

Aggregations

ChunkProviderServer (net.minecraft.world.gen.ChunkProviderServer)32 Chunk (net.minecraft.world.chunk.Chunk)14 WorldServer (net.minecraft.world.WorldServer)13 IChunkProvider (net.minecraft.world.chunk.IChunkProvider)6 TileEntity (net.minecraft.tileentity.TileEntity)4 ArrayList (java.util.ArrayList)3 Block (net.minecraft.block.Block)3 ChunkProviderClient (net.minecraft.client.multiplayer.ChunkProviderClient)3 Entity (net.minecraft.entity.Entity)3 MinecraftServer (net.minecraft.server.MinecraftServer)3 BlockPos (net.minecraft.util.math.BlockPos)3 ChunkCoordIntPair (net.minecraft.world.ChunkCoordIntPair)3 World (net.minecraft.world.World)3 IHasMass (com.builtbroken.mc.api.IHasMass)2 Collection (java.util.Collection)2 ChatComponentText (net.minecraft.util.ChatComponentText)2 ChunkPos (net.minecraft.util.math.ChunkPos)2 IMixinChunkProviderServer (org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer)2 EntitySelector (com.builtbroken.mc.prefab.entity.selector.EntitySelector)1 Predicate (com.google.common.base.Predicate)1