Skip to content

Commit

Permalink
Fixed water purifier crashing
Browse files Browse the repository at this point in the history
  • Loading branch information
Adubbz committed Jan 6, 2024
1 parent 700c5c3 commit 4a43a8c
Showing 1 changed file with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,16 @@ public static void serverTick(Level level, BlockPos pos, BlockState state, Water
boolean previouslyFiltering = blockEntity.currentlyFiltering();
boolean changed = false;

// Reduce the time remaining on the filter whilst purification is occurring
if (blockEntity.currentlyFiltering() && blockEntity.purifyProgress > 0)
if (blockEntity.currentlyFiltering())
{
--blockEntity.filterTimeRemaining;
}

if (!blockEntity.level.isClientSide)
{
ItemStack filterStack = blockEntity.items.get(1);
if (blockEntity.currentlyFiltering() || !filterStack.isEmpty() && !blockEntity.items.get(0).isEmpty()) {
boolean hasFilter = !filterStack.isEmpty();
if (blockEntity.currentlyFiltering() || hasFilter && !blockEntity.items.get(0).isEmpty()) {
RecipeHolder<?> recipe = blockEntity.level.getRecipeManager().getRecipeFor((RecipeType<WaterPurifierRecipe>) TANRecipeTypes.WATER_PURIFYING, blockEntity, blockEntity.level).orElse(null);

if (recipe != null)
Expand All @@ -161,15 +161,15 @@ public static void serverTick(Level level, BlockPos pos, BlockState state, Water
// If we are now filtering, consume the filter item
if (blockEntity.currentlyFiltering()) {
changed = true;
if (filterStack.getItem().hasCraftingRemainingItem())
blockEntity.items.set(1, new ItemStack(filterStack.getItem().getCraftingRemainingItem()));
else if (!filterStack.isEmpty()) {
filterStack.shrink(1);

// Replace the filter with the containing item (if there is one)
// Normally this would be something like an empty bucket
if (filterStack.isEmpty()) {
blockEntity.items.set(1, new ItemStack(filterStack.getItem().getCraftingRemainingItem()));
if (hasFilter)
{
Item filter = filterStack.getItem();
filterStack.shrink(1);
if (filterStack.isEmpty())
{
Item remainingItem = filter.getCraftingRemainingItem();
blockEntity.items.set(1, remainingItem == null ? ItemStack.EMPTY : new ItemStack(remainingItem));
}
}
}
Expand Down

0 comments on commit 4a43a8c

Please sign in to comment.