Build creative mode tabs contents when it is not built when using creativetabsorter
This commit is contained in:
parent
c6117e659d
commit
1ee071bfdb
@ -3,8 +3,10 @@ package ru.dbotthepony.mc.otm.core.util
|
||||
import it.unimi.dsi.fastutil.objects.Reference2IntFunction
|
||||
import it.unimi.dsi.fastutil.objects.Reference2IntOpenHashMap
|
||||
import net.minecraft.network.chat.Component
|
||||
import net.minecraft.world.item.CreativeModeTabs
|
||||
import net.minecraft.world.item.Item
|
||||
import net.minecraftforge.common.CreativeModeTabRegistry
|
||||
import ru.dbotthepony.mc.otm.client.minecraft
|
||||
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
||||
import ru.dbotthepony.mc.otm.core.nullsFirst
|
||||
import ru.dbotthepony.mc.otm.core.nullsLast
|
||||
@ -23,14 +25,26 @@ object CreativeMenuComparator : Comparator<Item> {
|
||||
item2index.defaultReturnValue(Int.MAX_VALUE)
|
||||
}
|
||||
|
||||
private fun doRebuild() {
|
||||
var i = 0
|
||||
|
||||
for (tab in CreativeModeTabRegistry.getSortedCreativeModeTabs()) {
|
||||
for (item in tab.displayItems) {
|
||||
item2index.computeIfAbsent(item.item, Reference2IntFunction { i++ })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun rebuild() {
|
||||
if (item2index.isEmpty()) {
|
||||
var i = 0
|
||||
doRebuild()
|
||||
|
||||
for (tab in CreativeModeTabRegistry.getSortedCreativeModeTabs()) {
|
||||
for (item in tab.displayItems) {
|
||||
item2index.computeIfAbsent(item.item, Reference2IntFunction { i++ })
|
||||
}
|
||||
if (item2index.isEmpty()) {
|
||||
val player = minecraft.player ?: return
|
||||
// creative tabs were not populated yet
|
||||
CreativeModeTabs.tryRebuildTabContents(player.connection.enabledFeatures(), false /* operator tabs */, player.level().registryAccess())
|
||||
|
||||
doRebuild()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user