mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-12 08:17:35 +00:00
Changed control flow of post mouse events to allow listening to events handled by vanilla. (#8133)
This commit is contained in:
1 parent
b639bcb5c7
commit
28dd76ebbf
3 files changed
+91
-19
No files matched your search
Regular → Executable
+9
-5
@@ -8,21 +8,25 @@
|
||||
boolean[] aboolean = new boolean[]{false};
|
||||
if (this.f_91503_.m_91265_() == null) {
|
||||
if (this.f_91503_.f_91080_ == null) {
|
||||
@@ -82,11 +_,15 @@
|
||||
@@ -82,11 +_,19 @@
|
||||
if (flag) {
|
||||
screen.m_169415_();
|
||||
Screen.m_96579_(() -> {
|
||||
- aboolean[0] = screen.m_6375_(d0, d1, i);
|
||||
+ aboolean[0] = net.minecraftforge.client.ForgeHooksClient.onGuiMouseClickedPre(this.f_91503_.f_91080_, d0, d1, i);
|
||||
+ if (!aboolean[0]) aboolean[0] = this.f_91503_.f_91080_.m_6375_(d0, d1, i);
|
||||
+ if (!aboolean[0]) aboolean[0] = net.minecraftforge.client.ForgeHooksClient.onGuiMouseClickedPost(this.f_91503_.f_91080_, d0, d1, i);
|
||||
+ if (!aboolean[0]) {
|
||||
+ aboolean[0] = this.f_91503_.f_91080_.m_6375_(d0, d1, i);
|
||||
+ aboolean[0] = net.minecraftforge.client.ForgeHooksClient.onGuiMouseClickedPost(this.f_91503_.f_91080_, d0, d1, i, aboolean[0]);
|
||||
+ }
|
||||
}, "mouseClicked event handler", screen.getClass().getCanonicalName());
|
||||
} else {
|
||||
Screen.m_96579_(() -> {
|
||||
- aboolean[0] = screen.m_6348_(d0, d1, i);
|
||||
+ aboolean[0] = net.minecraftforge.client.ForgeHooksClient.onGuiMouseReleasedPre(this.f_91503_.f_91080_, d0, d1, i);
|
||||
+ if (!aboolean[0]) aboolean[0] = this.f_91503_.f_91080_.m_6348_(d0, d1, i);
|
||||
+ if (!aboolean[0]) aboolean[0] = net.minecraftforge.client.ForgeHooksClient.onGuiMouseReleasedPost(this.f_91503_.f_91080_, d0, d1, i);
|
||||
+ if (!aboolean[0]) {
|
||||
+ aboolean[0] = this.f_91503_.f_91080_.m_6348_(d0, d1, i);
|
||||
+ aboolean[0] = net.minecraftforge.client.ForgeHooksClient.onGuiMouseReleasedPost(this.f_91503_.f_91080_, d0, d1, i, aboolean[0]);
|
||||
+ }
|
||||
}, "mouseReleased event handler", screen.getClass().getCanonicalName());
|
||||
}
|
||||
}
|
||||
|
||||
Regular → Executable
+10
-6
@@ -717,10 +717,12 @@ public class ForgeHooksClient
|
||||
return MinecraftForge.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static boolean onGuiMouseClickedPost(Screen guiScreen, double mouseX, double mouseY, int button)
|
||||
public static boolean onGuiMouseClickedPost(Screen guiScreen, double mouseX, double mouseY, int button, boolean handled)
|
||||
{
|
||||
Event event = new GuiScreenEvent.MouseClickedEvent.Post(guiScreen, mouseX, mouseY, button);
|
||||
return MinecraftForge.EVENT_BUS.post(event);
|
||||
Event event = new GuiScreenEvent.MouseClickedEvent.Post(guiScreen, mouseX, mouseY, button, handled);
|
||||
event.setCanceled(handled);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
return event.getResult() == Event.Result.DEFAULT ? handled : event.getResult() == Event.Result.ALLOW;
|
||||
}
|
||||
|
||||
public static boolean onGuiMouseReleasedPre(Screen guiScreen, double mouseX, double mouseY, int button)
|
||||
@@ -729,10 +731,12 @@ public class ForgeHooksClient
|
||||
return MinecraftForge.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static boolean onGuiMouseReleasedPost(Screen guiScreen, double mouseX, double mouseY, int button)
|
||||
public static boolean onGuiMouseReleasedPost(Screen guiScreen, double mouseX, double mouseY, int button, boolean handled)
|
||||
{
|
||||
Event event = new GuiScreenEvent.MouseReleasedEvent.Post(guiScreen, mouseX, mouseY, button);
|
||||
return MinecraftForge.EVENT_BUS.post(event);
|
||||
Event event = new GuiScreenEvent.MouseReleasedEvent.Post(guiScreen, mouseX, mouseY, button, handled);
|
||||
event.setCanceled(handled);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
return event.getResult() == Event.Result.DEFAULT ? handled : event.getResult() == Event.Result.ALLOW;
|
||||
}
|
||||
|
||||
public static boolean onGuiMouseDragPre(Screen guiScreen, double mouseX, double mouseY, int mouseButton, double dragX, double dragY)
|
||||
|
||||
Regular → Executable
+72
-8
@@ -283,15 +283,47 @@ public class GuiScreenEvent extends Event
|
||||
}
|
||||
|
||||
/**
|
||||
* This event fires after {@link IGuiEventListener#mouseClicked(double, double, int)} if the click was not already handled.
|
||||
* Cancel this event when you successfully use the mouse click, to prevent other handlers from using the same input.
|
||||
* This event fires after {@link GuiEventListener#mouseClicked(double, double, int)}.
|
||||
*
|
||||
* <p>This event {@linkplain HasResult has a result}.<br>
|
||||
* <ul>
|
||||
* <li><b>{@link Result#ALLOW}</b> - to force set the mouse click as handled</li>
|
||||
* <li><b>{@link Result#DEFAULT}</b> - to use the default value of {@link #handled}</li>
|
||||
* <li><b>{@link Result#DENY}</b> - to force set the mouse click as not handled</li>
|
||||
* </ul>
|
||||
* </p>
|
||||
*
|
||||
* <p>Note that this event is currently pre-cancelled if {@link Screen#mouseClicked} returns {@code true}
|
||||
* to retain old behavior. This will be changed in 1.18 when the event is made non-cancellable.</p>
|
||||
*/
|
||||
@Cancelable
|
||||
@Cancelable // TODO: Make non-cancellable in 1.18.
|
||||
@HasResult
|
||||
public static class Post extends MouseClickedEvent
|
||||
{
|
||||
public Post(Screen gui, double mouseX, double mouseY, int button)
|
||||
private final boolean handled;
|
||||
|
||||
public Post(Screen gui, double mouseX, double mouseY, int button, boolean handled)
|
||||
{
|
||||
super(gui, mouseX, mouseY, button);
|
||||
this.handled = handled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated event now has a result instead and will no longer be cancellable in 1.18; use {@link #setResult(Result)}
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public void setCanceled(boolean cancel)
|
||||
{
|
||||
this.setResult(cancel ? Result.ALLOW : Result.DEFAULT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@code true} if the mouse click was already handled by its screen
|
||||
*/
|
||||
public boolean wasHandled()
|
||||
{
|
||||
return handled;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -325,15 +357,47 @@ public class GuiScreenEvent extends Event
|
||||
}
|
||||
|
||||
/**
|
||||
* This event fires after {@link IGuiEventListener#mouseReleased(double, double, int)} if the release was not already handled.
|
||||
* Cancel this event when you successfully use the mouse release, to prevent other handlers from using the same input.
|
||||
* This event fires after {@link GuiEventListener#mouseReleased(double, double, int)}.
|
||||
*
|
||||
* <p>This event {@linkplain HasResult has a result}.<br>
|
||||
* <ul>
|
||||
* <li><b>{@link Result#ALLOW}</b> - to force set the mouse release as handled</li>
|
||||
* <li><b>{@link Result#DEFAULT}</b> - to use the default value of {@link #handled}</li>
|
||||
* <li><b>{@link Result#DENY}</b> - to force set the mouse release as not handled</li>
|
||||
* </ul>
|
||||
* </p>
|
||||
*
|
||||
* <p>Note that this event is currently pre-cancelled if {@link Screen#mouseReleased} returns {@code true}
|
||||
* to retain old behavior. This will be changed in 1.18 when the event is made non-cancellable.</p>
|
||||
*/
|
||||
@Cancelable
|
||||
@Cancelable // TODO: Make non-cancellable in 1.18.
|
||||
@HasResult
|
||||
public static class Post extends MouseReleasedEvent
|
||||
{
|
||||
public Post(Screen gui, double mouseX, double mouseY, int button)
|
||||
private final boolean handled;
|
||||
|
||||
public Post(Screen gui, double mouseX, double mouseY, int button, boolean handled)
|
||||
{
|
||||
super(gui, mouseX, mouseY, button);
|
||||
this.handled = handled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated event now has a result instead and will no longer be cancellable in 1.18; use {@link #setResult(Result)}
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public void setCanceled(boolean cancel)
|
||||
{
|
||||
this.setResult(cancel ? Result.ALLOW : Result.DEFAULT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@code true} if the mouse release was already handled by its screen
|
||||
*/
|
||||
public boolean wasHandled()
|
||||
{
|
||||
return handled;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user