-
Notifications
You must be signed in to change notification settings - Fork 497
/
FacadePluggableModel.java
73 lines (59 loc) · 2.87 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
package buildcraft.transport.render;
import java.util.List;
import javax.vecmath.Matrix4f;
import com.google.common.collect.Lists;
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.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.IPipe;
import buildcraft.api.transport.pluggable.*;
import buildcraft.core.lib.render.BCModelHelper;
import buildcraft.core.lib.render.BakedModelHolder;
import buildcraft.core.lib.render.MutableQuad;
import buildcraft.core.lib.utils.MatrixUtils;
public final class FacadePluggableModel extends BakedModelHolder implements IPipePluggableStaticRenderer {
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");
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);
}
@Override
public List<BakedQuad> bakeCutout(IPipeRenderState render, IPipePluggableState pluggableState, IPipe pipe, PipePluggable pluggable,
EnumFacing face) {
List<BakedQuad> quads = Lists.newArrayList();
IFacadePluggable facade = (IFacadePluggable) pluggable;
// 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(facade
.getCurrentState());
IModel model;
if (facade.isHollow()) {
model = modelHollow();
} else {
model = modelFilled();
}
if (model != null) {
IFlexibleBakedModel baked = model.bake(ModelRotation.X0_Y0, DefaultVertexFormats.BLOCK, singleTextureFunction(sprite));
Matrix4f matrix = MatrixUtils.rotateTowardsFace(face);
for (BakedQuad quad : baked.getGeneralQuads()) {
MutableQuad mutable = MutableQuad.create(quad);
mutable.transform(matrix);
mutable.setCalculatedDiffuse();
BCModelHelper.appendBakeQuads(quads, mutable);
}
}
return quads;
}
}