Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MinecraftForge
GitHub Repository: MinecraftForge/MinecraftForge
Path: blob/1.21.x/src/main/java/net/minecraftforge/client/model/generators/loaders/ObjModelBuilder.java
7251 views
1
/*
2
* Copyright (c) Forge Development LLC and contributors
3
* SPDX-License-Identifier: LGPL-2.1-only
4
*/
5
6
package net.minecraftforge.client.model.generators.loaders;
7
8
import com.google.common.base.Preconditions;
9
import com.google.gson.JsonObject;
10
import net.minecraft.server.packs.PackType;
11
import net.minecraft.resources.ResourceLocation;
12
import net.minecraftforge.client.model.generators.CustomLoaderBuilder;
13
import net.minecraftforge.client.model.generators.ModelBuilder;
14
import net.minecraftforge.common.data.ExistingFileHelper;
15
16
/**
17
* In 1.21.4 Mojang exposed their data generators for their models. So it should be feasible to just use theirs.
18
* If you find something lacking feel free to open a PR so that we can extend it.
19
* @deprecated Use Vanilla's providers {@link net.minecraft.client.data.models.ModelProvider}
20
*/
21
public class ObjModelBuilder<T extends ModelBuilder<T>> extends CustomLoaderBuilder<T>
22
{
23
private static final ResourceLocation NAME = ResourceLocation.fromNamespaceAndPath("forge", "obj");
24
public static <T extends ModelBuilder<T>> ObjModelBuilder<T> begin(T parent, ExistingFileHelper existingFileHelper)
25
{
26
return new ObjModelBuilder<>(parent, existingFileHelper);
27
}
28
29
private ResourceLocation modelLocation;
30
private Boolean automaticCulling;
31
private Boolean shadeQuads;
32
private Boolean flipV;
33
private Boolean emissiveAmbient;
34
private ResourceLocation mtlOverride;
35
36
protected ObjModelBuilder(T parent, ExistingFileHelper existingFileHelper)
37
{
38
super(NAME, parent, existingFileHelper);
39
}
40
41
public ObjModelBuilder<T> modelLocation(ResourceLocation modelLocation)
42
{
43
Preconditions.checkNotNull(modelLocation, "modelLocation must not be null");
44
Preconditions.checkArgument(existingFileHelper.exists(modelLocation, PackType.CLIENT_RESOURCES),
45
"OBJ Model %s does not exist in any known resource pack", modelLocation);
46
this.modelLocation = modelLocation;
47
return this;
48
}
49
50
public ObjModelBuilder<T> automaticCulling(boolean automaticCulling)
51
{
52
this.automaticCulling = automaticCulling;
53
return this;
54
}
55
56
public ObjModelBuilder<T> shadeQuads(boolean shadeQuads)
57
{
58
this.shadeQuads = shadeQuads;
59
return this;
60
}
61
62
public ObjModelBuilder<T> flipV(boolean flipV)
63
{
64
this.flipV = flipV;
65
return this;
66
}
67
68
public ObjModelBuilder<T> emissiveAmbient(boolean ambientEmissive)
69
{
70
this.emissiveAmbient = ambientEmissive;
71
return this;
72
}
73
74
public ObjModelBuilder<T> overrideMaterialLibrary(ResourceLocation mtlOverride)
75
{
76
Preconditions.checkNotNull(mtlOverride, "mtlOverride must not be null");
77
Preconditions.checkArgument(existingFileHelper.exists(mtlOverride, PackType.CLIENT_RESOURCES),
78
"OBJ Model %s does not exist in any known resource pack", mtlOverride);
79
this.mtlOverride = mtlOverride;
80
return this;
81
}
82
83
@Override
84
public JsonObject toJson(JsonObject json)
85
{
86
json = super.toJson(json);
87
88
Preconditions.checkNotNull(modelLocation, "modelLocation must not be null");
89
90
json.addProperty("model", modelLocation.toString());
91
92
if (automaticCulling != null)
93
json.addProperty("automatic_culling", automaticCulling);
94
95
if (shadeQuads != null)
96
json.addProperty("shade_quads", shadeQuads);
97
98
if (flipV != null)
99
json.addProperty("flip_v", flipV);
100
101
if (emissiveAmbient != null)
102
json.addProperty("emissive_ambient", emissiveAmbient);
103
104
if (mtlOverride != null)
105
json.addProperty("mtl_override", mtlOverride.toString());
106
107
return json;
108
}
109
}
110
111