aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorappable <enzospiacitelli@gmail.com>2022-10-11 14:32:32 -0700
committerappable <enzospiacitelli@gmail.com>2022-10-11 14:32:32 -0700
commit363b2426f8d9e45e52c472750c798dcaceb05a88 (patch)
treed50c71d73f4333253ef28f5e53c1a148fc7f8ab5 /src
downloadAmbientAddons-363b2426f8d9e45e52c472750c798dcaceb05a88.tar.gz
AmbientAddons-363b2426f8d9e45e52c472750c798dcaceb05a88.tar.bz2
AmbientAddons-363b2426f8d9e45e52c472750c798dcaceb05a88.zip
Initial commit
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/examplemod/mixin/MixinGuiMainMenu.java16
-rw-r--r--src/main/kotlin/com/examplemod/ExampleMod.kt61
-rw-r--r--src/main/kotlin/com/examplemod/commands/ExampleCommand.kt23
-rw-r--r--src/main/kotlin/com/examplemod/config/Config.kt52
-rw-r--r--src/main/kotlin/com/examplemod/config/PersistentData.kt35
-rw-r--r--src/main/resources/mcmod.info18
-rw-r--r--src/main/resources/mixins.examplemod.json9
7 files changed, 214 insertions, 0 deletions
diff --git a/src/main/java/com/examplemod/mixin/MixinGuiMainMenu.java b/src/main/java/com/examplemod/mixin/MixinGuiMainMenu.java
new file mode 100644
index 0000000..79c5db6
--- /dev/null
+++ b/src/main/java/com/examplemod/mixin/MixinGuiMainMenu.java
@@ -0,0 +1,16 @@
+package com.examplemod.mixin;
+
+import net.minecraft.client.gui.GuiMainMenu;
+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.callback.CallbackInfo;
+
+@Mixin(GuiMainMenu.class)
+public class MixinGuiMainMenu {
+
+ @Inject(method = "initGui", at = @At("HEAD"))
+ public void onInitGui(CallbackInfo ci) {
+ System.out.println("Hello from Main Menu!");
+ }
+}
diff --git a/src/main/kotlin/com/examplemod/ExampleMod.kt b/src/main/kotlin/com/examplemod/ExampleMod.kt
new file mode 100644
index 0000000..50434a1
--- /dev/null
+++ b/src/main/kotlin/com/examplemod/ExampleMod.kt
@@ -0,0 +1,61 @@
+import com.examplemod.commands.ExampleCommand
+import com.examplemod.config.Config
+import com.examplemod.config.PersistentData
+import net.minecraft.client.Minecraft
+import net.minecraft.client.gui.GuiScreen
+import net.minecraftforge.client.ClientCommandHandler
+import net.minecraftforge.common.MinecraftForge
+import net.minecraftforge.fml.common.Mod
+import net.minecraftforge.fml.common.ModMetadata
+import net.minecraftforge.fml.common.event.FMLInitializationEvent
+import net.minecraftforge.fml.common.event.FMLPreInitializationEvent
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import net.minecraftforge.fml.common.gameevent.TickEvent
+import java.io.File
+
+@Mod(
+ modid = "examplemod",
+ name = "ExampleMod",
+ version = "1.0",
+ useMetadata = true,
+ clientSideOnly = true
+)
+class ExampleMod {
+
+ @Mod.EventHandler
+ fun preInit(event: FMLPreInitializationEvent) {
+ metadata = event.modMetadata
+ val directory = File(event.modConfigurationDirectory, event.modMetadata.modId)
+ directory.mkdirs()
+ configDirectory = directory
+ persistentData = PersistentData.load()
+ config = Config
+ }
+
+ @Mod.EventHandler
+ fun onInit(event: FMLInitializationEvent) {
+ ClientCommandHandler.instance.registerCommand(ExampleCommand())
+
+ listOf(
+ this
+ ).forEach(MinecraftForge.EVENT_BUS::register)
+ }
+
+ @SubscribeEvent
+ fun onTick(event: TickEvent.ClientTickEvent) {
+ if (event.phase != TickEvent.Phase.START || currentGui == null) return
+ mc.displayGuiScreen(currentGui)
+ currentGui = null
+ }
+
+ companion object {
+ val mc: Minecraft = Minecraft.getMinecraft()
+ var currentGui: GuiScreen? = null
+
+ lateinit var configDirectory: File
+ lateinit var config: Config
+ lateinit var persistentData: PersistentData
+
+ lateinit var metadata: ModMetadata
+ }
+} \ No newline at end of file
diff --git a/src/main/kotlin/com/examplemod/commands/ExampleCommand.kt b/src/main/kotlin/com/examplemod/commands/ExampleCommand.kt
new file mode 100644
index 0000000..12538ca
--- /dev/null
+++ b/src/main/kotlin/com/examplemod/commands/ExampleCommand.kt
@@ -0,0 +1,23 @@
+package com.examplemod.commands
+
+import ExampleMod
+import com.examplemod.config.Config
+import net.minecraft.command.CommandBase
+import net.minecraft.command.ICommandSender
+import net.minecraft.util.ChatComponentText
+import net.minecraft.util.IChatComponent
+
+class ExampleCommand : CommandBase() {
+ override fun getCommandName() = "examplemod"
+
+ override fun getCommandAliases() = listOf("example")
+
+ override fun getCommandUsage(sender: ICommandSender?) = "/$commandName"
+
+ override fun getRequiredPermissionLevel() = 0
+
+ override fun processCommand(sender: ICommandSender?, args: Array<out String>?) {
+ sender?.addChatMessage(ChatComponentText("Example command run!"))
+ ExampleMod.currentGui = Config.gui()
+ }
+} \ No newline at end of file
diff --git a/src/main/kotlin/com/examplemod/config/Config.kt b/src/main/kotlin/com/examplemod/config/Config.kt
new file mode 100644
index 0000000..3008de3
--- /dev/null
+++ b/src/main/kotlin/com/examplemod/config/Config.kt
@@ -0,0 +1,52 @@
+package com.examplemod.config
+
+import gg.essential.vigilance.Vigilant
+import java.awt.Color
+import java.io.File
+
+
+object Config : Vigilant(
+ File(ExampleMod.configDirectory, "config.toml"),
+ ExampleMod.metadata.name
+) {
+ var demoSwitch = false
+ var demoSelector = 0
+ var demoColor : Color = Color.WHITE
+ var demoText = ""
+
+ init {
+ category("One category") {
+ switch(
+ ::demoSwitch,
+ name = "Switch",
+ description = "This is a switch"
+ )
+
+ subcategory("An additional category") {
+ selector(
+ ::demoSelector,
+ name = "Selector",
+ description = "This is a selector",
+ options = listOf("Option 1", "Option 2", "Option 3")
+ )
+ color(
+ ::demoColor,
+ name = "Color",
+ description = "This sets a color"
+ )
+ }
+ }
+
+ category("Another category") {
+ text(
+ ::demoText,
+ name = "Text",
+ description = "This is text",
+ placeholder = "This is some placeholder text."
+ )
+
+ }
+ }
+
+
+} \ No newline at end of file
diff --git a/src/main/kotlin/com/examplemod/config/PersistentData.kt b/src/main/kotlin/com/examplemod/config/PersistentData.kt
new file mode 100644
index 0000000..58e0ac0
--- /dev/null
+++ b/src/main/kotlin/com/examplemod/config/PersistentData.kt
@@ -0,0 +1,35 @@
+package com.examplemod.config
+
+import kotlinx.serialization.Serializable
+import kotlinx.serialization.Transient
+import kotlinx.serialization.json.Json
+import java.io.File
+import kotlinx.serialization.encodeToString
+import kotlinx.serialization.decodeFromString
+
+@Serializable
+data class PersistentData(
+ var exampleData: Map<String, String> = mapOf("key1" to "entry1"),
+ var moreExampleData: Int = 5
+) {
+
+ fun save() {
+ configFile.writeText(Json.encodeToString(this))
+ }
+
+ companion object {
+ private val configFile: File = File(ExampleMod.configDirectory,"data.json")
+
+ fun load(): PersistentData {
+ val data = if (!configFile.exists()) {
+ configFile.createNewFile()
+ PersistentData()
+ } else configFile.runCatching {
+ Json.decodeFromString<PersistentData>(this.readText())
+ }.getOrNull() ?: PersistentData()
+ return data.apply {
+ this.save()
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info
new file mode 100644
index 0000000..7393d36
--- /dev/null
+++ b/src/main/resources/mcmod.info
@@ -0,0 +1,18 @@
+[
+ {
+ "modid": "${modid}",
+ "name": "${modname}",
+ "description": "A template for Forge 1.8.9 client-side mods using Kotlin and Essential.",
+ "version": "${version}",
+ "mcversion": "${mcversion}",
+ "url": "",
+ "updateUrl": "",
+ "authorList": [
+ "appable"
+ ],
+ "credits": "",
+ "logoFile": "",
+ "screenshots": [],
+ "dependencies": []
+ }
+]
diff --git a/src/main/resources/mixins.examplemod.json b/src/main/resources/mixins.examplemod.json
new file mode 100644
index 0000000..1d28cda
--- /dev/null
+++ b/src/main/resources/mixins.examplemod.json
@@ -0,0 +1,9 @@
+{
+ "package": "com.examplemod.mixin",
+ "refmap": "mixins.examplemod.refmap.json",
+ "minVersion": "0.7",
+ "compatibilityLevel": "JAVA_8",
+ "client": [
+ "MixinGuiMainMenu"
+ ]
+}