Skip to content

Commit

Permalink
- Added single vs multi-block placement detection system. The mod sho…
Browse files Browse the repository at this point in the history
…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
orbwoi committed Jun 10, 2019
1 parent 3879593 commit 85633fa
Show file tree
Hide file tree
Showing 5 changed files with 331 additions and 192 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx3G
loader_version=0.4.8+build.154

# Mod Properties
mod_version = 1.0.2
mod_version = 1.0.3
maven_group = net.clayborn
archives_base_name = accurate-block-placement

Expand Down
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;
}
Loading

0 comments on commit 85633fa

Please sign in to comment.