mirror of
https://gitlab.com/cable-mc/cobblemon.git
synced 2026-10-21 14:46:25 -04:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0d4eaa464a |
@@ -21,6 +21,7 @@ import com.cobblemon.mod.common.api.events.CobblemonEvents
|
||||
import com.cobblemon.mod.common.api.events.entity.PokemonEntityLoadEvent
|
||||
import com.cobblemon.mod.common.api.events.entity.PokemonEntitySaveEvent
|
||||
import com.cobblemon.mod.common.api.events.entity.PokemonEntitySaveToWorldEvent
|
||||
import com.cobblemon.mod.common.api.events.pokemon.HeldItemEvent
|
||||
import com.cobblemon.mod.common.api.events.pokemon.RidePokemonEvent
|
||||
import com.cobblemon.mod.common.api.events.pokemon.ShoulderMountEvent
|
||||
import com.cobblemon.mod.common.api.interaction.PokemonEntityInteraction
|
||||
@@ -1469,10 +1470,16 @@ open class PokemonEntity(
|
||||
return false
|
||||
}
|
||||
|
||||
val returned = if (isCosmetic) {
|
||||
this.pokemon.swapCosmeticItem(stack = stack, decrement = !player.isCreative)
|
||||
val currentItem = if (isCosmetic) pokemon.cosmeticItem else pokemon.heldItem
|
||||
val pre = HeldItemEvent.Pre(pokemon, stack, currentItem.copy(), !player.isCreative)
|
||||
if (isCosmetic) CobblemonEvents.COSMETIC_ITEM_PRE.post(pre) else CobblemonEvents.HELD_ITEM_PRE.post(pre)
|
||||
if (pre.isCanceled) return false
|
||||
|
||||
val returned = pre.returning
|
||||
if (isCosmetic) {
|
||||
this.pokemon.swapCosmeticItem(stack = pre.receiving, decrement = !player.isCreative)
|
||||
} else {
|
||||
this.pokemon.swapHeldItem(stack = stack, decrement = !player.isCreative, false)
|
||||
this.pokemon.swapHeldItem(stack = pre.receiving, decrement = !player.isCreative, false)
|
||||
}
|
||||
|
||||
val text = when {
|
||||
@@ -1484,7 +1491,7 @@ open class PokemonEntity(
|
||||
else -> lang("held_item.replace", returned.displayName, this.pokemon.getDisplayName(), giving.displayName)
|
||||
}
|
||||
|
||||
player.giveOrDropItemStack(returned, false)
|
||||
player.giveOrDropItemStack(pre.returning, false)
|
||||
player.sendSystemMessage(text)
|
||||
this.level().playSoundServer(
|
||||
position = this.position(),
|
||||
@@ -1493,6 +1500,13 @@ open class PokemonEntity(
|
||||
pitch = 1.4F
|
||||
)
|
||||
|
||||
if (isCosmetic) {
|
||||
CobblemonEvents.COSMETIC_ITEM_POST.post(HeldItemEvent.Post(pokemon, pokemon.cosmeticItem.copy(), pre.returning.copy(), pre.decrement))
|
||||
}
|
||||
else {
|
||||
CobblemonEvents.HELD_ITEM_POST.post(HeldItemEvent.Post(pokemon, pokemon.heldItem.copy(), pre.returning.copy(), pre.decrement))
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
@@ -1188,25 +1188,19 @@ open class Pokemon : ShowdownIdentifiable {
|
||||
* @see [HeldItemEvent]
|
||||
*/
|
||||
fun swapHeldItem(stack: ItemStack, decrement: Boolean = true, aiCanDrop: Boolean = true): ItemStack {
|
||||
val existing = this.heldItem()
|
||||
val event = HeldItemEvent.Pre(this, stack, existing, decrement)
|
||||
if (!isClient) {
|
||||
CobblemonEvents.HELD_ITEM_PRE.post(event)
|
||||
val returning = this.heldItem.copy()
|
||||
val giving = stack.copy().apply { count = 1 }
|
||||
if (decrement) {
|
||||
stack.shrink(1)
|
||||
}
|
||||
if (!event.isCanceled) {
|
||||
val giving = event.receiving.copy().apply { count = 1 }
|
||||
if (event.decrement) {
|
||||
event.receiving.shrink(1)
|
||||
}
|
||||
this.heldItem = giving
|
||||
this.canDropHeldItem = giving.isEmpty || aiCanDrop
|
||||
onChange(HeldItemUpdatePacket({ this }, giving))
|
||||
CobblemonEvents.HELD_ITEM_POST.post(HeldItemEvent.Post(this, this.heldItem(), event.returning.copy(), event.decrement)) {
|
||||
StashHandler.giveHeldItem(it)
|
||||
}
|
||||
return event.returning
|
||||
this.heldItem = giving
|
||||
this.canDropHeldItem = giving.isEmpty || aiCanDrop
|
||||
onChange(HeldItemUpdatePacket({ this }, giving))
|
||||
val shouldRemoveHeldItem = StashHandler.handleItem(this, giving.item)
|
||||
if (shouldRemoveHeldItem) {
|
||||
removeHeldItem()
|
||||
}
|
||||
return stack
|
||||
return returning
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1230,21 +1224,13 @@ open class Pokemon : ShowdownIdentifiable {
|
||||
* @see [HeldItemEvent]
|
||||
*/
|
||||
fun swapCosmeticItem(stack: ItemStack, decrement: Boolean = true): ItemStack {
|
||||
val existing = this.cosmeticItem.copy()
|
||||
val event = HeldItemEvent.Pre(this, stack, existing, decrement)
|
||||
if (!isClient) {
|
||||
CobblemonEvents.COSMETIC_ITEM_PRE.post(event)
|
||||
val returning = this.cosmeticItem.copy()
|
||||
val giving = stack.copy().apply { count = 1 }
|
||||
if (decrement) {
|
||||
stack.shrink(1)
|
||||
}
|
||||
if (!event.isCanceled) {
|
||||
val giving = event.receiving.copy().apply { count = 1 }
|
||||
if (event.decrement) {
|
||||
event.receiving.shrink(1)
|
||||
}
|
||||
this.cosmeticItem = giving
|
||||
CobblemonEvents.COSMETIC_ITEM_POST.post(HeldItemEvent.Post(this, this.cosmeticItem.copy(), event.returning.copy(), event.decrement))
|
||||
return event.returning
|
||||
}
|
||||
return stack
|
||||
this.cosmeticItem = giving
|
||||
return returning
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user