Search in sources :

Example 1 with ProgressBar

use of net.minecraftforge.fml.common.ProgressManager.ProgressBar in project MinecraftForge by MinecraftForge.

the class ModelLoader method loadItemModels.

@Override
protected void loadItemModels() {
    // register model for the universal bucket, if it exists
    if (FluidRegistry.isUniversalBucketEnabled()) {
        setBucketModelDefinition(ForgeModContainer.getInstance().universalBucket);
    }
    registerVariantNames();
    List<Item> items = Lists.newArrayList(Iterables.filter(Item.REGISTRY, new Predicate<Item>() {

        public boolean apply(Item item) {
            return item.getRegistryName() != null;
        }
    }));
    Collections.sort(items, new Comparator<Item>() {

        public int compare(Item i1, Item i2) {
            return i1.getRegistryName().toString().compareTo(i2.getRegistryName().toString());
        }
    });
    ProgressBar itemBar = ProgressManager.push("ModelLoader: items", items.size());
    for (Item item : items) {
        itemBar.step(item.getRegistryName().toString());
        for (String s : getVariantNames(item)) {
            ResourceLocation file = getItemLocation(s);
            ModelResourceLocation memory = getInventoryVariant(s);
            IModel model = ModelLoaderRegistry.getMissingModel();
            Exception exception = null;
            try {
                model = ModelLoaderRegistry.getModel(file);
            } catch (Exception normalException) {
                // try blockstate json if the item model is missing
                FMLLog.fine("Item json isn't found for '" + memory + "', trying to load the variant from the blockstate json");
                try {
                    model = ModelLoaderRegistry.getModel(memory);
                } catch (Exception blockstateException) {
                    exception = new ItemLoadingException("Could not load item model either from the normal location " + file + " or from the blockstate", normalException, blockstateException);
                }
            }
            if (exception != null) {
                storeException(memory, exception);
                model = ModelLoaderRegistry.getMissingModel(memory, exception);
            }
            stateModels.put(memory, model);
        }
    }
    ProgressManager.pop(itemBar);
    // replace vanilla bucket models if desired. done afterwards for performance reasons
    if (ForgeModContainer.replaceVanillaBucketModel) {
        // ensure the bucket model is loaded
        if (!stateModels.containsKey(ModelDynBucket.LOCATION)) {
            // load forges blockstate json for it
            try {
                registerVariant(getModelBlockDefinition(ModelDynBucket.LOCATION), ModelDynBucket.LOCATION);
            } catch (Exception exception) {
                FMLLog.getLogger().error("Could not load the forge bucket model from the blockstate", exception);
                return;
            }
        }
        // empty bucket
        for (String s : getVariantNames(Items.BUCKET)) {
            ModelResourceLocation memory = getInventoryVariant(s);
            IModel model = ModelLoaderRegistry.getModelOrMissing(new ResourceLocation(ForgeVersion.MOD_ID, "item/bucket"));
            // only on successful load, otherwise continue using the old model
            if (model != getMissingModel()) {
                stateModels.put(memory, model);
            }
        }
        setBucketModel(Items.WATER_BUCKET);
        setBucketModel(Items.LAVA_BUCKET);
        // milk bucket only replaced if some mod adds milk
        if (FluidRegistry.isFluidRegistered("milk")) {
            // can the milk be put into a bucket?
            Fluid milk = FluidRegistry.getFluid("milk");
            FluidStack milkStack = new FluidStack(milk, Fluid.BUCKET_VOLUME);
            IFluidHandler bucketHandler = FluidUtil.getFluidHandler(new ItemStack(Items.BUCKET));
            if (bucketHandler != null && bucketHandler.fill(milkStack, false) == Fluid.BUCKET_VOLUME) {
                setBucketModel(Items.MILK_BUCKET);
            }
        } else {
            // milk bucket if no milk fluid is present
            for (String s : getVariantNames(Items.MILK_BUCKET)) {
                ModelResourceLocation memory = getInventoryVariant(s);
                IModel model = ModelLoaderRegistry.getModelOrMissing(new ResourceLocation(ForgeVersion.MOD_ID, "item/bucket_milk"));
                // only on successful load, otherwise continue using the old model
                if (model != getMissingModel()) {
                    stateModels.put(memory, model);
                }
            }
        }
    }
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) Fluid(net.minecraftforge.fluids.Fluid) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) MissingVariantException(net.minecraft.client.renderer.block.model.ModelBlockDefinition.MissingVariantException) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) Predicate(com.google.common.base.Predicate) Item(net.minecraft.item.Item) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation) ItemStack(net.minecraft.item.ItemStack) ProgressBar(net.minecraftforge.fml.common.ProgressManager.ProgressBar)

Example 2 with ProgressBar

use of net.minecraftforge.fml.common.ProgressManager.ProgressBar in project MinecraftForge by MinecraftForge.

the class ModelLoader method setupModelRegistry.

@Override
public IRegistry<ModelResourceLocation, IBakedModel> setupModelRegistry() {
    isLoading = true;
    loadBlocks();
    loadVariantItemModels();
    missingModel = ModelLoaderRegistry.getMissingModel();
    stateModels.put(MODEL_MISSING, missingModel);
    final Set<ResourceLocation> textures = Sets.newHashSet(ModelLoaderRegistry.getTextures());
    textures.remove(TextureMap.LOCATION_MISSING_TEXTURE);
    textures.addAll(LOCATIONS_BUILTIN_TEXTURES);
    textureMap.loadSprites(resourceManager, new ITextureMapPopulator() {

        public void registerSprites(TextureMap map) {
            for (ResourceLocation t : textures) {
                map.registerSprite(t);
            }
        }
    });
    IBakedModel missingBaked = missingModel.bake(missingModel.getDefaultState(), DefaultVertexFormats.ITEM, DefaultTextureGetter.INSTANCE);
    Map<IModel, IBakedModel> bakedModels = Maps.newHashMap();
    HashMultimap<IModel, ModelResourceLocation> models = HashMultimap.create();
    Multimaps.invertFrom(Multimaps.forMap(stateModels), models);
    if (firstLoad) {
        firstLoad = false;
        for (ModelResourceLocation mrl : stateModels.keySet()) {
            bakedRegistry.putObject(mrl, missingBaked);
        }
        return bakedRegistry;
    }
    ProgressBar bakeBar = ProgressManager.push("ModelLoader: baking", models.keySet().size());
    for (IModel model : models.keySet()) {
        bakeBar.step("[" + Joiner.on(", ").join(models.get(model)) + "]");
        if (model == getMissingModel()) {
            bakedModels.put(model, missingBaked);
        } else {
            bakedModels.put(model, model.bake(model.getDefaultState(), DefaultVertexFormats.ITEM, DefaultTextureGetter.INSTANCE));
        }
    }
    ProgressManager.pop(bakeBar);
    for (Entry<ModelResourceLocation, IModel> e : stateModels.entrySet()) {
        bakedRegistry.putObject(e.getKey(), bakedModels.get(e.getValue()));
    }
    return bakedRegistry;
}
Also used : TextureMap(net.minecraft.client.renderer.texture.TextureMap) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation) ITextureMapPopulator(net.minecraft.client.renderer.texture.ITextureMapPopulator) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ProgressBar(net.minecraftforge.fml.common.ProgressManager.ProgressBar)

Example 3 with ProgressBar

use of net.minecraftforge.fml.common.ProgressManager.ProgressBar in project MinecraftForge by MinecraftForge.

the class LoadController method propogateStateMessage.

@Subscribe
public void propogateStateMessage(FMLEvent stateEvent) {
    if (stateEvent instanceof FMLPreInitializationEvent) {
        modObjectList = buildModObjectList();
    }
    ProgressBar bar = ProgressManager.push(stateEvent.description(), activeModList.size(), true);
    for (ModContainer mc : activeModList) {
        bar.step(mc.getName());
        sendEventToModContainer(stateEvent, mc);
    }
    ProgressManager.pop(bar);
}
Also used : FMLPreInitializationEvent(net.minecraftforge.fml.common.event.FMLPreInitializationEvent) ProgressBar(net.minecraftforge.fml.common.ProgressManager.ProgressBar) Subscribe(com.google.common.eventbus.Subscribe)

Example 4 with ProgressBar

use of net.minecraftforge.fml.common.ProgressManager.ProgressBar in project BiomeTweaker by superckl.

the class BiomeTweaker method onPostInit.

@EventHandler
public void onPostInit(final FMLPostInitializationEvent e) {
    final ProgressBar bar = ProgressManager.push("BiomeTweaker PostInitialization", 2, true);
    bar.step("Post-Initializing Integration");
    IntegrationManager.INSTANCE.postInit();
    bar.step("Applying scripts");
    this.commandManager.applyCommandsFor(ApplicationStage.POST_INIT);
    ProgressManager.pop(bar);
}
Also used : ProgressBar(net.minecraftforge.fml.common.ProgressManager.ProgressBar) EventHandler(net.minecraftforge.fml.common.Mod.EventHandler)

Example 5 with ProgressBar

use of net.minecraftforge.fml.common.ProgressManager.ProgressBar in project BiomeTweaker by superckl.

the class BiomeTweaker method onInit.

@EventHandler
public void onInit(final FMLInitializationEvent e) throws InterruptedException {
    final ProgressBar bar = ProgressManager.push("BiomeTweaker Initialization", 2, true);
    bar.step("Initializing Integration");
    IntegrationManager.INSTANCE.init();
    bar.step("Applying scripts");
    this.commandManager.applyCommandsFor(ApplicationStage.INIT);
    ProgressManager.pop(bar);
}
Also used : ProgressBar(net.minecraftforge.fml.common.ProgressManager.ProgressBar) EventHandler(net.minecraftforge.fml.common.Mod.EventHandler)

Aggregations

ProgressBar (net.minecraftforge.fml.common.ProgressManager.ProgressBar)9 ResourceLocation (net.minecraft.util.ResourceLocation)4 EventHandler (net.minecraftforge.fml.common.Mod.EventHandler)4 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)3 Predicate (com.google.common.base.Predicate)2 File (java.io.File)2 Subscribe (com.google.common.eventbus.Subscribe)1 FileReader (java.io.FileReader)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 PrintWriter (java.io.PrintWriter)1 UncaughtExceptionHandler (java.lang.Thread.UncaughtExceptionHandler)1 Properties (java.util.Properties)1 BasicScriptCommandManager (me.superckl.api.superscript.script.command.BasicScriptCommandManager)1 Config (me.superckl.biometweaker.config.Config)1 Block (net.minecraft.block.Block)1 Minecraft (net.minecraft.client.Minecraft)1 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)1 ModelBlock (net.minecraft.client.renderer.block.model.ModelBlock)1