Skip to content

Commit

Permalink
Update Lambda API 3.1 -> 3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Ancient77 committed Aug 7, 2022
1 parent 3fa1935 commit 1757f63
Show file tree
Hide file tree
Showing 17 changed files with 85 additions and 361 deletions.
99 changes: 1 addition & 98 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,98 +1 @@
# Lambda Plugin Example

This project in an example to show how a proper plugin for [Lambda Client](https://github.com/lambda-client/lambda) is set up.
The advantage of plugins for a utility mod is that they allow the user to decide what features their personalized client will have. Plugins work in plug and play manner, and can be downloaded and activated inside the ingame menu without reloading the client as long as no mixins are used for the plugin.
If you are scared about the Kotlin in this project be aware that Kotlin is a wrapper language for Java. That means that plugins can also be natively written in Java.

## Setup

To achieve coding building and publishing your own plugin most of the following steps are required.

### Fork
This is a template repository and can be used as a base to create a custom plugin. Press the `Use as template` button on GitHub to automatically create a linked fork to this repository.

### Clone Repository

Clone the repository to your local machine. Use the link of either your fork or the main repository.
```
git clone https://github.com/lambda-client/ExamplePlugin
```

### Setup IDE

In this guide we will use [IntelliJ IDEA](https://www.jetbrains.com/idea/) as IDE.
1. Open the project from `File > Open...`
2. Let the IDE collect dependencies and index the code.
3. Goto `File > Project Structure... > SDKs` and make sure an SDK for Java 8 is installed and selected, if not download
it [here](https://adoptopenjdk.net/index.html?variant=openjdk8&jvmVariant=hotspot).
4. Run the `genIntellijRuns` Gradle task, or run `./gradlew genIntellijRuns`.
5. Open with `STRG+left_click` on `PluginModule` in `ExampleModule` to open the decompiled lambda dependency. To see the original source code go in the top right corner you can add `Sources...` and select the `lambda-*-api-source.jar`.

### Configure Gradle

Test if the environment is set up correctly by building the plugin jar using the Gradle tab on the right side of the IDE.
1. Go to `ExamplePlugin > Tasks > build > jar` in the Gradle tab and run the script
2. IntelliJ will create a new directory called `build`. The final built jar will be in `build/libs`

### Config

Configure the metadata of your plugin in `plugin_info.json`.
The flag `main_class` must contain the target main class `Plugin` in this case it is `PluginExample.kt`

### Plugin

The plugin main class will act as a register for the functions a plugin can provide.
For example when a new module class is created you have to add this to the `onLoad()` function of the plugin class.
```
modules.add(ExampleModule)
```
Every service is required to be added to the main class in order to index the contents.

### PluginModule

A module represents a utility module inside the game.
The `PluginModule` class acts as a wrapper for `Module` class. For many examples on how a module can work check out the [native modules](https://github.com/lambda-client/lambda/tree/master/src/main/kotlin/com/lambda/client/module/modules) of lambda, or the given example in this project.
The difference from the native `Module` class is that each component of a plugin requires a reference to the main `Plugin` class.
```
pluginMain = ExamplePlugin
```
Every PluginModule class will need to be registered to the main plugin class

### ClientCommand

Plugins use the same class as the native client for registering commands. Feel free to check out the [commands of Lambda Client](https://github.com/lambda-client/lambda/tree/master/src/main/kotlin/com/lambda/client/command/commands) as a reference.

### PluginLabelHud

A LabelHud is used to display information in the player GUI.
The `PluginLabelHud` class acts as a wrapper for `LabelHud` class. For many examples on how a hud can work check out the [native hud elements](https://github.com/lambda-client/lambda/tree/master/src/main/kotlin/com/lambda/client/gui/hudgui/elements) of lambda, or the given example in this project.
The difference to the native `LabelHud` class is that a referral to the main plugin class is given in the object data.
```
pluginMain = ExamplePlugin
```
Every `PluginLabelHud` class will need to be registered to the main `Plugin` class.

### Background Jobs

If coroutines are needed background jobs can be registered using
```
bgJobs.add(BackgroundJob)
```

### Mixins

To use mixins, you have to:
1. Register the files in the `plugin_info.json` in the `mixins` list.
2. Add the `refmap` path from `mixins.ExamplePlugin.json` to the `build.gradle` source sets.

### Build

1. Go to `ExamplePlugin > Tasks > build > jar` in the Gradle tab and run the script
2. IntelliJ will create a new directory called `build` the final built jar will be in `build/libs`
3. Put the `ExamplePlugin-1.0.jar` into your `./minecraft/lambda/plugins` folder and run the game.

### Publish

Publish your repository in Discord, and we may fork you, or transfer your repository to official
plugin [organization of Lambda](https://github.com/lambda-plugins/). After review, your plugin may get added to the native
marketplace.
This is just a small Lambda plugin to calculate the disk size of your generated chunks on a server.
36 changes: 25 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ group project.modGroup

buildscript {
repositories {
maven { url = 'https://files.minecraftforge.net/maven' }
maven { url = 'https://repo.spongepowered.org/repository/maven-public/' }
maven { url = 'https://maven.minecraftforge.net/' }
maven { url = 'https://repo.spongepowered.org/maven/' }
}

dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:5.+'
classpath 'org.spongepowered:mixingradle:0.7-SNAPSHOT'
classpath 'net.minecraftforge.gradle:ForgeGradle:4.+'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
classpath 'com.github.jengelman.gradle.plugins:shadow:6.1.0'
}
}

apply plugin: 'idea'
apply plugin: 'kotlin'
apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'org.spongepowered.mixin'
apply plugin: 'com.github.johnrengelman.shadow'

compileJava {
sourceCompatibility = targetCompatibility = '1.8'
Expand Down Expand Up @@ -125,11 +125,6 @@ dependencies {
// jarLibs 'com.lambda:example:1.0.0'
}

mixin {
defaultObfuscationEnv 'searge'
add sourceSets.main, 'mixins.ExamplePlugin.refmap.json'
}

processResources {
exclude '**/rawimagefiles'

Expand All @@ -144,4 +139,23 @@ test {
useJUnitPlatform()
}

jar.finalizedBy('reobfJar')
jar.finalizedBy('reobfJar')

shadowJar {
archiveClassifier.set('')
configurations = []
relocate 'kotlin', 'com.lambda.shadow.kotlin'
relocate 'kotlinx', 'com.lambda.shadow.kotlinx'
finalizedBy 'reobfShadowJar'
}

reobf {
shadowJar {}
jar {
enabled = false
}
}

artifacts {
shadowJar
}
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ forgeVersion=14.23.5.2860
mappingsChannel=stable
mappingsVersion=39-1.12

kotlinVersion=1.7.0
kotlinxCoroutinesVersion=1.6.2
kotlinVersion=1.7.10
kotlinxCoroutinesVersion=1.6.4
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Binary file modified lib/lambda-3.2-api-source.jar
Binary file not shown.
Binary file modified lib/lambda-3.2-api.jar
Binary file not shown.
15 changes: 0 additions & 15 deletions src/main/java/com/lambda/mixins/MixinMinecraft.java

This file was deleted.

37 changes: 37 additions & 0 deletions src/main/kotlin/com/lambda/Command.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.lambda

import com.lambda.client.command.ClientCommand
import com.lambda.client.util.FolderUtils
import com.lambda.client.util.text.MessageSendHelper
import java.io.BufferedReader
import java.io.File
import java.io.FileReader
import java.nio.file.Files
import kotlin.math.roundToInt

object Command : ClientCommand(
name = "size",
description = "Calculate the disk size of the chunks you generated."
) {
init {
execute("") {
try {
val folderName = mc.currentServerData?.serverName + "-" + mc.currentServerData?.serverIP
val rV = File(File(FolderUtils.newChunksFolder), "$folderName/logs").toPath()
var lines = 0
Files.walk(rV).forEach { item ->
if(item.toString().endsWith(".csv")){
val file = File(rV.toString() + "/" + item.fileName.toString())
val reader = BufferedReader(FileReader(file))
while (reader.readLine() != null) lines++
reader.close()
}
}
MessageSendHelper.sendRawChatMessage("YOU HAVE LOADED $lines CHUNKS OF SIZE ${(lines * 0.00584).roundToInt() } MB")
}catch (e: Exception){
MessageSendHelper.sendRawChatMessage("ERROR: $e")
}

}
}
}
26 changes: 0 additions & 26 deletions src/main/kotlin/com/lambda/ExamplePlugin.kt

This file was deleted.

13 changes: 13 additions & 0 deletions src/main/kotlin/com/lambda/Plugin.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.lambda

import com.lambda.client.plugin.api.Plugin


internal object Plugin : Plugin() {

override fun onLoad() {
commands.add(Command)
}


}
34 changes: 0 additions & 34 deletions src/main/kotlin/com/lambda/commands/ExampleCommand.kt

This file was deleted.

20 changes: 0 additions & 20 deletions src/main/kotlin/com/lambda/huds/ExampleLabelHud.kt

This file was deleted.

15 changes: 0 additions & 15 deletions src/main/kotlin/com/lambda/managers/ExampleManager.kt

This file was deleted.

Loading

0 comments on commit 1757f63

Please sign in to comment.