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

Release bed POI if villager child spawn is blocked #1793

Open
wants to merge 1 commit into
base: 1.21.x
Choose a base branch
from

Conversation

sciwhiz12
Copy link
Member

This PR fixes #1606 by ensuring the bed POI is released if the villager child is blocked from spawning in the world, such as being spawn-cancelled through FinalizeSpawnEvent, by returning an empty optional from VillagerMakeLove#breed to mimic an unsuccessful breeding event. See the linked issue for more details.

Tested by following the instructions in the linked issue, with the following code inserted in the constructor of FinalizeSpawnEvent to mimic the mod (and using hotswap to change the true to false as the arbitrary condition specified in the reproduction steps):

        if (entity instanceof Villager && spawnType == EntitySpawnReason.BREEDING) {
            System.out.println("Captured finalized spawn event for bred villager");

            if (true) {
                this.setSpawnCancelled(true);
                System.out.println("Cancelled spawn");
            } else {
                System.out.println("Allowed spawn to go through");
            }
        }

@sciwhiz12 sciwhiz12 added bug A bug or error 1.21.4 Targeted at Minecraft 1.21.4 labels Dec 23, 2024
@neoforged-pr-publishing
Copy link

neoforged-pr-publishing bot commented Dec 23, 2024

  • Publish PR to GitHub Packages

Last commit published: 01a2a084f1582bb2a8d44bb01ad2b7401903112f.

PR Publishing

The artifacts published by this PR:

Repository Declaration

In order to use the artifacts published by the PR, add the following repository to your buildscript:

repositories {
    maven {
        name 'Maven for PR #1793' // https://github.com/neoforged/NeoForge/pull/1793
        url 'https://prmaven.neoforged.net/NeoForge/pr1793'
        content {
            includeModule('net.neoforged', 'neoforge')
            includeModule('net.neoforged', 'testframework')
        }
    }
}

MDK installation

In order to setup a MDK using the latest PR version, run the following commands in a terminal.
The script works on both *nix and Windows as long as you have the JDK bin folder on the path.
The script will clone the MDK in a folder named NeoForge-pr1793.
On Powershell you will need to remove the -L flag from the curl invocation.

mkdir NeoForge-pr1793
cd NeoForge-pr1793
curl -L https://prmaven.neoforged.net/NeoForge/pr1793/net/neoforged/neoforge/21.4.40-beta-pr-1793-fix-1.21.4-GH-1606-villager-breed-finalizespawn-cancel/mdk-pr1793.zip -o mdk.zip
jar xf mdk.zip
rm mdk.zip || del mdk.zip

To test a production environment, you can download the installer from here.

@marchermans
Copy link
Contributor

Can this be tested somehow @sciwhiz12 ?

@sciwhiz12
Copy link
Member Author

  1. Insert the code block mentioned in the PR description into the constructor of FinalizeSpawnEvent (at the end).
  2. Create an enclosed room with 3 beds and a door.
  3. Spawn two villagers.
  4. Drop a stack of bread (for the villagers to eat).
  5. Wait until the villagers start to breed (signalled by heart particles).
  6. Once the villagers stop breeding (cessation of heart particles), check the console/log to see that the breed attempt was stopped by the constructor code preventing the spawn of the baby villager (signified by two print statements).
  7. Change the true in the if-condition of the previously-inserted code to false. (Don't forget to hotswap or restart the game for the change to take effect.)
  8. Wait 5 minutes for the villagers to breed again

After step 8, with this fix, the villagers' breeding attempt should be successful, and a baby villager should be spawned. Without this fix, the breeding attempt will fail, as signified by anger particles.

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 this pull request may close these issues.

[1.21.1] Cancelled villager breeding causes beds to be wrongly occupied
3 participants