Advertisement
Guest User

chunk test

a guest
Feb 27th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 2.41 KB | None | 0 0
  1.     internal fun processRegionFile(file: File) {
  2.         val splitted = file.name.split('.')
  3.         val regionX = splitted[1].toInt()
  4.         val regionZ = splitted[2].toInt()
  5.         if (locations.none { it.shouldSaveRegion(regionX, regionZ) }) {
  6.             println("Skipping region $regionX $regionZ")
  7.             return
  8.         }
  9.         for (x in 0..31) {
  10.             for (z in 0..31) {
  11.                 val chunkX = regionX * 32 + x
  12.                 val chunkZ = regionZ * 32 + z
  13.                 val input = RegionFileCache.getChunkInputStream(oldWorld, chunkX, chunkZ)
  14.                 if (input != null) {
  15.                     val tag = CompressedStreamTools.read(input)
  16.                     input.close()
  17.                     processChunk(tag, chunkX, chunkZ)
  18.                 }
  19.             }
  20.         }
  21.     }
  22.  
  23.     internal fun processChunk(tag: NBTTagCompound, x: Int, z: Int) {
  24.         if (locations.none { it.shouldSaveChunk(x, z) }) {
  25.             println("Skipping chunk $x $z")
  26.             return;
  27.         }
  28.  
  29.         val level = tag.getCompoundTag("Level")
  30.         val entities = level.getTagList("Entities")
  31.         if (setToTaiga) {
  32.             level.setByteArray("Biomes", ByteArray(256, { 12 }))
  33.         }
  34.         if (!noRemove) {
  35.             val numEntities = entities.tagCount()
  36.             for (i in entities.tagCount() - 1 downTo 0) {
  37.                 val entity = entities.tagAt(i) as NBTTagCompound
  38.                 if (entity.getString("id").toLowerCase().startsWith("npc")) {
  39.                     val owner = entity.getString("owner")
  40.                     if (owner != "" && owner != "Helper" && owner != "Reiker") {
  41.                         entities.removeTag(i)
  42.                     }
  43.                 } else if (entity.getString("id") != "Painting") {
  44.                     entities.removeTag(i);
  45.                 }
  46.             }
  47.             val numRemoved = numEntities - entities.tagCount()
  48.             if (numRemoved > 0) {
  49.                 println("Removed $numRemoved entities from chunk $x $z")
  50.             }
  51.  
  52.             val tileEntities = level.getTagList("TileEntities")
  53.             for (i in 0..tileEntities.tagCount() - 1) {
  54.                 val tileEntity = tileEntities.tagAt(i) as NBTTagCompound
  55.                 tileEntity.removeTag("Items")
  56.             }
  57.         }
  58.  
  59.         locations.filter { it.shouldSaveChunk(x, z) }.forEach { it.saveChunk(tag.copy() as NBTTagCompound, x, z) }
  60.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement