SimpleCache helper function
This commit is contained in:
parent
67fc8f99f6
commit
fbd34f3414
@ -33,6 +33,7 @@ import ru.dbotthepony.mc.otm.container.IEnhancedCraftingContainer
|
||||
import ru.dbotthepony.mc.otm.container.slotted.AutomationFilters
|
||||
import ru.dbotthepony.mc.otm.container.slotted.FilteredContainerSlot
|
||||
import ru.dbotthepony.mc.otm.container.slotted.SlottedContainer
|
||||
import ru.dbotthepony.mc.otm.core.SimpleCache
|
||||
import ru.dbotthepony.mc.otm.core.collect.filter
|
||||
import ru.dbotthepony.mc.otm.core.collect.forEach
|
||||
import ru.dbotthepony.mc.otm.core.collect.map
|
||||
@ -95,12 +96,7 @@ class MatterEntanglerBlockEntity(blockPos: BlockPos, blockState: BlockState) : M
|
||||
}
|
||||
|
||||
private inner class InputSlot(container: SlottedContainer, slot: Int) : FilteredContainerSlot(container, slot) {
|
||||
val insertCache: Cache<ItemStackKey, Boolean> = Caffeine.newBuilder()
|
||||
.maximumSize(1024L)
|
||||
.expireAfterWrite(Duration.ofMinutes(1L))
|
||||
.scheduler(Scheduler.systemScheduler())
|
||||
.executor(Util.backgroundExecutor())
|
||||
.build()
|
||||
val insertCache = SimpleCache<ItemStackKey, Boolean>(1024L, Duration.ofMinutes(1))
|
||||
|
||||
override fun canAutomationPlaceItem(itemStack: ItemStack): Boolean {
|
||||
if (!super.canAutomationPlaceItem(itemStack))
|
||||
|
@ -3,6 +3,9 @@
|
||||
|
||||
package ru.dbotthepony.mc.otm.core
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Cache
|
||||
import com.github.benmanes.caffeine.cache.Caffeine
|
||||
import com.github.benmanes.caffeine.cache.Scheduler
|
||||
import com.google.common.collect.ImmutableList
|
||||
import com.google.common.collect.ImmutableMap
|
||||
import com.google.common.collect.ImmutableMultimap
|
||||
@ -59,6 +62,7 @@ import java.io.InputStream
|
||||
import java.io.OutputStream
|
||||
import java.lang.ref.Reference
|
||||
import java.math.BigInteger
|
||||
import java.time.Duration
|
||||
import java.util.*
|
||||
import java.util.concurrent.Callable
|
||||
import java.util.concurrent.Future
|
||||
@ -655,3 +659,12 @@ fun RandomSource.nextNormalDoubles(stddev: Double, mean: Double): DoublePair {
|
||||
fun RandomSource.nextNormalDouble(stddev: Double, mean: Double): Double {
|
||||
return nextGaussian() * stddev + mean
|
||||
}
|
||||
|
||||
fun <K : Any, V> SimpleCache(size: Long, freshness: Duration): Cache<K, V> {
|
||||
return Caffeine.newBuilder()
|
||||
.maximumSize(size)
|
||||
.scheduler(Scheduler.systemScheduler())
|
||||
.executor(Util.backgroundExecutor())
|
||||
.expireAfterWrite(freshness)
|
||||
.build()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user