use of org.terasology.engine.entitySystem.entity.EntityBuilder in project Terasology by MovingBlocks.
the class VisualCharacterSystem method onCreateDefaultVisualCharacter.
@ReceiveEvent(priority = EventPriority.PRIORITY_TRIVIAL)
public void onCreateDefaultVisualCharacter(CreateVisualCharacterEvent event, EntityRef characterEntity) {
Prefab prefab = assetManager.getAsset("engine:defaultVisualCharacter", Prefab.class).get();
EntityBuilder entityBuilder = event.getVisualCharacterBuilder();
entityBuilder.addPrefab(prefab);
event.consume();
}
use of org.terasology.engine.entitySystem.entity.EntityBuilder in project Terasology by MovingBlocks.
the class BlockEntitySystem method commonDestroyed.
private void commonDestroyed(DoDestroyEvent event, EntityRef entity, Block block) {
entity.send(new CreateBlockDropsEvent(event.getInstigator(), event.getDirectCause(), event.getDamageType()));
BlockDamageModifierComponent blockDamageModifierComponent = event.getDamageType().getComponent(BlockDamageModifierComponent.class);
// TODO: Configurable via block definition
if (blockDamageModifierComponent == null || !blockDamageModifierComponent.skipPerBlockEffects) {
// dust particle effect
if (entity.hasComponent(LocationComponent.class) && block.isDebrisOnDestroy()) {
// TODO: particle system stuff should be split out better - this is effectively a stealth dependency on
// 'CoreAssets' from the engine
EntityBuilder dustBuilder = entityManager.newBuilder("CoreAssets:dustEffect");
if (dustBuilder.hasComponent(LocationComponent.class)) {
dustBuilder.getComponent(LocationComponent.class).setWorldPosition(entity.getComponent(LocationComponent.class).getWorldPosition(new Vector3f()));
dustBuilder.build();
}
}
// sound to play for destroyed block
BlockSounds sounds = block.getSounds();
if (!sounds.getDestroySounds().isEmpty()) {
StaticSound sound = random.nextItem(sounds.getDestroySounds());
entity.send(new PlaySoundEvent(sound, 0.6f));
}
}
}
use of org.terasology.engine.entitySystem.entity.EntityBuilder 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 Quaternionf().rotationYXZ(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.engine.entitySystem.entity.EntityBuilder in project Terasology by MovingBlocks.
the class ThirdPersonRemoteClientSystem method ensureClientSideEntityOnHeldItemMountPoint.
/**
* Ensures held item mount point entity exists, attaches it to the character and sets its transform.
*
* @param event the activation that triggered the need to consider changing a held item
* @param character the character for which we need to consider the held item
* @param remotePersonHeldItemMountPointComponent data for the mount point on the remote character
*/
@ReceiveEvent
public void ensureClientSideEntityOnHeldItemMountPoint(OnActivatedComponent event, EntityRef character, RemotePersonHeldItemMountPointComponent remotePersonHeldItemMountPointComponent) {
if (relatesToLocalPlayer(character)) {
logger.debug("ensureClientSideEntityOnHeldItemMountPoint found its given character to relate to the local" + " player, ignoring: {}", character);
return;
}
// In case we haven't dealt with a given remote player yet set up a non-persistent mount point
if (!remotePersonHeldItemMountPointComponent.mountPointEntity.exists()) {
EntityBuilder builder = entityManager.newBuilder("engine:RemotePersonHeldItemMountPoint");
builder.setPersistent(false);
remotePersonHeldItemMountPointComponent.mountPointEntity = builder.build();
character.saveComponent(remotePersonHeldItemMountPointComponent);
}
// Link the mount point entity to the camera
Location.removeChild(character, remotePersonHeldItemMountPointComponent.mountPointEntity);
Location.attachChild(character, remotePersonHeldItemMountPointComponent.mountPointEntity, remotePersonHeldItemMountPointComponent.translate, new Quaternionf().rotationYXZ(Math.toRadians(remotePersonHeldItemMountPointComponent.rotateDegrees.y), Math.toRadians(remotePersonHeldItemMountPointComponent.rotateDegrees.x), Math.toRadians(remotePersonHeldItemMountPointComponent.rotateDegrees.z)), remotePersonHeldItemMountPointComponent.scale);
}
Aggregations