Skip to content

Commit

Permalink
Fix CraftingCPUCalculator allowing non-CraftingBlockEntities inside t…
Browse files Browse the repository at this point in the history
…he multiblock (#8372)

This pull request fixes a crash that happens when users try to mix AE2
cpus with `IAEMultiBlock`s that aren't `CraftingBlockEntity`s, as
reported [here](pedroksl/AdvancedAE#108).

Testing for an instance of `CraftingBlockEntity` shouldn't be more
restrictive than the current implementation since the
`updateBlockEntities` method will force cast to that class, anyway.

---------

Co-authored-by: Sebastian Hartte <[email protected]>
  • Loading branch information
pedroksl and shartte authored Feb 14, 2025
1 parent 7cef8fc commit 3ed65e9
Showing 1 changed file with 2 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import appeng.api.networking.IGrid;
import appeng.api.networking.events.GridCraftingCpuChange;
import appeng.blockentity.crafting.CraftingBlockEntity;
import appeng.me.cluster.IAEMultiBlock;
import appeng.me.cluster.MBCalculator;

public class CraftingCPUCalculator extends MBCalculator<CraftingBlockEntity, CraftingCPUCluster> {
Expand Down Expand Up @@ -63,15 +62,11 @@ public boolean verifyInternalStructure(ServerLevel level, BlockPos min, BlockPos
boolean storage = false;

for (BlockPos blockPos : BlockPos.betweenClosed(min, max)) {
final IAEMultiBlock<?> te = (IAEMultiBlock<?>) level.getBlockEntity(blockPos);

if (te == null || !te.isValid()) {
if (!(level.getBlockEntity(blockPos) instanceof CraftingBlockEntity craftingBlockEntity)) {
return false;
}

if (!storage && te instanceof CraftingBlockEntity) {
storage = ((CraftingBlockEntity) te).getStorageBytes() > 0;
}
storage |= craftingBlockEntity.getStorageBytes() > 0;
}

return storage;
Expand Down

0 comments on commit 3ed65e9

Please sign in to comment.