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