Skip to content

Commit

Permalink
[WIP] refactor: Build a new tracking & versioning system (#7)
Browse files Browse the repository at this point in the history
* refactor: Deprecated old tracking classes

* refactor: Change type of entities in structure

Change type of `entities` from `List<NbtCompound>` to `Map<UUID, NbtCompound>` where `UUID` is `java.util.UUID`

Signed-off-by: Qian Qian "Cubik"‎ <cubik65536@cubik65536.top>

* feat: [NOT GREAT, DON'T WORK] Add new RVC IO and Tracked Structure designs

* feat: some code 4 tracking

* feat: add some fields

* feat: [DRAFT] New RVC IO architecture

Signed-off-by: Qian Qian "Cubik"‎ <cubik65536@cubik65536.top>

* fix: Fix TrackedStructure IO

Signed-off-by: Qian Qian "Cubik"‎ <cubik65536@cubik65536.top>

* feat: block events IO (Draft)

* refactor: Reorganize RVC IO architecture

Signed-off-by: Qian Qian "Cubik"‎ <cubik65536@cubik65536.top>

* refactor: RvcGitIO params

Signed-off-by: Qian Qian "Cubik"‎ <cubik65536@cubik65536.top>

* refactor: Change RVC file extension to `.rvc`

Signed-off-by: Qian Qian "Cubik"‎ <cubik65536@cubik65536.top>

* chore: Add data separator for RvcFileIO

Signed-off-by: Qian Qian "Cubik"‎ <cubik65536@cubik65536.top>

* refactor: Encapsulate RVC File IO functions

Signed-off-by: Qian Qian "Cubik"‎ <cubik65536@cubik65536.top>

* feat: Add part of RvcFile save

Signed-off-by: Qian Qian "Cubik"‎ <cubik65536@cubik65536.top>

* refactor: Improve tick saving for RVC File IO

Signed-off-by: Qian Qian "Cubik"‎ <cubik65536@cubik65536.top>

* feat: Add part of RvcFile load

Signed-off-by: Qian Qian "Cubik"‎ <cubik65536@cubik65536.top>

* fix: undo perm check crash

* chore

* feat: scheduled ticks

* refactor: remove unused files

* feat(RvcFileIO): Add some save/load funcs

TrackPoint deserialization needs to be implemented.

Signed-off-by: Qian Qian "Cubik"‎ <cubik65536@cubik65536.top>

* feat: Add `RvcDataReader` to properly read some RVC data

Signed-off-by: Qian Qian "Cubik"‎ <cubik65536@cubik65536.top>

* refactor: Improve RVC data file header read func

Signed-off-by: Qian Qian "Cubik"‎ <cubik65536@cubik65536.top>

* feat: IRvcFileReader

* chore: add jgit dependency

* style(RvcFileIO): Format document

Signed-off-by: Qian Qian "Cubik"‎ <cubik65536@cubik65536.top>

* refactor(RvcFileIO): Move `.forEach` to save data to `.entries.joinToString`

Signed-off-by: Qian Qian "Cubik"‎ <cubik65536@cubik65536.top>

* refactor(RvcFileIO): SImplify save codes

Signed-off-by: Qian Qian "Cubik"‎ <cubik65536@cubik65536.top>

* refactor: Build the new RvcFileReader architecture

Signed-off-by: Qian Qian "Cubik"‎ <cubik65536@cubik65536.top>

* feat: Complete RvcReader for version 1

Signed-off-by: Qian Qian "Cubik"‎ <cubik65536@cubik65536.top>

---------

Signed-off-by: Qian Qian "Cubik"‎ <cubik65536@cubik65536.top>
Co-authored-by: Liyan Zhao <return65535@qq.com>
  • Loading branch information
Cubik65536 and zly2006 authored Aug 30, 2023
1 parent 5eb88e3 commit 2cea96e
Show file tree
Hide file tree
Showing 19 changed files with 603 additions and 649 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ dependencies {
include(implementation("org.bouncycastle:bcprov-jdk18on:1.76"))
include(implementation("org.bouncycastle:bcpg-jdk18on:1.76"))
include(implementation("com.squareup.okhttp3:okhttp:4.11.0"))
include(implementation("org.eclipse.jgit:org.eclipse.jgit:6.6.0.202305301015-r"))
include(implementation("com.squareup.okio:okio-jvm:3.2.0"))
modImplementation "curse.maven:litematica-308892:4626718"
modImplementation "maven.modrinth:modmenu:7.2.1"
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/github/zly2006/reden/rvc/DummyStructure.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import net.minecraft.nbt.NbtCompound
import net.minecraft.util.math.BlockPos
import net.minecraft.world.World
import java.nio.file.Path
import java.util.*

open class DummyStructure(
final override var name: String,
Expand Down Expand Up @@ -66,7 +67,7 @@ open class DummyStructure(
return (blockState.block as BlockEntityProvider).createBlockEntity(pos, blockState)!!.createNbt()
}

override val entities: List<NbtCompound>
override val entities: Map<UUID, NbtCompound>
get() = TODO("Not yet implemented")

}
3 changes: 2 additions & 1 deletion src/main/java/com/github/zly2006/reden/rvc/IStructure.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import net.minecraft.nbt.NbtCompound
import net.minecraft.util.math.BlockPos
import net.minecraft.world.World
import java.nio.file.Path
import java.util.*

interface IStructure {
var name: String
Expand All @@ -18,5 +19,5 @@ interface IStructure {
fun getBlockState(pos: BlockPos): BlockState
fun getBlockEntityData(pos: BlockPos): NbtCompound?
fun getOrCreateBlockEntityData(pos: BlockPos): NbtCompound
val entities: List<NbtCompound>
val entities: Map<UUID, NbtCompound>
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package com.github.zly2006.reden.rvc
import net.minecraft.block.BlockState
import net.minecraft.nbt.NbtCompound
import net.minecraft.util.math.BlockPos
import java.util.*

interface IWritableStructure: IStructure {
fun setBlockState(pos: BlockPos, state: BlockState)

override val entities: MutableList<NbtCompound>
override val entities: MutableMap<UUID, NbtCompound>

/**
* copy block & entity data
Expand All @@ -27,7 +28,7 @@ interface IWritableStructure: IStructure {
}
}
entities.clear()
entities.addAll(another.entities)
entities.putAll(another.entities)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import net.minecraft.block.Blocks
import net.minecraft.nbt.NbtCompound
import net.minecraft.util.math.BlockPos
import java.nio.file.Path
import java.util.*

abstract class ReadWriteStructure(override var name: String) : IWritableStructure {
protected var io: StructureIO? = null
val blocks = mutableMapOf<BlockPos, BlockState>()
val blockEntities = mutableMapOf<BlockPos, NbtCompound>()
override val entities = mutableListOf<NbtCompound>()
override val entities = mutableMapOf<UUID, NbtCompound>()
override fun setBlockState(pos: BlockPos, state: BlockState) { blocks[pos] = state }
override fun getBlockState(pos: BlockPos) = blocks[pos] ?: Blocks.AIR.defaultState!!
override fun getBlockEntityData(pos: BlockPos) = blockEntities[pos]
Expand All @@ -26,7 +27,7 @@ abstract class ReadWriteStructure(override var name: String) : IWritableStructur
blockEntities.clear()
blockEntities.putAll(another.blockEntities)
entities.clear()
entities.addAll(another.entities)
entities.putAll(another.entities)
} else super.assign(another)
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/github/zly2006/reden/rvc/io/SchematicIO.kt
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ class SchematicStructure: SchematicFormat() {
template.blockInfoLists.add(StructureTemplate.PalettedBlockInfoList(list))
template.entities.clear()
template.entities.addAll(schematic.entities.map {
val posNbt = it.getList("Pos", NbtElement.DOUBLE_TYPE.toInt())
val posNbt = it.value.getList("Pos", NbtElement.DOUBLE_TYPE.toInt())
val pos = Vec3d(posNbt.getDouble(0), posNbt.getDouble(1), posNbt.getDouble(2))
StructureTemplate.StructureEntityInfo(
pos,
BlockPos.ofFloored(pos),
it
it.value
)
})
template.writeNbt(tagCompound)
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package com.github.zly2006.reden.rvc.tracking

import net.minecraft.util.math.BlockPos
import net.minecraft.block.BlockState
import net.minecraft.nbt.NbtCompound
import net.minecraft.server.world.BlockEvent
import java.util.UUID

/**
* Interface that defines the data reading methods for
* reading RVC data and transform to [TrackedStructure] structures.
*/
interface IRvcFileReader {

/**
* Read blocks data from RVC files to maps for structure
* @param data Lines contains data read form RVC files
* @return [Map]<[BlockPos], [BlockState]> data that can be saved to a [TrackedStructure]
*/
fun readBlocksData(data: List<String>): Map<BlockPos, BlockState>

/**
* Read blocks entities data from RVC files to maps for structure
* @param data Lines contains data read form RVC files
* @return [Map]<[BlockPos], [NbtCompound]> data that can be saved to a [TrackedStructure]
*/
fun readBlockEntitiesData(data: List<String>): Map<BlockPos, NbtCompound>

/**
* Read entities data from RVC files to maps for structure
* @param data Lines contains data read form RVC files
* @return [Map]<[UUID], [NbtCompound]> data that can be saved to a [TrackedStructure]
*/
fun readEntitiesData(data: List<String>): Map<UUID, NbtCompound>

/**
* Read track point data from RVC files to list for structure
* @param data Lines contains data read form RVC files
* @return [List]<[TrackedStructure.TrackPoint]> data that can be saved to a [TrackedStructure]
*/
fun readTrackPointData(data: List<String>): List<TrackedStructure.TrackPoint>

/**
* Read block events data from RVC files to list for structure
* @param data Lines contains data read form RVC files
* @return [List]<[BlockEvent]> data that can be saved to a [TrackedStructure]
*/
fun readBlockEventsData(data: List<String>): List<BlockEvent>

/**
* Read scheduled ticks data from RVC files to list for structure.
* (This is used for both block scheduled ticks and fluid scheduled ticks.)
* @param data Lines contains data read form RVC files
* @return [List]<[NbtCompound]> data that can be saved to a [TrackedStructure]
*/
fun readScheduledTicksData(data: List<String>): List<NbtCompound>

/**
* RVC File with a [IRvcFileReader] (for the corresponding data version)
* and data [List] of [String]s.
*/
data class RvcFile(
val reader: IRvcFileReader,
val data: List<String>
)

/**
* RVC File metadata header
*/
data class RvcHeader(
val metadata: MutableMap<String, String> = mutableMapOf()
) {
/**
* @param header The string containing the header data from the RVC file.
*/
constructor(header: String): this() {
if (!header.startsWith("RVC; ")) {
throw IllegalArgumentException("Invalid RVC header")
}
header.split("; ").drop(1).forEach {
val key = it.substringBefore(": ")
val value = it.substringAfter(": ")
metadata[key] = value
}
}

/**
* @return Generated RVC data string for RVC data files.
*/
override fun toString(): String {
var str = "RVC; "
metadata.forEach { (key, value) ->
str += "$key: $value; "
}
return str.substring(0, str.length - 2)
}
}
}
Loading

0 comments on commit 2cea96e

Please sign in to comment.