Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.21.1] Cancelled villager breeding causes beds to be wrongly occupied #1606

Open
RedstoneDubstep opened this issue Oct 20, 2024 · 3 comments · May be fixed by #1793
Open

[1.21.1] Cancelled villager breeding causes beds to be wrongly occupied #1606

RedstoneDubstep opened this issue Oct 20, 2024 · 3 comments · May be fixed by #1793
Labels
1.21.4 Targeted at Minecraft 1.21.4 bug A bug or error

Comments

@RedstoneDubstep
Copy link
Contributor

Minecraft Version: 1.21.1

NeoForge Version: 21.1.68

Steps to Reproduce:

  1. Create a test mod with an event listener which listens to the FinalizeSpawnEvent, and cancels it & calls setSpawnCancelled on the event if the entity in the event is a Villager, the MobSpawnType is BREEDING and the gametime is <24000 ticks (or any other arbitrary condition)
  2. Create a new singleplayer world with NeoForge and this mod
  3. Set up a simple villager breeding scenario: Place exactly 3 beds in an enclosure, spawn 2 villagers, give them a few stacks of bread to encourage them to breed
  4. Observe how breeding (after 10 seconds of heart particles) rightfully fails because the fail condition (in this case the gametime being less than 24000 ticks) is satisfied
  5. Set the gametime to anything higher than 24000 ticks, to make the condition no longer apply
  6. Observe how (after the villager breeding cooldown of 5 minutes has passed) the two villagers still cannot reproduce (this time with anger particles shown after the heart particles of the villager breeding process)

Description of issue:
When villager breeding is stopped through canceling the FinalizeSpawnEvent of the baby villager spawning, the relevant code in the VillagerMakeLove class does not account for the baby villager not actually being in the world and requests the one free bed in range to be reserved for the baby villager, even though the baby is not in the world. This lock of the bed POI (which can also happen repeatedly with multiple beds, if multiple free ones are pathfindable) will then prevent villagers from mating even if the relevant FinalizeSpawnEvent is no longer cancelled, due to the vanilla villager breeding logic not finding a free bed in range (even though at least one of the beds never had a villager sleeping in it, but was falsely marked as occupied by the cancelled first breeding process).
This can be fixed by breaking + replacing the wrongly occupied beds, however it is still an annoyance having to do that, since beds that will never be slept in should also logically allow villager breeding (everything else would be unintuitive).

@RedstoneDubstep RedstoneDubstep added the triage Needs triaging and confirmation label Oct 20, 2024
@sciwhiz12 sciwhiz12 added bug A bug or error 1.21.4 Targeted at Minecraft 1.21.4 and removed triage Needs triaging and confirmation labels Dec 23, 2024
@sciwhiz12
Copy link
Member

Confirmed on 21.4.38-beta.

The simple fix, which seems to work, is to modify VillagerMakeLove#breed to return an empty optional (signifying an unsuccessful attempt to breed) if the villager child is unable to be placed within the world. (Calling FinalizeSpawnEvent#setSpawnCancelled eventually leads to the villager not being placed in the world, thus #isAddedToLevel() will be false`.)

A remaining question, however, is what to do with the parent's ages (which controls when they're allowed to breed again) if the villager child is blocked from spawning. I'm assuming that what we want is to have the parents still have their age increased (for the 5-minute cooldown between breeding attempts), but that might be up for debate.

sciwhiz12 added a commit to sciwhiz12/NeoForge that referenced this issue Dec 23, 2024
@sciwhiz12 sciwhiz12 linked a pull request Dec 23, 2024 that will close this issue
@RedstoneDubstep
Copy link
Contributor Author

Hello, thank you for opening a PR addressing this issue!
I think I agree with you that increasing the parent's age for villagers for failed breeding attempts is a sensible idea, to mimic vanilla behaviour as closely as possible (maybe this could also be looked into for other animals, if that's not already the case?).

@sciwhiz12
Copy link
Member

Welcome! On your point of looking into other animals for this kind of fix, I think this particular fix only applies to villagers because of use of a bed POI for the child. The other mobs, which are various animals, use BreedGoal or AnimalMakeLove for breeding, which does not have any special interactions that might need to occur if the breeding is unsuccessful (outside of those already accounted for by the hooks for BabyEntitySpawnEvent).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.21.4 Targeted at Minecraft 1.21.4 bug A bug or error
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants