Search in sources :

Example 1 with IModel

use of net.minecraftforge.client.model.IModel in project Railcraft by Railcraft.

the class ActuatorModel method bakeModels.

@SuppressWarnings("Guava")
private Map<ModelResourceLocation, IBakedModel> bakeModels(VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter, Map<IBlockState, ModelResourceLocation> modelLocations) {
    Set<ModelResourceLocation> locations = new HashSet<>();
    locations.addAll(modelLocations.values());
    Map<ModelResourceLocation, IBakedModel> models = new HashMap<>();
    for (ModelResourceLocation modelLocation : locations) {
        IModel model = ModelManager.getModel(modelLocation);
        models.put(modelLocation, model.bake(model.getDefaultState(), format, bakedTextureGetter));
    }
    return models;
}
Also used : IModel(net.minecraftforge.client.model.IModel)

Example 2 with IModel

use of net.minecraftforge.client.model.IModel in project Railcraft by Railcraft.

the class JSONModelRenderer method loadModels.

@SubscribeEvent
public void loadModels(TextureStitchEvent.Pre event) {
    final TextureMap map = event.getMap();
    for (ResourceLocation modelLocation : modelLocations) {
        IModel model = ModelManager.getModel(modelLocation);
        models.put(modelLocation, model);
        model.getTextures().forEach(map::registerSprite);
    }
}
Also used : IModel(net.minecraftforge.client.model.IModel) TextureMap(net.minecraft.client.renderer.texture.TextureMap) ResourceLocation(net.minecraft.util.ResourceLocation) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 3 with IModel

use of net.minecraftforge.client.model.IModel in project Overloaded by CJ-MC-Mods.

the class ModelUtils method loadBakedModel.

public static IBakedModel loadBakedModel(ResourceLocation modelLocation) {
    if (!bakedModelCache.containsKey(modelLocation)) {
        try {
            IModel model = ModelLoaderRegistry.getModel(modelLocation);
            IBakedModel bakedModel = model.bake(TRSRTransformation.identity(), DefaultVertexFormats.ITEM, new Function<ResourceLocation, TextureAtlasSprite>() {

                @Nullable
                @Override
                public TextureAtlasSprite apply(ResourceLocation input) {
                    return Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(input.toString());
                }
            });
            bakedModelCache.put(modelLocation, bakedModel);
        } catch (Exception e) {
            System.err.println("Error at ModelUtils.loadBakedModel, Resource: " + modelLocation.toString());
            throw new RuntimeException(e);
        }
    }
    return bakedModelCache.get(modelLocation);
}
Also used : IModel(net.minecraftforge.client.model.IModel) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) ResourceLocation(net.minecraft.util.ResourceLocation) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) Nullable(jline.internal.Nullable)

Example 4 with IModel

use of net.minecraftforge.client.model.IModel in project MinecraftForge by MinecraftForge.

the class AnimationModelBase method render.

@SuppressWarnings("unchecked")
@Override
public void render(Entity entity, float limbSwing, float limbSwingSpeed, float timeAlive, float yawHead, float rotationPitch, float scale) {
    IAnimationStateMachine capability = entity.getCapability(CapabilityAnimation.ANIMATION_CAPABILITY, null);
    if (capability == null) {
        return;
    }
    Pair<IModelState, Iterable<Event>> pair = capability.apply(timeAlive / 20);
    handleEvents((T) entity, timeAlive / 20, pair.getRight());
    IModel model = ModelLoaderRegistry.getModelOrMissing(modelLocation);
    IBakedModel bakedModel = model.bake(pair.getLeft(), DefaultVertexFormats.ITEM, ModelLoader.defaultTextureGetter());
    BlockPos pos = new BlockPos(entity.posX, entity.posY + entity.height, entity.posZ);
    RenderHelper.disableStandardItemLighting();
    GlStateManager.pushMatrix();
    GlStateManager.rotate(180, 0, 0, 1);
    Tessellator tessellator = Tessellator.getInstance();
    VertexBuffer VertexBuffer = tessellator.getBuffer();
    VertexBuffer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
    VertexBuffer.setTranslation(-0.5, -1.5, -0.5);
    lighter.setParent(new VertexBufferConsumer(VertexBuffer));
    lighter.setWorld(entity.world);
    lighter.setState(Blocks.AIR.getDefaultState());
    lighter.setBlockPos(pos);
    boolean empty = true;
    List<BakedQuad> quads = bakedModel.getQuads(null, null, 0);
    if (!quads.isEmpty()) {
        lighter.updateBlockInfo();
        empty = false;
        for (BakedQuad quad : quads) {
            quad.pipe(lighter);
        }
    }
    for (EnumFacing side : EnumFacing.values()) {
        quads = bakedModel.getQuads(null, side, 0);
        if (!quads.isEmpty()) {
            if (empty)
                lighter.updateBlockInfo();
            empty = false;
            for (BakedQuad quad : quads) {
                quad.pipe(lighter);
            }
        }
    }
    // debug quad
    /*VertexBuffer.pos(0, 1, 0).color(0xFF, 0xFF, 0xFF, 0xFF).tex(0, 0).lightmap(240, 0).endVertex();
        VertexBuffer.pos(0, 1, 1).color(0xFF, 0xFF, 0xFF, 0xFF).tex(0, 1).lightmap(240, 0).endVertex();
        VertexBuffer.pos(1, 1, 1).color(0xFF, 0xFF, 0xFF, 0xFF).tex(1, 1).lightmap(240, 0).endVertex();
        VertexBuffer.pos(1, 1, 0).color(0xFF, 0xFF, 0xFF, 0xFF).tex(1, 0).lightmap(240, 0).endVertex();*/
    VertexBuffer.setTranslation(0, 0, 0);
    tessellator.draw();
    GlStateManager.popMatrix();
    RenderHelper.enableStandardItemLighting();
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) IModel(net.minecraftforge.client.model.IModel) Tessellator(net.minecraft.client.renderer.Tessellator) VertexBufferConsumer(net.minecraftforge.client.model.pipeline.VertexBufferConsumer) VertexBuffer(net.minecraft.client.renderer.VertexBuffer) EnumFacing(net.minecraft.util.EnumFacing) IModelState(net.minecraftforge.common.model.IModelState) IAnimationStateMachine(net.minecraftforge.common.model.animation.IAnimationStateMachine) BlockPos(net.minecraft.util.math.BlockPos) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel)

Example 5 with IModel

use of net.minecraftforge.client.model.IModel in project MinecraftForge by MinecraftForge.

the class Clips method getModelClipNode.

/**
     * Retrieves the clip from the model.
     */
@SideOnly(Side.CLIENT)
public static IClip getModelClipNode(ResourceLocation modelLocation, String clipName) {
    IModel model = ModelLoaderRegistry.getModelOrMissing(modelLocation);
    if (model instanceof IAnimatedModel) {
        Optional<? extends IClip> clip = ((IAnimatedModel) model).getClip(clipName);
        if (clip.isPresent()) {
            return new ModelClip(clip.get(), modelLocation, clipName);
        }
        FMLLog.getLogger().error("Unable to find clip " + clipName + " in the model " + modelLocation);
    }
    // FIXME: missing clip?
    return new ModelClip(IdentityClip.INSTANCE, modelLocation, clipName);
}
Also used : IAnimatedModel(net.minecraftforge.client.model.animation.IAnimatedModel) IModel(net.minecraftforge.client.model.IModel) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Aggregations

IModel (net.minecraftforge.client.model.IModel)8 ResourceLocation (net.minecraft.util.ResourceLocation)4 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)3 TextureMap (net.minecraft.client.renderer.texture.TextureMap)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 Nullable (jline.internal.Nullable)1 Tessellator (net.minecraft.client.renderer.Tessellator)1 VertexBuffer (net.minecraft.client.renderer.VertexBuffer)1 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)1 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)1 EnumFacing (net.minecraft.util.EnumFacing)1 BlockPos (net.minecraft.util.math.BlockPos)1 IAnimatedModel (net.minecraftforge.client.model.animation.IAnimatedModel)1 OBJModel (net.minecraftforge.client.model.obj.OBJModel)1 VertexBufferConsumer (net.minecraftforge.client.model.pipeline.VertexBufferConsumer)1 IModelState (net.minecraftforge.common.model.IModelState)1 IAnimationStateMachine (net.minecraftforge.common.model.animation.IAnimationStateMachine)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1