Search in sources :

Example 61 with IBakedModel

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

the class FoamFixModelDeduplicate method onModelBake.

@SubscribeEvent(priority = EventPriority.LOW)
public void onModelBake(ModelBakeEvent event) {
    if (FoamFixShared.config.dbgCountModels) {
        debugCountModels(event);
    }
    Map<ResourceLocation, IModel> cache;
    try {
        cache = (Map<ResourceLocation, IModel>) MethodHandleHelper.findFieldGetter(ModelLoaderRegistry.class, "cache").invoke();
    } catch (Throwable t) {
        t.printStackTrace();
        cache = Collections.emptyMap();
    }
    if (FoamFixShared.config.clWipeModelCache) {
        int itemsCleared = 0;
        FoamFix.logger.info("Clearing ModelLoaderRegistry cache (" + cache.size() + " items)...");
        int cacheSize = cache.size();
        cache.entrySet().removeIf((e) -> {
            ResourceLocation r = e.getKey();
            if ("minecraft".equals(r.getResourceDomain()) || "fml".equals(r.getResourceDomain()) || "forge".equals(r.getResourceDomain())) {
                if (r.getResourcePath().endsWith("/generated")) {
                    return false;
                }
                if (r.getResourcePath().startsWith("builtin/")) {
                    return false;
                }
            }
            return true;
        });
        itemsCleared += cacheSize - cache.size();
        FoamFix.logger.info("Cleared " + itemsCleared + " objects.");
        cache = Collections.emptyMap();
    }
    if (FoamFixShared.config.geDeduplicate) {
        FoamFix.logger.info("Deduplicating models...");
        try {
            if (cache != null) {
                ProgressManager.ProgressBar bakeBar = ProgressManager.push("FoamFix: deduplicating", cache.size() + 2);
                if (ProxyClient.deduplicator == null) {
                    ProxyClient.deduplicator = new Deduplicator();
                }
                ProxyClient.deduplicator.maxRecursion = FoamFixShared.config.clDeduplicateRecursionLevel;
                ProxyClient.deduplicator.addObjects(ForgeRegistries.BLOCKS.getKeys());
                ProxyClient.deduplicator.addObjects(ForgeRegistries.ITEMS.getKeys());
                try {
                    bakeBar.step("Vertex formats");
                    for (Field f : DefaultVertexFormats.class.getDeclaredFields()) {
                        if (f.getType() == VertexFormat.class) {
                            f.setAccessible(true);
                            ProxyClient.deduplicator.deduplicateObject(f.get(null), 0);
                        }
                    }
                } catch (Exception e) {
                }
                if (FoamFixShared.config.clDeduplicateIModels) {
                    for (ResourceLocation loc : cache.keySet()) {
                        IModel model = cache.get(loc);
                        String modelName = loc.toString();
                        bakeBar.step(String.format("[%s]", modelName));
                        try {
                            ProxyClient.deduplicator.addObject(loc);
                            ProxyClient.deduplicator.deduplicateObject(model, 0);
                        } catch (Exception e) {
                        }
                    }
                }
                try {
                    bakeBar.step("Stats");
                    for (Field f : StatList.class.getDeclaredFields()) {
                        if (f.getType() == StatBase[].class) {
                            f.setAccessible(true);
                            for (StatBase statBase : (StatBase[]) f.get(null)) {
                                ProxyClient.deduplicator.deduplicateObject(statBase, 0);
                            }
                        }
                    }
                    for (StatBase statBase : StatList.ALL_STATS) {
                        ProxyClient.deduplicator.deduplicateObject(statBase, 0);
                    }
                } catch (Exception e) {
                }
                ProgressManager.pop(bakeBar);
            }
        } catch (Throwable t) {
            t.printStackTrace();
        }
        ProgressManager.ProgressBar bakeBar = ProgressManager.push("FoamFix: deduplicating", event.getModelRegistry().getKeys().size());
        if (ProxyClient.deduplicator == null) {
            ProxyClient.deduplicator = new Deduplicator();
        }
        ProxyClient.deduplicator.maxRecursion = FoamFixShared.config.clDeduplicateRecursionLevel;
        FoamFix.logger.info("Deduplicating models...");
        for (ModelResourceLocation loc : event.getModelRegistry().getKeys()) {
            IBakedModel model = event.getModelRegistry().getObject(loc);
            String modelName = loc.toString();
            bakeBar.step(String.format("[%s]", modelName));
            if (model instanceof MultipartBakedModel) {
                ProxyClient.deduplicator.successfuls++;
                model = new FoamyMultipartBakedModel((MultipartBakedModel) model);
            }
            try {
                ProxyClient.deduplicator.addObject(loc);
                event.getModelRegistry().putObject(loc, (IBakedModel) ProxyClient.deduplicator.deduplicateObject(model, 0));
            } catch (Exception e) {
            }
        }
        ProgressManager.pop(bakeBar);
        FoamFix.logger.info("Deduplicated " + ProxyClient.deduplicator.successfuls + " (+ " + ProxyClient.deduplicator.successfulTrims + ") objects.");
    /* List<Class> map = Lists.newArrayList(ProxyClient.deduplicator.dedupObjDataMap.keySet());
            map.sort(Comparator.comparingInt(a -> ProxyClient.deduplicator.dedupObjDataMap.get(a)));
            for (Class c : map) {
                FoamFix.logger.info(c.getSimpleName() + " = " + ProxyClient.deduplicator.dedupObjDataMap.get(c));
            } */
    }
    // release deduplicator to save memory
    ProxyClient.deduplicator = null;
    FoamFix.updateRamSaved();
}
Also used : IModel(net.minecraftforge.client.model.IModel) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) Field(java.lang.reflect.Field) ModelLoaderRegistry(net.minecraftforge.client.model.ModelLoaderRegistry) ProgressManager(net.minecraftforge.fml.common.ProgressManager) MultipartBakedModel(net.minecraft.client.renderer.block.model.MultipartBakedModel) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation) StatBase(net.minecraft.stats.StatBase) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 62 with IBakedModel

use of net.minecraft.client.renderer.block.model.IBakedModel in project Kingdom-Keys-Re-Coded by Wehavecookies56.

the class RenderEntitySharpshooterBullet method doRender.

@Override
public void doRender(EntitySharpshooterBullet entity, double x, double y, double z, float entityYaw, float partialTicks) {
    Tessellator tessellator = Tessellator.getInstance();
    BufferBuilder worldRenderer = tessellator.getBuffer();
    if (entity.ticksExisted < 1)
        return;
    textureGetter.apply(texture);
    bindEntityTexture(entity);
    GL11.glPushMatrix();
    {
        GL11.glTranslatef((float) x, (float) y, (float) z);
        // GL11.glRotatef(entityYaw, 0.0F, 1.0F, -1.0F);
        GL11.glScalef(0.02f, 0.02f, 0.02f);
        // GL11.glRotatef(90F - entity.prevRotationPitch -
        // (entity.rotationPitch - entity.prevRotationPitch) * partialTicks,
        // 1.0F, 0.0F, 0.0F);
        IModel model = null;
        try {
            model = B3DLoader.INSTANCE.loadModel(this.model);
        } catch (Exception e) {
            model = ModelLoaderRegistry.getMissingModel();
        }
        IBakedModel bakedModel = model.bake((TRSRTransformation.identity()), Attributes.DEFAULT_BAKED_FORMAT, textureGetter);
        worldRenderer.begin(7, Attributes.DEFAULT_BAKED_FORMAT);
        // Get Quads
        List<BakedQuad> generalQuads = bakedModel.getQuads(null, null, 1);
        for (BakedQuad q : generalQuads) {
            int[] vd = q.getVertexData();
            worldRenderer.addVertexData(vd);
        }
        for (EnumFacing face : EnumFacing.values()) {
            List<BakedQuad> faceQuads = bakedModel.getQuads(null, null, 1);
            for (BakedQuad q : faceQuads) {
                int[] vd = q.getVertexData();
                worldRenderer.addVertexData(vd);
            }
        }
        tessellator.draw();
    }
    GL11.glPopMatrix();
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) IModel(net.minecraftforge.client.model.IModel) Tessellator(net.minecraft.client.renderer.Tessellator) BufferBuilder(net.minecraft.client.renderer.BufferBuilder) EnumFacing(net.minecraft.util.EnumFacing) List(java.util.List) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel)

Example 63 with IBakedModel

use of net.minecraft.client.renderer.block.model.IBakedModel in project Immersive-Tech by FerroO2000.

the class TileRenderSteamTurbine method render.

@Override
public void render(TileEntitySteamTurbine te, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
    if (!te.formed || te.isDummy() || !te.getWorld().isBlockLoaded(te.getPos(), false)) {
        return;
    }
    final BlockRendererDispatcher blockRenderer = Minecraft.getMinecraft().getBlockRendererDispatcher();
    BlockPos blockPos = te.getPos();
    IBlockState state = getWorld().getBlockState(blockPos);
    if (state.getBlock() != ITContent.blockMetalMultiblock) {
        return;
    }
    state = state.getBlock().getActualState(state, getWorld(), blockPos);
    state = state.withProperty(IEProperties.DYNAMICRENDER, true);
    IBakedModel model = blockRenderer.getBlockModelShapes().getModelForState(state);
    Tessellator tessellator = Tessellator.getInstance();
    BufferBuilder worldRenderer = tessellator.getBuffer();
    ClientUtils.bindAtlas();
    GlStateManager.pushMatrix();
    GlStateManager.translate(x, y, z);
    GlStateManager.translate(.5, .5, .5);
    RenderHelper.disableStandardItemLighting();
    GlStateManager.blendFunc(770, 771);
    GlStateManager.enableBlend();
    GlStateManager.disableCull();
    if (Minecraft.isAmbientOcclusionEnabled()) {
        GlStateManager.shadeModel(7425);
    } else {
        GlStateManager.shadeModel(7424);
    }
    GlStateManager.rotate(te.getAnimation().getAnimationRotation() + (te.getAnimation().getAnimationStep() * partialTicks), te.facing.getFrontOffsetX(), 0, te.facing.getFrontOffsetZ());
    worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
    worldRenderer.setTranslation(-.5 - blockPos.getX(), -.5 - blockPos.getY(), -.5 - blockPos.getZ());
    worldRenderer.color(255, 255, 255, 255);
    blockRenderer.getBlockModelRenderer().renderModel(te.getWorld(), model, state, blockPos, worldRenderer, true);
    worldRenderer.setTranslation(0.0D, 0.0D, 0.0D);
    tessellator.draw();
    RenderHelper.enableStandardItemLighting();
    GlStateManager.popMatrix();
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) Tessellator(net.minecraft.client.renderer.Tessellator) BufferBuilder(net.minecraft.client.renderer.BufferBuilder) BlockPos(net.minecraft.util.math.BlockPos) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) BlockRendererDispatcher(net.minecraft.client.renderer.BlockRendererDispatcher)

Example 64 with IBakedModel

use of net.minecraft.client.renderer.block.model.IBakedModel in project MC-Prefab by Brian-Wuest.

the class StructureRenderHandler method renderBlockBrightness.

public static void renderBlockBrightness(IBlockState state, float brightness) {
    BlockRendererDispatcher brd = Minecraft.getMinecraft().getBlockRendererDispatcher();
    EnumBlockRenderType enumblockrendertype = state.getRenderType();
    if (enumblockrendertype != EnumBlockRenderType.INVISIBLE) {
        switch(enumblockrendertype) {
            case MODEL:
            case ENTITYBLOCK_ANIMATED:
                {
                    // Only use the chest renderer if this is actually an instance of a chest.
                    if (enumblockrendertype == EnumBlockRenderType.ENTITYBLOCK_ANIMATED && state.getBlock() instanceof BlockChest) {
                        StructureRenderHandler.chestRenderer.renderChestBrightness(state.getBlock(), brightness);
                        break;
                    }
                    IBakedModel ibakedmodel = brd.getModelForState(state);
                    BlockModelRenderer renderer = brd.getBlockModelRenderer();
                    try {
                        renderer.renderModelBrightness(ibakedmodel, state, brightness, true);
                    } catch (Exception ex) {
                        // Don't do anything if a mod broke this vanilla block rendering. It just won't show up during the preview then.
                        int test = 1;
                        test = 2;
                    }
                    break;
                }
            default:
                {
                    break;
                }
        }
    }
}
Also used : BlockChest(net.minecraft.block.BlockChest) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) EnumBlockRenderType(net.minecraft.util.EnumBlockRenderType)

Example 65 with IBakedModel

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

the class ParticleItemStack method handleRender.

@Override
protected void handleRender(final float partialTicks) {
    final IBakedModel baked = net.minecraftforge.client.ForgeHooksClient.handleCameraTransforms(this.model, ItemCameraTransforms.TransformType.GROUND, false);
    itemRenderer.renderItem(this.prototype, baked);
}
Also used : IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel)

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