-
Notifications
You must be signed in to change notification settings - Fork 497
/
BakedModelHolder.java
86 lines (72 loc) · 3.12 KB
/
BakedModelHolder.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package buildcraft.core.lib.client.model;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.client.resources.model.IBakedModel;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.ModelBakeEvent;
import net.minecraftforge.client.model.IModel;
import net.minecraftforge.client.model.ModelLoaderRegistry;
import net.minecraftforge.client.model.TRSRTransformation;
import net.minecraftforge.client.model.obj.OBJLoader;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
public abstract class BakedModelHolder extends BuildCraftBakedModel {
public BakedModelHolder(ImmutableList<BakedQuad> quads, TextureAtlasSprite particle, VertexFormat format,
ImmutableMap<TransformType, TRSRTransformation> transforms) {
super(quads, particle, format, transforms);
}
public BakedModelHolder(ImmutableList<BakedQuad> quads, TextureAtlasSprite particle, VertexFormat format) {
this(quads, particle, format, getBlockTransforms());
}
private final Map<ResourceLocation, IModel> models = Maps.newHashMap();
private final Map<ResourceLocation, IBakedModel> bakedModels = Maps.newHashMap();
public BakedModelHolder() {
this(null, null, null);
}
@SubscribeEvent
public void modelBakeEvent(ModelBakeEvent event) {
models.clear();
}
protected IModel getModelJSON(ResourceLocation loc) {
if (!models.containsKey(loc)) {
IModel model = null;
try {
model = ModelLoaderRegistry.getModel(loc);
} catch (IOException e) {
e.printStackTrace();
}
if (model == null) model = ModelLoaderRegistry.getMissingModel();
models.put(loc, model);
}
return models.get(loc);
}
protected IModel getModelOBJ(ResourceLocation loc) {
if (!models.containsKey(loc)) {
IModel model = null;
try {
model = OBJLoader.instance.loadModel(loc);
} catch (IOException e) {
e.printStackTrace();
}
if (model == null) model = ModelLoaderRegistry.getMissingModel();
models.put(loc, model);
}
return models.get(loc);
}
protected IBakedModel getModelItemLayer(ResourceLocation identifier, TextureAtlasSprite sprite) {
return getModelItemLayer(identifier, ImmutableList.of(sprite));
}
protected IBakedModel getModelItemLayer(ResourceLocation identifier, List<TextureAtlasSprite> sprites) {
if (!bakedModels.containsKey(identifier)) {
bakedModels.put(identifier, createModelItemLayer(sprites));
}
return bakedModels.get(identifier);
}
}