Compare commits

...
Author SHA1 Message Date
tmetcalfe89 43c0159471 mock up for it 2024-10-13 16:57:59 -07:00
2 changed files with 91 additions and 0 deletions
@@ -10,6 +10,8 @@ package com.cobblemon.mod.common.item
import com.cobblemon.mod.common.client.CobblemonClient
import com.cobblemon.mod.common.client.pokedex.PokedexTypes
import com.cobblemon.mod.common.pokedex.scanner.PokedexController
import com.cobblemon.mod.common.pokedex.scanner.PokemonScanner
import net.minecraft.client.player.LocalPlayer
import net.minecraft.server.level.ServerPlayer
import net.minecraft.world.InteractionHand
@@ -53,6 +55,10 @@ class PokedexItem(val type: PokedexTypes): CobblemonItem(Item.Properties().stack
val ticksInUse = getUseDuration(stack, user) - remainingUseTicks
usageContext.useTick(user, ticksInUse, true)
}
if (!world.isClientSide && user is ServerPlayer) {
val controller = PokedexController.getController(user)
controller.useTick(remainingUseTicks)
}
super.onUseTick(world, user, stack, remainingUseTicks)
}
@@ -67,6 +73,10 @@ class PokedexItem(val type: PokedexTypes): CobblemonItem(Item.Properties().stack
val ticksInUse = getUseDuration(stack, user) - remainingUseTicks
usageContext.stopUsing(user, ticksInUse)
}
if (!world.isClientSide && user is ServerPlayer) {
val controller = PokedexController.getController(user)
controller.end()
}
super.releaseUsing(stack, world, user, remainingUseTicks)
}
@@ -0,0 +1,81 @@
package com.cobblemon.mod.common.pokedex.scanner
import com.cobblemon.mod.common.pokemon.Pokemon
import net.minecraft.server.level.ServerPlayer
import java.util.*
enum class STATE {
IDLE,
SCANNING,
SCANNED
}
class PokedexController(val player: ServerPlayer) {
companion object {
private val controllers = mutableMapOf<UUID, PokedexController>()
fun getController(player: ServerPlayer): PokedexController {
val uuid = player.uuid
if (!controllers.containsKey(uuid)) controllers[uuid] = PokedexController(player)
return controllers[uuid]!!
}
const val GOAL_TICKS = 50
}
var zoom: Int = 10
var targetPokemon: Pokemon? = null
private var startTime: Int? = null
var state: STATE = STATE.IDLE
fun useTick(remainingUseTicks: Int) {
val target = PokemonScanner.findPokemon(player, zoom)
if (target === null) {
// Not pointed at anything.
startTime = null
targetPokemon = null
zoom = 10
state = STATE.IDLE
// TODO: Send IDLE update packet
/**
* {
* state: "IDLE"
* }
*/
return
}
val newTargetPokemon = target.pokemon
if (targetPokemon !== newTargetPokemon) {
// Pointed at a new thing.
startTime = remainingUseTicks
targetPokemon = newTargetPokemon
state = STATE.SCANNING
// TODO: Send SCANNING update packet
/**
* {
* state: "SCANNING"
* }
*/
return
}
if (state == STATE.SCANNING && startTime!! - remainingUseTicks >= GOAL_TICKS) {
state = STATE.SCANNED
// TODO: Send SCANNED update packet
/**
* {
* state: "SCANNED",
* pokemon: targetPokemon
* }
*/
}
}
fun end() {
startTime = null
targetPokemon = null
if (state !== STATE.IDLE) {
// TODO: Send IDLE update packet (as above, so below)
state = STATE.IDLE
}
}
}