use of org.terasology.engine.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.
the class EntityAwareWorldProviderTest method testGetTemporaryBlockSendsNoEvent.
@Test
public void testGetTemporaryBlockSendsNoEvent() {
BlockEventChecker checker = new BlockEventChecker();
entityManager.getEventSystem().registerEventHandler(checker);
EntityRef blockEntity = worldProvider.getBlockEntityAt(new Vector3i());
assertTrue(blockEntity.exists());
assertFalse(checker.addedReceived);
assertFalse(checker.activateReceived);
assertFalse(checker.deactivateReceived);
assertFalse(checker.removedReceived);
}
use of org.terasology.engine.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.
the class EntityAwareWorldProviderTest method testNetworkComponentRemovedWhenTemporaryCleanedUp.
@Test
public void testNetworkComponentRemovedWhenTemporaryCleanedUp() {
EntityRef entity = worldProvider.getBlockEntityAt(new Vector3i());
entity.addComponent(new RetainedOnBlockChangeComponent(2));
LifecycleEventChecker checker = new LifecycleEventChecker(entityManager.getEventSystem(), NetworkComponent.class);
entity.removeComponent(RetainedOnBlockChangeComponent.class);
worldProvider.update(1.0f);
assertEquals(Lists.newArrayList(new EventInfo(BeforeDeactivateComponent.newInstance(), entity), new EventInfo(BeforeRemoveComponent.newInstance(), entity)), checker.receivedEvents);
}
use of org.terasology.engine.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.
the class EntityAwareWorldProviderTest method testComponentsAddedAndActivatedWhenBlockChanged.
@Disabled("Failing due to #2625. TODO: fix to match new behaviour")
@Test
public void testComponentsAddedAndActivatedWhenBlockChanged() {
LifecycleEventChecker checker = new LifecycleEventChecker(entityManager.getEventSystem(), StringComponent.class);
worldProvider.setBlock(new Vector3i(), blockWithString);
EntityRef blockEntity = worldProvider.getBlockEntityAt(new Vector3i());
assertTrue(blockEntity.exists());
assertEquals(Lists.newArrayList(new EventInfo(OnAddedComponent.newInstance(), blockEntity), new EventInfo(OnActivatedComponent.newInstance(), blockEntity)), checker.receivedEvents);
}
use of org.terasology.engine.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.
the class CharacterSystem method onAttackRequest.
@ReceiveEvent(components = LocationComponent.class, netFilter = RegisterMode.AUTHORITY)
public void onAttackRequest(AttackRequest event, EntityRef character, CharacterComponent characterComponent) {
// if an item is used, make sure this entity is allowed to attack with it
if (event.getItem().exists()) {
if (!character.equals(event.getItem().getOwner())) {
return;
}
}
OnItemUseEvent onItemUseEvent = new OnItemUseEvent();
character.send(onItemUseEvent);
if (!onItemUseEvent.isConsumed()) {
EntityRef gazeEntity = GazeAuthoritySystem.getGazeEntityForCharacter(character);
LocationComponent gazeLocation = gazeEntity.getComponent(LocationComponent.class);
Vector3f direction = gazeLocation.getWorldDirection(new Vector3f());
Vector3f originPos = gazeLocation.getWorldPosition(new Vector3f());
if (recordAndReplayCurrentStatus.getStatus() == RecordAndReplayStatus.RECORDING) {
directionAndOriginPosRecorderList.getAttackEventDirectionAndOriginPosRecorder().add(direction, originPos);
} else if (recordAndReplayCurrentStatus.getStatus() == RecordAndReplayStatus.REPLAYING) {
Vector3f[] data = directionAndOriginPosRecorderList.getAttackEventDirectionAndOriginPosRecorder().poll();
direction = data[0];
originPos = data[1];
}
HitResult result = physics.rayTrace(originPos, direction, characterComponent.interactionRange, Sets.newHashSet(character), DEFAULTPHYSICSFILTER);
if (result.isHit()) {
result.getEntity().send(new AttackEvent(character, event.getItem()));
}
}
}
use of org.terasology.engine.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.
the class CharacterSystem method getPlayerNameFromCharacter.
private String getPlayerNameFromCharacter(EntityRef character) {
CharacterComponent characterComponent = character.getComponent(CharacterComponent.class);
if (characterComponent == null) {
return "?";
}
EntityRef controller = characterComponent.controller;
ClientComponent clientComponent = controller.getComponent(ClientComponent.class);
EntityRef clientInfo = clientComponent.clientInfo;
DisplayNameComponent displayNameComponent = clientInfo.getComponent(DisplayNameComponent.class);
if (displayNameComponent == null) {
return "?";
}
return displayNameComponent.name;
}
Aggregations