Skip to content

Commit

Permalink
Merge branch 'refs/heads/beta' into fork/catgirlseraid/item-pickup-lo…
Browse files Browse the repository at this point in the history
…g-v2

# Conflicts:
#	src/main/java/at/hannibal2/skyhanni/features/inventory/ItemPickupLog.kt
  • Loading branch information
CalMWolfs committed Nov 12, 2024
2 parents 9cc33bd + 2049030 commit b28837a
Show file tree
Hide file tree
Showing 317 changed files with 4,274 additions and 2,905 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ jobs:
preprocess:
runs-on: ubuntu-latest
name: "Build multi version"
env:
SKIP_DETEKT: "true"
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -51,4 +49,4 @@ jobs:
mkdir -p .gradle
echo skyhanni.multi-version=preprocess-only > .gradle/private.properties
- name: Build with Gradle
run: ./gradlew build --stacktrace
run: ./gradlew build --stacktrace -PskipDetekt=true
17 changes: 16 additions & 1 deletion .github/workflows/detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
outputs:
sarif_exists: ${{ steps.check_sarif.outputs.exists }}
steps:
Expand All @@ -37,13 +38,27 @@ jobs:
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Add label if detekt fails
if: failure()
uses: actions-ecosystem/action-add-labels@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
labels: 'Detekt'
- name: Remove label if detekt passes
if: success()
uses: actions-ecosystem/action-remove-labels@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
labels: 'Detekt'

- name: Annotate detekt failures
if: ${{ !cancelled() && steps.check_sarif.outputs.exists == 'true' }}
run: |
chmod +x .github/scripts/process_detekt_sarif.sh
./.github/scripts/process_detekt_sarif.sh versions/1.8.9/build/reports/detekt/main.sarif | tee detekt_output.txt
- name: Upload detekt output as artifact
if: ${{ steps.check_sarif.outputs.exists == 'true' }}
if: ${{ !cancelled() && steps.check_sarif.outputs.exists == 'true' }}
uses: actions/upload-artifact@v4
with:
name: detekt-output
Expand Down
4 changes: 3 additions & 1 deletion .idea/dictionaries/default_user.xml

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

65 changes: 39 additions & 26 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ out [their guide](https://github.com/NotEnoughUpdates/NotEnoughUpdates/blob/mast

If you are not very familiar with git, you might want to try this out: https://learngitbranching.js.org/.

Proposed changes are better off being in their own branch, you can do this by doing the following from within IntelliJ with the SkyHanni project already open.
Proposed changes are better off being in their own branch as this makes development easier for both you and the maintainers of this repository, you can do this by following the instructions from within the IntelliJ window with the SkyHanni project already open.
- Click the beta dropdown at the top of IntelliJ
- Click new branch
- Give the branch a name relating to the changes you plan to make
Expand Down Expand Up @@ -153,6 +153,37 @@ for more information and usages.
- When updating a config option variable, use the `ConfigUpdaterMigrator.ConfigFixEvent` with event.move() when moving a value, and event.transform() when updating a value. [For Example](https://github.com/hannibal002/SkyHanni/blob/e88f416c48f9659f89b7047d7629cd9a1d1535bc/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/CustomScoreboard.kt#L276).
- Use American English spelling conventions (e.g., "color" not "colour").

## Additional Useful Development Tools

### DevAuth

[DevAuth](https://github.com/DJtheRedstoner/DevAuth) is a tool that allows logging in to a Minecraft account while
debugging in IntelliJ. This is very useful for coding live on Hypixel without the need to compile a jar.

- The library is already downloaded by Gradle.
- SkyHanni will automatically set up DevAuth.
- Start Minecraft inside IntelliJ normally.
- Click on the link in the console and verify with a Microsoft account.
- The verification process will reappear every few days (after the session token expires).

### Hot Swap

Hot Swap allows reloading edited code while debugging, removing the need to restart the whole game every time.

We use [dcevm](https://dcevm.github.io/) and the IntelliJ
Plugin [HotSwap Agent](https://plugins.jetbrains.com/plugin/9552-hotswapagent) to quickly reload code changes.

Follow [this](https://forums.Minecraftforge.net/topic/82228-1152-3110-intellij-and-gradlew-forge-hotswap-and-dcevm-tutorial/)
tutorial.

### [Live Plugin](https://plugins.jetbrains.com/plugin/7282-liveplugin)

Allows project specific plugins to run. Eg: Regex Intention

### [Live Templates Sharing](https://plugins.jetbrains.com/plugin/25007-live-templates-sharing)

Imports our custom live templates automatically. Live Templates allow for quicker code writing.

## Software Used in SkyHanni

### Basics
Expand Down Expand Up @@ -218,29 +249,6 @@ For info on usage, look at [DiscordRPCManager.kt](https://github.com/hannibal002

We use the [auto update library](https://github.com/nea89o/libautoupdate) from nea89.

## Additional Useful Development Tools

### DevAuth

[DevAuth](https://github.com/DJtheRedstoner/DevAuth) is a tool that allows logging in to a Minecraft account while
debugging in IntelliJ. This is very useful for coding live on Hypixel without the need to compile a jar.

- The library is already downloaded by Gradle.
- SkyHanni will automatically set up DevAuth.
- Start Minecraft inside IntelliJ normally.
- Click on the link in the console and verify with a Microsoft account.
- The verification process will reappear every few days (after the session token expires).

### Hot Swap

Hot Swap allows reloading edited code while debugging, removing the need to restart the whole game every time.

We use [dcevm](https://dcevm.github.io/) and the IntelliJ
Plugin [HotSwap Agent](https://plugins.jetbrains.com/plugin/9552-hotswapagent) to quickly reload code changes.

Follow [this](https://forums.Minecraftforge.net/topic/82228-1152-3110-intellij-and-gradlew-forge-hotswap-and-dcevm-tutorial/)
tutorial.

## 1.21 / Modern version development

You might have noticed that while the SkyHanni source code is found in `src/`, the actual tasks for compiling, building and running the mod
Expand Down Expand Up @@ -281,7 +289,7 @@ specifically compile 1.8.9 using `./gradlew :1.8.9:build`. This does not affect

`compile` enables compilation for the `:1.21` subproject. This means that a `build` or `assemble` task will try (and fail) to compile a
1.21 (as well as 1.8.9) JAR. This mode may be useful for someone seeking out issues to fix, but is generally not useful in day to day
operations since the compile will never succeed and will block things like hotswap compilations (via <kbd>CTRL+F9</kbd>) from completing.
operations since the compile task will never succeed and will block things like hotswap compilations (via <kbd>CTRL+F9</kbd>) from completing.

### Improving mappings

Expand Down Expand Up @@ -408,7 +416,7 @@ Let's look at the syntax of those `#if` expressions.

First of all, the `#else` block is optional. If you just want code on some versions (for example for adding a method call that is implicitly
done on newer versions, or simply because the corresponding code for newer versions has to be done in some other place), you can just omit
the `#else` section and you will simply not compile any code at that spot.
the `#else` section, and you will simply not compile any code at that spot.

There is also an `#elseif` in case you want to switch behaviour based on multiple version brackets. Again, while we don't actually target
1.12 or 1.16, making those versions compile will help other parts of the code to upgrade to 1.21 more cleanly and easily. So, making those
Expand All @@ -431,3 +439,8 @@ for the variable using `#if FORGE`.
Sadly, `#if` expressions cannot be applied globally (unlike name changes), so it is often very helpful to create a helper method and call
that method from various places in the codebase. This is generally already policy in SH for a lot of things. For more complex types that
change beyond just their name (for example different generics), a `typealias` can be used in combination with `#if` expressions.

These helper methods should generally be placed in the `at.hannibal2.skyhanni.utils.compat` package and should be named after what they are
compatability methods for. For example, `WorldClient.getAllEntities()` could be placed in `WorldCompat.kt`. This is not a strict rule, but
it is a good guideline to follow as for the most part we do not want to be doing large amount of preprocessing in the feature files
themselves.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ class ModuleProcessor(private val codeGenerator: CodeGenerator, private val logg
return annotation.arguments.find { it.name?.asString() == "devOnly" }?.value as? Boolean ?: false
}

private fun isNEUAnnotation(klass: KSClassDeclaration): Boolean {
val annotation = klass.annotations.find { it.shortName.asString() == "SkyHanniModule" } ?: return false
return annotation.arguments.find { it.name?.asString() == "neuRequired" }?.value as? Boolean ?: false
}

// TODO use Kotlin Poet once KMixins is merged
private fun generateFile(symbols: List<KSClassDeclaration>) {

Expand All @@ -101,11 +106,14 @@ class ModuleProcessor(private val codeGenerator: CodeGenerator, private val logg
it.write("package at.hannibal2.skyhanni.skyhannimodule\n\n")
it.write("object LoadedModules {\n")
it.write(" val isDev: Boolean = at.hannibal2.skyhanni.utils.system.PlatformUtils.isDevEnvironment\n")
it.write(" val hasNeu: Boolean get() = at.hannibal2.skyhanni.utils.system.PlatformUtils.isNeuLoaded()\n")
it.write(" val modules: List<Any> = buildList {\n")

symbols.forEach { symbol ->
if (isDevAnnotation(symbol)) {
it.write(" if (isDev) add(${symbol.qualifiedName!!.asString()})\n")
} else if (isNEUAnnotation(symbol)) {
it.write(" if (hasNeu) add(${symbol.qualifiedName!!.asString()})\n")
} else {
it.write(" add(${symbol.qualifiedName!!.asString()})\n")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ annotation class SkyHanniModule(
* If the module will only be loaded in a development environment.
*/
val devOnly: Boolean = false,
/**
* If the module will only be loaded while neu is installed
*/
val neuRequired: Boolean = false,
)
49 changes: 30 additions & 19 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import skyhannibuildsystem.ChangelogVerification
import skyhannibuildsystem.DownloadBackupRepo
import java.io.Serializable
import java.nio.file.Path
import java.util.zip.ZipFile
import java.util.zip.ZipOutputStream
import kotlin.io.path.moveTo
Expand All @@ -23,7 +25,7 @@ import kotlin.io.path.outputStream
plugins {
idea
java
id("com.github.johnrengelman.shadow") version "7.1.2"
id("com.gradleup.shadow") version "8.3.4"
id("gg.essential.loom")
id("dev.deftu.gradle.preprocess")
kotlin("jvm")
Expand Down Expand Up @@ -275,6 +277,21 @@ if (target == ProjectTarget.MAIN) {
}
}

fun includeBuildPaths(buildPathsFile: File, sourceSet: Provider<SourceSet>) {
if (buildPathsFile.exists()) {
sourceSet.get().apply {
val buildPaths = buildPathsFile.readText().lineSequence()
.map { it.substringBefore("#").trim() }
.filter { it.isNotBlank() }
.toSet()
kotlin.include(buildPaths)
java.include(buildPaths)
}
}
}
includeBuildPaths(file("buildpaths.txt"), sourceSets.main)
includeBuildPaths(file("buildpaths-test.txt"), sourceSets.test)

tasks.withType<KotlinCompile> {
compilerOptions.jvmTarget.set(JvmTarget.fromTarget(target.minecraftVersion.formattedJavaLanguageVersion))
}
Expand Down Expand Up @@ -404,8 +421,10 @@ detekt {

tasks.withType<Detekt>().configureEach {
onlyIf {
target == ProjectTarget.MAIN && System.getenv("SKIP_DETEKT") != "true"
target == ProjectTarget.MAIN && project.findProperty("skipDetekt") != "true"
}
jvmTarget = target.minecraftVersion.formattedJavaLanguageVersion
outputs.cacheIf { false } // Custom rules won't work if cached

reports {
html.required.set(true) // observe findings in your browser with structure and code snippets
Expand All @@ -415,26 +434,18 @@ tasks.withType<Detekt>().configureEach {
}
}

tasks.withType<Detekt>().configureEach {
jvmTarget = target.minecraftVersion.formattedJavaLanguageVersion
outputs.cacheIf { false } // Custom rules won't work if cached
}
tasks.withType<DetektCreateBaselineTask>().configureEach {
jvmTarget = target.minecraftVersion.formattedJavaLanguageVersion
outputs.cacheIf { false } // Custom rules won't work if cached
}

abstract class ShotApplicationJarProcessor @Inject constructor(val shots: Shots) : MinecraftJarProcessor<MinecraftJarProcessor.Spec> {
private class EnsureCompile(shots: Shots) : ShotApplicationJarProcessor(shots)
override fun buildSpec(context: SpecContext?): MinecraftJarProcessor.Spec? {
return object : MinecraftJarProcessor.Spec {}
}
abstract class ShotApplicationJarProcessor @Inject constructor(private val shots: Shots) :
MinecraftJarProcessor<MinecraftJarProcessor.Spec>,
Serializable {

override fun processJar(
source: java.nio.file.Path,
spec: MinecraftJarProcessor.Spec,
context: ProcessorContext?
) {
override fun buildSpec(context: SpecContext?): MinecraftJarProcessor.Spec? = ShotSpec(shots)

override fun processJar(source: Path, spec: MinecraftJarProcessor.Spec?, context: ProcessorContext?) {
val dest = source.resolveSibling(source.fileName.toString() + "-temp-shot")
ZipFile(source.toFile()).use { input ->
ZipOutputStream(dest.outputStream()).use { output ->
Expand All @@ -444,7 +455,7 @@ abstract class ShotApplicationJarProcessor @Inject constructor(val shots: Shots)
dest.moveTo(source, overwrite = true)
}

override fun getName(): String {
return "Shots"
}
override fun getName(): String = "Shots"

private data class ShotSpec(val shots: Shots) : MinecraftJarProcessor.Spec, Serializable
}
Loading

0 comments on commit b28837a

Please sign in to comment.