Skip to content

Commit

Permalink
feat: updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelHillcox committed Dec 17, 2023
1 parent 642a85c commit 91c5a3d
Show file tree
Hide file tree
Showing 16 changed files with 274 additions and 38 deletions.
Binary file added .github/assets/config_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 9 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Changelog
Merge pull request #34
Updated some lang keys.
## 4.0.3

### Added

- KubeJS integration back in with custom events

### Changed

- Improved the readme a bunch!
169 changes: 169 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
# Simple Discord Rich Presence (SDRP)

[![](https://cf.way2muchnoise.eu/short_334853.svg)](https://www.curseforge.com/minecraft/mc-mods/simple-discord-rich-presence)
[![](https://cf.way2muchnoise.eu/versions/334853.svg)](https://www.curseforge.com/minecraft/mc-mods/simple-discord-rich-presence)


<p>
<a href="https://maven.nanite.dev/#/releases/com/sunekaer/mods"><img src="https://cdn.nanite.dev/data/assets/available-on-nanite.png" height="70" /></a>
<a href="https://www.curseforge.com/minecraft/mc-mods/architectury-api"><img src="https://cdn.nanite.dev/data/assets/requires-arch.png" height="70" /></a>
<a href="https://fabricmc.net/"><img src="https://cdn.nanite.dev/data/assets/supports-fabric.png" height="70" /></a>
<a href="https://files.minecraftforge.net/net/minecraftforge/forge/"><img src="https://cdn.nanite.dev/data/assets/supports-forge.png" height="70" /></a>
</p>

## What is SDRP?

SDRP is a simple Discord Rich Presence client for Minecraft that allows you to display your current Minecraft status on Discord.

## How do I use SDRP?

- Simply download the mod from CurseForge and put it in your mods folder. This is a client-side only mod so you don't need to install it on your server.
- You will then need to create an application on Discord. You can do this by going to the [Discord Developer Portal](https://discord.com/developers/applications) and clicking "New Application". Give it a name and click "Create".
- Attach an image to your app on the `General Information` tab. This will be the image that is displayed on Discord when the status is not playing Minecraft.
- Go to the `Rich Presence` tab and add a new image. This will be the image that is displayed on Discord when the status is playing Minecraft.
- Once you have made your application, you will need to attach images with the correct names for the mod to work.
- We've attached example images in the [`images`](./Images) folder. These have the correct names for the mod to work out of the box.
- A correct configuration will look like this:
![Correct Configuration](./.github/assets/config_example.png)
- If you want to setup your own images, you can follow the next section.

### Caveats

We always will attempt to use an image called `loading` and an image called `menu` for when the game is loading or is on the main menu respectively. If you do not have these images, the mod will simply fail to display an image for these states.

- `menu` When the main menu is showing
- `loading` When the game is loading


## Using custom images

If you are not using the KubeJS integration then you will need to follow the our convention for naming images and language keys. The convention is as follows:

- Name: `sdrp.[DIMENSION_NAME]` (Language key)
- Image Key: `sdrp.[DIMENSION_NAME].in`
- Image Name: `[DIMESNION_NAME]`

So for this to work, you'd need to have an image added to your Discord apps rich presents settings under the name of the dimension you want to support.

If I wanted to support the end and the overworld for example. Their names are as follows `minecraft:overworld`, `minecraft:the_end`. We ignore the `minecraft:` part and name the images `the_end` and `overworld`. We then add a language key to the language Json for both the `Image Key` and `Name`:

```json
{
"sdrp.overworld": "Overworld",
"sdrp.overworld.in": "In the Overworld"
}
```

## What we support out of the box

### Dimensions

We omit the `modid` from the dimension name and use the `name` instead. So `minecraft:overworld` becomes `overworld`.

- `overworld`
- `the_nether`
- `the_end`
- `compact_world`
- `dungeon`
- `spatial_storage`
- `otherside`
- `paradise_lost`
- `mining`

*Not all of these dimensions have example images with-in the images folder*

### Languages

```json
{
"sdrp.logo": "Pack Logo",
"sdrp.mainmenu": "Main Menu",
"sdrp.overworld.in": "In Overworld",
"sdrp.overworld": "Overworld",
"sdrp.the_nether.in": "In Nether",
"sdrp.the_nether": "Nether",
"sdrp.the_end.in": "In The End",
"sdrp.the_end": "The End",
"sdrp.compact_world.in": "In Compact World",
"sdrp.compact_world": "Compact World",
"sdrp.dungeon.in": "In Dungeon World",
"sdrp.dungeon": "Dungeon World",
"sdrp.spatial_storage.in": "In Spatial Storage",
"sdrp.spatial_storage": "Spatial Storage",
"sdrp.otherside.in": "In Otherside",
"sdrp.otherside": "Otherside",
"sdrp.paradise_lost.in": "In Paradise Lost",
"sdrp.paradise_lost": "Paradise Lost",
"sdrp.mining": "Mining Dimension",
"sdrp.mining.in": "In Mining dimension"
}
```
## Config

```json5
{
"clientId": 1000000000, // Your Discord application ID
"enabled": true, // Whether or not the mod is enabled
"screenEvent": false, // Disables the `menu` and `loading` images
"clientJoinEvent": false, // Disables the level join events which will prevent the mod from showing the level you are in
"logState": false, // Enables developer logging of the state json being sent to Discord
}
```

## KubeJS Integration

> **Note!**
>
> KubeJS Support is only support in 3.0.0+ for `1.19.2` and `4.0.3+` for `1.20.1+`
>
> Only `KubeJS 6+` is supported!
Via KubeJS we expose the following methods:

- `SDRP.setState( String message, String imageName, String imageKey )`
- `message`: message to show under the packname aka "In Overworld" or "In Nether", can be passed a string with the text to show or a lang key.
- `imageName`: the text to show when hovering over the small image aka "Overworld" or "Nether", can be passed a string with the text to show or a lang key.
- `imageKey` : the name Rich Present Art Asset to show, like loading, overworld, menu and so on.

- `SDRP.getCurrentState()`
- Gets the current state the client is set to.

### 3.0.6+ and 4.0.3+

In 3.0.6+ and 4.0.3+ we expose a couple of new events to help with some KubeJS weirdness as well as the above methods.

`kubejs/startup_script/sdrp.js`

```js
sdrp.dimension_change((event) => {
const dimPath = event.level.dimension().location().getPath();
event.updateSDRPState(`sdrp.${dimPath}.in`, `sdrp.${dimPath}`, "dimPath");
});
```

*File path for illustration purposes only, you can put this file anywhere in the `kubejs` folder.*

The `event` object has the following properties:

- `dimensionType`: The dimension the player is in
- `player`: The player object
- `level`: The level object

#### Without our events

Example of how to change the state when a player joins a world.

`kubejs/startup_script/sdrp.js`

```js
// KubeJS 6+
// This might be the wrong event class for 1.20+, I didn't check
ForgeEvents.onEvent('net.minecraftforge.event.entity.EntityJoinWorldEvent', event => {
if (event.getEntity().type === "entity.minecraft.player") {
if (event.getWorld().isClientSide()) {
const dimPath = event.getWorld().dimension().location().getPath();
SDRP.setState(`sdrp.${dimPath}.in`, `sdrp.${dimPath}`, "dimPath");
}
}
})
```
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id "architectury-plugin" version "3.4-SNAPSHOT"
id "dev.architectury.loom" version "1.2-SNAPSHOT" apply false
id "me.modmuss50.mod-publish-plugin" version "0.3.0"
id "dev.architectury.loom" version "1.4-SNAPSHOT" apply false
id "me.modmuss50.mod-publish-plugin" version "0.4.5"
}

architectury {
Expand Down Expand Up @@ -141,4 +141,4 @@ publishMods {
}
}
}
}
}
4 changes: 2 additions & 2 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ dependencies {

modApi "dev.architectury:architectury:${rootProject.architectury_version}"

// modImplementation "dev.latvian.mods:kubejs-fabric:${rootProject.kubejs_version}"
// modImplementation "dev.latvian.mods:rhino-fabric:${rootProject.rhino_version}"
modImplementation "dev.latvian.mods:kubejs:${rootProject.kubejs_version}"
modImplementation "dev.latvian.mods:rhino:${rootProject.rhino_version}"
}

def ENV = System.getenv()
Expand Down
5 changes: 5 additions & 0 deletions common/src/main/java/com/sunekaer/sdrp/SDRP.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.sunekaer.sdrp.discord.RPClient;
import com.sunekaer.sdrp.discord.State;
//import com.sunekaer.sdrp.integration.kubejs.SDRPKubeJSIntegration;
import com.sunekaer.sdrp.integration.kubejs.SDRPKubeJSIntegration;
import dev.architectury.event.EventResult;
import dev.architectury.event.events.client.ClientGuiEvent;
import dev.architectury.event.events.client.ClientLifecycleEvent;
Expand Down Expand Up @@ -44,6 +45,10 @@ public static void init() {

EntityEvent.ADD.register(SDRP::clientJoinEvent);
ClientGuiEvent.INIT_POST.register(SDRP::screenEvent);

if (Platform.isModLoaded("kubejs")) {
SDRPKubeJSIntegration.setup();
}
}

/**
Expand Down
3 changes: 3 additions & 0 deletions common/src/main/java/com/sunekaer/sdrp/config/SDRPConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public class SDRPConfig implements ConfigData {
@Comment("If set to false, it disables the build in clientJoinEvent, which is used to tell when the player is join a world and changing Dimension.")
public boolean clientJoinEvent = true;

@Comment("When enabled, the mod will log the current state being sent to Discord")
public boolean logState = false;

@Override
public void validatePostLoad() {
var oldConfig = SDRPCrossPlatform.getConfigDirectory().resolve("sdrp.json");
Expand Down
3 changes: 3 additions & 0 deletions common/src/main/java/com/sunekaer/sdrp/discord/RPClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ private void processStateQueue() {
}

this.client.sendRichPresence(state);
if (SDRP.config.logState) {
LOGGER.info("Sent state to discord: {}", state.toJson().toString());
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,62 @@
//package com.sunekaer.sdrp.integration.kubejs;
//
//
//import dev.latvian.mods.kubejs.KubeJSPlugin;
//import dev.latvian.mods.kubejs.script.BindingsEvent;
//
//public class SDRPKubeJSIntegration extends KubeJSPlugin {
// @Override
// public void registerBindings(BindingsEvent event) {
// event.add("SDRP", SDRPKubeJSWrapper.class);
// }
//}
package com.sunekaer.sdrp.integration.kubejs;


import dev.architectury.event.EventResult;
import dev.architectury.event.events.common.EntityEvent;
import dev.latvian.mods.kubejs.KubeJSPlugin;
import dev.latvian.mods.kubejs.event.EventGroup;
import dev.latvian.mods.kubejs.event.EventHandler;
import dev.latvian.mods.kubejs.event.EventJS;
import dev.latvian.mods.kubejs.script.BindingsEvent;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.dimension.DimensionType;

public class SDRPKubeJSIntegration extends KubeJSPlugin {
static EventGroup GROUP = EventGroup.of("sdrp");
static EventHandler DIMENSION_CHANGE = GROUP.client("dimension_change", () -> ClientDimensionChangeEvent.class);

public static void setup() {
EntityEvent.ADD.register(SDRPKubeJSIntegration::clientJoinEvent);
}

@Override
public void registerBindings(BindingsEvent event) {
event.add("SDRP", SDRPKubeJSWrapper.class);
}

@Override
public void registerEvents() {
GROUP.register();
}

private static EventResult clientJoinEvent(Entity entity, Level level) {
if (!(entity instanceof Player player)) {
return EventResult.pass();
}

if (!level.isClientSide) {
return EventResult.pass();
}

DIMENSION_CHANGE.post(new ClientDimensionChangeEvent(level.dimensionType(), player, level));
return EventResult.pass();
}

public static class ClientDimensionChangeEvent extends EventJS {
public DimensionType dimensionType;
public Player player;
public Level level;

public ClientDimensionChangeEvent(DimensionType dimensionType, Player player, Level level) {
this.dimensionType = dimensionType;
this.player = player;
this.level = level;
}

public void updateSDRPState(String message, String imageName, String imageKey) {
SDRPKubeJSWrapper.setState(message, imageName, imageKey);
}
}
}
1 change: 1 addition & 0 deletions common/src/main/resources/sdrp-common.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"required": true,
"package": "com.sunekaer.sdrp.mixin",
"compatibilityLevel": "JAVA_17",
"minVersion": "0.8",
"client": [
],
"mixins": [
Expand Down
6 changes: 3 additions & 3 deletions fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ dependencies {
common(project(path: ":common", configuration: "namedElements")) { transitive false }
shadowCommon(project(path: ":common", configuration: "transformProductionFabric")) { transitive false }

// modImplementation "dev.latvian.mods:kubejs-fabric:${rootProject.kubejs_version}"
// modImplementation "dev.latvian.mods:rhino-fabric:${rootProject.rhino_version}"
modImplementation "dev.latvian.mods:kubejs-fabric:${rootProject.kubejs_version}"
modImplementation "dev.latvian.mods:rhino-fabric:${rootProject.rhino_version}"
}

processResources {
Expand Down Expand Up @@ -108,4 +108,4 @@ publishing {
}
}
}
}
}
4 changes: 2 additions & 2 deletions fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
],
"depends": {
"fabric": "*",
"minecraft": ">=1.19.3",
"architectury": ">=7.0.65",
"minecraft": ">=1.20.1",
"architectury": ">=9.0.8",
"cloth-config": ">=9.0.94"
}
}
7 changes: 3 additions & 4 deletions forge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ dependencies {
implementation 'com.github.jagrosh:DiscordIPC:a8d6631cc9'
forgeRuntimeLibrary 'com.github.jagrosh:DiscordIPC:a8d6631cc9'


include(implementation 'com.github.jagrosh:DiscordIPC:a8d6631cc9')
include(implementation "com.kohlschutter.junixsocket:junixsocket-common:2.6.2")
include(implementation "com.kohlschutter.junixsocket:junixsocket-native-common:2.6.2")
Expand All @@ -44,8 +43,8 @@ dependencies {
common(project(path: ":common", configuration: "namedElements")) { transitive false }
shadowCommon(project(path: ":common", configuration: "transformProductionForge")) { transitive = false }

// modImplementation "dev.latvian.mods:kubejs-forge:${rootProject.kubejs_version}"
// modImplementation "dev.latvian.mods:rhino-forge:${rootProject.rhino_version}"
modImplementation "dev.latvian.mods:kubejs-forge:${rootProject.kubejs_version}"
modImplementation "dev.latvian.mods:rhino-forge:${rootProject.rhino_version}"
}

processResources {
Expand Down Expand Up @@ -108,4 +107,4 @@ publishing {
}
}
}
}
}
Loading

0 comments on commit 91c5a3d

Please sign in to comment.