pick 97420a31d The big reformat of 2020
This commit is contained in:
@@ -18,12 +18,14 @@
|
||||
|
||||
package appeng.client.render.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import appeng.api.definitions.IItems;
|
||||
import appeng.block.storage.DriveSlotCellType;
|
||||
import appeng.block.storage.DriveSlotsState;
|
||||
import appeng.client.render.DelegateBakedModel;
|
||||
import appeng.core.Api;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.renderer.Matrix4f;
|
||||
import net.minecraft.client.renderer.model.BakedQuad;
|
||||
@@ -34,98 +36,92 @@ import net.minecraft.util.Direction;
|
||||
import net.minecraftforge.client.model.data.IModelData;
|
||||
import net.minecraftforge.client.model.pipeline.BakedQuadBuilder;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import appeng.api.definitions.IItems;
|
||||
import appeng.block.storage.DriveSlotCellType;
|
||||
import appeng.block.storage.DriveSlotsState;
|
||||
import appeng.client.render.DelegateBakedModel;
|
||||
import appeng.core.Api;
|
||||
|
||||
public class DriveBakedModel extends DelegateBakedModel {
|
||||
private final Map<DriveSlotCellType, IBakedModel> bakedCells;
|
||||
|
||||
public class DriveBakedModel extends DelegateBakedModel
|
||||
{
|
||||
private final Map<DriveSlotCellType, IBakedModel> bakedCells;
|
||||
public DriveBakedModel(IBakedModel bakedBase, Map<DriveSlotCellType, IBakedModel> bakedCells) {
|
||||
super(bakedBase);
|
||||
this.bakedCells = bakedCells;
|
||||
}
|
||||
|
||||
public DriveBakedModel( IBakedModel bakedBase, Map<DriveSlotCellType, IBakedModel> bakedCells )
|
||||
{
|
||||
super(bakedBase);
|
||||
this.bakedCells = bakedCells;
|
||||
}
|
||||
@Nonnull
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @Nonnull Random rand,
|
||||
@Nonnull IModelData extraData) {
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @Nonnull Random rand, @Nonnull IModelData extraData) {
|
||||
List<BakedQuad> result = new ArrayList<>(super.getQuads(state, side, rand, extraData));
|
||||
|
||||
List<BakedQuad> result = new ArrayList<>(super.getQuads(state, side, rand, extraData));
|
||||
if (!(extraData instanceof DriveModelData)) {
|
||||
return result;
|
||||
}
|
||||
DriveModelData driveModelData = (DriveModelData) extraData;
|
||||
|
||||
if (!(extraData instanceof DriveModelData)) {
|
||||
return result;
|
||||
}
|
||||
DriveModelData driveModelData = (DriveModelData) extraData;
|
||||
DriveSlotsState slotsState = driveModelData.getSlotsState();
|
||||
|
||||
DriveSlotsState slotsState = driveModelData.getSlotsState();
|
||||
if (side == null && slotsState != null) {
|
||||
for (int row = 0; row < 5; row++) {
|
||||
for (int col = 0; col < 2; col++) {
|
||||
Matrix4f transform = new Matrix4f();
|
||||
|
||||
if( side == null && slotsState != null )
|
||||
{
|
||||
for( int row = 0; row < 5; row++ )
|
||||
{
|
||||
for( int col = 0; col < 2; col++ )
|
||||
{
|
||||
Matrix4f transform = new Matrix4f();
|
||||
// Position this drive model copy at the correct slot. The transform is based on
|
||||
// the
|
||||
// cell-model being in slot 0,0 at the top left of the drive.
|
||||
float xOffset = -col * 7 / 16.0f;
|
||||
float yOffset = -row * 3 / 16.0f;
|
||||
transform.setTranslation(xOffset, yOffset, 0);
|
||||
|
||||
// Position this drive model copy at the correct slot. The transform is based on the
|
||||
// cell-model being in slot 0,0 at the top left of the drive.
|
||||
float xOffset = -col * 7 / 16.0f;
|
||||
float yOffset = -row * 3 / 16.0f;
|
||||
transform.setTranslation( xOffset, yOffset, 0 );
|
||||
int slot = row * 2 + col;
|
||||
|
||||
int slot = row * 2 + col;
|
||||
// Add the drive chassis
|
||||
Item cell = slotsState.getCell(slot);
|
||||
IBakedModel cellChassisModel = getCellChassisModel(cell);
|
||||
addModel(state, rand, extraData, result, cellChassisModel, transform);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add the drive chassis
|
||||
Item cell = slotsState.getCell(slot);
|
||||
IBakedModel cellChassisModel = getCellChassisModel(cell);
|
||||
addModel(state, rand, extraData, result, cellChassisModel, transform);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public boolean isAmbientOcclusion() {
|
||||
// We have faces inside the chassis that are facing east, but should not receive
|
||||
// ambient occlusion from the east-side, but sadly this cannot be fine-tuned on
|
||||
// a
|
||||
// face-by-face basis.
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAmbientOcclusion() {
|
||||
// We have faces inside the chassis that are facing east, but should not receive
|
||||
// ambient occlusion from the east-side, but sadly this cannot be fine-tuned on a
|
||||
// face-by-face basis.
|
||||
return false;
|
||||
}
|
||||
// Determine which drive chassis to show based on the used cell
|
||||
private IBakedModel getCellChassisModel(Item cell) {
|
||||
IItems items = Api.INSTANCE.definitions().items();
|
||||
if (cell == null) {
|
||||
return bakedCells.get(DriveSlotCellType.EMPTY);
|
||||
} else if (items.fluidCell1k().item() == cell || items.fluidCell4k().item() == cell
|
||||
|| items.fluidCell16k().item() == cell || items.fluidCell64k().item() == cell) {
|
||||
return bakedCells.get(DriveSlotCellType.FLUID);
|
||||
} else {
|
||||
// Fall back to an item model
|
||||
return bakedCells.get(DriveSlotCellType.ITEM);
|
||||
}
|
||||
}
|
||||
|
||||
// Determine which drive chassis to show based on the used cell
|
||||
private IBakedModel getCellChassisModel(Item cell) {
|
||||
IItems items = Api.INSTANCE.definitions().items();
|
||||
if (cell == null) {
|
||||
return bakedCells.get(DriveSlotCellType.EMPTY);
|
||||
} else if (items.fluidCell1k().item() == cell
|
||||
|| items.fluidCell4k().item() == cell
|
||||
|| items.fluidCell16k().item() == cell
|
||||
|| items.fluidCell64k().item() == cell) {
|
||||
return bakedCells.get(DriveSlotCellType.FLUID);
|
||||
} else {
|
||||
// Fall back to an item model
|
||||
return bakedCells.get(DriveSlotCellType.ITEM);
|
||||
}
|
||||
}
|
||||
|
||||
private static void addModel(@Nullable BlockState state, @Nonnull Random rand, @Nonnull IModelData extraData, List<BakedQuad> result, IBakedModel bakedCell, Matrix4f transform) {
|
||||
MatrixVertexTransformer transformer = new MatrixVertexTransformer( transform );
|
||||
for( BakedQuad bakedQuad : bakedCell.getQuads( state, null, rand, extraData ) )
|
||||
{
|
||||
BakedQuadBuilder builder = new BakedQuadBuilder();
|
||||
transformer.setParent( builder );
|
||||
transformer.setVertexFormat( builder.getVertexFormat() );
|
||||
bakedQuad.pipe( transformer );
|
||||
result.add( builder.build() );
|
||||
}
|
||||
}
|
||||
private static void addModel(@Nullable BlockState state, @Nonnull Random rand, @Nonnull IModelData extraData,
|
||||
List<BakedQuad> result, IBakedModel bakedCell, Matrix4f transform) {
|
||||
MatrixVertexTransformer transformer = new MatrixVertexTransformer(transform);
|
||||
for (BakedQuad bakedQuad : bakedCell.getQuads(state, null, rand, extraData)) {
|
||||
BakedQuadBuilder builder = new BakedQuadBuilder();
|
||||
transformer.setParent(builder);
|
||||
transformer.setVertexFormat(builder.getVertexFormat());
|
||||
bakedQuad.pipe(transformer);
|
||||
result.add(builder.build());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user