136 lines
4.5 KiB
Java
136 lines
4.5 KiB
Java
/*
|
|
* This file is part of Applied Energistics 2.
|
|
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
|
|
*
|
|
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
|
*/
|
|
|
|
package appeng.parts.automation;
|
|
|
|
import java.util.*;
|
|
import java.util.function.Supplier;
|
|
|
|
import javax.annotation.Nullable;
|
|
|
|
import net.fabricmc.fabric.api.renderer.v1.Renderer;
|
|
import net.fabricmc.fabric.api.renderer.v1.RendererAccess;
|
|
import net.fabricmc.fabric.api.renderer.v1.mesh.Mesh;
|
|
import net.fabricmc.fabric.api.renderer.v1.mesh.MeshBuilder;
|
|
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
|
|
import net.minecraft.block.BlockState;
|
|
import net.minecraft.client.render.model.BakedModel;
|
|
import net.minecraft.client.render.model.BakedQuad;
|
|
import net.minecraft.client.render.model.json.ModelOverrideList;
|
|
import net.minecraft.client.render.model.json.ModelTransformation;
|
|
import net.minecraft.client.texture.Sprite;
|
|
import net.minecraft.util.math.BlockPos;
|
|
import net.minecraft.util.math.Direction;
|
|
import net.minecraft.world.BlockRenderView;
|
|
|
|
import appeng.api.parts.IDynamicPartBakedModel;
|
|
import appeng.client.render.cablebus.CubeBuilder;
|
|
|
|
/**
|
|
* Built-in model for annihilation planes that supports connected textures.
|
|
*/
|
|
public class PlaneBakedModel implements BakedModel, IDynamicPartBakedModel {
|
|
|
|
private static final PlaneConnections DEFAULT_PERMUTATION = PlaneConnections.of(false, false, false, false);
|
|
|
|
private final Sprite frontTexture;
|
|
|
|
private final Map<PlaneConnections, Mesh> meshes;
|
|
|
|
PlaneBakedModel(Sprite frontTexture, Sprite sidesTexture, Sprite backTexture) {
|
|
this.frontTexture = frontTexture;
|
|
|
|
Renderer renderer = RendererAccess.INSTANCE.getRenderer();
|
|
|
|
meshes = new HashMap<>(PlaneConnections.PERMUTATIONS.size());
|
|
// Create all possible permutations (16)
|
|
for (PlaneConnections permutation : PlaneConnections.PERMUTATIONS) {
|
|
|
|
MeshBuilder meshBuilder = renderer.meshBuilder();
|
|
|
|
CubeBuilder builder = new CubeBuilder(meshBuilder.getEmitter());
|
|
|
|
builder.setTextures(sidesTexture, sidesTexture, frontTexture, backTexture, sidesTexture, sidesTexture);
|
|
|
|
// Keep the orientation of the X axis in mind here. When looking at a quad
|
|
// facing north from the front,
|
|
// The X-axis points left
|
|
int minX = permutation.isRight() ? 0 : 1;
|
|
int maxX = permutation.isLeft() ? 16 : 15;
|
|
int minY = permutation.isDown() ? 0 : 1;
|
|
int maxY = permutation.isUp() ? 16 : 15;
|
|
|
|
builder.addCube(minX, minY, 0, maxX, maxY, 1);
|
|
|
|
this.meshes.put(permutation, meshBuilder.build());
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void emitQuads(BlockRenderView blockView, BlockState state, BlockPos pos, Supplier<Random> randomSupplier,
|
|
RenderContext context, Direction partSide, @Nullable Object modelData) {
|
|
PlaneConnections connections = DEFAULT_PERMUTATION;
|
|
|
|
if (modelData instanceof PlaneConnections) {
|
|
connections = (PlaneConnections) modelData;
|
|
}
|
|
|
|
context.meshConsumer().accept(this.meshes.get(connections));
|
|
}
|
|
|
|
@Override
|
|
public ModelTransformation getTransformation() {
|
|
return ModelTransformation.NONE;
|
|
}
|
|
|
|
@Override
|
|
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand) {
|
|
return Collections.emptyList();
|
|
}
|
|
|
|
@Override
|
|
public boolean useAmbientOcclusion() {
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public boolean hasDepth() {
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public boolean isSideLit() {
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public boolean isBuiltin() {
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public Sprite getSprite() {
|
|
return this.frontTexture;
|
|
}
|
|
|
|
@Override
|
|
public ModelOverrideList getOverrides() {
|
|
return ModelOverrideList.EMPTY;
|
|
}
|
|
}
|