mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-20 12:20:11 +00:00
[1.18] Allow custom rarities to directly modify the style (#8648)
This commit is contained in:
1 parent
ccaa20b006
commit
15bd5f0d30
5 files changed
+93
-3
No files matched your search
@@ -27,7 +27,13 @@
|
||||
}
|
||||
}
|
||||
|
||||
@@ -625,7 +_,8 @@
|
||||
@@ -620,12 +_,13 @@
|
||||
public void m_93069_(PoseStack p_93070_) {
|
||||
this.f_92986_.m_91307_().m_6180_("selectedItemName");
|
||||
if (this.f_92993_ > 0 && !this.f_92994_.m_41619_()) {
|
||||
- MutableComponent mutablecomponent = (new TextComponent("")).m_7220_(this.f_92994_.m_41786_()).m_130940_(this.f_92994_.m_41791_().f_43022_);
|
||||
+ MutableComponent mutablecomponent = (new TextComponent("")).m_7220_(this.f_92994_.m_41786_()).m_130938_(this.f_92994_.m_41791_().getStyleModifier());
|
||||
if (this.f_92994_.m_41788_()) {
|
||||
mutablecomponent.m_130940_(ChatFormatting.ITALIC);
|
||||
}
|
||||
|
||||
|
||||
@@ -197,6 +197,15 @@
|
||||
this.m_41721_(this.m_41773_());
|
||||
}
|
||||
|
||||
@@ -599,7 +_,7 @@
|
||||
|
||||
public List<Component> m_41651_(@Nullable Player p_41652_, TooltipFlag p_41653_) {
|
||||
List<Component> list = Lists.newArrayList();
|
||||
- MutableComponent mutablecomponent = (new TextComponent("")).m_7220_(this.m_41786_()).m_130940_(this.m_41791_().f_43022_);
|
||||
+ MutableComponent mutablecomponent = (new TextComponent("")).m_7220_(this.m_41786_()).m_130938_(this.m_41791_().getStyleModifier());
|
||||
if (this.m_41788_()) {
|
||||
mutablecomponent.m_130940_(ChatFormatting.ITALIC);
|
||||
}
|
||||
@@ -738,6 +_,7 @@
|
||||
}
|
||||
}
|
||||
@@ -226,6 +235,15 @@
|
||||
return multimap;
|
||||
}
|
||||
|
||||
@@ -904,7 +_,7 @@
|
||||
|
||||
MutableComponent mutablecomponent1 = ComponentUtils.m_130748_(mutablecomponent);
|
||||
if (!this.f_41591_) {
|
||||
- mutablecomponent1.m_130940_(this.m_41791_().f_43022_).m_130938_((p_204127_) -> {
|
||||
+ mutablecomponent1.m_130938_(this.m_41791_().getStyleModifier()).m_130938_((p_204127_) -> {
|
||||
return p_204127_.m_131144_(new HoverEvent(HoverEvent.Action.f_130832_, new HoverEvent.ItemStackInfo(this)));
|
||||
});
|
||||
}
|
||||
@@ -957,12 +_,31 @@
|
||||
this.m_41720_().m_5929_(p_41732_, p_41733_, this, p_41734_);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
--- a/net/minecraft/world/item/Rarity.java
|
||||
+++ b/net/minecraft/world/item/Rarity.java
|
||||
@@ -2,7 +_,7 @@
|
||||
@@ -2,15 +_,36 @@
|
||||
|
||||
import net.minecraft.ChatFormatting;
|
||||
|
||||
@@ -9,13 +9,32 @@
|
||||
COMMON(ChatFormatting.WHITE),
|
||||
UNCOMMON(ChatFormatting.YELLOW),
|
||||
RARE(ChatFormatting.AQUA),
|
||||
@@ -12,5 +_,9 @@
|
||||
EPIC(ChatFormatting.LIGHT_PURPLE);
|
||||
|
||||
+ /** @deprecated Forge: Use {@link #getStyleModifier()} */
|
||||
+ @Deprecated
|
||||
public final ChatFormatting f_43022_;
|
||||
+ private final java.util.function.UnaryOperator<net.minecraft.network.chat.Style> styleModifier;
|
||||
|
||||
private Rarity(ChatFormatting p_43028_) {
|
||||
this.f_43022_ = p_43028_;
|
||||
+ this.styleModifier = style -> style.m_131140_(p_43028_);
|
||||
+ }
|
||||
+
|
||||
+ Rarity(java.util.function.UnaryOperator<net.minecraft.network.chat.Style> styleModifier) {
|
||||
+ this.f_43022_ = ChatFormatting.BLACK;
|
||||
+ this.styleModifier = styleModifier;
|
||||
+ }
|
||||
+
|
||||
+ public java.util.function.UnaryOperator<net.minecraft.network.chat.Style> getStyleModifier() {
|
||||
+ return this.styleModifier;
|
||||
+ }
|
||||
+
|
||||
+ public static Rarity create(String name, ChatFormatting p_43028_) {
|
||||
+ throw new IllegalStateException("Enum not extended");
|
||||
+ }
|
||||
+
|
||||
+ public static Rarity create(String name, java.util.function.UnaryOperator<net.minecraft.network.chat.Style> styleModifier) {
|
||||
+ throw new IllegalStateException("Enum not extended");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.debug.misc;
|
||||
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Rarity;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
|
||||
@Mod(CustomRarityTest.MOD_ID)
|
||||
public class CustomRarityTest {
|
||||
|
||||
private static final boolean ENABLED = true;
|
||||
static final String MOD_ID = "custom_rarity_test";
|
||||
|
||||
private static final Rarity CUSTOM_RARITY = Rarity.create(MOD_ID + "_CUSTOM", style -> style.withItalic(true).withColor(ChatFormatting.DARK_AQUA));
|
||||
|
||||
private static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MOD_ID);
|
||||
private static final RegistryObject<Item> CUSTOM_ITEM = ITEMS.register(
|
||||
"test",
|
||||
() -> new Item(new Item.Properties())
|
||||
{
|
||||
@Override
|
||||
public Rarity getRarity(ItemStack p_41461_)
|
||||
{
|
||||
return CUSTOM_RARITY;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
public CustomRarityTest() {
|
||||
if (ENABLED)
|
||||
{
|
||||
ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -222,5 +222,7 @@ license="LGPL v2.1"
|
||||
modId="player_negotiation_event_test"
|
||||
[[mods]]
|
||||
modId="custom_transformtype_test"
|
||||
[[mods]]
|
||||
modId="custom_rarity_test"
|
||||
|
||||
# ADD ABOVE THIS LINE
|
||||
Reference in new issue
Block a user