Skip to content

Commit

Permalink
Cherry-pick divergence from 1.20.4 branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Avanatiker authored and rfresh2 committed Feb 5, 2024
1 parent 55060af commit d3ebab4
Show file tree
Hide file tree
Showing 17 changed files with 66 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class BossBarHudMixin {
public Collection<BossBar> modifyValues(Map<UUID, ClientBossBar> bossBars) {
List<BossBar> newBossBars = new ArrayList<>(bossBars.size() + 2);
BarManager.INSTANCE.getCaptureBar().ifPresent(newBossBars::add);
BarManager.INSTANCE.getProgressBar().ifPresent(newBossBars::add);
BarManager.INSTANCE.progressBar().ifPresent(newBossBars::add);
newBossBars.addAll(bossBars.values());
return newBossBars;
}
Expand All @@ -36,6 +36,6 @@ public Collection<BossBar> modifyValues(Map<UUID, ClientBossBar> bossBars) {
public boolean modifyIsEmpty(Map<UUID, ClientBossBar> bossBars) {
return bossBars.isEmpty()
&& BarManager.INSTANCE.getCaptureBar().isEmpty()
&& BarManager.INSTANCE.getProgressBar().isEmpty();
&& BarManager.INSTANCE.progressBar().isEmpty();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.waste.of.time.mixin;

import com.llamalad7.mixinextras.sugar.Local;
import net.minecraft.client.world.ClientChunkManager;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.PacketByteBuf;
Expand All @@ -11,7 +12,6 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import org.waste.of.time.Events;

import java.util.function.Consumer;
Expand All @@ -28,10 +28,9 @@ private void onChunkLoad(final int x, final int z, final PacketByteBuf buf, fina
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/world/ClientChunkManager$ClientChunkMap;compareAndSet(ILnet/minecraft/world/chunk/WorldChunk;Lnet/minecraft/world/chunk/WorldChunk;)Lnet/minecraft/world/chunk/WorldChunk;"
),
locals = LocalCapture.CAPTURE_FAILEXCEPTION
)
)
private void onChunkUnload(int chunkX, int chunkZ, CallbackInfo ci, int i, WorldChunk chunk) {
private void onChunkUnload(int chunkX, int chunkZ, CallbackInfo ci, @Local WorldChunk chunk) {
Events.INSTANCE.onChunkUnload(chunk);
}

Expand All @@ -40,10 +39,12 @@ private void onChunkUnload(int chunkX, int chunkZ, CallbackInfo ci, int i, World
at = @At(
value = "INVOKE",
target = "net/minecraft/client/world/ClientChunkManager$ClientChunkMap.isInRadius(II)Z"
),
locals = LocalCapture.CAPTURE_FAILHARD
)
)
private void onUpdateLoadDistance(int loadDistance, CallbackInfo ci, int oldRadius, int newRadius, ClientChunkManager.ClientChunkMap clientChunkMap, int k, WorldChunk oldChunk, ChunkPos chunkPos) {
private void onUpdateLoadDistance(int loadDistance, CallbackInfo ci,
@Local ClientChunkManager.ClientChunkMap clientChunkMap,
@Local WorldChunk oldChunk,
@Local ChunkPos chunkPos) {
if (!clientChunkMap.isInRadius(chunkPos.x, chunkPos.z)) {
Events.INSTANCE.onChunkUnload(oldChunk);
}
Expand Down

This file was deleted.

This file was deleted.

4 changes: 3 additions & 1 deletion common/src/main/kotlin/org/waste/of/time/Utils.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.waste.of.time

import net.minecraft.nbt.NbtCompound
import net.minecraft.util.math.Vec3d
import java.time.LocalDateTime
import java.time.ZoneId
import java.time.ZonedDateTime
Expand All @@ -9,6 +10,7 @@ import java.time.format.DateTimeFormatter
object Utils {
// Why cant I use the std lib?
fun Boolean.toByte(): Byte = if (this) 1 else 0
fun Vec3d.asString() = "(%.2f, %.2f, %.2f)".format(x, y, z)
fun NbtCompound.addAuthor() = apply { putString("Author", WorldTools.CREDIT_MESSAGE) }

fun getTime(): String {
Expand All @@ -20,4 +22,4 @@ object Utils {

return zonedDateTime.format(formatter)
}
}
}
5 changes: 5 additions & 0 deletions common/src/main/kotlin/org/waste/of/time/WorldTools.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package org.waste.of.time

import com.google.gson.Gson
import com.google.gson.GsonBuilder
import dev.architectury.injectables.targets.ArchitecturyTarget
import me.shedaniel.autoconfig.AutoConfig
import me.shedaniel.autoconfig.serializer.GsonConfigSerializer
import net.fabricmc.loader.api.FabricLoader
import net.minecraft.SharedConstants
import net.minecraft.client.MinecraftClient
import net.minecraft.client.option.KeyBinding
import net.minecraft.client.util.InputUtil
Expand All @@ -19,6 +22,8 @@ object WorldTools {
const val MCA_EXTENSION = ".mca"
const val DAT_EXTENSION = ".dat"
const val MAX_LEVEL_NAME_LENGTH = 16
val GSON: Gson = GsonBuilder().setPrettyPrinting().create()
val CURRENT_VERSION = SharedConstants.getGameVersion().saveVersion.id
private val VERSION: String by lazy {
if (ArchitecturyTarget.getCurrentTarget() == "fabric") {
FabricLoader.getInstance().getModContainer(MOD_ID).orElseThrow().metadata.version.friendlyString
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ package org.waste.of.time.manager

import net.minecraft.client.gui.hud.ClientBossBar
import net.minecraft.text.Text
import org.waste.of.time.manager.CaptureManager.capturing
import org.waste.of.time.WorldTools.config
import org.waste.of.time.manager.MessageManager.sendInfo
import org.waste.of.time.manager.CaptureManager.capturing
import org.waste.of.time.storage.StorageFlow
import java.util.*

object BarManager {

private val progressBar =
val progressBar =
ClientBossBar(
UUID.randomUUID(),
Text.of(""),
Expand All @@ -35,7 +34,7 @@ object BarManager {
false
)

fun getProgressBar() = if (StorageFlow.lastStored != null) {
fun progressBar() = if (StorageFlow.lastStored != null) {
Optional.of(progressBar)
} else {
Optional.empty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ object CaptureManager {

val levelName: String
get() = if (mc.isInSingleplayer) {
mc.server?.serverMotd?.substringAfter(" - ")?.sanitizeWorldName() ?: "SinglePlayer"
mc.server?.serverMotd?.substringAfter(" - ")?.sanitizeWorldName() ?: "Singleplayer"
} else {
serverInfo.address.sanitizeWorldName()
mc.networkHandler?.serverInfo?.address?.sanitizeWorldName() ?: "Multiplayer"
}

fun toggleCapture() {
Expand All @@ -35,6 +35,10 @@ object CaptureManager {
return
}

if (mc.isInSingleplayer) {
MessageManager.sendInfo("worldtools.log.info.singleplayer_capture")
}

val potentialName = customName?.let { potentialName ->
if (potentialName.length > MAX_WORLD_NAME_LENGTH) {
MessageManager.sendError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import net.minecraft.text.MutableText
import net.minecraft.text.Text
import net.minecraft.text.TextColor
import net.minecraft.util.Formatting
import net.minecraft.util.math.Vec3d
import org.waste.of.time.WorldTools.LOG
import org.waste.of.time.WorldTools.config
import org.waste.of.time.WorldTools.mc
Expand Down Expand Up @@ -109,6 +108,4 @@ object MessageManager {
return Text.translatable(key, *it)
}
}

fun Vec3d.asString() = "(%.2f, %.2f, %.2f)".format(x, y, z)
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ object StorageFlow {
} catch (e: StopCollectingException) {
LOG.info("Canceled caching flow")
} catch (e: IOException) {
LOG.error("IOException: Failed to create session for $levelName", e)
MessageManager.sendError("worldtools.log.error.failed_to_create_session", levelName, e.localizedMessage)
} catch (e: SymlinkValidationException) {
LOG.error("SymlinkValidationException: Failed to create session for $levelName", e)
MessageManager.sendError("worldtools.log.error.failed_to_create_session", levelName, e.localizedMessage)
} catch (e: CancellationException) {
LOG.info("Canceled caching thread")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ import net.minecraft.util.Identifier
import net.minecraft.util.PathUtil
import net.minecraft.util.WorldSavePath
import net.minecraft.world.level.storage.LevelStorage
import org.waste.of.time.manager.MessageManager.translateHighlight
import org.waste.of.time.WorldTools
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.mixin.accessor.AdvancementProgressesAccessor
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

class AdvancementsStoreable : Storeable {
Expand Down Expand Up @@ -45,7 +44,7 @@ class AdvancementsStoreable : Storeable {
val advancements = session.getDirectory(WorldSavePath.ADVANCEMENTS)
PathUtil.createDirectories(advancements)

val progress = (mc.player?.networkHandler?.advancementHandler as? AdvancementProgressesAccessor)?.advancementProgresses ?: return
val progress = mc.player?.networkHandler?.advancementHandler?.advancementProgresses ?: return

val progressMap = LinkedHashMap<Identifier, AdvancementProgress>()
progress.entries.forEach { (key, advancementProgress) ->
Expand All @@ -59,4 +58,4 @@ class AdvancementsStoreable : Storeable {

WorldTools.LOG.info("Saved ${progressMap.size} advancements.")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package org.waste.of.time.storage.serializable
import net.minecraft.entity.player.PlayerEntity
import net.minecraft.text.MutableText
import net.minecraft.world.level.storage.LevelStorage.Session
import org.waste.of.time.manager.MessageManager.asString
import org.waste.of.time.Utils.asString
import org.waste.of.time.WorldTools.config
import org.waste.of.time.manager.MessageManager.translateHighlight
import org.waste.of.time.manager.StatisticManager
import org.waste.of.time.WorldTools.config
import org.waste.of.time.storage.Cacheable
import org.waste.of.time.storage.cache.HotCache
import org.waste.of.time.storage.Storeable
import org.waste.of.time.storage.CustomRegionBasedStorage
import org.waste.of.time.storage.Storeable
import org.waste.of.time.storage.cache.HotCache

data class PlayerStoreable(
val player: PlayerEntity
Expand Down Expand Up @@ -45,4 +45,4 @@ data class PlayerStoreable(
StatisticManager.players++
StatisticManager.dimensions.add(player.world.registryKey.value.path)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
package org.waste.of.time.storage.serializable

import com.google.gson.JsonObject
import net.minecraft.SharedConstants
import net.minecraft.registry.Registries
import net.minecraft.text.MutableText
import net.minecraft.util.PathUtil
import net.minecraft.util.WorldSavePath
import net.minecraft.world.level.storage.LevelStorage
import org.waste.of.time.manager.MessageManager.translateHighlight
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.config
import org.waste.of.time.WorldTools.mc
import org.waste.of.time.storage.Storeable
import org.waste.of.time.mixin.accessor.StatHandlerAccessor
import org.waste.of.time.manager.MessageManager.translateHighlight
import org.waste.of.time.storage.CustomRegionBasedStorage
import org.waste.of.time.storage.Storeable
import java.nio.charset.StandardCharsets
import java.nio.file.Files

class StatisticStoreable : Storeable {
override fun shouldStore() = config.capture.statistics
Expand All @@ -30,15 +32,11 @@ class StatisticStoreable : Storeable {
override fun store(session: LevelStorage.Session, cachedStorages: MutableMap<String, CustomRegionBasedStorage>) {
// we need to get the stat map from the player's stat handler instead of the packet because the packet only
// contains the stats that have changed since the last time the packet was sent
val completeStatMap = (mc.player?.statHandler as? StatHandlerAccessor)?.statMap?.toMap() ?: return

val completeStatMap = mc.player?.statHandler?.statMap?.toMap() ?: return
val uuid = mc.player?.uuid ?: return
val statDirectory = session.getDirectory(WorldSavePath.STATS)
val path = statDirectory.resolve("$uuid.json").toFile()

PathUtil.createDirectories(statDirectory)

path.writeText(JsonObject().apply {
val json = JsonObject().apply {
addProperty("Author", WorldTools.CREDIT_MESSAGE)
add("stats", JsonObject().apply {
completeStatMap.entries.groupBy { it.key.type }.forEach { (type, entries) ->
Expand All @@ -51,9 +49,17 @@ class StatisticStoreable : Storeable {
add(Registries.STAT_TYPE.getId(type).toString(), typeObject)
}
})
addProperty("DataVersion", SharedConstants.getGameVersion().saveVersion.id)
}.toString())
addProperty("DataVersion", CURRENT_VERSION)
}

PathUtil.createDirectories(statDirectory)
Files.newBufferedWriter(
statDirectory.resolve("$uuid.json"),
StandardCharsets.UTF_8
).use { writer ->
GSON.toJson(json, writer)
}

WorldTools.LOG.info("Saved ${completeStatMap.entries.size} stats.")
}
}
}
4 changes: 3 additions & 1 deletion common/src/main/resources/assets/worldtools/lang/de_de.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"worldtools.gui.manager.button.cancel": "Abbrechen",
"worldtools.gui.manager.button.config": "Konfiguration",
"worldtools.gui.manager.button.start_download": "Herunterladen",
"worldtools.gui.manager.button.stop_download": "Download stoppen",
"worldtools.gui.manager.title": "WorldTools Verwaltung",
"worldtools.gui.manager.world_name_placeholder": "Weltname eingeben... (Default: %s)",
"worldtools.key.categories": "WeltWerkzeuge",
Expand All @@ -87,5 +88,6 @@
"worldtools.log.error.not_capturing": "Es läuft noch keine Aufnahme!",
"worldtools.log.error.world_name_too_long": "Weltname \"%s\" darf nicht länger als %d Zeichen sein!",
"worldtools.log.info.started_capture": "Aufnahme von %s gestartet...",
"worldtools.log.info.stopping_capture": "Aufnahme von %s wird gestoppt..."
"worldtools.log.info.stopping_capture": "Aufnahme von %s wird gestoppt...",
"worldtools.log.info.singleplayer_capture": "EXPERIMENTELL: Die Aufnahme von Einzelspieler Welten ist noch nicht vollständig getestet und kann zu Fehlern führen!"
}
3 changes: 2 additions & 1 deletion common/src/main/resources/assets/worldtools/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,6 @@
"worldtools.log.error.not_capturing": "No capture is running yet!",
"worldtools.log.error.world_name_too_long": "World name \"%s\" is too long! (max %d characters)",
"worldtools.log.info.started_capture": "Started capturing %s...",
"worldtools.log.info.stopping_capture": "Stopping capture %s..."
"worldtools.log.info.stopping_capture": "Stopping capture %s...",
"worldtools.log.info.singleplayer_capture": "EXPERIMENTAL: Capturing in singleplayer is experimental and may not work as expected!"
}
3 changes: 3 additions & 0 deletions common/src/main/resources/worldtools.accesswidener
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ accessWidener v2 named

accessible class net/minecraft/client/world/ClientChunkManager$ClientChunkMap
accessible method net/minecraft/client/world/ClientChunkManager$ClientChunkMap isInRadius (II)Z
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;
accessible field net/minecraft/client/world/ClientChunkManager chunks Lnet/minecraft/client/world/ClientChunkManager$ClientChunkMap;
accessible method net/minecraft/client/world/ClientChunkManager$ClientChunkMap getChunk (I)Lnet/minecraft/world/chunk/WorldChunk;
accessible field net/minecraft/client/world/ClientChunkManager$ClientChunkMap diameter I
Expand Down
4 changes: 1 addition & 3 deletions common/src/main/resources/worldtools.mixins.common.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
"ClientPlayNetworkHandlerMixin",
"DebugRendererMixin",
"GameMenuScreenMixin",
"MinecraftClientMixin",
"accessor.AdvancementProgressesAccessor",
"accessor.StatHandlerAccessor"
"MinecraftClientMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit d3ebab4

Please sign in to comment.