Skip to content

Commit

Permalink
Change DSL to kotlin and fixed AutoEnchant
Browse files Browse the repository at this point in the history
  • Loading branch information
qingshu-ui committed Oct 14, 2024
1 parent fef076a commit 63da778
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 146 deletions.
97 changes: 0 additions & 97 deletions build.gradle

This file was deleted.

130 changes: 130 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
@file:Suppress("PropertyName")

import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

val minecraft_version: String by project
val yarn_version: String by project
val loader_version: String by project
val meteor_version: String by project
val baritone_version: String by project
val kotlin_loader_version: String by project

plugins {
kotlin("jvm") version "2.0.21"
id("fabric-loom") version "1.7-SNAPSHOT"
}

version = project.property("mod_version") as String
group = project.property("maven_group") as String

base {
archivesName.set(project.property("archives_base_name") as String)
}

val targetJavaVersion = 21
java {
toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
withSourcesJar()
}

repositories {
mavenCentral()
mavenLocal()
maven { url = uri("https://maven.meteordev.org/releases") }
maven { url = uri("https://maven.meteordev.org/snapshots") }
maven { url = uri("https://maven.seedfinding.com/") }
maven { url = uri("https://maven-snapshots.seedfinding.com/") }
maven { url = uri("https://jitpack.io") }
maven { url = uri("https://maven.duti.dev/releases") }
}
configurations {
// configuration that holds jars to include in the jar
create("extraLibs")
}

configurations {
named("implementation") {
extendsFrom(getByName("extraLibs"))
}
}

dependencies {
// This will make it work on most platforms. It automatically chooses the right dependencies at runtime.
"extraLibs"("dev.duti.acheong:cubiomes:1.22.3") { isTransitive = false }
"extraLibs"("dev.duti.acheong:cubiomes:1.22.3:linux64") { isTransitive = false }
"extraLibs"("dev.duti.acheong:cubiomes:1.22.3:osx") { isTransitive = false }
"extraLibs"("dev.duti.acheong:cubiomes:1.22.3:windows64") { isTransitive = false }
// To change the versions see the gradle.properties file
minecraft("com.mojang:minecraft:$minecraft_version")
mappings("net.fabricmc:yarn:$yarn_version:v2")
modImplementation("net.fabricmc:fabric-loader:$loader_version")
modImplementation("net.fabricmc:fabric-language-kotlin:$kotlin_loader_version")

modImplementation("meteordevelopment:meteor-client:$meteor_version-SNAPSHOT")
modCompileOnly("meteordevelopment:baritone:$baritone_version-SNAPSHOT")

// seed .locate and ore sim
"extraLibs"("com.seedfinding:mc_math:ffd2edcfcc0d18147549c88cc7d8ec6cf21b5b91") { isTransitive = false }
"extraLibs"("com.seedfinding:mc_seed:1ead6fcefe7e8de4b3d60cd6c4e993f1e8f33409") { isTransitive = false }
"extraLibs"("com.seedfinding:mc_core:d64d5f90be66300da41ef58f4f1736db2499784f") { isTransitive = false }
"extraLibs"("com.seedfinding:mc_noise:7e3ba65e181796c4a2a1c8881d840b2254b92962") { isTransitive = false }
"extraLibs"("com.seedfinding:mc_biome:41a42cb9019a552598f12089059538853e18ec78") { isTransitive = false }
"extraLibs"("com.seedfinding:mc_terrain:b4246cbd5880c4f8745ccb90e1b102bde3448126") { isTransitive = false }
"extraLibs"("com.seedfinding:mc_feature:919b7e513cc1e87e029a9cd703fc4e2dc8686229") { isTransitive = false }

// seedcracker api
implementation("com.github.19MisterX98.SeedcrackerX:seedcrackerx-api:2.10.1") { isTransitive = false }
// implementation (include('com.github.19MisterX98.SeedcrackerX:seedcrackerx-api:master-SNAPSHOT')) {transitive = false}
}

loom {
accessWidenerPath = file("src/main/resources/meteor-rejects.accesswidener")
}

tasks.processResources {
inputs.property("version", project.version)
inputs.property("minecraft_version", project.property("minecraft_version"))
inputs.property("loader_version", project.property("loader_version"))
filteringCharset = "UTF-8"


filesMatching("fabric.mod.json") {
expand(
"version" to project.version,
"mc_version" to project.property("minecraft_version"),
"gh_hash" to (System.getenv("GITHUB_SHA") ?: ""),
"kotlin_loader_version" to project.property("kotlin_loader_version"),
)
}
}

tasks.jar {
from("LICENSE") {
rename { "${it}_${project.base.archivesName}" }
}
from(configurations["extraLibs"].map { if (it.isDirectory) it else zipTree(it) })
}

tasks.withType<Jar>() {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}

tasks.withType<KotlinCompile>().configureEach {
compilerOptions.jvmTarget.set(JvmTarget.fromTarget(targetJavaVersion.toString()))
}

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

// The Minecraft launcher currently installs Java 8 for users, so your mod probably wants to target Java 8 too
// JDK 9 introduced a new way of specifying this that will make sure no newer classes or methods are used.
// We'll use that if it's available, but otherwise we'll use the older option.
if(JavaVersion.current().isJava9Compatible){
options.release.set(targetJavaVersion)
}
}
7 changes: 4 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx2G
org.gradle.jvmargs=-Xmx4G

# Fabric Properties
minecraft_version=1.21
yarn_version=1.21+build.2
minecraft_version=1.21.1
yarn_version=1.21.1+build.3
loader_version=0.15.11
kotlin_loader_version=1.12.3+kotlin.2.0.21

# Mod Properties
mod_version = 0.3
Expand Down
9 changes: 0 additions & 9 deletions settings.gradle

This file was deleted.

8 changes: 8 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pluginManagement {
repositories {
maven("https://maven.fabricmc.net/") {
name = "Fabric"
}
gradlePluginPortal()
}
}
66 changes: 32 additions & 34 deletions src/main/java/anticope/rejects/modules/AutoEnchant.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package anticope.rejects.modules;

import anticope.rejects.MeteorRejectsAddon;

import meteordevelopment.meteorclient.events.game.OpenScreenEvent;
import meteordevelopment.meteorclient.settings.*;
import meteordevelopment.meteorclient.utils.network.MeteorExecutor;
Expand All @@ -17,6 +16,9 @@

import java.util.List;
import java.util.Objects;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class AutoEnchant extends meteordevelopment.meteorclient.systems.modules.Module {

Expand Down Expand Up @@ -66,47 +68,43 @@ private void onOpenScreen(OpenScreenEvent event) {
MeteorExecutor.execute(this::autoEnchant);
}

private void autoEnchant() {
private synchronized void autoEnchant() {
if (!(Objects.requireNonNull(mc.player).currentScreenHandler instanceof EnchantmentScreenHandler handler))
return;
if (mc.player.experienceLevel < 30) {
info("You don't have enough experience levels");
return;
}
while (getEmptySlotCount(handler) > 2 || drop.get()) {
if (!(mc.player.currentScreenHandler instanceof EnchantmentScreenHandler)) {
info("Enchanting table is closed.");
break;
}
if (handler.getLapisCount() < level.get() && !fillLapisItem()) {
info("Lapis lazuli is not found.");
break;
}
if (!fillCanEnchantItem()) {
info("No items found to enchant.");
break;
}
Objects.requireNonNull(mc.interactionManager).clickButton(handler.syncId, level.get() - 1);
if (getEmptySlotCount(handler) > 2) {
InvUtils.shiftClick().slotId(0);
} else if (drop.get() && handler.getSlot(0).hasStack()) {
// I don't know why an exception LegacyRandomSource is thrown here,
// so I used the main thread to drop items.
mc.execute(() -> InvUtils.drop().slotId(0));
}

/*
Although the description here indicates that the tick is the unit,
the actual delay is not the tick unit,
but it does not affect the normal operation in the game.
Perhaps we can ignore it
*/
ScheduledExecutorService executors = Executors.newSingleThreadScheduledExecutor();
executors.scheduleAtFixedRate(() -> {
try {
Thread.sleep(delay.get());
} catch (InterruptedException e) {
throw new RuntimeException(e);
if (!(mc.player.currentScreenHandler instanceof EnchantmentScreenHandler)) {
info("Enchanting table is closed.");
executors.shutdown();
return;
}
if (handler.getLapisCount() < level.get() && !fillLapisItem()) {
info("Lapis lazuli is not found.");
executors.shutdown();
return;
}
if (!fillCanEnchantItem()) {
info("No items found to enchant.");
executors.shutdown();
return;
}

Objects.requireNonNull(mc.interactionManager).clickButton(handler.syncId, level.get() - 1);
if (getEmptySlotCount(handler) > 2) {
InvUtils.shiftClick().slotId(0);
} else if (drop.get() && handler.getSlot(0).hasStack()) {
mc.execute(() -> InvUtils.drop().slotId(0));
}
}catch (Exception e) {
e.printStackTrace();
executors.shutdown();
}
}
}, 0, delay.get(), TimeUnit.MILLISECONDS);
}

private boolean fillCanEnchantItem() {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/anticope/rejects/modules/CoordLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ private void onPacketReceive(PacketEvent.Receive event) {
// Teleports
if (event.packet instanceof EntityPositionS2CPacket) {
EntityPositionS2CPacket packet = (EntityPositionS2CPacket) event.packet;

try {
Entity entity = mc.world.getEntityById(packet.getId());
Entity entity = mc.world.getEntityById(packet.getEntityId());

// Player teleport
if (entity.getType().equals(EntityType.PLAYER) && players.get()) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"depends": {
"java": ">=16",
"minecraft": "~${mc_version}",
"meteor-client": "*"
"meteor-client": "*",
"fabric-language-kotlin": ">=${kotlin_loader_version}"
}
}

0 comments on commit 63da778

Please sign in to comment.