Skip to content

Commit 96172b2

Browse files
committed
Merge branch 'refs/heads/2023.3' into 2024.1
2 parents 1f9687f + ee7b9ac commit 96172b2

38 files changed

+1201
-66
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ kotlin.code.style=official
2424
ideaVersion = 2024.1
2525
ideaVersionName = 2024.1
2626

27-
coreVersion = 1.7.5
27+
coreVersion = 1.7.6
2828
downloadIdeaSources = true
2929

3030
pluginTomlVersion = 241.14494.150

readme.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ Minecraft Development for IntelliJ
2323
<td align="left">2024.1</td>
2424
<td align="left"><a href="https://ci.mcdev.io/viewType.html?buildTypeId=MinecraftDev_Nightly_20241"><img src="https://ci.mcdev.io/app/rest/builds/buildType:(id:MinecraftDev_Nightly_20241)/statusIcon.svg" alt="2024.1 Nightly Status" /></a></td>
2525
</tr>
26+
<tr>
27+
<td align="left">2024.2</td>
28+
<td align="left"><a href="https://ci.mcdev.io/viewType.html?buildTypeId=MinecraftDev_Nightly_20242"><img src="https://ci.mcdev.io/app/rest/builds/buildType:(id:MinecraftDev_Nightly_20242)/statusIcon.svg" alt="2024.2 Nightly Status" /></a></td>
29+
</tr>
2630
<tr>
2731
<td align="right"><b>OS Tests</b></td>
2832
<td align="left" colspan="2">
@@ -31,7 +35,7 @@ Minecraft Development for IntelliJ
3135
</tr>
3236
</table>
3337

34-
Info and Documentation [![Current Release](https://img.shields.io/badge/release-1.7.5-orange.svg?style=flat-square)](https://plugins.jetbrains.com/plugin/8327)
38+
Info and Documentation [![Current Release](https://img.shields.io/badge/release-1.7.6-orange.svg?style=flat-square)](https://plugins.jetbrains.com/plugin/8327)
3539
----------------------
3640

3741
<a href="https://discord.gg/j6UNcfr"><img src="https://i.imgur.com/JXu9C1G.png" height="48px"></img></a>

src/main/kotlin/platform/bungeecord/creator/bungee-platforms.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import com.demonwav.mcdev.util.SemanticVersion
2828
class BungeeMainPlatformStep(parent: BungeePlatformStep) : AbstractBungeePlatformStep(parent, PlatformType.BUNGEECORD) {
2929
override fun getRepositories(mcVersion: SemanticVersion) = listOf(
3030
BuildRepository("sonatype", "https://oss.sonatype.org/content/groups/public/"),
31+
// Seems to be required since 1.21
32+
BuildRepository("Minecraft Libraries", "https://libraries.minecraft.net/"),
3133
)
3234

3335
override fun getDependencies(mcVersion: SemanticVersion) = listOf(

src/main/kotlin/platform/forge/creator/asset-steps.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ class ForgeProjectFilesStep(parent: NewProjectWizardStep) : AbstractLongRunningA
108108
}
109109

110110
val mainClassTemplate = when {
111+
mcVersion >= MinecraftVersions.MC1_20_6 -> MinecraftTemplates.FG3_1_20_6_MAIN_CLASS_TEMPLATE
111112
mcVersion >= MinecraftVersions.MC1_20 -> MinecraftTemplates.FG3_1_20_MAIN_CLASS_TEMPLATE
112113
mcVersion >= MinecraftVersions.MC1_19_3 -> MinecraftTemplates.FG3_1_19_3_MAIN_CLASS_TEMPLATE
113114
mcVersion >= MinecraftVersions.MC1_19 -> MinecraftTemplates.FG3_1_19_MAIN_CLASS_TEMPLATE
@@ -124,6 +125,7 @@ class ForgeProjectFilesStep(parent: NewProjectWizardStep) : AbstractLongRunningA
124125
)
125126

126127
val configTemplate = when {
128+
mcVersion >= MinecraftVersions.MC1_21 -> MinecraftTemplates.FG3_1_21_CONFIG_TEMPLATE
127129
mcVersion >= MinecraftVersions.MC1_20 -> MinecraftTemplates.FG3_1_20_CONFIG_TEMPLATE
128130
else -> null
129131
}

src/main/kotlin/platform/forge/util/ForgePackDescriptor.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ data class ForgePackDescriptor(val format: Int, val comment: String) {
5555
val FORMAT_15 = ForgePackDescriptor(15, "")
5656
val FORMAT_18 = ForgePackDescriptor(18, "")
5757
val FORMAT_26 = ForgePackDescriptor(26, "")
58-
val FORMAT_41 = ForgePackDescriptor(26, "")
58+
val FORMAT_41 = ForgePackDescriptor(41, "")
59+
val FORMAT_48 = ForgePackDescriptor(48, "")
5960

6061
// See https://minecraft.gamepedia.com/Tutorials/Creating_a_resource_pack#.22pack_format.22
6162
fun forMcVersion(version: SemanticVersion): ForgePackDescriptor? = when {
@@ -71,7 +72,8 @@ data class ForgePackDescriptor(val format: Int, val comment: String) {
7172
version < MinecraftVersions.MC1_20_2 -> FORMAT_15
7273
version < MinecraftVersions.MC1_20_3 -> FORMAT_18
7374
version < MinecraftVersions.MC1_20_5 -> FORMAT_26
74-
version >= MinecraftVersions.MC1_20_5 -> FORMAT_41
75+
version < MinecraftVersions.MC1_21 -> FORMAT_41
76+
version >= MinecraftVersions.MC1_21 -> FORMAT_48
7577
else -> null
7678
}
7779
}

src/main/kotlin/platform/mixin/handlers/InjectorAnnotationHandler.kt

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,25 @@ import org.objectweb.asm.tree.MethodNode
5454

5555
abstract class InjectorAnnotationHandler : MixinAnnotationHandler {
5656
override fun resolveTarget(annotation: PsiAnnotation, targetClass: ClassNode): List<MixinTargetMember> {
57-
val targetClassMethods = targetClass.methods ?: return emptyList()
58-
5957
val methodAttr = annotation.findAttributeValue("method")
6058
val method = methodAttr?.computeStringArray() ?: emptyList()
6159
val desc = annotation.findAttributeValue("desc")?.findAnnotations() ?: emptyList()
6260
val selectors = method.mapNotNull { parseMixinSelector(it, methodAttr!!) } +
6361
desc.mapNotNull { DescSelectorParser.descSelectorFromAnnotation(it) }
6462

65-
return targetClassMethods.mapNotNull { targetMethod ->
66-
if (selectors.any { it.matchMethod(targetMethod, targetClass) }) {
67-
MethodTargetMember(targetClass, targetMethod)
68-
} else {
69-
null
63+
val targetClassMethods = selectors.associateWith { selector ->
64+
val actualTarget = selector.getCustomOwner(targetClass)
65+
(actualTarget to actualTarget.methods)
66+
}
67+
68+
return targetClassMethods.mapNotNull { (selector, pair) ->
69+
val (clazz, methods) = pair
70+
methods.firstNotNullOfOrNull { method ->
71+
if (selector.matchMethod(method, clazz)) {
72+
MethodTargetMember(clazz, method)
73+
} else {
74+
null
75+
}
7076
}
7177
}
7278
}
@@ -99,7 +105,7 @@ abstract class InjectorAnnotationHandler : MixinAnnotationHandler {
99105
override fun resolveForNavigation(annotation: PsiAnnotation, targetClass: ClassNode): List<PsiElement> {
100106
return resolveTarget(annotation, targetClass).flatMap { targetMember ->
101107
val targetMethod = targetMember as? MethodTargetMember ?: return@flatMap emptyList()
102-
resolveForNavigation(annotation, targetClass, targetMethod.classAndMethod.method)
108+
resolveForNavigation(annotation, targetMethod.classAndMethod.clazz, targetMethod.classAndMethod.method)
103109
}
104110
}
105111

src/main/kotlin/platform/mixin/handlers/injectionPoint/AtResolver.kt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
package com.demonwav.mcdev.platform.mixin.handlers.injectionPoint
2222

23+
import com.demonwav.mcdev.platform.mixin.reference.MixinSelector
2324
import com.demonwav.mcdev.platform.mixin.reference.isMiscDynamicSelector
2425
import com.demonwav.mcdev.platform.mixin.reference.parseMixinSelector
2526
import com.demonwav.mcdev.platform.mixin.reference.target.TargetReference
@@ -152,7 +153,7 @@ class AtResolver(
152153
val collectVisitor = injectionPoint.createCollectVisitor(
153154
at,
154155
target,
155-
targetClass,
156+
getTargetClass(target),
156157
CollectVisitor.Mode.MATCH_FIRST,
157158
)
158159
if (collectVisitor == null) {
@@ -181,7 +182,7 @@ class AtResolver(
181182
val targetAttr = at.findAttributeValue("target")
182183
val target = targetAttr?.let { parseMixinSelector(it) }
183184

184-
val collectVisitor = injectionPoint.createCollectVisitor(at, target, targetClass, mode)
185+
val collectVisitor = injectionPoint.createCollectVisitor(at, target, getTargetClass(target), mode)
185186
?: return InsnResolutionInfo.Failure()
186187
collectVisitor.visit(targetMethod)
187188
val result = collectVisitor.result
@@ -201,7 +202,7 @@ class AtResolver(
201202

202203
// Then attempt to find the corresponding source elements using the navigation visitor
203204
val targetElement = targetMethod.findSourceElement(
204-
targetClass,
205+
getTargetClass(target),
205206
at.project,
206207
GlobalSearchScope.allScope(at.project),
207208
canDecompile = true,
@@ -223,16 +224,23 @@ class AtResolver(
223224

224225
// Collect all possible targets
225226
fun <T : PsiElement> doCollectVariants(injectionPoint: InjectionPoint<T>): List<Any> {
226-
val visitor = injectionPoint.createCollectVisitor(at, target, targetClass, CollectVisitor.Mode.COMPLETION)
227+
val visitor = injectionPoint.createCollectVisitor(
228+
at, target, getTargetClass(target),
229+
CollectVisitor.Mode.COMPLETION
230+
)
227231
?: return emptyList()
228232
visitor.visit(targetMethod)
229233
return visitor.result
230234
.mapNotNull { result ->
231-
injectionPoint.createLookup(targetClass, result)?.let { completionHandler(it) }
235+
injectionPoint.createLookup(getTargetClass(target), result)?.let { completionHandler(it) }
232236
}
233237
}
234238
return doCollectVariants(injectionPoint)
235239
}
240+
241+
private fun getTargetClass(selector: MixinSelector?): ClassNode {
242+
return selector?.getCustomOwner(targetClass) ?: targetClass
243+
}
236244
}
237245

238246
sealed class InsnResolutionInfo {
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Minecraft Development for IntelliJ
3+
*
4+
* https://mcdev.io/
5+
*
6+
* Copyright (C) 2024 minecraft-dev
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Lesser General Public License as published
10+
* by the Free Software Foundation, version 3.0 only.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public License
18+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
*/
20+
21+
package com.demonwav.mcdev.platform.mixin.handlers.mixinextras
22+
23+
import com.demonwav.mcdev.platform.mixin.handlers.InjectorAnnotationHandler
24+
import com.demonwav.mcdev.platform.mixin.handlers.injectionPoint.InsnResolutionInfo
25+
import com.demonwav.mcdev.platform.mixin.inspection.injector.MethodSignature
26+
import com.demonwav.mcdev.platform.mixin.inspection.injector.ParameterGroup
27+
import com.demonwav.mcdev.platform.mixin.util.findSourceElement
28+
import com.demonwav.mcdev.platform.mixin.util.getGenericReturnType
29+
import com.demonwav.mcdev.platform.mixin.util.mixinExtrasOperationType
30+
import com.demonwav.mcdev.util.Parameter
31+
import com.intellij.psi.PsiAnnotation
32+
import com.intellij.psi.PsiElement
33+
import com.intellij.psi.search.GlobalSearchScope
34+
import org.objectweb.asm.tree.ClassNode
35+
import org.objectweb.asm.tree.MethodNode
36+
37+
class WrapMethodHandler : InjectorAnnotationHandler() {
38+
override fun expectedMethodSignature(
39+
annotation: PsiAnnotation,
40+
targetClass: ClassNode,
41+
targetMethod: MethodNode,
42+
): List<MethodSignature> {
43+
val returnType = targetMethod.getGenericReturnType(targetClass, annotation.project)
44+
45+
return listOf(
46+
MethodSignature(
47+
listOf(
48+
ParameterGroup(
49+
collectTargetMethodParameters(annotation.project, targetClass, targetMethod) +
50+
Parameter(
51+
"original",
52+
mixinExtrasOperationType(annotation, returnType) ?: return emptyList()
53+
),
54+
)
55+
),
56+
returnType
57+
)
58+
)
59+
}
60+
61+
override fun isUnresolved(
62+
annotation: PsiAnnotation,
63+
targetClass: ClassNode,
64+
targetMethod: MethodNode
65+
): InsnResolutionInfo.Failure? {
66+
// If we've got a target method that's good enough
67+
return null
68+
}
69+
70+
override fun resolveForNavigation(
71+
annotation: PsiAnnotation,
72+
targetClass: ClassNode,
73+
targetMethod: MethodNode
74+
): List<PsiElement> {
75+
val project = annotation.project
76+
return targetMethod.findSourceElement(
77+
targetClass,
78+
project,
79+
GlobalSearchScope.allScope(project),
80+
canDecompile = true
81+
)?.let(::listOf).orEmpty()
82+
}
83+
}

src/main/kotlin/platform/mixin/handlers/mixinextras/WrapOperationHandler.kt

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,9 @@
2121
package com.demonwav.mcdev.platform.mixin.handlers.mixinextras
2222

2323
import com.demonwav.mcdev.platform.mixin.inspection.injector.ParameterGroup
24-
import com.demonwav.mcdev.platform.mixin.util.MixinConstants.MixinExtras.OPERATION
24+
import com.demonwav.mcdev.platform.mixin.util.mixinExtrasOperationType
2525
import com.demonwav.mcdev.util.Parameter
26-
import com.intellij.psi.JavaPsiFacade
2726
import com.intellij.psi.PsiAnnotation
28-
import com.intellij.psi.PsiElement
29-
import com.intellij.psi.PsiPrimitiveType
3027
import com.intellij.psi.PsiType
3128
import org.objectweb.asm.tree.AbstractInsnNode
3229
import org.objectweb.asm.tree.ClassNode
@@ -50,21 +47,9 @@ class WrapOperationHandler : MixinExtrasInjectorAnnotationHandler() {
5047
): Pair<ParameterGroup, PsiType>? {
5148
val params = getPsiParameters(insn, targetClass, annotation) ?: return null
5249
val returnType = getPsiReturnType(insn, annotation) ?: return null
53-
val operationType = getOperationType(annotation, returnType) ?: return null
50+
val operationType = mixinExtrasOperationType(annotation, returnType) ?: return null
5451
return ParameterGroup(
5552
params + Parameter("original", operationType)
5653
) to returnType
5754
}
58-
59-
private fun getOperationType(context: PsiElement, type: PsiType): PsiType? {
60-
val project = context.project
61-
val boxedType = if (type is PsiPrimitiveType) {
62-
type.getBoxedType(context) ?: return null
63-
} else {
64-
type
65-
}
66-
67-
return JavaPsiFacade.getElementFactory(project)
68-
.createTypeFromText("$OPERATION<${boxedType.canonicalText}>", context)
69-
}
7055
}

src/main/kotlin/platform/mixin/inspection/StaticMemberInspection.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import com.intellij.psi.PsiModifier
3737
class StaticMemberInspection : MixinInspection() {
3838

3939
override fun getStaticDescription() =
40-
"A mixin class does not exist at runtime, and thus having them public does not make sense. " +
40+
"A mixin class does not exist at runtime, and thus having them not private does not make sense. " +
4141
"Make the field/method private instead."
4242

4343
override fun buildVisitor(holder: ProblemsHolder): PsiElementVisitor = Visitor(holder)
@@ -56,7 +56,7 @@ class StaticMemberInspection : MixinInspection() {
5656
if (isProblematic(member)) {
5757
holder.registerProblem(
5858
member,
59-
"Public static members are not allowed in Mixin classes",
59+
"Non-private static members are not allowed in Mixin classes",
6060
QuickFixFactory.getInstance().createModifierListFix(member, PsiModifier.PRIVATE, true, false),
6161
)
6262
}
@@ -70,7 +70,7 @@ class StaticMemberInspection : MixinInspection() {
7070

7171
val modifiers = member.modifierList!!
7272

73-
return modifiers.hasModifierProperty(PsiModifier.PUBLIC) &&
73+
return !modifiers.hasModifierProperty(PsiModifier.PRIVATE) &&
7474
modifiers.hasModifierProperty(PsiModifier.STATIC) &&
7575
modifiers.findAnnotation(SHADOW) == null &&
7676
modifiers.findAnnotation(OVERWRITE) == null &&

src/main/kotlin/platform/mixin/inspection/mixinextras/WrongOperationParametersInspection.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ class WrongOperationParametersInspection : MixinInspection() {
6161
PsiField::class.java
6262
) ?: return
6363

64-
if (!containingMethod.hasAnnotation(MixinConstants.MixinExtras.WRAP_OPERATION)) {
64+
if (!containingMethod.hasAnnotation(MixinConstants.MixinExtras.WRAP_OPERATION) &&
65+
!containingMethod.hasAnnotation(MixinConstants.MixinExtras.WRAP_METHOD)
66+
) {
6567
return
6668
}
6769

src/main/kotlin/platform/mixin/reference/AbstractMethodReference.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ abstract class AbstractMethodReference : PolyReferenceResolver(), MixinReference
8383
val stringValue = context.constantStringValue ?: return false
8484
val targetMethodInfo = parseSelector(stringValue, context) ?: return false
8585
val targets = getTargets(context) ?: return false
86-
return !targets.asSequence().flatMap { it.findMethods(targetMethodInfo) }.any()
86+
return !targets.asSequence().flatMap {
87+
targetMethodInfo.getCustomOwner(it).findMethods(targetMethodInfo)
88+
}.any()
8789
}
8890

8991
fun getReferenceIfAmbiguous(context: PsiElement): MemberReference? {
@@ -125,7 +127,10 @@ abstract class AbstractMethodReference : PolyReferenceResolver(), MixinReference
125127
selector: MixinSelector,
126128
): Sequence<ClassAndMethodNode> {
127129
return targets.asSequence()
128-
.flatMap { target -> target.findMethods(selector).map { ClassAndMethodNode(target, it) } }
130+
.flatMap { target ->
131+
val actualTarget = selector.getCustomOwner(target)
132+
actualTarget.findMethods(selector).map { ClassAndMethodNode(actualTarget, it) }
133+
}
129134
}
130135

131136
fun resolveIfUnique(context: PsiElement): ClassAndMethodNode? {

0 commit comments

Comments
 (0)