Search in sources :

Example 11 with ResourceLocation

use of net.minecraft.util.ResourceLocation in project MinecraftForge by MinecraftForge.

the class ModelLoaderRegistry method getModel.

/**
     * Primary method to get IModel instances.
     * ResourceLocation argument will be passed directly to the custom model loaders,
     * ModelResourceLocation argument will be loaded through the blockstate system.
     */
public static IModel getModel(ResourceLocation location) throws Exception {
    IModel model;
    if (cache.containsKey(location))
        return cache.get(location);
    for (ResourceLocation loading : loadingModels) {
        if (location.getClass() == loading.getClass() && location.equals(loading)) {
            throw new LoaderException("circular model dependencies, stack: [" + Joiner.on(", ").join(loadingModels) + "]");
        }
    }
    loadingModels.addLast(location);
    try {
        ResourceLocation actual = getActualLocation(location);
        ICustomModelLoader accepted = null;
        for (ICustomModelLoader loader : loaders) {
            try {
                if (loader.accepts(actual)) {
                    if (accepted != null) {
                        throw new LoaderException(String.format("2 loaders (%s and %s) want to load the same model %s", accepted, loader, location));
                    }
                    accepted = loader;
                }
            } catch (Exception e) {
                throw new LoaderException(String.format("Exception checking if model %s can be loaded with loader %s, skipping", location, loader), e);
            }
        }
        // no custom loaders found, try vanilla ones
        if (accepted == null) {
            if (VariantLoader.INSTANCE.accepts(actual)) {
                accepted = VariantLoader.INSTANCE;
            } else if (VanillaLoader.INSTANCE.accepts(actual)) {
                accepted = VanillaLoader.INSTANCE;
            }
        }
        if (accepted == null) {
            throw new LoaderException("no suitable loader found for the model " + location + ", skipping");
        }
        try {
            model = accepted.loadModel(actual);
        } catch (Exception e) {
            throw new LoaderException(String.format("Exception loading model %s with loader %s, skipping", location, accepted), e);
        }
        if (model == getMissingModel()) {
            throw new LoaderException(String.format("Loader %s returned missing model while loading model %s", accepted, location));
        }
        if (model == null) {
            throw new LoaderException(String.format("Loader %s returned null while loading model %s", accepted, location));
        }
        textures.addAll(model.getTextures());
    } finally {
        ResourceLocation popLoc = loadingModels.removeLast();
        if (popLoc != location) {
            throw new IllegalStateException("Corrupted loading model stack: " + popLoc + " != " + location);
        }
    }
    cache.put(location, model);
    for (ResourceLocation dep : model.getDependencies()) {
        getModelOrMissing(dep);
    }
    return model;
}
Also used : ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation)

Example 12 with ResourceLocation

use of net.minecraft.util.ResourceLocation 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 13 with ResourceLocation

use of net.minecraft.util.ResourceLocation in project MinecraftForge by MinecraftForge.

the class FMLContainer method getDataForWriting.

@Override
public NBTTagCompound getDataForWriting(SaveHandler handler, WorldInfo info) {
    NBTTagCompound fmlData = new NBTTagCompound();
    NBTTagList modList = new NBTTagList();
    for (ModContainer mc : Loader.instance().getActiveModList()) {
        NBTTagCompound mod = new NBTTagCompound();
        mod.setString("ModId", mc.getModId());
        mod.setString("ModVersion", mc.getVersion());
        modList.appendTag(mod);
    }
    fmlData.setTag("ModList", modList);
    NBTTagCompound registries = new NBTTagCompound();
    fmlData.setTag("Registries", registries);
    FMLLog.fine("Gathering id map for writing to world save %s", info.getWorldName());
    PersistentRegistryManager.GameDataSnapshot dataSnapshot = PersistentRegistryManager.takeSnapshot();
    for (Map.Entry<ResourceLocation, PersistentRegistryManager.GameDataSnapshot.Entry> e : dataSnapshot.entries.entrySet()) {
        NBTTagCompound data = new NBTTagCompound();
        registries.setTag(e.getKey().toString(), data);
        NBTTagList ids = new NBTTagList();
        for (Entry<ResourceLocation, Integer> item : e.getValue().ids.entrySet()) {
            NBTTagCompound tag = new NBTTagCompound();
            tag.setString("K", item.getKey().toString());
            tag.setInteger("V", item.getValue());
            ids.appendTag(tag);
        }
        data.setTag("ids", ids);
        NBTTagList aliases = new NBTTagList();
        for (Entry<ResourceLocation, ResourceLocation> entry : e.getValue().aliases.entrySet()) {
            NBTTagCompound tag = new NBTTagCompound();
            tag.setString("K", entry.getKey().toString());
            tag.setString("V", entry.getValue().toString());
            aliases.appendTag(tag);
        }
        data.setTag("aliases", aliases);
        NBTTagList subs = new NBTTagList();
        for (ResourceLocation entry : e.getValue().substitutions) {
            NBTTagCompound tag = new NBTTagCompound();
            tag.setString("K", entry.toString());
            subs.appendTag(tag);
        }
        data.setTag("substitutions", subs);
        int[] blocked = new int[e.getValue().blocked.size()];
        int idx = 0;
        for (Integer i : e.getValue().blocked) {
            blocked[idx++] = i;
        }
        data.setIntArray("blocked", blocked);
        NBTTagList dummied = new NBTTagList();
        for (ResourceLocation entry : e.getValue().dummied) {
            NBTTagCompound tag = new NBTTagCompound();
            tag.setString("K", entry.toString());
            dummied.appendTag(tag);
        }
        data.setTag("dummied", dummied);
    }
    return fmlData;
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) PersistentRegistryManager(net.minecraftforge.fml.common.registry.PersistentRegistryManager) NBTTagList(net.minecraft.nbt.NBTTagList) Entry(java.util.Map.Entry) ResourceLocation(net.minecraft.util.ResourceLocation) Map(java.util.Map)

Example 14 with ResourceLocation

use of net.minecraft.util.ResourceLocation in project MinecraftForge by MinecraftForge.

the class FMLClientHandler method logMissingTextureErrors.

public void logMissingTextureErrors() {
    if (missingTextures.isEmpty() && brokenTextures.isEmpty()) {
        return;
    }
    Logger logger = LogManager.getLogger("TEXTURE ERRORS");
    logger.error(Strings.repeat("+=", 25));
    logger.error("The following texture errors were found.");
    Map<String, FallbackResourceManager> resManagers = ObfuscationReflectionHelper.getPrivateValue(SimpleReloadableResourceManager.class, (SimpleReloadableResourceManager) Minecraft.getMinecraft().getResourceManager(), "domainResourceManagers", "field_110548" + "_a");
    for (String resourceDomain : badTextureDomains) {
        Set<ResourceLocation> missing = missingTextures.get(resourceDomain);
        logger.error(Strings.repeat("=", 50));
        logger.error("  DOMAIN {}", resourceDomain);
        logger.error(Strings.repeat("-", 50));
        logger.error("  domain {} is missing {} texture{}", resourceDomain, missing.size(), missing.size() != 1 ? "s" : "");
        FallbackResourceManager fallbackResourceManager = resManagers.get(resourceDomain);
        if (fallbackResourceManager == null) {
            logger.error("    domain {} is missing a resource manager - it is probably a side-effect of automatic texture processing", resourceDomain);
        } else {
            List<IResourcePack> resPacks = ObfuscationReflectionHelper.getPrivateValue(FallbackResourceManager.class, fallbackResourceManager, "resourcePacks", "field_110540" + "_a");
            logger.error("    domain {} has {} location{}:", resourceDomain, resPacks.size(), resPacks.size() != 1 ? "s" : "");
            for (IResourcePack resPack : resPacks) {
                if (resPack instanceof FMLContainerHolder) {
                    FMLContainerHolder containerHolder = (FMLContainerHolder) resPack;
                    ModContainer fmlContainer = containerHolder.getFMLContainer();
                    logger.error("      mod {} resources at {}", fmlContainer.getModId(), fmlContainer.getSource().getPath());
                } else if (resPack instanceof AbstractResourcePack) {
                    AbstractResourcePack resourcePack = (AbstractResourcePack) resPack;
                    File resPath = ObfuscationReflectionHelper.getPrivateValue(AbstractResourcePack.class, resourcePack, "resourcePackFile", "field_110597" + "_b");
                    logger.error("      resource pack at path {}", resPath.getPath());
                } else {
                    logger.error("      unknown resourcepack type {} : {}", resPack.getClass().getName(), resPack.getPackName());
                }
            }
        }
        logger.error(Strings.repeat("-", 25));
        if (missingTextures.containsKey(resourceDomain)) {
            logger.error("    The missing resources for domain {} are:", resourceDomain);
            for (ResourceLocation rl : missing) {
                logger.error("      {}", rl.getResourcePath());
            }
            logger.error(Strings.repeat("-", 25));
        }
        if (!brokenTextures.containsRow(resourceDomain)) {
            logger.error("    No other errors exist for domain {}", resourceDomain);
        } else {
            logger.error("    The following other errors were reported for domain {}:", resourceDomain);
            Map<String, Set<ResourceLocation>> resourceErrs = brokenTextures.row(resourceDomain);
            for (String error : resourceErrs.keySet()) {
                logger.error(Strings.repeat("-", 25));
                logger.error("    Problem: {}", error);
                for (ResourceLocation rl : resourceErrs.get(error)) {
                    logger.error("      {}", rl.getResourcePath());
                }
            }
        }
        logger.error(Strings.repeat("=", 50));
    }
    logger.error(Strings.repeat("+=", 25));
}
Also used : Set(java.util.Set) ForgeModContainer(net.minecraftforge.common.ForgeModContainer) ModContainer(net.minecraftforge.fml.common.ModContainer) DummyModContainer(net.minecraftforge.fml.common.DummyModContainer) AbstractResourcePack(net.minecraft.client.resources.AbstractResourcePack) Logger(org.apache.logging.log4j.Logger) FMLContainerHolder(net.minecraftforge.fml.common.FMLContainerHolder) IResourcePack(net.minecraft.client.resources.IResourcePack) ResourceLocation(net.minecraft.util.ResourceLocation) FallbackResourceManager(net.minecraft.client.resources.FallbackResourceManager) File(java.io.File)

Example 15 with ResourceLocation

use of net.minecraft.util.ResourceLocation in project MinecraftForge by MinecraftForge.

the class FMLControlledNamespacedRegistry method register.

// IForgeRegistry: Modders should only interfaces with these methods
@Override
public void register(@Nonnull I value) {
    ResourceLocation key = value.getRegistryName();
    if (key == null) {
        FMLLog.severe("Attempted to register a entry with a null name: %s", value);
        throw new NullPointerException(String.format("Attempted to register a entry with a null name: %s", value));
    }
    add(-1, key, value);
}
Also used : ResourceLocation(net.minecraft.util.ResourceLocation)

Aggregations

ResourceLocation (net.minecraft.util.ResourceLocation)272 ItemStack (net.minecraft.item.ItemStack)51 Block (net.minecraft.block.Block)47 Item (net.minecraft.item.Item)32 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)31 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)30 IBlockState (net.minecraft.block.state.IBlockState)17 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)15 ArrayList (java.util.ArrayList)14 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)14 Map (java.util.Map)11 EntityPlayer (net.minecraft.entity.player.EntityPlayer)11 ShaderLayer (blusunrize.immersiveengineering.api.shader.ShaderCase.ShaderLayer)10 IOException (java.io.IOException)10 TileEntity (net.minecraft.tileentity.TileEntity)9 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)8 EnumFacing (net.minecraft.util.EnumFacing)8 BlockPos (net.minecraft.util.math.BlockPos)8 Random (java.util.Random)7 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)7