Search in sources :

Example 1 with AttributeMap

use of net.minecraft.entity.ai.attributes.AttributeMap in project SpongeCommon by SpongePowered.

the class MixinEntityPlayerMP method refreshScaledHealth.

@Override
public void refreshScaledHealth() {
    // We need to use the dirty instances to signify that the player needs to ahve it updated, instead
    // of modifying the attribute instances themselves, we bypass other potentially detrimental logi
    // that would otherwise break the actual health scaling.
    final Set<IAttributeInstance> dirtyInstances = ((AttributeMap) this.getAttributeMap()).getDirtyInstances();
    injectScaledHealth(dirtyInstances, true);
    // Send the new information to the client.
    sendHealthUpdate();
    this.connection.sendPacket(new SPacketEntityProperties(this.getEntityId(), dirtyInstances));
    // Reset the dirty instances since they've now been manually updated on the client.
    dirtyInstances.clear();
}
Also used : SPacketEntityProperties(net.minecraft.network.play.server.SPacketEntityProperties) AttributeMap(net.minecraft.entity.ai.attributes.AttributeMap) IAttributeInstance(net.minecraft.entity.ai.attributes.IAttributeInstance)

Example 2 with AttributeMap

use of net.minecraft.entity.ai.attributes.AttributeMap in project Charset by CharsetMC.

the class ItemUtils method getAttributeValue.

public static double getAttributeValue(EntityEquipmentSlot slot, ItemStack is, IAttribute attr) {
    Multimap<String, AttributeModifier> attrs = is.getItem().getAttributeModifiers(slot, is);
    if (attrs != null) {
        AttributeMap map = new AttributeMap();
        map.applyAttributeModifiers(attrs);
        IAttributeInstance instance = map.getAttributeInstance(attr);
        if (instance != null) {
            return instance.getAttributeValue();
        }
    }
    return 0;
}
Also used : AttributeMap(net.minecraft.entity.ai.attributes.AttributeMap) IAttributeInstance(net.minecraft.entity.ai.attributes.IAttributeInstance) AttributeModifier(net.minecraft.entity.ai.attributes.AttributeModifier)

Example 3 with AttributeMap

use of net.minecraft.entity.ai.attributes.AttributeMap 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)

Aggregations

AttributeMap (net.minecraft.entity.ai.attributes.AttributeMap)3 IAttributeInstance (net.minecraft.entity.ai.attributes.IAttributeInstance)2 IBreathingHandler (ladysnake.gaspunk.api.IBreathingHandler)1 ISicknessHandler (ladysnake.pathos.api.ISicknessHandler)1 AbstractAttributeMap (net.minecraft.entity.ai.attributes.AbstractAttributeMap)1 AttributeModifier (net.minecraft.entity.ai.attributes.AttributeModifier)1 EntityCreeper (net.minecraft.entity.monster.EntityCreeper)1 SPacketEntityProperties (net.minecraft.network.play.server.SPacketEntityProperties)1 World (net.minecraft.world.World)1 Before (org.junit.Before)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1