Skip to content

Instantly share code, notes, and snippets.

@AzureDoom
Created August 20, 2020 07:21
Show Gist options
  • Save AzureDoom/45be3c88656e6d46d3b019dcd1f364a5 to your computer and use it in GitHub Desktop.
Save AzureDoom/45be3c88656e6d46d3b019dcd1f364a5 to your computer and use it in GitHub Desktop.
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import com.google.common.collect.ImmutableMap;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.SpawnGroup;
import net.minecraft.util.registry.BuiltinRegistries;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.SpawnSettings;
public class EntitySpawnsCheatSheetFabric {
//Iterate through all registered biomes in the WorldGenRegistries.
public static void addSpawnEntries() {
for (Biome biome : BuiltinRegistries.BIOME) {
if (biome.getCategory() != Biome.Category.NETHER && biome.getCategory() != Biome.Category.THEEND && biome.getCategory() != Biome.Category.NONE) {
addMobSpawnToBiome(biome, SpawnGroup.MONSTER, new SpawnSettings.SpawnEntry(EntityType.ENDERMAN, 100, 100, 100));
}
}
}
//Add the normal info along with a list of "Spawners"
public static void addMobSpawnToBiome(Biome biome, SpawnGroup classification, SpawnSettings.SpawnEntry... spawners) {
convertImmutableSpawners(biome);
//Copy the list of spawners that already exist for the given biome.
List<SpawnSettings.SpawnEntry> spawnersList = new ArrayList<>(biome.getSpawnSettings().spawners.get(classification));
//Add all the spawners within our list.
spawnersList.addAll(Arrays.asList(spawners));
//Overwrite the list for the given classification with the old list and our new entries.
biome.getSpawnSettings().spawners.put(classification, spawnersList);
}
//Convert the immutable map to a mutable HashMap in order for us to change the data stored in these maps
private static void convertImmutableSpawners(Biome biome) {
if (biome.getSpawnSettings().spawners instanceof ImmutableMap) {
biome.getSpawnSettings().spawners = new HashMap<>(biome.getSpawnSettings().spawners);
}
}
}
@AzureDoom
Copy link
Author

Here are the Access Wideners you need for this

accessible    field    net/minecraft/world/biome/SpawnSettings    spawners    Ljava/util/Map;

mutable    field    net/minecraft/world/biome/SpawnSettings    spawners    Ljava/util/Map;

accessible    method    net/minecraft/entity/SpawnRestriction    register    (Lnet/minecraft/entity/EntityType;Lnet/minecraft/entity/SpawnRestriction$Location;Lnet/minecraft/world/Heightmap$Type;Lnet/minecraft/entity/SpawnRestriction$SpawnPredicate;)V

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