Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions src/main/kotlin/insight/generation/MinecraftClassCreateAction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,20 @@ class MinecraftClassCreateAction :
val isForge = MinecraftFacet.getInstance(module, ForgeModuleType) != null
val isNeoForge = MinecraftFacet.getInstance(module, NeoForgeModuleType) != null
val isFabric = MinecraftFacet.getInstance(module, FabricModuleType) != null
val mcVersion = MinecraftFacet.getInstance(module, McpModuleType)?.getSettings()
val forgeMcVersion = MinecraftFacet.getInstance(module, McpModuleType)?.getSettings()
?.minecraftVersion?.let(SemanticVersion::parse)
val fabricMcVersion =
MinecraftFacet.getInstance(module, FabricModuleType)?.computeVersion()//Qui mica è un FabricModule

if (isForge && mcVersion != null) {
if (isForge && forgeMcVersion != null) {
val icon = PlatformAssets.FORGE_ICON

if (mcVersion < MinecraftVersions.MC1_17) {
if (forgeMcVersion < MinecraftVersions.MC1_17) {
builder.addKind("Block", icon, MinecraftTemplates.FORGE_BLOCK_TEMPLATE)
builder.addKind("Enchantment", icon, MinecraftTemplates.FORGE_ENCHANTMENT_TEMPLATE)
builder.addKind("Item", icon, MinecraftTemplates.FORGE_ITEM_TEMPLATE)
builder.addKind("Packet", icon, MinecraftTemplates.FORGE_PACKET_TEMPLATE)
} else if (mcVersion < MinecraftVersions.MC1_18) {
} else if (forgeMcVersion < MinecraftVersions.MC1_18) {
builder.addKind("Block", icon, MinecraftTemplates.FORGE_1_17_BLOCK_TEMPLATE)
builder.addKind("Enchantment", icon, MinecraftTemplates.FORGE_1_17_ENCHANTMENT_TEMPLATE)
builder.addKind("Item", icon, MinecraftTemplates.FORGE_1_17_ITEM_TEMPLATE)
Expand All @@ -106,11 +108,19 @@ class MinecraftClassCreateAction :

if (isFabric) {
val icon = PlatformAssets.FABRIC_ICON
if (fabricMcVersion != null && fabricMcVersion >= MinecraftVersions.MC26_1) {
builder.addKind("Block", icon, MinecraftTemplates.FABRIC_26_1_BLOCK_TEMPLATE)
builder.addKind("Enchantment", icon, MinecraftTemplates.FABRIC_26_1_ENCHANTMENT_TEMPLATE)
builder.addKind("Item", icon, MinecraftTemplates.FABRIC_26_1_ITEM_TEMPLATE)
builder.addKind("Mob effect", icon, MinecraftTemplates.FABRIC_26_1_MOB_EFFECT_TEMPLATE)

builder.addKind("Block", icon, MinecraftTemplates.FABRIC_BLOCK_TEMPLATE)
builder.addKind("Enchantment", icon, MinecraftTemplates.FABRIC_ENCHANTMENT_TEMPLATE)
builder.addKind("Item", icon, MinecraftTemplates.FABRIC_ITEM_TEMPLATE)
builder.addKind("Status effect", icon, MinecraftTemplates.FABRIC_STATUS_EFFECT_TEMPLATE)
} else {
builder.addKind("Block", icon, MinecraftTemplates.FABRIC_1_21_11_BLOCK_TEMPLATE)
builder.addKind("Enchantment", icon, MinecraftTemplates.FABRIC_1_21_11_ENCHANTMENT_TEMPLATE)
builder.addKind("Item", icon, MinecraftTemplates.FABRIC_1_21_11_ITEM_TEMPLATE)
builder.addKind("Status effect", icon, MinecraftTemplates.FABRIC_1_21_11_STATUS_EFFECT_TEMPLATE)

}
}
}

Expand Down
32 changes: 31 additions & 1 deletion src/main/kotlin/platform/fabric/FabricModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@ import com.demonwav.mcdev.platform.mcp.fabricloom.FabricLoomData
import com.demonwav.mcdev.platform.mcp.mappings.HardcodedYarnToMojmap
import com.demonwav.mcdev.platform.mcp.mappings.HasCustomNamedMappings
import com.demonwav.mcdev.platform.mcp.mappings.MappingsManager
import com.demonwav.mcdev.util.SemanticVersion
import com.demonwav.mcdev.util.SourceType
import com.demonwav.mcdev.util.nullable
import com.demonwav.mcdev.util.runCatchingKtIdeaExceptions
import com.intellij.json.JsonUtil
import com.intellij.json.psi.JsonArray
import com.intellij.json.psi.JsonFile
import com.intellij.json.psi.JsonObject
import com.intellij.json.psi.JsonStringLiteral
import com.intellij.psi.PsiClass
import com.intellij.psi.PsiElement
Expand Down Expand Up @@ -67,6 +70,7 @@ class FabricModule internal constructor(facet: MinecraftFacet) : AbstractModule(
override val moduleType = FabricModuleType
override val type = PlatformType.FABRIC
override val icon = PlatformAssets.FABRIC_ICON
var fabricMinecraftVersion: SemanticVersion? = null;

override fun computeModIds(): List<String> {
val jsonFile = PsiManager.getInstance(project).findFile(fabricJson ?: return emptyList()) as? JsonFile
Expand All @@ -75,6 +79,30 @@ class FabricModule internal constructor(facet: MinecraftFacet) : AbstractModule(
return listOfNotNull((jsonObj.findProperty("id")?.value as? JsonStringLiteral)?.value)
}

fun computeVersion(): SemanticVersion? {
val jsonFile = PsiManager.getInstance(project).findFile(fabricJson ?: return null) as? JsonFile
?: return null
val jsonObj = JsonUtil.getTopLevelObject(jsonFile) ?: return null;
val depends = jsonObj.findProperty("depends")?.value as? JsonObject
val range = depends?.findProperty("minecraft")
val value = (range?.value as? JsonStringLiteral)?.value;
val arrayValue = (range?.value as? JsonArray)
if (value != null) {
val end = value.trimStart { !it.isDigit() }
return SemanticVersion.parse(end)
} else if (arrayValue != null) {
var majorVersion: SemanticVersion? = null;
for (child in arrayValue.valueList) {
val string = (child as? JsonStringLiteral)?.value ?: "0.0"
val end = string.trimStart { !it.isDigit() }
val value = SemanticVersion.parse(end)
if (majorVersion == null || value > majorVersion) majorVersion = value;
}
return majorVersion
}
return null
}

override fun isEventClassValid(eventClass: PsiClass, method: PsiMethod?) = true

override fun writeErrorMessageForEventParameter(eventClass: PsiClass, method: PsiMethod) = ""
Expand Down Expand Up @@ -107,6 +135,7 @@ class FabricModule internal constructor(facet: MinecraftFacet) : AbstractModule(

private fun detectMappings(): MappingDetectionResult {
val gradleData = GradleUtil.findGradleModuleData(facet.module) ?: return MappingDetectionResult.DEFAULT

val loomData = gradleData.children.find { it.key == FabricLoomData.KEY }?.data as? FabricLoomData
?: return MappingDetectionResult.DEFAULT
val mappingsFile = loomData.tinyMappings ?: return MappingDetectionResult.DEFAULT
Expand Down Expand Up @@ -147,7 +176,8 @@ class FabricModule internal constructor(facet: MinecraftFacet) : AbstractModule(

override fun visitMethodArg(argPosition: Int, lvIndex: Int, srcName: String?) = false

override fun visitMethodVar(lvtRowIndex: Int, lvIndex: Int, startOpIdx: Int, endOpIdx: Int, srcName: String?) = false
override fun visitMethodVar(lvtRowIndex: Int, lvIndex: Int, startOpIdx: Int, endOpIdx: Int, srcName: String?) =
false

override fun visitDstName(targetKind: MappedElementKind?, namespace: Int, name: String) {
if (namespace == namedIndex && name == "net/minecraft/client/MinecraftClient") {
Expand Down
27 changes: 19 additions & 8 deletions src/main/kotlin/util/MinecraftTemplates.kt
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,16 @@ class MinecraftTemplates : FileTemplateGroupDescriptorFactory {
}
FileTemplateGroupDescriptor("Fabric", PlatformAssets.FABRIC_ICON).let { fabricSkeletonGroup ->
skeletonGroup.addTemplate(fabricSkeletonGroup)
fabricSkeletonGroup.addTemplate(FileTemplateDescriptor(FABRIC_BLOCK_TEMPLATE))
fabricSkeletonGroup.addTemplate(FileTemplateDescriptor(FABRIC_ITEM_TEMPLATE))
fabricSkeletonGroup.addTemplate(FileTemplateDescriptor(FABRIC_ENCHANTMENT_TEMPLATE))
fabricSkeletonGroup.addTemplate(FileTemplateDescriptor(FABRIC_STATUS_EFFECT_TEMPLATE))
fabricSkeletonGroup.addTemplate(FileTemplateDescriptor(FABRIC_1_21_11_BLOCK_TEMPLATE))
fabricSkeletonGroup.addTemplate(FileTemplateDescriptor(FABRIC_1_21_11_ITEM_TEMPLATE))
fabricSkeletonGroup.addTemplate(FileTemplateDescriptor(FABRIC_1_21_11_ENCHANTMENT_TEMPLATE))
fabricSkeletonGroup.addTemplate(FileTemplateDescriptor(FABRIC_1_21_11_STATUS_EFFECT_TEMPLATE))

fabricSkeletonGroup.addTemplate(FileTemplateDescriptor(FABRIC_26_1_BLOCK_TEMPLATE))
fabricSkeletonGroup.addTemplate(FileTemplateDescriptor(FABRIC_26_1_ITEM_TEMPLATE))
fabricSkeletonGroup.addTemplate(FileTemplateDescriptor(FABRIC_26_1_ENCHANTMENT_TEMPLATE))
fabricSkeletonGroup.addTemplate(FileTemplateDescriptor(FABRIC_26_1_MOB_EFFECT_TEMPLATE))

}
}

Expand Down Expand Up @@ -268,10 +274,15 @@ class MinecraftTemplates : FileTemplateGroupDescriptorFactory {

const val FORGE_1_18_PACKET_TEMPLATE = "ForgePacket (1.18+).java"

const val FABRIC_BLOCK_TEMPLATE = "FabricBlock.java"
const val FABRIC_ITEM_TEMPLATE = "FabricItem.java"
const val FABRIC_ENCHANTMENT_TEMPLATE = "FabricEnchantment.java"
const val FABRIC_STATUS_EFFECT_TEMPLATE = "FabricStatusEffect.java"
const val FABRIC_1_21_11_BLOCK_TEMPLATE = "FabricBlock (1.21.11-).java"
const val FABRIC_1_21_11_ITEM_TEMPLATE = "FabricItem (1.21.11-).java"
const val FABRIC_1_21_11_ENCHANTMENT_TEMPLATE = "FabricEnchantment (1.21.11-).java"
const val FABRIC_1_21_11_STATUS_EFFECT_TEMPLATE = "FabricStatusEffect (1.21.11-).java"

const val FABRIC_26_1_BLOCK_TEMPLATE = "FabricBlock (26.1+).java"
const val FABRIC_26_1_ITEM_TEMPLATE = "FabricItem (26.1+).java"
const val FABRIC_26_1_ENCHANTMENT_TEMPLATE = "FabricEnchantment (26.1+).java"
const val FABRIC_26_1_MOB_EFFECT_TEMPLATE = "FabricMobEffect (26.1+).java"

const val NEOFORGE_MIXINS_JSON_TEMPLATE = "NeoForge Mixins Config.json"
const val NEOFORGE_MAIN_CLASS_TEMPLATE = "NeoForge Main Class.java"
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/util/MinecraftVersions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ object MinecraftVersions {
val MC1_21_1 = SemanticVersion.release(1, 21, 1)
val MC1_21_11 = SemanticVersion.release(1, 21, 11)
val MC26_1 = SemanticVersion.release(26, 1)
val MC26_2 = SemanticVersion.release(26, 2)

fun requiredJavaVersion(minecraftVersion: SemanticVersion) = when {
minecraftVersion <= MC1_16_5 -> JavaSdkVersion.JDK_1_8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@

<html>
<body>
A basic enchantment class for fabric.
A basic block class for fabric 1.21.11-.
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
#parse("File Header.java")

import net.minecraft.world.level.block.Block;

public class ${NAME} extends Block {
public ${NAME}(Properties properties) {
super(properties);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@

<html>
<body>
A basic block class for fabric.
A basic block class for fabric 26.1+.
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!--
Minecraft Development for IntelliJ

https://mcdev.io/

Copyright (C) 2025 minecraft-dev

This program 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 3.0 only.

This program 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 General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
-->

<html>
<body>
A basic enchantment class for fabric 1.21.11-.
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
#parse("File Header.java")

//Not functional for MC 1.20.3+
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentCategory;

public class ${NAME} extends Enchantment {
public ${NAME}(Rarity rarity, EnchantmentCategory category, EquipmentSlot[] slots) {
super(rarity, category, slots);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!--
Minecraft Development for IntelliJ

https://mcdev.io/

Copyright (C) 2025 minecraft-dev

This program 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 3.0 only.

This program 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 General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
-->

<html>
<body>
A basic enchantment class for fabric 26.1+.
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@

<html>
<body>
An empty Fabric item class.
An empty Fabric item class for 1.21.11-.
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
#parse("File Header.java")

import net.minecraft.world.item.Item;

public class ${NAME} extends Item {
public ${NAME}(Properties props) {
super(props);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@

<html>
<body>
An empty Fabric status effect class.
An empty Fabric item class for 1.21.11-.
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
#parse("File Header.java")

import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectCategory;
public class ${NAME} extends MobEffect {
public ${NAME}(MobEffectCategory mobEffectCategory, int color) {
super(mobEffectCategory, color);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!--
Minecraft Development for IntelliJ

https://mcdev.io/

Copyright (C) 2025 minecraft-dev

This program 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 3.0 only.

This program 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 General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
-->

<html>
<body>
An empty Fabric status effect class for 1.21.11- .
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!--
Minecraft Development for IntelliJ
https://mcdev.io/
Copyright (C) 2025 minecraft-dev
This program 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 3.0 only.
This program 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 General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
-->

<html>
<body>
An empty Fabric status effect class for 1.21.11- .
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
#parse("File Header.java")

//Not functional for MC 1.20.3+
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentCategory;

public class ${NAME} extends Enchantment {
public ${NAME}(Rarity rarity, EnchantmentCategory category, EquipmentSlot[] slots) {
super(rarity, category, slots);
public ${NAME}(Rarity rarity, EnchantmentCategory category, EquipmentSlot[] slots){
super(rarity, category, slots);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
#parse("File Header.java")

//Not functional for MC 1.20.3+
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentCategory;
Expand Down
Loading