Make complexity be much more like complexity

Fixes #2
This commit is contained in:
DBotThePony 2022-09-09 19:27:47 +07:00
parent 9cc36c3e40
commit 51b2b88128
Signed by: DBot
GPG Key ID: DCC23B5715498507
2 changed files with 33 additions and 7 deletions

View File

@ -33,6 +33,7 @@ import ru.dbotthepony.mc.otm.matter.*
import ru.dbotthepony.mc.otm.menu.MatterScannerMenu
import ru.dbotthepony.mc.otm.registry.MBlockEntities
import java.util.*
import kotlin.math.pow
class MatterScannerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
MatteryWorkerBlockEntity<MatteryWorkerBlockEntity.ItemJob>(MBlockEntities.MATTER_SCANNER, p_155229_, p_155230_, ::ItemJob), IMatterGraphNode, IDroppableContainer {
@ -134,16 +135,18 @@ class MatterScannerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
for (state in grid.patterns.filter { it.item === stack.item }) {
if (findState == null && state.researchPercent < 1.0) {
findState = state
} else if (findState != null && findState.researchPercent < state.researchPercent) {
} else if (findState != null && findState.researchPercent < state.researchPercent && state.researchPercent < 1.0) {
findState = state
}
}
val new =
val researchAdvance = getResearchAdvance(stack.item)
val new: IPatternState =
if (findState != null) {
PatternState(findState.id, stack.item, findState.researchPercent + 0.2)
PatternState(findState.id, stack.item, (findState.researchPercent + researchAdvance).coerceAtMost(1.0))
} else {
PatternState(UUID.randomUUID(), stack.item, 0.2)
PatternState(UUID.randomUUID(), stack.item, researchAdvance)
}
if (!grid.insertPattern(new, onlyUpdate = false, simulate = false).isFailed) {
@ -170,21 +173,26 @@ class MatterScannerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
findState = state
} else if (state.researchPercent >= 1.0) {
return null to IdleReason.ITEM
} else if (findState != null && findState.researchPercent < state.researchPercent) {
findState = state
}
}
val researchAdvance = getResearchAdvance(stack.item)
val new: IPatternState =
if (findState != null) {
PatternState(findState.id, stack.item, findState.researchPercent + 0.2)
PatternState(findState.id, stack.item, (findState.researchPercent + researchAdvance).coerceAtMost(1.0))
} else {
PatternState(UUID.randomUUID(), stack.item, 0.2)
PatternState(UUID.randomUUID(), stack.item, researchAdvance)
}
if (!grid.insertPattern(new, onlyUpdate = false, simulate = true).isFailed) {
val copy = stack.copy().also { it.count = 1 }
stack.shrink(1)
container.setChanged()
return ItemJob(copy, getMatterValue(copy).complexity * baselineComplexityScanTicks, BASE_CONSUMPTION) to null
val complexity = getMatterValue(copy).complexity
return ItemJob(copy, (if (complexity > 1.0) complexity.pow(2.0) else complexity.pow(0.5)) * baselineComplexityScanTicks, BASE_CONSUMPTION) to null
}
return null to IdleReason.ITEM

View File

@ -7,6 +7,7 @@ import net.minecraft.network.FriendlyByteBuf
import net.minecraft.server.level.ServerPlayer
import net.minecraft.world.item.Item
import net.minecraft.world.item.ItemStack
import net.minecraft.world.level.ItemLike
import net.minecraftforge.event.entity.player.ItemTooltipEvent
import net.minecraftforge.event.entity.player.PlayerEvent
import net.minecraftforge.network.NetworkEvent
@ -21,6 +22,7 @@ import ru.dbotthepony.mc.otm.network.RegistryNetworkChannel
import ru.dbotthepony.mc.otm.storage.ItemStackWrapper
import java.math.BigInteger
import java.util.function.Supplier
import kotlin.math.pow
internal var building = false
@ -212,6 +214,22 @@ fun getMatterValue(stack: ItemStack): MatterTuple {
return getMatterValue(stack, 0)
}
fun getResearchAdvance(complexity: Double): Double {
if (complexity <= 0.0) {
return 0.0
}
return (1.0 / (complexity.pow(1.0 / 3.0) * 12.0).coerceAtLeast(0.01)).coerceAtMost(0.2).coerceAtLeast(0.025)
}
fun getResearchAdvance(stack: ItemStack): Double {
return getResearchAdvance(getMatterValue(stack).complexity)
}
fun getResearchAdvance(stack: ItemLike): Double {
return getResearchAdvance(getMatterValue(stack.asItem()).complexity)
}
fun onPlayerJoin(event: PlayerEvent.PlayerLoggedInEvent) {
if (NULLABLE_MINECRAFT_SERVER != null) {
RegistryNetworkChannel.send(PacketDistributor.PLAYER.with { event.entity as ServerPlayer }, RegistryPacketFullUpdate(MatterRegistryType.ROOT, rootEntries))