Skip to content

Commit

Permalink
1.0.22
Browse files Browse the repository at this point in the history
Fixed forms not having right type and other info
Fixed network spam
Fixed trade evolutions not working/having wrong text
  • Loading branch information
Rafacasari committed Jun 21, 2024
1 parent f880168 commit 58910b5
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ object CobbledexConstants {
return "${Cobbledex.MOD_ID}.errors.$name"
}

val NotAPokemon by lazy { buildErrorMessage("NotAPokemon") }
val invalid_entity by lazy { buildErrorMessage("NotAPokemon") }

val Cobbledex_Item = CobbledexItem(Item.Settings().maxCount(1).rarity(Rarity.COMMON))
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ class CobbledexGUI(var selectedPokemon: FormData?, var selectedAspects: Set<Stri

// Cache
private var lastLoadedSpecies: Species? = null
private var lastLoadedAspects: Set<String>? = null
private var lastLoadedForm: FormData? = null

private var lastLoadedSpawnDetails: List<SerializablePokemonSpawnDetail>? = null
private var lastLoadedPokemonDrops: List<SerializableItemDrop>? = null

Expand Down Expand Up @@ -379,21 +380,14 @@ class CobbledexGUI(var selectedPokemon: FormData?, var selectedAspects: Set<Stri

evolutionDisplay?.clearEvolutions()

// Don't should be needed, since we are never storing aspects that aren't part of form
val aspects = pokemonAspects?.let {
CobblemonUtils.removeUnnecessaryAspects(it)
} ?: setOf()

// Request Pokémon Info to server and load into cache in Packet Handler (See ReceiveCobbledexPacketHandler)
// if (pokemon != null
// && ((lastLoadedSpecies == null || lastLoadedSpecies != pokemon.species)
// || (lastLoadedAspects == null || lastLoadedAspects != pokemonAspects))) {
if (pokemon != null
&& ((lastLoadedSpecies == null || lastLoadedSpecies != pokemon.species)
|| (lastLoadedAspects == null || lastLoadedAspects != pokemonAspects))) {
logInfo("Requested Cobbledex Packet")
lastLoadedAspects = aspects

// TODO: Packet seems to be called always, check why
if (pokemon != null && (lastLoadedSpecies == null || lastLoadedSpecies != pokemon.species || (lastLoadedForm == null) || lastLoadedForm != pokemon)) {
lastLoadedForm = pokemon

RequestCobbledexPacket(pokemon.species.resourceIdentifier, aspects).sendToServer()
}

Expand All @@ -405,7 +399,7 @@ class CobbledexGUI(var selectedPokemon: FormData?, var selectedAspects: Set<Stri
pY = y + 41,
pWidth = PORTRAIT_SIZE,
pHeight = PORTRAIT_SIZE,
pokemon = RenderablePokemon(pokemon.species, pokemonAspects ?: setOf()),
pokemon = RenderablePokemon(pokemon.species, pokemon.aspects.toSet()),
baseScale = 1.8F,
rotationY = 345F,
offsetY = -10.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@ class PokemonEvolutionDisplay(x: Int, y: Int): CobbledexScrollList<PokemonEvolut
buttonWidth = 40,
buttonHeight = 10,
clickAction = {
CobbledexGUI.Instance?.selectedPokemon = evolution.standardForm
val form = evolution.getForm(aspects)

CobbledexGUI.Instance?.selectedPokemon = form
CobbledexGUI.Instance?.selectedAspects = aspects
CobbledexGUI.Instance?.setPreviewPokemon(evolution.standardForm, aspects)
CobbledexGUI.Instance?.setPreviewPokemon(form, aspects)

CobbledexGUI.Instance?.updateMenu()
CobbledexGUI.Instance?.updateRelatedSpecies()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ class CobbledexItem(settings: Settings) : Item(settings) {
}

if (target !is PokemonEntity) {
if (player.world.isClient) {
player.sendMessage(Text.translatable(CobbledexConstants.NotAPokemon))
}
if (player.world.isClient)
player.sendMessage(Text.translatable(CobbledexConstants.invalid_entity))

return ActionResult.FAIL
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import com.rafacasari.mod.cobbledex.network.server.INetworkPacket
import net.minecraft.network.PacketByteBuf
import net.minecraft.util.Identifier

class RequestCobbledexPacket internal constructor(val pokemon: Identifier, val aspects: Set<String>): INetworkPacket<RequestCobbledexPacket> {
class RequestCobbledexPacket internal constructor(val pokemon: Identifier, val aspects: Set<String>, val form: String = ""): INetworkPacket<RequestCobbledexPacket> {
override val id = ID

override fun encode(buffer: PacketByteBuf) {
buffer.writeIdentifier(pokemon)
buffer.writeCollection(aspects) {
buff, value -> buff.writeString(value)
}
buffer.writeString(form)
}

companion object{
Expand All @@ -21,8 +22,8 @@ class RequestCobbledexPacket internal constructor(val pokemon: Identifier, val a
val aspects = buffer.readList {
buff -> buff.readString()
}.toSet()

return RequestCobbledexPacket(identifier, aspects)
val form = buffer.readString()
return RequestCobbledexPacket(identifier, aspects, form)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,15 @@ class SerializablePokemonEvolution() : IEncodable {

val item = Registries.ITEM.get(Identifier("cobblemon", "link_cable"))
val itemStack = ItemStack(item)
val translation = Text.translatable("cobbledex.evolution.trade_or_link_cable", itemStack.name.bold())

val translation = tradePokemon?.species?.let { speciesName ->
val tradeSpecies = PokemonSpecies.getByName(speciesName)
if (tradeSpecies != null)
Text.translatable("cobbledex.evolution.trade_specific", tradeSpecies.translatedName.bold(), itemStack.name.bold())
Text.translatable("cobbledex.evolution.trade_specific", speciesName.text().bold(), itemStack.name.bold())
} ?: Text.translatable("cobbledex.evolution.trade_any", itemStack.name.bold())

longTextDisplay.addItemEntry(itemStack, translation, false, disableTooltip = false)
// if (tradePokemonString.isNullOrEmpty()) {
// val item = Registries.ITEM.get(Identifier("cobblemon", "link_cable"))
// val itemStack = ItemStack(item)
// val translation = Text.translatable("cobbledex.evolution.trade_or_link_cable", itemStack.name.bold())
// longTextDisplay.addItemEntry(itemStack, translation, false, disableTooltip = false)
// } else {
// longTextDisplay.addText(Text.translatable("cobbledex.evolution.trade"), false)
// tradePokemonString?.let { properties ->
// longTextDisplay.addText(properties.text(), false)
// }
// }
}

Unknown -> {
Expand Down
5 changes: 3 additions & 2 deletions common/src/main/resources/assets/cobbledex/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@

"cobbledex.texts.no_evolution_found": "No evolution found for %s",
"cobbledex.evolution.use_item": "Use a %s",
"cobbledex.evolution.trade": "Complete a trade",
"cobbledex.evolution.trade_or_link_cable": "Trade or use %s",

"cobbledex.evolution.trade_any": "Complete any trade or use a %s",
"cobbledex.evolution.trade_specific": "Trade for an %s or use a %s",

"cobbledex.evolution.damage_taken": "Need %s damage taken",
"cobbledex.evolution.level": "Level: %s",
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ mod_id=cobbledex

generated_file_name_addon=-1.20.1
archives_base_name=cobbledex-1.20.1
mod_version=1.0.21
mod_version=1.0.22
mod_description=A mod to track your progress on Cobblemon. Fabric and Forge compatible.
mod_icon=assets/cobbledex/icon.png
repository=https://github.com/rafacasari/cobbledex
Expand Down

0 comments on commit 58910b5

Please sign in to comment.