Skip to content

Commit

Permalink
Prevent AE cable removal when replace impossible
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
RecursivePineapple committed Jan 23, 2025
1 parent 1ec041b commit 5ed22c2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -157,19 +158,40 @@ 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();

// if the p2p is attunable (non-interface) then we don't need to remove it
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; }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 5ed22c2

Please sign in to comment.