Search in sources :

Example 1 with EntityAttributeCreationEvent

use of net.minecraftforge.event.entity.EntityAttributeCreationEvent in project Magma-1.16.x by magmafoundation.

the class ForgeHooks method modifyAttributes.

/**
 *  FOR INTERNAL USE ONLY, DO NOT CALL DIRECTLY
 */
@Deprecated
public static void modifyAttributes() {
    ModLoader.get().postEvent(new EntityAttributeCreationEvent(FORGE_ATTRIBUTES));
    Map<EntityType<? extends LivingEntity>, AttributeModifierMap.MutableAttribute> finalMap = new HashMap<>();
    ModLoader.get().postEvent(new EntityAttributeModificationEvent(finalMap));
    finalMap.forEach((k, v) -> {
        AttributeModifierMap modifiers = GlobalEntityTypeAttributes.getSupplier(k);
        AttributeModifierMap.MutableAttribute newMutable = modifiers != null ? new AttributeModifierMap.MutableAttribute(modifiers) : new AttributeModifierMap.MutableAttribute();
        newMutable.combine(v);
        FORGE_ATTRIBUTES.put(k, newMutable.build());
    });
}
Also used : EntityType(net.minecraft.entity.EntityType) LivingEntity(net.minecraft.entity.LivingEntity) EntityAttributeCreationEvent(net.minecraftforge.event.entity.EntityAttributeCreationEvent) HashMap(java.util.HashMap) EntityAttributeModificationEvent(net.minecraftforge.event.entity.EntityAttributeModificationEvent) AttributeModifierMap(net.minecraft.entity.ai.attributes.AttributeModifierMap)

Example 2 with EntityAttributeCreationEvent

use of net.minecraftforge.event.entity.EntityAttributeCreationEvent in project LoliServer by Loli-Server.

the class ForgeHooks method modifyAttributes.

/**
 *  FOR INTERNAL USE ONLY, DO NOT CALL DIRECTLY
 */
@Deprecated
public static void modifyAttributes() {
    ModLoader.get().postEvent(new EntityAttributeCreationEvent(FORGE_ATTRIBUTES));
    Map<EntityType<? extends LivingEntity>, AttributeModifierMap.MutableAttribute> finalMap = new HashMap<>();
    ModLoader.get().postEvent(new EntityAttributeModificationEvent(finalMap));
    finalMap.forEach((k, v) -> {
        AttributeModifierMap modifiers = GlobalEntityTypeAttributes.getSupplier(k);
        AttributeModifierMap.MutableAttribute newMutable = modifiers != null ? new AttributeModifierMap.MutableAttribute(modifiers) : new AttributeModifierMap.MutableAttribute();
        newMutable.combine(v);
        FORGE_ATTRIBUTES.put(k, newMutable.build());
    });
}
Also used : EntityType(net.minecraft.entity.EntityType) LivingEntity(net.minecraft.entity.LivingEntity) EntityAttributeCreationEvent(net.minecraftforge.event.entity.EntityAttributeCreationEvent) HashMap(java.util.HashMap) EntityAttributeModificationEvent(net.minecraftforge.event.entity.EntityAttributeModificationEvent) AttributeModifierMap(net.minecraft.entity.ai.attributes.AttributeModifierMap)

Aggregations

HashMap (java.util.HashMap)2 EntityType (net.minecraft.entity.EntityType)2 LivingEntity (net.minecraft.entity.LivingEntity)2 AttributeModifierMap (net.minecraft.entity.ai.attributes.AttributeModifierMap)2 EntityAttributeCreationEvent (net.minecraftforge.event.entity.EntityAttributeCreationEvent)2 EntityAttributeModificationEvent (net.minecraftforge.event.entity.EntityAttributeModificationEvent)2