use of org.terasology.engine.logic.location.LocationComponent 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 = playerCharacter.getComponent(LocationComponent.class);
PlayerFactory playerFactory = new PlayerFactory(entityManager, worldProvider);
Vector3f spawnPosition = playerFactory.findSpawnPositionFromLocationComponent(location);
playerCharacter.addComponent(new AliveCharacterComponent());
playerCharacter.send(new CharacterTeleportEvent(spawnPosition));
logger.debug("Re-spawing player at: {}", spawnPosition);
Client clientListener = networkSystem.getOwner(clientEntity);
Vector3ic distance = clientListener.getViewDistance().getChunkDistance();
updateRelevanceEntity(clientEntity, distance);
playerCharacter.send(new OnPlayerRespawnedEvent());
}
use of org.terasology.engine.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class LocalPlayerBlockSelectionByItemSystem method onCamTargetChanged.
@ReceiveEvent(components = LocationComponent.class)
public void onCamTargetChanged(CameraTargetChangedEvent event, EntityRef entity) {
// This method will update the block selection to whatever block is targeted in the players view
if (null == blockSelectionComponentEntity) {
return;
}
BlockSelectionComponent blockSelectionComponent = blockSelectionComponentEntity.getComponent(BlockSelectionComponent.class);
if (blockSelectionComponent == null) {
return;
}
EntityRef target = event.getNewTarget();
LocationComponent locationComponent = target.getComponent(LocationComponent.class);
if (locationComponent == null) {
return;
}
Vector3f targetLocation = locationComponent.getWorldPosition(new Vector3f());
if (blockSelectionComponent.isMovable) {
Vector3i pos = new Vector3i(targetLocation, RoundingMode.FLOOR);
Vector3i size = blockSelectionComponent.currentSelection.getSize(new Vector3i());
blockSelectionComponent.currentSelection.set(pos, pos).expand(size.x() / 2, 0, size.z() / 2);
blockSelectionComponentEntity.saveComponent(blockSelectionComponent);
return;
}
if (blockSelectionComponent.startPosition == null) {
return;
}
target.send(new SetBlockSelectionEndingPointEvent(blockSelectionComponentEntity));
}
use of org.terasology.engine.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class AudioSystem method onPlaySound.
/**
* Receives the sound played event and calls on the AudioManager to play it.
*
* @param playSoundEvent The sound event.
* @param entity The entity that instigated the event.
*/
@ReceiveEvent
public void onPlaySound(PlaySoundEvent playSoundEvent, EntityRef entity) {
LocationComponent location = entity.getComponent(LocationComponent.class);
if (location != null) {
Vector3f pos = location.getWorldPosition(new Vector3f());
if (pos.isFinite()) {
audioManager.playSound(playSoundEvent.getSound(), pos, playSoundEvent.getVolume(), AudioManager.PRIORITY_NORMAL);
return;
} else {
logger.warn("Can't play sound with non-finite position/rotation?! Entity: {}", entity);
}
}
audioManager.playSound(playSoundEvent.getSound(), playSoundEvent.getVolume());
}
use of org.terasology.engine.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class TargetSystem method updateTarget.
public boolean updateTarget(Vector3f pos, Vector3f dir, float maxDist) {
if (targetBlockPos != null && !target.exists()) {
target = blockRegistry.getEntityAt(targetBlockPos);
}
HitResult hitInfo = physics.rayTrace(pos, dir, maxDist, filter);
EntityRef newTarget = hitInfo.getEntity();
if (hitInfo.isWorldHit()) {
if (targetBlockPos != null) {
if (targetBlockPos.equals(hitInfo.getBlockPosition())) {
return false;
}
}
targetBlockPos = hitInfo.getBlockPosition();
} else {
if (target.equals(newTarget)) {
return false;
}
targetBlockPos = null;
}
prevTarget = target;
target = newTarget;
LocationComponent location = target.getComponent(LocationComponent.class);
if (location != null && targetBlockPos != null) {
location.setLocalPosition(new Vector3f(targetBlockPos));
}
return true;
}
use of org.terasology.engine.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class ActivateEvent method getInstigatorLocation.
public Vector3f getInstigatorLocation() {
LocationComponent loc = instigator.getComponent(LocationComponent.class);
if (loc != null) {
Vector3f result = loc.getWorldPosition(new Vector3f());
if (result.isFinite()) {
return result;
}
result.set(0, 0, 0);
return result;
}
return new Vector3f();
}
Aggregations