Skip to content

Commit 0124f37

Browse files
Fix scroll crashloop when per-world order hasn't been calculated yet (#992)
2 parents 288c6f8 + 8648ea5 commit 0124f37

3 files changed

Lines changed: 21 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
66

7+
## [UNRELEASED]
8+
9+
### Fixed
10+
11+
- Fixed a crash loop when trying to generate a creative-mode ancient scroll for a Great Spell whose per-world pattern hasn't been calculated yet, by Robotgiggle in [992](https://github.com/FallingColors/HexMod/pull/992).
12+
713
## `0.11.3` - 2025-11-22
814

915
### Added

Common/src/main/java/at/petrak/hexcasting/common/items/storage/ItemScroll.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
public class ItemScroll extends Item implements IotaHolderItem {
5050
public static final String TAG_OP_ID = "op_id";
5151
public static final String TAG_PATTERN = "pattern";
52+
public static final String TAG_RECALC_WARNING = "recalc_warning";
5253
public static final String TAG_NEEDS_PURCHASE = "needs_purchase";
5354
public static final ResourceLocation ANCIENT_PREDICATE = modLoc("ancient");
5455

@@ -180,6 +181,12 @@ public void inventoryTick(ItemStack pStack, Level pLevel, Entity pEntity, int pS
180181
}
181182
var patternKey = ResourceKey.create(IXplatAbstractions.INSTANCE.getActionRegistry().key(), opID);
182183
var pat = PatternRegistryManifest.getCanonicalStrokesPerWorld(patternKey, pEntity.getServer().overworld());
184+
if (pat == null) {
185+
// if pat is null, the per-world order hasn't been registered; remove the op_id and warn the player
186+
NBTHelper.putString(pStack, TAG_RECALC_WARNING, NBTHelper.getString(pStack, TAG_OP_ID));
187+
NBTHelper.remove(pStack, TAG_OP_ID);
188+
return;
189+
}
183190
NBTHelper.put(pStack, TAG_PATTERN, pat.serializeToNBT());
184191
}
185192
}
@@ -190,6 +197,12 @@ public void appendHoverText(ItemStack pStack, @Nullable Level pLevel, List<Compo
190197
if (NBTHelper.getBoolean(pStack, TAG_NEEDS_PURCHASE)) {
191198
var needsPurchase = Component.translatable("hexcasting.tooltip.scroll.needs_purchase");
192199
pTooltipComponents.add(needsPurchase.withStyle(ChatFormatting.GRAY));
200+
} else if (NBTHelper.hasString(pStack, TAG_RECALC_WARNING)) {
201+
var spellName = Component.translatable("hexcasting.action." + ResourceLocation.tryParse(NBTHelper.getString(pStack, TAG_RECALC_WARNING)));
202+
var line1 = Component.translatable("hexcasting.tooltip.scroll.recalc_warning.line1", spellName);
203+
var line2 = Component.translatable("hexcasting.tooltip.scroll.recalc_warning.line2");
204+
pTooltipComponents.add(line1.withStyle(ChatFormatting.RED));
205+
pTooltipComponents.add(line2.withStyle(ChatFormatting.RED));
193206
} else if (NBTHelper.hasString(pStack, TAG_OP_ID) && !NBTHelper.hasCompound(pStack, TAG_PATTERN)) {
194207
var notLoaded = Component.translatable("hexcasting.tooltip.scroll.pattern_not_loaded");
195208
pTooltipComponents.add(notLoaded.withStyle(ChatFormatting.GRAY));

Common/src/main/resources/assets/hexcasting/lang/en_us.flatten.json5

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,8 @@
581581
scroll: {
582582
needs_purchase: "Purchase to show pattern",
583583
pattern_not_loaded: "Place in inventory to load pattern",
584+
"recalc_warning.line1": "The per-world pattern for %s has not been calculated yet!",
585+
"recalc_warning.line2": "Please run /hexcasting recalcPatterns, then grab a new scroll.",
584586
},
585587

586588
abacus: {

0 commit comments

Comments
 (0)