Skip to content

Commit

Permalink
Fixed crash with invalid op_id on unloaded scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
Robotgiggle committed Jan 25, 2025
1 parent 2134295 commit 248ca92
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,15 @@ public void inventoryTick(ItemStack pStack, Level pLevel, Entity pEntity, int pS
if (NBTHelper.getBoolean(pStack, TAG_NEEDS_PURCHASE)) {
NBTHelper.remove(pStack, TAG_NEEDS_PURCHASE);
}
// if op_id is set but there's no stored pattern, load the pattern on inv tick
// if op_id is set but there's no stored pattern, attempt to load the pattern on inv tick
if (NBTHelper.hasString(pStack, TAG_OP_ID) && !NBTHelper.hasCompound(pStack, TAG_PATTERN) && pEntity.getServer() != null) {
var patternKey = ResourceKey.create(
IXplatAbstractions.INSTANCE.getActionRegistry().key(),
ResourceLocation.tryParse(NBTHelper.getString(pStack, TAG_OP_ID))
);
var opID = ResourceLocation.tryParse(NBTHelper.getString(pStack, TAG_OP_ID));
if (opID == null) {
// if the provided op_id is invalid, remove it so we don't keep trying every tick
NBTHelper.remove(pStack, TAG_OP_ID);
return;
}
var patternKey = ResourceKey.create(IXplatAbstractions.INSTANCE.getActionRegistry().key(), opID);
var pat = PatternRegistryManifest.getCanonicalStrokesPerWorld(patternKey, pEntity.getServer().overworld());
NBTHelper.put(pStack, TAG_PATTERN, pat.serializeToNBT());
}
Expand Down

0 comments on commit 248ca92

Please sign in to comment.