Skip to content

Commit f65eeaf

Browse files
committed
fix: patch for 73, not completely fixed
1 parent f342a19 commit f65eeaf

4 files changed

Lines changed: 23 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
# Release 3.0.0
1+
# Release 3.0.1
22

3-
- General bug fixes
4-
- Modern version support and 1.20.1 backport
5-
- Upgradeable belt slots
6-
7-
1.21.11 support will be added when Accessories is updated.
3+
- Patch fix for crash detailed in #73 (until further information about the root cause is available).

common/src/main/java/io/github/jamalam360/utility_belt/state/ServerStateManager.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,20 @@ public void setInBelt(Player player, boolean inBelt) {
3131

3232
@Override
3333
public int getSelectedBeltSlot(Player player) {
34-
return getState(player).selectedBeltSlot;
34+
if (!isInBelt(player)) {
35+
return -1;
36+
}
37+
38+
int slot = getState(player).selectedBeltSlot;
39+
int beltSize = getInventory(player).getContainerSize();
40+
41+
if (slot < 0 || slot >= beltSize) {
42+
slot = 0;
43+
getState(player).selectedBeltSlot = 0;
44+
UtilityBelt.LOGGER.warn("Broken state detected for player {}: selected belt slot {} is out of bounds for belt size {}. Resetting to 0.", player.getName().getString(), slot, beltSize);
45+
}
46+
47+
return slot;
3548
}
3649

3750
@Override

common/src/main/java/io/github/jamalam360/utility_belt/util/UtilityBeltInventory.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.github.jamalam360.utility_belt.util;
22

3+
import io.github.jamalam360.utility_belt.UtilityBelt;
34
import net.minecraft.core.NonNullList;
45
import net.minecraft.nbt.CompoundTag;
56
import net.minecraft.world.Container;
@@ -27,6 +28,11 @@ public UtilityBeltInventory copyWithSize(int newSize) {
2728
}
2829

2930
public ItemStack getItem(int index) {
31+
if (index < 0 || index >= this.getContainerSize()) {
32+
UtilityBelt.LOGGER.warn("Attempted to access index {} of UtilityBeltInventory of size {}", index, this.getContainerSize());
33+
return ItemStack.EMPTY;
34+
}
35+
3036
return items.get(index);
3137
}
3238

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ org.gradle.daemon=false
33
org.gradle.parallel=true
44
loom.ignoreDependencyLoomVersionValidation=true
55

6-
version=3.0.0+1.20.1
6+
version=3.0.1+1.20.1
77
minecraft_version=1.20.1
88

99
additional_minecraft_versions=

0 commit comments

Comments
 (0)