Skip to content

Create a models holder

Models holder is an Enum of individual models bounded with their textures.

  1. Create ModModels.java enum class and add your model

    • Directorylibs/
    • Directorysrc/main/
      • Directoryjava/your/namespace/your_mod_id/
        • Directoryclient/
          • Directoryloader/
            • ModModels.java
        • ExampleMod.java
      • Directoryresources/assets/your_mod_id/
        • Directorytextures/
          • Directorytesr/
        • Directorymodels/
          • Directorytesr/

    This is an example of models holder class structure:

    ModModels.java
    // ... other imports
    import dev.tauri.jsg.core.client.IModelsHolder;
    import dev.tauri.jsg.core.client.LoadersHolder;
    import dev.tauri.jsg.core.common.entity.BiomeOverlayInstance;
    public enum ModModels implements IModelsHolder { // should implement IModelsHolder
    // MODEL ENTRY
    // 1st parameter is path to the model file - must end with .obj
    // 2nd parameter is BASE path to the texture - file end is added automatically by scanning if file exists when loading textures (.png, then .webp and then .jpg)
    // 3rd parameter is true/false - true if you want to use different textures for each biome overlay
    MY_AWESOME_MODEL_WITH_TEXTURE("awesome/model.obj", "awesome/textures", true)
    ;
    // holds path to the obj model file
    public final ResourceLocation model;
    // map of texture path for each biome overlay registered in the core
    public final Map<BiomeOverlayInstance, ResourceLocation> biomeTextureResourceMap = new HashMap<>();
    // holds all biome overlays that have not been found for this model texture to prevent spamming log with errors
    private final List<BiomeOverlayInstance> nonExistingReported = new ArrayList<>();
    ModModels(String modelPath, String texturePath, boolean byOverlay) {
    this.model = ExampleMod.LOADERS_HOLDER.model().getModelResource(modelPath);
    loadEntry(texturePath, byOverlay);
    }
    @Override
    public @NotNull LoadersHolder getLoadersHolder() {
    return ExampleMod.LOADERS_HOLDER;
    }
    @Override
    public @NotNull ResourceLocation getModelLocation() {
    return model;
    }
    @Override
    public @NotNull Map<BiomeOverlayInstance, ResourceLocation> getBiomeTextureResourceMap() {
    return biomeTextureResourceMap;
    }
    @Override
    public @NotNull List<BiomeOverlayInstance> getNonExistingTexturesReported() {
    return nonExistingReported;
    }
    }
  2. Add model file and BASE texture

    • Directorylibs/
    • Directorysrc/main/
      • Directoryjava/your/namespace/your_mod_id/
        • Directoryclient/
          • Directoryloader/
            • ModModels.java
        • ExampleMod.java
      • Directoryresources/assets/your_mod_id/
        • Directorytextures/
          • Directorytesr/
            • Directoryawesome/
              • texture.webp
        • Directorymodels/
          • Directorytesr/
            • Directoryawesome/
              • model.obj
  3. Now you have added your model!