From bd34ad8d3be79c78adc5a1ad49c3d66576fc2ae3 Mon Sep 17 00:00:00 2001 From: YuRaNnNzZZ Date: Wed, 19 Jul 2023 09:28:35 +0300 Subject: [PATCH 1/2] replicator return unused matter back to network --- .../matter/MatterReplicatorBlockEntity.kt | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterReplicatorBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterReplicatorBlockEntity.kt index e82116f59..d3a879565 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterReplicatorBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterReplicatorBlockEntity.kt @@ -19,13 +19,7 @@ import ru.dbotthepony.mc.otm.capability.MatteryCapability import ru.dbotthepony.mc.otm.capability.energy.BlockEnergyStorageImpl import ru.dbotthepony.mc.otm.capability.energy.ProfiledEnergyStorage import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage -import ru.dbotthepony.mc.otm.capability.matter.IMatterStorage -import ru.dbotthepony.mc.otm.capability.matter.IPatternState -import ru.dbotthepony.mc.otm.capability.matter.IReplicationTask -import ru.dbotthepony.mc.otm.capability.matter.MatterStorageImpl -import ru.dbotthepony.mc.otm.capability.matter.PatternState -import ru.dbotthepony.mc.otm.capability.matter.ProfiledMatterStorage -import ru.dbotthepony.mc.otm.capability.matter.ReplicationTask +import ru.dbotthepony.mc.otm.capability.matter.* import ru.dbotthepony.mc.otm.config.ConciseBalanceValues import ru.dbotthepony.mc.otm.container.HandlerFilter import ru.dbotthepony.mc.otm.container.MatteryContainer @@ -37,6 +31,7 @@ import ru.dbotthepony.mc.otm.core.math.set import ru.dbotthepony.mc.otm.core.nbt.map import ru.dbotthepony.mc.otm.core.nbt.set import ru.dbotthepony.mc.otm.core.util.WriteOnce +import ru.dbotthepony.mc.otm.graph.matter.MatterGraph import ru.dbotthepony.mc.otm.graph.matter.MatterNode import ru.dbotthepony.mc.otm.matter.MatterManager import ru.dbotthepony.mc.otm.menu.matter.MatterReplicatorMenu @@ -265,6 +260,19 @@ class MatterReplicatorBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : return JobStatus.SUCCESS } + override fun tick() { + super.tick() + + if (jobEventLoops[0].currentJob == null && matter.storedMatter.isPositive) { + val graph = matterNode.graph as MatterGraph? ?: return + val received = graph.receiveMatter(matter.storedMatter, false) + + if (!received.isZero) { + matter.extractMatter(received, false) + } + } + } + companion object { private val BASE_CONSUMPTION get() = _BASE_CONSUMPTION.get() private val DRAIN_MULT get() = _DRAIN_MULT.get() From 03c12c5737b4c0299069009137f639db7e9a8dd2 Mon Sep 17 00:00:00 2001 From: YuRaNnNzZZ Date: Wed, 19 Jul 2023 11:24:52 +0300 Subject: [PATCH 2/2] do use recipe_type for crafting recipe finder for things like create mechanical crafting support --- .../ru/dbotthepony/mc/otm/matter/MatterManager.kt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/matter/MatterManager.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/matter/MatterManager.kt index 43579a4cf..f792586c8 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/matter/MatterManager.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/matter/MatterManager.kt @@ -471,10 +471,19 @@ object MatterManager { registrar.register("crafting") { Finder { server, data -> + val location = (data["recipe_type"] ?: throw JsonSyntaxException("Missing recipe type")).let { ResourceLocation.tryParse(it.asString) } ?: throw JsonSyntaxException("Invalid recipe type: ${data["recipe_type"]}") + + if (!ForgeRegistries.RECIPE_TYPES.containsKey(location)) { + LOGGER.error("Invalid or missing recipe category: $location!") + return@Finder Stream.empty() + } + + val findRecipeType = ForgeRegistries.RECIPE_TYPES.getValue(location) as RecipeType>? ?: throw ConcurrentModificationException() + val allowBacktrack = data["allow_backtrack"]?.asBoolean ?: true val ignoreDamageables = data["ignore_damageables"]?.asBoolean ?: false val isCritical = data["is_critical"]?.asBoolean ?: true - var stream = server.recipeManager.byType(RecipeType.CRAFTING).values.stream().filter { !it.isIncomplete } + var stream = server.recipeManager.byType(findRecipeType).values.stream().filter { !it.isIncomplete } if (ignoreDamageables) { stream = stream.filter { it.ingredients.stream().flatMap { it.items.stream() }.noneMatch { it.isDamageableItem } }