forked from mirrors/cobblemon
Compare commits
9
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ee8133356e | ||
|
|
d78e114b3b | ||
|
|
14ab259eee | ||
|
|
a8f78e3fd6 | ||
|
|
96ae054aae | ||
|
|
80666530db | ||
|
|
b5e912a13f | ||
|
|
945f6b5f84 | ||
|
|
bf6c668850 |
@@ -2,6 +2,10 @@
|
||||
## [1.8.0 (MONTH Xth, 2026)](#1-8-0)
|
||||
|
||||
### Additions
|
||||
- Added trades for Saccharine Saplings, Hearty Grains, Chipped Pot, and Masterpiece Teacup to the Wandering Trader.
|
||||
- Added brewing recipe for Throat Spray.
|
||||
- Added Berry Tree scanning for Pokedex
|
||||
- Added Datapackable Pokedex Scanning for Block Entities
|
||||
- Added config options to award experience to fainted Pokémon for opponents they helped defeat (`awardExperienceToFaintedPokemon`) and to still award experience for defeated enemies even after battle loss/forfeit (`awardExperienceOnBattleLoss`)
|
||||
- Party Overlay Exp Gained Animation will now display the amount of EXP the Pokémon gained
|
||||
- Added a toast to notify players of how they can scroll through their party. Did you know you can hold R and scroll instead of using arrow keys??!
|
||||
|
||||
@@ -93,6 +93,8 @@ import com.cobblemon.mod.common.events.StatHandler
|
||||
import com.cobblemon.mod.common.net.messages.client.settings.ServerSettingsPacket
|
||||
import com.cobblemon.mod.common.permission.LaxPermissionValidator
|
||||
import com.cobblemon.mod.common.platform.events.PlatformEvents
|
||||
import com.cobblemon.mod.common.api.pokedex.scan.BlockScanProviderRegistry
|
||||
import com.cobblemon.mod.common.pokedex.scanner.block.BerryBlockScanProvider
|
||||
import com.cobblemon.mod.common.pokemon.Pokemon
|
||||
import com.cobblemon.mod.common.pokemon.aspects.ALPHA_ASPECT
|
||||
import com.cobblemon.mod.common.pokemon.aspects.CHARACTERISTIC_RAINBOW_ASPECT
|
||||
@@ -351,6 +353,8 @@ object Cobblemon {
|
||||
|
||||
CobblemonEvents.POKEMON_PROPERTY_INITIALISED.emit(Unit)
|
||||
|
||||
BlockScanProviderRegistry.register(cobblemonResource("berry"), BerryBlockScanProvider)
|
||||
|
||||
CallbackHandler.setup()
|
||||
EntityCallbackHandler.setup()
|
||||
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package com.cobblemon.mod.common.api.pokedex.scan
|
||||
|
||||
object BlockScanDefinition {
|
||||
data class Frame(
|
||||
val slot: Int,
|
||||
val text: ScanText,
|
||||
val scale: Float? = null
|
||||
)
|
||||
|
||||
sealed interface ScanText {
|
||||
data class Literal(val text: String) : ScanText
|
||||
data class Key(val key: String) : ScanText
|
||||
data class Translate(val key: String, val with: List<ScanText> = emptyList()) : ScanText
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package com.cobblemon.mod.common.api.pokedex.scan
|
||||
|
||||
import com.cobblemon.mod.common.pokedex.scanner.block.BlockScanProvider
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
|
||||
object BlockScanProviderRegistry {
|
||||
private val providers = mutableMapOf<ResourceLocation, BlockScanProvider>()
|
||||
|
||||
fun register(typeId: ResourceLocation, provider: BlockScanProvider) {
|
||||
providers[typeId] = provider
|
||||
}
|
||||
|
||||
fun get(typeId: ResourceLocation): BlockScanProvider? = providers[typeId]
|
||||
}
|
||||
+182
-82
@@ -8,9 +8,11 @@
|
||||
|
||||
package com.cobblemon.mod.common.client.pokedex
|
||||
|
||||
import com.cobblemon.mod.common.Cobblemon
|
||||
import com.cobblemon.mod.common.api.gui.blitk
|
||||
import com.cobblemon.mod.common.api.pokedex.PokedexLearnedInformation
|
||||
import com.cobblemon.mod.common.api.text.*
|
||||
import com.cobblemon.mod.common.block.BerryBlock
|
||||
import com.cobblemon.mod.common.client.CobblemonClient
|
||||
import com.cobblemon.mod.common.client.CobblemonResources
|
||||
import com.cobblemon.mod.common.client.gui.battle.BattleOverlay.Companion.SCALE
|
||||
@@ -24,6 +26,11 @@ import com.cobblemon.mod.common.pokemon.Gender
|
||||
import com.cobblemon.mod.common.pokemon.PokemonSizeCategory
|
||||
import com.cobblemon.mod.common.util.cobblemonResource
|
||||
import com.cobblemon.mod.common.util.lang
|
||||
import com.cobblemon.mod.common.api.pokedex.scan.BlockScanDefinition
|
||||
import com.cobblemon.mod.common.api.pokedex.scan.BlockScanProviderRegistry
|
||||
import net.minecraft.core.registries.BuiltInRegistries
|
||||
import net.minecraft.network.chat.Component
|
||||
import net.minecraft.world.level.block.entity.BlockEntity
|
||||
import com.mojang.blaze3d.systems.RenderSystem
|
||||
import com.mojang.blaze3d.vertex.PoseStack
|
||||
import net.minecraft.client.DeltaTracker
|
||||
@@ -32,6 +39,7 @@ import net.minecraft.client.gui.GuiGraphics
|
||||
import net.minecraft.network.chat.MutableComponent
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
import net.minecraft.util.Mth.clamp
|
||||
import net.minecraft.world.item.ItemStack
|
||||
import org.joml.Quaternionf
|
||||
import kotlin.math.*
|
||||
|
||||
@@ -82,13 +90,45 @@ class PokedexScannerRenderer {
|
||||
fun infoFrameResource(isLeft: Boolean, tier: Int): ResourceLocation = cobblemonResource("textures/gui/pokedex/scan/scan_info_frame_${if (isLeft) "left" else "right"}_$tier.png")
|
||||
}
|
||||
|
||||
private var lastFocusedBlockTypeId: ResourceLocation? = null
|
||||
|
||||
fun renderInfoFrames(graphics: GuiGraphics, poseStack: PoseStack, usageContext: PokedexUsageContext, centerX: Int, centerY: Int, opacity: Float) {
|
||||
if (usageContext.focusIntervals > 0) {
|
||||
var infoDisplayedCounter = 0
|
||||
usageContext.availableInfoFrames.forEachIndexed {index, isLeftSide ->
|
||||
if (isLeftSide !== null) {
|
||||
if (infoDisplayedCounter > 2 && !usageContext.isPokemonInFocusOwned) return@forEachIndexed
|
||||
val isPokemonFocus = usageContext.scannableEntityInFocus != null
|
||||
if (isPokemonFocus && infoDisplayedCounter > 1 && !usageContext.isPokemonInFocusOwned) return@forEachIndexed
|
||||
infoDisplayedCounter++
|
||||
|
||||
val blockEntityInFocus: BlockEntity? = usageContext.blockEntityInFocus
|
||||
val pokedexEntityData = usageContext.scannableEntityInFocus?.resolvePokemonScan()
|
||||
|
||||
// store the block entity typeId so our close animation knows what to show
|
||||
if (pokedexEntityData != null) {
|
||||
lastFocusedBlockTypeId = null
|
||||
} else if (blockEntityInFocus != null) {
|
||||
lastFocusedBlockTypeId = BuiltInRegistries.BLOCK_ENTITY_TYPE.getKey(blockEntityInFocus.type)
|
||||
} else if (usageContext.focusIntervals <= 0f) {
|
||||
lastFocusedBlockTypeId = null
|
||||
}
|
||||
|
||||
val effectiveTypeId = blockEntityInFocus
|
||||
?.let { BuiltInRegistries.BLOCK_ENTITY_TYPE.getKey(it.type) }
|
||||
?: lastFocusedBlockTypeId
|
||||
|
||||
// if a block entity is being focused on make sure we only show the frames needed
|
||||
if (pokedexEntityData == null && effectiveTypeId != null) {
|
||||
val provider = BlockScanProviderRegistry.get(effectiveTypeId)
|
||||
if (provider != null) {
|
||||
val hasFrameForSlot = provider.frames.any { it.slot == infoDisplayedCounter }
|
||||
if (!hasFrameForSlot) {
|
||||
return@forEachIndexed
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Frames
|
||||
val isInnerFrame = index == 1 || index == 2
|
||||
val frameHeight = if (isInnerFrame) INNER_INFO_FRAME_HEIGHT else OUTER_INFO_FRAME_HEIGHT
|
||||
@@ -110,77 +150,79 @@ class PokedexScannerRenderer {
|
||||
val yOffsetText = when(index) { 0 -> 5; 1 -> 4; 2 -> 8; 3 -> 42; else -> 0 }
|
||||
|
||||
// Text
|
||||
if (usageContext.focusIntervals == PokedexUsageContext.FOCUS_INTERVALS && usageContext.scannableEntityInFocus != null) {
|
||||
val pokedexEntityData = usageContext.scannableEntityInFocus?.resolvePokemonScan() ?: return
|
||||
|
||||
if (infoDisplayedCounter == 1) {
|
||||
drawScaledText(
|
||||
context = graphics,
|
||||
font = CobblemonResources.DEFAULT_LARGE,
|
||||
text = lang("ui.lv.number", pokedexEntityData.pokemon.level).bold(),
|
||||
x = centerX + xOffset + xOffsetText,
|
||||
y = centerY + yOffset + yOffsetText,
|
||||
shadow = true,
|
||||
centered = true
|
||||
)
|
||||
}
|
||||
|
||||
if (infoDisplayedCounter == 2) {
|
||||
val hasTrainer = (usageContext.scannableEntityInFocus?.resolveEntityScan() as? PokemonEntity)?.ownerUUID !== null
|
||||
val speciesName = pokedexEntityData.getApparentSpecies().translatedName.bold()
|
||||
var yOffsetName = if (hasTrainer) 2 else 0
|
||||
if (hasTrainer) {
|
||||
drawScaledText(
|
||||
context = graphics,
|
||||
text = lang("ui.pokedex.scan.trainer_owned"),
|
||||
x = centerX + xOffset + xOffsetText,
|
||||
y = centerY + yOffset + yOffsetText - yOffsetName,
|
||||
shadow = true,
|
||||
centered = true,
|
||||
scale = 0.5F
|
||||
)
|
||||
}
|
||||
drawScaledText(
|
||||
context = graphics,
|
||||
font = CobblemonResources.DEFAULT_LARGE,
|
||||
text = speciesName,
|
||||
x = centerX + xOffset + xOffsetText,
|
||||
y = centerY + yOffset + yOffsetText + yOffsetName,
|
||||
shadow = true,
|
||||
centered = true
|
||||
)
|
||||
|
||||
val gender = pokedexEntityData.pokemon.gender
|
||||
val speciesNameWidth = Minecraft.getInstance().font.width(speciesName.font(CobblemonResources.DEFAULT_LARGE))
|
||||
if (gender != Gender.GENDERLESS) {
|
||||
val isMale = gender == Gender.MALE
|
||||
val textSymbol = if (isMale) "♂".text().bold() else "♀".text().bold()
|
||||
if (usageContext.focusIntervals == PokedexUsageContext.FOCUS_INTERVALS && (pokedexEntityData != null || blockEntityInFocus != null)) {
|
||||
if (pokedexEntityData != null) {
|
||||
if (infoDisplayedCounter == 1) {
|
||||
drawScaledText(
|
||||
context = graphics,
|
||||
font = CobblemonResources.DEFAULT_LARGE,
|
||||
text = textSymbol,
|
||||
x = centerX + xOffset + xOffsetText + 2 + (speciesNameWidth / 2),
|
||||
text = lang("ui.lv.number", pokedexEntityData.pokemon.level).bold(),
|
||||
x = centerX + xOffset + xOffsetText,
|
||||
y = centerY + yOffset + yOffsetText,
|
||||
shadow = true,
|
||||
centered = true
|
||||
)
|
||||
}
|
||||
|
||||
if (infoDisplayedCounter == 2) {
|
||||
val hasTrainer =
|
||||
(usageContext.scannableEntityInFocus?.resolveEntityScan() as? PokemonEntity)?.ownerUUID !== null
|
||||
val speciesName = pokedexEntityData.getApparentSpecies().translatedName.bold()
|
||||
var yOffsetName = if (hasTrainer) 2 else 0
|
||||
if (hasTrainer) {
|
||||
drawScaledText(
|
||||
context = graphics,
|
||||
text = lang("ui.pokedex.scan.trainer_owned"),
|
||||
x = centerX + xOffset + xOffsetText,
|
||||
y = centerY + yOffset + yOffsetText - yOffsetName,
|
||||
shadow = true,
|
||||
centered = true,
|
||||
scale = 0.5F
|
||||
)
|
||||
}
|
||||
drawScaledText(
|
||||
context = graphics,
|
||||
font = CobblemonResources.DEFAULT_LARGE,
|
||||
text = speciesName,
|
||||
x = centerX + xOffset + xOffsetText,
|
||||
y = centerY + yOffset + yOffsetText + yOffsetName,
|
||||
colour = if (isMale) 0x32CBFF else 0xFC5454,
|
||||
shadow = true
|
||||
shadow = true,
|
||||
centered = true
|
||||
)
|
||||
|
||||
val gender = pokedexEntityData.pokemon.gender
|
||||
val speciesNameWidth =
|
||||
Minecraft.getInstance().font.width(speciesName.font(CobblemonResources.DEFAULT_LARGE))
|
||||
if (gender != Gender.GENDERLESS) {
|
||||
val isMale = gender == Gender.MALE
|
||||
val textSymbol = if (isMale) "♂".text().bold() else "♀".text().bold()
|
||||
drawScaledText(
|
||||
context = graphics,
|
||||
font = CobblemonResources.DEFAULT_LARGE,
|
||||
text = textSymbol,
|
||||
x = centerX + xOffset + xOffsetText + 2 + (speciesNameWidth / 2),
|
||||
y = centerY + yOffset + yOffsetText + yOffsetName,
|
||||
colour = if (isMale) 0x32CBFF else 0xFC5454,
|
||||
shadow = true
|
||||
)
|
||||
}
|
||||
|
||||
if (usageContext.isPokemonInFocusOwned) {
|
||||
blitk(
|
||||
matrixStack = poseStack,
|
||||
texture = caughtIndicator,
|
||||
x = (centerX + xOffset + xOffsetText - 7 - (speciesNameWidth / 2)) / SCALE,
|
||||
y = (centerY + yOffset + yOffsetText + yOffsetName + 2) / SCALE,
|
||||
height = 10,
|
||||
width = 10,
|
||||
scale = SCALE
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (usageContext.isPokemonInFocusOwned) {
|
||||
blitk(
|
||||
matrixStack = poseStack,
|
||||
texture = caughtIndicator,
|
||||
x = (centerX + xOffset + xOffsetText - 7 - (speciesNameWidth / 2)) / SCALE,
|
||||
y = (centerY + yOffset + yOffsetText + yOffsetName + 2) / SCALE,
|
||||
height = 10,
|
||||
width = 10,
|
||||
scale = SCALE
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (infoDisplayedCounter == 3) {
|
||||
val pokemon = pokedexEntityData.pokemon
|
||||
if (infoDisplayedCounter == 3) {
|
||||
val pokemon = pokedexEntityData.pokemon
|
||||
val entityAlpha = (usageContext.scannableEntityInFocus?.resolveEntityScan() as? PokemonEntity)
|
||||
?.entityData
|
||||
?.get(PokemonEntity.IS_ALPHA)
|
||||
@@ -203,35 +245,70 @@ class PokedexScannerRenderer {
|
||||
}
|
||||
|
||||
if (infoDisplayedCounter == 4) {
|
||||
val typeText = lang("type.suffix", pokedexEntityData.getApparentForm().types.map { it.displayName.copy() }.reduce { acc, next -> acc.plus("/").plus(next) }).bold()
|
||||
val typeWidth = Minecraft.getInstance().font.width(typeText.font(CobblemonResources.DEFAULT_LARGE))
|
||||
// Split into 2 lines if text width is too long
|
||||
if (typeWidth > (OUTER_INFO_FRAME_WIDTH - 8) && pokedexEntityData.getApparentForm().secondaryType !== null) {
|
||||
val splitLines = typeText.string.split("/")
|
||||
drawScaledText(
|
||||
context = graphics,
|
||||
font = CobblemonResources.DEFAULT_LARGE,
|
||||
text = text(splitLines[0], "/").bold(),
|
||||
x = centerX + xOffset + xOffsetText,
|
||||
y = centerY + yOffset + yOffsetText - 4,
|
||||
shadow = true,
|
||||
centered = true
|
||||
)
|
||||
val typeText = lang(
|
||||
"type.suffix",
|
||||
pokedexEntityData.getApparentForm().types.map { it.displayName.copy() }
|
||||
.reduce { acc, next -> acc.plus("/").plus(next) }).bold()
|
||||
val typeWidth =
|
||||
Minecraft.getInstance().font.width(typeText.font(CobblemonResources.DEFAULT_LARGE))
|
||||
// Split into 2 lines if text width is too long
|
||||
if (typeWidth > (OUTER_INFO_FRAME_WIDTH - 8) && pokedexEntityData.getApparentForm().secondaryType !== null) {
|
||||
val splitLines = typeText.string.split("/")
|
||||
drawScaledText(
|
||||
context = graphics,
|
||||
font = CobblemonResources.DEFAULT_LARGE,
|
||||
text = text(splitLines[0], "/").bold(),
|
||||
x = centerX + xOffset + xOffsetText,
|
||||
y = centerY + yOffset + yOffsetText - 4,
|
||||
shadow = true,
|
||||
centered = true
|
||||
)
|
||||
|
||||
drawScaledText(
|
||||
context = graphics,
|
||||
font = CobblemonResources.DEFAULT_LARGE,
|
||||
text = text(splitLines[1]).bold(),
|
||||
x = centerX + xOffset + xOffsetText,
|
||||
y = centerY + yOffset + yOffsetText + 3,
|
||||
shadow = true,
|
||||
centered = true
|
||||
)
|
||||
} else {
|
||||
drawScaledText(
|
||||
context = graphics,
|
||||
font = CobblemonResources.DEFAULT_LARGE,
|
||||
text = typeText,
|
||||
x = centerX + xOffset + xOffsetText,
|
||||
y = centerY + yOffset + yOffsetText,
|
||||
shadow = true,
|
||||
centered = true
|
||||
)
|
||||
}
|
||||
}
|
||||
} else if (blockEntityInFocus != null) {
|
||||
val typeId = BuiltInRegistries.BLOCK_ENTITY_TYPE.getKey(blockEntityInFocus.type) ?: return@forEachIndexed
|
||||
val provider = BlockScanProviderRegistry.get(typeId) ?: return@forEachIndexed
|
||||
val values = provider.getValues(blockEntityInFocus)
|
||||
val frame = provider.frames.firstOrNull { it.slot == infoDisplayedCounter } ?: return@forEachIndexed
|
||||
val textComponent = resolveScanText(frame.text, values).bold()
|
||||
|
||||
val scale = frame.scale
|
||||
if (scale != null) {
|
||||
drawScaledText(
|
||||
context = graphics,
|
||||
font = CobblemonResources.DEFAULT_LARGE,
|
||||
text = text(splitLines[1]).bold(),
|
||||
text = textComponent,
|
||||
x = centerX + xOffset + xOffsetText,
|
||||
y = centerY + yOffset + yOffsetText + 3,
|
||||
y = centerY + yOffset + yOffsetText,
|
||||
shadow = true,
|
||||
centered = true
|
||||
centered = true,
|
||||
scale = scale
|
||||
)
|
||||
} else {
|
||||
drawScaledText(
|
||||
context = graphics,
|
||||
font = CobblemonResources.DEFAULT_LARGE,
|
||||
text = typeText,
|
||||
text = textComponent,
|
||||
x = centerX + xOffset + xOffsetText,
|
||||
y = centerY + yOffset + yOffsetText,
|
||||
shadow = true,
|
||||
@@ -462,4 +539,27 @@ class PokedexScannerRenderer {
|
||||
renderScanOverlay(graphics, tickDelta)
|
||||
}
|
||||
}
|
||||
|
||||
private fun anyToComponent(value: Any?): MutableComponent {
|
||||
return when (value) {
|
||||
null -> text("")
|
||||
is MutableComponent -> value
|
||||
is Component -> value.copy()
|
||||
else -> text(value.toString())
|
||||
}
|
||||
}
|
||||
|
||||
private fun resolveScanText(
|
||||
spec: BlockScanDefinition.ScanText,
|
||||
values: Map<String, Any?>
|
||||
): MutableComponent {
|
||||
return when (spec) {
|
||||
is BlockScanDefinition.ScanText.Literal -> text(spec.text)
|
||||
is BlockScanDefinition.ScanText.Key -> anyToComponent(values[spec.key])
|
||||
is BlockScanDefinition.ScanText.Translate -> {
|
||||
val args = spec.with.map { resolveScanText(it, values) }.toTypedArray()
|
||||
lang(spec.key, *args)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+47
-8
@@ -11,6 +11,7 @@ package com.cobblemon.mod.common.pokedex.scanner
|
||||
import com.cobblemon.mod.common.CobblemonSounds
|
||||
import com.cobblemon.mod.common.api.pokedex.PokedexEntryProgress
|
||||
import com.cobblemon.mod.common.api.pokedex.PokedexLearnedInformation
|
||||
import com.cobblemon.mod.common.block.entity.BerryBlockEntity
|
||||
import com.cobblemon.mod.common.client.CobblemonClient
|
||||
import com.cobblemon.mod.common.client.gui.pokedex.PokedexGUI
|
||||
import com.cobblemon.mod.common.client.pokedex.PokedexScannerRenderer
|
||||
@@ -18,6 +19,8 @@ import com.cobblemon.mod.common.client.pokedex.PokedexType
|
||||
import com.cobblemon.mod.common.net.messages.client.pokedex.ServerConfirmedRegisterPacket
|
||||
import com.cobblemon.mod.common.net.messages.server.pokedex.scanner.FinishScanningPacket
|
||||
import com.cobblemon.mod.common.net.messages.server.pokedex.scanner.StartScanningPacket
|
||||
import net.minecraft.core.registries.BuiltInRegistries
|
||||
import net.minecraft.world.level.block.entity.BlockEntity
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
import kotlin.random.Random
|
||||
@@ -26,6 +29,7 @@ import net.minecraft.client.Minecraft
|
||||
import net.minecraft.client.gui.GuiGraphics
|
||||
import net.minecraft.client.player.LocalPlayer
|
||||
import net.minecraft.client.resources.sounds.SimpleSoundInstance
|
||||
import net.minecraft.core.BlockPos
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
import net.minecraft.sounds.SoundEvent
|
||||
import kotlin.math.exp
|
||||
@@ -51,6 +55,8 @@ class PokedexUsageContext {
|
||||
var infoGuiOpen: Boolean = false
|
||||
var scanningGuiOpen: Boolean = false
|
||||
var isPokemonInFocusOwned: Boolean = false
|
||||
var blockEntityInFocus: BlockEntity? = null
|
||||
var blockPosInFocus: BlockPos? = null
|
||||
var registerCompleted: Boolean = false
|
||||
var scannedSpecies: ResourceLocation? = null
|
||||
var scannableEntityInFocus: ScannableEntity? = null
|
||||
@@ -68,6 +74,8 @@ class PokedexUsageContext {
|
||||
var availableInfoFrames: MutableList<Boolean?> = mutableListOf(null, null, null, null)
|
||||
val renderer: PokedexScannerRenderer = PokedexScannerRenderer()
|
||||
|
||||
private fun hasAnyFocus() = (scannableEntityInFocus != null) || (blockEntityInFocus != null)
|
||||
|
||||
fun stopUsing(ticksInUse: Int, speciesId: ResourceLocation? = null) {
|
||||
if (ticksInUse < OPEN_SCANNER_BUFFER_TICKS) {
|
||||
openPokedexGUI(type, speciesId)
|
||||
@@ -89,7 +97,9 @@ class PokedexUsageContext {
|
||||
if (transitionIntervals == TRANSITION_INTERVALS) playSound(CobblemonSounds.POKEDEX_SCAN_CLOSE)
|
||||
transitionIntervals = max(transitionIntervals - updateInterval, 0F)
|
||||
if (transitionIntervals <= 0) {
|
||||
if (viewInfoTicks >= VIEW_INFO_BUFFER_TICKS) openPokedexGUI(type, scannableEntityInFocus!!.resolvePokemonScan()?.getApparentSpecies()?.resourceIdentifier)
|
||||
if (viewInfoTicks >= VIEW_INFO_BUFFER_TICKS && scannableEntityInFocus != null) {
|
||||
openPokedexGUI(type, scannableEntityInFocus!!.resolvePokemonScan()?.getApparentSpecies()?.resourceIdentifier)
|
||||
}
|
||||
resetState()
|
||||
}
|
||||
}
|
||||
@@ -102,7 +112,7 @@ class PokedexUsageContext {
|
||||
if (scanningProgress >= MAX_SCAN_PROGRESS) targetId?.let { FinishScanningPacket(it, zoomLevel.toInt()).sendToServer() }
|
||||
if (focusIntervals > 0) focusIntervals = max(0F, focusIntervals - updateInterval)
|
||||
} else {
|
||||
if (scannableEntityInFocus != null) {
|
||||
if (hasAnyFocus()) {
|
||||
if (focusIntervals < FOCUS_INTERVALS) focusIntervals = min(focusIntervals + updateInterval, FOCUS_INTERVALS)
|
||||
} else {
|
||||
if (focusIntervals > 0) focusIntervals = max(0F, focusIntervals - updateInterval)
|
||||
@@ -137,8 +147,9 @@ class PokedexUsageContext {
|
||||
playSound(CobblemonSounds.POKEDEX_OPEN)
|
||||
}
|
||||
|
||||
// todo display info of scanned berry to the Berry Dex later
|
||||
fun attackKeyHeld(isHeld: Boolean) {
|
||||
if (isHeld && scannableEntityInFocus !== null && viewInfoTicks < VIEW_INFO_BUFFER_TICKS && scanningProgress == 0F) {
|
||||
if (isHeld && hasAnyFocus() && viewInfoTicks < VIEW_INFO_BUFFER_TICKS && scanningProgress == 0F) {
|
||||
viewInfoTicks++
|
||||
if (viewInfoTicks % 2 == 0) playSound(CobblemonSounds.POKEDEX_SCAN_LOOP)
|
||||
} else if (viewInfoTicks > 0 && viewInfoTicks < VIEW_INFO_BUFFER_TICKS) {
|
||||
@@ -147,26 +158,30 @@ class PokedexUsageContext {
|
||||
}
|
||||
|
||||
fun tryScanPokemon(user: LocalPlayer) {
|
||||
// Pokémon/entity scan
|
||||
val targetScannableEntity = PokemonScanner.findScannableEntity(user, zoomLevel.toInt())
|
||||
if (targetScannableEntity != null) {
|
||||
if (targetScannableEntity != scannableEntityInFocus) {
|
||||
resetFocusedPokemonState()
|
||||
scannableEntityInFocus = targetScannableEntity
|
||||
|
||||
val resolvedPokemon = scannableEntityInFocus?.resolvePokemonScan()
|
||||
if(resolvedPokemon == null) {
|
||||
if (resolvedPokemon == null) {
|
||||
resetFocusedPokemonState()
|
||||
return
|
||||
}
|
||||
|
||||
// Check if Pokémon in focus is owned
|
||||
isPokemonInFocusOwned = CobblemonClient.clientPokedexData.getHighestKnowledgeForSpecies(resolvedPokemon.getApparentSpecies().resourceIdentifier) == PokedexEntryProgress.OWNED
|
||||
isPokemonInFocusOwned =
|
||||
CobblemonClient.clientPokedexData.getHighestKnowledgeForSpecies(resolvedPokemon.getApparentSpecies().resourceIdentifier) == PokedexEntryProgress.OWNED
|
||||
|
||||
// Randomize info frames for render
|
||||
if (focusIntervals == 0F) {
|
||||
availableInfoFrames = mutableListOf(null, null, null, null)
|
||||
|
||||
for (i in 0..3) {
|
||||
var randomIndex = Random.nextInt(availableInfoFrames.size)
|
||||
if (availableInfoFrames[randomIndex] !== null) randomIndex = availableInfoFrames.indexOfFirst { it == null }
|
||||
if (availableInfoFrames[randomIndex] != null) randomIndex = availableInfoFrames.indexOfFirst { it == null }
|
||||
availableInfoFrames.set(randomIndex, Random.nextBoolean())
|
||||
}
|
||||
}
|
||||
@@ -176,9 +191,31 @@ class PokedexUsageContext {
|
||||
if (newPokemonInfo == PokedexLearnedInformation.NONE) playSound(CobblemonSounds.POKEDEX_SCAN_DETAIL)
|
||||
else scannedSpecies = resolvedPokemon.getApparentSpecies().resourceIdentifier
|
||||
}
|
||||
} else {
|
||||
resetFocusedPokemonState()
|
||||
return
|
||||
}
|
||||
|
||||
// BlockEntity scan
|
||||
val blockHit = PokemonScanner.findScannableBlockEntity(user, zoomLevel.toInt())
|
||||
if (blockHit != null) {
|
||||
val (pos, be) = blockHit
|
||||
if (be != blockEntityInFocus || pos != blockPosInFocus) {
|
||||
resetFocusedPokemonState()
|
||||
blockEntityInFocus = be
|
||||
blockPosInFocus = pos
|
||||
|
||||
if (focusIntervals == 0F) {
|
||||
availableInfoFrames = mutableListOf(null, null, null, null)
|
||||
for (i in 0..3) {
|
||||
var randomIndex = Random.nextInt(availableInfoFrames.size)
|
||||
if (availableInfoFrames[randomIndex] != null) randomIndex = availableInfoFrames.indexOfFirst { it == null }
|
||||
availableInfoFrames[randomIndex] = Random.nextBoolean()
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
resetFocusedPokemonState()
|
||||
}
|
||||
|
||||
fun onServerConfirmedRegister(packet: ServerConfirmedRegisterPacket) {
|
||||
@@ -196,6 +233,8 @@ class PokedexUsageContext {
|
||||
|
||||
fun resetFocusedPokemonState() {
|
||||
scannableEntityInFocus = null
|
||||
blockEntityInFocus = null
|
||||
blockPosInFocus = null
|
||||
scannedSpecies = null
|
||||
viewInfoTicks = 0
|
||||
scanningProgress = 0F
|
||||
|
||||
@@ -9,11 +9,17 @@
|
||||
package com.cobblemon.mod.common.pokedex.scanner
|
||||
|
||||
import com.cobblemon.mod.common.Cobblemon
|
||||
import com.cobblemon.mod.common.block.entity.BerryBlockEntity
|
||||
import com.cobblemon.mod.common.pokedex.scanner.PokedexUsageContext.Companion.BLOCK_LENGTH_PER_ZOOM_STAGE
|
||||
import net.minecraft.core.BlockPos
|
||||
import net.minecraft.world.entity.Entity
|
||||
import net.minecraft.world.level.ClipContext
|
||||
import net.minecraft.world.phys.AABB
|
||||
import net.minecraft.world.phys.BlockHitResult
|
||||
import net.minecraft.world.phys.HitResult
|
||||
import com.cobblemon.mod.common.api.pokedex.scan.BlockScanProviderRegistry
|
||||
import net.minecraft.core.registries.BuiltInRegistries
|
||||
import net.minecraft.world.level.block.entity.BlockEntity
|
||||
|
||||
//Handles the actual raycasting to figure out what pokemon we are looking at
|
||||
object PokemonScanner {
|
||||
@@ -100,4 +106,34 @@ object PokemonScanner {
|
||||
fun isEntityInRange(castingEntity: Entity, targetEntity: Entity, zoomLevel: Int): Boolean {
|
||||
return targetEntity.position().distanceTo(castingEntity.position()) <= Cobblemon.config.maxPokedexScanningDetectionRange + (zoomLevel * BLOCK_LENGTH_PER_ZOOM_STAGE)
|
||||
}
|
||||
|
||||
fun findScannableBlockEntity(castingEntity: Entity, zoomLevel: Int): Pair<BlockPos, BlockEntity>? {
|
||||
val eyePos = castingEntity.getEyePosition(1.0F)
|
||||
val lookVec = castingEntity.getViewVector(1.0F)
|
||||
|
||||
val maxDistance =
|
||||
Cobblemon.config.maxPokedexScanningDetectionRange + (zoomLevel * BLOCK_LENGTH_PER_ZOOM_STAGE)
|
||||
|
||||
val end = eyePos.add(lookVec.scale(maxDistance.toDouble()))
|
||||
|
||||
val hit = castingEntity.level().clip(
|
||||
ClipContext(
|
||||
eyePos,
|
||||
end,
|
||||
ClipContext.Block.OUTLINE,
|
||||
ClipContext.Fluid.NONE,
|
||||
castingEntity
|
||||
)
|
||||
)
|
||||
|
||||
if (hit.type != HitResult.Type.BLOCK) return null
|
||||
|
||||
val pos = (hit as BlockHitResult).blockPos
|
||||
val be = castingEntity.level().getBlockEntity(pos) ?: return null
|
||||
|
||||
val typeId = BuiltInRegistries.BLOCK_ENTITY_TYPE.getKey(be.type) ?: return null
|
||||
if (BlockScanProviderRegistry.get(typeId) == null) return null
|
||||
|
||||
return pos to be
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
package com.cobblemon.mod.common.pokedex.scanner.block
|
||||
|
||||
import com.cobblemon.mod.common.api.pokedex.scan.BlockScanDefinition
|
||||
import com.cobblemon.mod.common.api.text.bold
|
||||
import com.cobblemon.mod.common.api.text.text
|
||||
import com.cobblemon.mod.common.block.BerryBlock
|
||||
import com.cobblemon.mod.common.block.entity.BerryBlockEntity
|
||||
import net.minecraft.world.item.ItemStack
|
||||
import net.minecraft.world.level.block.entity.BlockEntity
|
||||
|
||||
object BerryBlockScanProvider : BlockScanProvider {
|
||||
override val frames = listOf(
|
||||
BlockScanDefinition.Frame(
|
||||
slot = 1,
|
||||
text = BlockScanDefinition.ScanText.Translate(
|
||||
key = "ui.pokedex.scan.berry.stage",
|
||||
with = listOf(BlockScanDefinition.ScanText.Key("stage"))
|
||||
)
|
||||
),
|
||||
BlockScanDefinition.Frame(
|
||||
slot = 2,
|
||||
text = BlockScanDefinition.ScanText.Key("berry_name")
|
||||
),
|
||||
BlockScanDefinition.Frame(
|
||||
slot = 3,
|
||||
text = BlockScanDefinition.ScanText.Translate(
|
||||
key = "ui.pokedex.scan.berry.mulch",
|
||||
with = listOf(BlockScanDefinition.ScanText.Key("mulch_variant"))
|
||||
),
|
||||
scale = 1.0f
|
||||
)
|
||||
)
|
||||
|
||||
override fun getValues(be: BlockEntity): Map<String, Any?> {
|
||||
val berry = be as BerryBlockEntity
|
||||
val stage = runCatching { berry.blockState.getValue(BerryBlock.AGE) }.getOrDefault(0)
|
||||
val berryName = berry.berry()?.item()?.let { ItemStack(it).hoverName.copy().bold() }
|
||||
?: berry.berryIdentifier.toString().text().bold()
|
||||
|
||||
return mapOf(
|
||||
"stage" to stage,
|
||||
"mulch_variant" to berry.mulchVariant.toString(),
|
||||
"berry_identifier" to berry.berryIdentifier.toString(),
|
||||
"berry_name" to berryName
|
||||
)
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package com.cobblemon.mod.common.pokedex.scanner.block
|
||||
|
||||
import com.cobblemon.mod.common.api.pokedex.scan.BlockScanDefinition
|
||||
import net.minecraft.world.level.block.entity.BlockEntity
|
||||
|
||||
interface BlockScanProvider {
|
||||
val frames: List<BlockScanDefinition.Frame>
|
||||
fun getValues(be: BlockEntity): Map<String, Any?>
|
||||
}
|
||||
@@ -1508,6 +1508,9 @@
|
||||
"cobblemon.ui.pokedex.weight": "Weight: %1$skg",
|
||||
"cobblemon.ui.pokedex.height": "Height: %1$sm",
|
||||
|
||||
"cobblemon.ui.pokedex.scan.berry.stage": "Stage: %s",
|
||||
"cobblemon.ui.pokedex.scan.berry.mulch": "Mulch: %s",
|
||||
|
||||
"cobblemon.pokedex.variation.cream": "Cream",
|
||||
"cobblemon.pokedex.variation.decoration": "Decoration",
|
||||
"cobblemon.pokedex.variation.flower": "Flower",
|
||||
|
||||
Reference in New Issue
Block a user