Pumpkin-MC/Pumpkin · error · TemplateError

Invalid field type for

Error message

Invalid field type for {0}

What it means

TemplateError::InvalidFieldType is raised by StructureTemplate::load and load_palette when an NBT field inside a structure template exists but has the wrong tag type or shape. The error names the offending field (e.g. 'palette', 'entities.pos', 'blocks.pos'), so the template NBT does not match the vanilla structure-template schema. It is thrown while parsing a structure template NBT compound, meaning the template file itself is malformed.

Solutions

  1. Regenerate the structure template by exporting it again from a vanilla Minecraft world (place the structure and use a structure block to save it).
  2. Validate the template NBT shape before loading: check that 'palette' is a List of Lists of Compounds and that 'entities.pos'/'blocks.pos' are lists of exactly 3 numeric tags.
  3. If building NBT programmatically, fix the writer to emit the correct tag types (Int for state/pos ints, Double for entity pos, Compound per entry).
  4. Inspect the field named in the error message with an NBT viewer (e.g. NBTExplorer) to confirm the tag type.

Example fix

// before: palette stored as a flat list of compounds
compound.put_list("palette", flat_palette_tags);
// after: palettes is a list of palettes (list of lists of compounds)
compound.put_list("palettes", NbtTag::List(vec![NbtTag::List(palette_entries)]));
Defensive patterns

Strategy: validation

Validate before calling

fn template_nbt_shape_ok(nbt: &NbtCompound) -> bool {
    let palettes_ok = match nbt.get_list("palettes") {
        Some(p) => p.iter().all(|t| matches!(t, NbtTag::List(_))),
        None => matches!(nbt.get_list("palette"), Some(_)),
    };
    let entities_ok = nbt.get_list("entities").map(|e| e.iter().all(|t| matches!(t, NbtTag::Compound(_)))).unwrap_or(true);
    palettes_ok && entities_ok
}

Type guard

fn as_list(tag: &NbtTag) -> Option<&Vec<NbtTag>> {
    if let NbtTag::List(l) = tag { Some(l) } else { None }
}

Try / catch

match template.load(&compound) {
    Err(TemplateError::InvalidFieldType(field)) => eprintln!("malformed template NBT at field '{field}'"),
    Err(e) => return Err(e),
    Ok(()) => {}
}

Prevention

When it happens

Trigger: StructureTemplate::load encounters: a 'palette' entry that is not a List-of-Lists; a palette or entities/blocks entry that is not a Compound; entities.pos or blocks.pos lists whose length != 3; pos elements that cannot be extracted as doubles/ints. Any of these call sites (structure_template.rs:908-1004) produce this error.

Common situations: Hand-edited or programmatically generated .nbt structure files with wrong tag types; templates exported by modified or older Minecraft versions with a different schema; corruption from incorrect NBT serialization in custom tooling; truncation or wrong compression leaving garbage tags.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of Pumpkin-MC/Pumpkin@8d4639e25a (2026-09-09). Data as JSON: /api/errors/3dd27140bfe2805f. Report an issue: GitHub.

Appendix: source

Thrown at crates/pumpkin-world/src/generation/structure/template/structure_template.rs:25

use pumpkin_data::{Mirror, Rotation};
use pumpkin_nbt::{compound::NbtCompound, nbt_compress::read_gzip_compound_tag, tag::NbtTag};
use pumpkin_util::math::{block_box::BlockBox, vector3::Vector3};
use thiserror::Error;

use super::processor::StructureProcessor;
use crate::generation::structure::structures::jigsaw::JigsawJointType;

/// Errors that can occur when loading or saving a structure template.
#[derive(Debug, Error)]
pub enum TemplateError {
    #[error("Failed to decompress NBT: {0}")]
    NbtError(#[from] pumpkin_nbt::Error),

    #[error("Missing required field: {0}")]
    MissingField(&'static str),

    #[error("Invalid field type for {0}")]
    InvalidFieldType(&'static str),

    #[error("Invalid palette index: {0}")]
    InvalidPaletteIndex(u32),
}

/// Settings used when placing, transforming, or querying a [`StructureTemplate`].
#[derive(Clone, Debug)]
pub struct StructurePlaceSettings {
    pub mirror: Mirror,
    pub rotation: Rotation,
    pub rotation_pivot: Vector3<i32>,
    pub bounding_box: Option<BlockBox>,
    pub ignore_entities: bool,
    pub apply_waterlogging: bool,
    pub known_shape: bool,
    pub processors: Vec<StructureProcessor>,
    pub finalize_entities: bool,

View on GitHub (pinned to 8d4639e25a)