Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 74 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,80 @@
# Forge Mod API

This repository contains the implementation of the Hypixel Mod API for the Froge Mod Loader in 1.8.9 for end-users. If you are a developer, and are looking to utilise the API you should look at the core [Hypixel Mod API](https://github.com/HypixelDev/ModAPI) repository.
This repository contains the implementation of the Hypixel Mod API for the Forge Mod Loader in 1.8.9 for end-users. If you are a developer, and are looking to utilise the API you should look at the core [Hypixel Mod API](https://github.com/HypixelDev/ModAPI) repository.

## Usage

Add the HyPixel Maven repository to your build:

```kotlin
repositories {
maven("https://repo.hypixel.net/repository/Hypixel/")
}
```

Then depend on the Forge Mod API. This will automatically pull in dependencies too.

```kotlin
val version = "1.0.0.2"
dependencies {
modImplementation("net.hypixel:mod-api-forge:$version")
// If you use ForgeGradle 2 you might need to use fg.deobf or deobfCompile instead. Consult your MDK for tips on how
// to depend on an obfuscated dependency
}
```

From here on out you can use the [HyPixel Mod API](https://github.com/HypixelDev/ModAPI#example-usage) directly.

### Bundling the HyPixel Mod API

When using the HyPixel Mod API you need to instruct your users to
[download](https://modrinth.com/mod/hypixel-mod-api/versions?l=forge) the mod api and put it in their mods folders.

Alternatively you can bundle a loading tweaker instead. This involves a bit more setup, but will result in your mod
containing a copy of the mod api and at runtime selecting the newest available version of the mod api.

First you need to have a shadow plugin in your gradle setup. Note that normal `fileTree` based JAR copying does not
work, since we will need to relocate some files. Instead, use the [shadow plugin](https://github.com/johnrengelman/shadow)
or make use of a [template](https://github.com/nea89o/Forge1.8.9Template) with the plugin already set up.

Once you have your shadow plugin set up you will need to include a new dependency:
```kotlin
dependencies {
modImplementation("net.hypixel:mod-api-forge:$version") // You should already have this dependency from earlier
shadowImpl("net.hypixel:mod-api-forge-tweaker:$version") // You need to add this dependency
}
```

Make sure to relocate the `net.hypixel.modapi.tweaker` package to a unique location such as `my.modid.modapitweaker`.

Finally, add a manifest entry to your JAR pointing the `TweakClass` to `my.modid.modapitweaker.HypixelModAPITweaker`
(or otherwise load the tweaker using delegation).

```kotlin
tasks.shadowJar {
configurations = listOf(shadowImpl)
relocate("net.hypixel.modapi.tweaker", "my.modid.modapitweaker.HypixelModAPITweaker")
}

tasks.withType(org.gradle.jvm.tasks.Jar::class) {
manifest.attributes.run {
this["TweakClass"] = "my.modid.modapitweaker.HypixelModAPITweaker"
}
}
```

Now your users will automatically use the bundled version of the mod api.


## Contributing

If you wish to contribute to this implementation of the Mod API to offer improvements or fixes, you can do so by forking the repository and creating a pull request.
If you wish to contribute to this implementation of the Mod API to offer improvements or fixes, you can do so by forking the repository and creating a pull request.

> [!IMPORTANT]
> Run `gradlew setupDecompWorkspace` after importing the project to generate the files required to build it

If IntelliJ still shows unknown symbol errors after running the command, you may need to [clear the filesystem cache](https://www.jetbrains.com/help/idea/invalidate-caches.html).

### Testing Your Changes

You can enable DevAuth to log in to the Hypixel server with your Minecraft account. Please see the [DevAuth docs](https://github.com/DJtheRedstoner/DevAuth) for more details.
39 changes: 30 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,46 @@ buildscript {
}
}
apply plugin: 'net.minecraftforge.gradle.forge'
allprojects {
apply plugin: 'maven-publish'
version = "1.0.0.2" // First 3 numbers should correspond to the version of the API, last number is for the mod itself for any changes/fixes
group = "net.hypixel" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "HypixelModAPI"

version = "1.0.0.1" // First 3 numbers should correspond to the version of the API, last number is for the mod itself for any changes/fixes
group = "net.hypixel.modapi" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "HypixelModAPI"
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
maven {
url "https://repo.hypixel.net/repository/Hypixel/"
}
maven {
url "https://pkgs.dev.azure.com/djtheredstoner/DevAuth/_packaging/public/maven/v1"
}
mavenLocal()
}

repositories {
maven {
url "https://repo.hypixel.net/repository/Hypixel/"
publishing {
publications {
maven(MavenPublication) {
groupId = project.group
artifactId = project == rootProject ? 'mod-api-forge' : ('mod-api-forge-' + project.name)
version = project.version
from components.java
}
}
}
mavenLocal()
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

minecraft {
version = "1.8.9-11.15.1.1722"
// version = "1.8.9-11.15.1.2318-1.8.9"
runDir = "run"

mappings = "stable_22"

replace('${version}', project.version)
replaceIn("ForgeModAPI.java")
}

configurations {
Expand All @@ -40,6 +60,7 @@ configurations {

dependencies {
shade "net.hypixel:mod-api:1.0"
runtimeOnly "me.djtheredstoner:DevAuth-forge-legacy:1.2.1"
}

jar {
Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Ensure Gradle has enough RAM to decompile Minecraft
org.gradle.jvmargs=-Xmx2G
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include 'tweaker'
12 changes: 6 additions & 6 deletions src/main/java/net/hypixel/modapi/forge/ForgeModAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.network.FMLNetworkEvent;

import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

@Mod(modid = ForgeModAPI.MODID, version = ForgeModAPI.VERSION, clientSideOnly = true, name = "Hypixel Mod API")
public class ForgeModAPI {
public static final String MODID = "hypixel_mod_api";
public static final String VERSION = "1.0.0.1";
private static final Logger LOGGER = Logger.getLogger("HypixelModAPI");
public static final String VERSION = "${version}";
private static final Logger LOGGER = LogManager.getLogger("HypixelModAPI");

// We store a local reference to the net handler, so it's instantly available from the moment we connect
private NetHandlerPlayClient netHandler;
Expand Down Expand Up @@ -55,7 +55,7 @@ private boolean sendPacket(HypixelPacket packet) {
}

if (!netHandler.getNetworkManager().isChannelOpen()) {
LOGGER.warning("Attempted to send packet while channel is closed!");
LOGGER.warn("Attempted to send packet while channel is closed!");
netHandler = null;
return false;
}
Expand Down Expand Up @@ -91,7 +91,7 @@ protected void channelRead0(ChannelHandlerContext ctx, Packet<?> msg) {
try {
HypixelModAPI.getInstance().handle(identifier, new PacketSerializer(buffer));
} catch (Exception e) {
LOGGER.log(Level.WARNING, "Failed to handle packet " + identifier, e);
LOGGER.warn("Failed to handle packet {}", identifier, e);
} finally {
buffer.release();
}
Expand Down
26 changes: 26 additions & 0 deletions tweaker/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
apply plugin: 'net.minecraftforge.gradle.forge'

minecraft {
version = "1.8.9-11.15.1.1722"
// version = "1.8.9-11.15.1.2318-1.8.9"
runDir = "run"

mappings = "stable_22"
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

task generateVersionInfo(type: WriteProperties) {
outputFile(file(new File(buildDir, "/properties/hypixel-mod-api-bundled.properties")))
property("version", version)
}

tasks.jar {
dependsOn(project(":").reobfJar)
from(project(":").jar)
from(generateVersionInfo)
manifest {
attributes("TweakClass": "net.hypixel.modapi.tweaker.HypixelModAPITweaker")
}
}
Loading