Skip to content

Commit 6ad7700

Browse files
committed
fix: 🐛 Fixed Sojourner's Staff to always cycle to next light source when one runs out
1 parent f5d7c92 commit 6ad7700

2 files changed

Lines changed: 18 additions & 13 deletions

File tree

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ loader_version_range=[4,)
1515
mod_id=reliquary
1616
mod_name=Reliquary Reincarnations
1717
mod_license=All Rights Reserved
18-
mod_version=2.0.73
18+
mod_version=2.0.74
1919
mod_group_id=net.p3pp3rf1y
2020
mod_authors=P3pp3rF1y
2121
mod_description=Two words: magical swag. Oh, and a gun.

src/main/java/reliquary/item/SojournerStaffItem.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,28 +74,36 @@ private void scanForMatchingTorchesToFillInternalStorage(ItemStack staff, Player
7474
}
7575

7676
public ItemStack getCurrentTorch(ItemStack stack) {
77-
return getFromHandler(stack, handler -> getCurrentTorchIndex(stack) < handler.getSlots() ? handler.getStackInSlot(getCurrentTorchIndex(stack)) : ItemStack.EMPTY);
77+
return getFromHandler(stack, handler -> handler.getStackInSlot(getCurrentTorchIndex(stack, handler.getSlots())));
7878
}
7979

8080
public int getTorchCount(ItemStack stack) {
81-
return getFromHandler(stack, handler -> getCurrentTorchIndex(stack) < handler.getSlots() ? handler.getCountInSlot(getCurrentTorchIndex(stack)) : 0);
81+
return getFromHandler(stack, handler -> handler.getCountInSlot(getCurrentTorchIndex(stack, handler.getSlots())));
8282
}
8383

8484
private void cycleTorchMode(ItemStack stack, boolean next) {
85-
ItemStack currentTorch = getCurrentTorch(stack);
86-
if (getCurrentTorchIndex(stack) != TORCH_SLOT && currentTorch.isEmpty()) {
87-
return;
88-
}
8985
runOnHandler(stack, handler -> {
9086
int slots = handler.getSlots();
9187
if (slots == 1) {
9288
return;
9389
}
94-
int currentIndex = getCurrentTorchIndex(stack);
90+
int currentIndex = getCurrentTorchIndex(stack, slots);
91+
if (currentIndex != TORCH_SLOT && handler.getStackInSlot(currentIndex).isEmpty()) {
92+
return;
93+
}
9594
stack.set(ModDataComponents.TORCH_INDEX, (byte) Math.floorMod(currentIndex + (next ? 1 : -1), slots));
9695
});
9796
}
9897

98+
private int getCurrentTorchIndex(ItemStack stack, int slots) {
99+
int currentIndex = getCurrentTorchIndex(stack);
100+
if (currentIndex < TORCH_SLOT || currentIndex >= slots) {
101+
currentIndex = Mth.clamp(currentIndex, TORCH_SLOT, slots - 1);
102+
stack.set(ModDataComponents.TORCH_INDEX, (byte) currentIndex);
103+
}
104+
return currentIndex;
105+
}
106+
99107
private int getCurrentTorchIndex(ItemStack stack) {
100108
return stack.getOrDefault(ModDataComponents.TORCH_INDEX, (byte) 0);
101109
}
@@ -174,8 +182,7 @@ private boolean removeTorches(Player player, ItemStack staff, BlockPos placeBloc
174182
int distance = (int) player.getEyePosition(1).distanceTo(new Vec3(placeBlockAt.getX(), placeBlockAt.getY(), placeBlockAt.getZ()));
175183
int cost = 1 + distance / Config.COMMON.items.sojournerStaff.tilePerCostMultiplier.get();
176184

177-
int torchIndex = getCurrentTorchIndex(staff);
178-
return useCharge(staff, torchIndex, cost);
185+
return getFromHandler(staff, handler -> useCharge(staff, getCurrentTorchIndex(staff, handler.getSlots()), cost));
179186
}
180187
return true;
181188
}
@@ -231,9 +238,7 @@ protected boolean removeSlotWhenEmpty(int slot) {
231238
protected void removeSlot(ItemStack containerStack, int slot) {
232239
runOnHandler(containerStack, handler -> {
233240
handler.removeSlot(slot);
234-
if (getCurrentTorchIndex(containerStack) >= handler.getSlots()) {
235-
cycleTorchMode(containerStack, false);
236-
}
241+
getCurrentTorchIndex(containerStack, createHandler(containerStack).getSlots());
237242
});
238243

239244
}

0 commit comments

Comments
 (0)