Add event for controlling potion indicators size (#8483)

This event allows forcing the rendering of the potion indicators in the
inventory screen to either compact mode (icons only) or classic mode
(full width with potion effect name).
This commit is contained in:
sciwhiz12 authored and GitHub committed 2022-03-06 14:31:12 +00:00
1 parent 3dcb4a2c9c
commit 898696d770
5 files changed
+108 -38

No files matched your search

@@ -1067,4 +1067,11 @@ public class ForgeHooksClient
return vanillaOne ? -1 : 1;
};
}
public static Event.Result onScreenPotionSize(Screen screen)
{
final ScreenEvent.PotionSizeEvent event = new ScreenEvent.PotionSizeEvent(screen);
MinecraftForge.EVENT_BUS.post(event);
return event.getResult();
}
}
@@ -18,8 +18,10 @@ import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraft.client.gui.screens.Screen;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.Cancelable;
import net.minecraftforge.eventbus.api.Event;
import net.minecraftforge.fml.LogicalSide;
import org.lwjgl.glfw.GLFW;
/**
@@ -209,7 +211,12 @@ public class ScreenEvent extends Event
* This event fires in {@link EffectRenderingInventoryScreen} in the
* {@code checkEffectRendering} method when potion effects are active and the gui wants to move over.
* Cancel this event to prevent the Gui from being moved.
*
* @deprecated This event was made redundant by the removal of the screen shifting due to potion indicators in the
* inventory screen (along with being moved to the right hand side). This has been changed to have no effect, and
* will be removed in 1.19. See {@link PotionSizeEvent} as a possible alternative instead.
*/
@Deprecated(forRemoval = true, since = "1.18.1")
@Cancelable
public static class PotionShiftEvent extends ScreenEvent
{
@@ -219,6 +226,33 @@ public class ScreenEvent extends Event
}
}
/**
* Fired to determine whether to render the potion indicators in the {@link EffectRenderingInventoryScreen inventory
* screen} in compact or classic mode.
*
* <p>This event is not {@linkplain Cancelable cancelable} and {@linkplain HasResult has a result}. </p>
* <ul>
* <li>{@link Result#ALLOW} - forcibly renders the potion indicators in <em>compact</em> mode.</li>
* <li>{@link Result#DEFAULT} - defaults to vanilla behavior to using compact mode if the the screen width is too
* small for classic rendering of potion indicators.</li>
* <li>{@link Result#DENY} - forcibly renders the potion indicators in <em>classic</em> mode.</li>
* </ul>
*
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
*/
@HasResult
public static class PotionSizeEvent extends ScreenEvent
{
/**
* @hidden For internal use only.
*/
public PotionSizeEvent(Screen screen)
{
super(screen);
}
}
public static abstract class MouseInputEvent extends ScreenEvent
{
private final double mouseX;