Search in sources :

Example 1 with AttackRequest

use of org.terasology.logic.characters.events.AttackRequest in project Terasology by MovingBlocks.

the class ByteCodeReflectFactoryTest method testCreateConstructorObjectWithProtectedConstructor.

@Test
public void testCreateConstructorObjectWithProtectedConstructor() throws Exception {
    ReflectFactory reflectFactory = new ByteCodeReflectFactory();
    ObjectConstructor<AttackRequest> constructor = reflectFactory.createConstructor(AttackRequest.class);
    AttackRequest result = constructor.construct();
    assertNotNull(result);
}
Also used : AttackRequest(org.terasology.logic.characters.events.AttackRequest) Test(org.junit.Test)

Example 2 with AttackRequest

use of org.terasology.logic.characters.events.AttackRequest in project Terasology by MovingBlocks.

the class CharacterSystem method onAttackRequest.

@ReceiveEvent(components = { CharacterComponent.class }, netFilter = RegisterMode.CLIENT)
public void onAttackRequest(AttackButton event, EntityRef entity, CharacterHeldItemComponent characterHeldItemComponent) {
    if (!event.isDown()) {
        return;
    }
    boolean attackRequestIsValid;
    if (networkSystem.getMode().isAuthority()) {
        // Let the AttackRequest handler trigger the OnItemUseEvent if this is a local client
        attackRequestIsValid = true;
    } else {
        OnItemUseEvent onItemUseEvent = new OnItemUseEvent();
        entity.send(onItemUseEvent);
        attackRequestIsValid = !onItemUseEvent.isConsumed();
    }
    if (attackRequestIsValid) {
        EntityRef selectedItemEntity = characterHeldItemComponent.selectedItem;
        entity.send(new AttackRequest(selectedItemEntity));
        event.consume();
    }
}
Also used : AttackRequest(org.terasology.logic.characters.events.AttackRequest) OnItemUseEvent(org.terasology.logic.characters.events.OnItemUseEvent) EntityRef(org.terasology.entitySystem.entity.EntityRef) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Aggregations

AttackRequest (org.terasology.logic.characters.events.AttackRequest)2 Test (org.junit.Test)1 EntityRef (org.terasology.entitySystem.entity.EntityRef)1 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)1 OnItemUseEvent (org.terasology.logic.characters.events.OnItemUseEvent)1