Skip to content

Commit 6c58a0b

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

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.77
18+
mod_version=2.0.78
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
@@ -75,24 +75,23 @@ private void scanForMatchingTorchesToFillInternalStorage(ItemStack staff, Player
7575
}
7676

7777
public ItemStack getCurrentTorch(ItemStack stack) {
78-
return getFromHandler(stack, handler -> getCurrentTorchIndex(stack) < handler.size() ? handler.getStackInSlot(getCurrentTorchIndex(stack)) : ItemStack.EMPTY);
78+
return getFromHandler(stack, handler -> handler.getStackInSlot(getCurrentTorchIndex(stack, handler.size())));
7979
}
8080

8181
public int getTorchCount(ItemStack stack) {
82-
return getFromHandler(stack, handler -> getCurrentTorchIndex(stack) < handler.size() ? handler.getAmountAsInt(getCurrentTorchIndex(stack)) : 0);
82+
return getFromHandler(stack, handler -> handler.getAmountAsInt(getCurrentTorchIndex(stack, handler.size())));
8383
}
8484

8585
private void cycleTorchMode(ItemStack stack, boolean next) {
86-
ItemStack currentTorch = getCurrentTorch(stack);
87-
if (getCurrentTorchIndex(stack) != TORCH_SLOT && currentTorch.isEmpty()) {
88-
return;
89-
}
9086
runOnHandler(stack, handler -> {
9187
int slots = handler.size();
88+
int currentIndex = getCurrentTorchIndex(stack, slots);
89+
if (currentIndex != TORCH_SLOT && handler.getStackInSlot(currentIndex).isEmpty()) {
90+
return;
91+
}
9292
if (slots == 1) {
9393
return;
9494
}
95-
int currentIndex = getCurrentTorchIndex(stack);
9695
stack.set(ModDataComponents.TORCH_INDEX, (byte) Math.floorMod(currentIndex + (next ? 1 : -1), slots));
9796
});
9897
}
@@ -101,6 +100,15 @@ private int getCurrentTorchIndex(ItemStack stack) {
101100
return stack.getOrDefault(ModDataComponents.TORCH_INDEX, (byte) 0);
102101
}
103102

103+
private int getCurrentTorchIndex(ItemStack stack, int slots) {
104+
int currentIndex = getCurrentTorchIndex(stack);
105+
if (currentIndex < TORCH_SLOT || currentIndex >= slots) {
106+
currentIndex = Mth.clamp(currentIndex, TORCH_SLOT, slots - 1);
107+
stack.set(ModDataComponents.TORCH_INDEX, (byte) currentIndex);
108+
}
109+
return currentIndex;
110+
}
111+
104112
@Override
105113
protected void addMoreInformation(ItemStack staff, @Nullable HolderLookup.Provider registries, TooltipBuilder tooltipBuilder) {
106114
StringJoiner joiner = new StringJoiner(";");
@@ -175,8 +183,7 @@ private boolean removeTorches(Player player, ItemStack staff, BlockPos placeBloc
175183
int distance = (int) player.getEyePosition(1).distanceTo(new Vec3(placeBlockAt.getX(), placeBlockAt.getY(), placeBlockAt.getZ()));
176184
int cost = 1 + distance / Config.COMMON.items.sojournerStaff.tilePerCostMultiplier.get();
177185

178-
int torchIndex = getCurrentTorchIndex(staff);
179-
return useCharge(staff, torchIndex, cost);
186+
return getFromHandler(staff, handler -> useCharge(staff, getCurrentTorchIndex(staff, handler.size()), cost));
180187
}
181188
return true;
182189
}
@@ -232,9 +239,7 @@ protected boolean removeSlotWhenEmpty(int slot) {
232239
protected void removeSlot(ItemStack containerStack, int slot) {
233240
runOnHandler(containerStack, handler -> {
234241
handler.removeSlot(slot);
235-
if (getCurrentTorchIndex(containerStack) >= handler.size()) {
236-
cycleTorchMode(containerStack, false);
237-
}
242+
getCurrentTorchIndex(containerStack, createHandler(containerStack).size());
238243
});
239244

240245
}

0 commit comments

Comments
 (0)