Skip to content

Commit

Permalink
use LexForge Events
Browse files Browse the repository at this point in the history
  • Loading branch information
TexBlock committed Nov 18, 2023
1 parent ad1fd1a commit ae3a470
Show file tree
Hide file tree
Showing 14 changed files with 130 additions and 160 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Changelog
- re-added `architectury-api` dependency
- fix version number
- use LexForge Events, not use `architectury-api`
10 changes: 4 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ plugins {
import net.fabricmc.loom.task.RemapJarTask

group = project.maven_group
version = "lexforge-${project.mod_version}+${getMCVersionString()}"
base.archivesName = "${project.archives_base_name}"
version = "${project.mod_version}+${getMCVersionString()}"
base.archivesName = "${project.archives_base_name}-lexforge"

// This field defines the Java version your mod target.
def targetJavaVersion = 17
Expand Down Expand Up @@ -56,8 +56,6 @@ dependencies {
mappings "org.quiltmc:quilt-mappings:${project.quilt_mappings}:intermediary-v2"
forge "net.minecraftforge:forge:${project.forge_version}"

modImplementation "dev.architectury:architectury-forge:${project.architectury_version}"

testmodImplementation sourceSets.main.output
}

Expand Down Expand Up @@ -130,7 +128,7 @@ modrinth {
token = System.getenv("MODRINTH_TOKEN")

projectId = "${project.modrinth_id}"
versionNumber = "${project.version}"
versionNumber = "lexforge-${project.version}"
versionType = "alpha"
changelog = file("CHANGELOG.md").getText('UTF-8')
uploadFile = remapJar
Expand All @@ -144,7 +142,7 @@ task publishCurseForge(type: net.darkhax.curseforgegradle.TaskPublishCurseForge)
disableVersionDetection()

def mainFile = upload(project.curseforge_id, remapJar)
mainFile.displayName = "${project.version}"
mainFile.displayName = "lexforge-${project.version}"
mainFile.releaseType = "alpha"
mainFile.changelog = file("CHANGELOG.md")
mainFile.changelogType = "markdown"
Expand Down
5 changes: 2 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ quilt_mappings=1.20.2+build.1
forge_version=1.20.2-48.0.38

# Mod Properties
mod_version=0.1.1
mod_version=0.1.2
maven_group=org.thinkingstudio
archives_base_name=obsidianui
modrinth_id=E0L8mfJZ
curseforge_id=684718

# Dependencies
architectury_version=10.0.8
# Dependencies
12 changes: 8 additions & 4 deletions src/main/java/dev/lambdaurora/spruceui/SpruceUI.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
package dev.lambdaurora.spruceui;

import dev.architectury.utils.EnvExecutor;
import dev.lambdaurora.spruceui.hud.HudManager;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.IExtensionPoint;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.fml.loading.FMLLoader;

@Mod(SpruceUI.MODID)
public class SpruceUI {
public static final String MODID = "spruceui";
public static final String MODID = "obsidianui";
public static final IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();

public SpruceUI() {
ModLoadingContext.get().registerExtensionPoint(IExtensionPoint.DisplayTest.class, () -> new IExtensionPoint.DisplayTest(() -> IExtensionPoint.DisplayTest.IGNORESERVERONLY, (a, b) -> true));
EnvExecutor.runInEnv(Dist.CLIENT, () -> this::onInitializeClient);
if (FMLLoader.getDist().isClient()) {
this.onInitializeClient();
}
}

public void onInitializeClient() {
Expand Down
41 changes: 0 additions & 41 deletions src/main/java/dev/lambdaurora/spruceui/event/EventUtil.java

This file was deleted.

This file was deleted.

42 changes: 42 additions & 0 deletions src/main/java/dev/lambdaurora/spruceui/event/OpenScreenEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package dev.lambdaurora.spruceui.event;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraftforge.eventbus.api.Cancelable;
import net.minecraftforge.eventbus.api.Event;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;

public abstract class OpenScreenEvent extends Event {
private final MinecraftClient client;
private final Screen screen;

@ApiStatus.Internal
public OpenScreenEvent(MinecraftClient client, @Nullable Screen screen) {
this.client = client;
this.screen = screen;
}

public MinecraftClient getClient() {
return client;
}

public Screen getScreen() {
return screen;
}

@Cancelable
public static class Pre extends OpenScreenEvent {
@ApiStatus.Internal
public Pre(MinecraftClient client, @Nullable Screen screen) {
super(client, screen);
}
}

public static class Post extends OpenScreenEvent {
@ApiStatus.Internal
public Post(MinecraftClient client, @Nullable Screen screen) {
super(client, screen);
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package dev.lambdaurora.spruceui.event;

import net.minecraft.client.MinecraftClient;
import net.minecraftforge.eventbus.api.Event;

public class ResolutionChangeEvent extends Event {
private final MinecraftClient client;
public ResolutionChangeEvent(MinecraftClient client) {
this.client = client;
}
public MinecraftClient getClient() {
return client;
}
}
59 changes: 40 additions & 19 deletions src/main/java/dev/lambdaurora/spruceui/hud/HudManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@

package dev.lambdaurora.spruceui.hud;

import dev.architectury.event.events.client.ClientGuiEvent;
import dev.architectury.event.events.client.ClientTickEvent;
import dev.lambdaurora.spruceui.event.OpenScreenCallback;
import dev.lambdaurora.spruceui.event.ResolutionChangeCallback;
import dev.lambdaurora.spruceui.event.OpenScreenEvent;
import dev.lambdaurora.spruceui.event.ResolutionChangeEvent;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.util.Identifier;
import net.minecraftforge.client.event.RenderGuiEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import org.jetbrains.annotations.NotNull;

Expand All @@ -33,23 +34,13 @@
* @since 1.2.0
*/
public class HudManager {
private static final Map<Identifier, Hud> HUDS = new Object2ObjectOpenHashMap<>();
public static final Map<Identifier, Hud> HUDS = new Object2ObjectOpenHashMap<>();

public static void initialize() {
ClientGuiEvent.RENDER_HUD.register((graphics, tickDelta) -> HUDS.forEach((id, hud) -> {
if (hud.isEnabled() && hud.isVisible())
hud.render(graphics, tickDelta);
}));
ClientTickEvent.CLIENT_POST.register(client -> {
if (!canRenderHuds(client))
return;
HUDS.forEach((id, hud) -> {
if (hud.isEnabled() && hud.isVisible() && hud.hasTicks())
hud.tick();
});
});
OpenScreenCallback.EVENT.register((client, screen) -> initAll(client, client.getWindow().getScaledWidth(), client.getWindow().getScaledHeight()));
ResolutionChangeCallback.EVENT.register(client -> initAll(client, client.getWindow().getScaledWidth(), client.getWindow().getScaledHeight()));
MinecraftForge.EVENT_BUS.addListener(HudManager::clientTickEvent);
MinecraftForge.EVENT_BUS.addListener(HudManager::renderGuiEvent);
MinecraftForge.EVENT_BUS.addListener(HudManager::openScreenEvent);
MinecraftForge.EVENT_BUS.addListener(HudManager::resolutionChangeEvent);
}

protected static void initAll(@NotNull MinecraftClient client, int screenWidth, int screenHeight) {
Expand Down Expand Up @@ -118,4 +109,34 @@ public static Optional<Hud> getHud(@NotNull Identifier identifier) {
public static Collection<Hud> getHuds() {
return HUDS.values();
}

@SubscribeEvent(priority = EventPriority.HIGHEST)
public static void clientTickEvent(TickEvent.ClientTickEvent event) {
if (!canRenderHuds(MinecraftClient.getInstance()))
return;
HUDS.forEach((id, hud) -> {
if (hud.isEnabled() && hud.isVisible() && hud.hasTicks())
hud.tick();
});
}

@SubscribeEvent(priority = EventPriority.HIGHEST)
public static void renderGuiEvent(RenderGuiEvent.Post event) {
GuiGraphics graphics = event.getGuiGraphics();
float tickDelta = event.getPartialTick();
HUDS.forEach((id, hud) -> {
if (hud.isEnabled() && hud.isVisible())
hud.render(graphics, tickDelta);
});
}

@SubscribeEvent(priority = EventPriority.HIGHEST)
public static void openScreenEvent(OpenScreenEvent.Post event) {
initAll(event.getClient(), event.getClient().getWindow().getScaledWidth(), event.getClient().getWindow().getScaledHeight());
}

@SubscribeEvent(priority = EventPriority.HIGHEST)
public static void resolutionChangeEvent(ResolutionChangeEvent event) {
initAll(event.getClient(), event.getClient().getWindow().getScaledWidth(), event.getClient().getWindow().getScaledHeight());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@

package dev.lambdaurora.spruceui.mixin;

import dev.lambdaurora.spruceui.event.OpenScreenCallback;
import dev.lambdaurora.spruceui.event.ResolutionChangeCallback;
import dev.lambdaurora.spruceui.SpruceUI;
import dev.lambdaurora.spruceui.event.OpenScreenEvent;
import dev.lambdaurora.spruceui.event.ResolutionChangeEvent;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -19,7 +20,7 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

/**
* Represents the injection point for the {@link OpenScreenCallback} and {@link ResolutionChangeCallback} events.
* Represents the injection point for the {@link OpenScreenEvent} and {@link ResolutionChangeEvent} events.
*
* @author LambdAurora
* @version 3.2.1
Expand All @@ -29,16 +30,16 @@
public class MinecraftClientMixin {
@Inject(method = "setScreen", at = @At("HEAD"))
private void onScreenPre(Screen screen, CallbackInfo ci) {
OpenScreenCallback.PRE.invoker().apply((MinecraftClient) (Object) this, screen);
SpruceUI.modEventBus.post(new OpenScreenEvent.Pre((MinecraftClient) (Object) this, screen));
}

@Inject(method = "setScreen", at = @At("RETURN"))
private void onScreenChange(Screen screen, CallbackInfo ci) {
OpenScreenCallback.EVENT.invoker().apply((MinecraftClient) (Object) this, screen);
SpruceUI.modEventBus.post(new OpenScreenEvent.Pre((MinecraftClient) (Object) this, screen));
}

@Inject(method = "onResolutionChanged", at = @At("RETURN"))
private void onResolutionChanged(CallbackInfo ci) {
ResolutionChangeCallback.EVENT.invoker().apply((MinecraftClient) (Object) this);
SpruceUI.modEventBus.post(new ResolutionChangeEvent((MinecraftClient) (Object) this));
}
}
Loading

0 comments on commit ae3a470

Please sign in to comment.