MinnDevelopment / java-discord-rpc

Java bindings for https://github.com/discordapp/discord-rpc (using JNA)
Apache License 2.0
132 stars 38 forks source link

Imposible to use it in a minecraft mod #32

Closed tompointexe closed 5 years ago

tompointexe commented 5 years ago

Hi i'm trying to use your API to add discord RichPresence in my minecraft mod

When i put the code in my main class at the init process my package become incorect

here is my code

package fr.altisrp.mod;
// Error is HERE
import club.minnced.discord.rpc.*;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import fr.altisrp.mod.proxy.CommonProxy;

@Mod(modid = AltisRpMod.MODID, version = AltisRpMod.VERSION)
public class AltisRpMod
{
    public static final String MODID = "Altis_RP";
    public static final String VERSION = "0.0.1";

    @Instance("AltisRpMod")
    public static AltisRpMod instance;

    @SidedProxy(clientSide = "fr.altisrp.mod.proxy.ClientProxy", serverSide = "fr.altisrp.mod.proxy.CommonProxy")
    public static CommonProxy proxy;

    @EventHandler
    public void preinit(FMLPreInitializationEvent event)
    {

        // some example code
        System.out.println("Pré init Altis Rp Mod");

    }

    @EventHandler
    public void init(FMLInitializationEvent event)
    {

        DiscordRPC lib = DiscordRPC.INSTANCE;
        String applicationId = "";
        String steamId = "";
        DiscordEventHandlers handlers = new DiscordEventHandlers();
        handlers.ready = (user) -> System.out.println("Ready!");
        lib.Discord_Initialize(applicationId, handlers, true, steamId);
        DiscordRichPresence presence = new DiscordRichPresence();
        presence.startTimestamp = System.currentTimeMillis() / 1000; // epoch second
        presence.details = "Starting Game";
        lib.Discord_UpdatePresence(presence);
        // in a worker thread
        new Thread(() -> {
            while (!Thread.currentThread().isInterrupted()) {
                lib.Discord_RunCallbacks();
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException ignored) {}
            }
        }, "RPC-Callback-Handler").start();
        // some example code
        System.out.println("init Altis Rp Mod");
        proxy.registerRender();

    }

    @EventHandler
    public void postInit(FMLPostInitializationEvent event)
    {

        // some example code
        System.out.println("PostInit Altis Rp Mod");

    }
}

eclipse says to configure build path . i dont knew what to do Thanks for helping me

MinnDevelopment commented 5 years ago

In order to use this dependency you have to add it through either maven or gradle.

tompointexe commented 5 years ago

Oh yeah i forget that ...

tompointexe commented 5 years ago

Build Failed

`**** Powered By MCP:
http://modcoderpack.com/
Searge, ProfMobius, Fesh0r, R4wk, ZeuX, IngisKahn, bspkrs MCP Data version : unknown


:compileApiJava UP-TO-DATE :processApiResources UP-TO-DATE :apiClasses UP-TO-DATE :sourceMainJava :compileJava

FAILURE: Build failed with an exception.

BUILD FAILED

Total time: 7.71 secs`

MinnDevelopment commented 5 years ago

You are missing the jcenter repository

tompointexe commented 5 years ago
buildscript {
    repositories {
        mavenCentral()
        jcenter()
        maven {
            name = "forge"
            url = "http://files.minecraftforge.net/maven"
        }
        maven {
            name = "sonatype"
            url = "https://oss.sonatype.org/content/repositories/snapshots/"
        }

    }
    dependencies {
        classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-SNAPSHOT'

    }
}

apply plugin: 'forge'
apply plugin: "java"

sourceCompatibility = targetCompatibility = '1.8'
compileJava {
    sourceCompatibility = targetCompatibility = '1.8'
}

version = "0.0.3"
group= "fr.altisrp.mod" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "Altis-Mod"

minecraft {
    version = "1.7.10-10.13.4.1614-1.7.10"
    runDir = "eclipse"
}

dependencies {
    // you may put jars on which you depend on in ./libs
    // or you may define them like so..
    //compile "some.group:artifact:version:classifier"
    //compile "some.group:artifact:version"

    // real examples
    //compile 'com.mod-buildcraft:buildcraft:6.0.8:dev'  // adds buildcraft to the dev env
    //compile 'com.googlecode.efficient-java-matrix-library:ejml:0.24' // adds ejml to the dev env

    // for more info...
    // http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
    // http://www.gradle.org/docs/current/userguide/dependency_management.html
    compile 'club.minnced:java-discord-rpc:2.0.1'
}

processResources
{
    // this will ensure that this task is redone when the versions change.
    inputs.property "version", project.version
    inputs.property "mcversion", project.minecraft.version

    // replace stuff in mcmod.info, nothing else
    from(sourceSets.main.resources.srcDirs) {
        include 'mcmod.info'

        // replace version and mcversion
        expand 'version':project.version, 'mcversion':project.minecraft.version
    }

    // copy everything else, thats not the mcmod.info
    from(sourceSets.main.resources.srcDirs) {
        exclude 'mcmod.info'
    }
}

Here is my build.gradle

tompointexe commented 5 years ago

Without theres lines build passed