Skip to content

Commit

Permalink
maybe fix weird bug, where mod stops working
Browse files Browse the repository at this point in the history
  • Loading branch information
btwonion committed Dec 23, 2024
1 parent 0ff5142 commit a103907
Showing 1 changed file with 46 additions and 39 deletions.
85 changes: 46 additions & 39 deletions src/main/kotlin/dev/nyon/autodrop/AutoDrop.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.nyon.autodrop

import com.mojang.blaze3d.platform.InputConstants
import dev.nyon.autodrop.config.ItemIdentifier
import dev.nyon.autodrop.config.config
import dev.nyon.autodrop.config.currentItems
import dev.nyon.autodrop.config.ignoredSlots
Expand All @@ -17,6 +18,7 @@ import net.minecraft.network.chat.Component
import net.minecraft.network.chat.Style
import net.minecraft.world.entity.player.Inventory
import net.minecraft.world.inventory.ClickType
import net.minecraft.world.item.ItemStack
//? if >=1.20.5
import net.minecraft.world.item.enchantment.ItemEnchantments
import org.lwjgl.glfw.GLFW
Expand Down Expand Up @@ -47,51 +49,14 @@ object AutoDrop {
val isValid = currentItems.any { identifier ->
val typeValid = identifier.type == null || itemStack.item == identifier.type
val amountValid = itemStack.count >= identifier.amount
val componentValid = isComponentValid(itemStack, identifier)

/*? if >=1.21 {*/
val componentValid =
identifier.components.isEmpty || identifier.components.entrySet().all { (key, component) ->
val identifierComponent = component.get()
val itemComponent = itemStack.get(key) ?: return@all false

if (identifierComponent as? ItemEnchantments != null && itemComponent as? ItemEnchantments != null) {
return@all identifierComponent.entrySet()
.all { entry -> // How tf is minecraft too bad to create a simple equals check - or is it me?
itemComponent.entrySet().map { it.key.value().description.string }
.contains(entry.key.value().description.string)
}
}

itemComponent == identifierComponent
}
/*?} else if >=1.20.5 {*/
/*val componentValid = identifier.components.isEmpty || identifier.components.all { component ->
val identifierComponent = component.value
val itemComponent = itemStack.get(component.type) ?: return@all false
if (identifierComponent as? ItemEnchantments != null && itemComponent as? ItemEnchantments != null) {
return@all identifierComponent.entrySet()
.all { entry -> // How tf is minecraft too bad to create a simple equals check - or is it me?
itemComponent.entrySet().map { it.key.value().descriptionId }
.contains(entry.key.value().descriptionId)
}
}
itemComponent == identifierComponent
}
*//*?} else {*//*
val componentValid = identifier.components.allKeys.all { key ->
if (itemStack.tag == null) return@all false
itemStack.tag!!.get(key) == identifier.components.get(key)
}
*//*?}*/
typeValid && amountValid && componentValid
}


if (isValid) minecraft.gameMode?.handleInventoryMouseClick(player.containerMenu.containerId, slot.index, 1, ClickType.THROW, player)
}

}.invokeOnCompletion {
jobWaiting = false
}
}
Expand All @@ -112,4 +77,46 @@ object AutoDrop {
}
if (menuKeyBind.consumeClick()) client.setScreen(ArchiveScreen(null))
}

fun isComponentValid(itemStack: ItemStack, identifier: ItemIdentifier): Boolean {
/*? if >=1.21 {*/
val componentValid =
identifier.components.isEmpty || identifier.components.entrySet().all { (key, component) ->
val identifierComponent = component.get()
val itemComponent = itemStack.get(key) ?: return@all false

if (identifierComponent as? ItemEnchantments != null && itemComponent as? ItemEnchantments != null) {
return@all identifierComponent.entrySet()
.all { entry -> // How tf is minecraft too bad to create a simple equals check - or is it me?
itemComponent.entrySet().map { it.key.value().description.string }
.contains(entry.key.value().description.string)
}
}

itemComponent == identifierComponent
}
/*?} else if >=1.20.5 {*/
/*val componentValid = identifier.components.isEmpty || identifier.components.all { component ->
val identifierComponent = component.value
val itemComponent = itemStack.get(component.type) ?: return@all false
if (identifierComponent as? ItemEnchantments != null && itemComponent as? ItemEnchantments != null) {
return@all identifierComponent.entrySet()
.all { entry -> // How tf is minecraft too bad to create a simple equals check - or is it me?
itemComponent.entrySet().map { it.key.value().descriptionId }
.contains(entry.key.value().descriptionId)
}
}
itemComponent == identifierComponent
}
*//*?} else {*//*
val componentValid = identifier.components.allKeys.all { key ->
if (itemStack.tag == null) return@all false
itemStack.tag!!.get(key) == identifier.components.get(key)
}
*//*?}*/

return componentValid
}
}

0 comments on commit a103907

Please sign in to comment.