mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-20 04:09:51 +00:00
* Bump pack.mcmeta formats * 1.19 biome modifiers * Mark ClientPlayerNetworkEvent.LoggedOutEvent's getters as nullable * Add docs and package-info to client extension interfaces package * Move RenderBlockOverlayEvent hooks to ForgeHooksClient * Add package-infos to client events package * Rename SoundLoadEvent to SoundEngineLoadEvent This reduces confusion from consumers which may think the name SoundLoadEvent refers to an individual sound being loaded rather than the sound engine. * Document and change SoundLoadEvent to fire on mod bus Previously, it fired on both the mod bus and the Forge bus, which is confusing for consumers. * Delete SoundSetupEvent Looking at its original implementation shows that there isn't an appropriate place in the new sound code to reinsert the event, and the place of 'sound engine/manager initialization event' is taken already by SoundLoadEvent. * Perform some cleanup on client events - Removed nullable annotations from ClientPlayerNetworkEvent - Renamed #getPartialTicks methods to #getPartialTick, to be consistent with vanilla's naming of the partial tick - Cleanup documentation to remove line breaks, use the spelling 'cancelled' over 'canceled', and improve docs on existing and new methods. * Remove EntityEvent.CanUpdate Closes MinecraftForge/MinecraftForge#6394 * Switch to Jetbrains nullability annotations * New PlayLevelSoundEvent; replaces old PlaySoundAtEntityEvent * Remove ForgeWorldPresetScreens * Remove IForgeRegistryEntry * Remove use of List<Throwable> in FML's CompletableFutures * Add docs to mod loading stages, stages, and phases * Gradle 7.4.2 * Use SLF4J in FMLLoader and other subprojects * Switch dynamic versions in subprojects to pinned ones * Switch ForgeRoot and MDK to FG plugin markers * Configure Forge javadoc task The task now uses a custom stylesheet with MCForge elements, and configured to combine the generation from the four FML subprojects (fmlloader, fmlcore, javafmllanguage, mclanguage) and the Forge project into the javadoc output. * Update docs/md files, for 1.19 update and the move away from IRC to Discord. * Make "Potentially dangerous alternative prefix" a debug warning, not info. Co-authored-by: Curle <[email protected]> Co-authored-by: sciwhiz12 <[email protected]> Signed-off-by: SizableShrimp <[email protected]>
130 lines
4.7 KiB
Java
130 lines
4.7 KiB
Java
/*
|
|
* Copyright (c) Forge Development LLC and contributors
|
|
* SPDX-License-Identifier: LGPL-2.1-only
|
|
*/
|
|
|
|
package net.minecraftforge.event;
|
|
|
|
import com.google.common.collect.HashMultimap;
|
|
import com.google.common.collect.Multimaps;
|
|
import net.minecraftforge.eventbus.api.Event;
|
|
import net.minecraft.world.entity.ai.attributes.Attribute;
|
|
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
|
|
import net.minecraft.world.entity.EquipmentSlot;
|
|
import net.minecraft.world.item.ItemStack;
|
|
import com.google.common.collect.Multimap;
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
import java.util.Collection;
|
|
|
|
/**
|
|
* This event is fired when the attributes for an ItemStack are being calculated.
|
|
* Attributes are calculated on the server when equipping and unequipping an item to add and remove attributes respectively, both must be consistent.
|
|
* Attributes are calculated on the client when rendering an item's tooltip to show relevant attributes.
|
|
* <br>
|
|
* Note that this event is fired regardless of if the stack has NBT overriding attributes or not. If your attribute should be
|
|
* ignored when attributes are overridden, you can check for the presence of the {@code AttributeModifiers} tag.
|
|
* <br>
|
|
* This event is fired on the {@link net.minecraftforge.common.MinecraftForge#EVENT_BUS}.
|
|
*/
|
|
public class ItemAttributeModifierEvent extends Event
|
|
{
|
|
private final ItemStack stack;
|
|
private final EquipmentSlot slotType;
|
|
private final Multimap<Attribute, AttributeModifier> originalModifiers;
|
|
private Multimap<Attribute, AttributeModifier> unmodifiableModifiers;
|
|
@Nullable
|
|
private Multimap<Attribute, AttributeModifier> modifiableModifiers;
|
|
|
|
public ItemAttributeModifierEvent(ItemStack stack, EquipmentSlot slotType, Multimap<Attribute, AttributeModifier> modifiers)
|
|
{
|
|
this.stack = stack;
|
|
this.slotType = slotType;
|
|
this.unmodifiableModifiers = this.originalModifiers = modifiers;
|
|
}
|
|
|
|
/**
|
|
* Returns an unmodifiable view of the attribute multimap. Use other methods from this event to modify the attributes map.
|
|
* Note that adding attributes based on existing attributes may lead to inconsistent results between the tooltip (client)
|
|
* and the actual attributes (server) if the listener order is different. Using {@link #getOriginalModifiers()} instead will give more consistent results.
|
|
*/
|
|
public Multimap<Attribute, AttributeModifier> getModifiers()
|
|
{
|
|
return this.unmodifiableModifiers;
|
|
}
|
|
|
|
/**
|
|
* Returns the attribute map before any changes from other event listeners was made.
|
|
*/
|
|
public Multimap<Attribute, AttributeModifier> getOriginalModifiers()
|
|
{
|
|
return this.originalModifiers;
|
|
}
|
|
|
|
/**
|
|
* Gets a modifiable map instance, creating it if the current map is currently unmodifiable
|
|
*/
|
|
private Multimap<Attribute, AttributeModifier> getModifiableMap()
|
|
{
|
|
if (this.modifiableModifiers == null)
|
|
{
|
|
this.modifiableModifiers = HashMultimap.create(this.originalModifiers);
|
|
this.unmodifiableModifiers = Multimaps.unmodifiableMultimap(this.modifiableModifiers);
|
|
}
|
|
return this.modifiableModifiers;
|
|
}
|
|
|
|
/**
|
|
* Adds a new attribute modifier to the given stack.
|
|
* Modifier must have a consistent UUID for consistency between equipping and unequipping items.
|
|
* Modifier name should clearly identify the mod that added the modifier.
|
|
* @param attribute Attribute
|
|
* @param modifier Modifier instance.
|
|
* @return True if the attribute was added, false if it was already present
|
|
*/
|
|
public boolean addModifier(Attribute attribute, AttributeModifier modifier)
|
|
{
|
|
return getModifiableMap().put(attribute, modifier);
|
|
}
|
|
|
|
/**
|
|
* Removes a single modifier for the given attribute
|
|
* @param attribute Attribute
|
|
* @param modifier Modifier instance
|
|
* @return True if an attribute was removed, false if no change
|
|
*/
|
|
public boolean removeModifier(Attribute attribute, AttributeModifier modifier)
|
|
{
|
|
return getModifiableMap().remove(attribute, modifier);
|
|
}
|
|
|
|
/**
|
|
* Removes all modifiers for the given attribute
|
|
* @param attribute Attribute
|
|
* @return Collection of removed modifiers
|
|
*/
|
|
public Collection<AttributeModifier> removeAttribute(Attribute attribute)
|
|
{
|
|
return getModifiableMap().removeAll(attribute);
|
|
}
|
|
|
|
/**
|
|
* Removes all modifiers for all attributes
|
|
*/
|
|
public void clearModifiers()
|
|
{
|
|
getModifiableMap().clear();
|
|
}
|
|
|
|
/** Gets the slot containing this stack */
|
|
public EquipmentSlot getSlotType()
|
|
{
|
|
return this.slotType;
|
|
}
|
|
|
|
/** Gets the item stack instance */
|
|
public ItemStack getItemStack()
|
|
{
|
|
return this.stack;
|
|
}
|
|
} |