Fix cell models not being loaded. (#4528)
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package appeng.client.render;
|
||||
|
||||
import net.minecraft.client.renderer.model.IBakedModel;
|
||||
|
||||
/**
|
||||
* Helper to get a specific baked model class out of a chain of delegating baked
|
||||
* models.
|
||||
*/
|
||||
public final class BakedModelUnwrapper {
|
||||
|
||||
private BakedModelUnwrapper() {
|
||||
}
|
||||
|
||||
public static <T> T unwrap(IBakedModel model, Class<T> targetClass) {
|
||||
if (targetClass.isInstance(model)) {
|
||||
return targetClass.cast(model);
|
||||
}
|
||||
|
||||
if (model instanceof DelegateBakedModel) {
|
||||
model = ((DelegateBakedModel) model).getBaseModel();
|
||||
if (targetClass.isInstance(model)) {
|
||||
return targetClass.cast(model);
|
||||
} else {
|
||||
return unwrap(model, targetClass);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -50,14 +50,16 @@ import net.minecraftforge.client.model.pipeline.BakedQuadBuilder;
|
||||
import net.minecraftforge.client.model.pipeline.IVertexConsumer;
|
||||
import net.minecraftforge.client.model.pipeline.QuadGatheringTransformer;
|
||||
|
||||
import appeng.client.render.DelegateBakedModel;
|
||||
import appeng.client.render.FacingToRotation;
|
||||
|
||||
public class AutoRotatingBakedModel implements IBakedModel {
|
||||
public class AutoRotatingBakedModel extends DelegateBakedModel {
|
||||
|
||||
private final IBakedModel parent;
|
||||
private final LoadingCache<AutoRotatingCacheKey, List<BakedQuad>> quadCache;
|
||||
|
||||
public AutoRotatingBakedModel(IBakedModel parent) {
|
||||
super(parent);
|
||||
this.parent = parent;
|
||||
// 6 (DUNSWE) * 6 (DUNSWE) * 7 (DUNSWE + null) = 252
|
||||
this.quadCache = CacheBuilder.newBuilder().maximumSize(252)
|
||||
@@ -113,42 +115,6 @@ public class AutoRotatingBakedModel implements IBakedModel {
|
||||
return rotated;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAmbientOcclusion() {
|
||||
return this.parent.isAmbientOcclusion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGui3d() {
|
||||
return this.parent.isGui3d();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean func_230044_c_() {
|
||||
return parent.func_230044_c_();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBuiltInRenderer() {
|
||||
return this.parent.isBuiltInRenderer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureAtlasSprite getParticleTexture() {
|
||||
return this.parent.getParticleTexture();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public ItemCameraTransforms getItemCameraTransforms() {
|
||||
return parent.getItemCameraTransforms();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemOverrideList getOverrides() {
|
||||
return parent.getOverrides();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand) {
|
||||
return getQuads(state, side, rand, EmptyModelData.INSTANCE);
|
||||
|
||||
@@ -108,7 +108,7 @@ public class DriveBakedModel extends DelegateBakedModel {
|
||||
}
|
||||
|
||||
// Determine which drive chassis to show based on the used cell
|
||||
private IBakedModel getCellChassisModel(Item cell) {
|
||||
public IBakedModel getCellChassisModel(Item cell) {
|
||||
if (cell == null) {
|
||||
return bakedCells.get(Items.AIR);
|
||||
}
|
||||
|
||||
@@ -41,15 +41,15 @@ import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.client.model.data.EmptyModelData;
|
||||
import net.minecraftforge.client.model.data.IModelData;
|
||||
|
||||
import appeng.api.client.ICellModelRegistry;
|
||||
import appeng.block.storage.DriveSlotsState;
|
||||
import appeng.client.render.BakedModelUnwrapper;
|
||||
import appeng.client.render.DelegateBakedModel;
|
||||
import appeng.client.render.FacingToRotation;
|
||||
import appeng.client.render.model.DriveBakedModel;
|
||||
import appeng.core.Api;
|
||||
import appeng.tile.storage.ChestTileEntity;
|
||||
|
||||
@@ -59,8 +59,6 @@ import appeng.tile.storage.ChestTileEntity;
|
||||
*/
|
||||
public class ChestTileEntityRenderer extends TileEntityRenderer<ChestTileEntity> {
|
||||
|
||||
private final ICellModelRegistry cellModelRegistry = Api.instance().client().cells();
|
||||
|
||||
private final ModelManager modelManager;
|
||||
|
||||
private final BlockModelRenderer blockRenderer;
|
||||
@@ -88,12 +86,13 @@ public class ChestTileEntityRenderer extends TileEntityRenderer<ChestTileEntity>
|
||||
return; // No cell inserted into chest
|
||||
}
|
||||
|
||||
ResourceLocation cellModelLocation = cellModelRegistry.model(cellItem);
|
||||
if (cellModelLocation == null) {
|
||||
cellModelLocation = cellModelRegistry.getDefaultModel();
|
||||
// Try to get the right cell chassis model from the drive model since it already
|
||||
// loads them all
|
||||
DriveBakedModel driveModel = getDriveModel();
|
||||
if (driveModel == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
IBakedModel model = modelManager.getModel(cellModelLocation);
|
||||
IBakedModel cellModel = driveModel.getCellChassisModel(cellItem);
|
||||
|
||||
matrices.push();
|
||||
matrices.translate(0.5, 0.5, 0.5);
|
||||
@@ -109,7 +108,7 @@ public class ChestTileEntityRenderer extends TileEntityRenderer<ChestTileEntity>
|
||||
IVertexBuilder buffer = buffers.getBuffer(RenderType.getCutout());
|
||||
// We "fake" the position here to make it use the light-value in front of the
|
||||
// drive
|
||||
FaceRotatingModel rotatedModel = new FaceRotatingModel(model, rotation);
|
||||
FaceRotatingModel rotatedModel = new FaceRotatingModel(cellModel, rotation);
|
||||
blockRenderer.renderModel(world, rotatedModel, chest.getBlockState(), chest.getPos(), matrices, buffer, false,
|
||||
new Random(), 0L, combinedOverlay, EmptyModelData.INSTANCE);
|
||||
|
||||
@@ -119,6 +118,12 @@ public class ChestTileEntityRenderer extends TileEntityRenderer<ChestTileEntity>
|
||||
matrices.pop();
|
||||
}
|
||||
|
||||
private DriveBakedModel getDriveModel() {
|
||||
IBakedModel driveModel = modelManager.getBlockModelShapes()
|
||||
.getModel(Api.instance().definitions().blocks().drive().block().getDefaultState());
|
||||
return BakedModelUnwrapper.unwrap(driveModel, DriveBakedModel.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* The actual vertex data will be transformed using the matrix stack, but the
|
||||
* faces will not be correctly rotated so the incorrect lighting data would be
|
||||
|
||||
Reference in New Issue
Block a user