Skip to content

Commit

Permalink
try tick-based approach
Browse files Browse the repository at this point in the history
  • Loading branch information
RecursiveG committed Jan 15, 2022
1 parent 8d9ae6e commit 07d08ef
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
20 changes: 15 additions & 5 deletions src/main/java/me/recursiveg/Mc122477Fix.java
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}
}

0 comments on commit 07d08ef

Please sign in to comment.