forked from orbwoi/AccurateBlockPlacement
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Flourick
committed
Sep 2, 2020
1 parent
52ac81c
commit 17338c3
Showing
10 changed files
with
94 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 24 additions & 45 deletions
69
src/main/java/net/clayborn/accurateblockplacement/AccurateBlockPlacementMod.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,47 @@ | ||
package net.clayborn.accurateblockplacement; | ||
|
||
import java.util.UUID; | ||
|
||
import org.lwjgl.glfw.GLFW; | ||
|
||
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.api.client.event.lifecycle.v1.ClientTickEvents; | ||
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.options.KeyBinding; | ||
import net.minecraft.client.util.InputUtil; | ||
import net.minecraft.network.MessageType; | ||
import net.minecraft.text.TranslatableText; | ||
import net.minecraft.util.Identifier; | ||
|
||
public class AccurateBlockPlacementMod implements ModInitializer | ||
{ | ||
// global state | ||
public static Boolean disableNormalItemUse = false; | ||
public static boolean isAccurateBlockPlacementEnabled = true; | ||
|
||
private static FabricKeyBinding keyBinding; | ||
public static Boolean disableNormalItemUse = false; | ||
public static boolean isAccurateBlockPlacementEnabled = true; | ||
|
||
private static boolean wasAccurateBlockPlacementToggleKeyPressed = false; | ||
|
||
final static String KEY_CATEGORY_NAME = "Accurate Block Placement"; | ||
public static MinecraftClient MC; | ||
|
||
@Override | ||
public void onInitialize() | ||
{ | ||
keyBinding = FabricKeyBinding.Builder.create( | ||
new Identifier("accurateblockplacement", "togglevanillaplacement"), | ||
InputUtil.Type.KEYSYM, | ||
GLFW.GLFW_KEY_UNKNOWN, | ||
KEY_CATEGORY_NAME | ||
).build(); | ||
MC = MinecraftClient.getInstance(); | ||
|
||
KeyBindingRegistry.INSTANCE.addCategory(KEY_CATEGORY_NAME); | ||
KeyBindingRegistry.INSTANCE.register(keyBinding); | ||
KeyBinding keybind = KeyBindingHelper.registerKeyBinding(new KeyBinding("net.clayborn.accurateblockplacement.togglevanillaplacement", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_UNKNOWN, "Accurate Block Placement")); | ||
|
||
ClientTickCallback.EVENT.register(e -> { | ||
MinecraftClient client = MinecraftClient.getInstance(); | ||
|
||
if (client == null || client.inGameHud == null) return; | ||
|
||
if(keyBinding.isPressed()) { | ||
if(!wasAccurateBlockPlacementToggleKeyPressed) { | ||
isAccurateBlockPlacementEnabled = !isAccurateBlockPlacementEnabled; | ||
|
||
TranslatableText message = null; | ||
|
||
if(isAccurateBlockPlacementEnabled) { | ||
message = new TranslatableText("net.clayborn.accurateblockplacement.modplacementmodemessage"); | ||
} | ||
else { | ||
message = new TranslatableText("net.clayborn.accurateblockplacement.vanillaplacementmodemessage"); | ||
} | ||
|
||
client.inGameHud.addChatMessage(MessageType.SYSTEM, message); | ||
} | ||
wasAccurateBlockPlacementToggleKeyPressed = true; | ||
ClientTickEvents.END_CLIENT_TICK.register(e -> { | ||
while(keybind.wasPressed()) { | ||
isAccurateBlockPlacementEnabled = !isAccurateBlockPlacementEnabled; | ||
|
||
TranslatableText message = null; | ||
|
||
if(isAccurateBlockPlacementEnabled) { | ||
message = new TranslatableText("net.clayborn.accurateblockplacement.modplacementmodemessage"); | ||
} | ||
else { | ||
message = new TranslatableText("net.clayborn.accurateblockplacement.vanillaplacementmodemessage"); | ||
} | ||
|
||
MC.inGameHud.addChatMessage(MessageType.SYSTEM, message, UUID.fromString("00000000-0000-0000-0000-000000000000")); | ||
} | ||
else { | ||
wasAccurateBlockPlacementToggleKeyPressed = false; | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/resources/assets/accurateblockplacement/lang/en_us.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"key.accurateblockplacement.togglevanillaplacement": "Toggle Vanilla Placement (report bugs!)", | ||
"net.clayborn.accurateblockplacement.togglevanillaplacement": "Toggle Vanilla Placement", | ||
"net.clayborn.accurateblockplacement.modplacementmodemessage": "Accurate block placement mode is now enabled.", | ||
"net.clayborn.accurateblockplacement.vanillaplacementmodemessage": "Vanilla block placement mode is now enabled (please report any bugs or issues)." | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters