Skip to content

Commit

Permalink
Add implementations for the newest fabric/forge/neoforge versions
Browse files Browse the repository at this point in the history
  • Loading branch information
TBlueF committed Jun 3, 2024
1 parent 75b562e commit 2dfd9fe
Show file tree
Hide file tree
Showing 45 changed files with 1,990 additions and 58 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
java-version: |
16
17
21
cache: 'gradle'
- name: Build with Gradle
run: ./gradlew clean spotlessCheck test build
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
java-version: |
16
17
21
cache: 'gradle'
- name: Build with Gradle
run: ./gradlew clean :BlueMapCore:publish :BlueMapCommon:publish
Expand Down
2 changes: 1 addition & 1 deletion implementations/cli/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
`java-library`
id("com.diffplug.spotless") version "6.1.2"
id ("com.github.node-gradle.node") version "3.0.1"
id ("com.github.johnrengelman.shadow") version "7.1.2"
id ("com.github.johnrengelman.shadow") version "8.1.1"
}

group = "de.bluecolored.bluemap"
Expand Down
2 changes: 1 addition & 1 deletion implementations/fabric-1.18/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
`java-library`
id("com.diffplug.spotless") version "6.1.2"
id ("com.github.node-gradle.node") version "3.0.1"
id ("com.github.johnrengelman.shadow") version "7.1.2"
id ("com.github.johnrengelman.shadow") version "8.1.1"
id ("fabric-loom") version "1.3-SNAPSHOT"
id ("com.modrinth.minotaur") version "2.+"
id ("com.matthewprenger.cursegradle") version "1.4.0"
Expand Down
2 changes: 1 addition & 1 deletion implementations/fabric-1.19.4/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
`java-library`
id("com.diffplug.spotless") version "6.1.2"
id ("com.github.node-gradle.node") version "3.0.1"
id ("com.github.johnrengelman.shadow") version "7.1.2"
id ("com.github.johnrengelman.shadow") version "8.1.1"
id ("fabric-loom") version "1.3-SNAPSHOT"
id ("com.modrinth.minotaur") version "2.+"
id ("com.matthewprenger.cursegradle") version "1.4.0"
Expand Down
2 changes: 1 addition & 1 deletion implementations/fabric-1.20/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
`java-library`
id("com.diffplug.spotless") version "6.1.2"
id ("com.github.node-gradle.node") version "3.0.1"
id ("com.github.johnrengelman.shadow") version "7.1.2"
id ("com.github.johnrengelman.shadow") version "8.1.1"
id ("fabric-loom") version "1.5-SNAPSHOT"
id ("com.modrinth.minotaur") version "2.+"
id ("com.matthewprenger.cursegradle") version "1.4.0"
Expand Down
177 changes: 177 additions & 0 deletions implementations/fabric/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
import com.matthewprenger.cursegradle.CurseArtifact
import com.matthewprenger.cursegradle.CurseProject
import com.matthewprenger.cursegradle.CurseRelation
import com.matthewprenger.cursegradle.Options
import net.fabricmc.loom.task.RemapJarTask

plugins {
java
`java-library`
id("com.diffplug.spotless") version "6.1.2"
id ("com.github.node-gradle.node") version "3.0.1"
id ("com.github.johnrengelman.shadow") version "8.1.1"
id ("fabric-loom") version "1.6-SNAPSHOT"
id ("com.modrinth.minotaur") version "2.+"
id ("com.matthewprenger.cursegradle") version "1.4.0"
}

group = "de.bluecolored.bluemap"
version = System.getProperty("bluemap.version") ?: "?" // set by BlueMapCore

val javaTarget = 21
java {
sourceCompatibility = JavaVersion.toVersion(javaTarget)
targetCompatibility = JavaVersion.toVersion(javaTarget)

withSourcesJar()
}

repositories {
mavenCentral()
maven ("https://libraries.minecraft.net")
maven ("https://maven.fabricmc.net/")
maven ("https://oss.sonatype.org/content/repositories/snapshots")
maven ("https://repo.bluecolored.de/releases")
}

val shadowInclude: Configuration by configurations.creating

configurations {
implementation.get().extendsFrom(shadowInclude)
}

dependencies {
shadowInclude ("de.bluecolored.bluemap:BlueMapCommon") {
//exclude dependencies provided by fabric
exclude (group = "com.google.guava", module = "guava")
exclude (group = "com.google.code.gson", module = "gson")
exclude (group = "com.mojang", module = "brigadier")
}

minecraft ("com.mojang:minecraft:1.20.5")
mappings ("net.fabricmc:yarn:1.20.5+build.1")
modImplementation ("net.fabricmc:fabric-loader:0.15.10")
modImplementation ("net.fabricmc.fabric-api:fabric-api:0.97.8+1.20.5")
modImplementation("me.lucko:fabric-permissions-api:0.1-SNAPSHOT")

testImplementation ("org.junit.jupiter:junit-jupiter:5.9.0")
testRuntimeOnly ("org.junit.jupiter:junit-jupiter-engine:5.9.0")
}

spotless {
java {
target ("src/*/java/**/*.java")

licenseHeaderFile("../../HEADER")
indentWithSpaces()
trimTrailingWhitespace()
}
}

tasks.withType(JavaCompile::class).configureEach {
options.apply {
encoding = "utf-8"
}
}

tasks.withType(AbstractArchiveTask::class).configureEach {
isReproducibleFileOrder = true
isPreserveFileTimestamps = false
}

tasks.test {
useJUnitPlatform()
}

tasks.processResources {
inputs.property ("version", project.version)

filesMatching("fabric.mod.json") {
expand ("version" to project.version)
}
}

tasks.shadowJar {
configurations = listOf(shadowInclude)

//relocate ("com.flowpowered.math", "de.bluecolored.shadow.flowpowered.math") //DON"T relocate this, because the API depends on it
relocate ("com.typesafe.config", "de.bluecolored.shadow.typesafe.config")
relocate ("de.bluecolored.bluenbt", "de.bluecolored.shadow.bluenbt")
relocate ("org.spongepowered.configurate", "de.bluecolored.shadow.configurate")
relocate ("com.github.benmanes.caffeine", "de.bluecolored.shadow.benmanes.caffeine")
relocate ("org.aopalliance", "de.bluecolored.shadow.aopalliance")
relocate ("javax.inject", "de.bluecolored.shadow.javax.inject")
relocate ("org.checkerframework", "de.bluecolored.shadow.checkerframework")
relocate ("org.codehaus", "de.bluecolored.shadow.codehaus")
relocate ("io.leangen.geantyref", "de.bluecolored.shadow.geantyref")
relocate ("io.airlift", "de.bluecolored.shadow.airlift")
relocate ("net.jpountz", "de.bluecolored.shadow.jpountz")

relocate ("com.google.errorprone", "de.bluecolored.shadow.google.errorprone")
relocate ("com.google.inject", "de.bluecolored.shadow.google.inject")

relocate ("org.apache.commons.dbcp2", "de.bluecolored.shadow.apache.commons.dbcp2")
relocate ("org.apache.commons.logging", "de.bluecolored.shadow.apache.commons.logging")
relocate ("org.apache.commons.pool2", "de.bluecolored.shadow.apache.commons.pool2")
}

tasks.register("remappedShadowJar", type = RemapJarTask::class) {
destinationDirectory.set(file("../../build/release"))
archiveFileName.set("BlueMap-${project.version}-${project.name}.jar")
dependsOn (tasks.shadowJar)
inputFile.set(tasks.shadowJar.get().archiveFile)
addNestedDependencies.set(true)
}

tasks.register("release") {
dependsOn("remappedShadowJar")
}

modrinth {
token.set(System.getenv("MODRINTH_TOKEN"))
projectId.set("swbUV1cr")
versionNumber.set("${project.version}-${project.name}")
changelog.set(file("../../release.md")
.readText()
.replace("{version}", project.version.toString()))
uploadFile.set(tasks.findByName("remappedShadowJar"))
gameVersions.addAll("1.20.5", "1.20.6")
dependencies {
required.project("P7dR8mSH") // Fabric API
}
}

curseforge {
apiKey = System.getenv("CURSEFORGE_TOKEN") ?: ""
project(closureOf<CurseProject> {
id = "406463"
changelogType = "markdown"
changelog = file("../../release.md")
.readText()
.replace("{version}", project.version.toString())
releaseType = "release"

addGameVersion("Fabric")

addGameVersion("Java 21")

addGameVersion("1.20.5")
addGameVersion("1.20.6")

mainArtifact(tasks.findByName("remappedShadowJar"), closureOf<CurseArtifact> {
relations(closureOf<CurseRelation> {
requiredDependency("fabric-api")
})
})
})
options(closureOf<Options> {
javaVersionAutoDetect = false
javaIntegration = false
forgeGradleIntegration = false
})
}

tasks.register("publish") {
dependsOn("modrinth")
dependsOn("curseforge")
}
13 changes: 13 additions & 0 deletions implementations/fabric/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
pluginManagement {
repositories {
maven {
name = "Fabric"
url = uri("https://maven.fabricmc.net/")
}
gradlePluginPortal()
}
}

rootProject.name = "fabric"

includeBuild("../../BlueMapCommon")
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* This file is part of BlueMap, licensed under the MIT License (MIT).
*
* Copyright (c) Blue (Lukas Rieger) <https://bluecolored.de>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package de.bluecolored.bluemap.fabric;

import com.flowpowered.math.vector.Vector3d;
import de.bluecolored.bluemap.common.plugin.Plugin;
import de.bluecolored.bluemap.common.plugin.text.Text;
import de.bluecolored.bluemap.common.serverinterface.CommandSource;
import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
import de.bluecolored.bluemap.core.world.World;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.minecraft.registry.BuiltinRegistries;
import net.minecraft.registry.RegistryWrapper;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.util.math.Vec3d;

import java.util.Optional;

public class FabricCommandSource implements CommandSource {

private static final RegistryWrapper.WrapperLookup lookup = BuiltinRegistries.createWrapperLookup();

private final FabricMod mod;
private final Plugin plugin;
private final ServerCommandSource delegate;

public FabricCommandSource(FabricMod mod, Plugin plugin, ServerCommandSource delegate) {
this.mod = mod;
this.plugin = plugin;
this.delegate = delegate;
}

@Override
public void sendMessage(Text text) {
delegate.sendFeedback(
() -> net.minecraft.text.Text.Serialization
.fromJson(text.toJSONString(), lookup),
false
);
}

@Override
public boolean hasPermission(String permission) {
try {
Class.forName("me.lucko.fabric.api.permissions.v0.Permissions");
return Permissions.check(delegate, permission, 1);
} catch (ClassNotFoundException ex) {
return delegate.hasPermissionLevel(1);
}
}

@Override
public Optional<Vector3d> getPosition() {
Vec3d pos = delegate.getPosition();
if (pos != null) {
return Optional.of(new Vector3d(pos.x, pos.y, pos.z));
}

return Optional.empty();
}

@Override
public Optional<World> getWorld() {
ServerWorld serverWorld = mod.getServerWorld(delegate.getWorld());
return Optional.ofNullable(plugin.getWorld(serverWorld));
}

}
Loading

0 comments on commit 2dfd9fe

Please sign in to comment.