aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/events/EntityUpdateEvent.kt
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2025-05-07 23:09:10 +0200
committerLinnea Gräf <nea@nea.moe>2025-05-07 23:09:10 +0200
commit63669bc28be11adbf55c8d49bb747bb22124be86 (patch)
treed77c8e5a7e32985ae1402eba16544a49d3c163e9 /src/main/kotlin/events/EntityUpdateEvent.kt
parent38fd61fdcc70f75f5b8b5eb39e21c34aaf5ceb90 (diff)
downloadFirmament-63669bc28be11adbf55c8d49bb747bb22124be86.tar.gz
Firmament-63669bc28be11adbf55c8d49bb747bb22124be86.tar.bz2
Firmament-63669bc28be11adbf55c8d49bb747bb22124be86.zip
feat: Add more complex entity equipment scraper
Diffstat (limited to 'src/main/kotlin/events/EntityUpdateEvent.kt')
-rw-r--r--src/main/kotlin/events/EntityUpdateEvent.kt24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/main/kotlin/events/EntityUpdateEvent.kt b/src/main/kotlin/events/EntityUpdateEvent.kt
index 27a90f9..fec2fa5 100644
--- a/src/main/kotlin/events/EntityUpdateEvent.kt
+++ b/src/main/kotlin/events/EntityUpdateEvent.kt
@@ -7,6 +7,8 @@ import net.minecraft.entity.LivingEntity
import net.minecraft.entity.data.DataTracker
import net.minecraft.item.ItemStack
import net.minecraft.network.packet.s2c.play.EntityAttributesS2CPacket
+import moe.nea.firmament.annotations.Subscribe
+import moe.nea.firmament.util.MC
/**
* This event is fired when some entity properties are updated.
@@ -15,7 +17,27 @@ import net.minecraft.network.packet.s2c.play.EntityAttributesS2CPacket
* *after* the values have been applied to the entity.
*/
sealed class EntityUpdateEvent : FirmamentEvent() {
- companion object : FirmamentEventBus<EntityUpdateEvent>()
+ companion object : FirmamentEventBus<EntityUpdateEvent>() {
+ @Subscribe
+ fun onPlayerInventoryUpdate(event: PlayerInventoryUpdate) {
+ val p = MC.player ?: return
+ val updatedSlots = listOf(
+ EquipmentSlot.HEAD to 39,
+ EquipmentSlot.CHEST to 38,
+ EquipmentSlot.LEGS to 37,
+ EquipmentSlot.FEET to 36,
+ EquipmentSlot.OFFHAND to 40,
+ EquipmentSlot.MAINHAND to p.inventory.selectedSlot, // TODO: also equipment update when you swap your selected slot perhaps
+ ).mapNotNull { (slot, stackIndex) ->
+ val slotIndex = p.playerScreenHandler.getSlotIndex(p.inventory, stackIndex).asInt
+ event.getOrNull(slotIndex)?.let {
+ Pair.of(slot, it)
+ }
+ }
+ if (updatedSlots.isNotEmpty())
+ publish(EquipmentUpdate(p, updatedSlots))
+ }
+ }
abstract val entity: Entity