Search in sources :

Example 1 with ModelBakeEvent

use of net.minecraftforge.client.event.ModelBakeEvent 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 ModelBakeEvent

use of net.minecraftforge.client.event.ModelBakeEvent in project MinecraftForge by MinecraftForge.

the class ForgeHooksClient method onModelBake.

public static void onModelBake(ModelManager modelManager, IRegistry<ModelResourceLocation, IBakedModel> modelRegistry, ModelLoader modelLoader) {
    MinecraftForge.EVENT_BUS.post(new ModelBakeEvent(modelManager, modelRegistry, modelLoader));
    modelLoader.onPostBakeEvent(modelRegistry);
}
Also used : ModelBakeEvent(net.minecraftforge.client.event.ModelBakeEvent)

Example 3 with ModelBakeEvent

use of net.minecraftforge.client.event.ModelBakeEvent in project Binnie by ForestryMC.

the class ModuleWood method onBakedEvent.

@SubscribeEvent
@SideOnly(Side.CLIENT)
public void onBakedEvent(ModelBakeEvent e) {
    // Find all ExtraTrees saplings
    List<ModelResourceLocation> models = e.getModelRegistry().getKeys().stream().filter(mrl -> mrl.getResourceDomain().startsWith(Constants.EXTRA_TREES_MOD_ID)).filter(mrl -> mrl.getResourcePath().startsWith("germlings")).collect(Collectors.toList());
    // Replace model
    Map<String, ETTreeDefinition> map = Arrays.stream(ETTreeDefinition.values()).collect(Collectors.toMap(o -> o.name().toLowerCase(), o -> o));
    models.forEach(model -> {
        String species = model.getVariant().split("=")[1];
        ETTreeDefinition treeSpecies = map.get(species);
        int primaryColor = treeSpecies.getLeafColor().getRGB();
        int secondaryColor = treeSpecies.getWoodColor().getRGB();
        IBakedModel bakedModel = e.getModelRegistry().getObject(model);
        if (bakedModel == null) {
            return;
        }
        e.getModelRegistry().putObject(model, new DoublePassBakedModel(bakedModel, primaryColor, secondaryColor));
    });
}
Also used : IWoodType(forestry.api.arboriculture.IWoodType) ModelBakeEvent(net.minecraftforge.client.event.ModelBakeEvent) Arrays(java.util.Arrays) ForestryModule(forestry.api.modules.ForestryModule) IWoodTyped(forestry.arboriculture.IWoodTyped) ILiquidDefinition(binnie.core.liquid.ILiquidDefinition) EnumETLog(binnie.extratrees.wood.EnumETLog) EnumShrubLog(binnie.extratrees.wood.EnumShrubLog) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) PropertyETType(binnie.extratrees.blocks.property.PropertyETType) BlockETSlab(binnie.extratrees.blocks.wood.BlockETSlab) ExtraTrees(binnie.extratrees.ExtraTrees) Block(net.minecraft.block.Block) ModuleManager(binnie.core.modules.ModuleManager) OreDictionary(net.minecraftforge.oredict.OreDictionary) Side(net.minecraftforge.fml.relauncher.Side) WoodManager(binnie.extratrees.wood.WoodManager) Constants(binnie.core.Constants) FruitSprite(binnie.extratrees.genetics.fruits.FruitSprite) Map(java.util.Map) BlockETDoor(binnie.extratrees.blocks.wood.BlockETDoor) RecipeUtil(binnie.core.util.RecipeUtil) WoodBlockKind(forestry.api.arboriculture.WoodBlockKind) AlleleRegisterEvent(forestry.api.genetics.AlleleRegisterEvent) ITreeRoot(forestry.api.arboriculture.ITreeRoot) WoodAccess(forestry.arboriculture.WoodAccess) ItemMetadata(binnie.core.block.ItemMetadata) BlockForestryFenceGate(forestry.arboriculture.blocks.BlockForestryFenceGate) ModuleArboriculture(forestry.arboriculture.ModuleArboriculture) OreDictUtil(forestry.core.utils.OreDictUtil) BlockETDefaultLeaves(binnie.extratrees.blocks.BlockETDefaultLeaves) Collectors(java.util.stream.Collectors) ModuleUtils(binnie.core.util.ModuleUtils) BlockMultiFence(binnie.extratrees.blocks.decor.BlockMultiFence) DoublePassBakedModel(binnie.core.models.DoublePassBakedModel) List(java.util.List) BlockForestryStairs(forestry.arboriculture.blocks.BlockForestryStairs) BinnieCore(binnie.core.BinnieCore) BlockETDecorativeLeaves(binnie.extratrees.blocks.BlockETDecorativeLeaves) ItemETSlab(binnie.extratrees.blocks.wood.ItemETSlab) FMLInterModComms(net.minecraftforge.fml.common.event.FMLInterModComms) EnumVanillaWoodType(forestry.api.arboriculture.EnumVanillaWoodType) AlleleETFruitDefinition(binnie.extratrees.genetics.AlleleETFruitDefinition) FluidStack(net.minecraftforge.fluids.FluidStack) VanillaPlanks(binnie.extratrees.wood.planks.VanillaPlanks) BlockETFence(binnie.extratrees.blocks.wood.BlockETFence) ItemBlockETDecorativeLeaves(binnie.extratrees.items.ItemBlockETDecorativeLeaves) IButterflyRoot(forestry.api.lepidopterology.IButterflyRoot) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) ExtraTreesModuleUIDs(binnie.core.modules.ExtraTreesModuleUIDs) ItemBlockETWood(binnie.extratrees.blocks.wood.ItemBlockETWood) RecipeManagers(forestry.api.recipes.RecipeManagers) IPlankType(binnie.extratrees.wood.planks.IPlankType) BlockETLog(binnie.extratrees.blocks.wood.BlockETLog) MultiFenceRecipeSize(binnie.extratrees.blocks.decor.MultiFenceRecipeSize) HashMap(java.util.HashMap) GameRegistry(net.minecraftforge.fml.common.registry.GameRegistry) MultiFenceRecipeEmbedded(binnie.extratrees.blocks.decor.MultiFenceRecipeEmbedded) ETTreeDefinition(binnie.extratrees.genetics.ETTreeDefinition) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) ExtraTreePlanks(binnie.extratrees.wood.planks.ExtraTreePlanks) Minecraft(net.minecraft.client.Minecraft) TextureStitchEvent(net.minecraftforge.client.event.TextureStitchEvent) CarpentryManager(binnie.extratrees.api.CarpentryManager) ItemBlockETWoodDoor(binnie.extratrees.blocks.wood.ItemBlockETWoodDoor) ButterflySpecies(binnie.extratrees.genetics.ButterflySpecies) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) ForestryPlanks(binnie.extratrees.wood.planks.ForestryPlanks) Nullable(javax.annotation.Nullable) ItemBlockLeaves(forestry.arboriculture.items.ItemBlockLeaves) IAlleleFruit(forestry.api.arboriculture.IAlleleFruit) Items(net.minecraft.init.Items) ExtraTreeLiquid(binnie.extratrees.items.ExtraTreeLiquid) TextureMap(net.minecraft.client.renderer.texture.TextureMap) ForestryModuleUids(forestry.modules.ForestryModuleUids) MultiFenceRecipeSolid(binnie.extratrees.blocks.decor.MultiFenceRecipeSolid) BlockShrubLog(binnie.extratrees.blocks.wood.BlockShrubLog) TreeManager(forestry.api.arboriculture.TreeManager) Mods(binnie.core.Mods) AlleleSpeciesRegisterEvent(forestry.api.genetics.AlleleSpeciesRegisterEvent) IWoodAccess(forestry.api.arboriculture.IWoodAccess) ExtraTreeMutation(binnie.extratrees.genetics.ExtraTreeMutation) IBlockState(net.minecraft.block.state.IBlockState) MinecraftForge(net.minecraftforge.common.MinecraftForge) Fluids(forestry.core.fluids.Fluids) ForgeRegistries(net.minecraftforge.fml.common.registry.ForgeRegistries) ResourceLocation(net.minecraft.util.ResourceLocation) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) BlankModule(binnie.core.modules.BlankModule) Preconditions(com.google.common.base.Preconditions) BlockETPlank(binnie.extratrees.blocks.wood.BlockETPlank) ETTreeDefinition(binnie.extratrees.genetics.ETTreeDefinition) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) DoublePassBakedModel(binnie.core.models.DoublePassBakedModel) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Aggregations

ModelBakeEvent (net.minecraftforge.client.event.ModelBakeEvent)3 BinnieCore (binnie.core.BinnieCore)1 Constants (binnie.core.Constants)1 Mods (binnie.core.Mods)1 ItemMetadata (binnie.core.block.ItemMetadata)1 ILiquidDefinition (binnie.core.liquid.ILiquidDefinition)1 DoublePassBakedModel (binnie.core.models.DoublePassBakedModel)1 BlankModule (binnie.core.modules.BlankModule)1 ExtraTreesModuleUIDs (binnie.core.modules.ExtraTreesModuleUIDs)1 ModuleManager (binnie.core.modules.ModuleManager)1 ModuleUtils (binnie.core.util.ModuleUtils)1 RecipeUtil (binnie.core.util.RecipeUtil)1 ExtraTrees (binnie.extratrees.ExtraTrees)1 CarpentryManager (binnie.extratrees.api.CarpentryManager)1 BlockETDecorativeLeaves (binnie.extratrees.blocks.BlockETDecorativeLeaves)1 BlockETDefaultLeaves (binnie.extratrees.blocks.BlockETDefaultLeaves)1 BlockMultiFence (binnie.extratrees.blocks.decor.BlockMultiFence)1 MultiFenceRecipeEmbedded (binnie.extratrees.blocks.decor.MultiFenceRecipeEmbedded)1 MultiFenceRecipeSize (binnie.extratrees.blocks.decor.MultiFenceRecipeSize)1 MultiFenceRecipeSolid (binnie.extratrees.blocks.decor.MultiFenceRecipeSolid)1