Search in sources :

Example 91 with IBakedModel

use of net.minecraft.client.renderer.block.model.IBakedModel in project ImmersiveEngineering by BluSunrize.

the class ModelCoresample method getQuads.

@Override
public List<BakedQuad> getQuads(@Nullable IBlockState blockState, @Nullable EnumFacing side, long rand) {
    if (bakedQuads == null) {
        try {
            bakedQuads = Collections.synchronizedSet(new LinkedHashSet<BakedQuad>());
            float width = .25f;
            float depth = .25f;
            float wOff = (1 - width) / 2;
            float dOff = (1 - depth) / 2;
            int pixelLength = 0;
            HashMap<TextureAtlasSprite, Integer> textureOre = new HashMap();
            if (mineral != null && mineral.oreOutput != null) {
                for (int i = 0; i < mineral.oreOutput.size(); i++) if (!mineral.oreOutput.get(i).isEmpty()) {
                    int weight = Math.max(2, Math.round(16 * mineral.recalculatedChances[i]));
                    Block b = Block.getBlockFromItem(mineral.oreOutput.get(i).getItem());
                    IBlockState state = b != null && b != Blocks.AIR ? b.getStateFromMeta(mineral.oreOutput.get(i).getMetadata()) : Blocks.STONE.getDefaultState();
                    IBakedModel model = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getModelForState(state);
                    if (model != null && model.getParticleTexture() != null)
                        textureOre.put(model.getParticleTexture(), weight);
                    pixelLength += weight;
                }
            } else
                pixelLength = 16;
            TextureAtlasSprite textureStone = ClientUtils.getSprite(new ResourceLocation("blocks/stone"));
            Vector2f[] stoneUVs = { new Vector2f(16 * wOff, 16 * dOff), new Vector2f(16 * wOff, 16 * (dOff + depth)), new Vector2f(16 * (wOff + width), 16 * (dOff + depth)), new Vector2f(16 * (wOff + width), 16 * dOff) };
            putVertexData(new Vector3f(0, -1, 0), new Vector3f[] { new Vector3f(wOff, 0, dOff), new Vector3f(wOff + width, 0, dOff), new Vector3f(wOff + width, 0, dOff + depth), new Vector3f(wOff, 0, dOff + depth) }, stoneUVs, textureStone);
            putVertexData(new Vector3f(0, 1, 0), new Vector3f[] { new Vector3f(wOff, 1, dOff), new Vector3f(wOff, 1, dOff + depth), new Vector3f(wOff + width, 1, dOff + depth), new Vector3f(wOff + width, 1, dOff) }, stoneUVs, textureStone);
            if (textureOre.isEmpty()) {
                Vector2f[][] uvs = new Vector2f[4][];
                for (int j = 0; j < 4; j++) uvs[j] = new Vector2f[] { new Vector2f(j * 4, 0), new Vector2f(j * 4, 16), new Vector2f((j + 1) * 4, 16), new Vector2f((j + 1) * 4, 0) };
                putVertexData(new Vector3f(0, 0, -1), new Vector3f[] { new Vector3f(wOff, 0, dOff), new Vector3f(wOff, 1, dOff), new Vector3f(wOff + width, 1, dOff), new Vector3f(wOff + width, 0, dOff) }, uvs[0], textureStone);
                putVertexData(new Vector3f(0, 0, 1), new Vector3f[] { new Vector3f(wOff + width, 0, dOff + depth), new Vector3f(wOff + width, 1, dOff + depth), new Vector3f(wOff, 1, dOff + depth), new Vector3f(wOff, 0, dOff + depth) }, uvs[2], textureStone);
                putVertexData(new Vector3f(-1, 0, 0), new Vector3f[] { new Vector3f(wOff, 0, dOff + depth), new Vector3f(wOff, 1, dOff + depth), new Vector3f(wOff, 1, dOff), new Vector3f(wOff, 0, dOff) }, uvs[3], textureStone);
                putVertexData(new Vector3f(1, 0, 0), new Vector3f[] { new Vector3f(wOff + width, 0, dOff), new Vector3f(wOff + width, 1, dOff), new Vector3f(wOff + width, 1, dOff + depth), new Vector3f(wOff + width, 0, dOff + depth) }, uvs[1], textureStone);
            } else {
                float h = 0;
                for (TextureAtlasSprite sprite : textureOre.keySet()) {
                    int weight = textureOre.get(sprite);
                    int v = weight > 8 ? 16 - weight : 8;
                    Vector2f[][] uvs = new Vector2f[4][];
                    for (int j = 0; j < 4; j++) uvs[j] = new Vector2f[] { new Vector2f(j * 4, v), new Vector2f(j * 4, v + weight), new Vector2f((j + 1) * 4, v + weight), new Vector2f((j + 1) * 4, v) };
                    float h1 = weight / (float) pixelLength;
                    putVertexData(new Vector3f(0, 0, -1), new Vector3f[] { new Vector3f(wOff, h, dOff), new Vector3f(wOff, h + h1, dOff), new Vector3f(wOff + width, h + h1, dOff), new Vector3f(wOff + width, h, dOff) }, uvs[0], sprite);
                    putVertexData(new Vector3f(0, 0, 1), new Vector3f[] { new Vector3f(wOff + width, h, dOff + depth), new Vector3f(wOff + width, h + h1, dOff + depth), new Vector3f(wOff, h + h1, dOff + depth), new Vector3f(wOff, h, dOff + depth) }, uvs[2], sprite);
                    putVertexData(new Vector3f(-1, 0, 0), new Vector3f[] { new Vector3f(wOff, h, dOff + depth), new Vector3f(wOff, h + h1, dOff + depth), new Vector3f(wOff, h + h1, dOff), new Vector3f(wOff, h, dOff) }, uvs[3], sprite);
                    putVertexData(new Vector3f(1, 0, 0), new Vector3f[] { new Vector3f(wOff + width, h, dOff), new Vector3f(wOff + width, h + h1, dOff), new Vector3f(wOff + width, h + h1, dOff + depth), new Vector3f(wOff + width, h, dOff + depth) }, uvs[1], sprite);
                    h += h1;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    if (bakedQuads != null && !bakedQuads.isEmpty()) {
        List<BakedQuad> quadList = Collections.synchronizedList(Lists.newArrayList(bakedQuads));
        return quadList;
    }
    return emptyQuads;
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) UnpackedBakedQuad(net.minecraftforge.client.model.pipeline.UnpackedBakedQuad) IBlockState(net.minecraft.block.state.IBlockState) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) Vector2f(org.lwjgl.util.vector.Vector2f) ResourceLocation(net.minecraft.util.ResourceLocation) Vector3f(org.lwjgl.util.vector.Vector3f) Block(net.minecraft.block.Block) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel)

Example 92 with IBakedModel

use of net.minecraft.client.renderer.block.model.IBakedModel in project ImmersiveEngineering by BluSunrize.

the class ConnModelReal method getQuads.

@Nonnull
@Override
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand) {
    if (side == null && state instanceof IExtendedBlockState) {
        IExtendedBlockState ext = (IExtendedBlockState) state;
        Object[] additional = null;
        if (ext.getUnlistedProperties().containsKey(IEProperties.TILEENTITY_PASSTHROUGH)) {
            TileEntity te = ext.getValue(IEProperties.TILEENTITY_PASSTHROUGH);
            if (te instanceof IEBlockInterfaces.ICacheData)
                additional = ((IEBlockInterfaces.ICacheData) te).getCacheData();
        }
        int x = 0, z = 0;
        if (ext.getUnlistedProperties().containsKey(IEProperties.CONNECTIONS)) {
            Set<Connection> conns = ext.getValue(IEProperties.CONNECTIONS);
            if (conns != null && conns.size() > 0) {
                BlockPos tmp = conns.iterator().next().start;
                x = (tmp.getX() % 16 + 16) % 16;
                z = (tmp.getZ() % 16 + 16) % 16;
            }
        }
        ExtBlockstateAdapter ad = new ExtBlockstateAdapter(ext, null, ExtBlockstateAdapter.ONLY_OBJ_CALLBACK, additional);
        Pair<Byte, ExtBlockstateAdapter> key = new ImmutablePair<>((byte) ((x << 4) | z), ad);
        try {
            IBakedModel ret = cache.get(key, () -> new AssembledBakedModel(ext, textureAtlasSprite, base, layers));
            return ret.getQuads(state, null, rand);
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    }
    return getBaseQuads(MinecraftForgeClient.getRenderLayer(), state, side, rand);
}
Also used : Connection(blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection) TileEntity(net.minecraft.tileentity.TileEntity) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) BlockPos(net.minecraft.util.math.BlockPos) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) ExecutionException(java.util.concurrent.ExecutionException) Nonnull(javax.annotation.Nonnull)

Example 93 with IBakedModel

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

use of net.minecraft.client.renderer.block.model.IBakedModel in project MorePlanets by SteveKunG.

the class ClientRendererUtils method renderModel.

public static void renderModel(IBlockState state) {
    Minecraft mc = Minecraft.getMinecraft();
    mc.renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
    GlStateManager.rotate(90.0F, 0.0F, 1.0F, 0.0F);
    int i = mc.getBlockColors().colorMultiplier(state, null, null, 0);
    IBakedModel model = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getModelForState(state);
    if (EntityRenderer.anaglyphEnable) {
        i = TextureUtil.anaglyphColor(i);
    }
    float f = (i >> 16 & 255) / 255.0F;
    float f1 = (i >> 8 & 255) / 255.0F;
    float f2 = (i & 255) / 255.0F;
    ClientRendererUtils.renderModelBrightnessColor(state, model, 1.0F, f, f1, f2);
}
Also used : IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) Minecraft(net.minecraft.client.Minecraft)

Example 95 with IBakedModel

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

the class ItemModelMesherForge method rebuildCache.

public void rebuildCache() {
    final ModelManager manager = this.getModelManager();
    for (Map.Entry<Item, TIntObjectHashMap<ModelResourceLocation>> e : locations.entrySet()) {
        TIntObjectHashMap<IBakedModel> mods = models.get(e.getKey());
        if (mods != null) {
            mods.clear();
        } else {
            mods = new TIntObjectHashMap<IBakedModel>();
            models.put(e.getKey(), mods);
        }
        final TIntObjectHashMap<IBakedModel> map = mods;
        e.getValue().forEachEntry(new TIntObjectProcedure<ModelResourceLocation>() {

            @Override
            public boolean execute(int meta, ModelResourceLocation location) {
                map.put(meta, manager.getModel(location));
                return true;
            }
        });
    }
}
Also used : Item(net.minecraft.item.Item) TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ModelManager(net.minecraft.client.renderer.block.model.ModelManager) TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) IdentityHashMap(java.util.IdentityHashMap) Map(java.util.Map)

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