aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/cc/polyfrost
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/cc/polyfrost')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/events/EventManager.java29
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/events/event/CancellableEvent.java6
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/events/event/ChatReceiveEvent.java6
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/events/event/HudRenderEvent.java6
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/events/event/LocrawEvent.java6
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/events/event/RenderEvent.java10
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/events/event/ScreenOpenEvent.java8
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/events/event/Stage.java6
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/events/event/TickEvent.java6
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/events/event/TimerUpdateEvent.java24
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/events/event/WorldLoadEvent.java3
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/mixin/MinecraftMixin.java16
12 files changed, 121 insertions, 5 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/events/EventManager.java b/src/main/java/cc/polyfrost/oneconfig/events/EventManager.java
index e1c1427..c758ec1 100644
--- a/src/main/java/cc/polyfrost/oneconfig/events/EventManager.java
+++ b/src/main/java/cc/polyfrost/oneconfig/events/EventManager.java
@@ -3,26 +3,55 @@ package cc.polyfrost.oneconfig.events;
import cc.polyfrost.oneconfig.libs.eventbus.EventBus;
import cc.polyfrost.oneconfig.libs.eventbus.invokers.LMFInvoker;
+/**
+ * Manages all events from OneConfig.
+ */
public final class EventManager {
private EventManager() {
}
+ /**
+ * The instance of the {@link EventManager}.
+ */
public static final EventManager INSTANCE = new EventManager();
private final EventBus eventBus = new EventBus(new LMFInvoker(), Throwable::printStackTrace);
+ /**
+ * Returns the {@link EventBus} instance.
+ *
+ * @return The {@link EventBus} instance.
+ */
public EventBus getEventBus() {
return eventBus;
}
+ /**
+ * Registers an object to the {@link EventBus}.
+ *
+ * @param object The object to register.
+ * @see EventBus#register(Object)
+ */
public void register(Object object) {
eventBus.register(object);
}
+ /**
+ * Unregisters an object from the {@link EventBus}.
+ *
+ * @param object The object to unregister.
+ * @see EventBus#unregister(Object)
+ */
public void unregister(Object object) {
eventBus.unregister(object);
}
+ /**
+ * Posts an event to the {@link EventBus}.
+ *
+ * @param event The event to post.
+ * @see EventBus#post(Object)
+ */
public void post(Object event) {
eventBus.post(event);
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/events/event/CancellableEvent.java b/src/main/java/cc/polyfrost/oneconfig/events/event/CancellableEvent.java
index 2afa613..82cbac4 100644
--- a/src/main/java/cc/polyfrost/oneconfig/events/event/CancellableEvent.java
+++ b/src/main/java/cc/polyfrost/oneconfig/events/event/CancellableEvent.java
@@ -1,5 +1,11 @@
package cc.polyfrost.oneconfig.events.event;
+/**
+ * Represents an event that can be cancelled.
+ */
public class CancellableEvent {
+ /**
+ * Whether the event has been cancelled.
+ */
public boolean isCancelled = false;
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/events/event/ChatReceiveEvent.java b/src/main/java/cc/polyfrost/oneconfig/events/event/ChatReceiveEvent.java
index b69b89b..616479e 100644
--- a/src/main/java/cc/polyfrost/oneconfig/events/event/ChatReceiveEvent.java
+++ b/src/main/java/cc/polyfrost/oneconfig/events/event/ChatReceiveEvent.java
@@ -3,7 +3,13 @@ package cc.polyfrost.oneconfig.events.event;
import net.minecraft.util.IChatComponent;
+/**
+ * Called when a chat message is received.
+ */
public class ChatReceiveEvent extends CancellableEvent {
+ /**
+ * The message that was received.
+ */
public final IChatComponent message;
public ChatReceiveEvent(IChatComponent message) {
diff --git a/src/main/java/cc/polyfrost/oneconfig/events/event/HudRenderEvent.java b/src/main/java/cc/polyfrost/oneconfig/events/event/HudRenderEvent.java
index 974508d..465a2f6 100644
--- a/src/main/java/cc/polyfrost/oneconfig/events/event/HudRenderEvent.java
+++ b/src/main/java/cc/polyfrost/oneconfig/events/event/HudRenderEvent.java
@@ -1,6 +1,12 @@
package cc.polyfrost.oneconfig.events.event;
+/**
+ * Called when external HUDs can be rendered.
+ */
public class HudRenderEvent {
+ /**
+ * How much time has elapsed since the last tick, in ticks. Used for animations.
+ */
public final float deltaTicks;
public HudRenderEvent(float deltaTicks) {
diff --git a/src/main/java/cc/polyfrost/oneconfig/events/event/LocrawEvent.java b/src/main/java/cc/polyfrost/oneconfig/events/event/LocrawEvent.java
index 42565f7..da14de3 100644
--- a/src/main/java/cc/polyfrost/oneconfig/events/event/LocrawEvent.java
+++ b/src/main/java/cc/polyfrost/oneconfig/events/event/LocrawEvent.java
@@ -2,6 +2,12 @@ package cc.polyfrost.oneconfig.events.event;
import cc.polyfrost.oneconfig.utils.hypixel.LocrawInfo;
+/**
+ * Called when the player's location in Hypixel is received via the /locraw command.
+ *
+ * @see LocrawInfo
+ * @see cc.polyfrost.oneconfig.utils.hypixel.HypixelUtils
+ */
public class LocrawEvent {
public final LocrawInfo info;
diff --git a/src/main/java/cc/polyfrost/oneconfig/events/event/RenderEvent.java b/src/main/java/cc/polyfrost/oneconfig/events/event/RenderEvent.java
index aa305a1..5f3be47 100644
--- a/src/main/java/cc/polyfrost/oneconfig/events/event/RenderEvent.java
+++ b/src/main/java/cc/polyfrost/oneconfig/events/event/RenderEvent.java
@@ -1,7 +1,17 @@
package cc.polyfrost.oneconfig.events.event;
+/**
+ * Called when a game tick is started / ended, represented by a {@link Stage}
+ */
public class RenderEvent {
+ /**
+ * Whether the tick is starting or ending.
+ */
public final Stage stage;
+
+ /**
+ * How much time has elapsed since the last tick, in ticks. Used for animations.
+ */
public final float deltaTicks;
public RenderEvent(Stage stage, float deltaTicks) {
diff --git a/src/main/java/cc/polyfrost/oneconfig/events/event/ScreenOpenEvent.java b/src/main/java/cc/polyfrost/oneconfig/events/event/ScreenOpenEvent.java
index d3a5b66..4593638 100644
--- a/src/main/java/cc/polyfrost/oneconfig/events/event/ScreenOpenEvent.java
+++ b/src/main/java/cc/polyfrost/oneconfig/events/event/ScreenOpenEvent.java
@@ -1,11 +1,17 @@
package cc.polyfrost.oneconfig.events.event;
import net.minecraft.client.gui.GuiScreen;
+import org.jetbrains.annotations.Nullable;
+/**
+ * Called when a screen is opened or closed.
+ * If the screen is closed, {@link ScreenOpenEvent#screen} will be null.
+ */
public class ScreenOpenEvent extends CancellableEvent {
+ @Nullable
public final GuiScreen screen;
- public ScreenOpenEvent(GuiScreen screen) {
+ public ScreenOpenEvent(@Nullable GuiScreen screen) {
this.screen = screen;
}
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/events/event/Stage.java b/src/main/java/cc/polyfrost/oneconfig/events/event/Stage.java
index 77c93b8..564058f 100644
--- a/src/main/java/cc/polyfrost/oneconfig/events/event/Stage.java
+++ b/src/main/java/cc/polyfrost/oneconfig/events/event/Stage.java
@@ -1,5 +1,11 @@
package cc.polyfrost.oneconfig.events.event;
+/**
+ * Represents whether the event is called when the specified action is started or ended.
+ *
+ * @see TickEvent
+ * @see RenderEvent
+ */
public enum Stage {
START,
END
diff --git a/src/main/java/cc/polyfrost/oneconfig/events/event/TickEvent.java b/src/main/java/cc/polyfrost/oneconfig/events/event/TickEvent.java
index 5eb776c..9ddae98 100644
--- a/src/main/java/cc/polyfrost/oneconfig/events/event/TickEvent.java
+++ b/src/main/java/cc/polyfrost/oneconfig/events/event/TickEvent.java
@@ -1,6 +1,12 @@
package cc.polyfrost.oneconfig.events.event;
+/**
+ * Called when a game tick is started / ended, represented by a {@link Stage}
+ */
public class TickEvent {
+ /**
+ * Whether the tick is starting or ending.
+ */
public final Stage stage;
public TickEvent(Stage stage) {
diff --git a/src/main/java/cc/polyfrost/oneconfig/events/event/TimerUpdateEvent.java b/src/main/java/cc/polyfrost/oneconfig/events/event/TimerUpdateEvent.java
new file mode 100644
index 0000000..a8b88dc
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/events/event/TimerUpdateEvent.java
@@ -0,0 +1,24 @@
+package cc.polyfrost.oneconfig.events.event;
+
+import net.minecraft.util.Timer;
+
+/**
+ * Called when the {@link Timer} is updated.
+ * Can be used as an alternative to getting instances of {@link Timer}
+ * via Mixin or Access Wideners / Transformers
+ */
+public class TimerUpdateEvent {
+ /**
+ * Whether the deltaTicks / renderPartialTicks was updated
+ */
+ public final boolean updatedDeltaTicks;
+ /**
+ * The {@link Timer} instance
+ */
+ public final Timer timer;
+
+ public TimerUpdateEvent(Timer timer, boolean updatedDeltaTicks) {
+ this.timer = timer;
+ this.updatedDeltaTicks = updatedDeltaTicks;
+ }
+} \ No newline at end of file
diff --git a/src/main/java/cc/polyfrost/oneconfig/events/event/WorldLoadEvent.java b/src/main/java/cc/polyfrost/oneconfig/events/event/WorldLoadEvent.java
index 1583fe6..560b539 100644
--- a/src/main/java/cc/polyfrost/oneconfig/events/event/WorldLoadEvent.java
+++ b/src/main/java/cc/polyfrost/oneconfig/events/event/WorldLoadEvent.java
@@ -1,4 +1,7 @@
package cc.polyfrost.oneconfig.events.event;
+/**
+ * Called when the world is loaded.
+ */
public class WorldLoadEvent {
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/mixin/MinecraftMixin.java b/src/main/java/cc/polyfrost/oneconfig/mixin/MinecraftMixin.java
index 97b843a..1226244 100644
--- a/src/main/java/cc/polyfrost/oneconfig/mixin/MinecraftMixin.java
+++ b/src/main/java/cc/polyfrost/oneconfig/mixin/MinecraftMixin.java
@@ -1,14 +1,12 @@
package cc.polyfrost.oneconfig.mixin;
import cc.polyfrost.oneconfig.events.EventManager;
-import cc.polyfrost.oneconfig.events.event.RenderEvent;
-import cc.polyfrost.oneconfig.events.event.ScreenOpenEvent;
-import cc.polyfrost.oneconfig.events.event.Stage;
-import cc.polyfrost.oneconfig.events.event.TickEvent;
+import cc.polyfrost.oneconfig.events.event.*;
import cc.polyfrost.oneconfig.libs.mixinextras.injector.ModifyExpressionValue;
import net.minecraft.client.Minecraft;
import net.minecraft.util.Timer;
import net.minecraftforge.client.event.GuiOpenEvent;
+import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
@@ -48,4 +46,14 @@ public class MinecraftMixin {
}
return screen;
}
+
+ @Inject(method = "runGameLoop", at = @At(value = "FIELD", target = "Lnet/minecraft/util/Timer;renderPartialTicks:F", opcode = Opcodes.PUTFIELD, shift = At.Shift.AFTER))
+ private void onNonDeltaTickTimerUpdate(CallbackInfo ci) {
+ EventManager.INSTANCE.post(new TimerUpdateEvent(timer, false));
+ }
+
+ @Inject(method = "runGameLoop", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/Timer;updateTimer()V", shift = At.Shift.AFTER, ordinal = 1))
+ private void onDeltaTickTimerUpdate(CallbackInfo ci) {
+ EventManager.INSTANCE.post(new TimerUpdateEvent(timer, true));
+ }
}