From 1b865d8c5f025aa18e605c4b8435a90147054f18 Mon Sep 17 00:00:00 2001 From: YuRaNnNzZZ Date: Mon, 10 Feb 2025 18:06:20 +0300 Subject: [PATCH 1/6] =?UTF-8?q?=D1=81=D0=B2=D0=B5=D1=82=D0=BB=D0=BE-=D1=81?= =?UTF-8?q?=D0=B5=D1=80=D1=8B=D0=BC=20=D0=BC=D0=B0=D0=BD=D0=B3=D0=B0=D0=BB?= =?UTF-8?q?-=D0=B4=D0=B8=D0=BF=D0=BB=D0=BE=D0=BC=D0=B0=D1=82=20=D0=9E?= =?UTF-8?q?=D0=BA=D1=80=D0=B0=D1=88=D0=B5=D0=BD=D0=BE=20=D0=B2=20=D1=81?= =?UTF-8?q?=D0=B2=D0=B5=D1=82=D0=BB=D0=BE-=D1=81=D0=B5=D1=80=D1=8B=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/Russian.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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, "Тритановая нажимная пластина") From a2c9234501e9e3eae3b1d3050d16e26bcff96922 Mon Sep 17 00:00:00 2001 From: YuRaNnNzZZ Date: Mon, 10 Feb 2025 18:38:28 +0300 Subject: [PATCH 2/6] =?UTF-8?q?=D0=B4=D0=B0=D0=B2=D0=B0=D0=B9=D1=82=D0=B5?= =?UTF-8?q?=20=D0=B8=D1=81=D1=85=D0=BE=D0=B4=D0=B8=D1=82=D1=8C=20=D0=B8?= =?UTF-8?q?=D0=B7=20=D1=82=D0=BE=D0=B3=D0=BE,=20=D1=87=D1=82=D0=BE=20?= =?UTF-8?q?=D0=B6=D0=B5=D0=BB=D0=B5=D0=B7=D0=BD=D1=8B=D1=85=20=D0=BF=D0=B0?= =?UTF-8?q?=D0=BB=D0=BE=D0=BA=20=D1=83=20=D0=BD=D0=B0=D1=81=20=D0=B2=20?= =?UTF-8?q?=D0=BC=D0=BE=D0=B4=D0=B5=20=D0=BD=D0=B5=D1=82,=20=D1=82=D0=B0?= =?UTF-8?q?=D0=BA=20=D1=87=D1=82=D0=BE=20=D0=B8=20=D1=80=D0=B5=D1=86=D0=B5?= =?UTF-8?q?=D0=BF=D1=82=D1=8B=20=D0=BF=D0=BE=D0=BA=D0=B0=D0=B7=D1=8B=D0=B2?= =?UTF-8?q?=D0=B0=D1=82=D1=8C=20=D0=9D=D0=95=20=D0=9D=D0=A3=D0=96=D0=9D?= =?UTF-8?q?=D0=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mc/otm/datagen/recipes/CraftingTableRecipes.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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) From bb9d5d9ae04466c43185ef5ee3922698853be28d Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Tue, 11 Feb 2025 00:09:18 +0700 Subject: [PATCH 3/6] Throttle cable path searches --- .../mc/otm/block/entity/cable/EnergyCableGraph.kt | 15 +++++++++++++-- .../ru/dbotthepony/mc/otm/config/CablesConfig.kt | 6 ++++++ 2 files changed, 19 insertions(+), 2 deletions(-) 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..5f2de56ea 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,7 @@ 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.math.Decimal import ru.dbotthepony.mc.otm.core.math.RelativeSide import ru.dbotthepony.mc.otm.core.shuffle @@ -446,16 +447,26 @@ 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) { + val maxSearches = CablesConfig.SEARCHES_PER_TICK + + if (!list.saturated && lastTickSearches <= maxSearches) { var maxThroughput = list.paths.maxOfOrNull { it.availableThroughput } ?: Decimal.ZERO - while (maxThroughput < energyToTransfer && !list.saturated) { + while (maxThroughput < energyToTransfer && !list.saturated && ++lastTickSearches <= maxSearches) { val find = findPath(a, b, list.paths, maxThroughput) if (find == null || find in list.paths) { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/config/CablesConfig.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/config/CablesConfig.kt index 7d801f062..40559732d 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/config/CablesConfig.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/config/CablesConfig.kt @@ -27,4 +27,10 @@ object CablesConfig : AbstractConfig("cables") { init { E.SUPERCONDUCTOR } + + val SEARCHES_PER_TICK: Int by builder + .comment("How many paths are allowed to be searched for during single tick *per* cable network") + .comment("Too low value will make huge cable networks woozy when their cabling changes (e.g. cable added or removed, or valve switched)") + .comment("Too high value will create lag spikes depending on complexity of cable network at hand when cabling changes") + .defineInRange("SEARCHER_PER_TICK", 40, 1) } From 614ba26da6e478fc4d158a077f652ffdc103fb69 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Tue, 11 Feb 2025 00:17:04 +0700 Subject: [PATCH 4/6] Improve extra path search performance --- .../mc/otm/block/entity/cable/EnergyCableGraph.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 5f2de56ea..81525d3db 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 @@ -9,6 +9,7 @@ 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.math.Decimal import ru.dbotthepony.mc.otm.core.math.RelativeSide import ru.dbotthepony.mc.otm.core.shuffle @@ -69,6 +70,7 @@ class EnergyCableGraph : GraphNodeList() + val nodes = HashSet() var shortCircuit = false private var lastTickTransfers = 0 private var lastTick = 0 @@ -81,7 +83,7 @@ class EnergyCableGraph : GraphNodeList Date: Tue, 11 Feb 2025 01:12:58 +0700 Subject: [PATCH 5/6] Improve performance on cable addition and removal from cable network --- .../entity/cable/EnergyCableBlockEntity.kt | 5 -- .../block/entity/cable/EnergyCableGraph.kt | 46 +++++++++++++++---- 2 files changed, 36 insertions(+), 15 deletions(-) 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 81525d3db..2e5dbd9c0 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 @@ -68,7 +68,7 @@ class EnergyCableGraph : GraphNodeList() val nodes = HashSet() var shortCircuit = false @@ -136,7 +136,7 @@ class EnergyCableGraph : GraphNodeList() - private var paths = ReferenceLinkedOpenHashSet() + var paths = ReferenceLinkedOpenHashSet() operator fun contains(node: EnergyCableBlockEntity.Node): Boolean { return node in nodes @@ -338,6 +338,26 @@ 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) @@ -385,11 +405,6 @@ class EnergyCableGraph : GraphNodeList, threshold: Decimal): SegmentPath? { val seenTop = existing.any { a in it } @@ -435,7 +450,7 @@ class EnergyCableGraph : GraphNodeList Date: Tue, 11 Feb 2025 01:17:34 +0700 Subject: [PATCH 6/6] There is no need for "greedy" strategy when searching for extra cable paths --- .../mc/otm/block/entity/cable/EnergyCableGraph.kt | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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 2e5dbd9c0..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 @@ -10,6 +10,9 @@ 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 @@ -168,6 +171,11 @@ class EnergyCableGraph : GraphNodeList