aboutsummaryrefslogtreecommitdiff
path: root/common/src/main/kotlin/net/examplemod
diff options
context:
space:
mode:
Diffstat (limited to 'common/src/main/kotlin/net/examplemod')
-rw-r--r--common/src/main/kotlin/net/examplemod/ExampleExpectPlatform.kt30
-rw-r--r--common/src/main/kotlin/net/examplemod/ExampleMod.kt31
-rw-r--r--common/src/main/kotlin/net/examplemod/mixin/MixinTitleScreen.kt23
3 files changed, 84 insertions, 0 deletions
diff --git a/common/src/main/kotlin/net/examplemod/ExampleExpectPlatform.kt b/common/src/main/kotlin/net/examplemod/ExampleExpectPlatform.kt
new file mode 100644
index 0000000..4949054
--- /dev/null
+++ b/common/src/main/kotlin/net/examplemod/ExampleExpectPlatform.kt
@@ -0,0 +1,30 @@
+package net.examplemod
+
+import dev.architectury.injectables.annotations.ExpectPlatform
+import dev.architectury.platform.Platform
+import java.nio.file.Path
+
+object ExampleExpectPlatform {
+ /**
+ * We can use [Platform.getConfigFolder] but this is just an example of [ExpectPlatform].
+ *
+ *
+ * This must be a **public static** method. The platform-implemented solution must be placed under a
+ * platform sub-package, with its class suffixed with `Impl`.
+ *
+ *
+ * Example:
+ * Expect: net.examplemod.ExampleExpectPlatform#getConfigDirectory()
+ * Actual Fabric: net.examplemod.fabric.ExampleExpectPlatformImpl#getConfigDirectory()
+ * Actual Forge: net.examplemod.forge.ExampleExpectPlatformImpl#getConfigDirectory()
+ *
+ *
+ * [You should also get the IntelliJ plugin to help with @ExpectPlatform.](https://plugins.jetbrains.com/plugin/16210-architectury)
+ */
+ @ExpectPlatform
+ @JvmStatic
+ fun getConfigDirectory(): Path {
+ // Just throw an error, the content should get replaced at runtime.
+ throw AssertionError()
+ }
+}
diff --git a/common/src/main/kotlin/net/examplemod/ExampleMod.kt b/common/src/main/kotlin/net/examplemod/ExampleMod.kt
new file mode 100644
index 0000000..4f618ce
--- /dev/null
+++ b/common/src/main/kotlin/net/examplemod/ExampleMod.kt
@@ -0,0 +1,31 @@
+package net.examplemod
+
+import com.google.common.base.Suppliers
+import dev.architectury.registry.CreativeTabRegistry
+import dev.architectury.registry.registries.DeferredRegister
+import dev.architectury.registry.registries.Registries
+import dev.architectury.registry.registries.RegistrySupplier
+import net.minecraft.core.Registry
+import net.minecraft.resources.ResourceLocation
+import net.minecraft.world.item.CreativeModeTab
+import net.minecraft.world.item.Item
+import net.minecraft.world.item.ItemStack
+import java.util.function.Supplier
+
+object ExampleMod {
+ const val MOD_ID = "examplemod"
+
+ // We can use this if we don't want to use DeferredRegister
+ @Suppress("unused")
+ val REGISTRIES: Supplier<Registries> = Suppliers.memoize { Registries.get(MOD_ID) }
+
+ // Registering a new creative tab
+ val EXAMPLE_TAB: CreativeModeTab = CreativeTabRegistry.create(ResourceLocation(MOD_ID, "example_tab")) { ItemStack(EXAMPLE_ITEM.get()) }
+ val ITEMS: DeferredRegister<Item> = DeferredRegister.create(MOD_ID, Registry.ITEM_REGISTRY)
+ val EXAMPLE_ITEM: RegistrySupplier<Item> = ITEMS.register("example_item") { Item(Item.Properties().tab(EXAMPLE_TAB)) }
+
+ fun init() {
+ ITEMS.register()
+ println(ExampleExpectPlatform.getConfigDirectory().toAbsolutePath().normalize().toString())
+ }
+}
diff --git a/common/src/main/kotlin/net/examplemod/mixin/MixinTitleScreen.kt b/common/src/main/kotlin/net/examplemod/mixin/MixinTitleScreen.kt
new file mode 100644
index 0000000..0b7e009
--- /dev/null
+++ b/common/src/main/kotlin/net/examplemod/mixin/MixinTitleScreen.kt
@@ -0,0 +1,23 @@
+package net.examplemod.mixin
+
+import net.minecraft.client.gui.screens.TitleScreen
+import org.objectweb.asm.Opcodes
+import org.spongepowered.asm.mixin.Mixin
+import org.spongepowered.asm.mixin.injection.At
+import org.spongepowered.asm.mixin.injection.Inject
+import org.spongepowered.asm.mixin.injection.Redirect
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo
+
+@Mixin(TitleScreen::class)
+class MixinTitleScreen {
+ @Inject(at = [At("HEAD")], method = ["init()V"])
+ private fun init(info: CallbackInfo) {
+ println("Hello from example architectury common mixin!")
+ }
+
+ @Redirect(method = ["render"], at = At("FIELD", target = "minceraftEasterEgg", opcode = Opcodes.GETFIELD))
+ private fun nextFloat(t: TitleScreen): Boolean {
+ return true
+ }
+
+}