Skip to content

Commit

Permalink
fix: crash when ritual is interrupted by removing ingredients
Browse files Browse the repository at this point in the history
Closes #1185
  • Loading branch information
klikli-dev committed Aug 7, 2024
1 parent 3643cf3 commit 6b2187f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/generated/resources/assets/occultism/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public static Criterion<RitualTrigger.TriggerInstance> 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());
}
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/com/klikli_dev/occultism/common/ritual/Ritual.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,21 @@ public RitualRecipe getRecipe() {
return this.recipe;
}

public RecipeHolder<RitualRecipe> getRecipeHolder(ServerPlayer player) {
public RecipeHolder<RitualRecipe> 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));
}
return this.recipeHolderSupplier.get();
}

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down

0 comments on commit 6b2187f

Please sign in to comment.