Some logic fixups to creative menus
This commit is contained in:
parent
2220a7039f
commit
f183e2a008
@ -199,6 +199,8 @@ public final class OverdriveThatMatters {
|
||||
EVENT_BUS.addListener(EventPriority.NORMAL, MatteryPlayerCapability.Companion::onStopTracking);
|
||||
EVENT_BUS.addListener(EventPriority.NORMAL, MatteryPlayerCapability.Companion::addCommands);
|
||||
|
||||
EVENT_BUS.addListener(EventPriority.NORMAL, MCreativeTabsKt::invalidateCreativeMenus);
|
||||
|
||||
EVENT_BUS.addListener(EventPriority.NORMAL, ExplosionQueue.Companion::onWorldTick);
|
||||
EVENT_BUS.addListener(EventPriority.NORMAL, AbstractWeaponItem.Companion::tick);
|
||||
EVENT_BUS.addListener(EventPriority.NORMAL, QuantumBatteryItem.Companion::tick);
|
||||
|
@ -16,6 +16,7 @@ import ru.dbotthepony.mc.otm.core.registryName
|
||||
import ru.dbotthepony.mc.otm.matter.MatterManager
|
||||
import ru.dbotthepony.mc.otm.storage.ItemStorageStack
|
||||
import ru.dbotthepony.mc.otm.client.render.Widgets18
|
||||
import ru.dbotthepony.mc.otm.registry.creativeMenuInvalidationCounter
|
||||
|
||||
private fun Comparator<Item>.stacks(): Comparator<ItemStack> {
|
||||
return Comparator { o1, o2 -> this@stacks.compare(o1.item, o2.item) }
|
||||
@ -31,7 +32,7 @@ object CreativeMenuItemComparator : Comparator<Item> {
|
||||
return item2index.getInt(o1).compareTo(item2index.getInt(o2))
|
||||
}
|
||||
|
||||
private val item2index = Reference2IntOpenHashMap<Item>()
|
||||
private val item2index by countingLazy(creativeMenuInvalidationCounter) { Reference2IntOpenHashMap<Item>() }
|
||||
|
||||
init {
|
||||
item2index.defaultReturnValue(Int.MAX_VALUE)
|
||||
|
@ -8,6 +8,7 @@ import net.minecraft.world.item.ItemStack
|
||||
import net.minecraft.world.level.ItemLike
|
||||
import net.minecraft.world.level.material.Fluids
|
||||
import net.minecraftforge.common.capabilities.ForgeCapabilities
|
||||
import net.minecraftforge.event.TagsUpdatedEvent
|
||||
import net.minecraftforge.fluids.FluidStack
|
||||
import net.minecraftforge.fluids.capability.IFluidHandler
|
||||
import net.minecraftforge.registries.ForgeRegistries
|
||||
@ -15,6 +16,8 @@ import ru.dbotthepony.mc.otm.capability.matter.matter
|
||||
import ru.dbotthepony.mc.otm.capability.matteryEnergy
|
||||
import ru.dbotthepony.mc.otm.core.ifPresentK
|
||||
import ru.dbotthepony.mc.otm.core.registryName
|
||||
import ru.dbotthepony.mc.otm.core.util.IntCounter
|
||||
import ru.dbotthepony.mc.otm.core.util.countingLazy
|
||||
|
||||
class CreativeTabOutput {
|
||||
private val items = ArrayList<ItemStack>()
|
||||
@ -285,6 +288,12 @@ private fun addDecorativeTabItems(consumer: CreativeTabOutput) {
|
||||
}
|
||||
}
|
||||
|
||||
val creativeMenuInvalidationCounter = IntCounter()
|
||||
|
||||
// lazy is to prevent "exception in initializer" and allow to re-initialize in future
|
||||
val MainTabContents by lazy { CreativeTabOutput().also { addMainCreativeTabItems(it) } }
|
||||
val DecorativeTabContents by lazy { CreativeTabOutput().also { addDecorativeTabItems(it) } }
|
||||
val MainTabContents by countingLazy(creativeMenuInvalidationCounter) { CreativeTabOutput().also { addMainCreativeTabItems(it) } }
|
||||
val DecorativeTabContents by countingLazy(creativeMenuInvalidationCounter) { CreativeTabOutput().also { addDecorativeTabItems(it) } }
|
||||
|
||||
fun invalidateCreativeMenus(event: TagsUpdatedEvent) {
|
||||
creativeMenuInvalidationCounter.increment()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user