Allow items to hide parts of their tooltips by default (#8358)

This commit is contained in:
Take Weiland authored and GitHub committed 2022-02-15 09:23:18 -08:00
1 parent a9958b19db
commit 21787234f4
4 files changed
+102 -1

No files matched your search

@@ -205,6 +205,15 @@
return list;
}
@@ -736,7 +_,7 @@
}
private int m_41618_() {
- return this.m_41782_() && this.f_41590_.m_128425_("HideFlags", 99) ? this.f_41590_.m_128451_("HideFlags") : 0;
+ return this.m_41782_() && this.f_41590_.m_128425_("HideFlags", 99) ? this.f_41590_.m_128451_("HideFlags") : this.m_41720_().getDefaultTooltipHideFlags(this);
}
public void m_41654_(ItemStack.TooltipPart p_41655_) {
@@ -865,9 +_,10 @@
}
}
@@ -1,6 +1,6 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2021.
* Copyright (c) 2016-2022.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -740,4 +740,16 @@ public interface IForgeItem
{
return target.getBoundingBox().inflate(1.0D, 0.25D, 1.0D);
}
/**
* Get the tooltip parts that should be hidden by default on the given stack if the {@code HideFlags} tag is not set.
* @see ItemStack.TooltipPart
* @param stack the stack
* @return the default hide flags
*/
default int getDefaultTooltipHideFlags(@Nonnull ItemStack stack)
{
return 0;
}
}
@@ -0,0 +1,78 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2022.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.debug.item;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Multimap;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.ai.attributes.Attribute;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.entity.ai.attributes.AttributeModifier.Operation;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
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;
import org.jetbrains.annotations.NotNull;
import java.util.Set;
@Mod(HiddenTooltipPartsTest.MOD_ID)
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE, modid = HiddenTooltipPartsTest.MOD_ID)
public class HiddenTooltipPartsTest
{
public static final String MOD_ID = "hidden_tooltip_parts";
public static final boolean ENABLED = true;
private static final AttributeModifier MODIFIER = new AttributeModifier(MOD_ID, 10f, Operation.ADDITION);
private static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MOD_ID);
private static final RegistryObject<Item> TEST_ITEM = ITEMS.register("test_item", () -> new TestItem(new Item.Properties().tab(CreativeModeTab.TAB_MISC)));
public HiddenTooltipPartsTest()
{
ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus());
}
static class TestItem extends Item
{
public TestItem(Properties properties)
{
super(properties);
}
@Override
public Multimap<Attribute, AttributeModifier> getAttributeModifiers(EquipmentSlot slot, ItemStack stack)
{
return ImmutableMultimap.<Attribute, AttributeModifier>builder()
.put(Attributes.ARMOR, MODIFIER)
.build();
}
@Override
public int getDefaultTooltipHideFlags(@NotNull ItemStack stack)
{
return ItemStack.TooltipPart.MODIFIERS.getMask();
}
}
}
+2
View File
@@ -194,5 +194,7 @@ license="LGPL v2.1"
modId="registry_codec_test"
[[mods]]
modId="registry_object_test"
[[mods]]
modId="hidden_tooltip_parts"
# ADD ABOVE THIS LINE