Skip to content

Commit

Permalink
Tweaked time capsule lore.
Browse files Browse the repository at this point in the history
  • Loading branch information
Waterpicker committed Dec 6, 2024
1 parent 3d1505d commit fadd774
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ import com.cobblemon.mod.common.util.asTranslated
import com.cobblemon.mod.common.util.toNbtList
import generations.gg.generations.core.generationscore.common.world.item.StatueSpawnerItem
import net.minecraft.nbt.CompoundTag
import net.minecraft.nbt.ListTag
import net.minecraft.nbt.StringTag
import net.minecraft.nbt.Tag
import net.minecraft.network.chat.Component
import net.minecraft.network.chat.MutableComponent
import net.minecraft.resources.ResourceLocation
import net.minecraft.world.entity.player.Player
import net.minecraft.world.item.ItemStack
Expand Down Expand Up @@ -138,3 +140,14 @@ fun Pokemon.removeIfBelongs(player: Player): Boolean {
return belongsTo(player) && storeCoordinates.get()?.remove() == true
}

fun <T:Any> ItemStack.setLore(lore: List<T>?): ItemStack {
val compoundtag = getOrCreateTagElement(ItemStack.TAG_DISPLAY)
if (lore != null) {
lore.map { if (it is MutableComponent) it else it.toString().text() }.map { Component.Serializer.toJson(it) }.map { StringTag.valueOf(it) }
.toCollection(ListTag()).let { compoundtag.put(ItemStack.TAG_LORE, it) }
} else {
compoundtag.remove(ItemStack.TAG_LORE)
}
return this
}

Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ class DnaSplicer(properties: Properties): PokemonStoringItem(properties) {
if (pokemonInStack == null && (pokemon.isSpecies("zekrom") || pokemon.isSpecies("reshiram"))) {
if (pokemon.removeIfBelongs(player)) {
stack.savePokemon(pokemon)

var list = mutableListOf<Component>()
list.add(pokemon)
stack.setLore(list)

player.level().playSound(null, entity, SoundEvents.ENDERMAN_TELEPORT, SoundSource.MASTER, 1.0f, 1.0f)

player.sendSystemMessage("generations_core.pokemon.encoded".asTranslated(pokemon.getDisplayName().string))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.cobblemon.mod.common.api.text.text
import generations.gg.generations.core.generationscore.common.util.add
import generations.gg.generations.core.generationscore.common.util.getPokemon
import generations.gg.generations.core.generationscore.common.util.removePokemon
import generations.gg.generations.core.generationscore.common.util.setLore
import generations.gg.generations.core.generationscore.common.world.item.GenerationsCobblemonInteractions.PokemonInteraction
import net.minecraft.network.chat.Component
import net.minecraft.server.level.ServerPlayer
Expand All @@ -31,8 +32,6 @@ abstract class PokemonStoringItem(properties: Properties) : Item(properties), Po
tooltipComponents: MutableList<Component>,
isAdvanced: TooltipFlag,
) {
stack.getPokemon()?.run { tooltipComponents.add(this) }

super.appendHoverText(stack, level, tooltipComponents, isAdvanced)
}

Expand All @@ -44,10 +43,12 @@ abstract class PokemonStoringItem(properties: Properties) : Item(properties), Po
storage.getParty((player as ServerPlayer)).add(pokemon)
item.shrink(1)
item.removePokemon()
item.setLore(mutableListOf<Component>())
player.level().playSound(null, player, SoundEvents.ENDERMAN_TELEPORT, SoundSource.MASTER, 1.0f, 1.0f)
return InteractionResultHolder.sidedSuccess(item, false)
}
}
return super.use(level, player, usedHand)
}

}
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
package generations.gg.generations.core.generationscore.common.world.item

import com.cobblemon.mod.common.Cobblemon.storage
import com.cobblemon.mod.common.api.text.plus
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity
import com.cobblemon.mod.common.pokemon.Species
import dev.architectury.registry.item.ItemPropertiesRegistry
import generations.gg.generations.core.generationscore.common.GenerationsCore
import generations.gg.generations.core.generationscore.common.util.getPokemon
import generations.gg.generations.core.generationscore.common.util.removeIfBelongs
import generations.gg.generations.core.generationscore.common.util.savePokemon
import generations.gg.generations.core.generationscore.common.util.*
import net.minecraft.client.multiplayer.ClientLevel
import net.minecraft.network.chat.Component
import net.minecraft.network.chat.MutableComponent
import net.minecraft.server.level.ServerPlayer
import net.minecraft.sounds.SoundEvents
import net.minecraft.sounds.SoundSource
import net.minecraft.world.InteractionHand
import net.minecraft.world.InteractionResultHolder
import net.minecraft.world.entity.LivingEntity
import net.minecraft.world.entity.player.Player
import net.minecraft.world.item.ItemStack
import net.minecraft.world.level.Level

class TimeCapsule(properties: Properties) : PokemonStoringItem(properties) {
override fun processInteraction(player: ServerPlayer, entity: PokemonEntity, stack: ItemStack): Boolean {
val pokemon = entity.pokemon
return if (pokemon.removeIfBelongs(player)) {
stack.savePokemon(pokemon)

var list = mutableListOf<Component>()
list.add(pokemon)
stack.setLore(list)

player.level().playSound(
null,
entity,
Expand Down

0 comments on commit fadd774

Please sign in to comment.