Skip to content

Instantly share code, notes, and snippets.

@Bowserinator
Last active July 3, 2021 03:16
Show Gist options
  • Save Bowserinator/9131c31804cb5fab5423a90398f03f77 to your computer and use it in GitHub Desktop.
Save Bowserinator/9131c31804cb5fab5423a90398f03f77 to your computer and use it in GitHub Desktop.
Patching Spigot incorrect mobcaps

Spigot (actually craftbukkit) has some bugs, namely persistent piglins and axolotls still count towards the mob cap. This is terrible, for example, this means a barter farm, axolotl aquarium or a piglin based wither skeleton farm can prevent mobs from spawning entirely. This is a patch for spigot that fixes it until it can be offically fixed.

Prereq

  • Git
  • Maven
  • Java 16 JDK
  • BuildTools

Building Spigot

See here under the "Running BuildTools" header for building spigot initially

Files to Change

All of these files are under Spigot/Spigot-Server:

src/main/java/net/minecraft/world/entity/animal/axolotl/Axolotl.java:

In setFromBucket change the this.persistenceRequired line to set to true so it looks like this:

    @Override
    public void setFromBucket(boolean flag) {
        this.entityData.set(Axolotl.FROM_BUCKET, flag);
        this.persistenceRequired = true;
    }

Currently spawning an axolotl from a bucket does not set its persistence which is what is considered for mob cap calculation.

src/main/java/net/minecraft/world/entity/monster/piglin/EntityPiglin.java:

In isTypeNotPersistent make it return true:

    @Override
    public boolean isTypeNotPersistent(double d0) {
        return true;
    }

Not sure why this change was made, it makes all piglins count to mob cap.

Apply patches

First commit your changes, cd to Spigot-Server and git add . and git commit -m "Piglin-Axoltol-Mob-Cap-Patch"

Then run makePatches.sh and applyPatches.sh in that order

Build

cd to Spigot (1 directory up from Spigot-Server) and run mvn clean install. The output jar will be in Spigot-Server/target (it's the one called like spigot-1.17-R0.1-SNAPSHOT.jar)

Congrats you now have a patched spigot jar!

@jacob1
Copy link

jacob1 commented Jul 3, 2021

I looked into it a little more. You are right, this spawn code is broken. Seems like the spigot devs are aware of this too, but don't want to put in the effort to fix it (this effort would I think be reverting all the patches - but I'm not sure whether or not this would break any api or plugins)

So knowing the persistence code won't be vanallified -

Your piglin patch is correct (with one caveat), I think it's vanilla minecraft that has the bugged isTypeNotPersistent implementation, probably a programmer creating Piglins was like, "hmm, isTypeNotPersistent method, I better implement this", set it to return !this.isPersistent(), which is technically correct .. but should not be implemented. Implementing it just manages to break the spawning code in spigot. The only thing is, your patch should instead delete the isTypeNotPersistent method from EntityPiglin.cpp, keep the original implementation (return true;) in place.

Your axolotl patch also looks correct. I think this was an implementation error in craftbukkit when the original commit (5b93c39d4b5b) was implemented. It should always set it to true. This patch should also be applied to EntityFish.java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment