From 6b2187fb6626eb0aa7e501f1db8449a01dec876d Mon Sep 17 00:00:00 2001 From: Kli Kli Date: Wed, 7 Aug 2024 09:47:18 +0200 Subject: [PATCH] fix: crash when ritual is interrupted by removing ingredients Closes #1185 --- .../resources/assets/occultism/lang/en_us.json | 4 ++++ .../occultism/common/advancement/RitualTrigger.java | 3 ++- .../com/klikli_dev/occultism/common/ritual/Ritual.java | 10 +++++++--- .../occultism/datagen/lang/ENUSProvider.java | 6 ++++++ 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/generated/resources/assets/occultism/lang/en_us.json b/src/generated/resources/assets/occultism/lang/en_us.json index 9f71331be..1673251bd 100644 --- a/src/generated/resources/assets/occultism/lang/en_us.json +++ b/src/generated/resources/assets/occultism/lang/en_us.json @@ -1832,6 +1832,10 @@ "ritual.occultism.summon_wild_silverfish.finished": "Summoned the wild horde silverfish successfully.", "ritual.occultism.summon_wild_silverfish.interrupted": "Summoning of the wild horde silverfish interrupted.", "ritual.occultism.summon_wild_silverfish.started": "Started summoning the wild horde silverfish.", + "ritual.occultism.unknown.conditions": "Not all requirements for this ritual are met.", + "ritual.occultism.unknown.finished": "Ritual completed successfully.", + "ritual.occultism.unknown.interrupted": "Ritual interrupted.", + "ritual.occultism.unknown.started": "Ritual started.", "tag.block.c.ores.iesnium": "Iesnium Ore", "tag.block.c.ores.silver": "Silver Ore", "tag.block.c.storage_blocks.iesnium": "Iesnium Storage Blocks", diff --git a/src/main/java/com/klikli_dev/occultism/common/advancement/RitualTrigger.java b/src/main/java/com/klikli_dev/occultism/common/advancement/RitualTrigger.java index b4616884a..9586cae2f 100644 --- a/src/main/java/com/klikli_dev/occultism/common/advancement/RitualTrigger.java +++ b/src/main/java/com/klikli_dev/occultism/common/advancement/RitualTrigger.java @@ -65,7 +65,8 @@ public static Criterion ritualFactory(ResourceLoc } public boolean matches(ServerPlayer player, Ritual ritual) { - if (this.ritualId.isPresent() && !this.ritualId.get().equals(ritual.getRecipeHolder(player).id())) + var holder = ritual.getRecipeHolder(player.level()); + if (this.ritualId.isPresent() && holder != null && !this.ritualId.get().equals(holder.id())) return false; else return this.ritualFactoryId.isEmpty() || this.ritualFactoryId.get().equals(ritual.getFactoryID()); } diff --git a/src/main/java/com/klikli_dev/occultism/common/ritual/Ritual.java b/src/main/java/com/klikli_dev/occultism/common/ritual/Ritual.java index af6cb4672..751be7d0c 100644 --- a/src/main/java/com/klikli_dev/occultism/common/ritual/Ritual.java +++ b/src/main/java/com/klikli_dev/occultism/common/ritual/Ritual.java @@ -125,9 +125,10 @@ public RitualRecipe getRecipe() { return this.recipe; } - public RecipeHolder getRecipeHolder(ServerPlayer player) { + public RecipeHolder getRecipeHolder(Level level) { if (this.recipeHolderSupplier == null) { - this.recipeHolderSupplier = Suppliers.memoize(() -> player.getServer().getRecipeManager().getAllRecipesFor(OccultismRecipes.RITUAL_TYPE.get()).stream().filter( + this.recipeHolderSupplier = + Suppliers.memoize(() -> level.getRecipeManager().getAllRecipesFor(OccultismRecipes.RITUAL_TYPE.get()).stream().filter( r -> r.value() == this.getRecipe() ).findFirst().orElse(null)); } @@ -135,7 +136,10 @@ public RecipeHolder getRecipeHolder(ServerPlayer player) { } public String getRitualID(ServerPlayer player) { - ResourceLocation recipeId = this.getRecipeHolder(player).id(); + var holder = this.getRecipeHolder(player.level()); + if(holder == null) + return "unknown"; + ResourceLocation recipeId = holder.id(); String path = recipeId.getPath(); if (path.contains("/")) path = path.substring(path.indexOf("/") + 1); diff --git a/src/main/java/com/klikli_dev/occultism/datagen/lang/ENUSProvider.java b/src/main/java/com/klikli_dev/occultism/datagen/lang/ENUSProvider.java index ccdb22604..fbece0c9c 100644 --- a/src/main/java/com/klikli_dev/occultism/datagen/lang/ENUSProvider.java +++ b/src/main/java/com/klikli_dev/occultism/datagen/lang/ENUSProvider.java @@ -528,6 +528,12 @@ private void addRitualMessages() { this.add("ritual.occultism.disabled", "This ritual is disabled on this server."); this.add("ritual.occultism.does_not_exist", "\u00a7lUnknown ritual\u00a7r. Make sure the pentacle & ingredients are set up correctly. If you are still unsuccessful join our discord at https://invite.gg/klikli"); this.add("ritual.occultism.book_not_bound", "\u00a7lUnbound Book of Calling\u00a7r. You must craft this book with Dictionary of Spirits to bind to a spirit before starting a ritual."); + + this.add("ritual.occultism.unknown.conditions", "Not all requirements for this ritual are met."); + this.add("ritual.occultism.unknown.started", "Ritual started."); + this.add("ritual.occultism.unknown.finished", "Ritual completed successfully."); + this.add("ritual.occultism.unknown.interrupted", "Ritual interrupted."); + this.add("ritual.occultism.debug.conditions", "Not all requirements for this ritual are met."); this.add("ritual.occultism.debug.started", "Ritual started."); this.add("ritual.occultism.debug.finished", "Ritual completed successfully.");