Skip to content

Commit 0333ba1

Browse files
committed
Reorganize according to new Polyfrost code guidelines.
1 parent 674a41a commit 0333ba1

16 files changed

+301
-54
lines changed

build.gradle.kts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,18 @@ toolkitLoomHelper {
4848
useKotlinForForge()
4949
}
5050
}
51+
52+
dependencies {
53+
// Add Fabric Language Kotlin and (Legacy) Fabric API as dependencies (these are both optional but are particularly useful).
54+
if (mcData.isFabric) {
55+
modImplementation("net.fabricmc:fabric-language-kotlin:${mcData.dependencies.fabric.fabricLanguageKotlinVersion}")
56+
57+
if (mcData.isLegacyFabric) {
58+
// 1.8.9 - 1.12.2
59+
modImplementation("net.legacyfabric.legacy-fabric-api:legacy-fabric-api:${mcData.dependencies.legacyFabric.legacyFabricApiVersion}")
60+
} else {
61+
// 1.16.5+
62+
modImplementation("net.fabricmc.fabric-api:fabric-api:${mcData.dependencies.fabric.fabricApiVersion}")
63+
}
64+
}
65+
}

root.gradle.kts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,31 @@ preprocess {
1010
// "1.8.9-forge"(10809, "srg")
1111
// }
1212

13-
"1.8.9-forge"(10809, "srg")
13+
"1.20.4-forge"(12004, "srg") {
14+
"1.20.4-fabric"(12004, "yarn") {
15+
"1.19.4-fabric"(11904, "yarn") {
16+
"1.19.4-forge"(11904, "srg") {
17+
"1.18.2-forge"(11802, "srg") {
18+
"1.18.2-fabric"(11802, "yarn") {
19+
"1.17.1-fabric"(11701, "yarn") {
20+
"1.17.1-forge"(11701, "srg") {
21+
"1.16.5-forge"(11605, "srg") {
22+
"1.16.5-fabric"(11605, "yarn") {
23+
"1.12.2-fabric"(11202, "yarn") {
24+
"1.12.2-forge"(11202, "srg") {
25+
"1.8.9-forge"(10809, "srg") {
26+
"1.8.9-fabric"(10809, "yarn")
27+
}
28+
}
29+
}
30+
}
31+
}
32+
}
33+
}
34+
}
35+
}
36+
}
37+
}
38+
}
39+
}
1440
}

settings.gradle.kts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,19 @@ rootProject.buildFileName = "root.gradle.kts"
4141
// **REMEMBER TO ALSO UPDATE THE `root.gradle.kts` AND `build.gradle.kts` FILES WITH THE NEW VERSION(S).
4242
listOf(
4343
"1.8.9-forge",
44-
// ...
44+
"1.8.9-fabric",
45+
"1.12.2-fabric",
46+
"1.12.2-forge",
47+
"1.16.5-forge",
48+
"1.16.5-fabric",
49+
"1.17.1-forge",
50+
"1.17.1-fabric",
51+
"1.18.2-forge",
52+
"1.18.2-fabric",
53+
"1.19.4-forge",
54+
"1.19.4-fabric",
55+
"1.20.4-fabric",
56+
"1.20.4-forge"
4557
).forEach { version ->
4658
include(":$version")
4759
project(":$version").apply {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.polyfrost.example;
2+
3+
public class Example {
4+
5+
public static final Example INSTANCE = new Example();
6+
7+
public void initialize() {
8+
// TODO
9+
}
10+
11+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package org.polyfrost.example;
2+
3+
public class ExampleConstants {
4+
5+
// Sets the variables from `gradle.properties`. Depends on the `bloom` DGT plugin.
6+
public static final String ID = "@MOD_ID@";
7+
public static final String NAME = "@MOD_NAME@";
8+
public static final String VERSION = "@MOD_VERSION@";
9+
10+
}
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
package org.polyfrost.example;
2+
3+
//#if FABRIC
4+
//$$ import net.fabricmc.api.ModInitializer;
5+
//$$ import net.fabricmc.api.ClientModInitializer;
6+
//$$ import net.fabricmc.api.DedicatedServerModInitializer;
7+
//#elseif FORGE
8+
//#if MC >= 1.16.5
9+
//$$ import net.minecraftforge.eventbus.api.IEventBus;
10+
//$$ import net.minecraftforge.fml.common.Mod;
11+
//$$ import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
12+
//$$ import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
13+
//$$ import net.minecraftforge.fml.event.lifecycle.FMLDedicatedServerSetupEvent;
14+
//$$ import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
15+
//#else
16+
import net.minecraftforge.fml.common.Mod;
17+
import net.minecraftforge.fml.common.Mod.EventHandler;
18+
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
19+
//#endif
20+
//#elseif NEOFORGE
21+
//$$ import net.neoforged.bus.api.IEventBus;
22+
//$$ import net.neoforged.fml.common.Mod;
23+
//$$ import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
24+
//$$ import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent;
25+
//$$ import net.neoforged.fml.event.lifecycle.FMLDedicatedServerSetupEvent;
26+
//#endif
27+
28+
import org.polyfrost.example.Example;
29+
import org.polyfrost.example.client.ExampleClient;
30+
import org.polyfrost.example.server.ExampleServer;
31+
32+
//#if FORGE-LIKE
33+
//$$ import org.polyfrost.example.ExampleConstants;
34+
//$$
35+
//#if MC >= 1.16.5
36+
//$$ @Mod(ModTemplateConstants.ID)
37+
//#else
38+
//$$ @Mod(modid = ExampleConstants.ID, version = ExampleConstants.VERSION)
39+
//#endif
40+
//#endif
41+
public class ExampleEntrypoint
42+
//#if FABRIC
43+
//$$ implements ModInitializer, ClientModInitializer, DedicatedServerModInitializer
44+
//#endif
45+
{
46+
47+
//#if FORGE && MC >= 1.16.5
48+
//$$ public ExampleEntrypoint() {
49+
//$$ setupForgeEvents(FMLJavaModLoadingContext.get().getModEventBus());
50+
//$$ }
51+
//#elseif NEOFORGE
52+
//$$ public ExampleEntrypoint(IEventBus modEventBus) {
53+
//$$ setupForgeEvents(modEventBus);
54+
//$$ }
55+
//#endif
56+
57+
//#if FABRIC
58+
//$$ @Override
59+
//#elseif FORGE && MC <= 1.12.2
60+
@Mod.EventHandler
61+
//#endif
62+
public void onInitialize(
63+
//#if FORGE-LIKE
64+
//#if MC >= 1.16.5
65+
//$$ FMLCommonSetupEvent event
66+
//#else
67+
FMLInitializationEvent event
68+
//#endif
69+
//#endif
70+
) {
71+
Example.INSTANCE.initialize();
72+
}
73+
74+
//#if FABRIC
75+
//$$ @Override
76+
//#elseif FORGE && MC <= 1.12.2
77+
@Mod.EventHandler
78+
//#endif
79+
public void onInitializeClient(
80+
//#if FORGE-LIKE
81+
//#if MC >= 1.16.5
82+
//$$ FMLClientSetupEvent event
83+
//#else
84+
FMLInitializationEvent event
85+
//#endif
86+
//#endif
87+
) {
88+
//#if FORGE && MC <= 1.12.2
89+
//$$ if (!event.side.isClient) {
90+
//$$ return;
91+
//$$ }
92+
//#endif
93+
94+
ExampleClient.INSTANCE.initialize();
95+
}
96+
97+
//#if FABRIC
98+
//$$ @Override
99+
//#elseif FORGE && MC <= 1.12.2
100+
@Mod.EventHandler
101+
//#endif
102+
public void onInitializeServer(
103+
//#if FORGE-LIKE
104+
//#if MC >= 1.16.5
105+
//$$ FMLDedicatedServerSetupEvent event
106+
//#else
107+
FMLInitializationEvent event
108+
//#endif
109+
//#endif
110+
) {
111+
//#if FORGE && MC <= 1.12.2
112+
//$$ if (!event.side.isServer) {
113+
//$$ return;
114+
//$$ }
115+
//#endif
116+
117+
ExampleServer.INSTANCE.initialize();
118+
}
119+
120+
//#if FORGE-LIKE && MC >= 1.16.5
121+
//$$ private void setupForgeEvents(IEventBus modEventBus) {
122+
//$$ modEventBus.addListener(this::onInitialize)
123+
//$$ modEventBus.addListener(this::onInitializeClient)
124+
//$$ modEventBus.addListener(this::onInitializeServer)
125+
//$$ }
126+
//#endif
127+
128+
}

src/main/java/org/polyfrost/example/ExampleMod.java

Lines changed: 0 additions & 39 deletions
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package org.polyfrost.example.client;
2+
3+
import org.polyfrost.oneconfig.api.commands.v1.CommandManager;
4+
5+
public class ExampleClient {
6+
7+
public static final ExampleClient INSTANCE = new ExampleClient();
8+
9+
private ExampleConfig config;
10+
11+
public void initialize() {
12+
System.out.println("Initializing Example Client");
13+
14+
config = new ExampleConfig();
15+
CommandManager.registerCommand(new ExampleCommand());
16+
}
17+
18+
public ExampleConfig getConfig() {
19+
return config;
20+
}
21+
22+
}

src/main/java/org/polyfrost/example/command/ExampleCommand.java renamed to src/main/java/org/polyfrost/example/client/ExampleCommand.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
package org.polyfrost.example.command;
1+
package org.polyfrost.example.client;
22

3-
import org.polyfrost.example.ExampleMod;
3+
import org.polyfrost.example.ExampleConstants;
44
import org.polyfrost.oneconfig.api.commands.v1.factories.annotated.Command;
55
import org.polyfrost.oneconfig.utils.v1.dsl.ScreensKt;
66

@@ -9,14 +9,14 @@
99
* Registered in ExampleMod.java with `CommandManager.INSTANCE.registerCommand(new ExampleCommand());`
1010
*
1111
* @see Command
12-
* @see ExampleMod
12+
* @see ExampleClient
1313
*/
14-
@Command(value = ExampleMod.ID, description = "Access the " + ExampleMod.NAME + " GUI.")
14+
@Command(value = ExampleConstants.ID, description = "Access the " + ExampleConstants.NAME + " GUI.")
1515
public class ExampleCommand {
1616

1717
@Command
1818
private void main() {
19-
ScreensKt.openUI(ExampleMod.getConfig());
19+
ScreensKt.openUI(ExampleClient.INSTANCE.getConfig());
2020
}
2121

2222
}

src/main/java/org/polyfrost/example/config/ExampleConfig.java renamed to src/main/java/org/polyfrost/example/client/ExampleConfig.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
package org.polyfrost.example.config;
1+
package org.polyfrost.example.client;
22

3-
import org.polyfrost.example.ExampleMod;
3+
import org.polyfrost.example.ExampleConstants;
44
import org.polyfrost.oneconfig.api.config.v1.Config;
55
import org.polyfrost.oneconfig.api.config.v1.annotations.Dropdown;
66
import org.polyfrost.oneconfig.api.config.v1.annotations.Slider;
@@ -29,7 +29,7 @@ public class ExampleConfig extends Config {
2929
public static int exampleDropdown = 1; // Default option (in this case "Option 2")
3030

3131
public ExampleConfig() {
32-
super(ExampleMod.ID + ".json", ExampleMod.NAME, Category.OTHER); // TODO: Change your category here.
32+
super(ExampleConstants.ID + ".json", ExampleConstants.NAME, Category.OTHER); // TODO: Change your category here.
3333
}
3434

3535
}

0 commit comments

Comments
 (0)