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.
- Added single vs multi-block placement detection system. The mod sho…
…uld no longer sometimes place two blocks when pressing right click once. Your torches or saplings are now safe :) - Added keybind to disable new placement mode for emergencies. If you ever need to use this, please report an issue describing the problem or annoyance! Signed-off-by: Clayborn <4501752+orbwoi@users.noreply.github.com>
- Loading branch information
Showing
5 changed files
with
331 additions
and
192 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
70 changes: 62 additions & 8 deletions
70
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,17 +1,71 @@ | ||
package net.clayborn.accurateblockplacement; | ||
|
||
import org.lwjgl.glfw.GLFW; | ||
|
||
import net.fabricmc.api.ModInitializer; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.Vec3d; | ||
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.minecraft.ChatFormat; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.util.InputUtil; | ||
import net.minecraft.network.chat.ChatMessageType; | ||
import net.minecraft.network.chat.Style; | ||
import net.minecraft.network.chat.TranslatableComponent; | ||
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; | ||
|
||
private static boolean wasAccurateBlockPlacementToggleKeyPressed = false; | ||
|
||
final static String KEY_CATEGORY_NAME = "Accurate Block Placement"; | ||
|
||
@Override | ||
public void onInitialize() { | ||
// nothing to do | ||
|
||
keyBinding = FabricKeyBinding.Builder.create( | ||
new Identifier("accurateblockplacement", "togglevanillaplacement"), | ||
InputUtil.Type.KEYSYM, | ||
GLFW.GLFW_KEY_UNKNOWN, | ||
KEY_CATEGORY_NAME | ||
).build(); | ||
|
||
KeyBindingRegistry.INSTANCE.addCategory(KEY_CATEGORY_NAME); | ||
KeyBindingRegistry.INSTANCE.register(keyBinding); | ||
|
||
ClientTickCallback.EVENT.register(e -> | ||
{ | ||
MinecraftClient client = MinecraftClient.getInstance(); | ||
if (client == null || client.inGameHud == null) return; | ||
|
||
if(keyBinding.isPressed()) | ||
{ | ||
if (!wasAccurateBlockPlacementToggleKeyPressed) | ||
{ | ||
isAccurateBlockPlacementEnabled = !isAccurateBlockPlacementEnabled; | ||
|
||
TranslatableComponent message = null; | ||
|
||
if (isAccurateBlockPlacementEnabled) { | ||
message = new TranslatableComponent("net.clayborn.accurateblockplacement.modplacementmodemessage"); | ||
} else { | ||
message = new TranslatableComponent("net.clayborn.accurateblockplacement.vanillaplacementmodemessage"); | ||
} | ||
|
||
message.setStyle((new Style()).setColor(ChatFormat.DARK_AQUA)); | ||
|
||
client.inGameHud.addChatMessage(ChatMessageType.SYSTEM, message); | ||
} | ||
wasAccurateBlockPlacementToggleKeyPressed = true; | ||
} else { | ||
wasAccurateBlockPlacementToggleKeyPressed = false; | ||
} | ||
}); | ||
} | ||
|
||
public static BlockPos lastSeenBlockPos = null; | ||
public static BlockPos lastPlacedBlockPos = null; | ||
public static Vec3d lastPlayerPlacedBlockPos = null; | ||
public static Boolean disableNormalItemUse = false; | ||
} |
Oops, something went wrong.