From 5ed22c2a4781008fc26f118a626c3a7dcea75271 Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Thu, 23 Jan 2025 15:54:20 -0500 Subject: [PATCH] Prevent AE cable removal when replace impossible MM would previously remove cables even when the replacing cable wasn't available or couldn't fit (ie small -> dense w/ parts). This stops that from happening so that the old cables won't be removed, preventing the setup from getting mangled. --- .../common/building/AEAnalysisResult.java | 24 ++++++++++++++++++- .../manipulator/ItemMatterManipulator.java | 2 +- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/recursive_pineapple/matter_manipulator/common/building/AEAnalysisResult.java b/src/main/java/com/recursive_pineapple/matter_manipulator/common/building/AEAnalysisResult.java index 2380919..757d8b3 100644 --- a/src/main/java/com/recursive_pineapple/matter_manipulator/common/building/AEAnalysisResult.java +++ b/src/main/java/com/recursive_pineapple/matter_manipulator/common/building/AEAnalysisResult.java @@ -32,6 +32,7 @@ import com.google.gson.JsonElement; import com.recursive_pineapple.matter_manipulator.common.building.BlockAnalyzer.IBlockApplyContext; import com.recursive_pineapple.matter_manipulator.common.items.manipulator.Transform; +import com.recursive_pineapple.matter_manipulator.common.utils.BigItemStack; import com.recursive_pineapple.matter_manipulator.common.utils.ItemId; import com.recursive_pineapple.matter_manipulator.common.utils.MMUtils; @@ -157,7 +158,9 @@ public boolean apply(IBlockApplyContext ctx) { AEPartData expected = mAEParts[dir.ordinal()]; ItemId actualItem = part == null ? null : ItemId.createWithoutNBT(part.getItemStack(PartItemStack.Break)); - ItemId expectedItem = expected == null ? null : ItemId.createWithoutNBT(expected.getEffectivePartStack()); + + ItemStack expectedStack = expected == null ? null : expected.getEffectivePartStack(); + ItemId expectedItem = expectedStack == null ? null : ItemId.createWithoutNBT(expectedStack); boolean isAttunable = part instanceof PartP2PTunnelNormal && expected != null && expected.isAttunable(); @@ -165,11 +168,30 @@ public boolean apply(IBlockApplyContext ctx) { if (!isAttunable) { // change the part into the proper version if (actualItem != null && (expectedItem == null || !Objects.equals(actualItem, expectedItem))) { + if (expectedStack != null && !partHost.canAddPart(expectedStack, dir)) { + ctx.error("Invalid location (" + MMUtils.getDirectionDisplayName(dir, true) + ") for part (" + expectedStack.getDisplayName() + ")"); + continue; + } + + if (expectedStack != null) { + var result = ctx.tryConsumeItems(Arrays.asList(new BigItemStack(expectedStack)), IPseudoInventory.CONSUME_SIMULATED); + + if (!result.leftBoolean()) { + ctx.error("Could not extract item: " + expectedStack.getDisplayName()); + continue; + } + } + removePart(ctx, partHost, dir, false); actualItem = null; } if (actualItem == null && expectedItem != null) { + if (expectedStack != null && !partHost.canAddPart(expectedStack, dir)) { + ctx.error("Invalid location (" + MMUtils.getDirectionDisplayName(dir, true) + ") for part (" + expectedStack.getDisplayName() + ")"); + continue; + } + if (!installPart(ctx, partHost, dir, expected, false)) { return false; } } } diff --git a/src/main/java/com/recursive_pineapple/matter_manipulator/common/items/manipulator/ItemMatterManipulator.java b/src/main/java/com/recursive_pineapple/matter_manipulator/common/items/manipulator/ItemMatterManipulator.java index 7f39f0a..0137ff6 100644 --- a/src/main/java/com/recursive_pineapple/matter_manipulator/common/items/manipulator/ItemMatterManipulator.java +++ b/src/main/java/com/recursive_pineapple/matter_manipulator/common/items/manipulator/ItemMatterManipulator.java @@ -938,7 +938,7 @@ private void onPickCable(World world, EntityPlayer player, ItemStack stack, MMSt private void checkForAECables(BlockSpec spec, World world, int x, int y, int z) { if (tier.hasCap(ALLOW_CABLES) && AppliedEnergistics2.isModLoaded()) { - if (spec.getItem() == MMUtils.AE_BLOCK_CABLE.get().getItem()) { + if (MMUtils.AE_BLOCK_CABLE.matches(spec)) { MMUtils.getAECable(spec, world, x, y, z); } }