Implement item hooks for potions and enchantments (#8718)

* Implement item hooks for potions and enchantments

* code style fixes
This commit is contained in:
Random832 authored and GitHub committed 2022-07-09 11:48:51 -04:00
1 parent ac44d72530
commit 1134fac54c
6 files changed
+129

No files matched your search

@@ -6,6 +6,8 @@
package net.minecraftforge.common.extensions;
import net.minecraft.world.entity.MobType;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.Enchantment;
@@ -28,4 +30,26 @@ public interface IForgeEnchantment
{
return self().getDamageBonus(level, mobType);
}
/**
* Determines what creative tabs this enchantment's variant of an enchanted book or similar item should appear in.
* @param book The item being added to the creative tab
* @param tab The creative tab that items are being added to
* @return whether the given Item's variant for this enchantment should appear in the respective creative tab
*/
default boolean allowedInCreativeTab(Item book, CreativeModeTab tab)
{
if (!self().isAllowedOnBooks())
{
return false;
}
else if (tab == CreativeModeTab.TAB_SEARCH)
{
return self().category != null;
}
else
{
return tab.hasEnchantmentCategory(self().category);
}
}
}
@@ -0,0 +1,43 @@
/*
* Copyright (c) Forge Development LLC and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/
package net.minecraftforge.common.extensions;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.alchemy.Potion;
import net.minecraft.world.item.alchemy.PotionUtils;
public interface IForgePotion
{
private Potion self()
{
return (Potion) this;
}
/**
* Determines what creative tabs this potion's variant of a potion-related item (e.g. bottles, tipped arrows) should appear in.
* @param item The item being added to a creative tab
* @param tab The creative tab that items are being added to
* @param isDefaultTab whether the tab is the default tab for this item (e.g. Brewing for bottles, Combat for tipped arrows)
* @return whether the given Item's variant for this enchantment should appear in the respective creative tab
*/
default boolean allowedInCreativeTab(Item item, CreativeModeTab tab, boolean isDefaultTab)
{
return isDefaultTab;
}
/**
* Determines whether the potion bottle item should be enchanted.
* Not called for tipped arrows or if the item is already enchanted.
* @param stack The potion bottle
* @return whether the item should appear enchanted.
*/
default boolean isFoil(ItemStack stack)
{
return !PotionUtils.getMobEffects(stack).isEmpty();
}
}