Search in sources :

Example 6 with IModelState

use of net.minecraftforge.common.model.IModelState in project Binnie by ForestryMC.

the class ModelManager method registerCustomModels.

public static void registerCustomModels(ModelBakeEvent event) {
    IRegistry<ModelResourceLocation, IBakedModel> registry = event.getModelRegistry();
    for (final BlockModelEntry entry : customBlockModels) {
        registry.putObject(entry.blockModelLocation, entry.model);
        if (entry.itemModelLocation != null) {
            registry.putObject(entry.itemModelLocation, entry.model);
        }
    }
    IModelState defaultBlockState = ModelUtil.loadModelState(new ResourceLocation("minecraft:models/block/block"));
    IModelState defaultFenceState = ModelUtil.loadModelState(new ResourceLocation("minecraft:models/block/fence_inventory"));
    ModelManager.defaultFenceState = mergeStates(defaultBlockState, defaultFenceState);
}
Also used : BlockModelEntry(forestry.core.models.BlockModelEntry) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation) IModelState(net.minecraftforge.common.model.IModelState) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel)

Example 7 with IModelState

use of net.minecraftforge.common.model.IModelState in project ImmersiveEngineering by BluSunrize.

the class IESmartObjModel method getQuads.

@Override
public List<BakedQuad> getQuads(IBlockState blockState, EnumFacing side, long rand) {
    if (side != null)
        return ImmutableList.of();
    OBJState objState = null;
    Map<String, String> tex = null;
    if (blockState instanceof IExtendedBlockState) {
        IExtendedBlockState ext = (IExtendedBlockState) blockState;
        if (ext.getUnlistedNames().contains(Properties.AnimationProperty)) {
            IModelState modState = ext.getValue(Properties.AnimationProperty);
            if (modState instanceof OBJState)
                objState = (OBJState) modState;
        }
        if (ext.getUnlistedNames().contains(IEProperties.OBJ_TEXTURE_REMAP))
            tex = ext.getValue(IEProperties.OBJ_TEXTURE_REMAP);
    }
    return getQuads(blockState, side, rand, objState, tex, false);
}
Also used : IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) IModelState(net.minecraftforge.common.model.IModelState)

Example 8 with IModelState

use of net.minecraftforge.common.model.IModelState in project MorePlanets by SteveKunG.

the class OBJLoaderMP method getModelFromOBJ.

@SuppressWarnings("deprecation")
public static IBakedModel getModelFromOBJ(ResourceLocation modelLocation, List<String> visibleGroups, IModelState parentState) throws IOException {
    IModel model = OBJLoaderMP.INSTANCE.loadModel(modelLocation);
    Function<ResourceLocation, TextureAtlasSprite> spriteFunction = location -> Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(location.toString());
    return model.bake(new OBJModel.OBJState(visibleGroups, false, parentState), DefaultVertexFormats.ITEM, spriteFunction);
}
Also used : IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) java.util(java.util) Function(com.google.common.base.Function) OBJModel(net.minecraftforge.client.model.obj.OBJModel) IReloadableResourceManager(net.minecraft.client.resources.IReloadableResourceManager) ImmutableMap(com.google.common.collect.ImmutableMap) IModelState(net.minecraftforge.common.model.IModelState) ModelLoaderRegistry(net.minecraftforge.client.model.ModelLoaderRegistry) IOException(java.io.IOException) IModel(net.minecraftforge.client.model.IModel) DefaultVertexFormats(net.minecraft.client.renderer.vertex.DefaultVertexFormats) ICustomModelLoader(net.minecraftforge.client.model.ICustomModelLoader) Minecraft(net.minecraft.client.Minecraft) IResourceManager(net.minecraft.client.resources.IResourceManager) ResourceLocation(net.minecraft.util.ResourceLocation) TRSRTransformation(net.minecraftforge.common.model.TRSRTransformation) IResource(net.minecraft.client.resources.IResource) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) IModel(net.minecraftforge.client.model.IModel) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) ResourceLocation(net.minecraft.util.ResourceLocation) OBJModel(net.minecraftforge.client.model.obj.OBJModel)

Example 9 with IModelState

use of net.minecraftforge.common.model.IModelState in project MinecraftForge by MinecraftForge.

the class MultiModel method bake.

@Override
public IBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) {
    IBakedModel bakedBase = null;
    if (base != null)
        bakedBase = base.bake(state, format, bakedTextureGetter);
    ImmutableMap.Builder<String, IBakedModel> mapBuilder = ImmutableMap.builder();
    for (Entry<String, Pair<IModel, IModelState>> entry : parts.entrySet()) {
        Pair<IModel, IModelState> pair = entry.getValue();
        mapBuilder.put(entry.getKey(), pair.getLeft().bake(new ModelStateComposition(state, pair.getRight()), format, bakedTextureGetter));
    }
    if (bakedBase == null && parts.isEmpty()) {
        FMLLog.log(Level.ERROR, "MultiModel %s is empty (no base model or parts were provided/resolved)", location);
        IModel missing = ModelLoaderRegistry.getMissingModel();
        return missing.bake(missing.getDefaultState(), format, bakedTextureGetter);
    }
    return new Baked(location, true, bakedBase, mapBuilder.build());
}
Also used : IModelState(net.minecraftforge.common.model.IModelState) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) ImmutableMap(com.google.common.collect.ImmutableMap) Pair(org.apache.commons.lang3.tuple.Pair) ItemOverride(net.minecraft.client.renderer.block.model.ItemOverride)

Example 10 with IModelState

use of net.minecraftforge.common.model.IModelState 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)

Aggregations

IModelState (net.minecraftforge.common.model.IModelState)18 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)11 IModel (net.minecraftforge.client.model.IModel)10 ResourceLocation (net.minecraft.util.ResourceLocation)6 EnumFacing (net.minecraft.util.EnumFacing)5 ModelStateComposition (net.minecraftforge.client.model.ModelStateComposition)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 IBlockState (net.minecraft.block.state.IBlockState)4 BlockPos (net.minecraft.util.math.BlockPos)4 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)3 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)3 IExtendedBlockState (net.minecraftforge.common.property.IExtendedBlockState)3 IBlockAccess (net.minecraft.world.IBlockAccess)2 TRSRTransformation (net.minecraftforge.common.model.TRSRTransformation)2 IAnimationStateMachine (net.minecraftforge.common.model.animation.IAnimationStateMachine)2 WrappedBakedModel (pl.asie.charset.lib.render.model.WrappedBakedModel)2 Function (com.google.common.base.Function)1 Predicate (com.google.common.base.Predicate)1 CacheBuilder (com.google.common.cache.CacheBuilder)1 Lists (com.google.common.collect.Lists)1