From 07d08ef831dda80dfacc0359c8dcc509d74861a5 Mon Sep 17 00:00:00 2001 From: Recursive G Date: Sat, 15 Jan 2022 14:13:09 -0600 Subject: [PATCH] try tick-based approach --- build.gradle | 2 +- src/main/java/me/recursiveg/Mc122477Fix.java | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index 45501ee..c94a656 100644 --- a/build.gradle +++ b/build.gradle @@ -13,7 +13,7 @@ apply plugin: 'net.minecraftforge.gradle' apply plugin: 'eclipse' apply plugin: 'maven-publish' -version = '1.0' +version = '1.1' group = 'me.recursiveg' // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = 'Mc122477Fix' diff --git a/src/main/java/me/recursiveg/Mc122477Fix.java b/src/main/java/me/recursiveg/Mc122477Fix.java index ed1a231..cb87fa2 100644 --- a/src/main/java/me/recursiveg/Mc122477Fix.java +++ b/src/main/java/me/recursiveg/Mc122477Fix.java @@ -5,24 +5,34 @@ import net.minecraftforge.client.event.ScreenEvent; import net.minecraftforge.client.event.ScreenOpenEvent; import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.TickEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; @Mod("mc122477fix") -public class Mc122477Fix -{ +public class Mc122477Fix { public Mc122477Fix() { MinecraftForge.EVENT_BUS.register(this); } - long lastScreenOpenTime = 0; + long renderTicksSinceScreenOpen = 0; + @SubscribeEvent public void onScreenOpen(ScreenOpenEvent ev) { - if (ev.getScreen() instanceof ChatScreen || ev.getScreen() instanceof CreativeModeInventoryScreen) lastScreenOpenTime = System.currentTimeMillis(); + if (ev.getScreen() instanceof ChatScreen || ev.getScreen() instanceof CreativeModeInventoryScreen) { + renderTicksSinceScreenOpen = 0; + } } @SubscribeEvent public void onCharTyped(ScreenEvent.KeyboardCharTypedEvent.Pre ev) { - if (System.currentTimeMillis() - lastScreenOpenTime < 50) ev.setCanceled(true); + if (renderTicksSinceScreenOpen < 2) { + ev.setCanceled(true); + } + } + + @SubscribeEvent + public void onPostClientTick(TickEvent.RenderTickEvent ev) { + if (ev.phase == TickEvent.Phase.END) renderTicksSinceScreenOpen++; } }