Skip to content

Commit

Permalink
Move block state smooth/unsmooth to its own keybind
Browse files Browse the repository at this point in the history
  • Loading branch information
Cadiboo committed Feb 9, 2024
1 parent 635e228 commit 526fa53
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static void onClientJoinServer(ClientPlayerNetworkEvent.LoggingIn event)
if (!NoCubesNetwork.currentServerHasNoCubes) {
// This lets players not phase through the ground on servers that don't have NoCubes installed
NoCubesConfig.Server.collisionsEnabled = false;
ClientUtil.warnPlayer(NoCubes.MOD_ID + ".notification.notInstalledOnServer", KeyMappings.translate(KeyMappings.TOGGLE_SMOOTHABLE));
ClientUtil.warnPlayer(NoCubes.MOD_ID + ".notification.notInstalledOnServer", KeyMappings.translate(KeyMappings.TOGGLE_SMOOTHABLE_BLOCK_TYPE));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static void sendPlayerInfoMessage() {
if (NoCubesConfig.Client.infoMessage)
Minecraft.getInstance().player.sendSystemMessage(
Component.translatable(NoCubes.MOD_ID + ".notification.infoMessage",
KeyMappings.translate(KeyMappings.TOGGLE_SMOOTHABLE),
KeyMappings.translate(KeyMappings.TOGGLE_SMOOTHABLE_BLOCK_TYPE),
NoCubesConfig.Client.INFO_MESSAGE,
clientConfigComponent()
).withStyle(ChatFormatting.GREEN));
Expand Down
19 changes: 12 additions & 7 deletions src/main/java/io/github/cadiboo/nocubes/client/KeyMappings.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,21 @@ public final class KeyMappings {
private static final Logger LOG = LogManager.getLogger();

public static final String TOGGLE_VISUALS = "toggleVisuals";
public static final String TOGGLE_SMOOTHABLE = "toggleSmoothable";
/**
* It is tedious to have to add/remove each block state for blocks that have many states with little to no visual difference.
* Leaves are a primary example of this.
* Therefore, the default add/remove keybind changes all block states for the targeted block.
* We have {@link #TOGGLE_SMOOTHABLE_BLOCK_STATE a separate keybind} that only changes a single state to give players that want it more fine-grained control.
*/
public static final String TOGGLE_SMOOTHABLE_BLOCK_TYPE = "toggleSmoothable";
public static final String TOGGLE_SMOOTHABLE_BLOCK_STATE = "toggleSmoothableBlockState";

public static void register(RegisterKeyMappingsEvent registerEvent, IEventBus forgeBus) {
LOG.debug("Registering keybindings");
var keybindings = Lists.newArrayList(
makeKeybinding(registerEvent, TOGGLE_VISUALS, InputConstants.UNKNOWN.getValue(), KeyMappings::toggleVisuals),
makeKeybinding(registerEvent, TOGGLE_SMOOTHABLE, GLFW.GLFW_KEY_N, KeyMappings::toggleLookedAtSmoothable)
makeKeybinding(registerEvent, TOGGLE_SMOOTHABLE_BLOCK_TYPE, GLFW.GLFW_KEY_N, () -> toggleLookedAtSmoothable(true)),
makeKeybinding(registerEvent, TOGGLE_SMOOTHABLE_BLOCK_STATE, InputConstants.UNKNOWN.getValue(), () -> toggleLookedAtSmoothable(false))
);
forgeBus.addListener((TickEvent.ClientTickEvent tickEvent) -> {
if (tickEvent.phase != TickEvent.Phase.END)
Expand Down Expand Up @@ -75,7 +83,7 @@ private static void toggleVisuals() {
reloadAllChunks("toggleVisuals was pressed");
}

private static void toggleLookedAtSmoothable() {
private static void toggleLookedAtSmoothable(boolean changeAllStatesOfBlock) {
var minecraft = Minecraft.getInstance();
var world = minecraft.level;
var player = minecraft.player;
Expand All @@ -88,10 +96,7 @@ private static void toggleLookedAtSmoothable() {
var targeted = ((BlockHitResult) lookingAt);
var targetedState = world.getBlockState(targeted.getBlockPos());
var newValue = !NoCubes.smoothableHandler.isSmoothable(targetedState);
// Add all states if the player is not crouching (to make it easy to toggle on/off all leaves)
// If the player needs fine-grained control over which specific blockstates are smoothable they can crouch
// (Yes I know it says shift, it actually checks the crouch key)
var states = player.isShiftKeyDown() ? new BlockState[]{targetedState} : ModUtil.getStates(targetedState.getBlock()).toArray(BlockState[]::new);
var states = changeAllStatesOfBlock ? ModUtil.getStates(targetedState.getBlock()).toArray(BlockState[]::new) : new BlockState[] {targetedState};

LOG.debug("toggleLookedAtSmoothable currentServerHasNoCubes={}", NoCubesNetwork.currentServerHasNoCubes);
if (!NoCubesNetwork.currentServerHasNoCubes) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/assets/nocubes/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"nocubes.keycategory": "NoCubes",
"nocubes.key.toggleVisuals": "Toggle rendering",
"nocubes.key.toggleSmoothable": "Toggle block smoothness",
"nocubes.key.toggleSmoothableBlockType": "Toggle block smoothness",
"nocubes.key.toggleSmoothableBlockState": "Toggle specific block state smoothness",

"nocubes.config.infoMessage": "NoCubes info message",
"nocubes.config.render": "NoCubes rendering",
Expand Down

0 comments on commit 526fa53

Please sign in to comment.