use of org.terasology.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.
the class FirstPersonClientSystem method onHeldItemChanged.
@ReceiveEvent
public void onHeldItemChanged(OnChangedComponent event, EntityRef character, CharacterHeldItemComponent heldItemComponent, CharacterComponent characterComponents) {
if (localPlayer.getCharacterEntity().equals(character)) {
EntityRef newItem = heldItemComponent.selectedItem;
linkHeldItemLocationForLocalPlayer(newItem);
}
}
use of org.terasology.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.
the class LocalPlayerSystem method onTargetChanged.
@ReceiveEvent
public void onTargetChanged(PlayerTargetChangedEvent event, EntityRef entity) {
EntityRef target = event.getNewTarget();
if (target.exists()) {
LocationComponent location = target.getComponent(LocationComponent.class);
if (location != null) {
BlockComponent blockComp = target.getComponent(BlockComponent.class);
BlockRegionComponent blockRegion = target.getComponent(BlockRegionComponent.class);
if (blockComp != null || blockRegion != null) {
Vector3f blockPos = location.getWorldPosition();
Block block = worldProvider.getBlock(blockPos);
aabb = block.getBounds(blockPos);
} else {
MeshComponent mesh = target.getComponent(MeshComponent.class);
if (mesh != null && mesh.mesh != null) {
aabb = mesh.mesh.getAABB();
aabb = aabb.transform(location.getWorldRotation(), location.getWorldPosition(), location.getWorldScale());
}
}
}
} else {
aabb = null;
}
}
use of org.terasology.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.
the class LocalPlayerSystem method onUseItemButton.
@ReceiveEvent(components = { CharacterComponent.class })
public void onUseItemButton(UseItemButton event, EntityRef entity, CharacterHeldItemComponent characterHeldItemComponent) {
if (!event.isDown()) {
return;
}
EntityRef selectedItemEntity = characterHeldItemComponent.selectedItem;
if (!selectedItemEntity.exists()) {
return;
}
boolean requestIsValid;
if (networkSystem.getMode().isAuthority()) {
// Let the ActivationRequest handler trigger the OnItemUseEvent if this is a local client
requestIsValid = true;
} else {
OnItemUseEvent onItemUseEvent = new OnItemUseEvent();
entity.send(onItemUseEvent);
requestIsValid = !onItemUseEvent.isConsumed();
}
if (requestIsValid) {
localPlayer.activateOwnedEntityAsClient(selectedItemEntity);
entity.saveComponent(characterHeldItemComponent);
event.consume();
}
}
use of org.terasology.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.
the class PlayerSystem method respawnPlayer.
private void respawnPlayer(EntityRef clientEntity) {
ClientComponent client = clientEntity.getComponent(ClientComponent.class);
EntityRef playerCharacter = client.character;
LocationComponent location = clientEntity.getComponent(LocationComponent.class);
PlayerFactory playerFactory = new PlayerFactory(entityManager, worldProvider);
Vector3f spawnPosition = playerFactory.findSpawnPositionFromLocationComponent(location);
location.setWorldPosition(spawnPosition);
clientEntity.saveComponent(location);
playerCharacter.addComponent(new AliveCharacterComponent());
playerCharacter.send(new CharacterTeleportEvent(spawnPosition));
logger.debug("Re-spawing player at: {}", spawnPosition);
Client clientListener = networkSystem.getOwner(clientEntity);
Vector3i distance = clientListener.getViewDistance().getChunkDistance();
updateRelevanceEntity(clientEntity, distance);
playerCharacter.send(new OnPlayerRespawnedEvent());
}
use of org.terasology.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.
the class LocalPlayerBlockSelectionByItemSystem method onPlaced.
@ReceiveEvent(components = { OnItemActivateSelectionComponent.class })
public void onPlaced(ActivateEvent event, EntityRef itemEntity) {
if (event.getTargetLocation() == null) {
return;
}
EntityRef targetLocationEntity = event.getTarget();
this.blockSelectionComponentEntity = itemEntity;
BlockSelectionComponent blockSelectionComponent = itemEntity.getComponent(BlockSelectionComponent.class);
if (null == blockSelectionComponent.startPosition) {
// on the first item click, we start selecting blocks
targetLocationEntity.send(new SetBlockSelectionStartingPointEvent(itemEntity));
blockSelectionComponent.shouldRender = true;
} else {
// on the second item click, we will set the ending selection point and send an ApplyBlockSelectionEvent
targetLocationEntity.send(new SetBlockSelectionEndingPointEvent(itemEntity));
localPlayer.getCharacterEntity().send(new ApplyBlockSelectionEvent(itemEntity, blockSelectionComponent.currentSelection));
blockSelectionComponent.shouldRender = false;
blockSelectionComponent.currentSelection = null;
blockSelectionComponent.startPosition = null;
}
}
Aggregations