Search in sources :

Example 1 with ModelFactory

use of gregtech.client.model.ModelFactory in project GregTech by GregTechCEu.

the class OreBakedModel method getQuads.

@Override
@Nonnull
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand) {
    if (state != null) {
        BlockOre ore = (BlockOre) state.getBlock();
        StoneType stoneType = state.getValue(ore.STONE_TYPE);
        MaterialIconSet materialIconSet = ore.material.getMaterialIconSet();
        TextureAtlasSprite textureAtlasSprite = stoneTypeModels.computeIfAbsent(stoneType, type -> Minecraft.getMinecraft().blockRenderDispatcher.getModelForState(type.stone.get()).getParticleTexture());
        particle.set(textureAtlasSprite);
        if (model == null) {
            model = new ModelFactory(ModelFactory.ModelTemplate.CUBE_2_LAYER_ALL_TINT_INDEX).bake();
        }
        BakedQuad bakedQuad = cacheBottom.get(stoneType, side);
        if (side == null)
            return Collections.emptyList();
        if (bakedQuad == null) {
            cacheBottom.put(stoneType, side, bakedQuad = new BakedQuadRetextured(model.getQuads(state, side, rand).get(0), textureAtlasSprite));
        }
        BakedQuad[] bakedQuads = cacheTop.get(materialIconSet, side);
        if (bakedQuads == null) {
            bakedQuads = new BakedQuad[2];
            bakedQuads[0] = new BakedQuadRetextured(model.getQuads(state, side, rand).get(1), ModelLoader.defaultTextureGetter().apply(MaterialIconType.ore.getBlockPath(materialIconSet)));
            bakedQuads[1] = CustomTexture.rebake(15, 15, bakedQuads[0]);
            cacheTop.put(materialIconSet, side, bakedQuads);
        }
        BlockRenderLayer layer = MinecraftForgeClient.getRenderLayer();
        boolean hasEmissive = ore.material.getProperty(PropertyKey.ORE).isEmissive();
        boolean isEmissiveLayer = hasEmissive && (layer == BloomEffectUtil.getRealBloomLayer() || layer == null);
        List<BakedQuad> quads = new ArrayList<>();
        if (!hasEmissive || !isEmissiveLayer || layer == null) {
            quads.add(bakedQuad);
        }
        if (hasEmissive && isEmissiveLayer) {
            quads.add(bakedQuads[1]);
        } else {
            quads.add(bakedQuads[0]);
        }
        return quads;
    } else {
        List<BakedQuad> quads = new ArrayList<>();
        ItemStack stack = OreItemOverride.INSTANCE.stack.get();
        if (!stack.isEmpty()) {
            BlockOre ore = (BlockOre) ((ItemBlock) stack.getItem()).getBlock();
            IBlockState oreState = ore.getDefaultState().withProperty(ore.STONE_TYPE, ore.STONE_TYPE.getAllowedValues().get(stack.getMetadata()));
            for (EnumFacing face : EnumFacing.VALUES) {
                quads.addAll(getQuads(oreState, face, rand));
            }
        }
        return quads;
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) MaterialIconSet(gregtech.api.unification.material.info.MaterialIconSet) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) StoneType(gregtech.api.unification.ore.StoneType) EnumFacing(net.minecraft.util.EnumFacing) BlockOre(gregtech.common.blocks.BlockOre) ModelFactory(gregtech.client.model.ModelFactory) BlockRenderLayer(net.minecraft.util.BlockRenderLayer) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Aggregations

MaterialIconSet (gregtech.api.unification.material.info.MaterialIconSet)1 StoneType (gregtech.api.unification.ore.StoneType)1 ModelFactory (gregtech.client.model.ModelFactory)1 BlockOre (gregtech.common.blocks.BlockOre)1 Nonnull (javax.annotation.Nonnull)1 IBlockState (net.minecraft.block.state.IBlockState)1 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)1 ItemStack (net.minecraft.item.ItemStack)1 BlockRenderLayer (net.minecraft.util.BlockRenderLayer)1 EnumFacing (net.minecraft.util.EnumFacing)1