Fix XP orb spawning to use queue system to prevent client lag on large amounts of xp spawns#96
Open
SkyzerFlyzer wants to merge 1 commit into
Conversation
This commit fixes all XP orb spawning issues by implementing a proper queue system and respecting Minecraft's 16-bit integer limit. ## Problems Fixed 1. **All XP orbs spawned instantly** - Previously: Loop spawned all orbs immediately in one tick - Now: XP orbs queue and spawn gradually over time 2. **Doesn't respect 32,767 max orb value** - Previously: Always used orbSize, never considered limit - Now: Clamps to MAX_ORB_VALUE = 32767 (16-bit signed int) 3. **Last orb value bug** - Previously: 2502 XP with size 5 → 501×5 = 2505 XP (3 extra!) - Now: 2502 XP with size 5 → 500×5 + 1×2 = 2502 XP ✓ 4. **XP orbs spawn at least 3x faster than items** - Previously: Items spawned at 3-10 per cycle - Now: XP spawns at 30 per cycle (minimum 3x faster) - Prevents long delays with large XP rewards ## Implementation **GatewayEntity.java:** - Added `Queue<Integer> undroppedXP` field - Added `spawnXPOrb(int value)` method - Added `queueXP(int value)` method - Added `getXPDropCount()` returning 30 (3x faster than items) - Updated tick() to spawn XP orbs in parallel with items - Added NBT serialization for XP queue (save/load) - Added ExperienceOrb import **NormalGatewayEntity.java:** - Updated `isCompleted()` to check XP queue is empty **Reward.java (ExperienceReward):** - Added `MAX_ORB_VALUE = 32767` constant - Changed to queue XP instead of spawning directly - Fixed remainder calculation: `Math.min(remaining, clampedOrbSize)` - Respects 32,767 limit by clamping orbSize ## Technical Details XP orbs now follow same pattern as items: - Queue during reward generation - Spawn gradually every 4 ticks via tick() - Persist across world reloads (NBT) - Gateway waits for all XP to spawn before completing Spawn rate: 30 XP orbs per 4 ticks (vs 3-10 items per 4 ticks) Fixes: All reported XP orb spawning issues
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This commit fixes all XP orb spawning issues by implementing a proper queue system and respecting Minecraft's 16-bit integer limit.
Problems Fixed
All XP orbs spawned instantly
Doesn't respect 32,767 max orb value
Last orb value bug
XP orbs spawn at least 3x faster than items
Implementation
GatewayEntity.java:
Queue<Integer> undroppedXPfieldspawnXPOrb(int value)methodqueueXP(int value)methodgetXPDropCount()returning 30 (3x faster than items)NormalGatewayEntity.java:
isCompleted()to check XP queue is emptyReward.java (ExperienceReward):
MAX_ORB_VALUE = 32767constantMath.min(remaining, clampedOrbSize)Technical Details
XP orbs now follow same pattern as items:
Spawn rate: 30 XP orbs per 4 ticks (vs 3-10 items per 4 ticks)
Fixes: All reported XP orb spawning issues