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

@@ -1,30 +1,13 @@
--- a/net/minecraft/client/gui/screens/inventory/EffectRenderingInventoryScreen.java
+++ b/net/minecraft/client/gui/screens/inventory/EffectRenderingInventoryScreen.java
@@ -32,13 +_,21 @@
}
public boolean m_194018_() {
- int i = this.f_97735_ + this.f_97726_ + 2;
+ int i;
+ if(cancelShift)
+ i = (this.f_96543_ - this.f_97726_) / 2;
+ else
+ i = this.f_97735_ + this.f_97726_ + 2;
int j = this.f_96543_ - i;
return j >= 32;
}
private void m_194014_(PoseStack p_194015_, int p_194016_, int p_194017_) {
- int i = this.f_97735_ + this.f_97726_ + 2;
+ int i;
+ if(cancelShift)
+ i = (this.f_96543_ - this.f_97726_) / 2;
+ else
+ i = this.f_97735_ + this.f_97726_ + 2;
int j = this.f_96543_ - i;
Collection<MobEffectInstance> collection = this.f_96541_.f_91074_.m_21220_();
@@ -44,12 +_,15 @@
if (!collection.isEmpty() && j >= 32) {
@@ -49,7 +_,8 @@
RenderSystem.m_157429_(1.0F, 1.0F, 1.0F, 1.0F);
boolean flag = j >= 120;
+ var event = net.minecraftforge.client.ForgeHooksClient.onScreenPotionSize(this);
+ if (event != net.minecraftforge.eventbus.api.Event.Result.DEFAULT) flag = event == net.minecraftforge.eventbus.api.Event.Result.DENY; // true means classic mode
int k = 33;
if (collection.size() > 5) {
k = 132 / (collection.size() - 1);
}
@@ -47,17 +30,3 @@
Component component = this.m_194000_(mobeffectinstance);
this.f_96547_.m_92763_(p_98723_, component, (float)(p_98724_ + 10 + 18), (float)(i + 6), 16777215);
String s = MobEffectUtil.m_19581_(mobeffectinstance, 1.0F);
@@ -126,5 +_,13 @@
}
return mutablecomponent;
+ }
+
+ // FORGE START
+ boolean cancelShift = false;
+ @Override
+ protected void m_7856_() {
+ super.m_7856_();
+ cancelShift = net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.client.event.ScreenEvent.PotionShiftEvent(this));
}
}
@@ -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;
@@ -0,0 +1,58 @@
/*
* Minecraft Forge - Forge Development LLC
* SPDX-License-Identifier: LGPL-2.1-only
*/
package net.minecraftforge.debug.client;
import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.ScreenEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.Event;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.loading.FMLEnvironment;
import java.util.Objects;
/**
* Test mod for {@link net.minecraftforge.client.event.ScreenEvent.PotionSizeEvent}. When enabled, this mod forces the
* potion indicators in the {@linkplain net.minecraft.client.gui.screens.inventory.EffectRenderingInventoryScreen
* inventory screen} to either render in compact mode when there are less than or equal to three active effects on the player,
* or render in classic mode if there are more than three active effects.
*/
@Mod(PotionSizeEventTest.MODID)
public class PotionSizeEventTest
{
static final String MODID = "potion_size_event_test";
public static final boolean ENABLED = false;
public PotionSizeEventTest()
{
if (ENABLED && FMLEnvironment.dist == Dist.CLIENT)
{
MinecraftForge.EVENT_BUS.register(ClientEventHandler.class);
}
}
static final class ClientEventHandler
{
@SubscribeEvent
public static void onPotionSize(ScreenEvent.PotionSizeEvent event)
{
if (!ENABLED) return;
final LocalPlayer player = Objects.requireNonNull(Minecraft.getInstance().player);
if (player.getActiveEffects().size() <= 3)
{
event.setResult(Event.Result.ALLOW); // Force compact mode for 3 or less active effects
} else
{
event.setResult(Event.Result.DENY); // Force classic mode for 4 or more active effects
}
}
}
}
+2
View File
@@ -198,5 +198,7 @@ license="LGPL v2.1"
modId="hidden_tooltip_parts"
[[mods]]
modId="gametest_test"
[[mods]]
modId="potion_size_event_test"
# ADD ABOVE THIS LINE