Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import net.fabricmc.loom.task.RemapJarTask
plugins {
kotlin("jvm") version ("2.1.0")
id("architectury-plugin") version "3.4-SNAPSHOT"
id("dev.architectury.loom") version "1.9-SNAPSHOT" apply false
id("dev.architectury.loom") version "1.10-SNAPSHOT" apply false
id("com.github.johnrengelman.shadow") version "8.1.1" apply false
}

Expand Down
2 changes: 1 addition & 1 deletion common/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
architectury { common("fabric", "forge") }
architectury { common("fabric") }

loom {
accessWidenerPath.set(File("src/main/resources/worldtools.accesswidener"))
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/kotlin/org/waste/of/time/WorldTools.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ object WorldTools {
const val MAX_LEVEL_NAME_LENGTH = 64
const val TIMESTAMP_KEY = "CaptureTimestamp"
val GSON: Gson = GsonBuilder().setPrettyPrinting().create()
val CURRENT_VERSION = SharedConstants.getGameVersion().saveVersion.id
val CURRENT_VERSION = SharedConstants.getGameVersion().dataVersion().id
private val VERSION: String = LoaderInfo.getVersion()
val CREDIT_MESSAGE = "This file was created by $MOD_NAME $VERSION ($URL)"
val CREDIT_MESSAGE_MD = "This file was created by [$MOD_NAME $VERSION]($URL)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import net.minecraft.nbt.NbtCompound
import net.minecraft.nbt.NbtIo
import net.minecraft.registry.Registries
import net.minecraft.util.Identifier
import net.minecraft.util.PathUtil
import net.minecraft.util.path.PathUtil
import net.minecraft.util.ThrowableDeliverer
import net.minecraft.util.math.BlockPos
import net.minecraft.util.math.ChunkPos
Expand All @@ -16,6 +16,7 @@ import net.minecraft.world.storage.StorageKey
import org.waste.of.time.WorldTools.MCA_EXTENSION
import org.waste.of.time.WorldTools.MOD_NAME
import org.waste.of.time.WorldTools.mc
import net.minecraft.storage.NbtReadView
import java.io.DataOutput
import java.io.IOException
import java.nio.file.Path
Expand Down Expand Up @@ -68,11 +69,12 @@ open class CustomRegionBasedStorage internal constructor(

fun getBlockEntities(chunkPos: ChunkPos): List<BlockEntity> =
getNbtAt(chunkPos)
?.getList("block_entities", 10)
?.getList("block_entities")
?.orElse(null)
?.filterIsInstance<NbtCompound>()
?.mapNotNull { compoundTag ->
val blockPos = BlockPos(compoundTag.getInt("x"), compoundTag.getInt("y"), compoundTag.getInt("z"))
val blockStateIdentifier = Identifier.of(compoundTag.getString("id"))
val blockPos = BlockPos(compoundTag.getInt("x", 0), compoundTag.getInt("y", 0), compoundTag.getInt("z", 0))
val blockStateIdentifier = Identifier.of(compoundTag.getString("id", ""))
val world = mc.world ?: return@mapNotNull null

runCatching {
Expand All @@ -81,7 +83,7 @@ open class CustomRegionBasedStorage internal constructor(
.getOptionalValue(blockStateIdentifier)
.orElse(null)
?.instantiate(blockPos, block.defaultState)?.apply {
read(compoundTag, world.registryManager)
read(NbtReadView.create(null,null,compoundTag))
}
}.getOrNull()
} ?: emptyList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@ import org.waste.of.time.Utils.toByte
import org.waste.of.time.WorldTools.TIMESTAMP_KEY
import org.waste.of.time.WorldTools.config
import org.waste.of.time.storage.Cacheable
import net.minecraft.util.ErrorReporter
import net.minecraft.storage.NbtWriteView

data class EntityCacheable(
val entity: Entity
) : Cacheable {
fun compound() = NbtCompound().apply {


fun compound() = NbtWriteView.create(ErrorReporter.EMPTY).apply {
// saveSelfNbt has a check for RemovalReason.DISCARDED
EntityType.getId(entity.type)?.let { putString(Entity.ID_KEY, it.toString()) }
entity.writeNbt(this)
entity.writeData(this)

if (config.entity.behavior.modifyEntityBehavior) {
putByte("NoAI", config.entity.behavior.noAI.toByte())
Expand All @@ -26,7 +30,7 @@ data class EntityCacheable(
if (config.entity.metadata.captureTimestamp) {
putLong(TIMESTAMP_KEY, System.currentTimeMillis())
}
}
}.nbt

override fun cache() {
HotCache.entities.computeIfAbsent(entity.chunkPos) { mutableSetOf() }.apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.mojang.serialization.JsonOps
import net.minecraft.advancement.PlayerAdvancementTracker
import net.minecraft.datafixer.DataFixTypes
import net.minecraft.text.MutableText
import net.minecraft.util.PathUtil
import net.minecraft.util.path.PathUtil
import net.minecraft.util.WorldSavePath
import net.minecraft.world.level.storage.LevelStorage
import org.waste.of.time.WorldTools.CURRENT_VERSION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ class EndFlow : Storeable() {
currentLevelName
).copy().styled {
it.withClickEvent(
ClickEvent(
ClickEvent.Action.OPEN_FILE,
ClickEvent.OpenFile(
session.getDirectory(WorldSavePath.ROOT).toFile().path
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ import org.waste.of.time.manager.MessageManager
import org.waste.of.time.manager.MessageManager.translateHighlight
import org.waste.of.time.storage.CustomRegionBasedStorage
import org.waste.of.time.storage.Storeable
import net.minecraft.storage.NbtWriteView
import net.minecraft.nbt.NbtOps
import java.io.File
import java.io.IOException
import net.minecraft.util.ErrorReporter

class LevelDataStoreable : Storeable() {
override fun shouldStore() = config.general.capture.levelData
Expand Down Expand Up @@ -83,10 +86,10 @@ class LevelDataStoreable : Storeable() {
// skip removed features

put("Version", NbtCompound().apply {
putString("Name", SharedConstants.getGameVersion().name)
putInt("Id", SharedConstants.getGameVersion().saveVersion.id)
putBoolean("Snapshot", !SharedConstants.getGameVersion().isStable)
putString("Series", SharedConstants.getGameVersion().saveVersion.series)
putString("Name", SharedConstants.getGameVersion().name())
putInt("Id", SharedConstants.getGameVersion().dataVersion().id)
putBoolean("Snapshot", !SharedConstants.getGameVersion().stable())
putString("Series", SharedConstants.getGameVersion().dataVersion().series)
})

NbtHelper.putDataVersion(this)
Expand All @@ -95,8 +98,8 @@ class LevelDataStoreable : Storeable() {
mc.networkHandler?.listedPlayerListEntries?.find {
it.profile.id == player.uuid
}?.let {
putInt("GameType", it.gameMode.id)
} ?: putInt("GameType", player.server?.defaultGameMode?.id ?: 0)
putInt("GameType", it.gameMode.index)
} ?: putInt("GameType", player.server?.defaultGameMode?.index ?: 0)

putInt("SpawnX", player.world.levelProperties.spawnPos.x)
putInt("SpawnY", player.world.levelProperties.spawnPos.y)
Expand Down Expand Up @@ -124,11 +127,13 @@ class LevelDataStoreable : Storeable() {
// ToDo: Seems that the client side game rules were removed. Now only works for single player :/
val rules = player.world?.server?.gameRules?.genGameRules() ?: NbtCompound()
put("GameRules", rules)
put("Player", NbtCompound().apply {
player.writeNbt(this)
remove("LastDeathLocation") // can contain sensitive information

val view = NbtWriteView.create(ErrorReporter.EMPTY).apply {
player.writeData(this)
remove("LastDeathLocation")
putString("Dimension", "minecraft:${player.world.registryKey.value.path}")
})
}
put("Player", view.nbt)

put("DragonFight", NbtCompound()) // not sure
put("CustomBossEvents", NbtCompound()) // not sure
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.waste.of.time.storage.serializable

import net.minecraft.item.map.MapState
import net.minecraft.nbt.NbtCompound
import net.minecraft.nbt.NbtHelper
import net.minecraft.nbt.NbtIo
Expand Down Expand Up @@ -43,7 +44,7 @@ class MapDataStoreable : Storeable() {
}?.forEach { (component, mapState) ->
val id = component.id
NbtCompound().apply {
put("data", mapState.writeNbt(NbtCompound(), world.registryManager))
put("data", MapState.CODEC, mapState)
NbtHelper.putDataVersion(this)
val mapFile = dataDirectory.resolve("map_$id${WorldTools.DAT_EXTENSION}")
if (!mapFile.exists()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package org.waste.of.time.storage.serializable

import net.minecraft.client.network.PlayerListEntry
import net.minecraft.text.MutableText
import net.minecraft.util.PathUtil
import net.minecraft.util.path.PathUtil
import net.minecraft.util.WorldSavePath
import net.minecraft.world.level.storage.LevelStorage.Session
import org.waste.of.time.Utils
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import org.waste.of.time.storage.cache.HotCache
import java.io.File
import java.nio.file.Files
import java.nio.file.Path
import net.minecraft.util.ErrorReporter
import net.minecraft.storage.NbtWriteView

data class PlayerStoreable(
val player: PlayerEntity
Expand Down Expand Up @@ -56,16 +58,23 @@ data class PlayerStoreable(
}

private fun savePlayerData(player: PlayerEntity, session: Session) {

try {
val playerDataDir = session.getDirectory(WorldSavePath.PLAYERDATA).toFile()
playerDataDir.mkdirs()

val newPlayerFile = File.createTempFile(player.uuidAsString + "-", ".dat", playerDataDir).toPath()
NbtIo.writeCompressed(player.writeNbt(NbtCompound()).apply {
if (config.entity.censor.lastDeathLocation) {


val view = NbtWriteView.create(ErrorReporter.EMPTY).apply {
player.writeData(this)
if (config.entity.censor.lastDeathLocation) {
remove("LastDeathLocation")
}
}, newPlayerFile)
}

//writeCompresesed wants a compound tag and a path
NbtIo.writeCompressed(view.nbt, newPlayerFile)
val currentFile = File(playerDataDir, player.uuidAsString + ".dat").toPath()
val backupFile = File(playerDataDir, player.uuidAsString + ".dat_old").toPath()
Util.backupAndReplace(currentFile, newPlayerFile, backupFile)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ open class RegionBasedChunk(
putLong(TIMESTAMP_KEY, System.currentTimeMillis())
}

putInt("DataVersion", SharedConstants.getGameVersion().saveVersion.id)
putInt("DataVersion", SharedConstants.getGameVersion().dataVersion().id)
putInt(SerializedChunk.X_POS_KEY, chunk.pos.x)
putInt("yPos", chunk.bottomSectionCoord)
putInt(SerializedChunk.Z_POS_KEY, chunk.pos.z)
Expand Down Expand Up @@ -231,16 +231,7 @@ open class RegionBasedChunk(

private fun NbtCompound.getTickSchedulers(chunk: WorldChunk) {
val time = chunk.world.levelProperties.time
val tickSchedulers = chunk.getTickSchedulers(time)

val blockTickSchedulers = tickSchedulers.blocks.map { ticker ->
ticker.toNbt { Registries.BLOCK.getId(it).toString()}
}
put("block_ticks", NbtList().apply { addAll(blockTickSchedulers) })
val fluidTickSchedulers = tickSchedulers.fluids.map { ticker ->
ticker.toNbt { Registries.FLUID.getId(it).toString()}
}
put("fluid_ticks", NbtList().apply { addAll(fluidTickSchedulers) })
SerializedChunk.serializeTicks(this, chunk.getTickSchedulers(time))
}

private fun NbtCompound.genPostProcessing(chunk: WorldChunk) {
Expand All @@ -250,7 +241,7 @@ open class RegionBasedChunk(
chunk.heightmaps.filter {
chunk.status.heightmapTypes.contains(it.key)
}.forEach { (key, value) ->
put(key.getName(), NbtLongArray(value.asLongArray()))
put(key.id, NbtLongArray(value.asLongArray()))
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class RegionBasedEntities(
}
})

putInt("DataVersion", SharedConstants.getGameVersion().saveVersion.id)
putInt("DataVersion", SharedConstants.getGameVersion().dataVersion().id)
put("Position", NbtIntArray(intArrayOf(chunkPos.x, chunkPos.z)))
if (config.debug.logSavedEntities) {
entities.forEach { entity -> LOG.info("Entity saved: $entity (Chunk: $chunkPos)") }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package org.waste.of.time.storage.serializable
import com.google.gson.JsonObject
import net.minecraft.registry.Registries
import net.minecraft.text.MutableText
import net.minecraft.util.PathUtil
import net.minecraft.util.path.PathUtil
import net.minecraft.util.WorldSavePath
import net.minecraft.world.level.storage.LevelStorage
import org.waste.of.time.manager.MessageManager.translateHighlight
Expand Down
3 changes: 2 additions & 1 deletion common/src/main/resources/worldtools.accesswidener
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ accessible method net/minecraft/client/world/ClientWorld getMapStates ()Ljava/ut
accessible field net/minecraft/entity/player/PlayerEntity enderChestInventory Lnet/minecraft/inventory/EnderChestInventory;
accessible method net/minecraft/block/entity/LockableContainerBlockEntity getHeldStacks ()Lnet/minecraft/util/collection/DefaultedList;
accessible method net/minecraft/block/entity/LockableContainerBlockEntity setHeldStacks (Lnet/minecraft/util/collection/DefaultedList;)V
accessible method net/minecraft/world/chunk/SerializedChunk toNbt ([Lit/unimi/dsi/fastutil/shorts/ShortList;)Lnet/minecraft/nbt/NbtList;
accessible method net/minecraft/world/chunk/SerializedChunk toNbt ([Lit/unimi/dsi/fastutil/shorts/ShortList;)Lnet/minecraft/nbt/NbtList;
accessible method net/minecraft/world/chunk/SerializedChunk serializeTicks (Lnet/minecraft/nbt/NbtCompound;Lnet/minecraft/world/chunk/Chunk$TickSchedulers;)V
2 changes: 1 addition & 1 deletion fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"depends": {
"fabricloader": ">=${fabric_loader_version}",
"fabric-api": "*",
"minecraft": ["1.21.4"],
"minecraft": ["1.21.8"],
"java": ">=21",
"fabric-language-kotlin": ">=${fabric_kotlin_version}",
"cloth-config": ">=15"
Expand Down
51 changes: 0 additions & 51 deletions forge/build.gradle.kts

This file was deleted.

1 change: 0 additions & 1 deletion forge/gradle.properties

This file was deleted.

10 changes: 0 additions & 10 deletions forge/src/main/java/org/waste/of/time/forge/LoaderInfoImpl.java

This file was deleted.

Loading
Loading