Skip to content

Commit

Permalink
mod
Browse files Browse the repository at this point in the history
  • Loading branch information
BetterClient committed Aug 31, 2024
1 parent 37ffbc2 commit df6f640
Show file tree
Hide file tree
Showing 19 changed files with 257 additions and 167 deletions.
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# Fabric Example Mod
# SnapTapMC

## Setup
- The controversial feature from Wooting/Razer keyboards for minecraft!

For setup instructions please see the [fabric wiki page](https://fabricmc.net/wiki/tutorial:setup) that relates to the IDE that you are using.
# DISCLAIMER: Please check server rules before using this on your favorite server, this may be considered a ***CHEAT***

## License
[![Showcase](https://img.youtube.com/vi/Y6VBWgT2YH4/0.jpg)](https://www.youtube.com/watch?v=Y6VBWgT2YH4)

This template is available under the CC0 license. Feel free to learn from it and incorporate it in your own projects.
# What does it do?

- When both strafing keys (A & D) is pressed, the one pressed last is prioritized.-
- This allows for very-accurate strafing, causing this feature to be banned in CS2.
49 changes: 2 additions & 47 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,13 @@ base {
archivesName = project.archives_base_name
}

repositories {
// Add repositories to retrieve artifacts from in here.
// You should only use this when depending on other mods because
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
// for more information about repositories.
}

loom {
splitEnvironmentSourceSets()

mods {
"modid" {
sourceSet sourceSets.main
sourceSet sourceSets.client
}
}

}
repositories {}

dependencies {
// To change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

modRuntimeOnly "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" //only used so that languages work
}

processResources {
Expand All @@ -54,11 +32,6 @@ tasks.withType(JavaCompile).configureEach {
}

java {
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()

sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}
Expand All @@ -67,22 +40,4 @@ jar {
from("LICENSE") {
rename { "${it}_${project.base.archivesName.get()}"}
}
}

// configure the maven publication
publishing {
publications {
create("mavenJava", MavenPublication) {
artifactId = project.archives_base_name
from components.java
}
}

// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
repositories {
// Add repositories to publish to here.
// Notice: This block does NOT have the same function as the block in the top level.
// The repositories here will be used for publishing your artifact, not for
// retrieving dependencies.
}
}
11 changes: 5 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ minecraft_version=1.21.1
yarn_mappings=1.21.1+build.3
loader_version=0.16.2

# Mod Properties
mod_version=1.0.0
maven_group=com.example
archives_base_name=modid
fabric_version=0.103.0+1.21.1

# Dependencies
fabric_version=0.102.1+1.21.1
# Mod Properties
mod_version=1.0
maven_group=io.github.betterclient
archives_base_name=snaptapmc
10 changes: 0 additions & 10 deletions src/client/java/com/example/ExampleModClient.java

This file was deleted.

15 changes: 0 additions & 15 deletions src/client/java/com/example/mixin/client/ExampleClientMixin.java

This file was deleted.

11 changes: 0 additions & 11 deletions src/client/resources/modid.client.mixins.json

This file was deleted.

24 changes: 0 additions & 24 deletions src/main/java/com/example/ExampleMod.java

This file was deleted.

15 changes: 0 additions & 15 deletions src/main/java/com/example/mixin/ExampleMixin.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package io.github.betterclient.snaptap;

public interface KeybindingAccess {
boolean snapTap$isPressedReal();
}
82 changes: 82 additions & 0 deletions src/main/java/io/github/betterclient/snaptap/SnapTap.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package io.github.betterclient.snaptap;

import net.fabricmc.api.ModInitializer;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import net.minecraft.text.Style;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;

public class SnapTap implements ModInitializer {
public static long LEFT_STRAFE_LAST_PRESS_TIME = 0;
public static long RIGHT_STRAFE_LAST_PRESS_TIME = 0;
public static KeyBinding TOGGLE_BIND;
public static boolean TOGGLED = true;

public static KeyBinding KEYSTROKES_TOGGLE_BIND;
public static boolean KEYSTROKES_TOGGLED = true;

@Override
public void onInitialize() {
LEFT_STRAFE_LAST_PRESS_TIME = 0;
RIGHT_STRAFE_LAST_PRESS_TIME = 0;
TOGGLE_BIND = new KeyBinding("text.snaptap.toggle", InputUtil.GLFW_KEY_F8, "key.categories.misc") {
@Override
public void setPressed(boolean pressed) {
if(pressed) {
TOGGLED = !TOGGLED;
MinecraftClient.getInstance().inGameHud.getChatHud().addMessage(
Text.translatable("text.snaptap.toggled",
Text.translatable(TOGGLED ? "text.snaptap.enabled" : "options.ao.off")
.fillStyle(Style.EMPTY
.withColor(TOGGLED ? Formatting.GREEN : Formatting.RED))));
}

super.setPressed(pressed);
}
};

KEYSTROKES_TOGGLE_BIND = new KeyBinding("text.snaptap.keystrokestoggle", InputUtil.GLFW_KEY_F7, "key.categories.misc") {
@Override
public void setPressed(boolean pressed) {
if(pressed) {
KEYSTROKES_TOGGLED = !KEYSTROKES_TOGGLED;
MinecraftClient.getInstance().inGameHud.getChatHud().addMessage(
Text.translatable("text.snaptap.toggledkeystokes",
Text.translatable(KEYSTROKES_TOGGLED ? "text.snaptap.enabled" : "options.ao.off")
.fillStyle(Style.EMPTY
.withColor(KEYSTROKES_TOGGLED ? Formatting.GREEN : Formatting.RED))));
}

super.setPressed(pressed);
}
};
}

public static void render(DrawContext context) {
MinecraftClient client = MinecraftClient.getInstance();

KeyBinding leftKey = client.options.leftKey;
KeyBinding rightKey = client.options.rightKey;

KeybindingAccess left = (KeybindingAccess) leftKey;
KeybindingAccess right = (KeybindingAccess) rightKey;

if (left.snapTap$isPressedReal()) {
context.fill(5, 5, 25, 25, 0xFF444444);
} else {
context.fill(5, 5, 25, 25, 0xFF000000);
}

if (right.snapTap$isPressedReal()) {
context.fill(30, 5, 50, 25, 0xFF444444);
} else {
context.fill(30, 5, 50, 25, 0xFF000000);
}

context.drawCenteredTextWithShadow(client.textRenderer, leftKey.getBoundKeyLocalizedText(), 15, 11, -1);
context.drawCenteredTextWithShadow(client.textRenderer, rightKey.getBoundKeyLocalizedText(), 40, 11, -1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.github.betterclient.snaptap.mixins;

import io.github.betterclient.snaptap.SnapTap;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.option.GameOptions;
import net.minecraft.client.option.KeyBinding;
import org.apache.commons.lang3.ArrayUtils;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.io.File;

@Mixin(GameOptions.class)
public class MixinGameOptions {
@Mutable @Shadow @Final public KeyBinding[] allKeys;

@Inject(method = "<init>", at = @At("RETURN"))
public void onInit(MinecraftClient client, File optionsFile, CallbackInfo ci) {
this.allKeys = ArrayUtils.addAll(this.allKeys, SnapTap.TOGGLE_BIND, SnapTap.KEYSTROKES_TOGGLE_BIND);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.github.betterclient.snaptap.mixins;

import io.github.betterclient.snaptap.SnapTap;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.hud.InGameHud;
import net.minecraft.client.render.RenderTickCounter;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(InGameHud.class)
public class MixinInGameHud {
@Inject(method = "render", at = @At("RETURN"))
public void onRender(DrawContext context, RenderTickCounter tickCounter, CallbackInfo ci) {
if(SnapTap.KEYSTROKES_TOGGLED)
SnapTap.render(context);
}
}
Loading

0 comments on commit df6f640

Please sign in to comment.