Skip to content

Commit

Permalink
Merge pull request #4439 from ZacSharp/1.20.5-update
Browse files Browse the repository at this point in the history
Merge 1.19.4 into 1.20.5
  • Loading branch information
leijurv committed Jul 28, 2024
2 parents 1704d56 + 6b2fd5a commit acdcbf5
Show file tree
Hide file tree
Showing 19 changed files with 164 additions and 220 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ allprojects {
}
group = rootProject.maven_group

sourceCompatibility = targetCompatibility = JavaVersion.VERSION_21
sourceCompatibility = targetCompatibility = JavaVersion.toVersion(project.java_version)

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(21))
languageVersion.set(JavaLanguageVersion.of(sourceCompatibility.majorVersion.toInteger()))
}
}

Expand Down Expand Up @@ -103,7 +103,7 @@ allprojects {
tasks.withType(JavaCompile).configureEach {
it.options.encoding = "UTF-8"

def targetVersion = 17
def targetVersion = project.java_version.toInteger()
if (JavaVersion.current().isJava9Compatible()) {
it.options.release = targetVersion
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
class BaritoneGradleTask extends DefaultTask {

protected static final String
PROGUARD_ZIP = "proguard.zip",
PROGUARD_JAR = "proguard.jar",
PROGUARD_ZIP = "proguard-%s.zip",
PROGUARD_JAR = "proguard-%s.jar",
PROGUARD_CONFIG_TEMPLATE = "scripts/proguard.pro",
PROGUARD_CONFIG_DEST = "template.pro",
PROGUARD_API_CONFIG = "api.pro",
Expand Down
152 changes: 27 additions & 125 deletions buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
import org.gradle.api.tasks.compile.ForkOptions;
import org.gradle.api.tasks.compile.JavaCompile;
import org.gradle.internal.jvm.Jvm;
import org.gradle.jvm.toolchain.JavaLanguageVersion;
import org.gradle.jvm.toolchain.JavaLauncher;
import org.gradle.jvm.toolchain.JavaToolchainService;
import xyz.wagyourtail.unimined.api.UniminedExtension;
import xyz.wagyourtail.unimined.api.minecraft.MinecraftConfig;

Expand All @@ -47,17 +50,10 @@
public class ProguardTask extends BaritoneGradleTask {

@Input
private String url;
private String proguardVersion;

public String getUrl() {
return url;
}

@Input
private String extract;

public String getExtract() {
return extract;
public String getProguardVersion() {
return proguardVersion;
}

private List<String> requiredLibraries;
Expand Down Expand Up @@ -99,98 +95,33 @@ private void processArtifact() throws Exception {
}

private void downloadProguard() throws Exception {
Path proguardZip = getTemporaryFile(PROGUARD_ZIP);
Path proguardZip = getTemporaryFile(String.format(PROGUARD_ZIP, proguardVersion));
if (!Files.exists(proguardZip)) {
write(new URL(this.url).openStream(), proguardZip);
write(new URL(String.format("https://github.com/Guardsquare/proguard/releases/download/v%s/proguard-%s.zip", proguardVersion, proguardVersion)).openStream(), proguardZip);
}
}

private void extractProguard() throws Exception {
Path proguardJar = getTemporaryFile(PROGUARD_JAR);
Path proguardJar = getTemporaryFile(String.format(PROGUARD_JAR, proguardVersion));
if (!Files.exists(proguardJar)) {
ZipFile zipFile = new ZipFile(getTemporaryFile(PROGUARD_ZIP).toFile());
ZipEntry zipJarEntry = zipFile.getEntry(this.extract);
ZipFile zipFile = new ZipFile(getTemporaryFile(String.format(PROGUARD_ZIP, proguardVersion)).toFile());
ZipEntry zipJarEntry = zipFile.getEntry(String.format("proguard-%s/lib/proguard.jar", proguardVersion));
write(zipFile.getInputStream(zipJarEntry), proguardJar);
zipFile.close();
}
}

private String getJavaBinPathForProguard() throws Exception {
String path;
try {
path = findJavaPathByGradleConfig();
if (path != null) return path;
} catch (Exception ex) {
System.err.println("Unable to find java by javaCompile options");
ex.printStackTrace();
}

path = findJavaByGradleCurrentRuntime();
if (path != null) return path;

try {
path = findJavaByJavaHome();
if (path != null) return path;
} catch (Exception ex) {
System.err.println("Unable to find java by JAVA_HOME");
ex.printStackTrace();
}

throw new Exception("Unable to find java to determine ProGuard libraryjars. Please specify forkOptions.executable in javaCompile," +
" JAVA_HOME environment variable, or make sure to run Gradle with the correct JDK (a v1.8 only)");
}

private String findJavaByGradleCurrentRuntime() {
String path = Jvm.current().getJavaExecutable().getAbsolutePath();
System.out.println("Using Gradle's runtime Java for ProGuard");
return path;
}

private String findJavaByJavaHome() {
final String javaHomeEnv = System.getenv("JAVA_HOME");
if (javaHomeEnv != null) {
String path = Jvm.forHome(new File(javaHomeEnv)).getJavaExecutable().getAbsolutePath();
System.out.println("Detected Java path by JAVA_HOME");
return path;
}
return null;
}
private JavaLauncher getJavaLauncherForProguard() {
var toolchains = getProject().getExtensions().getByType(JavaToolchainService.class);
var toolchain = toolchains.launcherFor((spec) -> {
spec.getLanguageVersion().set(JavaLanguageVersion.of(getProject().findProperty("java_version").toString()));
}).getOrNull();

private String findJavaPathByGradleConfig() {
final TaskCollection<JavaCompile> javaCompiles = super.getProject().getTasks().withType(JavaCompile.class);

final JavaCompile compileTask = javaCompiles.iterator().next();
final ForkOptions forkOptions = compileTask.getOptions().getForkOptions();

if (forkOptions != null) {
String javacPath = forkOptions.getExecutable();
if (javacPath != null) {
File javacFile = new File(javacPath);
if (javacFile.exists()) {
File[] maybeJava = javacFile.getParentFile().listFiles((dir, name) -> name.equals("java"));
if (maybeJava != null && maybeJava.length > 0) {
String path = maybeJava[0].getAbsolutePath();
System.out.println("Detected Java path by forkOptions");
return path;
}
}
}
if (toolchain == null) {
throw new IllegalStateException("Java toolchain not found");
}
return null;
}

private boolean validateJavaVersion(String java) {
//TODO: fix for j16
// final JavaVersion javaVersion = new DefaultJvmVersionDetector(new DefaultExecActionFactory(new IdentityFileResolver())).getJavaVersion(java);
//
// if (!javaVersion.getMajorVersion().equals("8")) {
// System.out.println("Failed to validate Java version " + javaVersion.toString() + " [" + java + "] for ProGuard libraryjars");
// // throw new RuntimeException("Java version incorrect: " + javaVersion.getMajorVersion() + " for " + java);
// return false;
// }
//
// System.out.println("Validated Java version " + javaVersion.toString() + " [" + java + "] for ProGuard libraryjars");
return true;
return toolchain;
}

private void generateConfigs() throws Exception {
Expand Down Expand Up @@ -284,13 +215,8 @@ private void cleanup() {
} catch (IOException ignored) {}
}

public void setUrl(String url) {
this.url = url;
}


public void setExtract(String extract) {
this.extract = extract;
public void setProguardVersion(String url) {
this.proguardVersion = url;
}

private void runProguard(Path config) throws Exception {
Expand All @@ -299,39 +225,15 @@ private void runProguard(Path config) throws Exception {
Files.delete(this.proguardOut);
}

// Make paths relative to work directory; fixes spaces in path to config, @"" doesn't work
Path workingDirectory = getTemporaryFile("");
Path proguardJar = workingDirectory.relativize(getTemporaryFile(PROGUARD_JAR));
config = workingDirectory.relativize(config);

// Honestly, if you still have spaces in your path at this point, you're SOL.

Process p = new ProcessBuilder("java", "-jar", proguardJar.toString(), "@" + config.toString())
.directory(workingDirectory.toFile()) // Set the working directory to the temporary folder]
.start();
getProject().javaexec(spec -> {
spec.workingDir(workingDirectory.toFile());
spec.args("@" + workingDirectory.relativize(config));
spec.classpath(getTemporaryFile(String.format(PROGUARD_JAR, proguardVersion)));

// We can't do output inherit process I/O with gradle for some reason and have it work, so we have to do this
this.printOutputLog(p.getInputStream(), System.out);
this.printOutputLog(p.getErrorStream(), System.err);

// Halt the current thread until the process is complete, if the exit code isn't 0, throw an exception
int exitCode = p.waitFor();
if (exitCode != 0) {
Thread.sleep(1000);
throw new IllegalStateException("Proguard exited with code " + exitCode);
}
spec.executable(getJavaLauncherForProguard().getExecutablePath().getAsFile());
}).assertNormalExitValue().rethrowFailure();
}

private void printOutputLog(InputStream stream, PrintStream outerr) {
new Thread(() -> {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(stream))) {
String line;
while ((line = reader.readLine()) != null) {
outerr.println(line);
}
} catch (Exception e) {
e.printStackTrace();
}
}).start();
}
}
4 changes: 2 additions & 2 deletions buildSrc/src/main/java/baritone/gradle/util/Determinizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ public static void determinize(String inputPath, String outputPath, List<File> t
ByteArrayOutputStream cancer = new ByteArrayOutputStream();
copy(jarFile.getInputStream(entry), cancer);
String manifest = new String(cancer.toByteArray());
if (!manifest.contains("baritone.launch.BaritoneTweaker")) {
if (!manifest.contains("baritone.launch.tweaker.BaritoneTweaker")) {
throw new IllegalStateException("unable to replace");
}
manifest = manifest.replace("baritone.launch.BaritoneTweaker", "org.spongepowered.asm.launch.MixinTweaker");
manifest = manifest.replace("baritone.launch.tweaker.BaritoneTweaker", "org.spongepowered.asm.launch.MixinTweaker");
jos.write(manifest.getBytes());
} else {
copy(jarFile.getInputStream(entry), jos);
Expand Down
3 changes: 1 addition & 2 deletions fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ components.java {
}

task proguard(type: ProguardTask) {
url 'https://github.com/Guardsquare/proguard/releases/download/v7.4.2/proguard-7.4.2.zip'
extract 'proguard-7.4.2/lib/proguard.jar'
proguardVersion "7.4.2"
compType "fabric"
}

Expand Down
3 changes: 1 addition & 2 deletions forge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ components.java {
}

task proguard(type: ProguardTask) {
url 'https://github.com/Guardsquare/proguard/releases/download/v7.4.2/proguard-7.4.2.zip'
extract 'proguard-7.4.2/lib/proguard.jar'
proguardVersion "7.4.2"
compType "forge"
}

Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ mod_version=1.10.2
maven_group=baritone
archives_base_name=baritone

java_version=21

minecraft_version=1.20.6

forge_version=50.0.8
Expand Down
3 changes: 1 addition & 2 deletions neoforge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ components.java {
}

task proguard(type: ProguardTask) {
url 'https://github.com/Guardsquare/proguard/releases/download/v7.4.2/proguard-7.4.2.zip'
extract 'proguard-7.4.2/lib/proguard.jar'
proguardVersion "7.4.2"
compType "neoforge"
}

Expand Down
7 changes: 6 additions & 1 deletion src/api/java/baritone/api/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ public final class Settings {

/**
* How many ticks between breaking a block and starting to break the next block. Default in game is 6 ticks.
* Values under 2 will be clamped.
* Values under 1 will be clamped. The delay only applies to non-instant (1-tick) breaks.
*/
public final Setting<Integer> blockBreakSpeed = new Setting<>(6);

Expand Down Expand Up @@ -973,6 +973,11 @@ public final class Settings {
*/
public final Setting<Boolean> replantNetherWart = new Setting<>(false);

/**
* Farming will scan for at most this many blocks.
*/
public final Setting<Integer> farmMaxScanSize = new Setting<>(256);

/**
* When the cache scan gives less blocks than the maximum threshold (but still above zero), scan the main world too.
* <p>
Expand Down
Loading

0 comments on commit acdcbf5

Please sign in to comment.