Skip to content

Commit

Permalink
Make HarvestCheckEvent actually stop further computations as soon as …
Browse files Browse the repository at this point in the history
…harvesting is prevented.
  • Loading branch information
Crystal-Spider committed Jun 27, 2024
1 parent b594481 commit fd7d46b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,13 @@ interface HarvestCheckEvent extends HarvestEvent<Player, Level> {
*
* @return whether the crop can be harvested.
*/
@ApiStatus.Internal
boolean canHarvest();

/**
* Sets whether the crop can be harvested.
*
* @param canHarvest whether the crop can be harvested.
* Prevents harvesting.
*/
void setCanHarvest(boolean canHarvest);
void preventHarvest();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,9 @@ public boolean canHarvest() {
}

@Override
public void setCanHarvest(boolean canHarvest) {
this.canHarvest = canHarvest;
@ApiStatus.Internal
public void preventHarvest() {
this.canHarvest = false;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public BlockState getCrop() {
* Event triggered when checking whether a crop can be harvested.<br>
* Fired on both sides.
*/
@Cancelable
public static class HarvestCheckEvent extends ForgeHarvestEvent<Player, Level> implements HarvestEvent.HarvestCheckEvent {
/**
* Whether the crop can be harvested.
Expand All @@ -106,13 +107,15 @@ public static class HarvestCheckEvent extends ForgeHarvestEvent<Player, Level> i
}

@Override
@ApiStatus.Internal
public boolean canHarvest() {
return canHarvest;
}

@Override
public void setCanHarvest(boolean canHarvest) {
this.canHarvest = canHarvest;
public void preventHarvest() {
this.canHarvest = false;
this.setCanceled(true);
}
}

Expand Down

0 comments on commit fd7d46b

Please sign in to comment.