Skip to content

Commit

Permalink
1.20.2 port
Browse files Browse the repository at this point in the history
  • Loading branch information
rfresh2 committed Feb 5, 2024
1 parent 076b665 commit b984736
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 95 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/fabric-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- '[0-9]+.[0-9]+.[0-9]+'

env:
MINECRAFT_VERSION: "1.20.1"
MINECRAFT_VERSION: "1.20.2"

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/forge-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- '[0-9]+.[0-9]+.[0-9]+'

env:
MINECRAFT_VERSION: "1.20.1"
MINECRAFT_VERSION: "1.20.2"

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/github-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- '[0-9]+.[0-9]+.[0-9]+'

env:
MINECRAFT_VERSION: "1.20.1"
MINECRAFT_VERSION: "1.20.2"

jobs:
build:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private void onChunkLoad(final int x, final int z, final PacketByteBuf buf, fina
target = "Lnet/minecraft/client/world/ClientChunkManager$ClientChunkMap;compareAndSet(ILnet/minecraft/world/chunk/WorldChunk;Lnet/minecraft/world/chunk/WorldChunk;)Lnet/minecraft/world/chunk/WorldChunk;"
)
)
private void onChunkUnload(int chunkX, int chunkZ, CallbackInfo ci, @Local WorldChunk chunk) {
private void onChunkUnload(ChunkPos pos, CallbackInfo ci, @Local final WorldChunk chunk) {
Events.INSTANCE.onChunkUnload(chunk);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
package org.waste.of.time.storage.serializable

import com.google.gson.GsonBuilder
import net.minecraft.SharedConstants
import net.minecraft.advancement.AdvancementProgress
import com.mojang.serialization.JsonOps
import net.minecraft.advancement.PlayerAdvancementTracker
import net.minecraft.datafixer.DataFixTypes
import net.minecraft.text.MutableText
import net.minecraft.util.Identifier
import net.minecraft.util.PathUtil
import net.minecraft.util.Util
import net.minecraft.util.WorldSavePath
import net.minecraft.world.level.storage.LevelStorage
import org.waste.of.time.WorldTools
import org.waste.of.time.WorldTools.CURRENT_VERSION
import org.waste.of.time.WorldTools.GSON
import org.waste.of.time.WorldTools.LOG
import org.waste.of.time.WorldTools.config
import org.waste.of.time.WorldTools.mc
import org.waste.of.time.manager.MessageManager.translateHighlight
import org.waste.of.time.storage.CustomRegionBasedStorage
import org.waste.of.time.storage.Storeable
import java.lang.reflect.Type
import java.nio.charset.StandardCharsets
import java.nio.file.Files

class AdvancementsStoreable : Storeable {
override fun shouldStore() = config.capture.advancements
Expand All @@ -28,34 +31,41 @@ class AdvancementsStoreable : Storeable {
override val anonymizedInfo: MutableText
get() = verboseInfo

private val gson = GsonBuilder().registerTypeAdapter(
AdvancementProgress::class.java as Type,
AdvancementProgress.Serializer()
).registerTypeAdapter(
Identifier::class.java as Type,
Identifier.Serializer()
).setPrettyPrinting().create()
private val progressMapCodec =
DataFixTypes.ADVANCEMENTS.createDataFixingCodec(
PlayerAdvancementTracker.ProgressMap.CODEC, mc.dataFixer, CURRENT_VERSION
)

override fun store(
session: LevelStorage.Session,
cachedStorages: MutableMap<String, CustomRegionBasedStorage>
) {
val uuid = mc.player?.uuid ?: return
val progress = mc.player
?.networkHandler
?.advancementHandler
?.advancementProgresses ?: return
val progressMap = progress.entries
.filter { it.value.isAnyObtained }
.associate {
it.key.id to it.value
}
val jsonElement = Util.getResult(
progressMapCodec.encodeStart(
JsonOps.INSTANCE,
PlayerAdvancementTracker.ProgressMap(progressMap)
)
) { s -> IllegalStateException(s) }

val advancements = session.getDirectory(WorldSavePath.ADVANCEMENTS)
PathUtil.createDirectories(advancements)

val progress = mc.player?.networkHandler?.advancementHandler?.advancementProgresses ?: return

val progressMap = LinkedHashMap<Identifier, AdvancementProgress>()
progress.entries.forEach { (key, advancementProgress) ->
if (!advancementProgress.isAnyObtained) return@forEach
progressMap[key.id] = advancementProgress
Files.newBufferedWriter(
advancements.resolve("$uuid.json"),
StandardCharsets.UTF_8
).use { writer ->
GSON.toJson(jsonElement, writer)
}
val jsonElement = gson.toJsonTree(progressMap)
jsonElement.asJsonObject.addProperty("DataVersion", SharedConstants.getGameVersion().saveVersion.id)

advancements.resolve("$uuid.json").toFile().writeText(jsonElement.toString())

WorldTools.LOG.info("Saved ${progressMap.size} advancements.")
LOG.info("Saved ${progressMap.size} advancements.")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ import net.minecraft.util.WorldSavePath
import net.minecraft.world.GameRules
import net.minecraft.world.level.storage.LevelStorage.Session
import org.waste.of.time.Utils.addAuthor
import org.waste.of.time.manager.CaptureManager.currentLevelName
import org.waste.of.time.manager.MessageManager
import org.waste.of.time.manager.MessageManager.translateHighlight
import org.waste.of.time.WorldTools
import org.waste.of.time.WorldTools.DAT_EXTENSION
import org.waste.of.time.WorldTools.LOG
import org.waste.of.time.WorldTools.config
import org.waste.of.time.WorldTools.mc
import org.waste.of.time.storage.Storeable
import org.waste.of.time.manager.CaptureManager.currentLevelName
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 java.io.File
import java.io.IOException

Expand Down Expand Up @@ -69,8 +69,7 @@ class LevelDataStoreable : Storeable {
*/
private fun serializeLevelData() = NbtCompound().apply {
val player = mc.player ?: return@apply

player.serverBrand?.let {
mc.networkHandler?.brand?.let {
put("ServerBrands", NbtList().apply {
add(NbtString.of(it))
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
package org.waste.of.time.storage.serializable

import com.mojang.authlib.GameProfile
import net.minecraft.client.network.PlayerListEntry
import net.minecraft.text.MutableText
import net.minecraft.util.PathUtil
import net.minecraft.util.WorldSavePath
import net.minecraft.world.level.storage.LevelStorage.Session
import org.waste.of.time.manager.CaptureManager.currentLevelName
import org.waste.of.time.manager.CaptureManager.levelName
import org.waste.of.time.manager.CaptureManager.serverInfo
import org.waste.of.time.manager.MessageManager.translateHighlight
import org.waste.of.time.Utils
import org.waste.of.time.WorldTools.CREDIT_MESSAGE_MD
import org.waste.of.time.WorldTools.LOG
import org.waste.of.time.WorldTools.MOD_NAME
import org.waste.of.time.WorldTools.config
import org.waste.of.time.WorldTools.mc
import org.waste.of.time.storage.Storeable
import org.waste.of.time.storage.PathTreeNode
import org.waste.of.time.manager.BarManager
import org.waste.of.time.manager.CaptureManager.currentLevelName
import org.waste.of.time.manager.CaptureManager.levelName
import org.waste.of.time.manager.MessageManager.translateHighlight
import org.waste.of.time.storage.CustomRegionBasedStorage
import org.waste.of.time.storage.PathTreeNode
import org.waste.of.time.storage.StorageFlow
import org.waste.of.time.storage.Storeable
import java.net.InetSocketAddress
import java.nio.file.Path
import kotlin.io.path.writeBytes
Expand Down Expand Up @@ -76,17 +76,13 @@ class MetadataStoreable : Storeable {
}

private fun Session.writeIconFile() {
if (mc.isInSingleplayer) {
mc.server?.iconFile?.ifPresent { spIconPath ->
iconFile.ifPresent {
it.writeBytes(spIconPath.toFile().readBytes())
}
mc.networkHandler?.serverInfo?.favicon?.let { favicon ->
iconFile.ifPresent {
it.writeBytes(favicon)
}
} else {
serverInfo.favicon?.let { favicon ->
iconFile.ifPresent {
it.writeBytes(favicon)
}
} ?: mc.server?.iconFile?.ifPresent { spIconPath ->
iconFile.ifPresent {
it.writeBytes(spIconPath.toFile().readBytes())
}
}
LOG.info("Saved favicon.")
Expand All @@ -111,25 +107,28 @@ class MetadataStoreable : Storeable {

appendLine()

if (!mc.isInSingleplayer) {
mc.networkHandler?.serverInfo?.let { info ->
appendLine("## Server")
if (serverInfo.name != "Minecraft Server") {
appendLine("- **List Entry Name**: `${serverInfo.name}`")
if (info.name != "Minecraft Server") {
appendLine("- **List Entry Name**: `${info.name}`")
}
appendLine("- **IP**: `${serverInfo.address}`")
if (serverInfo.playerCountLabel.string.isNotBlank()) {
appendLine("- **Capacity**: `${serverInfo.playerCountLabel.string}`")
appendLine("- **IP**: `${info.address}`")
if (info.playerCountLabel.string.isNotBlank()) {
appendLine("- **Capacity**: `${info.playerCountLabel.string}`")
}
appendLine("- **Brand**: `${mc.player?.serverBrand}`")
appendLine("- **MOTD**: `${serverInfo.label.string.split("\n").joinToString(" ")}`")
appendLine("- **Version**: `${serverInfo.version.string}`")
mc.networkHandler?.let {
appendLine("- **Brand**: `${it.brand}`")
}
appendLine("- **MOTD**: `${info.label.string.split("\n").joinToString(" ")}`")
appendLine("- **Version**: `${info.version.string}`")
appendLine("- **Protocol Version**: `${info.protocolVersion}`")

serverInfo.players?.sample?.let { sample ->
if (sample.isEmpty()) return@let
info.players?.sample?.let l@ { sample ->
if (sample.isEmpty()) return@l
appendLine("- **Short Label**: `${sample.joinToString { it.name }}`")
}
serverInfo.playerListSummary?.let {
if (it.isEmpty()) return@let
info.playerListSummary?.let l@ {
if (it.isEmpty()) return@l
appendLine("- **Full Label**: `${it.joinToString(" ") { str -> str.string }}`")
}

Expand All @@ -139,7 +138,7 @@ class MetadataStoreable : Storeable {
appendLine("- **Host Name**: `${it.address.canonicalHostName}`")
appendLine("- **Port**: `${it.port}`")
}
} else {
} ?: run {
appendLine("## Singleplayer Capture")
appendLine("- **Source World Name**: `${mc.server?.name}`")
appendLine("- **Version**: `${mc.server?.version}`")
Expand All @@ -154,36 +153,25 @@ class MetadataStoreable : Storeable {
}.toString()

private fun createPlayerEntryList(listEntries: List<PlayerListEntry>) = StringBuilder().apply {
appendLine("Name, ID, Legacy, Complete, Properties, Game Mode, Latency, Session ID, Scoreboard Team, Model")
listEntries.forEach {
serializePlayerListEntry(it)
appendLine("Name, ID, Game Mode, Latency, Scoreboard Team, Model Type, Session ID, Public Key")

listEntries.forEachIndexed { i, entry ->
StorageFlow.lastStoredTimestamp = System.currentTimeMillis()
BarManager.progressBar.percent = i.toFloat() / listEntries.size
serializePlayerListEntry(entry)
}
}.toString()

private fun StringBuilder.serializePlayerListEntry(entry: PlayerListEntry) {
serializeGameProfile(entry.profile)
append("${entry.profile.name}, ")
append("${entry.profile.id}, ")
append("${entry.gameMode.name}, ")
append("${entry.latency}, ")
append("${entry.session?.sessionId}, ")
entry.session?.publicKeyData?.let {
append("Public Key Data: ${it.data} ")
}
append("${entry.scoreboardTeam?.name}, ")
appendLine(entry.model)
}

private fun StringBuilder.serializeGameProfile(gameProfile: GameProfile) {
append(gameProfile.name)
append(", ")
append(gameProfile.id)
append(", ")
append(gameProfile.isLegacy)
append(", ")
append(gameProfile.isComplete)
append(", ")
gameProfile.properties.forEach { t, u ->
append("[key: $t | name: ${u.name} | value: ${u.value} | signature: ${u.signature}] ")
appendLine(entry.skinTextures.model)
entry.session?.let {
append("${it.sessionId}, ")
append("${it.publicKeyData?.data}, ")
}
append(", ")
}
}
2 changes: 2 additions & 0 deletions common/src/main/resources/worldtools.accesswidener
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ accessWidener v2 named

accessible class net/minecraft/client/world/ClientChunkManager$ClientChunkMap
accessible method net/minecraft/client/world/ClientChunkManager$ClientChunkMap isInRadius (II)Z
accessible class net/minecraft/advancement/PlayerAdvancementTracker$ProgressMap
accessible method net/minecraft/advancement/PlayerAdvancementTracker$ProgressMap <init> (Ljava/util/Map;)V
accessible field net/minecraft/client/network/ClientAdvancementManager advancementProgresses Ljava/util/Map;
accessible class net/minecraft/stat/StatHandler
accessible field net/minecraft/stat/StatHandler statMap Lit/unimi/dsi/fastutil/objects/Object2IntMap;
Expand Down
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ archives_base_name=WorldTools
maven_group=org.waste.of.time
mod_version=1.2.0

minecraft_version=1.20.1
minecraft_version=1.20.2
enabled_platforms=fabric,forge
architectury_version=9.1.12
mixinextras_version=0.3.5
cloth_config_version=11.1.106
mod_menu_version=7.2.2
cloth_config_version=12.0.119
mod_menu_version=8.0.1

# Fabric
fabric_loader_version=0.15.2
yarn_mappings=1.20.1+build.10
fabric_api_version=0.91.0+1.20.1
yarn_mappings=1.20.2+build.4
fabric_api_version=0.91.6+1.20.2
fabric_kotlin_version=1.10.17+kotlin.1.9.22

# Forge
forge_version=1.20.1-47.2.17
forge_version=1.20.2-48.1.0
kotlin_forge_version=4.10.0

0 comments on commit b984736

Please sign in to comment.