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/IModelBuilder.java
7608 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;
7
8
import net.minecraft.client.renderer.block.model.BakedQuad;
9
import net.minecraft.client.renderer.block.model.ItemTransforms;
10
import net.minecraft.client.renderer.block.model.SimpleModelWrapper;
11
import net.minecraft.client.renderer.item.EmptyModel;
12
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
13
import net.minecraft.client.renderer.block.model.BlockModelPart;
14
import net.minecraft.client.resources.model.QuadCollection;
15
import net.minecraft.core.Direction;
16
import net.minecraft.resources.ResourceLocation;
17
import net.minecraftforge.client.RenderTypeGroup;
18
19
import java.util.List;
20
21
/**
22
* Base interface for any object that collects culled and unculled faces and bakes them into a model.
23
* <p>
24
* Provides a generic base implementation via {@link #of(boolean, boolean, boolean, ItemTransforms, TextureAtlasSprite, RenderTypeGroup, RenderTypeGroup)}
25
* and a quad-collecting alternative via {@link #collecting(List)}.
26
*
27
* @deprecated Use {@link net.minecraft.client.resources.model.QuadCollection} instead.
28
*/
29
@Deprecated(forRemoval = true, since = "1.21.5")
30
public interface IModelBuilder<T extends IModelBuilder<T>> {
31
/**
32
* Creates a new model builder that uses the provided attributes in the final baked model.
33
*/
34
static IModelBuilder<?> of(
35
boolean hasAmbientOcclusion,
36
boolean usesBlockLight,
37
boolean isGui3d,
38
ItemTransforms transforms,
39
TextureAtlasSprite particle
40
){
41
return of(hasAmbientOcclusion, usesBlockLight, isGui3d, transforms, particle, RenderTypeGroup.EMPTY);
42
}
43
44
static IModelBuilder<?> of(
45
boolean hasAmbientOcclusion,
46
boolean usesBlockLight,
47
boolean isGui3d,
48
ItemTransforms transforms,
49
TextureAtlasSprite particle,
50
RenderTypeGroup renderTypes
51
){
52
return new Simple(hasAmbientOcclusion, usesBlockLight, isGui3d, transforms, particle, renderTypes);
53
}
54
55
static IModelBuilder<?> of(
56
boolean hasAmbientOcclusion,
57
boolean usesBlockLight,
58
boolean isGui3d,
59
ItemTransforms transforms,
60
TextureAtlasSprite particle,
61
RenderTypeGroup renderTypes,
62
RenderTypeGroup renderTypesFast
63
){
64
return new Simple(hasAmbientOcclusion, usesBlockLight, isGui3d, transforms, particle, renderTypes, renderTypesFast);
65
}
66
67
/**
68
* Creates a new model builder that collects quads to the provided list, returning
69
* {@linkplain EmptyModel#BAKED an empty model} if you call {@link #build()}.
70
*/
71
static IModelBuilder<?> collecting(List<BakedQuad> quads) {
72
return new Collecting(quads);
73
}
74
75
T addCulledFace(Direction facing, BakedQuad quad);
76
77
T addUnculledFace(BakedQuad quad);
78
79
BlockModelPart build();
80
81
class Simple implements IModelBuilder<Simple> {
82
private final QuadCollection.Builder builder;
83
84
private final boolean hasAmbientOcclusion;
85
86
// TODO: [VEN] These are UNUSED, and this is GOING TO BREAK.
87
private final boolean usesBlockLight;
88
private final boolean isGui3d;
89
private final ItemTransforms transforms;
90
private final TextureAtlasSprite particle;
91
private final RenderTypeGroup renderTypes;
92
private final RenderTypeGroup renderTypesFast;
93
94
private Simple(
95
boolean hasAmbientOcclusion, boolean usesBlockLight, boolean isGui3d,
96
ItemTransforms transforms, TextureAtlasSprite particle, RenderTypeGroup renderTypes
97
) {
98
this(hasAmbientOcclusion, usesBlockLight, isGui3d, transforms, particle, renderTypes, RenderTypeGroup.EMPTY);
99
}
100
101
private Simple(
102
boolean hasAmbientOcclusion, boolean usesBlockLight, boolean isGui3d,
103
ItemTransforms transforms, TextureAtlasSprite particle, RenderTypeGroup renderTypes, RenderTypeGroup renderTypesFast
104
) {
105
this.builder = new QuadCollection.Builder();
106
this.hasAmbientOcclusion = hasAmbientOcclusion;
107
this.usesBlockLight = usesBlockLight;
108
this.isGui3d = isGui3d;
109
this.transforms = transforms;
110
this.particle = particle;
111
this.renderTypes = renderTypes;
112
this.renderTypesFast = renderTypesFast;
113
}
114
115
@Override
116
public Simple addCulledFace(Direction facing, BakedQuad quad) {
117
builder.addCulledFace(facing, quad);
118
return this;
119
}
120
121
@Override
122
public Simple addUnculledFace(BakedQuad quad) {
123
builder.addUnculledFace(quad);
124
return this;
125
}
126
127
@Override
128
public BlockModelPart build() {
129
var quads = builder.build();
130
// TODO: [VEN] Models will NOT be complete here!!!!
131
return new SimpleModelWrapper(quads, hasAmbientOcclusion, particle);
132
}
133
}
134
135
class Collecting implements IModelBuilder<Collecting> {
136
private static final BlockModelPart EMPTY = new SimpleModelWrapper(QuadCollection.EMPTY, false, new TextureAtlasSprite(ResourceLocation.fromNamespaceAndPath("forge", "empty"), null, 0, 0, 0, 0) {});
137
private final List<BakedQuad> quads;
138
139
private Collecting(List<BakedQuad> quads) {
140
this.quads = quads;
141
}
142
143
@Override
144
public Collecting addCulledFace(Direction facing, BakedQuad quad) {
145
quads.add(quad);
146
return this;
147
}
148
149
@Override
150
public Collecting addUnculledFace(BakedQuad quad) {
151
quads.add(quad);
152
return this;
153
}
154
155
@Override
156
public BlockModelPart build() {
157
return EMPTY;
158
}
159
}
160
}
161
162