Skip to content

Commit

Permalink
Prevent AE cable removal when replace impossible (#31)
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.

(cherry picked from commit 7e98a77)
  • Loading branch information
RecursivePineapple committed Jan 29, 2025
1 parent e0cb77a commit 396239b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 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 Expand Up @@ -1539,13 +1539,11 @@ public ModularWindow createTransformWindow(UIBuildContext buildContext, ItemStac
if (t.flipY) flips.add("Y");
if (t.flipZ) flips.add("Z");

String[] names = { "Down", "Up", "North", "South", "West", "East" };

return String.format(
"Flip: %s\nUp: %s\nForward: %s",
flips.isEmpty() ? "None" : String.join(", ", flips),
names[t.up.ordinal()],
names[t.forward.ordinal()]);
MMUtils.getDirectionDisplayName(t.up),
MMUtils.getDirectionDisplayName(t.forward));
});

Widget[] left = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1375,4 +1375,20 @@ public static boolean getGTCable(BlockSpec spec, World world, int x, int y, int

return false;
}

public static String getDirectionDisplayName(ForgeDirection dir) {
return getDirectionDisplayName(dir, false);
}

public static String getDirectionDisplayName(ForgeDirection dir, boolean unknownIsCentre) {
return switch (dir) {
case DOWN -> "Down";
case EAST -> "East";
case NORTH -> "North";
case SOUTH -> "South";
case UNKNOWN -> unknownIsCentre ? "Center" : "Unknown";
case UP -> "Up";
case WEST -> "West";
};
}
}

0 comments on commit 396239b

Please sign in to comment.