从文件 json 下载并启动 Minecraft 库
Minecraft libraries download and launch from file json
我在为 windows 生成和下载 minecraft 库和本地程序时遇到问题。
来自:
<package>:<name>:<version>
至:
<package>/<name>/<version>/<name>-<version>
请帮忙!
Json 文件:
{
"id": "1.8.8",
"time": "2015-07-27T12:31:28+02:00",
"releaseTime": "2015-07-27T12:31:28+02:00",
"type": "release",
"minecraftArguments": "--username ${auth_player_name} --version ${version_name} --gameDir ${game_directory} --assetsDir ${assets_root} --assetIndex ${assets_index_name} --uuid ${auth_uuid} --accessToken ${auth_access_token} --userProperties ${user_properties} --userType ${user_type}",
"libraries": [
{
"name": "oshi-project:oshi-core:1.1"
},
{
"name": "net.java.dev.jna:jna:3.4.0"
},
{
"name": "net.java.dev.jna:platform:3.4.0"
},
{
"name": "com.ibm.icu:icu4j-core-mojang:51.2"
},
{
"name": "net.sf.jopt-simple:jopt-simple:4.6"
},
{
"name": "com.paulscode:codecjorbis:20101023"
},
{
"name": "com.paulscode:codecwav:20101023"
},
{
"name": "com.paulscode:libraryjavasound:20101123"
},
{
"name": "com.paulscode:librarylwjglopenal:20100824"
},
{
"name": "com.paulscode:soundsystem:20120107"
},
{
"name": "io.netty:netty-all:4.0.23.Final"
},
{
"name": "com.google.guava:guava:17.0"
},
{
"name": "org.apache.commons:commons-lang3:3.3.2"
},
{
"name": "commons-io:commons-io:2.4"
},
{
"name": "commons-codec:commons-codec:1.9"
},
{
"name": "net.java.jinput:jinput:2.0.5"
},
{
"name": "net.java.jutils:jutils:1.0.0"
},
{
"name": "com.google.code.gson:gson:2.2.4"
},
{
"name": "com.mojang:authlib:1.5.21"
},
{
"name": "com.mojang:realms:1.7.28"
},
{
"name": "org.apache.commons:commons-compress:1.8.1"
},
{
"name": "org.apache.httpcomponents:httpclient:4.3.3"
},
{
"name": "commons-logging:commons-logging:1.1.3"
},
{
"name": "org.apache.httpcomponents:httpcore:4.3.2"
},
{
"name": "org.apache.logging.log4j:log4j-api:2.0-beta9"
},
{
"name": "org.apache.logging.log4j:log4j-core:2.0-beta9"
},
{
"name": "org.lwjgl.lwjgl:lwjgl:2.9.4-nightly-20150209",
"rules": [
{
"action": "allow"
},
{
"action": "disallow",
"os": {
"name": "osx"
}
}
]
},
{
"name": "org.lwjgl.lwjgl:lwjgl_util:2.9.4-nightly-20150209",
"rules": [
{
"action": "allow"
},
{
"action": "disallow",
"os": {
"name": "osx"
}
}
]
},
{
"name": "org.lwjgl.lwjgl:lwjgl-platform:2.9.4-nightly-20150209",
"rules": [
{
"action": "allow"
},
{
"action": "disallow",
"os": {
"name": "osx"
}
}
],
"natives": {
"linux": "natives-linux",
"windows": "natives-windows",
"osx": "natives-osx"
},
"extract": {
"exclude": [
"META-INF/"
]
}
},
{
"name": "org.lwjgl.lwjgl:lwjgl:2.9.2-nightly-20140822",
"rules": [
{
"action": "allow",
"os": {
"name": "osx"
}
}
]
},
{
"name": "org.lwjgl.lwjgl:lwjgl_util:2.9.2-nightly-20140822",
"rules": [
{
"action": "allow",
"os": {
"name": "osx"
}
}
]
},
{
"name": "org.lwjgl.lwjgl:lwjgl-platform:2.9.2-nightly-20140822",
"rules": [
{
"action": "allow",
"os": {
"name": "osx"
}
}
],
"natives": {
"linux": "natives-linux",
"windows": "natives-windows",
"osx": "natives-osx"
},
"extract": {
"exclude": [
"META-INF/"
]
}
},
{
"name": "net.java.jinput:jinput-platform:2.0.5",
"natives": {
"linux": "natives-linux",
"windows": "natives-windows",
"osx": "natives-osx"
},
"extract": {
"exclude": [
"META-INF/"
]
}
},
{
"name": "tv.twitch:twitch:6.5"
},
{
"name": "tv.twitch:twitch-platform:6.5",
"rules": [
{
"action": "allow"
},
{
"action": "disallow",
"os": {
"name": "linux"
}
}
],
"natives": {
"linux": "natives-linux",
"windows": "natives-windows-${arch}",
"osx": "natives-osx"
},
"extract": {
"exclude": [
"META-INF/"
]
}
},
{
"name": "tv.twitch:twitch-external-platform:4.5",
"rules": [
{
"action": "allow",
"os": {
"name": "windows"
}
}
],
"natives": {
"windows": "natives-windows-${arch}"
},
"extract": {
"exclude": [
"META-INF/"
]
}
}
],
"mainClass": "net.minecraft.client.main.Main",
"minimumLauncherVersion": 14,
"assets": "1.8"
}
示例:
oshi-project:oshi-core:1.1
至:
oshi-project/oshi-core/1.1/oshi-core-1.1.jar
和 link 在 libraries.minecraft.net (JAR file)
从 mojang 下载 link:
https://libraries.minecraft.net/<package>/<name>/<version>/<name>-<version>.jar
代码如下:
Dim Libraries As New List(Of List(Of String))
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'The path of your json file.
Dim FilePath As String = "C:\Users\Drarig29\Desktop\File.json"
'Gets all the json file content.
Dim FileContent As String = My.Computer.FileSystem.ReadAllText(FilePath)
'Gets only the libraries.
FileContent = FileContent.Substring(FileContent.IndexOf(" ""libraries"": ["))
Dim NextLineIsOsName As Boolean = False
For Each Line In ReadAllLines(FileContent)
If Line.Contains("""name"":") Then
If NextLineIsOsName Then
NextLineIsOsName = False
Else
'The extracted library (<package>:<name>:<version>).
Dim ExtractedLibrary As String = Line.Split({"""name"": """}, StringSplitOptions.RemoveEmptyEntries)(1).Replace("""", "").Replace(",", "")
'The extracted under splitted by ":" form.
'LibrarySplitted(0) = <package>
'LibrarySplitted(1) = <name>
'LibrarySplitted(2) = <version>
Dim LibrarySplitted() As String = ExtractedLibrary.Split(CChar(":"))
Dim Package As String = LibrarySplitted(0) '<package>
Dim Name As String = LibrarySplitted(1) '<name>
Dim Version As String = LibrarySplitted(2) '<version>
'The string with the slashes (<package>/<name>/<version>/<name>-<version>).
Dim WithSlashes As String = Package & "/" & Name & "/" & Version & "/" & Name & "-" & Version
'The link (https://libraries.minecraft.net/<package>/<name>/<version>/<name>-<version>.jar).
Dim Link As String = "https://libraries.minecraft.net/" & Package & "/" & Name & "/" & Version & "/" & Name & "-" & Version
Dim AllTheForms As New List(Of String)
AllTheForms.Add(ExtractedLibrary)
AllTheForms.Add(WithSlashes)
AllTheForms.Add(Link)
Libraries.Add(AllTheForms)
End If
ElseIf Line.Contains("""os"": {") Then
NextLineIsOsName = True
End If
Next
End Sub
Private Function ReadAllLines(value As String) As List(Of String)
If value Is Nothing Then
Return Nothing
End If
Dim lines As New List(Of String)
Using StringRdr As New StringReader(value)
While StringRdr.Peek() <> -1
Dim line As String = StringRdr.ReadLine
If Not String.IsNullOrWhiteSpace(line) Then
lines.Add(line)
End If
End While
End Using
Return lines
End Function
完成后,您可以访问每个项目(ExtractedLibrary
、WithSlashes
或Link
)每个图书馆做 Libraries(<library's index>)(item's index)
.
例如,如果您想获取所有库的link,您可以这样做:
For Each Library In Libraries
'Library(0) corresponds to the name of the library.
'Library(1) corresponds to the "WithSlashes" string of the library.
MsgBox(Library(2)) 'Library(2) corresponds to the link of the library.
Next
阅读 后,我写了另一个代码,应该可以更好地工作。 (我不知道JSON是序列化数据)。
要运行下面的代码,你必须安装Json.NET framework for .NET(使用NuGet包是更好的方法),然后 import Newtonsoft.Json.Linq
(Imports Newtonsoft.Json.Linq
).
Dim Libraries As New List(Of List(Of String))
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'The path of your json file.
Dim FilePath As String = "C:\Users\Drarig29\Desktop\File.json"
'Parses the your json file.
Dim FileData = JObject.Parse(My.Computer.FileSystem.ReadAllText(FilePath))
For Each Library In FileData("libraries")
'The extracted library (<package>:<name>:<version>).
Dim ExtractedLibrary As String = CStr(Library("name"))
'The extracted under splitted by ":" form.
'LibrarySplitted(0) = <package>
'LibrarySplitted(1) = <name>
'LibrarySplitted(2) = <version>
Dim LibrarySplitted() As String = ExtractedLibrary.Split(CChar(":"))
Dim Package As String = LibrarySplitted(0) '<package>
Dim Name As String = LibrarySplitted(1) '<name>
Dim Version As String = LibrarySplitted(2) '<version>
'The string with the slashes (<package>/<name>/<version>/<name>-<version>).
Dim WithSlashes As String = CreateWithSlashesString(Package, Name, Version)
'The link (https://libraries.minecraft.net/<package>/<name>/<version>/<name>-<version>.jar).
Dim Link As String = CreateLink(Package, Name, Version)
Dim AllTheForms As New List(Of String)
AllTheForms.Add(ExtractedLibrary)
AllTheForms.Add(WithSlashes)
AllTheForms.Add(Link)
Libraries.Add(AllTheForms)
Next
End Sub
'Creates a string with slashes (<package>/<name>/<version>/<name>-<version>).
Private Function CreateWithSlashesString(Package As String, Name As String, Version As String) As String
Return Package & "/" & Name & "/" & Version & "/" & Name & "-" & Version
End Function
'Creates a web link to the library.
Private Function CreateLink(Package As String, Name As String, Version As String) As String
Return "https://libraries.minecraft.net/" & Package & "/" & Name & "/" & Version & "/" & Name & "-" & Version
End Function
完成后,您可以访问每个项目(ExtractedLibrary
、WithSlashes
或Link
)每个库通过做 Libraries(<library's index>)(item's index)
.
例如,如果您想获取所有库的link,您可以这样做:
For Each Library In Libraries
'Library(0) corresponds to the name of the library.
'Library(1) corresponds to the "WithSlashes" string of the library.
MsgBox(Library(2)) 'Library(2) corresponds to the link of the library.
Next
我在为 windows 生成和下载 minecraft 库和本地程序时遇到问题。
来自:
<package>:<name>:<version>
至:
<package>/<name>/<version>/<name>-<version>
请帮忙!
Json 文件:
{
"id": "1.8.8",
"time": "2015-07-27T12:31:28+02:00",
"releaseTime": "2015-07-27T12:31:28+02:00",
"type": "release",
"minecraftArguments": "--username ${auth_player_name} --version ${version_name} --gameDir ${game_directory} --assetsDir ${assets_root} --assetIndex ${assets_index_name} --uuid ${auth_uuid} --accessToken ${auth_access_token} --userProperties ${user_properties} --userType ${user_type}",
"libraries": [
{
"name": "oshi-project:oshi-core:1.1"
},
{
"name": "net.java.dev.jna:jna:3.4.0"
},
{
"name": "net.java.dev.jna:platform:3.4.0"
},
{
"name": "com.ibm.icu:icu4j-core-mojang:51.2"
},
{
"name": "net.sf.jopt-simple:jopt-simple:4.6"
},
{
"name": "com.paulscode:codecjorbis:20101023"
},
{
"name": "com.paulscode:codecwav:20101023"
},
{
"name": "com.paulscode:libraryjavasound:20101123"
},
{
"name": "com.paulscode:librarylwjglopenal:20100824"
},
{
"name": "com.paulscode:soundsystem:20120107"
},
{
"name": "io.netty:netty-all:4.0.23.Final"
},
{
"name": "com.google.guava:guava:17.0"
},
{
"name": "org.apache.commons:commons-lang3:3.3.2"
},
{
"name": "commons-io:commons-io:2.4"
},
{
"name": "commons-codec:commons-codec:1.9"
},
{
"name": "net.java.jinput:jinput:2.0.5"
},
{
"name": "net.java.jutils:jutils:1.0.0"
},
{
"name": "com.google.code.gson:gson:2.2.4"
},
{
"name": "com.mojang:authlib:1.5.21"
},
{
"name": "com.mojang:realms:1.7.28"
},
{
"name": "org.apache.commons:commons-compress:1.8.1"
},
{
"name": "org.apache.httpcomponents:httpclient:4.3.3"
},
{
"name": "commons-logging:commons-logging:1.1.3"
},
{
"name": "org.apache.httpcomponents:httpcore:4.3.2"
},
{
"name": "org.apache.logging.log4j:log4j-api:2.0-beta9"
},
{
"name": "org.apache.logging.log4j:log4j-core:2.0-beta9"
},
{
"name": "org.lwjgl.lwjgl:lwjgl:2.9.4-nightly-20150209",
"rules": [
{
"action": "allow"
},
{
"action": "disallow",
"os": {
"name": "osx"
}
}
]
},
{
"name": "org.lwjgl.lwjgl:lwjgl_util:2.9.4-nightly-20150209",
"rules": [
{
"action": "allow"
},
{
"action": "disallow",
"os": {
"name": "osx"
}
}
]
},
{
"name": "org.lwjgl.lwjgl:lwjgl-platform:2.9.4-nightly-20150209",
"rules": [
{
"action": "allow"
},
{
"action": "disallow",
"os": {
"name": "osx"
}
}
],
"natives": {
"linux": "natives-linux",
"windows": "natives-windows",
"osx": "natives-osx"
},
"extract": {
"exclude": [
"META-INF/"
]
}
},
{
"name": "org.lwjgl.lwjgl:lwjgl:2.9.2-nightly-20140822",
"rules": [
{
"action": "allow",
"os": {
"name": "osx"
}
}
]
},
{
"name": "org.lwjgl.lwjgl:lwjgl_util:2.9.2-nightly-20140822",
"rules": [
{
"action": "allow",
"os": {
"name": "osx"
}
}
]
},
{
"name": "org.lwjgl.lwjgl:lwjgl-platform:2.9.2-nightly-20140822",
"rules": [
{
"action": "allow",
"os": {
"name": "osx"
}
}
],
"natives": {
"linux": "natives-linux",
"windows": "natives-windows",
"osx": "natives-osx"
},
"extract": {
"exclude": [
"META-INF/"
]
}
},
{
"name": "net.java.jinput:jinput-platform:2.0.5",
"natives": {
"linux": "natives-linux",
"windows": "natives-windows",
"osx": "natives-osx"
},
"extract": {
"exclude": [
"META-INF/"
]
}
},
{
"name": "tv.twitch:twitch:6.5"
},
{
"name": "tv.twitch:twitch-platform:6.5",
"rules": [
{
"action": "allow"
},
{
"action": "disallow",
"os": {
"name": "linux"
}
}
],
"natives": {
"linux": "natives-linux",
"windows": "natives-windows-${arch}",
"osx": "natives-osx"
},
"extract": {
"exclude": [
"META-INF/"
]
}
},
{
"name": "tv.twitch:twitch-external-platform:4.5",
"rules": [
{
"action": "allow",
"os": {
"name": "windows"
}
}
],
"natives": {
"windows": "natives-windows-${arch}"
},
"extract": {
"exclude": [
"META-INF/"
]
}
}
],
"mainClass": "net.minecraft.client.main.Main",
"minimumLauncherVersion": 14,
"assets": "1.8"
}
示例:
oshi-project:oshi-core:1.1
至:
oshi-project/oshi-core/1.1/oshi-core-1.1.jar
和 link 在 libraries.minecraft.net (JAR file)
从 mojang 下载 link:
https://libraries.minecraft.net/<package>/<name>/<version>/<name>-<version>.jar
代码如下:
Dim Libraries As New List(Of List(Of String))
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'The path of your json file.
Dim FilePath As String = "C:\Users\Drarig29\Desktop\File.json"
'Gets all the json file content.
Dim FileContent As String = My.Computer.FileSystem.ReadAllText(FilePath)
'Gets only the libraries.
FileContent = FileContent.Substring(FileContent.IndexOf(" ""libraries"": ["))
Dim NextLineIsOsName As Boolean = False
For Each Line In ReadAllLines(FileContent)
If Line.Contains("""name"":") Then
If NextLineIsOsName Then
NextLineIsOsName = False
Else
'The extracted library (<package>:<name>:<version>).
Dim ExtractedLibrary As String = Line.Split({"""name"": """}, StringSplitOptions.RemoveEmptyEntries)(1).Replace("""", "").Replace(",", "")
'The extracted under splitted by ":" form.
'LibrarySplitted(0) = <package>
'LibrarySplitted(1) = <name>
'LibrarySplitted(2) = <version>
Dim LibrarySplitted() As String = ExtractedLibrary.Split(CChar(":"))
Dim Package As String = LibrarySplitted(0) '<package>
Dim Name As String = LibrarySplitted(1) '<name>
Dim Version As String = LibrarySplitted(2) '<version>
'The string with the slashes (<package>/<name>/<version>/<name>-<version>).
Dim WithSlashes As String = Package & "/" & Name & "/" & Version & "/" & Name & "-" & Version
'The link (https://libraries.minecraft.net/<package>/<name>/<version>/<name>-<version>.jar).
Dim Link As String = "https://libraries.minecraft.net/" & Package & "/" & Name & "/" & Version & "/" & Name & "-" & Version
Dim AllTheForms As New List(Of String)
AllTheForms.Add(ExtractedLibrary)
AllTheForms.Add(WithSlashes)
AllTheForms.Add(Link)
Libraries.Add(AllTheForms)
End If
ElseIf Line.Contains("""os"": {") Then
NextLineIsOsName = True
End If
Next
End Sub
Private Function ReadAllLines(value As String) As List(Of String)
If value Is Nothing Then
Return Nothing
End If
Dim lines As New List(Of String)
Using StringRdr As New StringReader(value)
While StringRdr.Peek() <> -1
Dim line As String = StringRdr.ReadLine
If Not String.IsNullOrWhiteSpace(line) Then
lines.Add(line)
End If
End While
End Using
Return lines
End Function
完成后,您可以访问每个项目(ExtractedLibrary
、WithSlashes
或Link
)每个图书馆做 Libraries(<library's index>)(item's index)
.
例如,如果您想获取所有库的link,您可以这样做:
For Each Library In Libraries
'Library(0) corresponds to the name of the library.
'Library(1) corresponds to the "WithSlashes" string of the library.
MsgBox(Library(2)) 'Library(2) corresponds to the link of the library.
Next
阅读
要运行下面的代码,你必须安装Json.NET framework for .NET(使用NuGet包是更好的方法),然后 import Newtonsoft.Json.Linq
(Imports Newtonsoft.Json.Linq
).
Dim Libraries As New List(Of List(Of String))
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'The path of your json file.
Dim FilePath As String = "C:\Users\Drarig29\Desktop\File.json"
'Parses the your json file.
Dim FileData = JObject.Parse(My.Computer.FileSystem.ReadAllText(FilePath))
For Each Library In FileData("libraries")
'The extracted library (<package>:<name>:<version>).
Dim ExtractedLibrary As String = CStr(Library("name"))
'The extracted under splitted by ":" form.
'LibrarySplitted(0) = <package>
'LibrarySplitted(1) = <name>
'LibrarySplitted(2) = <version>
Dim LibrarySplitted() As String = ExtractedLibrary.Split(CChar(":"))
Dim Package As String = LibrarySplitted(0) '<package>
Dim Name As String = LibrarySplitted(1) '<name>
Dim Version As String = LibrarySplitted(2) '<version>
'The string with the slashes (<package>/<name>/<version>/<name>-<version>).
Dim WithSlashes As String = CreateWithSlashesString(Package, Name, Version)
'The link (https://libraries.minecraft.net/<package>/<name>/<version>/<name>-<version>.jar).
Dim Link As String = CreateLink(Package, Name, Version)
Dim AllTheForms As New List(Of String)
AllTheForms.Add(ExtractedLibrary)
AllTheForms.Add(WithSlashes)
AllTheForms.Add(Link)
Libraries.Add(AllTheForms)
Next
End Sub
'Creates a string with slashes (<package>/<name>/<version>/<name>-<version>).
Private Function CreateWithSlashesString(Package As String, Name As String, Version As String) As String
Return Package & "/" & Name & "/" & Version & "/" & Name & "-" & Version
End Function
'Creates a web link to the library.
Private Function CreateLink(Package As String, Name As String, Version As String) As String
Return "https://libraries.minecraft.net/" & Package & "/" & Name & "/" & Version & "/" & Name & "-" & Version
End Function
完成后,您可以访问每个项目(ExtractedLibrary
、WithSlashes
或Link
)每个库通过做 Libraries(<library's index>)(item's index)
.
例如,如果您想获取所有库的link,您可以这样做:
For Each Library In Libraries
'Library(0) corresponds to the name of the library.
'Library(1) corresponds to the "WithSlashes" string of the library.
MsgBox(Library(2)) 'Library(2) corresponds to the link of the library.
Next