This method, `getPotentialBonusSpawns`, determines and calculates the number of potential...
This method, getPotentialBonusSpawns
, determines and calculates the number of potential bonus spawns for a specific entity type in a raid, based on various factors such as the raid type, game difficulty, wave number, and RNG (randomly generated numbers). Let's break the code down:
Inputs to the method:
Raid.RaiderType p_219829_
: Specifies the type of raider (e.g.,VINDICATOR
,PILLAGER
,EVOKER
,ILLUSIONER
,WITCH
,RAVAGER
).RandomSource p_219830_
: A source of randomness, used to produce random integers.int p_219831_
: Represents the wave number within the raid.DifficultyInstance p_219832_
: Provides the difficulty of the game (e.g.,EASY
,NORMAL
, or more challenging difficulties such asEXTREME
).boolean p_219833_
: An additional condition provided, though unused in this fragment of code.
Execution:
-
Difficulty flags:
- The difficulty is extracted from
p_219832_
(Difficulty difficulty = p_219832_.getDifficulty()
). - Corresponding boolean flags are set:
flag
forEASY
,flag1
forNORMAL
,flag2
forEXTREME
.
- The difficulty is extracted from
-
Switch-case on the raider type (
p_219829_
):- Different behaviors occur depending on the raider type:
RaiderType:
VINDICATOR
andPILLAGER
:- Based on difficulty:
- On
EASY
: Randomly choose between 0 or 1 bonus spawns (i = p_219830_.nextInt(2)
). - On
NORMAL
: Fixed bonus of 1 spawn (i = 1
). - On harder difficulties: Fixed bonus of 2 spawns (
i = 2
).
- On
RaiderType:
EVOKER
andILLUSIONER
:- Always returns 0 (no bonus spawns allowed for this type).
RaiderType:
WITCH
:- Returns 0 (no bonus spawns) if:
- Difficulty is
EASY
, - Wave number (
p_219831_
) is 5 or below, - Wave number is 8,
- Or wave number is 11 or higher.
- Difficulty is
- Otherwise:
- Defaults to 1 bonus.
- In
EXTREME
difficulty, wave numbers >= 5 (excluding wave 8) affect the result such that it returns 1.
RaiderType:
RAVAGER
:- Returns 0 (no bonus spawns) if:
- Difficulty is
EASY
, - Wave number is 3 or lower,
- Or wave number is 6 or higher.
- Difficulty is
- Otherwise:
- Defaults to 1 bonus.
- In
EXTREME
difficulty, wave numbers between 4 and 5 result in a fixed return of 1. All other cases return 0.
-
Final adjustment (after the switch):
- If
i > 0
(i
being the calculated number of bonus spawns):- Randomly determine the number of spawns between 0 and
i
(p_219830_.nextInt(i + 1)
).
- Randomly determine the number of spawns between 0 and
- If
i <= 0
, return 0 (no bonus spawns).
- If
Output:
The method returns an integer, which represents the number of potential randomly determined bonus spawns for the specified entity type in the raid.
Purpose:
This code likely serves as part of a raid system in a game (e.g., a Minecraft-like implementation). It adjusts the number of additional spawns for different raider types, depending on game difficulty, wave number, and random chance, allowing for scalable challenge and variability during raids.