Skip to content

Commit b0b4a35

Browse files
authored
Merge pull request #3 from breakthebot/feat-breakthelibrary
Integrate breakthelibrary into breakthemod
2 parents 0b2eaa6 + efa6ce0 commit b0b4a35

38 files changed

Lines changed: 488 additions & 973 deletions

TODO.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# TODO
22
* Find a way to bypass the xaeros packets to enable entity radar.
33
* Make a proper emc api library.
4-
* Improve performance and try to decrease jar size.
4+
* Improve performance and try to decrease jar size.
5+
* Improve testing.

build.gradle.kts

Lines changed: 90 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
44
plugins {
55
kotlin("jvm") version "2.2.10"
66
id("fabric-loom") version "1.11-SNAPSHOT"
7-
id("maven-publish")
87
kotlin("plugin.serialization") version "1.9.10"
8+
id("com.github.johnrengelman.shadow") version "8.1.1"
9+
910
}
1011

1112
version = project.property("mod_version") as String
@@ -18,9 +19,6 @@ base {
1819
val targetJavaVersion = 21
1920
java {
2021
toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
21-
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
22-
// if it is present.
23-
// If you remove this line, sources will not be generated.
2422
withSourcesJar()
2523
}
2624

@@ -32,11 +30,6 @@ fabricApi {
3230
}
3331

3432
repositories {
35-
// Add repositories to retrieve artifacts from in here.
36-
// You should only use this when depending on other mods because
37-
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
38-
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
39-
// for more information about repositories.
4033
maven ("https://maven.terraformersmc.com/") {
4134
name = "Terraformers"
4235
}
@@ -45,6 +38,7 @@ repositories {
4538
}
4639
maven("https://maven.shedaniel.me/")
4740
maven("https://maven.isxander.dev/releases")
41+
maven("https://jitpack.io")
4842
exclusiveContent {
4943
forRepository {
5044
maven("https://api.modrinth.com/maven")
@@ -56,31 +50,54 @@ repositories {
5650

5751
}
5852

53+
val shade: Configuration by configurations.creating {
54+
isCanBeConsumed = false
55+
isCanBeResolved = true
56+
isVisible = false
57+
}
58+
59+
val mcVer = project.property("minecraft_version")
60+
val mappings = project.property("yarn_mappings")
61+
62+
val fabricVersion = project.property("fabric_version")
63+
val fabricLoader = project.property("loader_version")
64+
val kotlinLoader = project.property("kotlin_loader_version")
65+
val ktSere = project.property("kt_sere")
66+
67+
val xaerosVersion = project.property("xaeros_version")
68+
val clothVersion = project.property("cloth_config")
69+
val modmenu = project.property("modmenu")
70+
val placeholderVersion = project.property("placeholder_api")
71+
5972
dependencies {
60-
minecraft("com.mojang:minecraft:${project.property("minecraft_version")}")
61-
mappings("net.fabricmc:yarn:${project.property("yarn_mappings")}:v2")
73+
minecraft("com.mojang:minecraft:$mcVer")
74+
mappings("net.fabricmc:yarn:$mappings:v2")
6275

6376
compileOnly("org.jetbrains.kotlin:kotlin-stdlib")
6477
compileOnly("org.jetbrains.kotlin:kotlin-reflect")
6578

66-
compileOnly("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3")
79+
compileOnly("org.jetbrains.kotlinx:kotlinx-serialization-json:$ktSere")
6780

68-
modImplementation("net.fabricmc:fabric-loader:${project.property("loader_version")}")
69-
modImplementation("net.fabricmc:fabric-language-kotlin:${project.property("kotlin_loader_version")}")
81+
modImplementation("net.fabricmc:fabric-loader:$fabricLoader")
82+
modImplementation("net.fabricmc.fabric-api:fabric-api:$fabricVersion")
7083

71-
modImplementation("net.fabricmc.fabric-api:fabric-api:${project.property("fabric_version")}")
84+
modImplementation("net.fabricmc:fabric-language-kotlin:$kotlinLoader")
7285

73-
modImplementation("eu.pb4:placeholder-api:${project.property("placeholder_api")}")
86+
modImplementation("eu.pb4:placeholder-api:$placeholderVersion")
7487

75-
modApi("me.shedaniel.cloth:cloth-config-fabric:${project.property("cloth_config")}") {
88+
modApi("me.shedaniel.cloth:cloth-config-fabric:$clothVersion") {
7689
exclude("net.fabricmc.fabric-api")
7790
}
7891

79-
modApi("com.terraformersmc:modmenu:${project.property("modmenu")}")
92+
modApi("com.terraformersmc:modmenu:$modmenu")
93+
94+
implementation("com.github.breakthebot:breakthelibrary:1.0.4")
95+
shade("com.github.breakthebot:breakthelibrary:1.0.4") {
96+
isTransitive = false
97+
}
98+
8099
modImplementation("maven.modrinth:xaeros-minimap:${project.property("xaeros_version")}")
81100

82-
testImplementation(kotlin("test"))
83-
testImplementation("org.junit.jupiter:junit-jupiter:5.10.1")
84101
}
85102

86103
tasks.processResources {
@@ -92,22 +109,68 @@ tasks.processResources {
92109
filesMatching("fabric.mod.json") {
93110
expand(
94111
"version" to project.version,
95-
"minecraft_version" to project.property("minecraft_version"),
96-
"loader_version" to project.property("loader_version"),
97-
"kotlin_loader_version" to project.property("kotlin_loader_version")
112+
"minecraft_version" to mcVer,
113+
"loader_version" to fabricLoader,
114+
"kotlin_loader_version" to kotlinLoader,
115+
"cloth_config" to clothVersion,
116+
"placeholder_api" to placeholderVersion,
117+
"modmenu" to modmenu
98118
)
99119
}
100120
}
101121

102122
tasks.withType<JavaCompile>().configureEach {
103-
// ensure that the encoding is set to UTF-8, no matter what the system default is
104-
// this fixes some edge cases with special characters not displaying correctly
105-
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
106-
// If Javadoc is generated, this must be specified in that task too.
107123
options.encoding = "UTF-8"
108124
options.release.set(targetJavaVersion)
109125
}
110126

127+
val headerText = file("header.txt").readText()
128+
129+
val addHeader by tasks.registering {
130+
group = "build"
131+
132+
val targetFiles = fileTree("src") {
133+
include("**/*.kt")
134+
include("**/*.java")
135+
}
136+
137+
doLast {
138+
targetFiles.forEach { file: File ->
139+
val content = file.readText()
140+
if (!content.startsWith(headerText)) {
141+
file.writeText("$headerText\n$content")
142+
}
143+
}
144+
}
145+
}
146+
147+
tasks.shadowJar {
148+
dependsOn(tasks.jar)
149+
150+
archiveClassifier.set("shadow-dev")
151+
152+
configurations = listOf(shade)
153+
154+
from(zipTree(tasks.jar.get().archiveFile))
155+
156+
relocate(
157+
"org.breakthebot.breakthelibrary",
158+
"net.chariskar.breakthebot.breakthelibrary"
159+
)
160+
}
161+
162+
val remapShadowJar by tasks.registering(net.fabricmc.loom.task.RemapJarTask::class) {
163+
dependsOn(tasks.shadowJar)
164+
inputFile.set(tasks.shadowJar.get().archiveFile)
165+
archiveClassifier.set("shadowed")
166+
167+
doLast {
168+
delete(tasks.shadowJar.get().archiveFile.get().asFile)
169+
}
170+
}
171+
172+
tasks["build"].dependsOn(addHeader, remapShadowJar)
173+
111174
tasks.withType<KotlinCompile>().configureEach {
112175
compilerOptions.jvmTarget.set(JvmTarget.fromTarget(targetJavaVersion.toString()))
113176
}
@@ -118,10 +181,6 @@ tasks.jar {
118181
}
119182
}
120183

121-
tasks.test {
122-
useJUnitPlatform()
123-
}
124-
125184
kotlin {
126185
compilerOptions {
127186
allWarningsAsErrors.set(true)

gradle.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ fabric_version=0.136.0+1.21.8
1616
xaeros_version=25.2.16_Fabric_1.21.8
1717
placeholder_api=2.7.2+1.21.8
1818
cloth_config=19.0.147
19-
modmenu=15.0.0
19+
modmenu=15.0.0
20+
kt_sere = 1.6.3

src/main/kotlin/net/chariskar/breakthemod/client/objects/Reference.kt renamed to header.txt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,3 @@
1414
* You should have received a copy of the GNU General Public License
1515
* along with breakthemod. If not, see <https://www.gnu.org/licenses/>.
1616
*/
17-
package net.chariskar.breakthemod.client.objects
18-
19-
import kotlinx.serialization.Serializable
20-
import net.chariskar.breakthemod.client.utils.serialization.SerializableUUID
21-
22-
@Serializable
23-
data class Reference(
24-
val uuid: SerializableUUID?,
25-
val name: String?
26-
)

proguard-rules.pro

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
-dontnote
33
-dontoptimize
44

5-
-injars build/libs/breakthemod-1.4.3.jar
5+
-injars build/libs/breakthemod-1.4.5-shadowed.jar
66
-outjars build/libs/btm-obf.jar
77

88
-libraryjars <java.home>/jmods/
@@ -14,16 +14,21 @@
1414

1515
-keep public class net.chariskar.breakthemod.Breakthemod { *; }
1616

17-
-keep class net.chariskar.breakthemod.client.commands.** implements net.chariskar.breakthemod.client.api.* { *; }
18-
-keep class * implements net.fabricmc.api.ClientModInitializer { *; }
19-
-keep public class net.chariskar.breakthemod.client.api.** { *; }
20-
-keep public class net.chariskar.breakthemod.client.hooks.** { *; }
17+
-keep class net.chariskar.breakthemod.client.commands.** implements net.chariskar.breakthemod.client.api.BaseCommand { *; }
18+
19+
# -keep public class net.chariskar.breakthemod.Breakthemod implements net.fabricmc.api.ClientModInitializer { *; }
20+
21+
-keep public class net.chariskar.breakthebot.breakthelibrary.models.** { *; }
2122

22-
-keep class net.chariskar.breakthemod.client.utils.** { *; }
2323
-keep public class net.chariskar.breakthemod.mixins.** { *; }
2424

2525
-keepclassmembers class kotlin.Metadata { *; }
26-
-keepattributes RuntimeVisibleAnnotations,RuntimeInvisibleAnnotations
26+
-keepattributes RuntimeVisibleAnnotations,
27+
RuntimeInvisibleAnnotations,
28+
Signature,
29+
InnerClasses,
30+
EnclosingMethod,
31+
Exceptions
2732

2833
-keepdirectories META-INF/**
2934
-keepdirectories resources/**

src/main/java/net/chariskar/breakthemod/mixins/EntityRadar.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/*
2+
* This file is part of breakthemod.
3+
*
4+
* breakthemod is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* breakthemod is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with breakthemod. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
118
package net.chariskar.breakthemod.mixins;
219

320

src/main/java/net/chariskar/breakthemod/mixins/FairPlay.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/*
2+
* This file is part of breakthemod.
3+
*
4+
* breakthemod is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* breakthemod is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with breakthemod. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
118
package net.chariskar.breakthemod.mixins;
219

320

src/main/java/net/chariskar/breakthemod/mixins/RadarStateAccessor.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/*
2+
* This file is part of breakthemod.
3+
*
4+
* breakthemod is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* breakthemod is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with breakthemod. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
118
package net.chariskar.breakthemod.mixins;
219

320
import org.spongepowered.asm.mixin.Mixin;

src/main/kotlin/net/chariskar/breakthemod/Breakthemod.kt

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@
1616
*/
1717
package net.chariskar.breakthemod
1818

19-
import net.chariskar.breakthemod.client.api.Command
19+
import net.chariskar.breakthemod.client.api.BaseCommand
2020
import net.chariskar.breakthemod.client.api.engine.NearbyEngine
2121
import net.chariskar.breakthemod.client.commands.Debug
22-
import net.chariskar.breakthemod.client.commands.discordId
22+
import net.chariskar.breakthemod.client.commands.DiscordId
2323
import net.chariskar.breakthemod.client.commands.FindPlayer
2424
import net.chariskar.breakthemod.client.commands.goto
25-
import net.chariskar.breakthemod.client.commands.help
26-
import net.chariskar.breakthemod.client.commands.lastSeen
27-
import net.chariskar.breakthemod.client.commands.locate
28-
import net.chariskar.breakthemod.client.commands.nearby
29-
import net.chariskar.breakthemod.client.commands.onlineStaff
30-
import net.chariskar.breakthemod.client.commands.townless
25+
import net.chariskar.breakthemod.client.commands.Help
26+
import net.chariskar.breakthemod.client.commands.LastSeen
27+
import net.chariskar.breakthemod.client.commands.Locate
28+
import net.chariskar.breakthemod.client.commands.Nearby
29+
import net.chariskar.breakthemod.client.commands.OnlineStaff
30+
import net.chariskar.breakthemod.client.commands.Townless
3131
import net.chariskar.breakthemod.client.hooks.nearby.Hud
3232
import net.chariskar.breakthemod.client.utils.Config
3333
import net.fabricmc.api.ClientModInitializer
@@ -43,7 +43,7 @@ import com.mojang.brigadier.CommandDispatcher
4343
class Breakthemod : ClientModInitializer {
4444
val nearbyLayer: Identifier = Identifier.of("breakthemod", "nearby_layer")
4545

46-
private fun loadCommands(commands: MutableList<Command>) {
46+
private fun loadCommands(commands: MutableList<BaseCommand>) {
4747
ClientCommandRegistrationCallback.EVENT.register(ClientCommandRegistrationCallback { dispatcher: CommandDispatcher<FabricClientCommandSource>, _: CommandRegistryAccess ->
4848
for (command in commands) {
4949
command.register(dispatcher)
@@ -53,16 +53,16 @@ class Breakthemod : ClientModInitializer {
5353

5454
override fun onInitializeClient() {
5555
Config.loadConfig()
56-
val helpCmd = help()
57-
val commandList: MutableList<Command> = mutableListOf(
58-
nearby(),
59-
onlineStaff(),
60-
townless(),
56+
val helpCmd = Help()
57+
val commandList: MutableList<BaseCommand> = mutableListOf(
58+
Nearby(),
59+
OnlineStaff(),
60+
Townless(),
6161
goto(),
6262
FindPlayer(),
63-
lastSeen(),
64-
discordId(),
65-
locate(),
63+
LastSeen(),
64+
DiscordId(),
65+
Locate(),
6666
Debug(),
6767
helpCmd
6868
)

src/main/kotlin/net/chariskar/breakthemod/client/api/Command.kt renamed to src/main/kotlin/net/chariskar/breakthemod/client/api/BaseCommand.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ private object CommandScope {
4444
}
4545
}
4646

47-
abstract class Command {
47+
abstract class BaseCommand {
4848
val logger: Logger = LoggerFactory.getLogger("breakthemod")
49-
val fetch: Fetch = Fetch
5049
val client: MinecraftClient = MinecraftClient.getInstance()
5150
protected val scope = CommandScope.scope
5251

0 commit comments

Comments
 (0)