LWJGL is now an optional dependency (example project to use it incoming)

This commit is contained in:
jglrxavpok 2020-08-10 14:50:39 +02:00
parent 3144f64b06
commit 5533e3f9e7
7 changed files with 44 additions and 18 deletions

View File

@ -51,6 +51,21 @@ sourceSets {
compileClasspath += sourceSets.main.runtimeClasspath compileClasspath += sourceSets.main.runtimeClasspath
runtimeClasspath += sourceSets.main.runtimeClasspath runtimeClasspath += sourceSets.main.runtimeClasspath
} }
lwjgl {
java {
srcDir 'src/lwjgl/java'
}
compileClasspath += sourceSets.main.runtimeClasspath
runtimeClasspath += sourceSets.main.runtimeClasspath
}
}
// Minestom uses LWJGL libs as optional dependency if interfacing with a GPU is asked
java {
registerFeature("lwjgl") {
usingSourceSet(sourceSets.lwjgl)
}
} }
dependencies { dependencies {
@ -95,15 +110,15 @@ dependencies {
api 'com.github.jglrxavpok:Hephaistos:v1.0.4' api 'com.github.jglrxavpok:Hephaistos:v1.0.4'
// LWJGL, for map rendering // LWJGL, for map rendering
implementation platform("org.lwjgl:lwjgl-bom:$lwjglVersion") lwjglApi platform("org.lwjgl:lwjgl-bom:$lwjglVersion")
api "org.lwjgl:lwjgl" lwjglApi "org.lwjgl:lwjgl"
api "org.lwjgl:lwjgl-egl" lwjglApi "org.lwjgl:lwjgl-egl"
api "org.lwjgl:lwjgl-opengl" lwjglApi "org.lwjgl:lwjgl-opengl"
api "org.lwjgl:lwjgl-opengles" lwjglApi "org.lwjgl:lwjgl-opengles"
api "org.lwjgl:lwjgl-glfw" lwjglApi "org.lwjgl:lwjgl-glfw"
runtimeOnly "org.lwjgl:lwjgl::$lwjglNatives" lwjglRuntimeOnly "org.lwjgl:lwjgl::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-opengl::$lwjglNatives" lwjglRuntimeOnly "org.lwjgl:lwjgl-opengl::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-opengles::$lwjglNatives" lwjglRuntimeOnly "org.lwjgl:lwjgl-opengles::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-glfw::$lwjglNatives" lwjglRuntimeOnly "org.lwjgl:lwjgl-glfw::$lwjglNatives"
} }

4
src/lwjgl/README.md Normal file
View File

@ -0,0 +1,4 @@
# Minestom LWJGL code
Here is all LWJGL-related code in Minestom.
Accessible when using "lwjgl" as an optional dependency in Gradle when declaring Minestom as a dependency

View File

@ -1,5 +1,6 @@
package fr.themode.demo.map; package fr.themode.demo.map;
import fr.themode.demo.Main;
import net.minestom.server.MinecraftServer; import net.minestom.server.MinecraftServer;
import net.minestom.server.event.player.PlayerSpawnEvent; import net.minestom.server.event.player.PlayerSpawnEvent;
import net.minestom.server.item.ItemStack; import net.minestom.server.item.ItemStack;
@ -131,4 +132,12 @@ public class MapAnimationDemo {
p.getPlayerConnection().sendPacket(mapDataPacket); p.getPlayerConnection().sendPacket(mapDataPacket);
}); });
} }
public static void main(String[] args) {
MinecraftServer.init();
MinecraftServer.getCommandManager().register(new TestItemFrame());
init();
Main.main(args);
}
} }

View File

@ -1,6 +1,5 @@
package fr.themode.demo.commands; package fr.themode.demo.map;
import fr.themode.demo.map.MapAnimationDemo;
import net.minestom.server.command.CommandProcessor; import net.minestom.server.command.CommandProcessor;
import net.minestom.server.command.CommandSender; import net.minestom.server.command.CommandSender;
import net.minestom.server.entity.Player; import net.minestom.server.entity.Player;

View File

@ -10,12 +10,11 @@ import org.lwjgl.PointerBuffer;
import org.lwjgl.glfw.GLFWErrorCallback; import org.lwjgl.glfw.GLFWErrorCallback;
import org.lwjgl.opengl.GL; import org.lwjgl.opengl.GL;
import org.lwjgl.system.MemoryStack; import org.lwjgl.system.MemoryStack;
import org.lwjgl.system.MemoryUtil;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.glfw.GLFW.*; import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL11.*;
/** /**
* GLFW-based framebuffer. * GLFW-based framebuffer.
@ -31,6 +30,8 @@ import static org.lwjgl.glfw.GLFW.*;
* *
* GLFWFramebuffer does not provide guarantee that the result of {@link #toMapColors()} is synchronized with rendering, but * GLFWFramebuffer does not provide guarantee that the result of {@link #toMapColors()} is synchronized with rendering, but
* it will be updated after each frame rendered through {@link #render(Runnable)} or {@link #setupRenderLoop(long, TimeUnit, Runnable)}. * it will be updated after each frame rendered through {@link #render(Runnable)} or {@link #setupRenderLoop(long, TimeUnit, Runnable)}.
*
* This framebuffer is meant to render to a single map (ie it is only compatible with 128x128 rendering)
*/ */
public class GLFWFramebuffer implements Framebuffer { public class GLFWFramebuffer implements Framebuffer {

View File

@ -4,7 +4,6 @@ import fr.themode.demo.blocks.BurningTorchBlock;
import fr.themode.demo.blocks.StoneBlock; import fr.themode.demo.blocks.StoneBlock;
import fr.themode.demo.blocks.UpdatableBlockDemo; import fr.themode.demo.blocks.UpdatableBlockDemo;
import fr.themode.demo.commands.*; import fr.themode.demo.commands.*;
import fr.themode.demo.map.MapAnimationDemo;
import net.minestom.server.MinecraftServer; import net.minestom.server.MinecraftServer;
import net.minestom.server.command.CommandManager; import net.minestom.server.command.CommandManager;
import net.minestom.server.instance.block.BlockManager; import net.minestom.server.instance.block.BlockManager;
@ -35,9 +34,6 @@ public class Main {
commandManager.register(new GamemodeCommand()); commandManager.register(new GamemodeCommand());
commandManager.register(new DimensionCommand()); commandManager.register(new DimensionCommand());
commandManager.register(new ShutdownCommand()); commandManager.register(new ShutdownCommand());
commandManager.register(new TestItemFrame());
MapAnimationDemo.init();
/*RecipeManager recipeManager = MinecraftServer.getRecipeManager(); /*RecipeManager recipeManager = MinecraftServer.getRecipeManager();
ShapelessRecipe shapelessRecipe = new ShapelessRecipe("test", "groupname") { ShapelessRecipe shapelessRecipe = new ShapelessRecipe("test", "groupname") {

View File

@ -127,6 +127,8 @@ public class MinecraftServer {
private static MinecraftSessionService sessionService = authService.createMinecraftSessionService(); private static MinecraftSessionService sessionService = authService.createMinecraftSessionService();
public static MinecraftServer init() { public static MinecraftServer init() {
if(minecraftServer != null) // don't init twice
return minecraftServer;
// warmup/force-init registries // warmup/force-init registries
// without this line, registry types that are not loaded explicitly will have an internal empty registry in Registries // without this line, registry types that are not loaded explicitly will have an internal empty registry in Registries
// That can happen with PotionType for instance, if no code tries to access a PotionType field // That can happen with PotionType for instance, if no code tries to access a PotionType field