diff --git a/BlueMapFabric/build.gradle b/BlueMapFabric/build.gradle new file mode 100644 index 00000000..1b3103df --- /dev/null +++ b/BlueMapFabric/build.gradle @@ -0,0 +1,54 @@ +plugins { + id 'fabric-loom' version '0.2.7-SNAPSHOT' +} + +configurations { + compile.extendsFrom include +} + +dependencies { + minecraft "com.mojang:minecraft:1.15.2" + mappings "net.fabricmc:yarn:1.15.2+build.15:v2" + modImplementation "net.fabricmc:fabric-loader:0.8.2+build.194" + modImplementation "net.fabricmc.fabric-api:fabric-api:0.5.1+build.294-1.15" + + include (project(':BlueMapCommon')) { + //exclude dependencies provided by fabric + exclude group: 'com.google.guava', module: 'guava' + exclude group: 'com.google.code.gson', module: 'gson' + exclude group: 'org.apache.commons', module: 'commons-lang3' + exclude group: 'commons-io', module: 'commons-io' + exclude group: 'com.mojang', module: 'brigadier' + } +} + +build.dependsOn shadowJar { + destinationDir = file '../build/unsupported' + archiveFileName = "BlueMap-${version}-fabric.jar" + + configurations = [project.configurations.include] + + //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 'net.querz.nbt', 'de.bluecolored.shadow.querz.nbt' + relocate 'ninja.leaping.configurate', 'de.bluecolored.shadow.ninja.leaping.configurate' + relocate 'org.yaml.snakeyaml', 'de.bluecolored.shadow.yaml.snakeyaml' +} + +processResources { + inputs.property "version", project.version + + from(sourceSets.main.resources.srcDirs) { + include "fabric.mod.json" + expand "version": project.version + } + + from(sourceSets.main.resources.srcDirs) { + exclude "fabric.mod.json" + } +} + +task sourcesJar(type: Jar, dependsOn: classes) { + classifier = "sources" + from sourceSets.main.allSource +} diff --git a/BlueMapFabric/src/main/java/de/bluecolored/bluemap/fabric/FabricCommandSource.java b/BlueMapFabric/src/main/java/de/bluecolored/bluemap/fabric/FabricCommandSource.java new file mode 100644 index 00000000..ed9b1542 --- /dev/null +++ b/BlueMapFabric/src/main/java/de/bluecolored/bluemap/fabric/FabricCommandSource.java @@ -0,0 +1,84 @@ +/* + * This file is part of BlueMap, licensed under the MIT License (MIT). + * + * Copyright (c) Blue (Lukas Rieger) + * 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 java.io.IOException; +import java.util.Optional; + +import com.flowpowered.math.vector.Vector3d; + +import de.bluecolored.bluemap.common.plugin.Plugin; +import de.bluecolored.bluemap.common.plugin.serverinterface.CommandSource; +import de.bluecolored.bluemap.common.plugin.text.Text; +import de.bluecolored.bluemap.core.world.World; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.math.Vec3d; + +public class FabricCommandSource implements CommandSource { + + private FabricMod mod; + private Plugin plugin; + private 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.Serializer.fromJson(text.toJSONString()), false); + } + + @Override + public boolean hasPermission(String permission) { + return delegate.hasPermissionLevel(1); + } + + @Override + public Optional 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 getWorld() { + try { + ServerWorld world = delegate.getWorld(); + if (world != null) { + return Optional.ofNullable(plugin.getWorld(mod.getUUIDForWorld(world))); + } + } catch (IOException ignore) {} + + return Optional.empty(); + } + +} diff --git a/BlueMapFabric/src/main/java/de/bluecolored/bluemap/fabric/FabricMod.java b/BlueMapFabric/src/main/java/de/bluecolored/bluemap/fabric/FabricMod.java new file mode 100644 index 00000000..2fb082c1 --- /dev/null +++ b/BlueMapFabric/src/main/java/de/bluecolored/bluemap/fabric/FabricMod.java @@ -0,0 +1,63 @@ +package de.bluecolored.bluemap.fabric; + +import java.io.File; +import java.io.IOException; +import java.util.UUID; + +import org.apache.logging.log4j.LogManager; + +import de.bluecolored.bluemap.common.plugin.Plugin; +import de.bluecolored.bluemap.common.plugin.commands.Commands; +import de.bluecolored.bluemap.common.plugin.serverinterface.ServerEventListener; +import de.bluecolored.bluemap.common.plugin.serverinterface.ServerInterface; +import de.bluecolored.bluemap.core.logger.Logger; +import net.fabricmc.api.ModInitializer; +import net.fabricmc.fabric.api.registry.CommandRegistry; +import net.minecraft.server.world.ServerWorld; + +public class FabricMod implements ModInitializer, ServerInterface { + + private Plugin plugin; + + @Override + public void onInitialize() { + Logger.global = new Log4jLogger(LogManager.getLogger(Plugin.PLUGIN_NAME)); + + this.plugin = new Plugin("forge", this); + + //register commands + CommandRegistry.INSTANCE.register(true, dispatcher -> { + new Commands<>(plugin, dispatcher, fabricSource -> new FabricCommandSource(this, plugin, fabricSource)); + }); + } + + public UUID getUUIDForWorld(ServerWorld world) throws IOException { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Not implemented!"); + } + + @Override + public void registerListener(ServerEventListener listener) { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Not implemented!"); + } + + @Override + public void unregisterAllListeners() { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Not implemented!"); + } + + @Override + public UUID getUUIDForWorld(File worldFolder) throws IOException { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Not implemented!"); + } + + @Override + public File getConfigFolder() { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Not implemented!"); + } + +} diff --git a/BlueMapFabric/src/main/java/de/bluecolored/bluemap/fabric/Log4jLogger.java b/BlueMapFabric/src/main/java/de/bluecolored/bluemap/fabric/Log4jLogger.java new file mode 100644 index 00000000..41206a3b --- /dev/null +++ b/BlueMapFabric/src/main/java/de/bluecolored/bluemap/fabric/Log4jLogger.java @@ -0,0 +1,69 @@ +/* + * This file is part of BlueMapSponge, licensed under the MIT License (MIT). + * + * Copyright (c) Blue (Lukas Rieger) + * 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 org.apache.logging.log4j.Logger; + +import de.bluecolored.bluemap.core.logger.AbstractLogger; + +public class Log4jLogger extends AbstractLogger { + + private Logger out; + + public Log4jLogger(Logger out) { + this.out = out; + } + + @Override + public void logError(String message, Throwable throwable) { + out.error(message, throwable); + } + + @Override + public void logWarning(String message) { + out.warn(message); + } + + @Override + public void logInfo(String message) { + out.info(message); + } + + @Override + public void logDebug(String message) { + if (out.isDebugEnabled()) out.debug(message); + } + + @Override + public void noFloodDebug(String message) { + if (out.isDebugEnabled()) super.noFloodDebug(message); + } + + @Override + public void noFloodDebug(String key, String message) { + if (out.isDebugEnabled()) super.noFloodDebug(key, message); + } + +} diff --git a/BlueMapFabric/src/main/resources/assets/bluemap/icon.png b/BlueMapFabric/src/main/resources/assets/bluemap/icon.png new file mode 100644 index 00000000..65d56d7a Binary files /dev/null and b/BlueMapFabric/src/main/resources/assets/bluemap/icon.png differ diff --git a/BlueMapFabric/src/main/resources/bluemap.mixins.json b/BlueMapFabric/src/main/resources/bluemap.mixins.json new file mode 100644 index 00000000..abb10ecd --- /dev/null +++ b/BlueMapFabric/src/main/resources/bluemap.mixins.json @@ -0,0 +1,13 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "de.bluecolored.bluemap.fabric.mixin", + "compatibilityLevel": "JAVA_8", + "mixins": [ + ], + "client": [ + ], + "injectors": { + "defaultRequire": 1 + } +} diff --git a/BlueMapFabric/src/main/resources/fabric.mod.json b/BlueMapFabric/src/main/resources/fabric.mod.json new file mode 100644 index 00000000..0cec38f6 --- /dev/null +++ b/BlueMapFabric/src/main/resources/fabric.mod.json @@ -0,0 +1,35 @@ +{ + "schemaVersion": 1, + "id": "bluemap", + "version": "${version}", + + "name": "BlueMap", + "description": "A 3d-map of your Minecraft worlds view-able in your browser using three.js (WebGL)", + "authors": [ + "Blue (TBlueF, Lukas Rieger)" + ], + "contact": { + "homepage": "https://github.com/BlueMap-Minecraft", + "sources": "https://github.com/BlueMap-Minecraft/BlueMap" + }, + + "license": "MIT", + "icon": "assets/bluemap/icon.png", + + "environment": "*", + "entrypoints": { + "main": [ + "de.bluecolored.bluemap.fabric.FabricMod" + ] + }, + "mixins": [ + "bluemap.mixins.json" + ], + + "depends": { + "fabricloader": ">=0.7.4", + "fabric": "*", + "minecraft": "1.15.x" + }, + "suggests": {} +} diff --git a/build.gradle b/build.gradle index 0b5089b0..fef52440 100644 --- a/build.gradle +++ b/build.gradle @@ -24,10 +24,18 @@ allprojects { maven { url "https://libraries.minecraft.net" } + maven { + name = 'Fabric' + url = 'https://maven.fabricmc.net/' + } } compileJava.options.compilerArgs.add '-parameters' compileTestJava.options.compilerArgs.add '-parameters' + + tasks.withType(JavaCompile) { + options.encoding = "UTF-8" + } apply plugin: 'java' diff --git a/settings.gradle b/settings.gradle index fd1b97fc..dd4abee2 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,3 +1,14 @@ +pluginManagement { + repositories { + jcenter() + maven { + name = 'Fabric' + url = 'https://maven.fabricmc.net/' + } + gradlePluginPortal() + } +} + rootProject.name = 'BlueMap' include ':BlueMapCore' include ':BlueMapCLI' @@ -6,6 +17,7 @@ include ':BlueMapSponge' include ':BlueMapBukkit' include ':BlueMapForge' include ':BlueMapAPI' +include ':BlueMapFabric' project(':BlueMapCore').projectDir = "$rootDir/BlueMapCore" as File project(':BlueMapCLI').projectDir = "$rootDir/BlueMapCLI" as File @@ -14,3 +26,4 @@ project(':BlueMapSponge').projectDir = "$rootDir/BlueMapSponge" as File project(':BlueMapBukkit').projectDir = "$rootDir/BlueMapBukkit" as File project(':BlueMapForge').projectDir = "$rootDir/BlueMapForge" as File project(':BlueMapAPI').projectDir = "$rootDir/BlueMapAPI" as File +project(':BlueMapFabric').projectDir = "$rootDir/BlueMapFabric" as File