Skip to content

Commit

Permalink
shadowing discord4j in both loaders, reimpl of all events
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyagara committed Sep 26, 2024
1 parent a508eeb commit eaf0f10
Show file tree
Hide file tree
Showing 14 changed files with 92 additions and 129 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ jobs:
- name: Build
run: ./gradlew build

- run: rm ./build/libs/cooptweaks-*-all.jar

- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: Artifacts
path: build/libs/
path: build/
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ goal with this is to add on the coop experience I really enjoyed from Cooperativ

## TODO

- Build system needs some work, merging jars is really slow, shadowing is probably not done right.
- Add Discord commands to retrieve general information about the server, TPS, uptime, etc.
- Maybe move dimension logic to a separate class, maybe in the Discord package.
- Utils class might need to become a package as more features are added.

## Configuration
Expand Down
39 changes: 22 additions & 17 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id 'dev.architectury.loom' version '1.7-SNAPSHOT' apply false
id 'architectury-plugin' version '3.4-SNAPSHOT'
id 'com.gradleup.shadow' version '8.3.2' apply false
id "dev.architectury.loom" version "1.7-SNAPSHOT" apply false
id "architectury-plugin" version "3.4-SNAPSHOT"
id "com.gradleup.shadow" version "8.3.2" apply false

id "io.github.pacifistmc.forgix" version "1.2.9"
}
Expand All @@ -11,32 +11,34 @@ architectury {
}

allprojects {
group = rootProject.maven_group
version = rootProject.mod_version
group = project.maven_group
version = project.mod_version
}

forgix {
group = rootProject.maven_group
mergedJarName = "cooptweaks-${rootProject.mod_version}-fabric-neoforge.jar"
group = project.maven_group
mergedJarName = "cooptweaks-${project.mod_version}-fabric-neoforge.jar"
outputDir = "build"

if (findProject(":neoforge"))
if (findProject(":neoforge")) {
neoforge {
jarLocation = "build/libs/cooptweaks-neoforge-${rootProject.mod_version}.jar"
jarLocation = "build/libs/cooptweaks-neoforge-${project.mod_version}.jar"
}
}

if (findProject(":fabric"))
if (findProject(":fabric")) {
fabric {
jarLocation = "build/libs/cooptweaks-fabric-${rootProject.mod_version}.jar"
jarLocation = "build/libs/cooptweaks-fabric-${project.mod_version}.jar"
}
}
}

subprojects {
apply plugin: 'dev.architectury.loom'
apply plugin: 'architectury-plugin'
apply plugin: "dev.architectury.loom"
apply plugin: "architectury-plugin"

base {
archivesName = "$rootProject.archives_name-$project.name"
archivesName = "$project.archives_name-$project.name"
}

repositories {
Expand All @@ -48,10 +50,10 @@ subprojects {
}

dependencies {
minecraft "net.minecraft:minecraft:$rootProject.minecraft_version"
minecraft "net.minecraft:minecraft:$project.minecraft_version"
mappings loom.layered {
it.mappings("net.fabricmc:yarn:$rootProject.yarn_mappings:v2")
it.mappings("dev.architectury:yarn-mappings-patch-neoforge:$rootProject.yarn_mappings_patch_neoforge_version")
it.mappings("net.fabricmc:yarn:$project.yarn_mappings:v2")
it.mappings("dev.architectury:yarn-mappings-patch-neoforge:$project.yarn_mappings_patch_neoforge_version")
}
}

Expand All @@ -65,4 +67,7 @@ subprojects {
tasks.withType(JavaCompile).configureEach {
it.options.release = 21
}

build.finalizedBy(mergeJars)
assemble.finalizedBy(mergeJars)
}
6 changes: 3 additions & 3 deletions common/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
architectury {
common rootProject.enabled_platforms.split(',')
common rootProject.enabled_platforms.split(",")
}

dependencies {
// We depend on Fabric Loader here to use the Fabric @Environment annotations,
// which get remapped to the correct annotations on each platform.
// Do NOT use other classes from Fabric Loader.
modImplementation "net.fabricmc:fabric-loader:$rootProject.fabric_loader_version"
modImplementation "net.fabricmc:fabric-loader:$project.fabric_loader_version"

// Architectury API. This is optional, and you can comment it out if you don't need it.
modImplementation "dev.architectury:architectury:$rootProject.architectury_api_version"
modImplementation "dev.architectury:architectury:$project.architectury_api_version"

implementation "com.discord4j:discord4j-core:${project.discord4j_version}"
}
31 changes: 13 additions & 18 deletions common/src/main/java/com/cooptweaks/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
import com.cooptweaks.advancements.Advancements;
import com.cooptweaks.discord.Discord;
import com.cooptweaks.events.GrantCriterionCallback;
import com.cooptweaks.events.PlayerDeathCallback;
import dev.architectury.event.EventResult;
import dev.architectury.event.events.common.*;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.BlockPos;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -25,7 +24,7 @@ public final class Main {
private static final ConcurrentHashMap<String, String> PLAYER_CURRENT_DIMENSION_ID = new ConcurrentHashMap<>();

public static void init() {
LifecycleEvent.SERVER_STARTING.register(server -> {
LifecycleEvent.SERVER_BEFORE_START.register(server -> {
DISCORD.Start(CONFIG.getDiscordConfig());
});

Expand All @@ -52,13 +51,6 @@ public static void init() {

PlayerEvent.PLAYER_QUIT.register(DISCORD::PlayerLeft);

/*PlayerEvent.PLAYER_RESPAWN.register((newPlayer, conqueredEnd, removalReason) -> {
String name = newPlayer.getName().getString();
String dimensionId = newPlayer.getWorld().getRegistryKey().getValue().toString();
updatePlayerCurrentDimension(name, dimensionId);
});*/

PlayerEvent.CHANGE_DIMENSION.register((player, oldWorld, newWorld) -> {
String name = player.getName().getString();
String dimensionId = newWorld.getValue().toString();
Expand All @@ -67,21 +59,24 @@ public static void init() {
DISCORD.PlayerChangedDimension(name, Utils.getPlayerDimension(name));
});

// Maybe use DECORATE event instead?
ChatEvent.RECEIVED.register((player, message) -> {
DISCORD.PlayerSentChatMessage(player, message);
return EventResult.pass();
});

EntityEvent.LIVING_DEATH.register((entity, source) -> {
if (entity.isPlayer()) {
String name = entity.getName().getString();
String dimensionId = entity.getWorld().getRegistryKey().getValue().toString();
EntityEvent.LIVING_DEATH.register((entity, source) -> {
if (entity.isPlayer()) {
String name = entity.getName().getString();
String dimensionId = entity.getWorld().getRegistryKey().getValue().toString();
BlockPos pos = entity.getBlockPos();

updatePlayerCurrentDimension(name, dimensionId);
}
updatePlayerCurrentDimension(name, dimensionId);
DISCORD.PlayerDied(name, pos, source.getDeathMessage(entity));
}

return EventResult.pass();
});
return EventResult.pass();
});

GrantCriterionCallback.EVENT.register(ADVANCEMENTS::OnCriterion);
CommandRegistrationEvent.EVENT.register(ADVANCEMENTS::RegisterCommands);
Expand Down
5 changes: 1 addition & 4 deletions common/src/main/java/com/cooptweaks/discord/Discord.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.GlobalPos;

import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
Expand Down Expand Up @@ -302,10 +301,8 @@ public void PlayerChangedDimension(String name, String dimension) {
SendEmbed(message, Color.BLACK);
}

public void PlayerDied(ServerPlayerEntity serverPlayerEntity, GlobalPos lastDeathPos, Text deathMessage) {
String name = serverPlayerEntity.getName().getString();
public void PlayerDied(String name, BlockPos pos, Text deathMessage) {
String dimension = Utils.getPlayerDimension(name);
BlockPos pos = lastDeathPos.pos();

String text = deathMessage.getString().replace(name, String.format("**%s**", name));

Expand Down

This file was deleted.

This file was deleted.

4 changes: 1 addition & 3 deletions common/src/main/resources/cooptweaks.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
"client": [
],
"mixins": [
"PlayerAdvancementTrackerMixin",
"PlayerEntityAccessor",
"ServerPlayerEntityMixin"
"PlayerAdvancementTrackerMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down
24 changes: 15 additions & 9 deletions fabric/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'com.gradleup.shadow'
id "com.gradleup.shadow"
}

architectury {
Expand All @@ -12,6 +12,7 @@ configurations {
canBeResolved = true
canBeConsumed = false
}

compileClasspath.extendsFrom common
runtimeClasspath.extendsFrom common
developmentFabric.extendsFrom common
Expand All @@ -25,29 +26,34 @@ configurations {
}

dependencies {
modImplementation "net.fabricmc:fabric-loader:$rootProject.fabric_loader_version"
modImplementation "net.fabricmc:fabric-loader:$project.fabric_loader_version"

// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:$rootProject.fabric_api_version"
modImplementation "net.fabricmc.fabric-api:fabric-api:$project.fabric_api_version"

// Architectury API. This is optional, and you can comment it out if you don't need it.
modImplementation "dev.architectury:architectury-fabric:$rootProject.architectury_api_version"
modImplementation "dev.architectury:architectury-fabric:$project.architectury_api_version"

common(project(path: ":common", configuration: "namedElements")) { transitive false }
shadowBundle project(path: ":common", configuration: "transformProductionFabric")

common(project(path: ':common', configuration: 'namedElements')) { transitive false }
shadowBundle project(path: ':common', configuration: 'transformProductionFabric')
shadowBundle implementation("com.discord4j:discord4j-core:${project.discord4j_version}")
}

processResources {
inputs.property 'version', project.version
inputs.property "version", project.version

filesMatching('fabric.mod.json') {
filesMatching("fabric.mod.json") {
expand version: project.version
}
}

shadowJar {
configurations = [project.configurations.shadowBundle]
archiveClassifier = 'dev-shadow'
archiveClassifier = "dev-shadow"
relocate 'io.netty', 'shadow.io.netty'
relocate 'org.checkerframework', 'shadow.org.checkerframework'
relocate 'com.google', 'shadow.com.google'
}

remapJar {
Expand Down
27 changes: 12 additions & 15 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,19 @@ org.gradle.jvmargs=-Xmx3G
org.gradle.parallel=true

# Mod properties
mod_version = 0.1.0
maven_group = com.cooptweaks
archives_name = cooptweaks
enabled_platforms = fabric,neoforge
mod_version=0.1.0
maven_group=com.cooptweaks
archives_name=cooptweaks
enabled_platforms=fabric,neoforge

# Minecraft properties
minecraft_version = 1.21.1
yarn_mappings = 1.21+build.3
minecraft_version=1.21.1
yarn_mappings=1.21+build.3
yarn_mappings_patch_neoforge_version=1.21+build.4

# Dependencies
discord4j_version = 3.2.6

architectury_api_version = 13.0.6

fabric_loader_version = 0.16.5
fabric_api_version = 0.105.0+1.21.1

neoforge_version = 21.1.61
yarn_mappings_patch_neoforge_version = 1.21+build.4
discord4j_version=3.2.6
architectury_api_version=13.0.6
fabric_loader_version=0.16.5
fabric_api_version=0.105.0+1.21.1
neoforge_version=21.1.61
Loading

0 comments on commit eaf0f10

Please sign in to comment.