Skip to content

Commit

Permalink
kotlin on the microwave
Browse files Browse the repository at this point in the history
  • Loading branch information
NotNite committed Feb 15, 2024
1 parent 337adcd commit 735d687
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 66 deletions.
13 changes: 10 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id("org.jetbrains.kotlin.jvm") version "1.9.0"
id("fabric-loom") version "1.3-SNAPSHOT"
id("fabric-loom") version "1.5.7"
id("maven-publish")
java
}
Expand Down Expand Up @@ -36,13 +36,15 @@ dependencies {
modImplementation("net.fabricmc:fabric-language-kotlin:${property("fabric_kotlin_version")}")
modImplementation("net.fabricmc.fabric-api:fabric-api:${property("fabric_version")}")

modApi("com.adryd:cauldron:${property("cauldron_version")}")
modApi("pm.n2:hajlib:${property("hajlib_version")}")
modApi(files("./libs/cauldron-mc1.20.4-0.1.9+5e30141a.jar"))
modApi(files("./libs/hajlib-1.2.5.jar"))

modCompileOnly("com.terraformersmc:modmenu:${property("modmenu_version")}")
modRuntimeOnly("me.djtheredstoner:DevAuth-fabric:${property("devauth_version")}")
}



tasks {
compileKotlin {
kotlinOptions {
Expand All @@ -68,6 +70,11 @@ tasks {
rename { "${it}_${base.archivesName}" }
}
}

remapJar {
nestedJars.from(file("./libs/cauldron-mc1.20.4-0.1.9+5e30141a.jar"))
nestedJars.from(file("./libs/hajlib-1.2.5.jar"))
}
}

java {
Expand Down
16 changes: 7 additions & 9 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
org.gradle.jvmargs=-Xmx2G
org.gradle.parallel=true

minecraft_version=1.20.1
yarn_mappings=1.20.1+build.9
loader_version=0.14.21
fabric_kotlin_version=1.10.0+kotlin.1.9.0
minecraft_version=1.20.4
yarn_mappings=1.20.4+build.3
loader_version=0.15.6
fabric_kotlin_version=1.10.17+kotlin.1.9.22

version=0.3.4
version=0.3.5
group=pm.n2
archives_base_name=tangerine

fabric_version=0.85.0+1.20.1
cauldron_version=0.1.9
fabric_version=0.96.1+1.20.4
devauth_version=1.1.2
modmenu_version=7.0.1
hajlib_version=1.2.3
modmenu_version=9.0.0
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Binary file added libs/cauldron-mc1.20.4-0.1.9+5e30141a.jar
Binary file not shown.
Binary file added libs/hajlib-1.2.5.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ public class ClientPlayNetworkHandlerMixin {
private void onChunkData(ChunkDataS2CPacket packet, CallbackInfo ci) {
var world = MinecraftClient.getInstance().world;
if (world == null) return;
var chunk = world.getChunk(packet.getX(), packet.getZ());
var chunk = world.getChunk(packet.getChunkX(), packet.getChunkZ());
if (chunk == null) return;
BlockESPModule.INSTANCE.searchChunkSync(chunk);
}

@Inject(at = @At("HEAD"), method = "onUnloadChunk")
private void onChunkUnload(UnloadChunkS2CPacket packet, CallbackInfo ci) {
BlockESPModule.INSTANCE.unloadChunk(packet.getX() * 16, packet.getZ() * 16);
var pos = packet.pos();
BlockESPModule.INSTANCE.unloadChunk(pos.x * 16, pos.z * 16);
}

@Inject(method = "onPlayerPositionLook", at = @At("HEAD"))
Expand Down
54 changes: 4 additions & 50 deletions src/main/kotlin/pm/n2/tangerine/managers/MappingManager.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package pm.n2.tangerine.managers

import net.fabricmc.loader.api.FabricLoader
import net.fabricmc.mapping.tree.ClassDef
import net.fabricmc.mapping.tree.FieldDef
import net.fabricmc.mapping.tree.TinyMappingFactory
import net.fabricmc.mapping.tree.TinyTree
import pm.n2.tangerine.Tangerine
import pm.n2.tangerine.core.Manager
import java.io.BufferedReader
Expand All @@ -19,50 +15,8 @@ import java.lang.reflect.Field
* just ignore em.
*/
object MappingManager : Manager {
lateinit var tree: TinyTree

override fun init() {
val stream = Tangerine::class.java.getResourceAsStream("/assets/tangerine/mappings.tiny") ?: return
val reader = BufferedReader(stream.reader())
tree = TinyMappingFactory.loadWithDetection(reader)
}

private fun getClass(clazz: Class<*>): ClassDef? {
if (FabricLoader.getInstance().isDevelopmentEnvironment) return null
val name = clazz.name.replace(".", "/")
return tree.defaultNamespaceClassMap[name]
}

private fun getField(clazz: Class<*>, field: Field): FieldDef? {
if (FabricLoader.getInstance().isDevelopmentEnvironment) return null
val classDef = getClass(clazz) ?: return null

return classDef.fields.firstOrNull {
it.getName("intermediary") == field.name
}
}

fun mapClass(clazz: Class<*>): String = getClass(clazz)
?.getName("named")
?.replace("/", ".")
?: clazz.name

fun mapClassSimple(clazz: Class<*>): String = getClass(clazz)
?.getName("named")
.let {
it?.substringAfterLast("/")?.substringAfterLast("$")
?: clazz.simpleName
}

fun mapField(clazz: Class<*>, field: Field): String {
// fucking `extends` go fuck yourself
var superclazz: Class<*>? = clazz
while (superclazz != null) {
val name = getField(superclazz, field)?.getName("named")
if (name != null) return name
superclazz = superclazz.superclass
}

return field.name
}
// Mappings got removed I guess, just do this for now
fun mapClass(clazz: Class<*>) = clazz.name
fun mapClassSimple(clazz: Class<*>) = mapClass(clazz)
fun mapField(clazz: Class<*>, field: Field) = field.name
}
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
"depends": {
"fabricloader": ">=0.14.21",
"minecraft": "~1.20.1",
"minecraft": "~1.20.4",
"java": ">=17",
"fabric-api": "*",
"hajlib": ">=1.2.2",
Expand Down

0 comments on commit 735d687

Please sign in to comment.