Skip to content

Commit

Permalink
feat: Support neoforged
Browse files Browse the repository at this point in the history
  • Loading branch information
ci010 committed Oct 4, 2023
1 parent ada20c4 commit 2bba457
Show file tree
Hide file tree
Showing 18 changed files with 333 additions and 16 deletions.
13 changes: 12 additions & 1 deletion xmcl-keystone-ui/locales/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ diagnosis:
incompatibleJava:
message: You can ask Launcher to download it for you.
name: The java version {javaVersion} does not suitable to {version}!
instanceFiles:
description: This might be incompleted installation last time
title: Install files to instances
invalidJava:
message: Click to use another java to launch.
name: Invalid java location.
Expand Down Expand Up @@ -604,7 +607,7 @@ mod:
backToAllMods: Back to All Mods
compatible: Compatible Mod.
currentVersion: Current {current}
deletion: Deleting Mod
deletion: Delete Mod
deletionHint: >-
You will lose this mod & its metadata forever. Are you sure you want to
delete it? | You will lose these mod & these metadata forever. Are you sure
Expand Down Expand Up @@ -796,6 +799,7 @@ modrinth:
version: Version
install: Install
installFrom: Install from Modrinth
issueUrl: Issue
license: License
licenses:
name: Licenses
Expand All @@ -820,9 +824,11 @@ modrinth:
relevance: Relevance
title: Sort By
updated: Recently updated
sourceUrl: Source
technicalInformation: Technical Information
updateAt: Updated
versions: Versions
wikiUrl: Wiki
modrinthCard:
currentVersion: Current Version
projectHint: >
Expand Down Expand Up @@ -911,6 +917,11 @@ natType:
symmetricNat: Symmetric NAT
symmetricUDPFirewall: Symmetric UDP Firewall
unknown: Unknown
neoForgeVersion:
disable: Disable NeoForged
empty: NeoForged does not support {version}
neoForgedVersion:
name: NeoForged
news:
name: News
readMore: Read More
Expand Down
11 changes: 11 additions & 0 deletions xmcl-keystone-ui/locales/zh-CN.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ diagnosis:
incompatibleJava:
message: 你可以选择自己让启动器帮你下载,或者自己下载
name: 版本 {version} 可能不兼容 Java {javaVersion}!
instanceFiles:
description: 这可能是因为之前安装实例时没安装完
title: 实例文件缺失
invalidJava:
message: 请选择一个有效的 Java 路径.
name: 当前 Java 路径已经失效
Expand Down Expand Up @@ -804,6 +807,7 @@ modrinth:
version: 版本
install: 安装
installFrom: 从 Modrinth 安装
issueUrl: 反馈链接
license: 协议
licenses:
name: 协议
Expand All @@ -828,9 +832,11 @@ modrinth:
relevance: 相关性
title: 排序
updated: 更新时间
sourceUrl: 源码
technicalInformation: 技术信息
updateAt: 更新于
versions: 版本
wikiUrl: 百科链接
modrinthCard:
currentVersion: 当前版本
projectHint: >
Expand Down Expand Up @@ -905,6 +911,11 @@ natType:
symmetricNat: 对称 NAT
symmetricUDPFirewall: 对称 UDP 防火墙
unknown: 未知
neoForgeVersion:
disable: 不使用 NeoForged
empty: Neoforge 不支持 Minecraft {version}
neoForgedVersion:
name: NeoForged
news:
name: 新闻
readMore: 阅读更多
Expand Down
5 changes: 5 additions & 0 deletions xmcl-keystone-ui/src/composables/instanceEdit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export function useInstanceEdit(instance: Ref<Instance>, edit: (instance: EditIn
quiltLoader: instance.value?.runtime.quiltLoader,
optifine: instance.value?.runtime.optifine,
liteloader: instance.value?.runtime.liteloader,
neoForged: instance.value?.runtime.neoForged,
} as RuntimeVersions,
version: '',

Expand Down Expand Up @@ -161,6 +162,9 @@ export function useInstanceEdit(instance: Ref<Instance>, edit: (instance: EditIn
if (current.runtime.forge !== data.runtime.forge) {
return true
}
if (current.runtime.neoForged !== data.runtime.neoForged) {
return true
}
if (current.runtime.fabricLoader !== data.runtime.fabricLoader) {
return true
}
Expand Down Expand Up @@ -247,6 +251,7 @@ export function useInstanceEdit(instance: Ref<Instance>, edit: (instance: EditIn
data.runtime.minecraft = current.runtime.minecraft
data.runtime.optifine = current.runtime.optifine
data.runtime.quiltLoader = current.runtime.quiltLoader
data.runtime.neoForged = current.runtime.neoForged
data.version = current.version
data.icon = current.icon

Expand Down
1 change: 1 addition & 0 deletions xmcl-keystone-ui/src/composables/instanceVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export function useInstanceVersion(instance: Ref<Instance>, local: Ref<LocalVers
instance.value.version,
instance.value.runtime.minecraft,
instance.value.runtime.forge,
instance.value.runtime.neoForged,
instance.value.runtime.fabricLoader,
instance.value.runtime.optifine,
instance.value.runtime.quiltLoader) || markRaw(EMPTY_VERSION))
Expand Down
16 changes: 15 additions & 1 deletion xmcl-keystone-ui/src/composables/instanceVersionInstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ export function useInstanceVersionInstall(versions: Ref<LocalVersionHeader[]>) {
const {
getMinecraftVersionList,
getForgeVersionList,
getNeoForgedVersionList,
installForge,
installNeoForged,
installMinecraft,
installOptifine,
installFabric,
Expand All @@ -26,7 +28,7 @@ export function useInstanceVersionInstall(versions: Ref<LocalVersionHeader[]>) {
return data
}
async function install(runtime: RuntimeVersions) {
const { minecraft, forge, fabricLoader, quiltLoader, optifine } = runtime
const { minecraft, forge, fabricLoader, quiltLoader, optifine, neoForged } = runtime
const mcVersions = await getCacheOrFetch('/minecraft-versions', () => getMinecraftVersionList())
const local = versions.value
if (!local.find(v => v.id === minecraft)) {
Expand All @@ -47,6 +49,18 @@ export function useInstanceVersionInstall(versions: Ref<LocalVersionHeader[]>) {
}
}

if (neoForged) {
const localNeoForge = local.find(v => v.neoForged === neoForged && v.minecraft === minecraft)
if (!localNeoForge) {
const neoForgedVersion = await getCacheOrFetch('/neoforged-versions', () => getNeoForgedVersionList())
const found = neoForgedVersion.versions.find(v => v === neoForged)
const id = found ?? neoForged
forgeVersion = await installNeoForged({ version: id, minecraft })
} else {
forgeVersion = localNeoForge.id
}
}

if (optifine) {
let optifineVersion = optifine
if (optifineVersion.startsWith(minecraft)) {
Expand Down
2 changes: 1 addition & 1 deletion xmcl-keystone-ui/src/composables/launchTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function useLaunchTask(path: Ref<string>, version: Ref<Instance['runtime'
if (i.path === 'installAssets' && (p?.id === localVersion.value.id || p?.id === version.value.minecraft || p?.id === version.value.minecraft.substring(version.value.minecraft.lastIndexOf('.')))) {
return true
}
if (i.path === 'installForge' && (p?.id === version.value.forge || p?.id === localVersion.value.id)) {
if (i.path === 'installForge' && (p?.id === version.value.forge || p?.id === localVersion.value.id || p?.id === version.value.neoForged)) {
return true
}
if (i.path === 'installOptifine' && p?.id === version.value.optifine) {
Expand Down
48 changes: 48 additions & 0 deletions xmcl-keystone-ui/src/composables/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,54 @@ export function useQuiltVersions(minecraftVersion: Ref<string>, local: Ref<Local
}
}

export function useNeoForgedVersions(local: Ref<LocalVersionHeader[]>) {
const { getNeoForgedVersionList } = useService(InstallServiceKey)
const _refreshing = useServiceBusy(InstallServiceKey, 'getNeoForgedVersionList')

const { data, isValidating, mutate, error } = useSWRV('/neoforged-versions',
async () => {
const result = await getNeoForgedVersionList().then(markRaw)
return result
},
inject(kSWRVConfig))

const refreshing = computed(() => isValidating.value || _refreshing.value)

const recommended = computed(() => {
const vers = data.value
if (!vers) return undefined
return vers.release
})
const latest = computed(() => {
const vers = data.value
if (!vers) return undefined
return vers.latest
})
const versions = computed(() => {
const vers = data.value
if (!vers) return []
return vers.versions
})
const installed = computed(() => {
const localForgeVersion: { [k: string]: string } = {}
for (const ver of local.value) {
if (!ver.neoForged) continue
localForgeVersion[ver.neoForged] = ver.id
}
return localForgeVersion
})

return {
error,
installed,
versions,
refresh: mutate,
refreshing,
recommended,
latest,
}
}

export function useForgeVersions(minecraftVersion: Ref<string>, local: Ref<LocalVersionHeader[]>) {
const { getForgeVersionList } = useService(InstallServiceKey)
const _refreshing = useServiceBusy(InstallServiceKey, 'getForgeVersionList')
Expand Down
43 changes: 42 additions & 1 deletion xmcl-keystone-ui/src/composables/versionList.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Ref } from 'vue'
import { ForgeVersion, LocalVersionHeader, LockKey } from '@xmcl/runtime-api'
import { useFabricVersions, useForgeVersions, useMinecraftVersions, useOptifineVersions, useQuiltVersions } from './version'
import { useFabricVersions, useForgeVersions, useMinecraftVersions, useNeoForgedVersions, useOptifineVersions, useQuiltVersions } from './version'

import { kSemaphores } from '@/composables'
import { getLocalDateString } from '@/util/date'
Expand Down Expand Up @@ -56,6 +56,47 @@ export function useMinecraftVersionList(version: Ref<string>, local: Ref<LocalVe
}
}

export function useNeoForgedVersionList(minecraft: Ref<string>, version: Ref<string>, local: Ref<LocalVersionHeader[]>) {
const { versions, installed, latest, recommended, refresh, refreshing, error } = useNeoForgedVersions(local)
const { semaphores } = injection(kSemaphores)
const { t } = useI18n()

const items = computed(() => {
const vers = versions.value
const result: VersionItem[] = vers
.filter(v => v.startsWith(minecraft.value))
.map(v => {
const key = LockKey.version(`neoforge-${v}`)
return reactive({
name: v,
status: computed(() => {
const status = semaphores[key] > 0 ? 'installing' : installed.value[v] ? 'local' : 'remote'
return status
}),
folder: computed(() => {
const folder = installed.value[v]
return folder ?? ''
}),
description: '',
isSelected: computed(() => version.value === v),
tag: recommended.value === v
? t('forgeVersion.recommended')
: latest.value === v ? t('forgeVersion.latest') : '',
tagColor: recommended.value === v ? 'primary' : '',
instance: markRaw({ version }),
})
})
return result
})

return {
items,
refreshing,
refresh,
error,
}
}

export function useForgeVersionList(minecraft: Ref<string>, version: Ref<string>, local: Ref<LocalVersionHeader[]>) {
const { versions, refreshing, refresh, installed } = useForgeVersions(minecraft, local)
const { semaphores } = injection(kSemaphores)
Expand Down

0 comments on commit 2bba457

Please sign in to comment.