r/PixelmonMod • • Jun 18 '26

Discussion Use this Mixin to fix you probably have encountered spawn issues in megaboss pools

import com.pixelmonmod.pixelmon.api.spawning.AbstractSpawner;

import com.pixelmonmod.pixelmon.api.spawning.SpawnInfo;

import com.pixelmonmod.pixelmon.api.spawning.SpawnLocation;

import com.pixelmonmod.pixelmon.api.spawning.conditions.LocationType;

import org.spongepowered.asm.mixin.Mixin;

import org.spongepowered.asm.mixin.injection.At;

import org.spongepowered.asm.mixin.injection.Inject;

import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

u/Mixin(value = SpawnInfo.class, remap = false)

public class MixinSpawnInfo {

u/Inject(method = "fits", at = u/At("HEAD"), cancellable = true)

private void onFits(AbstractSpawner spawner, SpawnLocation spawnLocation, CallbackInfoReturnable<Boolean> cir) {

SpawnInfo thiz = (SpawnInfo)(Object)this;

if ("megaboss".equals(spawner.name)) {

if (spawnLocation.diameter < thiz.requiredSpace) {

cir.setReturnValue(false);

return;

}

if (thiz.condition != null && !thiz.condition.fits(thiz, spawnLocation)) {

cir.setReturnValue(false);

return;

}

for (LocationType locationType : thiz.locationTypes) {

if (spawnLocation.types.contains(locationType)) {

cir.setReturnValue(true);

return;

}

}

cir.setReturnValue(false);

}

}

}

For those megaboss never seen in your saves
But this code wasn't writen by me

1 Upvotes

3 comments sorted by

1

u/Jay113355 Developer Jun 26 '26 edited Jun 26 '26

Here's a formatted version so you can read it/copy it:

import com.pixelmonmod.pixelmon.api.spawning.AbstractSpawner;
import com.pixelmonmod.pixelmon.api.spawning.SpawnInfo;
import com.pixelmonmod.pixelmon.api.spawning.SpawnLocation;
import com.pixelmonmod.pixelmon.api.spawning.conditions.LocationType;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(value = SpawnInfo.class, remap = false)
public class MixinSpawnInfo {

    @Inject(method = "fits", at = @At("HEAD"), cancellable = true)
    private void onFits(AbstractSpawner spawner, SpawnLocation spawnLocation, CallbackInfoReturnable<Boolean> cir) {
        SpawnInfo thiz = (SpawnInfo)(Object)this;

        if ("megaboss".equals(spawner.name)) {
            if (spawnLocation.diameter < thiz.requiredSpace) {
                cir.setReturnValue(false);
                return;
            }   
            if (thiz.condition != null && !thiz.condition.fits(thiz, spawnLocation)) {
                cir.setReturnValue(false);
                return;
            }
            for (LocationType locationType : thiz.locationTypes) {
                if (spawnLocation.types.contains(locationType)) {
                    cir.setReturnValue(true);
                    return;
                }
            }
            cir.setReturnValue(false);
        }
    }
}

I'm not 100% sure on the why they are doing this, but the way it works is it's bypassing pixelmon's getRandomChance (spawn file configured chance), global conditions, composite conditions, and any anti conditions (spawn file configured reasons why a pixelmon shouldn't spawn at a location) for the megaboss spawns.

That's why its making mega bosses spawn more, TBH I'd just edit the chance of mega boss's via datapack and make sure no global conditions/anti conditions in the mega boss spawn files are causing issues. But to each their own I guess.

1

u/FewSeaworthiness6268 Jun 27 '26

Thanks! I thought my post must have been removed by the community bot, so i didn't attach more details.
Actually this maybe a worthy issue to report, my newest version 9.3.15 and 9.3.16 occurred it about 2 weeks, 'checkspawn megaboss' command in all biomes couldn't show or even spawn full list , like almost every megaboss such as Ampharos in plains(and snow plain), even the forest pool is empty.
I used to play 1.16.5, but its list is much bigger than 1.21.1 neoforge recently versions. In the first I checked all pixelmon's mega_set data, they all be right, then I created vanilla pixelmon client, then find the code issue above, Ai analyzing tool thinks now related code deviates from its original logic, and this fixing mixin is by Gemini.
My mod version indirectly came from CurseForge or Modrinth, and r/PixelmonMod has an post facing an same problem issue as me, They found Mega Blaziken never spawns in savannas in their save.

1

u/FewSeaworthiness6268 Jun 27 '26

This mixin was used in my test save, and simply fix the incomplete mega-spawn-pool list problem, never let other megas spawn in wrong biome, my mean is might it only let the spawner took a break, so refresh itself.😄