Skip to content
This repository has been archived by the owner on May 27, 2024. It is now read-only.

Commit

Permalink
Speed up item tracking system
Browse files Browse the repository at this point in the history
  • Loading branch information
0ffz committed Aug 21, 2022
1 parent 40a3bc2 commit 26094d2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/main/kotlin/com/mineinabyss/looty/LootyFactory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ object LootyFactory {
}
}

private fun updateOldLootyItem(pdc: PersistentDataContainer, item: NMSItemStack) {
private fun updateOldLootyItem(pdc: PersistentDataContainer, prefabs: Set<PrefabKey>, item: NMSItemStack) {
val tag = item.tag ?: return
if (!tag.contains("CustomModelData")) return
if (!pdc.hasComponentsEncoded || pdc.decodePrefabs().isEmpty()) {
if (prefabs.isEmpty()) {
val prefab = CustomModelDataToPrefabMap[CustomItem(
CraftMagicNumbers.getMaterial(item.item),
tag.getInt("CustomModelData")
Expand All @@ -71,11 +71,11 @@ object LootyFactory {

//TODO maybe if the prefab has PlayerInstancedItem added to it, we should remove id?
fun getItemState(pdc: PersistentDataContainer?, slot: Int, item: NMSItemStack): ItemState {
if (pdc == null || item.item == Items.AIR) return ItemState.Empty()
if (pdc == null || item.item == Items.AIR || !pdc.hasComponentsEncoded) return ItemState.Empty()
val prefabs = pdc.decodePrefabs()
if (LootyConfig.data.migrateByCustomModelData) {
updateOldLootyItem(pdc, item)
updateOldLootyItem(pdc, prefabs, item)
}
val prefabs = pdc.decodePrefabs()
if (prefabs.size == 1) {
val prefab = prefabs.first().toEntityOrNull() ?: return ItemState.Empty()
if (prefab.has<PlayerInstancedItem>()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ class PlayerItemCache(parent: GearyEntity) {

fun updateItem(slot: Int, item: NMSItemStack) {
// Get the instance of the prefab if the entity is a prefab

val cached = cachedItems[slot]
if(cached === item) return
cachedItems[slot] = item
val entity = entities[slot].toGeary()
if(entity == NO_ENTITY) return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class ItemTrackerSystem : RepeatingSystem(interval = 1.ticks) {
}

nmsInv.compartments.forEach { comp ->
comp.forEach itemLoop@{ item ->
comp.forEach { item ->
calculateForItem(item, slot++)
}
}
Expand Down

0 comments on commit 26094d2

Please sign in to comment.