feat: Add more complex entity equipment scraper
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -1,11 +1,22 @@
|
||||
|
||||
package moe.nea.firmament.events
|
||||
|
||||
import net.minecraft.item.ItemStack
|
||||
|
||||
sealed class PlayerInventoryUpdate : FirmamentEvent() {
|
||||
companion object : FirmamentEventBus<PlayerInventoryUpdate>()
|
||||
data class Single(val slot: Int, val stack: ItemStack) : PlayerInventoryUpdate()
|
||||
data class Multi(val contents: List<ItemStack>) : PlayerInventoryUpdate()
|
||||
companion object : FirmamentEventBus<PlayerInventoryUpdate>()
|
||||
data class Single(val slot: Int, val stack: ItemStack) : PlayerInventoryUpdate() {
|
||||
override fun getOrNull(slot: Int): ItemStack? {
|
||||
if (slot == this.slot) return stack
|
||||
return null
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
data class Multi(val contents: List<ItemStack>) : PlayerInventoryUpdate() {
|
||||
override fun getOrNull(slot: Int): ItemStack? {
|
||||
return contents.getOrNull(slot)
|
||||
}
|
||||
}
|
||||
|
||||
abstract fun getOrNull(slot: Int): ItemStack?
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user