Add ItemAttributeModifierEvent (#7484)

This commit is contained in:
KnightMiner authored and GitHub committed 2020-12-28 11:59:09 -08:00
1 parent 33880331d2
commit 1c98b29087
5 files changed
+222 -4

No files matched your search

@@ -0,0 +1,55 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2020.
*
* 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 net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.entity.ai.attributes.AttributeModifier.Operation;
import net.minecraft.entity.ai.attributes.Attributes;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.Item;
import net.minecraft.item.Items;
import net.minecraftforge.event.ItemAttributeModifierEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
@Mod(ItemAttributeModifierTest.MOD_ID)
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE, modid = ItemAttributeModifierTest.MOD_ID)
public class ItemAttributeModifierTest
{
public static final String MOD_ID = "item_modifier_test";
public static final boolean ENABLED = true;
private static final AttributeModifier MODIFIER = new AttributeModifier(MOD_ID, 10f, Operation.ADDITION);
@SubscribeEvent
public static void onItemAttribute(ItemAttributeModifierEvent event)
{
if (ENABLED && event.getSlotType() == EquipmentSlotType.MAINHAND)
{
final Item item = event.getItemStack().getItem();
if (item == Items.APPLE)
{
event.addModifier(Attributes.ARMOR, MODIFIER);
}
else if (item == Items.GOLDEN_SWORD)
{
event.clearModifiers();
}
}
}
}