Skip to content

Commit

Permalink
Fix #2751 Crash when MC window becomes too narrow
Browse files Browse the repository at this point in the history
  • Loading branch information
mezz committed Mar 17, 2022
1 parent 543ad9b commit 8414218
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/main/java/mezz/jei/util/ImmutableRect2i.java
@@ -1,7 +1,6 @@
package mezz.jei.util;

import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import net.minecraft.client.renderer.Rect2i;

import javax.annotation.Nonnegative;
Expand All @@ -22,16 +21,19 @@ public ImmutableRect2i(Rect2i rect) {
this(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
}

@SuppressWarnings("ConstantConditions")
public ImmutableRect2i(@Nonnegative int x, @Nonnegative int y, @Nonnegative int width, @Nonnegative int height) {
Preconditions.checkArgument(x >= 0, "x must be greater or equal 0");
Preconditions.checkArgument(y >= 0, "y must be greater or equal 0");
Preconditions.checkArgument(width >= 0, "width must be greater or equal 0");
Preconditions.checkArgument(height >= 0, "height must be greater or equal 0");
public ImmutableRect2i(int x, int y, int width, int height) {
if (x < 0) {
width -= x;
x = 0;
}
if (y < 0) {
height -= y;
y = 0;
}
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.width = Math.max(0, width);
this.height = Math.max(0, height);
}

@Nonnegative
Expand Down

0 comments on commit 8414218

Please sign in to comment.