Skip to content

Commit c7f340d

Browse files
committed
Add neoforge implementation
1 parent 3f82a82 commit c7f340d

File tree

13 files changed

+988
-0
lines changed

13 files changed

+988
-0
lines changed

build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11

22
tasks.register("clean") {
33
gradle.includedBuilds.forEach {
4+
// workaround for https://github.com/neoforged/NeoGradle/issues/18
5+
if (it.name == "neoforge-1.20.2") return@forEach
6+
47
dependsOn(it.task(":clean"))
58
}
69

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
plugins {
2+
id "java"
3+
id "java-library"
4+
id "net.neoforged.gradle.userdev" version '7.0.57'
5+
id "com.diffplug.spotless" version "6.1.2"
6+
id "com.github.node-gradle.node" version "3.0.1"
7+
id "com.modrinth.minotaur" version "2.+"
8+
id "com.matthewprenger.cursegradle" version "1.4.0"
9+
id "com.github.johnrengelman.shadow" version "7.1.2"
10+
}
11+
12+
group = "de.bluecolored.bluemap.forge"
13+
version = System.getProperty("bluemap.version") ?: "?" // set by BlueMapCore
14+
15+
repositories {
16+
mavenLocal()
17+
mavenCentral()
18+
maven {
19+
setUrl("https://libraries.minecraft.net")
20+
}
21+
maven {
22+
setUrl("https://jitpack.io")
23+
}
24+
}
25+
26+
base {
27+
archivesName = "bluemap"
28+
}
29+
30+
java.toolchain.languageVersion = JavaLanguageVersion.of(17)
31+
sourceSets.main.resources { srcDir 'src/generated/resources' }
32+
33+
configurations {
34+
implementation.extendsFrom(shadowInclude)
35+
}
36+
37+
dependencies {
38+
implementation "net.neoforged:neoforge:20.2.86"
39+
40+
shadowInclude ("de.bluecolored.bluemap.common:BlueMapCommon") {
41+
//exclude dependencies provided by forge
42+
exclude (group: "com.google.guava", module: "guava")
43+
exclude (group: "com.google.code.gson", module: "gson")
44+
exclude (group: "org.apache.commons", module: "commons-lang3")
45+
exclude (group: "commons-io", module: "commons-io")
46+
exclude (group: "com.mojang", module: "brigadier")
47+
}
48+
49+
testImplementation ("org.junit.jupiter:junit-jupiter:5.8.2")
50+
testRuntimeOnly ("org.junit.jupiter:junit-jupiter-engine:5.8.2")
51+
}
52+
53+
tasks.withType(ProcessResources).configureEach {
54+
var replaceProperties = [
55+
minecraft_version: minecraft_version,
56+
minecraft_version_range: minecraft_version_range,
57+
neo_version: neo_version,
58+
neo_version_range: neo_version_range,
59+
loader_version_range: loader_version_range,
60+
mod_id: mod_id,
61+
mod_name: mod_name,
62+
mod_license: mod_license,
63+
mod_version: version,
64+
mod_description: mod_description,
65+
pack_format_number: pack_format_number,
66+
]
67+
inputs.properties replaceProperties
68+
69+
filesMatching(['META-INF/mods.toml', 'pack.mcmeta']) {
70+
expand replaceProperties + [project: project]
71+
}
72+
}
73+
74+
tasks.withType(JavaCompile).configureEach {
75+
options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation
76+
}
77+
78+
tasks.withType(AbstractArchiveTask).configureEach {
79+
setReproducibleFileOrder(true)
80+
setPreserveFileTimestamps(false)
81+
}
82+
83+
spotless {
84+
java {
85+
target ("src/*/java/**/*.java")
86+
87+
licenseHeaderFile("../../HEADER")
88+
indentWithSpaces()
89+
trimTrailingWhitespace()
90+
}
91+
}
92+
93+
test {
94+
useJUnitPlatform()
95+
}
96+
97+
shadowJar {
98+
destinationDirectory.set(file("../../build/release"))
99+
archiveFileName.set("BlueMap-${project.version}-${project.name}.jar")
100+
101+
configurations = [project.configurations.shadowInclude]
102+
103+
//relocate ("com.flowpowered.math", "de.bluecolored.shadow.flowpowered.math") //DON"T relocate this, because the API depends on it
104+
relocate ("com.typesafe.config", "de.bluecolored.shadow.typesafe.config")
105+
relocate ("net.querz.nbt", "de.bluecolored.shadow.querz.nbt")
106+
relocate ("org.spongepowered.configurate", "de.bluecolored.shadow.configurate")
107+
relocate ("com.github.benmanes.caffeine", "de.bluecolored.shadow.benmanes.caffeine")
108+
relocate ("org.aopalliance", "de.bluecolored.shadow.aopalliance")
109+
relocate ("javax.inject", "de.bluecolored.shadow.javax.inject")
110+
relocate ("org.checkerframework", "de.bluecolored.shadow.checkerframework")
111+
relocate ("org.codehaus", "de.bluecolored.shadow.codehaus")
112+
relocate ("io.leangen.geantyref", "de.bluecolored.shadow.geantyref")
113+
relocate ("io.airlift", "de.bluecolored.shadow.airlift")
114+
115+
relocate ("com.google.errorprone", "de.bluecolored.shadow.google.errorprone")
116+
relocate ("com.google.inject", "de.bluecolored.shadow.google.inject")
117+
118+
relocate ("org.apache.commons.dbcp2", "de.bluecolored.shadow.apache.commons.dbcp2")
119+
relocate ("org.apache.commons.logging", "de.bluecolored.shadow.apache.commons.logging")
120+
relocate ("org.apache.commons.pool2", "de.bluecolored.shadow.apache.commons.pool2")
121+
}
122+
123+
task release {
124+
dependsOn(shadowJar)
125+
}
126+
127+
modrinth {
128+
token = System.getenv("MODRINTH_TOKEN")
129+
projectId = "swbUV1cr"
130+
versionNumber = "${project.version}-${project.name}"
131+
changelog = file("../../release.md")
132+
.getText()
133+
.replace("{version}", project.version.toString())
134+
uploadFile = shadowJar
135+
loaders = ["neoforge"]
136+
gameVersions = ["1.20.2", "1.20.3"]
137+
}
138+
139+
curseforge {
140+
apiKey = System.getenv("CURSEFORGE_TOKEN") ?: ""
141+
project {
142+
id = "406463"
143+
changelogType = "markdown"
144+
changelog = file("../../release.md")
145+
.getText()
146+
.replace("{version}", project.version.toString())
147+
releaseType = "release"
148+
149+
addGameVersion "NeoForge"
150+
151+
addGameVersion "Java 18"
152+
addGameVersion "Java 17"
153+
154+
addGameVersion "1.20.2"
155+
addGameVersion "1.20.3"
156+
157+
mainArtifact shadowJar
158+
}
159+
options {
160+
javaVersionAutoDetect = false
161+
javaIntegration = false
162+
forgeGradleIntegration = false
163+
}
164+
}
165+
166+
task publish {
167+
dependsOn(tasks.findByName("modrinth"))
168+
dependsOn(tasks.findByName("curseforge"))
169+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
org.gradle.daemon=false
2+
org.gradle.debug=false
3+
4+
minecraft_version=1.20.2
5+
minecraft_version_range=[1.20.2,1.21)
6+
neo_version=20.2.86
7+
neo_version_range=[20.2,)
8+
loader_version_range=[1,)
9+
mapping_channel=official
10+
mapping_version=1.20.2
11+
12+
mod_id=bluemap
13+
mod_name=BlueMap
14+
mod_description=A 3d-map of your Minecraft worlds view-able in your browser using three.js (WebGL)
15+
mod_license=MIT
16+
pack_format_number=18
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
pluginManagement {
2+
repositories {
3+
mavenLocal()
4+
gradlePluginPortal()
5+
maven { url = 'https://maven.neoforged.net/releases' }
6+
}
7+
}
8+
9+
plugins {
10+
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.5.0'
11+
}
12+
13+
rootProject.name = "neoforge-1.20.2"
14+
15+
includeBuild("../../BlueMapCommon")
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* This file is part of BlueMap, licensed under the MIT License (MIT).
3+
*
4+
* Copyright (c) Blue (Lukas Rieger) <https://bluecolored.de>
5+
* Copyright (c) contributors
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
package de.bluecolored.bluemap.forge;
26+
27+
import com.flowpowered.math.vector.Vector3d;
28+
import de.bluecolored.bluemap.common.plugin.Plugin;
29+
import de.bluecolored.bluemap.common.plugin.text.Text;
30+
import de.bluecolored.bluemap.common.serverinterface.CommandSource;
31+
import de.bluecolored.bluemap.core.world.World;
32+
import net.minecraft.commands.CommandSourceStack;
33+
import net.minecraft.network.chat.Component;
34+
35+
import java.io.IOException;
36+
import java.util.Optional;
37+
38+
public class ForgeCommandSource implements CommandSource {
39+
40+
private final ForgeMod mod;
41+
private final Plugin plugin;
42+
private final CommandSourceStack delegate;
43+
44+
public ForgeCommandSource(ForgeMod mod, Plugin plugin, CommandSourceStack delegate) {
45+
this.mod = mod;
46+
this.plugin = plugin;
47+
this.delegate = delegate;
48+
}
49+
50+
@Override
51+
public void sendMessage(Text text) {
52+
var component = Component.Serializer.fromJsonLenient(text.toJSONString());
53+
if (component != null)
54+
delegate.sendSuccess(() -> component, false);
55+
}
56+
57+
@Override
58+
public boolean hasPermission(String permission) {
59+
return delegate.hasPermission(1);
60+
}
61+
62+
@Override
63+
public Optional<Vector3d> getPosition() {
64+
var pos = delegate.getPosition();
65+
return Optional.of(new Vector3d(pos.x, pos.y, pos.z));
66+
}
67+
68+
@Override
69+
public Optional<World> getWorld() {
70+
try {
71+
var serverWorld = mod.getWorld(delegate.getLevel());
72+
String worldId = plugin.getBlueMap().getWorldId(serverWorld.getSaveFolder());
73+
return Optional.ofNullable(plugin.getWorlds().get(worldId));
74+
} catch (IOException ignore) {}
75+
76+
return Optional.empty();
77+
}
78+
79+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* This file is part of BlueMap, licensed under the MIT License (MIT).
3+
*
4+
* Copyright (c) Blue (Lukas Rieger) <https://bluecolored.de>
5+
* Copyright (c) contributors
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
package de.bluecolored.bluemap.forge;
26+
27+
import de.bluecolored.bluemap.common.serverinterface.ServerEventListener;
28+
import net.neoforged.bus.api.SubscribeEvent;
29+
import net.neoforged.neoforge.common.NeoForge;
30+
import net.neoforged.neoforge.event.entity.player.PlayerEvent;
31+
32+
import java.util.ArrayList;
33+
import java.util.Collection;
34+
import java.util.UUID;
35+
36+
public class ForgeEventForwarder {
37+
38+
private final Collection<ServerEventListener> eventListeners;
39+
40+
public ForgeEventForwarder() {
41+
this.eventListeners = new ArrayList<>(1);
42+
43+
NeoForge.EVENT_BUS.register(this);
44+
}
45+
46+
public synchronized void addEventListener(ServerEventListener listener) {
47+
this.eventListeners.add(listener);
48+
}
49+
50+
public synchronized void removeAllListeners() {
51+
this.eventListeners.clear();
52+
}
53+
54+
@SubscribeEvent
55+
public synchronized void onPlayerJoin(PlayerEvent.PlayerLoggedInEvent evt) {
56+
UUID uuid = evt.getEntity().getUUID();
57+
for (ServerEventListener listener : eventListeners) listener.onPlayerJoin(uuid);
58+
}
59+
60+
@SubscribeEvent
61+
public synchronized void onPlayerLeave(PlayerEvent.PlayerLoggedOutEvent evt) {
62+
UUID uuid = evt.getEntity().getUUID();
63+
for (ServerEventListener listener : eventListeners) listener.onPlayerLeave(uuid);
64+
}
65+
66+
}

0 commit comments

Comments
 (0)