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);
}
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();
}
}
Aggregations