Skip to content

Commit

Permalink
hopefully fix some capability cache invalidation issues
Browse files Browse the repository at this point in the history
also fixed pressure tube neighbor rediscovery after a neighbor is rotated
  • Loading branch information
desht committed May 1, 2024
1 parent c5f9c37 commit 78d42e9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ private void handleSecurityUpgrade(IAirHandlerMachine handler) {
public void onBlockRotated() {
super.onBlockRotated();

// force a recalculation of where any possible leak might be coming from
initializeHullAirHandlers();

airHandlerMap.keySet().forEach(h -> h.setSideLeaking(null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public class PressureTubeBlockEntity extends AbstractAirHandlingBlockEntity impl
private final List<Direction> neighbourDirections = new ArrayList<>();
private VoxelShape cachedTubeShape = null; // important for performance
private int pendingCacheShapeClear = 0;
private boolean needDiscover = false;

public PressureTubeBlockEntity(BlockPos pos, BlockState state) {
this(ModBlockEntityTypes.PRESSURE_TUBE.get(), pos, state, PressureTier.TIER_ONE, PneumaticValues.VOLUME_PRESSURE_TUBE);
Expand Down Expand Up @@ -199,6 +200,11 @@ public void tickClient() {
public void tickServer() {
super.tickServer();

if (needDiscover) {
discoverConnectedNeighbors();
needDiscover = false;
}

boolean couldLeak = true;

for (Direction dir : DirectionUtil.VALUES) {
Expand Down Expand Up @@ -320,7 +326,10 @@ public void onNeighborBlockUpdate(BlockPos fromPos) {

tubeModules().forEach(AbstractTubeModule::onNeighborBlockUpdate);

discoverConnectedNeighbors();
// connected neighbour discovery needs to be deferred,
// since although the neighbouring block has updated,
// the block entity's air handler data may not yet have updated
needDiscover = true;
}

private void discoverConnectedNeighbors() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,6 @@ public void disableSafetyVenting() {
public void setConnectableFaces(Collection<Direction> sides) {
connectableFaces.clear();
sides.forEach(side -> connectableFaces.set(side.get3DDataValue()));

// invalidate cached neighbour data
for (Direction dir : DirectionUtil.VALUES) {
this.neighbourAirHandlers.put(dir, null);
}
}

@Override
Expand Down Expand Up @@ -248,9 +243,7 @@ private Optional<IAirHandlerMachine> getNeighbourAirHandler(BlockEntity ownerTE,
neighbourAirHandlers.put(dir, BlockCapabilityCache.create(PNCCapabilities.AIR_HANDLER_MACHINE,
level,
ownerTE.getBlockPos().relative(dir),
dir.getOpposite(),
() -> !ownerTE.isRemoved(),
() -> neighbourAirHandlers.put(dir, null)
dir.getOpposite()
));
}
return Optional.ofNullable(neighbourAirHandlers.get(dir).getCapability());
Expand Down

0 comments on commit 78d42e9

Please sign in to comment.