So I heard you were talking crap about Minecraft's difficulty?

So I heard you were talking crap about Minecraft's difficulty?

797k Downloads

Crash on canCaveSpiderSpawn with Negative Y Position

T0paz opened this issue ยท 2 comments

commented

Server Exception:

java.lang.IllegalArgumentException: bound must be positive
	at java.util.Random.nextInt(Random.java:388)
	at com.github.galatynf.sihywtcamd.Utils.canCaveSpiderSpawn(Utils.java:21)
	at net.minecraft.entity.mob.HostileEntity.handler$dhb000$changeCaveSpiderSpawn(HostileEntity:525)
	at net.minecraft.entity.mob.HostileEntity.canSpawnInDark(HostileEntity)
	at net.minecraft.entity.SpawnRestriction.canSpawn(SpawnRestriction:156)
	at net.minecraft.world.SpawnHelper.canSpawn(SpawnHelper:329)
	at net.minecraft.world.SpawnHelper.spawnEntitiesInChunk(SpawnHelper:262)
	at net.minecraft.world.SpawnHelper.spawnEntitiesInChunk(SpawnHelper:199)
	at net.minecraft.world.SpawnHelper.spawn(SpawnHelper:187)
	at net.minecraft.server.world.ServerChunkManager.method_20801(ServerChunkManager:368)
	at java.util.ArrayList.forEach(ArrayList.java:1511)
	at net.minecraft.server.world.ServerChunkManager.tickChunks(ServerChunkManager:355)
	at net.minecraft.server.world.ServerChunkManager.tick(ServerChunkManager:324)
	at net.minecraft.server.world.ServerWorld.tick(ServerWorld:372)
	at net.minecraft.server.MinecraftServer.tickWorlds(MinecraftServer:891)
	at net.minecraft.server.MinecraftServer.tick(MinecraftServer:831)
	at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer:96)
	at net.minecraft.server.MinecraftServer.runServer(MinecraftServer:697)
	at net.minecraft.server.MinecraftServer.method_29739(MinecraftServer:270)
	at java.lang.Thread.run(Thread.java:831)

com.github.galatynf.sihywtcamd.utils
Line 21: random.nextInt((int) Math.cbrt(pos.getY())) assumes the Y position of the attempted spawn is never negative. This doesn't hold true for the experimental 1.17 datapack deepening cave generation to negative Y levels. Either abs(), round or offset this.

commented

I changed the behavior of the spawning so you won't have this crash anymore. However, cave spiders may not spawn at all. Indeed, the datapack from Mojang override every mob spawn, so you may not see guardians too spawn naturally I guess. I don't know much about datapacks but maybe you can just delete lines about spawn and it will keep the normal values (it may also crash the datapacks idk), or add new lines in the datapack to let the cave spiders spawn (should work I guess but you would have to do it for every single biome and find good values for mob spawn)

commented

I thought that it could work but I actually forgot that I put a random generated with the Y position haha. Alright, I'll fix that quickly for this weekend. Thanks for the report! =)