Inspired by 2020's April Fools' 20w14infinite Snapshot, this mod brings endless randomly generated dimensions into Minecraft.
1package net.lerariemann.infinity.util.var;
2
3import net.lerariemann.infinity.InfinityMod;
4import net.lerariemann.infinity.util.InfinityMethods;
5import net.minecraft.core.BlockPos;
6import net.minecraft.core.registries.BuiltInRegistries;
7import net.minecraft.tags.FluidTags;
8import net.minecraft.util.RandomSource;
9import net.minecraft.world.Difficulty;
10import net.minecraft.world.entity.Entity;
11import net.minecraft.world.entity.EntityType;
12import net.minecraft.world.entity.MobCategory;
13//? if >1.21.2 {
14import net.minecraft.world.entity.EntitySpawnReason;
15import static net.minecraft.world.entity.EntitySpawnReason.isSpawner;
16//?} else {
17/*import net.minecraft.world.entity.MobSpawnType;
18 *///?}
19//? if =1.21.1 {
20/*import static net.minecraft.world.entity.MobSpawnType.isSpawner;
21*///?}
22import net.minecraft.world.entity.animal.WaterAnimal;
23import net.minecraft.world.entity.monster.Monster;
24import net.minecraft.world.level.ServerLevelAccessor;
25
26
27
28public interface InfinitySpawnHelper {
29 static <T extends Entity> boolean canSpawn(EntityType<T> type, ServerLevelAccessor world,
30 //? if >1.21.2 {
31 EntitySpawnReason
32 //?} else {
33 /*MobSpawnType
34 *///?}
35 spawnReason, BlockPos pos, RandomSource random) {
36 boolean bl;
37 MobCategory sg = type.getCategory();
38 if (isSpawnGroupWater(sg) || (WaterAnimal.class.isAssignableFrom(type.getBaseClass())))
39 bl = world.getFluidState(pos).is(FluidTags.WATER);
40 else bl = (world.getBlockState(pos.below()).isValidSpawn(world, pos.below(), type));
41
42 //? if >1.21 {
43 bl = bl || isSpawner(spawnReason);
44 //?} else {
45 /*bl = bl || spawnReason.equals(MobSpawnType.SPAWNER);
46 *///?}
47
48 if (sg.equals(MobCategory.MONSTER))
49 bl = bl && (Monster.isDarkEnoughToSpawn(world, pos, random) && world.getDifficulty() != Difficulty.PEACEFUL);
50 if (BuiltInRegistries.ENTITY_TYPE.getKey(type).getNamespace().equals(InfinityMod.MOD_ID)) bl = bl && InfinityMethods.chaosMobsEnabled();
51 return bl;
52 }
53
54 static boolean isSpawnGroupWater(MobCategory sg) {
55 return switch (sg) {
56 case WATER_CREATURE, WATER_AMBIENT, UNDERGROUND_WATER_CREATURE, AXOLOTLS -> true;
57 default -> false;
58 };
59 }
60}