Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion CubicChunksCore
Submodule CubicChunksCore updated 1 files
+5 −0 build.gradle
17 changes: 6 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

## Not yet usable or functional, don't try.

Rewrite of the previous rewrite, targeting NeoForge/MC 1.20.4.
Rewrite of the previous rewrite, targeting NeoForge/MC 1.21.5.

This Minecraft mod extends Minecraft height and depth to be nearly infinite (at least a million blocks).

For the most up-to-date information about this mod and its related mods, as well as the newest downloads, please join us on the [**Cubic Chunks Discord**](https://discord.gg/kMfWg9m).

### Cubic Chunks (CC) - Links:

Github - [Cubic Chunks - 1.20.4 and above](https://github.com/OpenCubicChunks/CubicChunks3)
Github - [Cubic Chunks - 1.21.5 and above](https://github.com/OpenCubicChunks/CubicChunks3)
Github - [Cubic Chunks - 1.12.2 and lower](https://github.com/OpenCubicChunks/CubicChunks)

### Cloning the repository
Expand All @@ -37,12 +37,6 @@ Configure commits to be ignored for git blame:
git config blame.ignoreRevsFile .git-blame-ignore-revs
```

### Running the game

If running with IntelliJ, ensure that `io.github.opencubicchunks.[folder name].main` is selected, not `[folder name].main`:

![image](https://github.com/OpenCubicChunks/CubicChunks2/assets/18627001/0d88d6b5-0944-44f1-9461-fc90daef5766)

### Contributing

#### PR Guidelines
Expand All @@ -55,11 +49,12 @@ If running with IntelliJ, ensure that `io.github.opencubicchunks.[folder name].m
- If a mixin is "untestable" its test class should have a comment explaining *why* it's untestable.
- Optionally a to-do (project task? issue?) suggesting integration tests when possible.
- All non-trivial mixins _**must**_ have a comment explaining their purpose.
- _**Must**_ pass checkstyle.
- _**Must**_ build.
- All tests _**must**_ pass (no regressions).
- //todo Investigate code coverage for mixin tests ([jacoco?](https://docs.gradle.org/current/userguide/jacoco_plugin.html) [other link maybe it's bad](https://igorski.co/generating-junit-test-coverage-using-gradle-and-jacoco/)) .
- Any non-mixin class _**must**_ have tests associated with it.
- The tests should reasonably cover all expected usage of the class (its external api).
- Any method(s) that can be reasonably unit tested _**must**_ be.
- Anything annotated with `@SuppressWarnings` _**must**_ have either a TODO comment, or a comment explaining why the warning is suppressed.
- _**Must**_ pass spotless check and checkstyle. Spotless formats automatically if you run `./gradlew spotlessApply`; checkstyle violations must be fixed manually.
- _**Must**_ build.
- All tests _**must**_ pass (no regressions).
(TODO more contributing docs)
25 changes: 25 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import io.github.opencubicchunks.gradle.FixAnnotationsFormatterStep
import io.github.opencubicchunks.gradle.GeneratePackageInfo
import org.gradle.api.tasks.testing.logging.TestExceptionFormat

Expand All @@ -11,6 +12,8 @@ plugins {
id 'eclipse'
id 'idea'
id 'maven-publish'
id("com.diffplug.spotless") version "7.0.4"
id "checkstyle"
id 'net.neoforged.moddev' version '2.0.90'
id("io.github.opencubicchunks.javaheaders").version("1.2.8")
id("io.github.opencubicchunks.gradle.mcGitVersion")
Expand Down Expand Up @@ -380,6 +383,28 @@ test {
// dependsOn longRunTest
//}

spotless {
java {
// Specified explicitly to ignore CubicChunksCore and src_old
target(
"src/*/java/**/*.java",
"buildSrc/src/*/java/**/*.java"
)

eclipse().configFile('config/eclipse_formatter.xml')
// Eclipse JDT puts all annotations on their own lines; we merge some of them back onto the same line as their target.
addStep(new FixAnnotationsFormatterStep())

importOrder("\\#", "java", "javax", "")
removeUnusedImports()
}
}

tasks.withType(Checkstyle) {
// Auto-formatting might fix some Checkstyle violations, so don't run Checkstyle unless spotlessCheck passes
dependsOn spotlessCheck
}

publishing {
publications {
register('mavenJava', MavenPublication) {
Expand Down
3 changes: 3 additions & 0 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@ dependencies {

implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
implementation "org.ajoberstar.grgit:grgit-core:5.3.0"

implementation "com.diffplug.spotless:spotless-lib:3.1.2"
implementation "com.diffplug.spotless:spotless-lib-extra:3.1.2"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.github.opencubicchunks.gradle;

import java.io.File;

import com.diffplug.spotless.FormatterStep;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class FixAnnotationsFormatterStep implements FormatterStep {
@Override public String getName() {
return "cc_fix_annotations";
}

private static final String[] ANNOTATIONS = { "@Shadow", "@Final", "@Mutable", "@Public", "@Override", "@Nullable", "@NotNull", };

@Override public @Nullable String format(String s, @NotNull File file) {
var outputString = s;
for (var annotation : ANNOTATIONS) {
// Remove newlines after the listed annotations
outputString = outputString.replaceAll(annotation + "\\n\\h*", annotation + " ");
}
return outputString;
}

@Override public void close() {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ public class GeneratePackageInfo {
public static void generateFiles(SourceSet sourceSet) throws IOException {
Map<Path, Path> packages = getPackages(sourceSet.getAllJava());
String code = """
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
package __PACKAGE__;
import javax.annotation.ParametersAreNonnullByDefault;
import io.github.opencubicchunks.cc_core.annotation.MethodsReturnNonnullByDefault;""";
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
package __PACKAGE__;

import javax.annotation.ParametersAreNonnullByDefault;

import io.github.opencubicchunks.cc_core.annotation.MethodsReturnNonnullByDefault;""";
for (Path pkg : packages.keySet()) {
Path absolutePath = packages.get(pkg);
Path file = absolutePath.resolve("package-info.java");
Expand All @@ -45,7 +45,8 @@ private static Map<Path, Path> getPackages(SourceDirectorySet allJava) throws IO
for (File it : allJava) {
Path javaClass = it.getCanonicalFile().toPath();
if (javaClass.toString().contains("mixin/test")) {
// junit will try to load package-info files (when scanning for tests) causing mixin to throw as classes in mixin packages must not be loaded.
// junit will try to load package-info files (when scanning for tests) causing mixin to throw as classes in mixin packages must not be
// loaded.
continue;
}
for (Path srcPath : srcPaths) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ private GitVersionInfo manualDescribe(Project project, Git git, Map<String, Stri
shortestVersion = version;
shortestCommit = commit;
} else if (commitCount == shortest) {
project.getLogger().warn("Potentially ambiguous version detection: The same amount of commits since " +
commit + "(version=" + version + ") as since " + shortestCommit + " (version=" + shortestVersion + ")");
project.getLogger().warn("Potentially ambiguous version detection: The same amount of commits since " + commit + "(version=" + version
+ ") as since " + shortestCommit + " (version=" + shortestVersion + ")");
}
revWalk.close();
}
Expand Down Expand Up @@ -118,11 +118,7 @@ private String getGitBranch(Git git) throws IOException {
if (branch.equals("HEAD")) {
branch = firstNonEmpty(
() -> new RuntimeException("Found HEAD branch! This is most likely caused by detached head state! Will assume unknown version!"),
System.getenv("TRAVIS_BRANCH"),
System.getenv("GIT_BRANCH"),
System.getenv("BRANCH_NAME"),
System.getenv("GITHUB_HEAD_REF")
);
System.getenv("TRAVIS_BRANCH"), System.getenv("GIT_BRANCH"), System.getenv("BRANCH_NAME"), System.getenv("GITHUB_HEAD_REF"));
}

if (branch.startsWith("origin/")) {
Expand All @@ -131,22 +127,20 @@ private String getGitBranch(Git git) throws IOException {
return branch;
}


private String getModVersion(Project target, McGitVersionExtension extension, GitVersionInfo describe, String branch, boolean mvn) {
String mcVersion = getMcVersion(extension);
if (branch.startsWith("MC_")) {
String branchMcVersion = branch.substring("MC_".length());
if (!mcVersion.startsWith(branchMcVersion)) {
target.getLogger().warn("Branch version different than project MC version! MC version: " +
mcVersion + ", branch: " + branch + ", branch version: " + branchMcVersion);
target.getLogger().warn("Branch version different than project MC version! MC version: " + mcVersion + ", branch: " + branch
+ ", branch version: " + branchMcVersion);
}
}

//branches "master" and "MC_something" are not appended to version string, everything else is
//only builds from "master" and "MC_version" branches will actually use the correct versioning
//but it allows to distinguish between builds from different branches even if version number is the same
String branchSuffix = (branch.equals("master") || branch.startsWith("MC_")) ? "" :
("-" + branch.replaceAll("[^a-zA-Z0-9.-]", "_"));
// branches "master" and "MC_something" are not appended to version string, everything else is
// only builds from "master" and "MC_version" branches will actually use the correct versioning
// but it allows to distinguish between builds from different branches even if version number is the same
String branchSuffix = (branch.equals("master") || branch.startsWith("MC_")) ? "" : ("-" + branch.replaceAll("[^a-zA-Z0-9.-]", "_"));
String versionSuffix = extension.getVersionSuffix();
String modAndApiVersion = describe.baseVersion;

Expand Down Expand Up @@ -200,4 +194,4 @@ public GitVersionInfo(String baseVersion, int commitsSinceBase) {
this.commitsSinceBase = commitsSinceBase;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ public void setForceVersionString(String forceVersionString) {
this.configured = true;
this.forceVersionString = forceVersionString;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ public class MixinAutoGen implements Plugin<Project> {
}
});
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.github.opencubicchunks.gradle;


import static java.nio.file.StandardOpenOption.CREATE;
import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING;
import static org.apache.tools.ant.util.StringUtils.removePrefix;
Expand Down Expand Up @@ -28,7 +27,8 @@
import org.gradle.api.tasks.SourceSet;

// Note: this intentionally only contains the parts that I actually use
@SuppressWarnings("unused") public class MixinGenExtension {
@SuppressWarnings("unused")
public class MixinGenExtension {

private final Map<SourceSet, Map<String, Action<MixinConfig>>> configsBySourceSet = new HashMap<>();

Expand All @@ -39,8 +39,7 @@
private String defaultCompatibilityLevel;
private String defaultMinVersion;

MixinGenExtension() {
}
MixinGenExtension() {}

public void setFilePattern(String pattern) {
this.filePattern = pattern;
Expand Down Expand Up @@ -253,7 +252,8 @@ void generateFiles(JavaPluginConvention convention) throws IOException {
});
}

private void writeMixins(JavaPluginConvention convention, SourceSet sourceSet, String name, MixinConfig config, JsonWriter writer) throws IOException {
private void writeMixins(JavaPluginConvention convention, SourceSet sourceSet, String name, MixinConfig config, JsonWriter writer)
throws IOException {
Set<Path> classes = getMixinClasses(config, sourceSet.getAllJava());

Set<Path> commonSet = new HashSet<>();
Expand All @@ -272,12 +272,14 @@ private void writeMixins(JavaPluginConvention convention, SourceSet sourceSet, S
commonSet.add(relative);
}
}
Function<Path, String> transform = path ->
removeSuffix(removePrefix(path.toString().replace(File.separatorChar, '.'), name + "."), ".java");
Function<Path, String> transform = path -> removeSuffix(removePrefix(path.toString().replace(File.separatorChar, '.'), name + "."), ".java");

List<String> common = commonSet.stream().map(transform).sorted(Comparator.comparing(a -> a.toLowerCase(Locale.ROOT))).collect(Collectors.toList());
List<String> client = clientSet.stream().map(transform).sorted(Comparator.comparing(a -> a.toLowerCase(Locale.ROOT))).collect(Collectors.toList());
List<String> server = serverSet.stream().map(transform).sorted(Comparator.comparing(a -> a.toLowerCase(Locale.ROOT))).collect(Collectors.toList());
List<String> common = commonSet.stream().map(transform).sorted(Comparator.comparing(a -> a.toLowerCase(Locale.ROOT)))
.collect(Collectors.toList());
List<String> client = clientSet.stream().map(transform).sorted(Comparator.comparing(a -> a.toLowerCase(Locale.ROOT)))
.collect(Collectors.toList());
List<String> server = serverSet.stream().map(transform).sorted(Comparator.comparing(a -> a.toLowerCase(Locale.ROOT)))
.collect(Collectors.toList());

writer.name("mixins").beginArray();
for (String path : common) {
Expand Down Expand Up @@ -323,4 +325,4 @@ private Set<Path> getMixinClasses(MixinConfig config, SourceDirectorySet allJava
}
return classes;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

public class Utils {

@Nonnull public static JavaPluginConvention getJavaPluginConvention(@Nonnull Project target) {
@Nonnull
public static JavaPluginConvention getJavaPluginConvention(@Nonnull Project target) {
JavaPluginConvention convention = target.getConvention().findByType(JavaPluginConvention.class);
if (convention == null) {
convention = target.getConvention().findPlugin(JavaPluginConvention.class);
Expand All @@ -17,4 +18,4 @@ public class Utils {
}
return convention;
}
}
}
Loading