Rework item evolution so it works with the stones

This commit is contained in:
Paul committed 2022-08-29 14:41:43 +10:00
1 parent df4bde2295
commit de76affc30
20 files changed
+183 -68

No files matched your search

@@ -1,7 +1,5 @@
package com.cablemc.pokemoncobbled.common.api.item
import com.cablemc.pokemoncobbled.common.item.CobbledItem
import net.minecraft.item.ItemGroup
import com.cablemc.pokemoncobbled.common.item.interactive.EvolutionItem
open class EvolutionStoneItem : CobbledItem(Settings().group(ItemGroup.MISC)) {
}
open class EvolutionStoneItem : EvolutionItem()
@@ -1,7 +1,5 @@
package com.cablemc.pokemoncobbled.common.api.pokemon.evolution
import com.cablemc.pokemoncobbled.common.pokemon.FormData
import com.cablemc.pokemoncobbled.common.pokemon.Gender
import com.cablemc.pokemoncobbled.common.pokemon.Pokemon
import com.cablemc.pokemoncobbled.common.pokemon.Species
@@ -30,6 +30,7 @@ import com.cablemc.pokemoncobbled.common.pokemon.activestate.ActivePokemonState
import com.cablemc.pokemoncobbled.common.pokemon.activestate.InactivePokemonState
import com.cablemc.pokemoncobbled.common.pokemon.activestate.ShoulderedState
import com.cablemc.pokemoncobbled.common.pokemon.ai.FormPokemonBehaviour
import com.cablemc.pokemoncobbled.common.pokemon.evolution.variants.ItemInteractionEvolution
import com.cablemc.pokemoncobbled.common.util.DataKeys
import com.cablemc.pokemoncobbled.common.util.getBitForByte
import com.cablemc.pokemoncobbled.common.util.playSoundServer
@@ -61,6 +62,7 @@ import net.minecraft.server.world.ServerWorld
import net.minecraft.util.ActionResult
import net.minecraft.util.Hand
import net.minecraft.util.math.BlockPos
import net.minecraft.util.registry.Registry
import net.minecraft.world.World
class PokemonEntity(
@@ -258,7 +260,10 @@ class PokemonEntity(
override fun interactMob(player: PlayerEntity, hand: Hand) : ActionResult {
// TODO: Move to proper pokemon interaction menu
this.attemptItemInteraction(player, player.getStackInHand(hand))
if (this.attemptItemInteraction(player, player.getStackInHand(hand))) {
// TODO #105
return ActionResult.SUCCESS
}
if (player.isSneaking && hand == Hand.MAIN_HAND) {
if (isReadyToSitOnPlayer && player is ServerPlayerEntity && !isBusy) {
this.tryMountingShoulder(player)
@@ -350,12 +355,37 @@ class PokemonEntity(
return true
}
private fun attemptItemInteraction(playerIn: PlayerEntity, stack: ItemStack) {
if (playerIn !is ServerPlayerEntity || stack.isEmpty) return
(stack.item as? PokemonInteractiveItem)?.onInteraction(playerIn, this, stack)
private fun attemptItemInteraction(player: PlayerEntity, stack: ItemStack): Boolean {
if (player !is ServerPlayerEntity || stack.isEmpty) {
return false
}
val itemRegistry = player.getWorld().registryManager.get(Registry.ITEM_KEY)
val item = itemRegistry.getKey(stack.item).orElse(null).value
if (pokemon.getOwnerPlayer() == player) {
pokemon.evolutions
.filterIsInstance<ItemInteractionEvolution>()
.forEach { evolution ->
if (evolution.attemptEvolution(pokemon, item)) {
if (!player.isCreative && evolution.consumeHeldItem) {
stack.decrement(1)
}
return true
}
}
}
(stack.item as? PokemonInteractiveItem)?.let {
if (it.onInteraction(player, this, stack)) {
return true
}
}
return false
}
private fun tryMountingShoulder(player: ServerPlayerEntity) {
private fun tryMountingShoulder(player: ServerPlayerEntity): Boolean {
if (this.pokemon.belongsTo(player) && this.hasRoomToMount(player)) {
CobbledEvents.SHOULDER_MOUNT.postThen(ShoulderMountEvent(player, pokemon, isLeft = player.shoulderEntityLeft.isEmpty)) {
val dirToPlayer = player.eyePos.subtract(pos).multiply(1.0, 0.0, 1.0).normalize()
@@ -373,8 +403,10 @@ class PokemonEntity(
}
}
}
return true
}
}
return false
}
override fun remove(reason: RemovalReason?) {
@@ -2,6 +2,4 @@ package com.cablemc.pokemoncobbled.common.item.evo
import com.cablemc.pokemoncobbled.common.api.item.EvolutionStoneItem
class DawnStone : EvolutionStoneItem() {
// TODO: Evolutions on whatever right click idk...
}
class DawnStone : EvolutionStoneItem()
@@ -2,6 +2,4 @@ package com.cablemc.pokemoncobbled.common.item.evo
import com.cablemc.pokemoncobbled.common.api.item.EvolutionStoneItem
class DuskStone : EvolutionStoneItem() {
// TODO: Evolutions on whatever right click idk...
}
class DuskStone : EvolutionStoneItem()
@@ -2,6 +2,4 @@ package com.cablemc.pokemoncobbled.common.item.evo
import com.cablemc.pokemoncobbled.common.api.item.EvolutionStoneItem
class FireStone : EvolutionStoneItem() {
// TODO: Evolutions on whatever right click idk...
}
class FireStone : EvolutionStoneItem()
@@ -2,6 +2,4 @@ package com.cablemc.pokemoncobbled.common.item.evo
import com.cablemc.pokemoncobbled.common.api.item.EvolutionStoneItem
class IceStone : EvolutionStoneItem() {
// TODO: Evolutions on whatever right click idk...
}
class IceStone : EvolutionStoneItem()
@@ -2,6 +2,4 @@ package com.cablemc.pokemoncobbled.common.item.evo
import com.cablemc.pokemoncobbled.common.api.item.EvolutionStoneItem
class LeafStone : EvolutionStoneItem() {
// TODO: Evolutions on whatever right click idk...
}
class LeafStone : EvolutionStoneItem()
@@ -2,6 +2,4 @@ package com.cablemc.pokemoncobbled.common.item.evo
import com.cablemc.pokemoncobbled.common.api.item.EvolutionStoneItem
class MoonStone : EvolutionStoneItem() {
// TODO: Evolutions on whatever right click idk...
}
class MoonStone : EvolutionStoneItem()
@@ -2,6 +2,4 @@ package com.cablemc.pokemoncobbled.common.item.evo
import com.cablemc.pokemoncobbled.common.api.item.EvolutionStoneItem
class ShinyStone : EvolutionStoneItem() {
// TODO: Evolutions on whatever right click idk...
}
class ShinyStone : EvolutionStoneItem()
@@ -2,6 +2,4 @@ package com.cablemc.pokemoncobbled.common.item.evo
import com.cablemc.pokemoncobbled.common.api.item.EvolutionStoneItem
class SunStone : EvolutionStoneItem() {
// TODO: Evolutions on whatever right click idk...
}
class SunStone : EvolutionStoneItem()
@@ -2,6 +2,4 @@ package com.cablemc.pokemoncobbled.common.item.evo
import com.cablemc.pokemoncobbled.common.api.item.EvolutionStoneItem
class ThunderStone : EvolutionStoneItem() {
// TODO: Evolutions on whatever right click idk...
}
class ThunderStone : EvolutionStoneItem()
@@ -2,6 +2,4 @@ package com.cablemc.pokemoncobbled.common.item.evo
import com.cablemc.pokemoncobbled.common.api.item.EvolutionStoneItem
class WaterStone : EvolutionStoneItem() {
// TODO: Evolutions on whatever right click idk...
}
class WaterStone : EvolutionStoneItem()
@@ -23,7 +23,7 @@ class CandyItem(
val calculator: Calculator
) : PokemonInteractiveItem(Settings().group(CobbledItemGroups.MEDICINE_ITEM_GROUP), Ownership.OWNER) {
override fun processInteraction(player: ServerPlayerEntity, entity: PokemonEntity, stack: ItemStack) {
override fun processInteraction(player: ServerPlayerEntity, entity: PokemonEntity, stack: ItemStack): Boolean {
val pokemon = entity.pokemon
val experience = this.calculator.calculate(player, pokemon)
CobbledEvents.EXPERIENCE_CANDY_USE_PRE.postThen(
@@ -34,8 +34,10 @@ class CandyItem(
val source = CandyExperienceSource(player, stack)
pokemon.addExperienceWithPlayer(player, source, finalExperience)
this.consumeItem(player, stack)
return true
}
)
return false
}
/**
@@ -1,19 +1,6 @@
package com.cablemc.pokemoncobbled.common.item.interactive
import com.cablemc.pokemoncobbled.common.entity.pokemon.PokemonEntity
import com.cablemc.pokemoncobbled.common.item.CobbledItem
import com.cablemc.pokemoncobbled.common.item.CobbledItemGroups
import com.cablemc.pokemoncobbled.common.pokemon.evolution.variants.ItemInteractionEvolution
import net.minecraft.item.ItemStack
import net.minecraft.server.network.ServerPlayerEntity
class EvolutionItem(properties: Settings = Settings().group(CobbledItemGroups.EVOLUTION_ITEM_GROUP)) : PokemonInteractiveItem(properties, Ownership.OWNER) {
override fun processInteraction(player: ServerPlayerEntity, entity: PokemonEntity, stack: ItemStack) {
val pokemon = entity.pokemon
pokemon.evolutions.filterIsInstance<ItemInteractionEvolution>()
.forEach { evolution ->
if (evolution.attemptEvolution(pokemon, this)) {
this.consumeItem(player, stack)
}
}
}
}
open class EvolutionItem(properties: Settings = Settings().group(CobbledItemGroups.EVOLUTION_ITEM_GROUP)) : CobbledItem(properties)
@@ -21,7 +21,8 @@ abstract class InteractiveItem<T : Entity>(properties: Settings) : CobbledItem(p
* @param player The [ServerPlayerEntity] interacting with the [entity].
* @param entity The [Entity] of type [T] being interacted.
* @param stack The [ItemStack] used in this interaction. [ItemStack.getItem] will always be of the same type as this [InteractiveItem].
* @return true if the interaction was successful and no further interactions should be processed
*/
abstract fun onInteraction(player: ServerPlayerEntity, entity: T, stack: ItemStack)
abstract fun onInteraction(player: ServerPlayerEntity, entity: T, stack: ItemStack): Boolean
}
@@ -14,7 +14,7 @@ abstract class PokemonInteractiveItem(properties: Settings, vararg accepted: Own
private val accepted = accepted.toSet()
final override fun onInteraction(player: ServerPlayerEntity, entity: PokemonEntity, stack: ItemStack) {
final override fun onInteraction(player: ServerPlayerEntity, entity: PokemonEntity, stack: ItemStack): Boolean {
val pokemon = entity.pokemon
val storeCoordinates = pokemon.storeCoordinates.get()
val ownership = when {
@@ -22,8 +22,11 @@ abstract class PokemonInteractiveItem(properties: Settings, vararg accepted: Own
storeCoordinates.store.uuid == player.uuid -> Ownership.OWNER
else -> Ownership.OWNED_ANOTHER
}
if (this.accepted.contains(ownership))
return if (ownership in accepted) {
this.processInteraction(player, entity, stack)
} else {
false
}
}
/**
@@ -32,8 +35,9 @@ abstract class PokemonInteractiveItem(properties: Settings, vararg accepted: Own
* @param player The [ServerPlayerEntity] interacting with the [entity].
* @param entity The [PokemonEntity] being interacted with.
* @param stack The [ItemStack] used in this interaction. [ItemStack.getItem] will always be of the same type as this [InteractiveItem].
* @return true if the interaction was successful and no further interactions should be processed.
*/
abstract fun processInteraction(player: ServerPlayerEntity, entity: PokemonEntity, stack: ItemStack)
abstract fun processInteraction(player: ServerPlayerEntity, entity: PokemonEntity, stack: ItemStack): Boolean
/**
* Decreases the stack size by a given amount.
@@ -45,8 +49,9 @@ abstract class PokemonInteractiveItem(properties: Settings, vararg accepted: Own
* @param amount The amount to deduct from the stack, default is 1.
*/
protected fun consumeItem(player: ServerPlayerEntity, stack: ItemStack, amount: Int = 1) {
if (!player.isCreative)
if (!player.isCreative) {
stack.decrement(amount)
}
}
/**
@@ -14,5 +14,4 @@ class AcceptEvolutionPacket() : EvolutionDisplayUpdatePacket() {
val evolution = pokemon.evolutionProxy.server().firstOrNull { evolution -> evolution.id.equals(this.evolutionId, true) } ?: return
pokemon.evolutionProxy.server().start(evolution)
}
}
@@ -7,7 +7,6 @@ import com.cablemc.pokemoncobbled.common.api.pokemon.evolution.requirement.Evolu
import com.cablemc.pokemoncobbled.common.item.interactive.EvolutionItem
import com.cablemc.pokemoncobbled.common.pokemon.Pokemon
import net.minecraft.util.Identifier
import net.minecraft.util.registry.Registry
/**
* Represents a [ContextEvolution] with [Identifier] context.
@@ -25,7 +24,7 @@ open class ItemInteractionEvolution(
override var consumeHeldItem: Boolean,
override val requirements: MutableSet<EvolutionRequirement>,
override val learnableMoves: MutableSet<MoveTemplate>
) : ContextEvolution<EvolutionItem, Identifier> {
) : ContextEvolution<Identifier, Identifier> {
constructor(): this(
id = "id",
result = PokemonProperties(),
@@ -36,9 +35,8 @@ open class ItemInteractionEvolution(
learnableMoves = mutableSetOf()
)
override fun testContext(pokemon: Pokemon, context: EvolutionItem): Boolean {
val contextKey = Registry.ITEM.getKey(context)
return contextKey == this.requiredContext
override fun testContext(pokemon: Pokemon, context: Identifier): Boolean {
return context == this.requiredContext
}
override fun equals(other: Any?) = other is ItemInteractionEvolution && other.id.equals(this.id, true)
@@ -0,0 +1,115 @@
{
"name": "cleffa",
"nationalPokedexNumber": 173,
"primaryType": "fairy",
"abilities": [
"cutecharm",
"magicguard",
"h:friendguard"
],
"baseStats": {
"hp": 50,
"attack": 25,
"defence": 28,
"special_attack": 45,
"special_defence": 55,
"speed": 15
},
"catchRate": 150,
"maleRatio": 0.25,
"shoulderMountable": false,
"forms": [],
"baseExperienceYield": 44,
"experienceGroup": "fast",
"eggCycles": 10,
"eggGroups": [
"no-eggs"
],
"moves": [
"1:pound",
"1:splash",
"1:copycat",
"4:sing",
"8:sweetkiss",
"12:disarmingvoice",
"16:encore",
"20:charm",
"egg:aromatherapy",
"egg:healpulse",
"egg:present",
"egg:tickle",
"egg:wish",
"tm:amnesia",
"tm:attract",
"tm:bodyslam",
"tm:dig",
"tm:drainingkiss",
"tm:endure",
"tm:facade",
"tm:faketears",
"tm:fireblast",
"tm:flamethrower",
"tm:fling",
"tm:grassknot",
"tm:helpinghand",
"tm:hypervoice",
"tm:icywind",
"tm:irontail",
"tm:lightscreen",
"tm:magicalleaf",
"tm:megakick",
"tm:megapunch",
"tm:metronome",
"tm:mistyterrain",
"tm:playrough",
"tm:protect",
"tm:psychic",
"tm:psyshock",
"tm:raindance",
"tm:reflect",
"tm:rest",
"tm:round",
"tm:safeguard",
"tm:shadowball",
"tm:sleeptalk",
"tm:snore",
"tm:solarbeam",
"tm:storedpower",
"tm:substitute",
"tm:sunnyday",
"tm:thunderwave",
"tm:trick",
"tm:uproar",
"tm:wonderroom",
"tm:workup",
"tm:zenheadbutt"
],
"labels": [
"baby",
"gen2"
],
"pokedex": [
"pokemoncobbled.species.cleffa.desc1",
"pokemoncobbled.species.cleffa.desc2"
],
"evolutions": [
{
"variant": "level_up",
"result": "clefairy",
"consumeHeldItem": false,
"learnableMoves": [],
"requirements": [
{
"variant": "friendship",
"amount": 160
}
]
}
],
"baseScale": 1.0,
"hitbox": {
"width": 1.0,
"height": 1.0,
"fixed": false
}
}