Search in sources :

Example 16 with IBakedModel

use of net.minecraft.client.renderer.block.model.IBakedModel 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 17 with IBakedModel

use of net.minecraft.client.renderer.block.model.IBakedModel in project Charset by CharsetMC.

the class CharsetCraftingCauldron method onModelBake.

@SubscribeEvent(priority = EventPriority.LOW)
@SideOnly(Side.CLIENT)
public void onModelBake(ModelBakeEvent event) {
    IBakedModel l0 = event.getModelRegistry().getObject(new ModelResourceLocation("minecraft:cauldron#level=0"));
    if (l0 != null) {
        event.getModelRegistry().putObject(new ModelResourceLocation("minecraft:cauldron#level=1"), l0);
        event.getModelRegistry().putObject(new ModelResourceLocation("minecraft:cauldron#level=2"), l0);
        event.getModelRegistry().putObject(new ModelResourceLocation("minecraft:cauldron#level=3"), l0);
    }
}
Also used : IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 18 with IBakedModel

use of net.minecraft.client.renderer.block.model.IBakedModel in project Charset by CharsetMC.

the class RendererGate method bake.

@Override
public IBakedModel bake(PartGate gate, boolean isItem, BlockRenderLayer blockRenderLayer) {
    SimpleBakedModel result = new SimpleBakedModel(this);
    ModelStateComposition transform = new ModelStateComposition(new TRSRTransformation(ROTATIONS_SIDE[gate.getSide().ordinal()]), new TRSRTransformation(ROTATIONS_TOP[gate.getTop().ordinal()]));
    if (gate.mirrored) {
        transform = new ModelStateComposition(transform, new TRSRTransformation(null, null, new Vector3f(-1.0f, 1.0f, 1.0f), null));
    }
    GateLogic logic = gate.logic;
    GateRenderDefinitions.Definition definition = GateRenderDefinitions.INSTANCE.getGateDefinition(SimpleLogicGates.getId(logic));
    if (definition == null) {
        result.addModel(ModelLoaderRegistry.getMissingModel().bake(transform, DefaultVertexFormats.BLOCK, ModelLoader.defaultTextureGetter()));
        return result;
    }
    GateRenderDefinitions.BaseDefinition base = GateRenderDefinitions.INSTANCE.base;
    IModel model = definition.getModel(gate.getModelName());
    if (model != null) {
        result.addModel(model.bake(transform, DefaultVertexFormats.BLOCK, ModelLoader.defaultTextureGetter()));
    }
    IModel layerModel = definition.getModel("layer");
    int i = 0;
    for (GateRenderDefinitions.Layer layer : definition.layers) {
        GateLogic.State state = gate.logic.getLayerState(i++);
        if (state == GateLogic.State.NO_RENDER) {
            continue;
        }
        IModelState layerTransform = transform;
        if (layer.height != 0) {
            layerTransform = new ModelStateComposition(new TRSRTransformation(new Vector3f(0, (float) layer.height / 16f, 0), null, null, null), transform);
        }
        if ("color".equals(layer.type) && layer.texture != null) {
            model = layerModels.get(layer.texture);
            if (model == null) {
                model = layerModel.retexture(ImmutableMap.of("layer", layer.texture));
                layerModels.put(layer.texture, model);
            }
            IBakedModel bakedModel = model.bake(layerTransform, DefaultVertexFormats.BLOCK, ModelLoader.defaultTextureGetter());
            int color = state == GateLogic.State.ON ? base.colorMul.get("on") : (state == GateLogic.State.OFF ? base.colorMul.get("off") : base.colorMul.get("disabled"));
            result.addModel(ModelTransformer.transform(bakedModel, SimpleLogicGates.blockGate.getDefaultState(), 0, ((quad, element, data) -> {
                if (element.getUsage() == VertexFormatElement.EnumUsage.COLOR) {
                    return new float[] { ((color) & 0xFF) / 255.0f, ((color >> 8) & 0xFF) / 255.0f, ((color >> 16) & 0xFF) / 255.0f, 1 };
                } else {
                    return data;
                }
            })));
        } else if ("map".equals(layer.type) && layer.textures != null) {
            String texture = layer.textures.get(state.name().toLowerCase(Locale.ENGLISH));
            if (texture == null) {
                texture = layer.textures.get("off");
                if (texture == null) {
                    texture = layer.textures.get("disabled");
                }
            }
            if (texture != null) {
                model = layerModels.get(texture);
                if (model == null) {
                    model = layerModel.retexture(ImmutableMap.of("layer", texture));
                    layerModels.put(texture, model);
                }
                result.addModel(model.bake(layerTransform, DefaultVertexFormats.BLOCK, ModelLoader.defaultTextureGetter()));
            }
        }
    }
    Set<EnumFacing> invertedSides = EnumSet.noneOf(EnumFacing.class);
    i = 0;
    for (GateRenderDefinitions.Torch torch : definition.torches) {
        GateLogic.State state = gate.logic.getTorchState(i++);
        if (state == GateLogic.State.NO_RENDER) {
            continue;
        }
        if (torch.inverter != null) {
            EnumFacing inverter = EnumFacing.byName(torch.inverter);
            if (gate.logic.isSideInverted(inverter)) {
                invertedSides.add(inverter);
            } else {
                continue;
            }
        }
        result.addModel(definition.getModel(state == GateLogic.State.ON ? (torch.model_on == null ? "torch_on" : torch.model_on) : (torch.model_off == null ? "torch_off" : torch.model_off)).bake(new ModelStateComposition(transform, new TRSRTransformation(new Vector3f((torch.pos[0] - 7.5f) / 16.0f, 0f, (torch.pos[1] - 7.5f) / 16.0f), null, null, null)), DefaultVertexFormats.BLOCK, ModelLoader.defaultTextureGetter()));
    }
    for (EnumFacing facing : EnumFacing.HORIZONTALS) {
        if (gate.logic.isSideInverted(facing) && !invertedSides.contains(facing)) {
            result.addModel(definition.getModel(gate.getInverterState(facing) ? "torch_on" : "torch_off").bake(new ModelStateComposition(transform, new TRSRTransformation(new Vector3f(((facing.getFrontOffsetX() * 6.9875f)) / 16.0f, 0f, ((facing.getFrontOffsetZ() * 6.9875f)) / 16.0f), null, null, null)), DefaultVertexFormats.BLOCK, ModelLoader.defaultTextureGetter()));
        }
    }
    return result;
}
Also used : TRSRTransformation(net.minecraftforge.common.model.TRSRTransformation) IModel(net.minecraftforge.client.model.IModel) EnumFacing(net.minecraft.util.EnumFacing) IModelState(net.minecraftforge.common.model.IModelState) SimpleBakedModel(pl.asie.charset.lib.render.model.SimpleBakedModel) GateLogic(pl.asie.simplelogic.gates.logic.GateLogic) ModelStateComposition(net.minecraftforge.client.model.ModelStateComposition) Vector3f(javax.vecmath.Vector3f) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel)

Example 19 with IBakedModel

use of net.minecraft.client.renderer.block.model.IBakedModel in project Charset by CharsetMC.

the class BlockBase method addDestroyEffects.

@Override
@SideOnly(Side.CLIENT)
public boolean addDestroyEffects(World world, BlockPos pos, ParticleManager manager) {
    IBlockState state = world.getBlockState(pos);
    IBakedModel model = Minecraft.getMinecraft().getBlockRendererDispatcher().getModelForState(state);
    if (model instanceof IStateParticleBakedModel) {
        state = getExtendedState(state.getActualState(world, pos), world, pos);
        TextureAtlasSprite sprite = ((IStateParticleBakedModel) model).getParticleTexture(state, null);
        if (sprite != null) {
            for (int j = 0; j < 4; ++j) {
                for (int k = 0; k < 4; ++k) {
                    for (int l = 0; l < 4; ++l) {
                        double d0 = ((double) j + 0.5D) / 4.0D;
                        double d1 = ((double) k + 0.5D) / 4.0D;
                        double d2 = ((double) l + 0.5D) / 4.0D;
                        manager.addEffect(new ParticleDiggingCharset(world, (double) pos.getX() + d0, (double) pos.getY() + d1, (double) pos.getZ() + d2, d0 - 0.5D, d1 - 0.5D, d2 - 0.5D, state, pos, sprite, getParticleTintIndex()));
                    }
                }
            }
            return true;
        }
    }
    return false;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) ParticleDiggingCharset(pl.asie.charset.lib.render.ParticleDiggingCharset) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) IStateParticleBakedModel(pl.asie.charset.lib.render.model.IStateParticleBakedModel) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 20 with IBakedModel

use of net.minecraft.client.renderer.block.model.IBakedModel 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

IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)197 IBlockState (net.minecraft.block.state.IBlockState)94 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)42 BlockPos (net.minecraft.util.math.BlockPos)40 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)38 EnumFacing (net.minecraft.util.EnumFacing)38 ResourceLocation (net.minecraft.util.ResourceLocation)36 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)30 ItemStack (net.minecraft.item.ItemStack)27 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)24 Block (net.minecraft.block.Block)23 IModel (net.minecraftforge.client.model.IModel)22 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)22 ArrayList (java.util.ArrayList)20 IExtendedBlockState (net.minecraftforge.common.property.IExtendedBlockState)17 Minecraft (net.minecraft.client.Minecraft)15 BlockRendererDispatcher (net.minecraft.client.renderer.BlockRendererDispatcher)15 List (java.util.List)14 ItemOverride (net.minecraft.client.renderer.block.model.ItemOverride)14 ImmutableList (com.google.common.collect.ImmutableList)13