use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class Location method onDestroyed.
@ReceiveEvent
public void onDestroyed(BeforeRemoveComponent event, EntityRef entity, LocationComponent location) {
if (location.parent.exists()) {
removeChild(location.parent, entity);
}
Iterator<EntityRef> childIterator = location.getChildren().iterator();
while (childIterator.hasNext()) {
EntityRef child = childIterator.next();
LocationComponent childLoc = child.getComponent(LocationComponent.class);
if (childLoc != null) {
Vector3f oldWorldPos = childLoc.getWorldPosition();
childLoc.parent = EntityRef.NULL;
childLoc.setWorldPosition(oldWorldPos);
child.saveComponent(childLoc);
}
childIterator.remove();
}
}
use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class FirstPersonClientSystem method ensureClientSideEntityOnHeldItemMountPoint.
// ensures held item mount point entity exists, attaches it to the camera and sets its transform
@ReceiveEvent
public void ensureClientSideEntityOnHeldItemMountPoint(OnActivatedComponent event, EntityRef camera, FirstPersonHeldItemMountPointComponent firstPersonHeldItemMountPointComponent) {
if (!firstPersonHeldItemMountPointComponent.mountPointEntity.exists()) {
EntityBuilder builder = entityManager.newBuilder("engine:FirstPersonHeldItemMountPoint");
builder.setPersistent(false);
firstPersonHeldItemMountPointComponent.mountPointEntity = builder.build();
camera.saveComponent(firstPersonHeldItemMountPointComponent);
}
// link the mount point entity to the camera
Location.removeChild(camera, firstPersonHeldItemMountPointComponent.mountPointEntity);
Location.attachChild(camera, firstPersonHeldItemMountPointComponent.mountPointEntity, firstPersonHeldItemMountPointComponent.translate, new Quat4f(TeraMath.DEG_TO_RAD * firstPersonHeldItemMountPointComponent.rotateDegrees.y, TeraMath.DEG_TO_RAD * firstPersonHeldItemMountPointComponent.rotateDegrees.x, TeraMath.DEG_TO_RAD * firstPersonHeldItemMountPointComponent.rotateDegrees.z), firstPersonHeldItemMountPointComponent.scale);
}
use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class LocalPlayerSystem method onFrobButton.
@ReceiveEvent(components = { CharacterComponent.class })
public void onFrobButton(FrobButton event, EntityRef character) {
if (event.getState() != ButtonState.DOWN) {
return;
}
ResourceUrn activeInteractionScreenUri = InteractionUtil.getActiveInteractionScreenUri(character);
if (activeInteractionScreenUri != null) {
InteractionUtil.cancelInteractionAsClient(character);
return;
}
boolean activeRequestSent = localPlayer.activateTargetAsClient();
if (activeRequestSent) {
event.consume();
}
}
use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class LocalPlayerSystem method onPlayerSpawn.
@ReceiveEvent
public void onPlayerSpawn(OnPlayerSpawnedEvent event, EntityRef character) {
if (character.equals(localPlayer.getCharacterEntity())) {
// Change height as per PlayerSettings
Float height = config.getPlayer().getHeight();
movementDebugCommands.playerHeight(localPlayer.getClientEntity(), height);
// Change eyeHeight as per PlayerSettings
Float eyeHeight = config.getPlayer().getEyeHeight();
GazeMountPointComponent gazeMountPointComponent = character.getComponent(GazeMountPointComponent.class);
gazeMountPointComponent.translate = new Vector3f(0, eyeHeight, 0);
// Trigger updating the player camera position as soon as the local player is spawned.
// This is not done while the game is still loading, since systems are not updated.
// RenderableWorldImpl pre-generates chunks around the player camera and therefore needs
// the correct location.
lookYaw = 0f;
lookPitch = 0f;
update(0);
}
}
use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class MenuControlSystem method onPlayerDeath.
@ReceiveEvent(components = { CharacterComponent.class })
public void onPlayerDeath(PlayerDeathEvent event, EntityRef character) {
EntityRef client = character.getComponent(CharacterComponent.class).controller;
if (client.getComponent(ClientComponent.class).local) {
nuiManager.removeOverlay("engine:onlinePlayersOverlay");
nuiManager.pushScreen("engine:deathScreen");
if (event.damageTypeName != null) {
((DeathScreen) nuiManager.getScreen("engine:deathScreen")).setDeathDetails(event.instigatorName, event.damageTypeName);
}
}
}
Aggregations