User: rednesto Date: 29 Dec 21 18:54 Revision: 62e1c65ef2c5bc4cf78f73522a715abcf26c1ff2 Summary: Fix #1783 outdated Forge 1.17+ templates TeamCity URL: https://ci.denwav.dev/viewModification.html?tab=vcsModificationFiles&modId=7919&personal=false Index: src/main/kotlin/insight/generation/MinecraftClassCreateAction.kt =================================================================== --- src/main/kotlin/insight/generation/MinecraftClassCreateAction.kt (revision a6d67b25f80c1f78d3383686927304fed673063b) +++ src/main/kotlin/insight/generation/MinecraftClassCreateAction.kt (revision 62e1c65ef2c5bc4cf78f73522a715abcf26c1ff2) @@ -15,7 +15,10 @@ import com.demonwav.mcdev.facet.MinecraftFacet import com.demonwav.mcdev.platform.fabric.FabricModuleType import com.demonwav.mcdev.platform.forge.ForgeModuleType +import com.demonwav.mcdev.platform.mcp.McpModuleType import com.demonwav.mcdev.util.MinecraftTemplates +import com.demonwav.mcdev.util.MinecraftVersions +import com.demonwav.mcdev.util.SemanticVersion import com.demonwav.mcdev.util.findModule import com.intellij.codeInsight.daemon.JavaErrorBundle import com.intellij.codeInsight.daemon.impl.analysis.HighlightClassUtil @@ -50,18 +53,32 @@ builder.setTitle(CAPTION) builder.setValidator(ClassInputValidator(project, directory)) - val module = directory.findModule() - val isForge = module?.let { MinecraftFacet.getInstance(it, ForgeModuleType) } != null - val isFabric = module?.let { MinecraftFacet.getInstance(it, FabricModuleType) } != null + val module = directory.findModule() ?: return + val isForge = MinecraftFacet.getInstance(module, ForgeModuleType) != null + val isFabric = MinecraftFacet.getInstance(module, FabricModuleType) != null + val mcVersion = MinecraftFacet.getInstance(module, McpModuleType)?.getSettings() + ?.minecraftVersion?.let(SemanticVersion::parse) - if (isForge) { + if (isForge && mcVersion != null) { val icon = PlatformAssets.FORGE_ICON + if (mcVersion < MinecraftVersions.MC1_17) { - builder.addKind("Block", icon, MinecraftTemplates.FORGE_BLOCK_TEMPLATE) - builder.addKind("Item", icon, MinecraftTemplates.FORGE_ITEM_TEMPLATE) - builder.addKind("Packet", icon, MinecraftTemplates.FORGE_PACKET_TEMPLATE) - builder.addKind("Enchantment", icon, MinecraftTemplates.FORGE_ENCHANTMENT_TEMPLATE) + builder.addKind("Block", icon, MinecraftTemplates.FORGE_BLOCK_TEMPLATE) + builder.addKind("Item", icon, MinecraftTemplates.FORGE_ITEM_TEMPLATE) + builder.addKind("Packet", icon, MinecraftTemplates.FORGE_PACKET_TEMPLATE) + builder.addKind("Enchantment", icon, MinecraftTemplates.FORGE_ENCHANTMENT_TEMPLATE) + } else if (mcVersion < MinecraftVersions.MC1_18) { + builder.addKind("Block", icon, MinecraftTemplates.FORGE_1_17_BLOCK_TEMPLATE) + builder.addKind("Item", icon, MinecraftTemplates.FORGE_1_17_ITEM_TEMPLATE) + builder.addKind("Packet", icon, MinecraftTemplates.FORGE_1_17_PACKET_TEMPLATE) + builder.addKind("Enchantment", icon, MinecraftTemplates.FORGE_1_17_ENCHANTMENT_TEMPLATE) + } else { + builder.addKind("Block", icon, MinecraftTemplates.FORGE_1_17_BLOCK_TEMPLATE) + builder.addKind("Item", icon, MinecraftTemplates.FORGE_1_17_ITEM_TEMPLATE) + builder.addKind("Packet", icon, MinecraftTemplates.FORGE_1_18_PACKET_TEMPLATE) + builder.addKind("Enchantment", icon, MinecraftTemplates.FORGE_1_17_ENCHANTMENT_TEMPLATE) - } + } + } if (isFabric) { val icon = PlatformAssets.FABRIC_ICON @@ -73,11 +90,11 @@ override fun isAvailable(dataContext: DataContext): Boolean { val psi = dataContext.getData(CommonDataKeys.PSI_ELEMENT) - val isModModule = psi?.findModule()?.let { - MinecraftFacet.getInstance(it, FabricModuleType, ForgeModuleType) - } != null + val module = psi?.findModule() ?: return false + val isModModule = MinecraftFacet.getInstance(module, FabricModuleType, ForgeModuleType) != null + val hasMcVersion = MinecraftFacet.getInstance(module, McpModuleType)?.getSettings()?.minecraftVersion != null - return isModModule && super.isAvailable(dataContext) + return isModModule && hasMcVersion && super.isAvailable(dataContext) } override fun checkPackageExists(directory: PsiDirectory): Boolean { Index: src/main/kotlin/util/MinecraftTemplates.kt =================================================================== --- src/main/kotlin/util/MinecraftTemplates.kt (revision a6d67b25f80c1f78d3383686927304fed673063b) +++ src/main/kotlin/util/MinecraftTemplates.kt (revision 62e1c65ef2c5bc4cf78f73522a715abcf26c1ff2) @@ -154,6 +154,17 @@ forgeSkeletonGroup.addTemplate(FileTemplateDescriptor(FORGE_BLOCK_TEMPLATE)) forgeSkeletonGroup.addTemplate(FileTemplateDescriptor(FORGE_ITEM_TEMPLATE)) } + FileTemplateGroupDescriptor("Forge 1.17+", PlatformAssets.FORGE_ICON).let { forgeSkeletonGroup -> + skeletonGroup.addTemplate(forgeSkeletonGroup) + forgeSkeletonGroup.addTemplate(FileTemplateDescriptor(FORGE_1_17_ENCHANTMENT_TEMPLATE)) + forgeSkeletonGroup.addTemplate(FileTemplateDescriptor(FORGE_1_17_PACKET_TEMPLATE)) + forgeSkeletonGroup.addTemplate(FileTemplateDescriptor(FORGE_1_17_BLOCK_TEMPLATE)) + forgeSkeletonGroup.addTemplate(FileTemplateDescriptor(FORGE_1_17_ITEM_TEMPLATE)) + } + FileTemplateGroupDescriptor("Forge 1.18+", PlatformAssets.FORGE_ICON).let { forgeSkeletonGroup -> + skeletonGroup.addTemplate(forgeSkeletonGroup) + forgeSkeletonGroup.addTemplate(FileTemplateDescriptor(FORGE_1_18_PACKET_TEMPLATE)) + } FileTemplateGroupDescriptor("Fabric", PlatformAssets.FABRIC_ICON).let { fabricSkeletonGroup -> skeletonGroup.addTemplate(fabricSkeletonGroup) fabricSkeletonGroup.addTemplate(FileTemplateDescriptor(FABRIC_BLOCK_TEMPLATE)) @@ -263,6 +274,13 @@ const val FORGE_PACKET_TEMPLATE = "ForgePacket.java" const val FORGE_ENCHANTMENT_TEMPLATE = "ForgeEnchantment.java" + const val FORGE_1_17_BLOCK_TEMPLATE = "ForgeBlock (1.17+).java" + const val FORGE_1_17_ITEM_TEMPLATE = "ForgeItem (1.17+).java" + const val FORGE_1_17_PACKET_TEMPLATE = "ForgePacket (1.17+).java" + const val FORGE_1_17_ENCHANTMENT_TEMPLATE = "ForgeEnchantment (1.17+).java" + + 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" Index: src/main/resources/fileTemplates/j2ee/skeleton/forge/ForgeBlock (1.17+).java.ft =================================================================== --- src/main/resources/fileTemplates/j2ee/skeleton/forge/ForgeBlock (1.17+).java.ft (revision 62e1c65ef2c5bc4cf78f73522a715abcf26c1ff2) +++ src/main/resources/fileTemplates/j2ee/skeleton/forge/ForgeBlock (1.17+).java.ft (revision 62e1c65ef2c5bc4cf78f73522a715abcf26c1ff2) @@ -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); + } +} Index: src/main/resources/fileTemplates/j2ee/skeleton/forge/ForgeBlock (1.17+).java.html =================================================================== --- src/main/resources/fileTemplates/j2ee/skeleton/forge/ForgeBlock (1.17+).java.html (revision 62e1c65ef2c5bc4cf78f73522a715abcf26c1ff2) +++ src/main/resources/fileTemplates/j2ee/skeleton/forge/ForgeBlock (1.17+).java.html (revision 62e1c65ef2c5bc4cf78f73522a715abcf26c1ff2) @@ -0,0 +1,15 @@ + + + + + A basic block class for forge 1.17+. + + Index: src/main/resources/fileTemplates/j2ee/skeleton/forge/ForgeEnchantment (1.17+).java.ft =================================================================== --- src/main/resources/fileTemplates/j2ee/skeleton/forge/ForgeEnchantment (1.17+).java.ft (revision 62e1c65ef2c5bc4cf78f73522a715abcf26c1ff2) +++ src/main/resources/fileTemplates/j2ee/skeleton/forge/ForgeEnchantment (1.17+).java.ft (revision 62e1c65ef2c5bc4cf78f73522a715abcf26c1ff2) @@ -0,0 +1,12 @@ +#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end +#parse("File Header.java") + +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); + } +} Index: src/main/resources/fileTemplates/j2ee/skeleton/forge/ForgeEnchantment (1.17+).java.html =================================================================== --- src/main/resources/fileTemplates/j2ee/skeleton/forge/ForgeEnchantment (1.17+).java.html (revision 62e1c65ef2c5bc4cf78f73522a715abcf26c1ff2) +++ src/main/resources/fileTemplates/j2ee/skeleton/forge/ForgeEnchantment (1.17+).java.html (revision 62e1c65ef2c5bc4cf78f73522a715abcf26c1ff2) @@ -0,0 +1,15 @@ + + + + + Forge 1.17+ style enchantment class + + Index: src/main/resources/fileTemplates/j2ee/skeleton/forge/ForgeItem (1.17+).java.ft =================================================================== --- src/main/resources/fileTemplates/j2ee/skeleton/forge/ForgeItem (1.17+).java.ft (revision 62e1c65ef2c5bc4cf78f73522a715abcf26c1ff2) +++ src/main/resources/fileTemplates/j2ee/skeleton/forge/ForgeItem (1.17+).java.ft (revision 62e1c65ef2c5bc4cf78f73522a715abcf26c1ff2) @@ -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 properties) { + super(properties); + } +} Index: src/main/resources/fileTemplates/j2ee/skeleton/forge/ForgeItem (1.17+).java.html =================================================================== --- src/main/resources/fileTemplates/j2ee/skeleton/forge/ForgeItem (1.17+).java.html (revision 62e1c65ef2c5bc4cf78f73522a715abcf26c1ff2) +++ src/main/resources/fileTemplates/j2ee/skeleton/forge/ForgeItem (1.17+).java.html (revision 62e1c65ef2c5bc4cf78f73522a715abcf26c1ff2) @@ -0,0 +1,15 @@ + + + + + An empty Forge 1.17+ item class. + + Index: src/main/resources/fileTemplates/j2ee/skeleton/forge/ForgePacket (1.17+).java.ft =================================================================== --- src/main/resources/fileTemplates/j2ee/skeleton/forge/ForgePacket (1.17+).java.ft (revision 62e1c65ef2c5bc4cf78f73522a715abcf26c1ff2) +++ src/main/resources/fileTemplates/j2ee/skeleton/forge/ForgePacket (1.17+).java.ft (revision 62e1c65ef2c5bc4cf78f73522a715abcf26c1ff2) @@ -0,0 +1,28 @@ +#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end +#parse("File Header.java") + +import net.minecraft.network.FriendlyByteBuf; +import net.minecraftforge.fmllegacy.network.NetworkEvent; +import java.util.function.Supplier; + +public class ${NAME} { + + public ${NAME}() { + + } + + public ${NAME}(FriendlyByteBuf buf) { + + } + + public void toBytes(FriendlyByteBuf buf) { + + } + + public void handle(Supplier ctx) { + ctx.get().enqueueWork(() -> { + + }); + ctx.get().setPacketHandled(true); + } +} Index: src/main/resources/fileTemplates/j2ee/skeleton/forge/ForgePacket (1.17+).java.html =================================================================== --- src/main/resources/fileTemplates/j2ee/skeleton/forge/ForgePacket (1.17+).java.html (revision 62e1c65ef2c5bc4cf78f73522a715abcf26c1ff2) +++ src/main/resources/fileTemplates/j2ee/skeleton/forge/ForgePacket (1.17+).java.html (revision 62e1c65ef2c5bc4cf78f73522a715abcf26c1ff2) @@ -0,0 +1,15 @@ + + + + + Forge 1.17+ style packet class + + Index: src/main/resources/fileTemplates/j2ee/skeleton/forge/ForgePacket (1.18+).java.ft =================================================================== --- src/main/resources/fileTemplates/j2ee/skeleton/forge/ForgePacket (1.18+).java.ft (revision 62e1c65ef2c5bc4cf78f73522a715abcf26c1ff2) +++ src/main/resources/fileTemplates/j2ee/skeleton/forge/ForgePacket (1.18+).java.ft (revision 62e1c65ef2c5bc4cf78f73522a715abcf26c1ff2) @@ -0,0 +1,28 @@ +#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end +#parse("File Header.java") + +import net.minecraft.network.FriendlyByteBuf; +import net.minecraftforge.network.NetworkEvent; +import java.util.function.Supplier; + +public class ${NAME} { + + public ${NAME}() { + + } + + public ${NAME}(FriendlyByteBuf buf) { + + } + + public void toBytes(FriendlyByteBuf buf) { + + } + + public void handle(Supplier ctx) { + ctx.get().enqueueWork(() -> { + + }); + ctx.get().setPacketHandled(true); + } +} Index: src/main/resources/fileTemplates/j2ee/skeleton/forge/ForgePacket (1.18+).java.html =================================================================== --- src/main/resources/fileTemplates/j2ee/skeleton/forge/ForgePacket (1.18+).java.html (revision 62e1c65ef2c5bc4cf78f73522a715abcf26c1ff2) +++ src/main/resources/fileTemplates/j2ee/skeleton/forge/ForgePacket (1.18+).java.html (revision 62e1c65ef2c5bc4cf78f73522a715abcf26c1ff2) @@ -0,0 +1,15 @@ + + + + + Forge 1.18+ style packet class + +