Overview
TheProjectItem class represents a single file or folder within a Minecraft project. It provides methods for loading, saving, and managing file content, as well as tracking relationships between items.
Constructor
Creates a new ProjectItem instance.Parent project
Existing item data to initialize from
Properties
project
The parent project containing this item
itemType
Type of the item (e.g., entityTypeBehavior, blockTypeDefinition)
name
Display name of the item
projectPath
Path relative to the project root
storageType
Storage type (singleFile or folder)
defaultFile
The primary file for this item (for singleFile storage)
primaryFile
The most important file for this item (considers variants)
defaultFolder
The folder for this item (for folder storage)
isContentLoaded
Whether the item’s content has been loaded
needsSave
Whether the item has unsaved changes
tags
Array of tags associated with this item
parentItems
Items that reference this item
childItems
Items referenced by this item
errorStatus
Error status if the item failed to load
errorMessage
Error message if the item failed to load
editPreference
Edit preference for this specific item
Methods
loadContent
Loads the item’s content from storage.True if successful
saveContent
Saves the item’s content to storage.ensureStorage
Ensures the item’s storage (file or folder) is initialized.ensureFileStorage
Ensures the item’s file storage is initialized (for singleFile items).The initialized file
loadFolder
Loads the item’s folder and contents (for folder items).The loaded folder
getStringContent
Gets the item’s content as a string.The content as a string, or undefined if not text
getJsonObject
Parses the item’s content as JSON.The parsed JSON object
getContentAsJson
Gets the item’s content as a parsed JSON object.The parsed JSON
rename
Renames the item’s file.New base name (without extension)
deleteItem
Deletes the item and its file from the project.getManager
Gets the manager object for this item (e.g., EntityTypeDefinition).The manager object
prepareToSave
Prepares the item for saving (runs auto-generation, etc.).hasTag
Checks if the item has a specific tag.Tag name to check
True if the tag exists
ensureTag
Adds a tag to the item if it doesn’t already exist.Tag name to add
addChildItem
Adds a child item relationship (this item references another).The child item
addParentItem
Adds a parent item relationship (another item references this one).The parent item
ensureDependencies
Calculates and updates the item’s dependencies.getPack
Gets the pack (behavior or resource pack) containing this item.The containing pack
getPackRelativePath
Gets the path relative to the containing pack.Pack-relative path
invalidateContentProcessedState
Marks the item’s content as needing reprocessing.Variants
getVariant
Gets a specific variant of the item (for multi-version files).Variant label (e.g., “1.20.0”, “preview”)
The variant, or undefined if not found
ensureVariant
Gets or creates a variant.Variant label
The variant
getVariantList
Gets all variants for this item.Array of variants
Events
onPropertyChanged
Fired when a property changes.onLoaded
Fired when the item finishes loading.onFileRetrieved
Fired when the item’s file is retrieved.onFolderRetrieved
Fired when the item’s folder is retrieved.Types
ProjectItemType
ProjectItemStorageType
ProjectItemEditPreference
ProjectItemCreationType
Usage Examples
Working with Entity Files
Creating and Saving a New File
Tracking Dependencies
See Also
- Project - Parent project management
- CreatorTools - Main application class
- Utilities - Helper functions