Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 🐛 Fixed hopper upgrade occasionally freezing game due to it unne… #481

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ org.gradle.daemon=false

mod_id=sophisticatedstorage
mod_group_id=sophisticatedstorage
mod_version=0.10.35
mod_version=0.10.36
sonar_project_key=sophisticatedstorage:SophisticatedStorage
github_package_url=https://maven.pkg.github.com/P3pp3rF1y/SophisticatedStorage

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,27 @@ private boolean moveItems(IItemHandler fromHandler, IItemHandler toHandler, Filt

@Override
public void onNeighborChange(Level level, BlockPos pos, Direction direction) {
if (pushDirections.contains(direction) || pullDirections.contains(direction)) {
if (!level.isClientSide() && (pushDirections.contains(direction) || pullDirections.contains(direction))
&& needsCacheUpdate(level, pos, direction)) {
updateCacheOnSide(level, pos, direction);
}
}

private boolean needsCacheUpdate(Level level, BlockPos pos, Direction direction) {
List<LazyOptional<IItemHandler>> handlers = handlerCache.get(direction);
if (handlers == null || handlers.isEmpty()) {
return !level.getBlockState(pos).isAir();
}

for (LazyOptional<IItemHandler> handler : handlers) {
if (!handler.isPresent()) {
return true;
}
}

return false;
}

public void updateCacheOnSide(Level level, BlockPos pos, Direction direction) {
if (!level.isLoaded(pos) || !level.isLoaded(pos.relative(direction))) {
handlerCache.remove(direction);
Expand Down