Search in sources :

Example 1 with AbstractAttributeMap

use of net.minecraft.entity.ai.attributes.AbstractAttributeMap in project Bewitchment by Um-Mitternacht.

the class BrewAttributeModifier method applyAttributeModifiers.

public void applyAttributeModifiers(AbstractAttributeMap attributeMap, int amplifier) {
    for (Map.Entry<IAttribute, AttributeModifier> entry : modifierMap.entrySet()) {
        IAttributeInstance attribute = attributeMap.getAttributeInstance(entry.getKey());
        if (attribute == null)
            continue;
        AttributeModifier modifier = entry.getValue();
        attribute.removeModifier(modifier);
        attribute.applyModifier(new AttributeModifier(modifier.getID(), this.getName() + " " + amplifier, modifier.getAmount() * (amplifier + 1), modifier.getOperation()));
    }
}
Also used : IAttribute(net.minecraft.entity.ai.attributes.IAttribute) IAttributeInstance(net.minecraft.entity.ai.attributes.IAttributeInstance) AttributeModifier(net.minecraft.entity.ai.attributes.AttributeModifier) AbstractAttributeMap(net.minecraft.entity.ai.attributes.AbstractAttributeMap) Map(java.util.Map)

Example 2 with AbstractAttributeMap

use of net.minecraft.entity.ai.attributes.AbstractAttributeMap in project Gaspunk by Ladysnake.

the class SicknessTests method setUp.

@Before
public void setUp() {
    mockedCreeper = mock(EntityCreeper.class);
    // prevent entity.world.isRemote check from crashing
    mockedCreeper.world = mock(World.class);
    // allow the testing of the air supply attribute
    AbstractAttributeMap attributeMap = new AttributeMap();
    attributeMap.registerAttribute(CapabilityBreathing.MAX_AIR_SUPPLY);
    when(mockedCreeper.getAttributeMap()).thenReturn(attributeMap);
    when(mockedCreeper.getEntityAttribute(any())).then(InvocationOnMock::callRealMethod);
    // setup capabilities
    IBreathingHandler breathingHandler = new CapabilityBreathing.DefaultBreathingHandler(mockedCreeper);
    ISicknessHandler sicknessHandler = new CapabilitySickness.DefaultSicknessHandler(mockedCreeper);
    when(mockedCreeper.getCapability(any(), any())).then(invocation -> invocation.getArgument(0) == CapabilitySickness.CAPABILITY_SICKNESS ? sicknessHandler : breathingHandler);
    when(mockedCreeper.getItemStackFromSlot(any())).thenReturn(ItemStack.EMPTY);
    when(mockedCreeper.decreaseAirSupply(anyInt())).then(InvocationOnMock::callRealMethod);
}
Also used : AbstractAttributeMap(net.minecraft.entity.ai.attributes.AbstractAttributeMap) AttributeMap(net.minecraft.entity.ai.attributes.AttributeMap) AbstractAttributeMap(net.minecraft.entity.ai.attributes.AbstractAttributeMap) IBreathingHandler(ladysnake.gaspunk.api.IBreathingHandler) EntityCreeper(net.minecraft.entity.monster.EntityCreeper) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ISicknessHandler(ladysnake.pathos.api.ISicknessHandler) World(net.minecraft.world.World) Before(org.junit.Before)

Example 3 with AbstractAttributeMap

use of net.minecraft.entity.ai.attributes.AbstractAttributeMap in project Bewitchment by Um-Mitternacht.

the class BrewAttributeModifier method removeAttributeModifiers.

public void removeAttributeModifiers(AbstractAttributeMap attributeMapIn, int amplifier) {
    for (Map.Entry<IAttribute, AttributeModifier> entry : modifierMap.entrySet()) {
        IAttributeInstance attribute = attributeMapIn.getAttributeInstance(entry.getKey());
        if (attribute == null)
            continue;
        attribute.removeModifier(entry.getValue());
    }
}
Also used : IAttribute(net.minecraft.entity.ai.attributes.IAttribute) IAttributeInstance(net.minecraft.entity.ai.attributes.IAttributeInstance) AttributeModifier(net.minecraft.entity.ai.attributes.AttributeModifier) AbstractAttributeMap(net.minecraft.entity.ai.attributes.AbstractAttributeMap) Map(java.util.Map)

Aggregations

AbstractAttributeMap (net.minecraft.entity.ai.attributes.AbstractAttributeMap)3 Map (java.util.Map)2 AttributeModifier (net.minecraft.entity.ai.attributes.AttributeModifier)2 IAttribute (net.minecraft.entity.ai.attributes.IAttribute)2 IAttributeInstance (net.minecraft.entity.ai.attributes.IAttributeInstance)2 IBreathingHandler (ladysnake.gaspunk.api.IBreathingHandler)1 ISicknessHandler (ladysnake.pathos.api.ISicknessHandler)1 AttributeMap (net.minecraft.entity.ai.attributes.AttributeMap)1 EntityCreeper (net.minecraft.entity.monster.EntityCreeper)1 World (net.minecraft.world.World)1 Before (org.junit.Before)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1