本文整理了Java中net.minecraft.client.Minecraft.getResourcePackRepository()
方法的一些代码示例,展示了Minecraft.getResourcePackRepository()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Minecraft.getResourcePackRepository()
方法的具体详情如下:
包路径:net.minecraft.client.Minecraft
类名称:Minecraft
方法名:getResourcePackRepository
暂无
代码示例来源:origin: CFPAOrg/I18nUpdateMod
private boolean intervalDaysCheck() {
File f = new File(Minecraft.getMinecraft().getResourcePackRepository().getDirResourcepacks().toString(), I18nConfig.download.langPackName);
try {
return (System.currentTimeMillis() - f.lastModified()) > (I18nConfig.download.maxDay * 24 * 3600 * 1000);
} catch (Throwable e) {
logger.error("检查文件日期失败", e);
return false;
}
}
代码示例来源:origin: CFPAOrg/I18nUpdateMod
private boolean isResourcePackExist() {
File f = new File(Minecraft.getMinecraft().getResourcePackRepository().getDirResourcepacks().toString(), I18nConfig.download.langPackName);
return f.exists();
}
代码示例来源:origin: CFPAOrg/I18nUpdateMod
private boolean checkLength() {
File f = new File(Minecraft.getMinecraft().getResourcePackRepository().getDirResourcepacks().toString(), I18nConfig.download.langPackName);
try {
URL url = new URL(I18nConfig.download.langPackURL);
return url.openConnection().getContentLengthLong() == f.length();
} catch (Throwable e) {
logger.error("检查文件大小失败", e);
return false;
}
}
代码示例来源:origin: CFPAOrg/I18nUpdateMod
/**
* 检索资源包列表,获取语言文件地址
*
* @return 获取的语言文件列表
*/
private List<String> getLangpackName() {
List<String> outputModid = new ArrayList<>();
File resourcepacksDir = new File(Minecraft.getMinecraft().getResourcePackRepository().getDirResourcepacks().toString());
if (resourcepacksDir.exists() && resourcepacksDir.isDirectory()) {
for (File i : resourcepacksDir.listFiles()) {
Matcher matcher = Pattern.compile("resourcepacks" + Matcher.quoteReplacement(File.separator) + "(.*?)_tmp_resource_pack").matcher(i.toString());
while (matcher.find()) {
File transFile = new File(i.toString() + File.separator + "assets" + File.separator + matcher.group(1) + File.separator + "lang" + File.separator + "zh_cn.lang");
if (transFile.exists() && transFile.isFile()) {
outputModid.add(matcher.group(1));
}
}
}
}
return outputModid;
}
代码示例来源:origin: CFPAOrg/I18nUpdateMod
/**
* 构建资源包文件夹
*
* @param modid 想要下载的模组资源 id
* @return 是否构建成功
*/
private boolean cerateTempLangpack(String modid) {
// 构建文件夹
File tempDir = new File(String.format(Minecraft.getMinecraft().getResourcePackRepository().getDirResourcepacks().toString() + File.separator + "%s_tmp_resource_pack" + File.separator + "assets" + File.separator + "%s" + File.separator + "lang", modid, modid));
if (tempDir.exists() || !tempDir.mkdirs()) {
return false;
}
// 构建 pack.mcmeta
File tempPackFile = new File(String.format(Minecraft.getMinecraft().getResourcePackRepository().getDirResourcepacks().toString() + File.separator + "%s_tmp_resource_pack" + File.separator + "pack.mcmeta", modid));
String metaText = String.format("{\"pack\":{\"pack_format\":3,\"description\":\"临时汉化资源包,仅包含 %s 模组中英文文件\"}}", modid);
// 判定文件是否存在
if (tempPackFile.exists()) {
return false;
}
// 写入数据
try {
FileUtils.write(tempPackFile, metaText, StandardCharsets.UTF_8);
} catch (IOException ioe) {
return false;
}
// 走到了这一步,恭喜你
return true;
}
代码示例来源:origin: CFPAOrg/I18nUpdateMod
List<String> en_us = FileUtils.readLines(new File(String.format(Minecraft.getMinecraft().getResourcePackRepository().getDirResourcepacks().toString() + File.separator + "%s_tmp_resource_pack" + File.separator + "assets" + File.separator + "%s" + File.separator + "lang" + File.separator + "en_us.lang", modid, modid)), StandardCharsets.UTF_8);
List<String> zh_cn = FileUtils.readLines(new File(String.format(Minecraft.getMinecraft().getResourcePackRepository().getDirResourcepacks().toString() + File.separator + "%s_tmp_resource_pack" + File.separator + "assets" + File.separator + "%s" + File.separator + "lang" + File.separator + "zh_cn.lang", modid, modid)), StandardCharsets.UTF_8);
FileUtils.writeLines(new File(String.format(Minecraft.getMinecraft().getResourcePackRepository().getDirResourcepacks().toString() + File.separator + "%s_tmp_resource_pack" + File.separator + "assets" + File.separator + "%s" + File.separator + "lang" + File.separator + "zh_cn.lang", modid, modid)), "UTF-8", tmpFile, "\n", false);
代码示例来源:origin: CFPAOrg/I18nUpdateMod
private void reloadResources() {
Minecraft mc = Minecraft.getMinecraft();
GameSettings gameSettings = mc.gameSettings;
// 因为这时候资源包已经加载了,所以需要重新读取,重新加载
ResourcePackRepository resourcePackRepository = mc.getResourcePackRepository();
resourcePackRepository.updateRepositoryEntriesAll();
List<ResourcePackRepository.Entry> repositoryEntriesAll = resourcePackRepository.getRepositoryEntriesAll();
List<ResourcePackRepository.Entry> repositoryEntries = Lists.newArrayList();
Iterator<String> it = gameSettings.resourcePacks.iterator();
while (it.hasNext()) {
String packName = it.next();
for (ResourcePackRepository.Entry entry : repositoryEntriesAll) {
if (entry.getResourcePackName().equals(packName)) {
// packFormat 为 3,或者 incompatibleResourcePacks 条目中有的资源包才会加入
if (entry.getPackFormat() == 3 || gameSettings.incompatibleResourcePacks.contains(entry.getResourcePackName())) {
repositoryEntries.add(entry);
break;
}
// 否则移除
it.remove();
logger.warn("移除资源包 {},因为它无法兼容当前版本", entry.getResourcePackName());
}
}
}
resourcePackRepository.setRepositories(repositoryEntries);
}
代码示例来源:origin: CFPAOrg/I18nUpdateMod
@Override
public void install() {
super.install();
if (updateResourcePack) {
DownloadManager downloader = new DownloadManager(I18nConfig.download.langPackURL, I18nConfig.download.langPackName, Minecraft.getMinecraft().getResourcePackRepository().getDirResourcepacks().toString());
downloader.start("I18n-Download-Thread");
downloader.setSuccessTask(() -> {
setResourcesRepository();
Minecraft.getMinecraft().getLanguageManager().onResourceManagerReload(Minecraft.getMinecraft().getResourceManager());
DownloadInfoHelper.info.add("资源包更新成功。");
});
}
}
}
代码示例来源:origin: CFPAOrg/I18nUpdateMod
@Override
public void install() {
super.install();
if (updateResourcePack) {
DownloadManager downloader = new DownloadManager(I18nConfig.download.langPackURL, I18nConfig.download.langPackName, Minecraft.getMinecraft().getResourcePackRepository().getDirResourcepacks().toString());
DownloadWindow window = new DownloadWindow(downloader);
window.showWindow();
downloader.start("I18n-Download-Thread");
while (downloader.getStatus() == DownloadStatus.DOWNLOADING) {
try {
Thread.sleep(50);
} catch (InterruptedException ignore) {
}
}
if (downloader.getStatus() == DownloadStatus.SUCCESS) {
setResourcesRepository();
}
}
}
}
代码示例来源:origin: CFPAOrg/I18nUpdateMod
DownloadManager langpackChinese = new DownloadManager(String.format("https://coding.net/u/baka943/p/Minecraft-Mod-Language-Package/git/raw/1.12.2/project/assets/%s/lang/zh_cn.lang", modid), "zh_cn.lang", String.format(Minecraft.getMinecraft().getResourcePackRepository().getDirResourcepacks().toString() + File.separator + "%s_tmp_resource_pack" + File.separator + "assets" + File.separator + "%s" + File.separator + "lang", modid, modid));
DownloadManager langpackEnglish = new DownloadManager(String.format("https://coding.net/u/baka943/p/Minecraft-Mod-Language-Package/git/raw/1.12.2/project/assets/%s/lang/en_us.lang", modid), "en_us.lang", String.format(Minecraft.getMinecraft().getResourcePackRepository().getDirResourcepacks().toString() + File.separator + "%s_tmp_resource_pack" + File.separator + "assets" + File.separator + "%s" + File.separator + "lang", modid, modid));
FileUtils.deleteDirectory(new File(String.format(Minecraft.getMinecraft().getResourcePackRepository().getDirResourcepacks().toString() + File.separator + "%s_tmp_resource_pack", modid)));
} catch (IOException ioe) {
ioe.printStackTrace();
FileUtils.deleteDirectory(new File(String.format(Minecraft.getMinecraft().getResourcePackRepository().getDirResourcepacks().toString() + File.separator + "%s_tmp_resource_pack", modid)));
} catch (IOException ioe) {
ioe.printStackTrace();
代码示例来源:origin: MatterOverdrive/MatterOverdrive-Legacy-Edition
@Override
public void preInit(FMLPreInitializationEvent event) {
super.preInit(event);
OBJLoader.INSTANCE.addDomain(Reference.MOD_ID);
modelLoader = new MOModelLoader();
ModelLoaderRegistry.registerLoader(modelLoader);
Minecraft.getMinecraft().getResourcePackRepository().rprMetadataSerializer.registerMetadataSectionType(new WeaponMetadataSectionSerializer(), WeaponMetadataSection.class);
renderHandler = new RenderHandler();
renderHandler.registerEntityRenderers();
renderHandler.createItemRenderers();
renderHandler.registerWeaponModuleRenders();
}
内容来源于网络,如有侵权,请联系作者删除!