Search in sources :

Example 6 with BlockModelShapes

use of net.minecraft.client.renderer.BlockModelShapes in project EnderIO by SleepyTrousers.

the class QuadCollector method addFriendlyBlockStates.

/**
 * Adds the baked model(s) of the given block states to the quad lists for the given block layer. The models are expected to behave. The block layer will be
 * NOT set when the models are asked for their quads.
 */
public void addFriendlyBlockStates(BlockRenderLayer pass, List<IBlockState> states) {
    if (states == null || states.isEmpty()) {
        return;
    }
    BlockModelShapes modelShapes = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes();
    for (IBlockState state : states) {
        if (state != null) {
            IBakedModel model = modelShapes.getModelForState(state);
            List<BakedQuad> generalQuads = model.getQuads(state, null, 0);
            if (!generalQuads.isEmpty()) {
                addQuads(null, pass, generalQuads);
            }
            for (EnumFacing face : EnumFacing.values()) {
                List<BakedQuad> faceQuads = model.getQuads(state, face, 0);
                if (!faceQuads.isEmpty()) {
                    addQuads(face, pass, faceQuads);
                }
            }
        }
    }
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) BlockModelShapes(net.minecraft.client.renderer.BlockModelShapes)

Example 7 with BlockModelShapes

use of net.minecraft.client.renderer.BlockModelShapes in project ForestryMC by ForestryMC.

the class CamouflageHandlerBlock method getModel.

@SideOnly(Side.CLIENT)
@Override
public Pair<IBlockState, IBakedModel> getModel(ItemStack stack) {
    Preconditions.checkArgument(!stack.isEmpty(), "Stack cannot be empty");
    BlockRendererDispatcher rendererDispatcher = Minecraft.getMinecraft().getBlockRendererDispatcher();
    BlockModelShapes modelShapes = rendererDispatcher.getBlockModelShapes();
    Block block = Block.getBlockFromItem(stack.getItem());
    Preconditions.checkArgument(block != Blocks.AIR, "Block cannot be AIR");
    IBlockState state = block.getStateFromMeta(stack.getItemDamage());
    return Pair.of(state, modelShapes.getModelForState(state));
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) Block(net.minecraft.block.Block) BlockModelShapes(net.minecraft.client.renderer.BlockModelShapes) BlockRendererDispatcher(net.minecraft.client.renderer.BlockRendererDispatcher) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 8 with BlockModelShapes

use of net.minecraft.client.renderer.BlockModelShapes in project FoamFix by asiekierka.

the class FoamFixModelRegistryDuplicateWipe method onTextureStitchPost.

@SubscribeEvent
public void onTextureStitchPost(TextureStitchEvent.Post event) {
    ItemModelMesher imm = Minecraft.getMinecraft().getRenderItem().getItemModelMesher();
    BlockModelShapes bms = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes();
    ModelManager mgr = bms.getModelManager();
    Field f = ReflectionHelper.findField(ModelManager.class, "modelRegistry", "field_174958_a");
    try {
        IRegistry<ModelResourceLocation, IBakedModel> registry = (IRegistry<ModelResourceLocation, IBakedModel>) f.get(mgr);
        FoamFix.logger.info("Clearing unnecessary model registry of size " + registry.getKeys().size() + ".");
        for (ModelResourceLocation l : registry.getKeys()) {
            registry.putObject(l, ProxyClient.DUMMY_MODEL);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    f = ReflectionHelper.findField(BlockModelShapes.class, "bakedModelStore", "field_178129_a");
    try {
        Map<IBlockState, IBakedModel> modelStore = (Map<IBlockState, IBakedModel>) f.get(bms);
        FoamFix.logger.info("Clearing unnecessary model store of size " + modelStore.size() + ".");
        modelStore.clear();
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (imm instanceof ItemModelMesherForge) {
        f = ReflectionHelper.findField(ItemModelMesherForge.class, "models");
        try {
            Map<IRegistryDelegate<Item>, TIntObjectHashMap<IBakedModel>> modelStore = (Map<IRegistryDelegate<Item>, TIntObjectHashMap<IBakedModel>>) f.get(imm);
            FoamFix.logger.info("Clearing unnecessary item shapes cache of size " + modelStore.size() + ".");
            modelStore.clear();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ModelManager(net.minecraft.client.renderer.block.model.ModelManager) BlockModelShapes(net.minecraft.client.renderer.BlockModelShapes) Field(java.lang.reflect.Field) Item(net.minecraft.item.Item) ItemModelMesher(net.minecraft.client.renderer.ItemModelMesher) IRegistryDelegate(net.minecraftforge.registries.IRegistryDelegate) TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) ItemModelMesherForge(net.minecraftforge.client.ItemModelMesherForge) IRegistry(net.minecraft.util.registry.IRegistry) TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) Map(java.util.Map) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 9 with BlockModelShapes

use of net.minecraft.client.renderer.BlockModelShapes in project pnc-repressurized by TeamPneumatic.

the class CamoModel method handleBlockState.

private IBakedModel handleBlockState(IBlockState state) {
    if (state instanceof IExtendedBlockState) {
        IExtendedBlockState ext = (IExtendedBlockState) state;
        IBlockState camoState = ext.getValue(BlockPneumaticCraftCamo.CAMO_STATE);
        if (camoState != null && !(camoState.getBlock() instanceof BlockPneumaticCraftCamo)) {
            BlockModelShapes blockModelShapes = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes();
            return blockModelShapes.getModelForState(camoState);
        }
    }
    return originalModel;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) BlockPneumaticCraftCamo(me.desht.pneumaticcraft.common.block.BlockPneumaticCraftCamo) BlockModelShapes(net.minecraft.client.renderer.BlockModelShapes)

Aggregations

BlockModelShapes (net.minecraft.client.renderer.BlockModelShapes)9 IBlockState (net.minecraft.block.state.IBlockState)6 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)6 BlockRendererDispatcher (net.minecraft.client.renderer.BlockRendererDispatcher)4 BufferBuilder (net.minecraft.client.renderer.BufferBuilder)2 ItemStack (net.minecraft.item.ItemStack)2 EnumFacing (net.minecraft.util.EnumFacing)2 TIntObjectHashMap (gnu.trove.map.hash.TIntObjectHashMap)1 Field (java.lang.reflect.Field)1 HashMap (java.util.HashMap)1 IdentityHashMap (java.util.IdentityHashMap)1 Map (java.util.Map)1 Nullable (javax.annotation.Nullable)1 BlockPneumaticCraftCamo (me.desht.pneumaticcraft.common.block.BlockPneumaticCraftCamo)1 Block (net.minecraft.block.Block)1 Minecraft (net.minecraft.client.Minecraft)1 ItemModelMesher (net.minecraft.client.renderer.ItemModelMesher)1 Tessellator (net.minecraft.client.renderer.Tessellator)1 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)1 ModelManager (net.minecraft.client.renderer.block.model.ModelManager)1