-
Notifications
You must be signed in to change notification settings - Fork 497
/
FacadePluggableModel.java
99 lines (81 loc) · 3.96 KB
/
FacadePluggableModel.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
87
88
89
90
91
92
93
94
95
96
97
98
99
package buildcraft.transport.client.model;
import java.util.List;
import javax.vecmath.Matrix4f;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.client.resources.model.ModelRotation;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.IFlexibleBakedModel;
import net.minecraftforge.client.model.IModel;
import buildcraft.api.transport.pluggable.IPluggableModelBaker;
import buildcraft.core.lib.client.model.BCModelHelper;
import buildcraft.core.lib.client.model.BakedModelHolder;
import buildcraft.core.lib.client.model.MutableQuad;
import buildcraft.core.lib.utils.MatrixUtils;
import buildcraft.transport.PipeIconProvider;
public final class FacadePluggableModel extends BakedModelHolder implements IPluggableModelBaker<ModelKeyFacade> {
private static final ResourceLocation hollowLoc = new ResourceLocation("buildcrafttransport:models/blocks/pluggables/facade_hollow.obj");
private static final ResourceLocation filledLoc = new ResourceLocation("buildcrafttransport:models/blocks/pluggables/facade_filled.obj");
private static final ResourceLocation connectorLoc = new ResourceLocation("buildcrafttransport:models/blocks/pluggables/plug.obj");
public static final FacadePluggableModel INSTANCE = new FacadePluggableModel();
private FacadePluggableModel() {
// We only extend BakedModelHolder to get the model functions
}
public IModel modelHollow() {
return getModelOBJ(hollowLoc);
}
public IModel modelFilled() {
return getModelOBJ(filledLoc);
}
public IModel modelConnector() {
return getModelOBJ(connectorLoc);
}
@Override
public VertexFormat getVertexFormat() {
return DefaultVertexFormats.BLOCK;
}
@Override
public ImmutableList<BakedQuad> bake(ModelKeyFacade key) {
return ImmutableList.copyOf(bakeCutout(key.side, key.hollow, key.state, getVertexFormat()));
}
public List<BakedQuad> bakeCutout(EnumFacing face, boolean hollow, IBlockState state, VertexFormat format) {
List<BakedQuad> quads = Lists.newArrayList();
// FIXME: Use the model bisector to cut a model down + squish one side down so it looks right
final TextureAtlasSprite sprite = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getTexture(state);
Matrix4f matrix = MatrixUtils.rotateTowardsFace(face);
IModel model;
if (hollow) {
model = modelHollow();
} else {
model = modelFilled();
}
if (model != null) {
IFlexibleBakedModel baked = model.bake(ModelRotation.X0_Y0, format, singleTextureFunction(sprite));
for (BakedQuad quad : baked.getGeneralQuads()) {
MutableQuad mutable = MutableQuad.create(quad);
mutable.transform(matrix);
mutable.setCalculatedDiffuse();
BCModelHelper.appendBakeQuads(quads, mutable);
}
}
if (!hollow) {
IModel connector = modelConnector();
TextureAtlasSprite structure = PipeIconProvider.TYPE.PipeStructureCobblestone.getIcon();
IFlexibleBakedModel baked = connector.bake(ModelRotation.X0_Y0, format, singleTextureFunction(structure));
for (BakedQuad quad : baked.getGeneralQuads()) {
MutableQuad mutable = MutableQuad.create(quad);
mutable.transform(matrix);
mutable.setCalculatedDiffuse();
BCModelHelper.appendBakeQuads(quads, mutable);
}
}
return quads;
}
}