-
-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added modifier key states to TooltipFlag and Level to TooltipContext (#…
- Loading branch information
1 parent
682a618
commit c556779
Showing
6 changed files
with
132 additions
and
3 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
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
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- a/net/minecraft/world/item/TooltipFlag.java | ||
+++ b/net/minecraft/world/item/TooltipFlag.java | ||
@@ -8,6 +_,27 @@ | ||
|
||
boolean isCreative(); | ||
|
||
+ /** | ||
+ * Neo: Returns the state of the Control key (as reported by Screen) on the client, or {@code false} on the server. | ||
+ */ | ||
+ default boolean hasControlDown() { | ||
+ return false; | ||
+ } | ||
+ | ||
+ /** | ||
+ * Neo: Returns the state of the Shift key (as reported by Screen) on the client, or {@code false} on the server. | ||
+ */ | ||
+ default boolean hasShiftDown() { | ||
+ return false; | ||
+ } | ||
+ | ||
+ /** | ||
+ * Neo: Returns the state of the Alt key (as reported by Screen) on the client, or {@code false} on the server. | ||
+ */ | ||
+ default boolean hasAltDown() { | ||
+ return false; | ||
+ } | ||
+ | ||
public static record Default(boolean advanced, boolean creative) implements TooltipFlag { | ||
@Override | ||
public boolean isAdvanced() { |
49 changes: 49 additions & 0 deletions
49
src/main/java/net/neoforged/neoforge/client/ClientTooltipFlag.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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright (c) NeoForged and contributors | ||
* SPDX-License-Identifier: LGPL-2.1-only | ||
*/ | ||
|
||
package net.neoforged.neoforge.client; | ||
|
||
import net.minecraft.client.gui.screens.Screen; | ||
import net.minecraft.world.item.TooltipFlag; | ||
import org.jetbrains.annotations.ApiStatus; | ||
|
||
/** | ||
* A version of {@link TooltipFlag} that knows about Screen and can provide modifier key states. It is patched into all vanilla uses of TooltipFlags in client classes. | ||
* <p> | ||
* When calling any tooltip method that needs a TooltipFlag yourself, use either this (by calling {@link #of(TooltipFlag)}) or {@link TooltipFlag.Default} depending on the <em>logical</em> side you're on. | ||
*/ | ||
public record ClientTooltipFlag(boolean advanced, boolean creative, boolean shiftDown, boolean controlDown, boolean altDown) implements TooltipFlag { | ||
@ApiStatus.Internal | ||
public ClientTooltipFlag {} | ||
|
||
@Override | ||
public boolean isAdvanced() { | ||
return this.advanced; | ||
} | ||
|
||
@Override | ||
public boolean isCreative() { | ||
return this.creative; | ||
} | ||
|
||
@Override | ||
public boolean hasControlDown() { | ||
return controlDown; | ||
} | ||
|
||
@Override | ||
public boolean hasShiftDown() { | ||
return shiftDown; | ||
} | ||
|
||
@Override | ||
public boolean hasAltDown() { | ||
return altDown; | ||
} | ||
|
||
public static TooltipFlag of(TooltipFlag other) { | ||
return new ClientTooltipFlag(other.isAdvanced(), other.isCreative(), Screen.hasShiftDown(), Screen.hasControlDown(), Screen.hasAltDown()); | ||
} | ||
} |