Skip to content

Commit

Permalink
Oops. EventManager fix and forgot to add a mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
tanishisherewithhh committed Jun 17, 2024
1 parent ac69f4a commit 8c07825
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/main/java/dev/heliosclient/managers/EventManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static void unregister(Listener listener) {
public static Event postEvent(Event event) {
List<EventListener> eventListeners = listeners.get(event.getClass());
if (eventListeners != null && !eventListeners.isEmpty()) {
for (EventListener listener : new CopyOnWriteArrayList<>(eventListeners)) {
for (EventListener listener : new CopyOnWriteArraySet<>(eventListeners)) {
listener.accept(event);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public KeybindManager() {
EventManager.register(this);
}


@SubscribeEvent(priority = SubscribeEvent.Priority.HIGHEST)
public void keyPressedEvent(KeyPressedEvent event) {
int key = event.getKey();
Expand Down
43 changes: 24 additions & 19 deletions src/main/java/dev/heliosclient/mixin/KeyboardMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
import dev.heliosclient.managers.EventManager;
import dev.heliosclient.managers.ModuleManager;
import dev.heliosclient.module.modules.misc.NoNarrator;
import net.fabricmc.fabric.api.client.screen.v1.ScreenKeyboardEvents;
import net.minecraft.client.Keyboard;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.option.GameOptions;
import net.minecraft.client.option.SimpleOption;
import net.minecraft.client.util.InputUtil;
import org.lwjgl.glfw.GLFW;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
Expand All @@ -21,34 +24,35 @@

@Mixin(Keyboard.class)
public abstract class KeyboardMixin {
@Unique
private static final MinecraftClient mc = MinecraftClient.getInstance();

@Inject(method = "onKey", at = @At("HEAD"), cancellable = true)
public void onKey(long window, int key, int scancode, int action, int modifiers, CallbackInfo info) {
if (action == GLFW.GLFW_PRESS) {
KeyPressedEvent event = new KeyPressedEvent(window, key, scancode, action, modifiers);
EventManager.postEvent(event);
if (event.isCanceled()) {
info.cancel();
if(key >= 0 && window == MinecraftClient.getInstance().getWindow().getHandle() && InputUtil.isKeyPressed(window,key)) {
if (action != GLFW.GLFW_RELEASE) {
KeyHeldEvent event = new KeyHeldEvent(window, key, scancode, action, modifiers);
EventManager.postEvent(event);
if (event.isCanceled()) {
info.cancel();
}
}
}
if (action == GLFW.GLFW_RELEASE) {
KeyReleasedEvent event = new KeyReleasedEvent(window, key, scancode, action, modifiers);
EventManager.postEvent(event);
if (event.isCanceled()) {
info.cancel();
if (action == GLFW.GLFW_PRESS) {
KeyPressedEvent event = new KeyPressedEvent(window, key, scancode, action, modifiers);
EventManager.postEvent(event);
if (event.isCanceled()) {
info.cancel();
}
}
}
if (action != GLFW.GLFW_RELEASE) {
KeyHeldEvent event = new KeyHeldEvent(window, key, scancode, action, modifiers);
EventManager.postEvent(event);
if (event.isCanceled()) {
info.cancel();
if (action == GLFW.GLFW_RELEASE) {
KeyReleasedEvent event = new KeyReleasedEvent(window, key, scancode, action, modifiers);
EventManager.postEvent(event);
if (event.isCanceled()) {
info.cancel();
}
}
}
}


@Redirect(method = "onKey", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/option/GameOptions;getNarratorHotkey()Lnet/minecraft/client/option/SimpleOption;"))
private SimpleOption<Boolean> disableNarratorKey(GameOptions instance) {
if (ModuleManager.get(NoNarrator.class).isActive()) {
Expand All @@ -57,6 +61,7 @@ private SimpleOption<Boolean> disableNarratorKey(GameOptions instance) {
return instance.getNarratorHotkey();
}


@Inject(method = "onChar", at = @At("HEAD"), cancellable = true)
private void onChar(long window, int i, int j, CallbackInfo info) {
CharTypedEvent event = new CharTypedEvent(window, (char) i, j);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
public abstract class MixinBackgroundRenderer {
@Inject(method = "applyFog", at = @At("TAIL"))
private static void onApplyFog(Camera camera, BackgroundRenderer.FogType fogType, float viewDistance, boolean thickFog, float tickDelta, CallbackInfo ci) {
if (NoRender.get().isActive() && NoRender.get().noFog.value || ModuleManager.get(Xray.class).isActive()) {
if ((NoRender.get().isActive() && NoRender.get().noFog.value) || ModuleManager.get(Xray.class).isActive()) {
if (fogType == BackgroundRenderer.FogType.FOG_TERRAIN) {
RenderSystem.setShaderFogStart(viewDistance * 4);
RenderSystem.setShaderFogEnd(viewDistance * 4.25f);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public abstract class MixinItemRenderer {
)
)
private void modifyEnchant(Args args, ItemStack stack, ModelTransformationMode renderMode, boolean leftHanded, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay, BakedModel model) {
if (NoRender.get().isActive() && !NoRender.get().noEnchantGlint.value) return;
if (!NoRender.get().isActive() && !NoRender.get().noEnchantGlint.value) return;
boolean bl = (renderMode == ModelTransformationMode.GUI || renderMode.isFirstPerson() || !(stack.getItem() instanceof BlockItem blockItem) || !(blockItem.getBlock() instanceof TransparentBlock) && !(blockItem.getBlock() instanceof StainedGlassPaneBlock));
args.set(5, vertexConsumers.getBuffer(RenderLayers.getItemLayer(stack, bl)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public class BrandSpoof extends Module_ {
.onSettingChange(this)
.inputMode(InputBox.InputMode.ALL)
.characterLimit(100)
.value("vanilla")
.defaultValue("vanilla")
.value("brand")
.defaultValue("brand")
.shouldRender(() -> spoofBrand.value)
.build()
);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/heliosclient/ui/clickgui/Tooltip.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private void renderTooltip(DrawContext drawContext, String text, int x, int y) {
Renderer2D.drawRoundedRectangleWithShadow(drawContext.getMatrices(), x + 5, textY - 2, textWidth + 8, textHeight + 3, 3, 3, Color.BLACK.brighter().brighter().getRGB());
Renderer2D.drawOutlineGradientRoundedBox(drawContext.getMatrices().peek().getPositionMatrix(), x + 5, textY - 2, textWidth + 8, textHeight + 3, 3, 0.7f, ColorManager.INSTANCE.getPrimaryGradientStart().darker(), ColorManager.INSTANCE.getPrimaryGradientEnd().darker(), ColorManager.INSTANCE.getPrimaryGradientEnd().darker(), ColorManager.INSTANCE.getPrimaryGradientStart().darker());

Renderer2D.drawCustomString(FontRenderers.Small_fxfontRenderer, drawContext.getMatrices(), text, x + 8, textY, ColorManager.INSTANCE.defaultTextColor());
Renderer2D.drawCustomString(FontRenderers.Small_fxfontRenderer, drawContext.getMatrices(), text, x + 8 + (Renderer2D.isVanillaRenderer()? 1:0), textY + (Renderer2D.isVanillaRenderer()? 1:0), ColorManager.INSTANCE.defaultTextColor());

Renderer2D.stopScaling(drawContext.getMatrices());
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/heliosclient.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"KeyboardMixin",
"LivingEntityRendererMixin",
"MinecraftClientMixin",
"MixinBackgroundRenderer",
"MixinBlockEntityRenderDispatcher",
"MixinBlockModelRenderer",
"MixinBossBarHud",
Expand Down

0 comments on commit 8c07825

Please sign in to comment.