Merge branch 'small-fix' into 'main'

Remove Unused ClientDataSynchronizer

See merge request cable-mc/cobblemon!2240
This commit is contained in:
Polymeta
2026-05-11 14:46:26 +00:00
6 changed files with 13 additions and 75 deletions
@@ -1,33 +0,0 @@
/*
* Copyright (C) 2023 Cobblemon Contributors
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package com.cobblemon.mod.common.api.data
import com.cobblemon.mod.common.api.net.Decodable
import com.cobblemon.mod.common.api.net.Encodable
// TODO this is implemented in multiple places but unused. Can we scratch this?
/**
* Represents an object that will possibly be synchronized to the client during datapack synchronization.
*
* @param T The type of the object being synchronized.
*
* @author Licious
* @since October 14th, 2022
*/
interface ClientDataSynchronizer<T> : Decodable, Encodable {
/**
* Compares an object of type [T] with this instance to see if synchronization is necessary.
*
* @param other The other instance of type [T].
* @return If synchronization is necessary.
*/
fun shouldSynchronize(other: T): Boolean
}
@@ -56,10 +56,8 @@ class AggregatePokedexDef(
return speciesToEntry.values.toList()
}
}
override fun shouldSynchronize(other: PokedexDef) = true
override fun decode(buffer: RegistryFriendlyByteBuf) {
fun decode(buffer: RegistryFriendlyByteBuf) {
sortOrder = buffer.readSizedInt(IntSize.U_BYTE)
val size = buffer.readInt()
for (i in 0 until size) {
@@ -67,7 +65,7 @@ class AggregatePokedexDef(
}
}
override fun encode(buffer: RegistryFriendlyByteBuf) {
fun encode(buffer: RegistryFriendlyByteBuf) {
buffer.writeSizedInt(IntSize.U_BYTE, sortOrder)
buffer.writeInt(subDexIds.size)
subDexIds.forEach {
@@ -8,8 +8,6 @@
package com.cobblemon.mod.common.api.pokedex.def
import com.cobblemon.mod.common.api.data.ClientDataSynchronizer
import com.cobblemon.mod.common.api.pokedex.entry.DexEntries
import com.cobblemon.mod.common.api.pokedex.entry.PokedexEntry
import com.mojang.serialization.Codec
import com.mojang.serialization.MapCodec
@@ -23,7 +21,7 @@ import net.minecraft.resources.ResourceLocation
* @since August 24, 2024
* @author Apion
*/
abstract class PokedexDef: ClientDataSynchronizer<PokedexDef> {
abstract class PokedexDef {
//The ID used to find the codecs for this "type" of PokedexDef
abstract val typeId: ResourceLocation
//The ID of this dex in the Dexes registry
@@ -45,9 +45,7 @@ class SimplePokedexDef(
override fun getEntries() = entries.mapNotNull { DexEntries.entries[it] }
override fun shouldSynchronize(other: PokedexDef) = true
override fun decode(buffer: RegistryFriendlyByteBuf) {
fun decode(buffer: RegistryFriendlyByteBuf) {
sortOrder = buffer.readSizedInt(IntSize.U_BYTE)
val size = buffer.readInt()
for (i in 0 until size) {
@@ -55,7 +53,7 @@ class SimplePokedexDef(
}
}
override fun encode(buffer: RegistryFriendlyByteBuf) {
fun encode(buffer: RegistryFriendlyByteBuf) {
buffer.writeSizedInt(IntSize.U_BYTE, sortOrder)
buffer.writeInt(entries.size)
entries.forEach {
@@ -8,7 +8,6 @@
package com.cobblemon.mod.common.api.pokemon.moves
import com.cobblemon.mod.common.api.data.ClientDataSynchronizer
import com.cobblemon.mod.common.api.moves.MoveTemplate
import com.cobblemon.mod.common.api.moves.Moves
import com.cobblemon.mod.common.net.IntSize
@@ -18,7 +17,7 @@ import com.cobblemon.mod.common.util.writeSizedInt
import com.google.gson.JsonElement
import net.minecraft.network.RegistryFriendlyByteBuf
open class Learnset : ClientDataSynchronizer<Learnset> {
open class Learnset {
class Interpreter(val loadMove: (JsonElement, Learnset) -> Boolean) {
companion object {
fun parseFromPrefixIntoList(prefix: String, list: (Learnset) -> MutableList<MoveTemplate>): Interpreter {
@@ -111,9 +110,9 @@ open class Learnset : ClientDataSynchronizer<Learnset> {
}
// We only sync level up moves atm
override fun shouldSynchronize(other: Learnset) = other.levelUpMoves != this.levelUpMoves
fun shouldSynchronize(other: Learnset) = other.levelUpMoves != this.levelUpMoves
override fun decode(buffer: RegistryFriendlyByteBuf) {
fun decode(buffer: RegistryFriendlyByteBuf) {
this.levelUpMoves.clear()
repeat(times = buffer.readSizedInt(IntSize.U_BYTE)) {
val level = buffer.readSizedInt(IntSize.U_SHORT)
@@ -125,7 +124,7 @@ open class Learnset : ClientDataSynchronizer<Learnset> {
}
}
override fun encode(buffer: RegistryFriendlyByteBuf) {
fun encode(buffer: RegistryFriendlyByteBuf) {
buffer.writeSizedInt(IntSize.U_BYTE, levelUpMoves.size)
for ((level, moves) in levelUpMoves) {
buffer.writeSizedInt(IntSize.U_SHORT, level)
@@ -16,7 +16,6 @@ import com.cobblemon.mod.common.api.abilities.AbilityPool
import com.cobblemon.mod.common.api.abilities.CommonAbility
import com.cobblemon.mod.common.api.abilities.PotentialAbility
import com.cobblemon.mod.common.api.ai.config.BehaviourConfig
import com.cobblemon.mod.common.api.data.ClientDataSynchronizer
import com.cobblemon.mod.common.api.data.ShowdownIdentifiable
import com.cobblemon.mod.common.api.drop.DropTable
import com.cobblemon.mod.common.api.molang.MoLangFunctions.addSpeciesFunctions
@@ -52,7 +51,7 @@ import net.minecraft.network.chat.MutableComponent
import net.minecraft.resources.ResourceLocation
import net.minecraft.world.entity.EntityDimensions
class Species : ClientDataSynchronizer<Species>, ShowdownIdentifiable {
class Species : ShowdownIdentifiable {
var name: String = "Bulbasaur"
val translationKey: String
get() = "${this.resourceIdentifier.namespace}.species.${this.unformattedShowdownId()}.name"
@@ -218,7 +217,7 @@ class Species : ClientDataSynchronizer<Species>, ShowdownIdentifiable {
fun canGmax() = this.forms.find { it.formOnlyShowdownId() == "gmax" } != null
override fun encode(buffer: RegistryFriendlyByteBuf) {
fun encode(buffer: RegistryFriendlyByteBuf) {
buffer.writeBoolean(this.implemented)
buffer.writeString(this.name)
buffer.writeInt(this.nationalPokedexNumber)
@@ -259,7 +258,7 @@ class Species : ClientDataSynchronizer<Species>, ShowdownIdentifiable {
this.riding.encode(buffer)
}
override fun decode(buffer: RegistryFriendlyByteBuf) {
fun decode(buffer: RegistryFriendlyByteBuf) {
this.implemented = buffer.readBoolean()
this.name = buffer.readString()
this.nationalPokedexNumber = buffer.readInt()
@@ -303,27 +302,6 @@ class Species : ClientDataSynchronizer<Species>, ShowdownIdentifiable {
this.initialize()
}
override fun shouldSynchronize(other: Species): Boolean {
if (other.resourceIdentifier.toString() != other.resourceIdentifier.toString())
return false
return other.showdownId() != this.showdownId()
|| other.nationalPokedexNumber != this.nationalPokedexNumber
|| other.baseStats != this.baseStats
|| other.hitbox != this.hitbox
|| other.primaryType != this.primaryType
|| other.secondaryType != this.secondaryType
|| other.standingEyeHeight != this.standingEyeHeight
|| other.swimmingEyeHeight != this.swimmingEyeHeight
|| other.flyingEyeHeight != this.flyingEyeHeight
|| other.dynamaxBlocked != this.dynamaxBlocked
|| other.pokedex != this.pokedex
|| other.forms != this.forms
// We only sync level up moves atm
|| this.moves.shouldSynchronize(other.moves)
|| other.battleTheme != this.battleTheme
|| other.features != this.features
}
/**
* The literal Showdown ID of this species.
* This will be a lowercase version of the [name] with all the non-alphanumeric characters removed. For example, "Mr. Mime" becomes "mrmime".