Skip to content

Commit

Permalink
Updated a lot
Browse files Browse the repository at this point in the history
  • Loading branch information
XyperCode committed Oct 5, 2024
1 parent 8c4362b commit 30b0d24
Show file tree
Hide file tree
Showing 91 changed files with 8,678 additions and 559 deletions.
7 changes: 1 addition & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
# User-specific stuff
.idea/*.xml
.idea/.name
.idea/runConfigurations
.idea/modules
.idea/sonarlint
!.idea/discord.xml
.idea

*.iml
*.ipr
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2023
Copyright 2024

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
16 changes: 16 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright (c) 2024.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

plugins {
id "architectury-plugin" version "3.4-SNAPSHOT"
id "dev.architectury.loom" version "1.4-SNAPSHOT" apply false
Expand Down
35 changes: 35 additions & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,50 @@
/*
* Copyright (c) 2024.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

sourceSets {
api {
java {
srcDir("src/api/java")
}
}

main {
compileClasspath += api.output
runtimeClasspath += api.output
}
}

dependencies {
// We depend on fabric loader here to use the fabric @Environment annotations and get the mixin dependencies
// Do NOT use other classes from fabric loader
modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}"

implementation(annotationProcessor("io.github.llamalad7:mixinextras-fabric:0.4.0"))

modApi "dev.architectury:architectury:${rootProject.architectury_version}"

implementation api("space.earlygrey:shapedrawer:$shapedrawer_version")
implementation api("com.badlogicgames.gdx:gdx-backend-lwjgl3:$gdx_version", {
exclude group: "org.lwjgl.lwjgl"
exclude group: "org.lwjgl"
})
implementation api("com.badlogicgames.gdx:gdx:$gdx_version")
implementation api("com.badlogicgames.gdx:gdx-platform:$gdx_version:natives-desktop")
apiImplementation api("com.badlogicgames.gdx:gdx:$gdx_version")
apiImplementation api("com.badlogicgames.gdx:gdx-platform:$gdx_version:natives-desktop")
}

architectury {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,67 @@
package io.github.ultreon.gdxminecraft;
/*
* Copyright (c) 2024.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package dev.ultreon.mcgdx;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.ApplicationLogger;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Version;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Window;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3WindowListener;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.*;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.g3d.Material;
import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.graphics.g3d.ModelBatch;
import com.badlogic.gdx.graphics.g3d.ModelInstance;
import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
import com.badlogic.gdx.graphics.g3d.utils.ModelBuilder;
import com.badlogic.gdx.graphics.glutils.FrameBufferCubemap;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.utils.GdxNativesLoader;
import com.mojang.blaze3d.platform.Window;
import io.github.ultreon.gdxminecraft.api.ModLoader;
import io.github.ultreon.gdxminecraft.impl.MinecraftApplication;
import io.github.ultreon.gdxminecraft.impl.MinecraftGdxLogger;
import io.github.ultreon.gdxminecraft.impl.MinecraftWindow;
import io.github.ultreon.gdxminecraft.mixin.accessors.Lwjgl3GraphicsAccessor;
import dev.ultreon.mcgdx.api.McGdx;
import dev.ultreon.mcgdx.api.ModLoader;
import dev.ultreon.mcgdx.api.NamespaceID;
import dev.ultreon.mcgdx.impl.*;
import net.minecraft.CrashReport;
import net.minecraft.CrashReportCategory;
import net.minecraft.client.Minecraft;
import org.jetbrains.annotations.ApiStatus;
import org.lwjgl.system.Configuration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import space.earlygrey.shapedrawer.ShapeDrawer;

public class GdxMinecraft implements ApplicationListener {
public static final String MOD_ID = "gdx_minecraft";
public static final String MOD_ID = "mcgdx";
public static final Logger LOGGER = LoggerFactory.getLogger("GDX-Minecraft");
public static Color fogColor = new Color();
// public static Cubemap cubeMap;
//
// public static FrameBufferCubemap cubemapFBO;
public static boolean disableCubemapUsage = false;

private static GdxMinecraft instance;
private static Material material;
private static Model cube;
private static ModelInstance cubeInstance;
private final Lwjgl3WindowListener windowListener = new UselessWindowListener();
public static ModLoader loader;
private final ApplicationLogger logger = new MinecraftGdxLogger();
Expand All @@ -47,11 +76,17 @@ public class GdxMinecraft implements ApplicationListener {
private boolean posted;
private static BitmapFont bitmapFont;

public GdxMinecraft() {
private GdxMinecraft() {
instance = this;
try {
GdxNativesLoader.load();
GdxMinecraft.app = new MinecraftApplication(this, Minecraft.getInstance());
GdxMinecraft.app = new MinecraftApplication(this, new MinecraftApplicationConfiguration(), Minecraft.getInstance());
McGdx.blockEntityManager = new MinecraftBlockEntityManager();

McGdx.blockEntityManager.register(new NamespaceID("mcgdx", "example"), source -> {
ModelBatch batch1 = source.getBatch();
batch1.render(cubeInstance);
});
} catch (Throwable e) {
CrashReport libGDXCrash = new CrashReport("LibGDX failed to initialize", e);
CrashReportCategory libGDX = libGDXCrash.addCategory("LibGDX");
Expand All @@ -60,15 +95,18 @@ public GdxMinecraft() {
}
}

// public static void beginCubeFBO() {
// cubemapFBO.begin();
// }

// public static void endCubeFBO() {
// cubemapFBO.end();
// }

public static GdxMinecraft instance() {
return instance;
}

@ApiStatus.Internal
public static void init() {
new GdxMinecraft();
}

public static void initialize() {
batch = new SpriteBatch();
Pixmap whitePix = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
Expand All @@ -78,6 +116,19 @@ public static void initialize() {
texture = new Texture(new Pixmap(Gdx.files.internal("test.png")), true);
gdxThread = Thread.currentThread();
bitmapFont = new BitmapFont(true);

material = new Material("box_id");
material.set(ColorAttribute.createDiffuse(new Color(1, 1, 1, 1)));
ModelBuilder modelBuilder = new ModelBuilder();
cube = modelBuilder.createSphere(1, 1, 1, 50, 50, GL20.GL_TRIANGLES, material, VertexAttributes.Usage.Normal | VertexAttributes.Usage.Position | VertexAttributes.Usage.TextureCoordinates | VertexAttributes.Usage.ColorPacked);
cubeInstance = new ModelInstance(cube);
cubeInstance.transform.translate(0.5f, 0.5f, 0.5f);
}

public static void init() {
if (instance == null) {
instance = new GdxMinecraft();
}
}

@Override
Expand All @@ -87,14 +138,17 @@ public void create() {
}

public void resize0(int width, int height) {
if (batch == null) return;
Gdx.app.log("GDX-Minecraft", "Resizing to " + width + "x" + height);

batch.setProjectionMatrix(batch.getProjectionMatrix().setToOrtho(0, width, height, 0, -1000000, 1000000));

this.width = width;
this.height = height;

long windowHandle = window.getHandle();
// if (cubemapFBO != null) cubemapFBO.dispose();
// cubemapFBO = new FrameBufferCubemap(Pixmap.Format.RGBA8888, width, height, true);
long windowHandle = window.getWindowHandle();
if (Boolean.TRUE.equals(Configuration.GLFW_CHECK_THREAD0.get(true))) {
this.renderWindow(windowHandle, width, height);
} else {
Expand All @@ -114,16 +168,24 @@ public void resize(int width, int height) {
}

private void renderWindow(long windowHandle, int width, int height) {
((Lwjgl3GraphicsAccessor) app.getGraphics()).invokeRenderWindow(windowHandle, width, height);
app.getGraphics();
}

@Override
public void render() {
if (GdxMinecraft.app == null) return;
if (GdxMinecraft.window == null) {
LOGGER.warn("Window not initialized yet! This is probably not a good sign!");
return;
}
Window window = GdxMinecraft.window.getWindow();
int width = window.getWidth();
int height = window.getHeight();
if (width != this.width || height != this.height) {
this.resize0(width, height);

this.width = width;
this.height = height;
}
}

Expand Down
23 changes: 23 additions & 0 deletions common/src/main/java/dev/ultreon/mcgdx/api/BlockEntityManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) 2024.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package dev.ultreon.mcgdx.api;

import dev.ultreon.mcgdx.impl.Gdx3DRenderable;

public interface BlockEntityManager {
void register(NamespaceID id, Gdx3DRenderable source);
}
22 changes: 22 additions & 0 deletions common/src/main/java/dev/ultreon/mcgdx/api/GameEnvironment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (c) 2024.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package dev.ultreon.mcgdx.api;

public enum GameEnvironment {
CLIENT,
UNKNOWN, SERVER
}
29 changes: 29 additions & 0 deletions common/src/main/java/dev/ultreon/mcgdx/api/Gdx3DRenderSource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2024.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package dev.ultreon.mcgdx.api;

import com.badlogic.gdx.graphics.g3d.Environment;
import com.badlogic.gdx.graphics.g3d.ModelBatch;
import net.minecraft.world.entity.Entity;

public interface Gdx3DRenderSource<T> {
ModelBatch getBatch();

void render(T holder);

Environment getEnvironment();
}
Loading

0 comments on commit 30b0d24

Please sign in to comment.