@@ -407,12 +407,13 @@ public void preGenerateLoot(SpawnerData spawner, LootGenerationCallback callback
407407
408408 final int minMobs ;
409409 final int maxMobs ;
410- final boolean atCapacity ;
410+ final boolean itemStorageFull ;
411411
412412 try {
413413 int usedSlots = spawner .getVirtualInventory ().getUsedSlots ();
414414 int maxSlots = spawner .getMaxSpawnerLootSlots ();
415- atCapacity = usedSlots >= maxSlots && spawner .getSpawnerExp () >= spawner .getMaxStoredExp ();
415+ itemStorageFull = usedSlots >= maxSlots ;
416+ boolean atCapacity = itemStorageFull && spawner .getSpawnerExp () >= spawner .getMaxStoredExp ();
416417
417418 if (atCapacity ) {
418419 callback .onLootGenerated (Collections .emptyList (), 0 );
@@ -426,16 +427,28 @@ public void preGenerateLoot(SpawnerData spawner, LootGenerationCallback callback
426427 }
427428
428429 Scheduler .runTaskAsync (() -> {
429- LootResult loot = generateLoot (minMobs , maxMobs , spawner );
430+ LootResult loot ;
431+ if (itemStorageFull ) {
432+ loot = generateExperienceOnlyLoot (minMobs , maxMobs , spawner );
433+ } else {
434+ loot = generateLoot (minMobs , maxMobs , spawner );
435+ }
436+
430437 callback .onLootGenerated (
431- loot .items () != null ? new ArrayList <>(loot .items ()) : Collections .emptyList (),
432- loot .experience ()
438+ loot .items () != null ? new ArrayList <>(loot .items ()) : Collections .emptyList (),
439+ loot .experience ()
433440 );
434441 });
435442 } finally {
436443 spawner .getLootGenerationLock ().unlock ();
437444 }
438445 }
446+
447+ private LootResult generateExperienceOnlyLoot (int minMobs , int maxMobs , SpawnerData spawner ) {
448+ int mobCount = random .nextInt (maxMobs - minMobs + 1 ) + minMobs ;
449+ int totalExperience = spawner .getEntityExperienceValue () * mobCount ;
450+ return new LootResult (Collections .emptyList (), totalExperience );
451+ }
439452
440453 /**
441454 * Adds pre-generated loot to spawner instantly when timer expires.
@@ -493,14 +506,12 @@ public void addPreGeneratedLoot(SpawnerData spawner, List<ItemStack> items, int
493506 return ;
494507 }
495508
496- final boolean capacityCheck ;
497-
498509 try {
499510 int usedSlots = spawner .getVirtualInventory ().getUsedSlots ();
500511 int maxSlots = spawner .getMaxSpawnerLootSlots ();
501- capacityCheck = usedSlots >= maxSlots && spawner .getSpawnerExp () >= spawner .getMaxStoredExp ();
502-
503- if (capacityCheck ) {
512+ boolean isCompletelyFull = usedSlots >= maxSlots && spawner .getSpawnerExp () >= spawner .getMaxStoredExp ();
513+
514+ if (isCompletelyFull ) {
504515 return ;
505516 }
506517 } finally {
@@ -530,8 +541,22 @@ public void addPreGeneratedLoot(SpawnerData spawner, List<ItemStack> items, int
530541 }
531542
532543 if (!validItems .isEmpty ()) {
533- spawner .addItemsAndUpdateSellValue (validItems );
534- changed = true ;
544+ int usedSlots = spawner .getVirtualInventory ().getUsedSlots ();
545+ int maxSlots = spawner .getMaxSpawnerLootSlots ();
546+
547+ if (usedSlots < maxSlots ) {
548+ List <ItemStack > itemsToAdd = validItems ;
549+
550+ int totalRequiredSlots = calculateRequiredSlots (itemsToAdd , spawner .getVirtualInventory ());
551+ if (totalRequiredSlots > maxSlots ) {
552+ itemsToAdd = limitItemsToAvailableSlots (itemsToAdd , spawner );
553+ }
554+
555+ if (!itemsToAdd .isEmpty ()) {
556+ spawner .addItemsAndUpdateSellValue (itemsToAdd );
557+ changed = true ;
558+ }
559+ }
535560 }
536561 }
537562
0 commit comments