Skip to content

Commit 6b2fd5a

Browse files
committed
Merge branch '1.19.4' into 1.20.5
2 parents 1704d56 + edb433e commit 6b2fd5a

File tree

19 files changed

+164
-220
lines changed

19 files changed

+164
-220
lines changed

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ allprojects {
3737
}
3838
group = rootProject.maven_group
3939

40-
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_21
40+
sourceCompatibility = targetCompatibility = JavaVersion.toVersion(project.java_version)
4141

4242
java {
4343
toolchain {
44-
languageVersion.set(JavaLanguageVersion.of(21))
44+
languageVersion.set(JavaLanguageVersion.of(sourceCompatibility.majorVersion.toInteger()))
4545
}
4646
}
4747

@@ -103,7 +103,7 @@ allprojects {
103103
tasks.withType(JavaCompile).configureEach {
104104
it.options.encoding = "UTF-8"
105105

106-
def targetVersion = 17
106+
def targetVersion = project.java_version.toInteger()
107107
if (JavaVersion.current().isJava9Compatible()) {
108108
it.options.release = targetVersion
109109
}

buildSrc/src/main/java/baritone/gradle/task/BaritoneGradleTask.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
class BaritoneGradleTask extends DefaultTask {
3737

3838
protected static final String
39-
PROGUARD_ZIP = "proguard.zip",
40-
PROGUARD_JAR = "proguard.jar",
39+
PROGUARD_ZIP = "proguard-%s.zip",
40+
PROGUARD_JAR = "proguard-%s.jar",
4141
PROGUARD_CONFIG_TEMPLATE = "scripts/proguard.pro",
4242
PROGUARD_CONFIG_DEST = "template.pro",
4343
PROGUARD_API_CONFIG = "api.pro",

buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java

Lines changed: 27 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
import org.gradle.api.tasks.compile.ForkOptions;
2727
import org.gradle.api.tasks.compile.JavaCompile;
2828
import org.gradle.internal.jvm.Jvm;
29+
import org.gradle.jvm.toolchain.JavaLanguageVersion;
30+
import org.gradle.jvm.toolchain.JavaLauncher;
31+
import org.gradle.jvm.toolchain.JavaToolchainService;
2932
import xyz.wagyourtail.unimined.api.UniminedExtension;
3033
import xyz.wagyourtail.unimined.api.minecraft.MinecraftConfig;
3134

@@ -47,17 +50,10 @@
4750
public class ProguardTask extends BaritoneGradleTask {
4851

4952
@Input
50-
private String url;
53+
private String proguardVersion;
5154

52-
public String getUrl() {
53-
return url;
54-
}
55-
56-
@Input
57-
private String extract;
58-
59-
public String getExtract() {
60-
return extract;
55+
public String getProguardVersion() {
56+
return proguardVersion;
6157
}
6258

6359
private List<String> requiredLibraries;
@@ -99,98 +95,33 @@ private void processArtifact() throws Exception {
9995
}
10096

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

108104
private void extractProguard() throws Exception {
109-
Path proguardJar = getTemporaryFile(PROGUARD_JAR);
105+
Path proguardJar = getTemporaryFile(String.format(PROGUARD_JAR, proguardVersion));
110106
if (!Files.exists(proguardJar)) {
111-
ZipFile zipFile = new ZipFile(getTemporaryFile(PROGUARD_ZIP).toFile());
112-
ZipEntry zipJarEntry = zipFile.getEntry(this.extract);
107+
ZipFile zipFile = new ZipFile(getTemporaryFile(String.format(PROGUARD_ZIP, proguardVersion)).toFile());
108+
ZipEntry zipJarEntry = zipFile.getEntry(String.format("proguard-%s/lib/proguard.jar", proguardVersion));
113109
write(zipFile.getInputStream(zipJarEntry), proguardJar);
114110
zipFile.close();
115111
}
116112
}
117113

118-
private String getJavaBinPathForProguard() throws Exception {
119-
String path;
120-
try {
121-
path = findJavaPathByGradleConfig();
122-
if (path != null) return path;
123-
} catch (Exception ex) {
124-
System.err.println("Unable to find java by javaCompile options");
125-
ex.printStackTrace();
126-
}
127-
128-
path = findJavaByGradleCurrentRuntime();
129-
if (path != null) return path;
130-
131-
try {
132-
path = findJavaByJavaHome();
133-
if (path != null) return path;
134-
} catch (Exception ex) {
135-
System.err.println("Unable to find java by JAVA_HOME");
136-
ex.printStackTrace();
137-
}
138-
139-
throw new Exception("Unable to find java to determine ProGuard libraryjars. Please specify forkOptions.executable in javaCompile," +
140-
" JAVA_HOME environment variable, or make sure to run Gradle with the correct JDK (a v1.8 only)");
141-
}
142-
143-
private String findJavaByGradleCurrentRuntime() {
144-
String path = Jvm.current().getJavaExecutable().getAbsolutePath();
145-
System.out.println("Using Gradle's runtime Java for ProGuard");
146-
return path;
147-
}
148-
149-
private String findJavaByJavaHome() {
150-
final String javaHomeEnv = System.getenv("JAVA_HOME");
151-
if (javaHomeEnv != null) {
152-
String path = Jvm.forHome(new File(javaHomeEnv)).getJavaExecutable().getAbsolutePath();
153-
System.out.println("Detected Java path by JAVA_HOME");
154-
return path;
155-
}
156-
return null;
157-
}
114+
private JavaLauncher getJavaLauncherForProguard() {
115+
var toolchains = getProject().getExtensions().getByType(JavaToolchainService.class);
116+
var toolchain = toolchains.launcherFor((spec) -> {
117+
spec.getLanguageVersion().set(JavaLanguageVersion.of(getProject().findProperty("java_version").toString()));
118+
}).getOrNull();
158119

159-
private String findJavaPathByGradleConfig() {
160-
final TaskCollection<JavaCompile> javaCompiles = super.getProject().getTasks().withType(JavaCompile.class);
161-
162-
final JavaCompile compileTask = javaCompiles.iterator().next();
163-
final ForkOptions forkOptions = compileTask.getOptions().getForkOptions();
164-
165-
if (forkOptions != null) {
166-
String javacPath = forkOptions.getExecutable();
167-
if (javacPath != null) {
168-
File javacFile = new File(javacPath);
169-
if (javacFile.exists()) {
170-
File[] maybeJava = javacFile.getParentFile().listFiles((dir, name) -> name.equals("java"));
171-
if (maybeJava != null && maybeJava.length > 0) {
172-
String path = maybeJava[0].getAbsolutePath();
173-
System.out.println("Detected Java path by forkOptions");
174-
return path;
175-
}
176-
}
177-
}
120+
if (toolchain == null) {
121+
throw new IllegalStateException("Java toolchain not found");
178122
}
179-
return null;
180-
}
181123

182-
private boolean validateJavaVersion(String java) {
183-
//TODO: fix for j16
184-
// final JavaVersion javaVersion = new DefaultJvmVersionDetector(new DefaultExecActionFactory(new IdentityFileResolver())).getJavaVersion(java);
185-
//
186-
// if (!javaVersion.getMajorVersion().equals("8")) {
187-
// System.out.println("Failed to validate Java version " + javaVersion.toString() + " [" + java + "] for ProGuard libraryjars");
188-
// // throw new RuntimeException("Java version incorrect: " + javaVersion.getMajorVersion() + " for " + java);
189-
// return false;
190-
// }
191-
//
192-
// System.out.println("Validated Java version " + javaVersion.toString() + " [" + java + "] for ProGuard libraryjars");
193-
return true;
124+
return toolchain;
194125
}
195126

196127
private void generateConfigs() throws Exception {
@@ -284,13 +215,8 @@ private void cleanup() {
284215
} catch (IOException ignored) {}
285216
}
286217

287-
public void setUrl(String url) {
288-
this.url = url;
289-
}
290-
291-
292-
public void setExtract(String extract) {
293-
this.extract = extract;
218+
public void setProguardVersion(String url) {
219+
this.proguardVersion = url;
294220
}
295221

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

302-
// Make paths relative to work directory; fixes spaces in path to config, @"" doesn't work
303228
Path workingDirectory = getTemporaryFile("");
304-
Path proguardJar = workingDirectory.relativize(getTemporaryFile(PROGUARD_JAR));
305-
config = workingDirectory.relativize(config);
306-
307-
// Honestly, if you still have spaces in your path at this point, you're SOL.
308229

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

313-
// We can't do output inherit process I/O with gradle for some reason and have it work, so we have to do this
314-
this.printOutputLog(p.getInputStream(), System.out);
315-
this.printOutputLog(p.getErrorStream(), System.err);
316-
317-
// Halt the current thread until the process is complete, if the exit code isn't 0, throw an exception
318-
int exitCode = p.waitFor();
319-
if (exitCode != 0) {
320-
Thread.sleep(1000);
321-
throw new IllegalStateException("Proguard exited with code " + exitCode);
322-
}
235+
spec.executable(getJavaLauncherForProguard().getExecutablePath().getAsFile());
236+
}).assertNormalExitValue().rethrowFailure();
323237
}
324238

325-
private void printOutputLog(InputStream stream, PrintStream outerr) {
326-
new Thread(() -> {
327-
try (BufferedReader reader = new BufferedReader(new InputStreamReader(stream))) {
328-
String line;
329-
while ((line = reader.readLine()) != null) {
330-
outerr.println(line);
331-
}
332-
} catch (Exception e) {
333-
e.printStackTrace();
334-
}
335-
}).start();
336-
}
337239
}

buildSrc/src/main/java/baritone/gradle/util/Determinizer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ public static void determinize(String inputPath, String outputPath, List<File> t
7171
ByteArrayOutputStream cancer = new ByteArrayOutputStream();
7272
copy(jarFile.getInputStream(entry), cancer);
7373
String manifest = new String(cancer.toByteArray());
74-
if (!manifest.contains("baritone.launch.BaritoneTweaker")) {
74+
if (!manifest.contains("baritone.launch.tweaker.BaritoneTweaker")) {
7575
throw new IllegalStateException("unable to replace");
7676
}
77-
manifest = manifest.replace("baritone.launch.BaritoneTweaker", "org.spongepowered.asm.launch.MixinTweaker");
77+
manifest = manifest.replace("baritone.launch.tweaker.BaritoneTweaker", "org.spongepowered.asm.launch.MixinTweaker");
7878
jos.write(manifest.getBytes());
7979
} else {
8080
copy(jarFile.getInputStream(entry), jos);

fabric/build.gradle

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ components.java {
7878
}
7979

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

forge/build.gradle

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ components.java {
9595
}
9696

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

gradle.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ mod_version=1.10.2
66
maven_group=baritone
77
archives_base_name=baritone
88

9+
java_version=21
10+
911
minecraft_version=1.20.6
1012

1113
forge_version=50.0.8

neoforge/build.gradle

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ components.java {
105105
}
106106

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

src/api/java/baritone/api/Settings.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ public final class Settings {
387387

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

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

976+
/**
977+
* Farming will scan for at most this many blocks.
978+
*/
979+
public final Setting<Integer> farmMaxScanSize = new Setting<>(256);
980+
976981
/**
977982
* When the cache scan gives less blocks than the maximum threshold (but still above zero), scan the main world too.
978983
* <p>

0 commit comments

Comments
 (0)