forked from Chicken-Bones/NotEnoughItems
-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add RenderTooltipEvent Compat (#574)
Co-authored-by: Martin Robertz <dream-master@gmx.net> Co-authored-by: Maya <10861407+serenibyss@users.noreply.github.com>
- Loading branch information
1 parent
4613ade
commit 8dd36f1
Showing
4 changed files
with
137 additions
and
5 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
78 changes: 78 additions & 0 deletions
78
src/main/java/codechicken/nei/util/RenderTooltipEventHelper.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,78 @@ | ||
package codechicken.nei.util; | ||
|
||
import static com.gtnewhorizon.gtnhlib.client.event.RenderTooltipEvent.*; | ||
|
||
import java.util.List; | ||
import java.util.function.Consumer; | ||
|
||
import net.minecraft.client.gui.FontRenderer; | ||
import net.minecraft.client.gui.GuiScreen; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraftforge.common.MinecraftForge; | ||
|
||
import com.gtnewhorizon.gtnhlib.client.event.RenderTooltipEvent; | ||
|
||
public class RenderTooltipEventHelper { | ||
|
||
private static RenderTooltipEvent event; | ||
|
||
/** | ||
* @return {@code true} if the event has been canceled | ||
*/ | ||
public static boolean post(ItemStack stack, GuiScreen gui, int x, int y, FontRenderer font) { | ||
event = new RenderTooltipEvent( | ||
stack, | ||
gui, | ||
ORIGINAL_BG_START, | ||
ORIGINAL_BG_END, | ||
ORIGINAL_BORDER_START, | ||
ORIGINAL_BORDER_END, | ||
x, | ||
y, | ||
font); | ||
if (stack != null) { | ||
MinecraftForge.EVENT_BUS.post(event); | ||
if (event.isCanceled()) { | ||
flush(); | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
public static void flush() { | ||
event = null; | ||
} | ||
|
||
public static int getBackgroundStart() { | ||
return event == null ? ORIGINAL_BG_START : event.backgroundStart; | ||
} | ||
|
||
public static int getBackgroundEnd() { | ||
return event == null ? ORIGINAL_BG_END : event.backgroundEnd; | ||
} | ||
|
||
public static int getBorderStart() { | ||
return event == null ? ORIGINAL_BORDER_START : event.borderStart; | ||
} | ||
|
||
public static int getBorderEnd() { | ||
return event == null ? ORIGINAL_BORDER_END : event.borderEnd; | ||
} | ||
|
||
public static int getX() { | ||
return event.x; | ||
} | ||
|
||
public static int getY() { | ||
return event.y; | ||
} | ||
|
||
public static FontRenderer getFont() { | ||
return event.font; | ||
} | ||
|
||
public static Consumer<List<String>> getAlternativeRenderer() { | ||
return event.alternativeRenderer; | ||
} | ||
} |