Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IClickEventAction and IHoverEventAction #107

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions patches/minecraft/net/minecraft/client/gui/GuiScreen.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
{
this.func_146279_a(TextFormatting.RED + "Invalid Entity!", p_175272_2_, p_175272_3_);
}
@@ -303,11 +314,7 @@
@@ -303,11 +314,9 @@
}
else if (hoverevent.func_150701_a() == HoverEvent.Action.SHOW_TEXT)
{
Expand All @@ -163,10 +163,12 @@
- p_175272_3_
- );
+ this.func_146283_a(this.field_146297_k.field_71466_p.func_78271_c(hoverevent.func_150702_b().func_150254_d(), Math.max(this.field_146294_l / 2, 200)), p_175272_2_, p_175272_3_);
+ }else if (hoverevent.func_150701_a() != null){
+ hoverevent.func_150701_a().handle(hoverevent, this, p_175272_1_, p_175272_2_, p_175272_3_);
}

GlStateManager.func_179140_f();
@@ -376,7 +383,7 @@
@@ -376,7 +385,7 @@
}
else if (clickevent.func_150669_a() == ClickEvent.Action.OPEN_FILE)
{
Expand All @@ -175,16 +177,17 @@
this.func_175282_a(uri1);
}
else if (clickevent.func_150669_a() == ClickEvent.Action.SUGGEST_COMMAND)
@@ -389,7 +396,7 @@
@@ -389,7 +398,8 @@
}
else
{
- field_175287_a.error("Don't know how to handle {}", clickevent);
+ field_175287_a.error("Don't know how to handle {}", (Object)clickevent);
+ if (clickevent.func_150669_a() != null && clickevent.func_150669_a().handle(clickevent, this, p_175276_1_)) return true;
+ else field_175287_a.error("Don't know how to handle {}", (Object)clickevent);
}

return true;
@@ -406,10 +413,13 @@
@@ -406,10 +416,13 @@

public void func_175281_b(String p_175281_1_, boolean p_175281_2_)
{
Expand All @@ -198,7 +201,7 @@

this.field_146297_k.field_71439_g.func_71165_d(p_175281_1_);
}
@@ -424,9 +434,15 @@
@@ -424,9 +437,15 @@

if (guibutton.func_146116_c(this.field_146297_k, p_73864_1_, p_73864_2_))
{
Expand All @@ -214,7 +217,7 @@
}
}
}
@@ -456,8 +472,12 @@
@@ -456,8 +475,12 @@
this.field_146289_q = p_146280_1_.field_71466_p;
this.field_146294_l = p_146280_2_;
this.field_146295_m = p_146280_3_;
Expand All @@ -227,7 +230,7 @@
}

public void func_183500_a(int p_183500_1_, int p_183500_2_)
@@ -476,7 +496,10 @@
@@ -476,7 +499,10 @@
{
while (Mouse.next())
{
Expand All @@ -238,7 +241,7 @@
}
}

@@ -484,7 +507,10 @@
@@ -484,7 +510,10 @@
{
while (Keyboard.next())
{
Expand All @@ -249,15 +252,15 @@
}
}
}
@@ -546,6 +572,7 @@
@@ -546,6 +575,7 @@
public void func_146276_q_()
{
this.func_146270_b(0);
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.client.event.GuiScreenEvent.BackgroundDrawnEvent(this));
}

public void func_146270_b(int p_146270_1_)
@@ -570,19 +597,10 @@
@@ -570,19 +600,10 @@
GlStateManager.func_179131_c(1.0F, 1.0F, 1.0F, 1.0F);
float f = 32.0F;
bufferbuilder.func_181668_a(7, DefaultVertexFormats.field_181709_i);
Expand All @@ -281,15 +284,15 @@
tessellator.func_78381_a();
}

@@ -591,7 +609,6 @@
@@ -591,7 +612,6 @@
return true;
}

- @Override
public void func_73878_a(boolean p_73878_1_, int p_73878_2_)
{
if (p_73878_2_ == 31102009)
@@ -611,13 +628,13 @@
@@ -611,13 +631,13 @@
try
{
Class<?> oclass = Class.forName("java.awt.Desktop");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
--- before/net/minecraft/util/text/event/ClickEvent.java
+++ after/net/minecraft/util/text/event/ClickEvent.java
@@ -2,6 +2,7 @@

import com.google.common.collect.Maps;
import java.util.Map;
+import java.util.Objects;

public class ClickEvent
{
@@ -41,7 +42,7 @@
}
else
{
- return this.field_150670_b != null ? this.field_150670_b.equals(clickevent.field_150670_b) : clickevent.field_150670_b == null;
+ return Objects.equals(this.field_150670_b, clickevent.field_150670_b);
}
}
else
@@ -63,7 +64,8 @@
return 31 * i + (this.field_150670_b != null ? this.field_150670_b.hashCode() : 0);
}

- public static enum Action
+ private static final Map<String, ClickEvent.Action> NAME_MAPPING = Maps.newHashMap();
+ public static enum Action implements net.minecraftforge.client.gui.text.IClickEventAction
{
OPEN_URL("open_url", true),
OPEN_FILE("open_file", false),
@@ -71,14 +73,23 @@
SUGGEST_COMMAND("suggest_command", true),
CHANGE_PAGE("change_page", true);

+ @Deprecated //Forge : use ClickEvent#NAME_MAPPING
private static final Map<String, ClickEvent.Action> field_150679_e = Maps.newHashMap();
private final boolean field_150676_f;
private final String field_150677_g;
-
- private Action(String p_i45155_3_, boolean p_i45155_4_)
- {
- this.field_150677_g = p_i45155_3_;
- this.field_150676_f = p_i45155_4_;
+ private final net.minecraftforge.client.gui.text.IClickEventAction action;
+
+ Action(net.minecraftforge.client.gui.text.IClickEventAction actionIn, String canonicalNameIn, boolean allowedInChatIn)
+ {
+ this.action = actionIn;
+ this.field_150677_g = canonicalNameIn;
+ this.field_150676_f = allowedInChatIn;
+ ClickEvent.NAME_MAPPING.put(canonicalNameIn, this);
+ }
+
+ Action(String p_i45155_3_, boolean p_i45155_4_)
+ {
+ this(net.minecraftforge.client.gui.text.IClickEventAction.EMPTY, p_i45155_3_, p_i45155_4_);
}

public boolean func_150674_a()
@@ -93,15 +104,14 @@

public static ClickEvent.Action func_150672_a(String p_150672_0_)
{
- return field_150679_e.get(p_150672_0_);
+ ClickEvent.Action action = ClickEvent.NAME_MAPPING.get(p_150672_0_);
+ if (action == null) return Action.field_150679_e.get(p_150672_0_); // if somebody has already hacked in the mapping.
+ else return action;
}

- static
- {
- for (ClickEvent.Action clickevent$action : values())
- {
- field_150679_e.put(clickevent$action.func_150673_b(), clickevent$action);
- }
+ @Override
+ public boolean handle(ClickEvent clickEvent, net.minecraft.client.gui.GuiScreen screen, net.minecraft.util.text.ITextComponent textComponent){
+ return action.handle(clickEvent, screen, textComponent);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
--- before/net/minecraft/util/text/event/HoverEvent.java
+++ after/net/minecraft/util/text/event/HoverEvent.java
@@ -64,20 +64,30 @@
return 31 * i + (this.field_150703_b != null ? this.field_150703_b.hashCode() : 0);
}

- public static enum Action
+ private static final Map<String, HoverEvent.Action> NAME_MAPPING = Maps.newHashMap();
+ public static enum Action implements net.minecraftforge.client.gui.text.IHoverEventAction
{
SHOW_TEXT("show_text", true),
SHOW_ITEM("show_item", true),
SHOW_ENTITY("show_entity", true);

+ @Deprecated //Forge : use HoverEvent#NAME_MAPPING
private static final Map<String, HoverEvent.Action> field_150690_d = Maps.newHashMap();
+
private final boolean field_150691_e;
private final String field_150688_f;
+ private final net.minecraftforge.client.gui.text.IHoverEventAction action;

- private Action(String p_i45157_3_, boolean p_i45157_4_)
- {
- this.field_150688_f = p_i45157_3_;
- this.field_150691_e = p_i45157_4_;
+ Action(net.minecraftforge.client.gui.text.IHoverEventAction actionIn, String canonicalNameIn, boolean allowedInChatIn)
+ {
+ this.field_150688_f = canonicalNameIn;
+ this.field_150691_e = allowedInChatIn;
+ this.action = actionIn;
+ HoverEvent.NAME_MAPPING.put(canonicalNameIn, this);
+ }
+ Action(String p_i45157_3_, boolean p_i45157_4_)
+ {
+ this(net.minecraftforge.client.gui.text.IHoverEventAction.EMPTY, p_i45157_3_, p_i45157_4_);
}

public boolean func_150686_a()
@@ -92,15 +102,14 @@

public static HoverEvent.Action func_150684_a(String p_150684_0_)
{
- return field_150690_d.get(p_150684_0_);
+ HoverEvent.Action action = HoverEvent.NAME_MAPPING.get(p_150684_0_);
+ if (action == null) return Action.field_150690_d.get(p_150684_0_); // if somebody has already hacked in the mapping.
+ else return action;
}

- static
- {
- for (HoverEvent.Action hoverevent$action : values())
- {
- field_150690_d.put(hoverevent$action.func_150685_b(), hoverevent$action);
- }
+ @Override
+ public void handle(HoverEvent hoverEvent, net.minecraft.client.gui.GuiScreen screen, ITextComponent textComponent, int x, int y) {
+ action.handle(hoverEvent, screen, textComponent, x, y);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package net.minecraftforge.client.gui.text;

import net.minecraft.client.gui.GuiScreen;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.event.ClickEvent;

@FunctionalInterface
public interface IClickEventAction {
IClickEventAction EMPTY = (clickEvent, screen, textComponent) -> false;
boolean handle(ClickEvent clickEvent, GuiScreen screen, ITextComponent textComponent);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package net.minecraftforge.client.gui.text;

import net.minecraft.client.gui.GuiScreen;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.event.HoverEvent;

@FunctionalInterface
public interface IHoverEventAction {
IHoverEventAction EMPTY = (hoverEvent, screen, textComponent, x, y) -> {};
void handle(HoverEvent hoverEvent, GuiScreen screen, ITextComponent textComponent, int x, int y);
}