GithubHelp home page GithubHelp logo

powernukkit / region-manipulator Goto Github PK

View Code? Open in Web Editor NEW
9.0 4.0 3.0 9.22 MB

A kotlin/java lib that allows you to read and write MCA files in a clean way

License: MIT License

Kotlin 99.70% CSS 0.30%
kotlin-library java-library mca-region anvil mca-file mca chunk minecraft-world minecraft minecraft-library

region-manipulator's Introduction

Region Manipulator

A Kotlin/Java library that allows you to read and write mca files in a simple way.

Here you can find the library documentation:

You may also want to see the changelog file to be aware of all changes in the tool that may impact you.

Adding to your project

The library is shared in the maven center, so you don't need to declare any custom repository.

Gradle

repositories {
    mavenCentral() // or jcenter()
}

dependencies {
    compile 'br.com.gamemods:region-manipulator:2.0.0'
}

Maven

<dependencies>
    <dependency>
      <groupId>br.com.gamemods</groupId>
      <artifactId>region-manipulator</artifactId>
      <version>2.0.0</version>
    </dependency>
</dependencies>

Ivy

<dependency org="br.com.gamemods" name="region-manipulator" rev="2.0.0"/>

Direct JAR

Download it from maven central.

Examples

internal fun clearEntities(from: File, to: File) {
    val region = RegionIO.readRegion(from)
    val chunk = region[ChunkPos(region.position.xPos * 32, region.position.zPos * 32)] ?: return
    chunk.level.getCompoundList("Entities").forEach { 
        println(it.getString("id") + " "+ it.getDoubleList("Pos"))
    }
    chunk.level["Entities"] = emptyListOf<NbtCompound>().toNbtList()
    RegionIO.writeRegion(to, region)
}

region-manipulator's People

Contributors

joserobjr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

region-manipulator's Issues

kotlin.KotlinNullPointerException when reading a region file

That's why we should never use !!.

kotlin.KotlinNullPointerException
	at br.com.gamemods.regionmanipulator.RegionIO.readRegion(RegionIO.kt:47)
	at br.com.gamemods.regionmanipulator.RegionIO.readRegion(RegionIO.kt:26)
	at br.com.gamemods.j2nwc.internal.RegionFileConverter.convertRegionFile(RegionFileConverter.kt:18)
	at br.com.gamemods.j2nwc.WorldConverter.convert(WorldConverter.kt:101)
	at br.com.gamemods.worldrepo.MundoJava.converterParaNukkit(MundoJava.kt:29)
	at br.com.gamemods.worldrepo.MundoConstrucao.publicar(MundoConstrucao.kt:181)
	at br.com.gamemods.worldrepo.ImportadorDeMundo$Companion.importarLegado(ImportadorDeMundo.kt:104)
	at privado.Importar_legadoKt.main(importar-legado.kt:16)
	at privado.Importar_legadoKt.main(importar-legado.kt)

The failing region file:
r.0.-1.mca.zip

IndexOutOfBoundsException when writing an empty chunk

java.lang.IndexOutOfBoundsException
	at java.nio.ByteBuffer.wrap(ByteBuffer.java:375)
	at br.com.gamemods.regionmanipulator.RegionIO.writeRegion(RegionIO.kt:133)
	at br.com.gamemods.regionmanipulator.RegionTest.testReadMCA1(RegionTest.kt:18)

Corrupt chunk prevents the entire region to load

java.io.UTFDataFormatException: malformed input around byte 1
	at java.io.DataInputStream.readUTF(DataInputStream.java:656)
	at java.io.DataInputStream.readUTF(DataInputStream.java:564)
	at br.com.gamemods.nbtmanipulator.NbtCompoundSerial.readTag(NbtIO.kt:244)
	at br.com.gamemods.nbtmanipulator.NbtCompoundSerial.readTag(NbtIO.kt:235)
	at br.com.gamemods.nbtmanipulator.NbtListSerial.readTag(NbtIO.kt:213)
	at br.com.gamemods.nbtmanipulator.NbtListSerial.readTag(NbtIO.kt:203)
	at br.com.gamemods.nbtmanipulator.NbtCompoundSerial.readTag(NbtIO.kt:246)
	at br.com.gamemods.nbtmanipulator.NbtCompoundSerial.readTag(NbtIO.kt:235)
	at br.com.gamemods.nbtmanipulator.NbtCompoundSerial.readTag(NbtIO.kt:246)
	at br.com.gamemods.nbtmanipulator.NbtCompoundSerial.readTag(NbtIO.kt:235)
	at br.com.gamemods.nbtmanipulator.NbtIO.readNbtFile(NbtIO.kt:65)
	at br.com.gamemods.regionmanipulator.RegionIO.readRegion(RegionIO.kt:69)
	at br.com.gamemods.regionmanipulator.RegionIO.readRegion(RegionIO.kt:26)
	at br.com.gamemods.j2nwc.internal.RegionFileConverter.convertRegionFile(RegionFileConverter.kt:18)
	at br.com.gamemods.j2nwc.WorldConverter.convert(WorldConverter.kt:101)
	at br.com.gamemods.worldrepo.MundoJava.converterParaNukkit(MundoJava.kt:29)
	at br.com.gamemods.worldrepo.MundoConstrucao.publicar(MundoConstrucao.kt:181)
	at br.com.gamemods.worldrepo.ImportadorDeMundo$Companion.importarLegado(ImportadorDeMundo.kt:104)
	at privado.Importar_legadoKt.main(importar-legado.kt:16)
	at privado.Importar_legadoKt.main(importar-legado.kt)

Should allow to load the region but without the corrupted chunk.

The failing region file:
r.-1.-1.mca.zip

Proof that it is corrupted:

Error upgrading chunk [-24, -17]
java.io.UTFDataFormatException: malformed input around byte 1
	at java.io.DataInputStream.readUTF(DataInputStream.java:656) ~[?:1.8.0_201]
	at java.io.DataInputStream.readUTF(DataInputStream.java:564) ~[?:1.8.0_201]
	at net.minecraft.server.v1_14_R1.NBTTagCompound.b(SourceFile:431) ~[spigot-1.14.2-R0.1-SNAPSHOT.jar:git-Spigot-093165d-cb3d14c]
	at net.minecraft.server.v1_14_R1.NBTTagCompound.load(SourceFile:78) ~[spigot-1.14.2-R0.1-SNAPSHOT.jar:git-Spigot-093165d-cb3d14c]
	at net.minecraft.server.v1_14_R1.NBTTagList.load(SourceFile:65) ~[spigot-1.14.2-R0.1-SNAPSHOT.jar:git-Spigot-093165d-cb3d14c]
	at net.minecraft.server.v1_14_R1.NBTTagCompound.a(SourceFile:438) ~[spigot-1.14.2-R0.1-SNAPSHOT.jar:git-Spigot-093165d-cb3d14c]
	at net.minecraft.server.v1_14_R1.NBTTagCompound.load(SourceFile:81) ~[spigot-1.14.2-R0.1-SNAPSHOT.jar:git-Spigot-093165d-cb3d14c]
	at net.minecraft.server.v1_14_R1.NBTTagCompound.a(SourceFile:438) ~[spigot-1.14.2-R0.1-SNAPSHOT.jar:git-Spigot-093165d-cb3d14c]
	at net.minecraft.server.v1_14_R1.NBTTagCompound.load(SourceFile:81) ~[spigot-1.14.2-R0.1-SNAPSHOT.jar:git-Spigot-093165d-cb3d14c]
	at net.minecraft.server.v1_14_R1.NBTCompressedStreamTools.a(NBTCompressedStreamTools.java:114) ~[spigot-1.14.2-R0.1-SNAPSHOT.jar:git-Spigot-093165d-cb3d14c]
	at net.minecraft.server.v1_14_R1.NBTCompressedStreamTools.a(NBTCompressedStreamTools.java:83) ~[spigot-1.14.2-R0.1-SNAPSHOT.jar:git-Spigot-093165d-cb3d14c]
	at net.minecraft.server.v1_14_R1.NBTCompressedStreamTools.a(NBTCompressedStreamTools.java:73) ~[spigot-1.14.2-R0.1-SNAPSHOT.jar:git-Spigot-093165d-cb3d14c]
	at net.minecraft.server.v1_14_R1.RegionFileCache.read(RegionFileCache.java:55) ~[spigot-1.14.2-R0.1-SNAPSHOT.jar:git-Spigot-093165d-cb3d14c]
	at net.minecraft.server.v1_14_R1.WorldUpgrader.i(WorldUpgrader.java:120) ~[spigot-1.14.2-R0.1-SNAPSHOT.jar:git-Spigot-093165d-cb3d14c]
	at java.lang.Thread.run(Thread.java:748) [?:1.8.0_201]

Removing existing chunks from region throws server errors when loaded.

After removing a bunch of chunks from a region folder, I receive errors like this the next time the server starts up:

[01:43:06] [chunk IO worker/WARN]: Chunk [-8, -21] is allocated, but stream is missing
[01:43:06] [chunk IO worker/WARN]: Chunk [-7, -21] is allocated, but stream is missing
[01:43:06] [chunk IO worker/WARN]: Chunk [-6, -21] is allocated, but stream is missing
[01:44:38] [chunk IO worker/ERROR]: Chunk [-11, -26] header is truncated: expected 8192 but read 0
[01:44:38] [Server thread/ERROR]: Chunk file at [-9, -26] is in the wrong location; relocating. (Expected [-9, -26], got [-3, -6])
[01:44:38] [Server thread/WARN]: Found invalid structure reference [ Mineshaft @ [2, -4] ] for chunk [-9, -26].
[01:44:38] [chunk IO worker/WARN]: Chunk [-8, -26] is allocated, but stream is missing
[01:44:38] [chunk IO worker/WARN]: Chunk has both internal and external streams
[01:44:38] [chunk IO worker/ERROR]: External chunk path .\world\region\c.-5.-26.mcc is not file
[01:44:38] [chunk IO worker/ERROR]: Chunk [-4, -26] header is truncated: expected 8192 but read 0
[01:44:38] [chunk IO worker/WARN]: Chunk [-3, -26] is allocated, but stream is missing
`

Basically, you should be able to remove almost all of a chunks in a region to recreate the issue. Here's a copy of the region files that gets corrupted:
r.-1.-1.zip

Corrupt Chunks Handling

There seem to be a lot of false-positives as far as corrupt chunks go. I can't really make a proper bug report since I can't read kotlin, but I seem to get a lot of instances where perfectly normal chunks are marked as corrupt.

Issue reading 1.15 region.

Hello,

I've been using this util in one of my plugins, and while updating my server to 1.15, I started receiving the following error: `

[21:25:55] [Server thread/WARN]: java.io.EOFException
[21:25:55] [Server thread/WARN]: at java.base/java.io.RandomAccessFile.readFully(Unknown Source)
[21:25:55] [Server thread/WARN]: at java.base/java.io.RandomAccessFile.readFully(Unknown Source)
[21:25:55] [Server thread/WARN]: at br.com.gamemods.regionmanipulator.RegionIO.readRegion(RegionIO.kt:63)
[21:25:55] [Server thread/WARN]: at br.com.gamemods.regionmanipulator.RegionIO.readRegion(RegionIO.kt:26)
[21:25:55] [Server thread/WARN]: at me.zombie_striker.chunkculler.Main.cullForWorld(Main.java:666)
[21:25:55] [Server thread/WARN]: at me.zombie_striker.chunkculler.Main.cullForWorld(Main.java:599)
[21:25:55] [Server thread/WARN]: at me.zombie_striker.chunkculler.Main.onDisable(Main.java:329)
[21:25:55] [Server thread/WARN]: at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:265)
[21:25:55] [Server thread/WARN]: at org.bukkit.plugin.java.JavaPluginLoader.disablePlugin(JavaPluginLoader.java:377)
[21:25:55] [Server thread/WARN]: at org.bukkit.plugin.SimplePluginManager.disablePlugin(SimplePluginManager.java:438)
[21:25:55] [Server thread/WARN]: at org.bukkit.plugin.SimplePluginManager.disablePlugins(SimplePluginManager.java:430)
[21:25:55] [Server thread/WARN]: at org.bukkit.craftbukkit.v1_15_R1.CraftServer.disablePlugins(CraftServer.java:396)
[21:25:55] [Server thread/WARN]: at net.minecraft.server.v1_15_R1.MinecraftServer.stop(MinecraftServer.java:698)
[21:25:55] [Server thread/WARN]: at net.minecraft.server.v1_15_R1.DedicatedServer.stop(DedicatedServer.java:683)
[21:25:55] [Server thread/WARN]: at net.minecraft.server.v1_15_R1.MinecraftServer.run(MinecraftServer.java:863)
[21:25:55] [Server thread/WARN]: at java.base/java.lang.Thread.run(Unknown Source)

My plugin worked on 1.14, and now this error appears whenever my plugin tries to read any chunk from my 1.15 world.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.