--- a/net/minecraft/world/level/levelgen/structure/templatesystem/DefinedStructureInfo.java
+++ b/net/minecraft/world/level/levelgen/structure/templatesystem/DefinedStructureInfo.java
@@ -22,7 +22,7 @@
     private LiquidSettings liquidSettings;
     @Nullable
     private RandomSource random;
-    private int palette;
+    public int palette = -1; // CraftBukkit - Set initial value so we know if the palette has been set forcefully
     private final List<DefinedStructureProcessor> processors;
     private boolean knownShape;
     private boolean finalizeEntities;
@@ -149,6 +149,13 @@
 
         if (i == 0) {
             throw new IllegalStateException("No palettes");
+        // CraftBukkit start
+        } else if (this.palette >= 0) {
+            if (this.palette >= i) {
+                throw new IllegalArgumentException("Palette index out of bounds. Got " + this.palette + " where there are only " + i + " palettes available.");
+            }
+            return list.get(this.palette);
+        // CraftBukkit end
         } else {
             return (DefinedStructure.b) list.get(this.getRandom(blockposition).nextInt(i));
         }
