Path: blob/1.21.x/src/main/java/net/minecraftforge/client/model/generators/loaders/ObjModelBuilder.java
7251 views
/*1* Copyright (c) Forge Development LLC and contributors2* SPDX-License-Identifier: LGPL-2.1-only3*/45package net.minecraftforge.client.model.generators.loaders;67import com.google.common.base.Preconditions;8import com.google.gson.JsonObject;9import net.minecraft.server.packs.PackType;10import net.minecraft.resources.ResourceLocation;11import net.minecraftforge.client.model.generators.CustomLoaderBuilder;12import net.minecraftforge.client.model.generators.ModelBuilder;13import net.minecraftforge.common.data.ExistingFileHelper;1415/**16* In 1.21.4 Mojang exposed their data generators for their models. So it should be feasible to just use theirs.17* If you find something lacking feel free to open a PR so that we can extend it.18* @deprecated Use Vanilla's providers {@link net.minecraft.client.data.models.ModelProvider}19*/20public class ObjModelBuilder<T extends ModelBuilder<T>> extends CustomLoaderBuilder<T>21{22private static final ResourceLocation NAME = ResourceLocation.fromNamespaceAndPath("forge", "obj");23public static <T extends ModelBuilder<T>> ObjModelBuilder<T> begin(T parent, ExistingFileHelper existingFileHelper)24{25return new ObjModelBuilder<>(parent, existingFileHelper);26}2728private ResourceLocation modelLocation;29private Boolean automaticCulling;30private Boolean shadeQuads;31private Boolean flipV;32private Boolean emissiveAmbient;33private ResourceLocation mtlOverride;3435protected ObjModelBuilder(T parent, ExistingFileHelper existingFileHelper)36{37super(NAME, parent, existingFileHelper);38}3940public ObjModelBuilder<T> modelLocation(ResourceLocation modelLocation)41{42Preconditions.checkNotNull(modelLocation, "modelLocation must not be null");43Preconditions.checkArgument(existingFileHelper.exists(modelLocation, PackType.CLIENT_RESOURCES),44"OBJ Model %s does not exist in any known resource pack", modelLocation);45this.modelLocation = modelLocation;46return this;47}4849public ObjModelBuilder<T> automaticCulling(boolean automaticCulling)50{51this.automaticCulling = automaticCulling;52return this;53}5455public ObjModelBuilder<T> shadeQuads(boolean shadeQuads)56{57this.shadeQuads = shadeQuads;58return this;59}6061public ObjModelBuilder<T> flipV(boolean flipV)62{63this.flipV = flipV;64return this;65}6667public ObjModelBuilder<T> emissiveAmbient(boolean ambientEmissive)68{69this.emissiveAmbient = ambientEmissive;70return this;71}7273public ObjModelBuilder<T> overrideMaterialLibrary(ResourceLocation mtlOverride)74{75Preconditions.checkNotNull(mtlOverride, "mtlOverride must not be null");76Preconditions.checkArgument(existingFileHelper.exists(mtlOverride, PackType.CLIENT_RESOURCES),77"OBJ Model %s does not exist in any known resource pack", mtlOverride);78this.mtlOverride = mtlOverride;79return this;80}8182@Override83public JsonObject toJson(JsonObject json)84{85json = super.toJson(json);8687Preconditions.checkNotNull(modelLocation, "modelLocation must not be null");8889json.addProperty("model", modelLocation.toString());9091if (automaticCulling != null)92json.addProperty("automatic_culling", automaticCulling);9394if (shadeQuads != null)95json.addProperty("shade_quads", shadeQuads);9697if (flipV != null)98json.addProperty("flip_v", flipV);99100if (emissiveAmbient != null)101json.addProperty("emissive_ambient", emissiveAmbient);102103if (mtlOverride != null)104json.addProperty("mtl_override", mtlOverride.toString());105106return json;107}108}109110111