--- a/net/minecraft/world/level/levelgen/structure/pools/StructureTemplatePool.java
+++ b/net/minecraft/world/level/levelgen/structure/pools/StructureTemplatePool.java
@@ -97,7 +97,13 @@
     }
 
     public StructurePoolElement getRandomTemplate(RandomSource random) {
+        //Paper start - Prevent random.nextInt throwing an IllegalArgumentException
+        if (this.templates.size() == 0) {
+            return EmptyPoolElement.INSTANCE;
+        } else {
         return this.templates.get(random.nextInt(this.templates.size()));
+        }
+        // Paper end
     }
 
     public List<StructurePoolElement> getShuffledTemplates(RandomSource random) {
