Skip to content

Commit

Permalink
Improved exchanging (#30)
Browse files Browse the repository at this point in the history
Exchanging will now keep all possible settings from prior blocks
(including rotation for energy hatches). You can also replace air now.

(cherry picked from commit 1ec041b)
  • Loading branch information
RecursivePineapple committed Jan 29, 2025
1 parent 8ec66af commit e0cb77a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -364,58 +364,55 @@ private List<PendingBlock> getExchangeBlocks(ManipulatorTier tier, World world)
XSTR rng = new XSTR(config.hashCode());

BlockSpec existing = new BlockSpec();
BlockSpec aeCable = new BlockSpec();

boolean replacingAir = config.replaceWhitelist.contains(BlockSpec.air());

for (Vector3i voxel : MMUtils.getBlocksInBB(coordA, deltas)) {
int x = voxel.x;
int y = voxel.y;
int z = voxel.z;

if (world.isAirBlock(x, y, z)) continue;

BlockSpec.fromBlock(existing, world, x, y, z);
if (!replacingAir) {
if (world.isAirBlock(x, y, z)) continue;
}

if (existing.isAir()) continue;
if (existing == null) existing = new BlockSpec();

boolean wasAECable = false;
BlockSpec.fromBlock(existing, world, x, y, z);

if (MMUtils.getAECable(aeCable, world, x, y, z)) {
if (!config.replaceWhitelist.contains(aeCable)) continue;
if (existing.shouldBeSkipped()) continue;

wasAECable = true;
if (!replacingAir) {
if (existing.isAir()) continue;
}

if (!wasAECable) {
if (!config.replaceWhitelist.contains(existing)) continue;
if (AppliedEnergistics2.isModLoaded()) {
// get ae cable if possible
MMUtils.getAECable(existing, world, x, y, z);
}

ImmutableBlockSpec replacement = config.replaceWith.get(rng);

boolean replacingWithGTCable = tier.hasCap(ItemMatterManipulator.ALLOW_CABLES) && GregTech.isModLoaded() && MMUtils.isGTCable(replacement);
boolean replacingWithAECable = tier.hasCap(ItemMatterManipulator.ALLOW_CABLES) && AppliedEnergistics2.isModLoaded() &&
MMUtils.isAECable(replacement);
if (!config.replaceWhitelist.contains(existing)) continue;

if (replacingWithGTCable) {
PendingBlock rep = replacement.instantiate(world, x, y, z);
ImmutableBlockSpec replacement = config.replaceWith.get(rng);
ImmutableBlockSpec block = replacement;

if (MMUtils.isGTCable(existing)) {
rep.analyze(world.getTileEntity(x, y, z), PendingBlock.ANALYZE_ALL);
if (tier.hasCap(ItemMatterManipulator.ALLOW_CABLES)) {
if (AppliedEnergistics2.isModLoaded() && MMUtils.isAECable(replacement)) {
block = MMUtils.AE_BLOCK_CABLE.get().asSpec();
}
}

pending.add(rep);
} else if (replacingWithAECable) {
PendingBlock rep = MMUtils.AE_BLOCK_CABLE.get().asSpec().instantiate(world, x, y, z);
PendingBlock rep = block.instantiate(world, x, y, z);

if (world.getTileEntity(x, y, z) instanceof IPartHost) {
rep.analyze(world.getTileEntity(x, y, z), PendingBlock.ANALYZE_ALL);
}
rep.analyze(world.getTileEntity(x, y, z), PendingBlock.ANALYZE_ALL);

placingAECable(rep, replacement);

pending.add(rep);
} else {
pending.add(replacement.instantiate(world, x, y, z));
if (tier.hasCap(ItemMatterManipulator.ALLOW_CABLES)) {
if (AppliedEnergistics2.isModLoaded() && MMUtils.isAECable(replacement)) {
placingAECable(rep, replacement);
}
}

pending.add(rep);
}

return pending;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1319,6 +1319,15 @@ public static Block getBlockFromItem(Item item, int metadata) {
return block;
}

@Optional(Names.GREG_TECH)
public static boolean isGTMachine(ImmutableBlockSpec spec) {
if (spec.getBlock() instanceof BlockMachines) {
if (getIndexSafe(GregTechAPI.METATILEENTITIES, spec.getMeta()) != null) { return true; }
}

return false;
}

@Optional(Names.GREG_TECH)
public static boolean isGTCable(ImmutableBlockSpec spec) {
if (spec.getBlock() instanceof BlockMachines) {
Expand Down

0 comments on commit e0cb77a

Please sign in to comment.