Skip to content

Commit

Permalink
Fix brewing statistics
Browse files Browse the repository at this point in the history
Coffee brewing recipes now increase the item's crafted statistic
  • Loading branch information
Chikorita-Lover committed Sep 17, 2024
1 parent 29b87bc commit 75ab94b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public ItemActionResult onUseWithItem(ItemStack stack, BlockState state, World w
player.giveItemStack(ingredientStack);
}
cauldronCampfire.clear();
cauldronCampfire.dropExperienceForRecipesUsed((ServerPlayerEntity) player);
cauldronCampfire.onRecipesCrafted((ServerPlayerEntity) player);
world.playSound(null, pos, SoundEvents.ITEM_BOTTLE_FILL, SoundCategory.BLOCKS, 1.0F, 1.0F);
world.emitGameEvent(null, GameEvent.FLUID_PICKUP, pos);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory;
import net.minecraft.stat.Stats;
import net.minecraft.util.Identifier;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.math.BlockPos;
Expand Down Expand Up @@ -215,15 +216,18 @@ public void clear() {
}
}

public void dropExperienceForRecipesUsed(ServerPlayerEntity player) {
public void onRecipesCrafted(ServerPlayerEntity player) {
ArrayList<RecipeEntry<?>> recipeEntries = new ArrayList<>();
for (Identifier recipeId : this.recipesUsed) {
this.getWorld().getRecipeManager().get(recipeId).ifPresent(recipeEntries::add);
}
player.unlockRecipes(recipeEntries);
for (RecipeEntry<?> recipe : recipeEntries) {
if (recipe == null || !(recipe.value() instanceof CoffeeBrewingRecipe coffeeBrewingRecipe)) continue;
if (recipe == null || !(recipe.value() instanceof CoffeeBrewingRecipe coffeeBrewingRecipe)) {
continue;
}
player.onRecipeCrafted(recipe, this.inventory);
player.incrementStat(Stats.CRAFTED.getOrCreateStat(coffeeBrewingRecipe.getResult(this.world.getRegistryManager()).getItem()));
Caffeinated.BREW_COFFEE_CRITERION.trigger(player, coffeeBrewingRecipe.getResult(this.getWorld().getRegistryManager()));
dropExperience(player.getServerWorld(), player.getPos(), coffeeBrewingRecipe.getExperience());
}
Expand Down

0 comments on commit 75ab94b

Please sign in to comment.