Search in sources :

Example 1 with SimpleMultiLayerBakedModel

use of pl.asie.charset.lib.render.model.SimpleMultiLayerBakedModel in project Charset by CharsetMC.

the class ProxyClient method bakeModels.

@SubscribeEvent
@SideOnly(Side.CLIENT)
public void bakeModels(ModelBakeEvent event) {
    if (prismModel != null) {
        for (Orientation o : Orientation.values()) {
            ModelResourceLocation location = new ModelResourceLocation("charset:laser_prism", "orientation=" + o.name().toLowerCase());
            IBakedModel model = prismModel.bake(o.toTransformation(), DefaultVertexFormats.BLOCK, ModelLoader.defaultTextureGetter());
            event.getModelRegistry().putObject(location, model);
        }
    }
    // Patch jars to glow
    for (EnumFacing facing : EnumFacing.VALUES) {
        for (LaserColor color : LaserColor.VALUES) {
            if (color == LaserColor.NONE)
                continue;
            IBlockState state = CharsetLaser.blockJar.getDefaultState().withProperty(CharsetLaser.LASER_COLOR, color).withProperty(Properties.FACING, facing);
            ModelResourceLocation location = new ModelResourceLocation("charset:light_jar", "color=" + color.getName() + ",facing=" + facing.getName());
            IBakedModel model = event.getModelRegistry().getObject(location);
            VertexFormat format = new VertexFormat(DefaultVertexFormats.ITEM);
            format.addElement(DefaultVertexFormats.TEX_2S);
            if (model != null) {
                SimpleMultiLayerBakedModel result = new SimpleMultiLayerBakedModel(model);
                BlockRenderLayer layerPre = MinecraftForgeClient.getRenderLayer();
                for (BlockRenderLayer layer : BlockRenderLayer.values()) {
                    if (CharsetLaser.blockJar.canRenderInLayer(CharsetLaser.blockJar.getDefaultState(), layer)) {
                        ForgeHooksClient.setRenderLayer(layer);
                        for (int i = 0; i <= 6; i++) {
                            EnumFacing facingIn = (i < 6) ? EnumFacing.getFront(i) : null;
                            for (BakedQuad quadIn : model.getQuads(state, facingIn, 0)) {
                                result.addQuad(layer, facingIn, ModelTransformer.transform(quadIn, (quad, element, data) -> {
                                    if (quad.getTintIndex() == 1 && element == DefaultVertexFormats.TEX_2S) {
                                        return new float[] { 15f * 0x20 / 0xFFFF, 0, 0, 0 };
                                    }
                                    return data;
                                }, (bakedQuad -> {
                                    if (bakedQuad.getTintIndex() == 1) {
                                        return format;
                                    } else {
                                        return bakedQuad.getFormat();
                                    }
                                })));
                            }
                        }
                    }
                }
                ForgeHooksClient.setRenderLayer(layerPre);
                event.getModelRegistry().putObject(location, result);
            }
        }
    }
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) SimpleMultiLayerBakedModel(pl.asie.charset.lib.render.model.SimpleMultiLayerBakedModel) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) ModelBakeEvent(net.minecraftforge.client.event.ModelBakeEvent) ModelRegistryEvent(net.minecraftforge.client.event.ModelRegistryEvent) Properties(pl.asie.charset.lib.Properties) LaserRenderer(pl.asie.charset.module.optics.laser.system.LaserRenderer) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) MinecraftForgeClient(net.minecraftforge.client.MinecraftForgeClient) LaserTintHandler(pl.asie.charset.module.optics.laser.blocks.LaserTintHandler) DefaultVertexFormats(net.minecraft.client.renderer.vertex.DefaultVertexFormats) PixelOperationSprite(pl.asie.charset.lib.render.sprite.PixelOperationSprite) Side(net.minecraftforge.fml.relauncher.Side) CommandCharset(pl.asie.charset.lib.command.CommandCharset) RegistryUtils(pl.asie.charset.lib.utils.RegistryUtils) TextureStitchEvent(net.minecraftforge.client.event.TextureStitchEvent) ColorHandlerEvent(net.minecraftforge.client.event.ColorHandlerEvent) ModelLoader(net.minecraftforge.client.model.ModelLoader) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) ModelTransformer(pl.asie.charset.lib.render.model.ModelTransformer) VertexFormat(net.minecraft.client.renderer.vertex.VertexFormat) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) LaserColor(pl.asie.charset.api.laser.LaserColor) EnumFacing(net.minecraft.util.EnumFacing) SubCommandDebugLasersClient(pl.asie.charset.module.optics.laser.system.SubCommandDebugLasersClient) BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) BlockRenderLayer(net.minecraft.util.BlockRenderLayer) IModel(net.minecraftforge.client.model.IModel) RenderUtils(pl.asie.charset.lib.utils.RenderUtils) IBlockState(net.minecraft.block.state.IBlockState) MinecraftForge(net.minecraftforge.common.MinecraftForge) Orientation(pl.asie.charset.lib.utils.Orientation) ResourceLocation(net.minecraft.util.ResourceLocation) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) ForgeHooksClient(net.minecraftforge.client.ForgeHooksClient) SimpleMultiLayerBakedModel(pl.asie.charset.lib.render.model.SimpleMultiLayerBakedModel) IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) BlockRenderLayer(net.minecraft.util.BlockRenderLayer) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) Orientation(pl.asie.charset.lib.utils.Orientation) LaserColor(pl.asie.charset.api.laser.LaserColor) VertexFormat(net.minecraft.client.renderer.vertex.VertexFormat) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 2 with SimpleMultiLayerBakedModel

use of pl.asie.charset.lib.render.model.SimpleMultiLayerBakedModel in project Charset by CharsetMC.

the class CharsetStorageTanks method bakeModels.

@SubscribeEvent
@SideOnly(Side.CLIENT)
public void bakeModels(ModelBakeEvent event) {
    for (int i = 0; i < 12; i++) {
        IBlockState state = tankBlock.getDefaultState().withProperty(BlockTank.VARIANT, i);
        ModelResourceLocation location = new ModelResourceLocation("charset:fluidtank", "connections=" + i);
        IBakedModel model = event.getModelRegistry().getObject(location);
        if (model != null) {
            SimpleMultiLayerBakedModel result = new SimpleMultiLayerBakedModel(model);
            BlockRenderLayer targetLayer = (i >= 4 && i < 8) ? BlockRenderLayer.TRANSLUCENT : BlockRenderLayer.CUTOUT;
            for (int j = 0; j <= 6; j++) {
                EnumFacing facingIn = (j < 6) ? EnumFacing.getFront(j) : null;
                for (BakedQuad quadIn : model.getQuads(state, facingIn, 0)) {
                    result.addQuad(targetLayer, facingIn, quadIn);
                }
            }
            event.getModelRegistry().putObject(location, result);
        }
    }
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) SimpleMultiLayerBakedModel(pl.asie.charset.lib.render.model.SimpleMultiLayerBakedModel) IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) BlockRenderLayer(net.minecraft.util.BlockRenderLayer) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Aggregations

IBlockState (net.minecraft.block.state.IBlockState)2 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)2 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)2 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)2 BlockRenderLayer (net.minecraft.util.BlockRenderLayer)2 EnumFacing (net.minecraft.util.EnumFacing)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)2 SimpleMultiLayerBakedModel (pl.asie.charset.lib.render.model.SimpleMultiLayerBakedModel)2 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)1 DefaultVertexFormats (net.minecraft.client.renderer.vertex.DefaultVertexFormats)1 VertexFormat (net.minecraft.client.renderer.vertex.VertexFormat)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 ForgeHooksClient (net.minecraftforge.client.ForgeHooksClient)1 MinecraftForgeClient (net.minecraftforge.client.MinecraftForgeClient)1 ColorHandlerEvent (net.minecraftforge.client.event.ColorHandlerEvent)1 ModelBakeEvent (net.minecraftforge.client.event.ModelBakeEvent)1 ModelRegistryEvent (net.minecraftforge.client.event.ModelRegistryEvent)1 TextureStitchEvent (net.minecraftforge.client.event.TextureStitchEvent)1 IModel (net.minecraftforge.client.model.IModel)1