Search in sources :

Example 81 with ModelResourceLocation

use of net.minecraft.client.renderer.block.model.ModelResourceLocation in project Tropicraft by Tropicraft.

the class ClientProxy method onModelBake.

@SubscribeEvent
public void onModelBake(ModelBakeEvent event) {
    for (Entry<String, String[]> e : blockVariants.entrySet()) {
        for (String variant : e.getValue()) {
            ModelResourceLocation loc = new ModelResourceLocation(Info.MODID + ":" + e.getKey(), variant);
            IModel model = ModelLoaderRegistry.getModelOrLogError(loc, "Could not load arbitrary block variant " + variant + " for block " + e.getKey());
            event.getModelRegistry().putObject(loc, model.bake(model.getDefaultState(), DefaultVertexFormats.ITEM, ModelLoader.defaultTextureGetter()));
        }
    }
    try {
        IModel waterTop = ModelLoaderRegistry.getModel(new ResourceLocation("tropicraft:block/tropics_water_top"));
        final IBakedModel waterTopBaked = waterTop.bake(waterTop.getDefaultState(), DefaultVertexFormats.ITEM, ModelLoader.defaultTextureGetter());
        Block[] fences = new Block[] { BlockRegistry.bambooFence, BlockRegistry.chunkFence, BlockRegistry.mahoganyFence, BlockRegistry.palmFence, BlockRegistry.thatchFence };
        for (Block block : fences) {
            ModelResourceLocation loc = new ModelResourceLocation(block.getRegistryName(), "normal");
            final IBakedModel fenceModel = event.getModelRegistry().getObject(loc);
            event.getModelRegistry().putObject(loc, new IBakedModel() {

                @Override
                @Nonnull
                public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand) {
                    BlockRenderLayer layer = MinecraftForgeClient.getRenderLayer();
                    if (layer == null || layer == BlockRenderLayer.SOLID) {
                        return fenceModel.getQuads(state, side, rand);
                    } else if (layer == BlockRenderLayer.TRANSLUCENT && state.getValue(BlockTropicraftFence.WATER) == WaterState.SURFACE) {
                        return waterTopBaked.getQuads(state, side, rand);
                    }
                    return Collections.emptyList();
                }

                @Override
                public boolean isGui3d() {
                    return true;
                }

                @Override
                public boolean isBuiltInRenderer() {
                    return false;
                }

                @Override
                public boolean isAmbientOcclusion() {
                    return true;
                }

                @Override
                @Nonnull
                public TextureAtlasSprite getParticleTexture() {
                    return fenceModel.getParticleTexture();
                }

                @Override
                @Nonnull
                public ItemOverrideList getOverrides() {
                    return fenceModel.getOverrides();
                }
            });
        }
    } catch (Exception e1) {
        e1.printStackTrace();
    }
}
Also used : IModel(net.minecraftforge.client.model.IModel) IBlockState(net.minecraft.block.state.IBlockState) Nonnull(javax.annotation.Nonnull) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) EnumFacing(net.minecraft.util.EnumFacing) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation) ItemOverrideList(net.minecraft.client.renderer.block.model.ItemOverrideList) Block(net.minecraft.block.Block) ITropicraftBlock(net.tropicraft.core.common.block.ITropicraftBlock) ItemOverrideList(net.minecraft.client.renderer.block.model.ItemOverrideList) NonNullList(net.minecraft.util.NonNullList) List(java.util.List) BlockRenderLayer(net.minecraft.util.BlockRenderLayer) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 82 with ModelResourceLocation

use of net.minecraft.client.renderer.block.model.ModelResourceLocation in project EnderIO by SleepyTrousers.

the class ItemModelRegistry method bakeModels.

@SubscribeEvent()
public void bakeModels(@Nonnull ModelBakeEvent event) {
    for (Entry<ModelResourceLocation, Registry> entry : registries.entrySet()) {
        final ModelResourceLocation resource = entry.getKey();
        if (resource != null) {
            IBakedModel model = event.getModelRegistry().getObject(resource);
            final Registry registry = entry.getValue();
            if (registry != null && model != null) {
                event.getModelRegistry().putObject(resource, registry.wrap(model));
            }
        }
    }
}
Also used : ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 83 with ModelResourceLocation

use of net.minecraft.client.renderer.block.model.ModelResourceLocation in project EnderIO by SleepyTrousers.

the class SmartModelAttacher method registerBlockItemModels.

/**
 * Registers the default ModelResourceLocation for the items of all blocks that have registered for MachineSmartModel-based rendering.
 * <p>
 * For items that have subtypes, all subtypes are registered. All subtypes are registered to the same model, as the smart model can be damage-aware.
 */
@SideOnly(Side.CLIENT)
public static void registerBlockItemModels() {
    for (RegistrationHolder<?, ?> holder : blocks) {
        Block block = holder.block;
        Registerable modObject = ModObjectRegistry.getModObject(holder.block);
        if (modObject == null) {
            Log.debug("Block " + block + " has no modObject. What?");
        } else {
            Item item = modObject.getItem();
            if (item instanceof IHaveRenderers || block instanceof IHaveRenderers) {
                // Nothing to do for us, the item/block handles it for itself
                Log.debug(block.getClass() + " handles its item registrations itself");
                if (item instanceof ICustomSubItems || block instanceof ICustomSubItems) {
                    throw new RuntimeException(block.getClass() + " implements both IHaveRenderers and ICustomSubItems");
                }
            } else if (block instanceof IDefaultRenderers) {
                // Nothing to do for us, the block wants ClientProxy to handle it
                Log.debug(block.getClass() + " has default item registrations");
                if (item instanceof ICustomSubItems || block instanceof ICustomSubItems) {
                    throw new RuntimeException(block.getClass() + " implements both IDefaultRenderers and ICustomSubItems");
                }
            } else if (item != null && item != Items.AIR) {
                @Nonnull final ResourceLocation registryName = item instanceof ICustomItemResourceLocation ? ((ICustomItemResourceLocation) item).getRegistryNameForCustomModelResourceLocation() : NullHelper.notnullF(item.getRegistryName(), "Item.getItemFromBlock() returned an unregistered item");
                ModelResourceLocation location = new ModelResourceLocation(registryName, "inventory");
                if (item.getHasSubtypes()) {
                    NNList<ItemStack> subItems;
                    if (item instanceof ICustomSubItems) {
                        subItems = ((ICustomSubItems) item).getSubItems();
                    } else if (block instanceof ICustomSubItems) {
                        subItems = ((ICustomSubItems) block).getSubItems();
                    } else {
                        throw new RuntimeException(block.getClass() + " has subitems but it does not implement ICustomSubItems");
                    }
                    for (ItemStack itemStack : subItems) {
                        Log.debug("Registering RL " + location + " for " + itemStack);
                        ModelLoader.setCustomModelResourceLocation(item, itemStack.getItemDamage(), location);
                    }
                } else {
                    Log.debug("Registering RL " + location + " for " + item);
                    ModelLoader.setCustomModelResourceLocation(item, 0, location);
                }
            } else {
                Log.debug("Block " + block + " has no item, is it intended?");
            }
        }
    }
}
Also used : ICustomSubItems(crazypants.enderio.base.render.ICustomSubItems) Nonnull(javax.annotation.Nonnull) IDefaultRenderers(crazypants.enderio.base.render.IDefaultRenderers) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) Item(net.minecraft.item.Item) ITintedItem(crazypants.enderio.base.render.ITintedItem) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ICustomItemResourceLocation(crazypants.enderio.base.render.ICustomItemResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation) ITintedBlock(crazypants.enderio.base.render.ITintedBlock) Block(net.minecraft.block.Block) Registerable(crazypants.enderio.base.init.IModObject.Registerable) IHaveRenderers(crazypants.enderio.base.render.IHaveRenderers) ICustomItemResourceLocation(crazypants.enderio.base.render.ICustomItemResourceLocation) ItemStack(net.minecraft.item.ItemStack) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 84 with ModelResourceLocation

use of net.minecraft.client.renderer.block.model.ModelResourceLocation in project EnderIO by SleepyTrousers.

the class ItemEnderface method registerVariant.

private void registerVariant(@Nonnull IModObject mo, int meta, String name) {
    ModelLoader.setCustomModelResourceLocation(this, meta, new ModelResourceLocation(mo.getRegistryName(), "variant=" + name));
    // Non-glint version
    ModelLoader.setCustomModelResourceLocation(this, meta | (1 << 4), new ModelResourceLocation(mo.getRegistryName(), "variant=" + name));
}
Also used : ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation)

Example 85 with ModelResourceLocation

use of net.minecraft.client.renderer.block.model.ModelResourceLocation in project EnderIO by SleepyTrousers.

the class BlockDecoration method registerRenderers.

@Override
@SideOnly(Side.CLIENT)
public void registerRenderers(@Nonnull IModObject modObject) {
    Item item = Item.getItemFromBlock(this);
    Map<IBlockState, ModelResourceLocation> locations = new DefaultStateMapper().putStateModelLocations(this);
    NNIterator<EnumDecoBlock> iterator = NNList.of(EnumDecoBlock.class).iterator();
    while (iterator.hasNext()) {
        EnumDecoBlock type = iterator.next();
        IBlockState state = getDefaultState().withProperty(EnumDecoBlock.TYPE, type);
        ModelResourceLocation mrl = locations.get(state);
        if (mrl != null) {
            ModelLoader.setCustomModelResourceLocation(item, EnumDecoBlock.getMetaFromType(type), mrl);
        }
    }
}
Also used : Item(net.minecraft.item.Item) IBlockState(net.minecraft.block.state.IBlockState) DefaultStateMapper(net.minecraft.client.renderer.block.statemap.DefaultStateMapper) EnumDecoBlock(crazypants.enderio.base.render.property.EnumDecoBlock) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Aggregations

ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)320 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)129 ResourceLocation (net.minecraft.util.ResourceLocation)101 Item (net.minecraft.item.Item)55 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)52 IBlockState (net.minecraft.block.state.IBlockState)48 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)26 ArrayList (java.util.ArrayList)25 Block (net.minecraft.block.Block)21 StateMapperBase (net.minecraft.client.renderer.block.statemap.StateMapperBase)20 ItemStack (net.minecraft.item.ItemStack)16 EnumFacing (net.minecraft.util.EnumFacing)13 Map (java.util.Map)12 ItemMeshDefinition (net.minecraft.client.renderer.ItemMeshDefinition)11 IModel (net.minecraftforge.client.model.IModel)11 Nonnull (javax.annotation.Nonnull)10 IProperty (net.minecraft.block.properties.IProperty)9 Side (net.minecraftforge.fml.relauncher.Side)9 DefaultStateMapper (net.minecraft.client.renderer.block.statemap.DefaultStateMapper)8 RenderItem (net.minecraft.client.renderer.RenderItem)7