mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-22 13:09:59 +00:00
load languages on the server as well as the client, and fix up a bunch of data packs.
This commit is contained in:
1 parent
1c9b5fae5e
commit
e199e78a4f
24 files changed
+252
-157
No files matched your search
@@ -24,9 +24,7 @@ import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.resources.DownloadingPackFinder;
|
||||
import net.minecraft.client.resources.ResourcePackInfoClient;
|
||||
import net.minecraft.resources.IReloadableResourceManager;
|
||||
import net.minecraft.resources.IResourcePack;
|
||||
import net.minecraft.resources.ResourcePackList;
|
||||
import net.minecraft.resources.data.IMetadataSectionSerializer;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.fml.LoadingFailedException;
|
||||
@@ -34,12 +32,8 @@ import net.minecraftforge.fml.LogicalSidedProvider;
|
||||
import net.minecraftforge.fml.ModLoader;
|
||||
import net.minecraftforge.fml.SidedProvider;
|
||||
import net.minecraftforge.fml.VersionChecker;
|
||||
import net.minecraftforge.fml.client.gui.GuiNotification;
|
||||
import net.minecraftforge.fml.client.gui.LoadingErrorScreen;
|
||||
import net.minecraftforge.fml.client.registry.RenderingRegistry;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import net.minecraftforge.fml.packs.ResourcePackLoader;
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class ClientModLoader
|
||||
|
||||
@@ -1,105 +0,0 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2018.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.client;
|
||||
|
||||
import net.minecraft.resources.AbstractResourcePack;
|
||||
import net.minecraft.resources.ResourcePackType;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.loading.moddiscovery.ModFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ModFileResourcePack extends AbstractResourcePack
|
||||
{
|
||||
private final ModFile modFile;
|
||||
|
||||
public ModFileResourcePack(final ModFile modFile)
|
||||
{
|
||||
super(new File("dummy"));
|
||||
this.modFile = modFile;
|
||||
}
|
||||
|
||||
public ModFile getModFile() {
|
||||
return this.modFile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return modFile.getFileName();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InputStream getInputStream(String name) throws IOException
|
||||
{
|
||||
return Files.newInputStream(modFile.getLocator().findPath(modFile, name));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean resourceExists(String name)
|
||||
{
|
||||
return Files.exists(modFile.getLocator().findPath(modFile, name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ResourceLocation> getAllResourceLocations(ResourcePackType type, String pathIn, int maxDepth, Predicate<String> filter)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
return Files.walk(modFile.getLocator().findPath(modFile, type.getDirectoryName())).
|
||||
filter(path -> !path.toString().endsWith(".mcmeta")).
|
||||
filter(path -> path.getNameCount() > 2 && pathIn.equals(path.getName(2).toString())).
|
||||
filter(path -> filter.test(path.subpath(3, Math.min(maxDepth+3, path.getNameCount())).toString())).
|
||||
map(path -> new ResourceLocation(path.getName(1).toString(),path.subpath(3,Math.min(maxDepth+3, path.getNameCount())).toString())).
|
||||
collect(Collectors.toList());
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getResourceNamespaces(ResourcePackType type)
|
||||
{
|
||||
try {
|
||||
return Files.walk(modFile.getLocator().findPath(modFile, type.getDirectoryName()),1).map(p->p.getFileName().toString()).collect(Collectors.toSet());
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
return Collections.emptySet();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2018.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.client;
|
||||
|
||||
import net.minecraft.resources.AbstractResourcePack;
|
||||
import net.minecraft.resources.FilePack;
|
||||
import net.minecraft.resources.FolderPack;
|
||||
import net.minecraft.resources.IResourcePack;
|
||||
import net.minecraft.resources.ResourcePackInfo;
|
||||
import net.minecraft.resources.ResourcePackList;
|
||||
import net.minecraftforge.fml.ModList;
|
||||
import net.minecraftforge.fml.loading.FMLLoader;
|
||||
import net.minecraftforge.fml.loading.moddiscovery.ModFile;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ResourcePackLoader
|
||||
{
|
||||
private static Map<ModFile, ModFileResourcePack> modResourcePacks;
|
||||
private static AbstractResourcePack forgePack;
|
||||
private static ResourcePackList<?> resourcePackList;
|
||||
|
||||
public static IResourcePack getResourcePackFor(String modId)
|
||||
{
|
||||
if (modId == "forge") return forgePack;
|
||||
else return modResourcePacks.get(ModList.get().getModFileById(modId).getFile());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T extends ResourcePackInfo> T getResourcePackInfo(String modId) {
|
||||
return (T)resourcePackList.getPackInfo(modId);
|
||||
}
|
||||
|
||||
public static <T extends ResourcePackInfo> void loadResourcePacks(ResourcePackList<T> resourcePacks) {
|
||||
resourcePackList = resourcePacks;
|
||||
modResourcePacks = ModList.get().getModFiles().stream().
|
||||
map(mf -> new ModFileResourcePack(mf.getFile())).
|
||||
collect(Collectors.toMap(ModFileResourcePack::getModFile, Function.identity()));
|
||||
forgePack = Files.isDirectory(FMLLoader.getForgePath()) ?
|
||||
new FolderPack(FMLLoader.getForgePath().toFile()) :
|
||||
new FilePack(FMLLoader.getForgePath().toFile());
|
||||
resourcePacks.addPackFinder(new ModPackFinder());
|
||||
}
|
||||
|
||||
private static class ModPackFinder implements net.minecraft.resources.IPackFinder
|
||||
{
|
||||
@Override
|
||||
public <T extends ResourcePackInfo> void addPackInfosToMap(Map<String, T> packList, ResourcePackInfo.IFactory<T> factory)
|
||||
{
|
||||
packList.put("forge", ResourcePackInfo.func_195793_a("forge", true, ()->forgePack, factory, ResourcePackInfo.Priority.BOTTOM));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,7 @@ import net.minecraft.util.text.TextComponentString;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
import net.minecraftforge.fml.*;
|
||||
import net.minecraftforge.fml.client.ConfigGuiHandler;
|
||||
import net.minecraftforge.fml.client.ResourcePackLoader;
|
||||
import net.minecraftforge.fml.packs.ResourcePackLoader;
|
||||
import net.minecraftforge.fml.language.IModInfo;
|
||||
import net.minecraftforge.fml.loading.StringUtils;
|
||||
import net.minecraftforge.fml.loading.moddiscovery.ModInfo;
|
||||
|
||||
Reference in new issue
Block a user