diff --git a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/Russian.kt b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/Russian.kt index efd485f3d..d024f6ff0 100644 --- a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/Russian.kt +++ b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/Russian.kt @@ -58,7 +58,7 @@ private fun decoratives(provider: MatteryLanguageProvider) { add(MBlocks.TRITANIUM_TRAPDOOR[color]!!, "description1", FEELING_SAFE_NOW) add(MBlocks.TRITANIUM_TRAPDOOR[color]!!, "description2", "Данный вариант выкрашен в $name") - add(MBlocks.GRILL[color]!!, "$nameAdj мангал-дипломат") + add(MBlocks.GRILL[color]!!, "$name мангал-дипломат") } add(MRegistry.TRITANIUM_PRESSURE_PLATE.block, "Тритановая нажимная пластина") diff --git a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/recipes/CraftingTableRecipes.kt b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/recipes/CraftingTableRecipes.kt index fffb48458..5ba4a2ce6 100644 --- a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/recipes/CraftingTableRecipes.kt +++ b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/recipes/CraftingTableRecipes.kt @@ -9,6 +9,8 @@ import net.minecraft.world.item.ItemStack import net.minecraft.world.item.Items import net.minecraft.world.item.crafting.Ingredient import net.neoforged.neoforge.common.Tags +import net.neoforged.neoforge.common.conditions.NotCondition +import net.neoforged.neoforge.common.conditions.TagEmptyCondition import ru.dbotthepony.mc.otm.block.entity.MatteryBlockEntity import ru.dbotthepony.mc.otm.config.CablesConfig import ru.dbotthepony.mc.otm.core.ResourceLocation @@ -530,6 +532,7 @@ fun addCraftingTableRecipes(consumer: RecipeOutput) { .build(consumer) val ironRod = ItemTags.create(ResourceLocation("c", "rods/iron")) + var condConsumer = consumer.withConditions(NotCondition(TagEmptyCondition(ironRod))) for ((color, item) in MItems.GRILL) { MatteryRecipe(item, category = RecipeCategory.DECORATIONS) @@ -542,13 +545,13 @@ fun addCraftingTableRecipes(consumer: RecipeOutput) { .rowB(color?.tag) .row(ironRod, ironRod, ironRod) .rowAC(MItemTags.TRITANIUM_INGOTS, MItemTags.TRITANIUM_INGOTS) - .build(consumer, "grill_alt_a/${color?.name?.lowercase() ?: "default"}") + .build(condConsumer, "grill_alt_a/${color?.name?.lowercase() ?: "default"}") MatteryRecipe(item, category = RecipeCategory.DECORATIONS) .rowB(color?.tag) .row(ironRod, ironRod, ironRod) .rowB(MItemTags.TRITANIUM_PLATES) - .build(consumer, "grill_alt_b/${color?.name?.lowercase() ?: "default"}") + .build(condConsumer, "grill_alt_b/${color?.name?.lowercase() ?: "default"}") MatteryRecipe(item, category = RecipeCategory.DECORATIONS) .rowB(color?.tag) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/cable/EnergyCableBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/cable/EnergyCableBlockEntity.kt index 61741903d..829192b37 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/cable/EnergyCableBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/cable/EnergyCableBlockEntity.kt @@ -111,11 +111,6 @@ abstract class EnergyCableBlockEntity(type: BlockEntityType<*>, blockPos: BlockP _segment = value } - fun onInvalidate() { - _segment = EnergyCableGraph.Segment(this) - updatePoweredState(false) - } - val sides get() = energySides override fun onNeighbour(link: Link) { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/cable/EnergyCableGraph.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/cable/EnergyCableGraph.kt index a5fde294b..c00d7d159 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/cable/EnergyCableGraph.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/cable/EnergyCableGraph.kt @@ -8,6 +8,11 @@ import org.apache.logging.log4j.LogManager import ru.dbotthepony.mc.otm.SERVER_IS_LIVE import ru.dbotthepony.mc.otm.UNIVERSE_TICKS import ru.dbotthepony.mc.otm.capability.receiveEnergy +import ru.dbotthepony.mc.otm.config.CablesConfig +import ru.dbotthepony.mc.otm.core.addAll +import ru.dbotthepony.mc.otm.core.collect.map +import ru.dbotthepony.mc.otm.core.collect.max +import ru.dbotthepony.mc.otm.core.collect.reduce import ru.dbotthepony.mc.otm.core.math.Decimal import ru.dbotthepony.mc.otm.core.math.RelativeSide import ru.dbotthepony.mc.otm.core.shuffle @@ -66,8 +71,9 @@ class EnergyCableGraph : GraphNodeList() + val nodes = HashSet() var shortCircuit = false private var lastTickTransfers = 0 private var lastTick = 0 @@ -80,7 +86,7 @@ class EnergyCableGraph : GraphNodeList() - private var paths = ReferenceLinkedOpenHashSet() + var paths = ReferenceLinkedOpenHashSet() operator fun contains(node: EnergyCableBlockEntity.Node): Boolean { return node in nodes @@ -165,6 +171,11 @@ class EnergyCableGraph : GraphNodeList { + val result = ArrayList() + result.add(this) + + for (v in nodes) { + val segment = Segment() + v._segment = segment + segment.nodes.add(v) + segment.throughput = v.energyThroughput + segment.throughputKnown = true + segment.transferredLastTick = transferredLastTick + result.add(segment) + v.updatePoweredState(false) + } + + // mark this segment as dead + this.nodes.clear() + return result + } + private fun combineInto(segment: Segment) { nodes.forEach { it._segment = segment } segment.nodes.addAll(nodes) @@ -378,11 +413,6 @@ class EnergyCableGraph : GraphNodeList, threshold: Decimal): SegmentPath? { val seenTop = existing.any { a in it } @@ -428,7 +458,7 @@ class EnergyCableGraph : GraphNodeList { if (!a.canTraverse || !b.canTraverse) return listOf() + if (searchedOnTick != UNIVERSE_TICKS) { + searchedOnTick = UNIVERSE_TICKS + lastTickSearches = 0 + } + val list = pathCache.computeIfAbsent(a to b) { CacheEntry() } - if (!list.saturated) { - var maxThroughput = list.paths.maxOfOrNull { it.availableThroughput } ?: Decimal.ZERO + val maxSearches = CablesConfig.SEARCHES_PER_TICK - while (maxThroughput < energyToTransfer && !list.saturated) { + if (!list.saturated && lastTickSearches <= maxSearches) { + var maxThroughput = list.paths.iterator().map { it.availableThroughput }.reduce(Decimal.ZERO, Decimal::plus) + + while (maxThroughput < energyToTransfer && !list.saturated && ++lastTickSearches <= maxSearches) { + // TODO: Heuristics here is wrong val find = findPath(a, b, list.paths, maxThroughput) if (find == null || find in list.paths) { list.saturated = true } else { list.paths.add(find) - maxThroughput = maxOf(maxThroughput, find.availableThroughput) + maxThroughput += find.availableThroughput } } } @@ -473,18 +514,29 @@ class EnergyCableGraph : GraphNodeList