Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
Draylar committed Sep 26, 2019
1 parent 912bbac commit 5f7feb7
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 109 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
plugins {
id 'fabric-loom' version '0.2.3-SNAPSHOT'
id 'fabric-loom' version '0.2.5-SNAPSHOT'
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

archivesBaseName = "modid"
archivesBaseName = "togglecrouch"
version = "1.0.0"

minecraft {
Expand Down
19 changes: 0 additions & 19 deletions src/main/java/com/github/draylar/modid/ExampleMod.java

This file was deleted.

24 changes: 0 additions & 24 deletions src/main/java/com/github/draylar/modid/common/Blocks.java

This file was deleted.

32 changes: 0 additions & 32 deletions src/main/java/com/github/draylar/modid/common/Entities.java

This file was deleted.

24 changes: 0 additions & 24 deletions src/main/java/com/github/draylar/modid/common/Items.java

This file was deleted.

59 changes: 59 additions & 0 deletions src/main/java/com/github/draylar/togglecrouch/ToggleCrouch.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.github.draylar.togglecrouch;

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.client.keybinding.FabricKeyBinding;
import net.fabricmc.fabric.api.client.keybinding.KeyBindingRegistry;
import net.fabricmc.fabric.api.event.client.ClientTickCallback;
import net.fabricmc.fabric.mixin.client.keybinding.KeyCodeAccessor;
import net.minecraft.client.options.KeyBinding;
import net.minecraft.client.util.InputUtil;
import net.minecraft.util.Identifier;
import org.lwjgl.glfw.GLFW;

public class ToggleCrouch implements ModInitializer
{
private static final String MODID = "togglecrouch";

private static FabricKeyBinding toggleCrouch = FabricKeyBinding.Builder.create(
new Identifier(MODID, "toggle"),
InputUtil.Type.KEYSYM,
GLFW.GLFW_KEY_C,
"Togglecrouch"
).build();

private static boolean isCrouching = false;
private static boolean wasJustOn = false;

@Override
public void onInitialize()
{
KeyBindingRegistry.INSTANCE.register(toggleCrouch);

ClientTickCallback.EVENT.register((client) -> {
if(client.options.keySneak.wasPressed()) {
isCrouching = false;
wasJustOn = false;
}

if(client.player != null) {
if (toggleCrouch.wasPressed()) {
isCrouching = !isCrouching;
}

if (isCrouching) {
KeyBinding.setKeyPressed(getConfiguredKeyCode(client.options.keySneak), true);
wasJustOn = true;
} else {
if(client.player.isSneaking() && wasJustOn) {
KeyBinding.setKeyPressed(getConfiguredKeyCode(client.options.keySneak), false);
wasJustOn = false;
}
}
}
});
}

private static InputUtil.KeyCode getConfiguredKeyCode(KeyBinding keyBinding) {
return ((KeyCodeAccessor) keyBinding).getKeyCode();
}
}
14 changes: 7 additions & 7 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@

{
"schemaVersion": 1,
"id": "modid",
"id": "togglecrouch",
"version": "${version}",

"name": "Example Mod",
"description": "This is an example description! Tell everyone what your mod is about!",
"name": "Toggle Crouch",
"description": "Simple toggle crouch mod.",
"authors": [
"Me!"
"Draylar"
],
"contact": {
"homepage": "https://fabricmc.net/",
"sources": "https://github.com/FabricMC/fabric-example-mod"
},

"license": "CC0-1.0",
"icon": "assets/modid/icon.png",
"icon": "assets/togglecrouch/icon.png",

"environment": "*",
"entrypoints": {
"main": [
"com.github.draylar.modid.ExampleMod"
"com.github.draylar.togglecrouch.ToggleCrouch"
]
},
"mixins": [
"modid.mixins.json"
"togglecrouch.mixins.json"
],

"requires": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"required": true,
"package": "com.github.draylar.modid.mixin",
"package": "com.github.draylar.togglecrouch.mixin",
"compatibilityLevel": "JAVA_8",
"mixins": [

Expand Down

0 comments on commit 5f7feb7

Please sign in to comment.