Search in sources :

Example 11 with DisplayNameComponent

use of org.terasology.logic.common.DisplayNameComponent in project Terasology by MovingBlocks.

the class BlockItemFactory method newBuilder.

/**
 * Use this method instead of {@link #newInstance(BlockFamily)} to modify entity properties like the persistence
 * flag before it gets created.
 *
 * @param blockFamily must not be null
 */
public EntityBuilder newBuilder(BlockFamily blockFamily, int quantity) {
    EntityBuilder builder = entityManager.newBuilder("engine:blockItemBase");
    if (blockFamily.getArchetypeBlock().getLuminance() > 0) {
        builder.addComponent(new LightComponent());
    }
    // Copy the components from block prefab into the block item
    Optional<Prefab> prefab = blockFamily.getArchetypeBlock().getPrefab();
    if (prefab.isPresent()) {
        for (Component component : prefab.get().iterateComponents()) {
            if (component.getClass().getAnnotation(AddToBlockBasedItem.class) != null) {
                builder.addComponent(entityManager.getComponentLibrary().copy(component));
            }
        }
    }
    DisplayNameComponent displayNameComponent = builder.getComponent(DisplayNameComponent.class);
    displayNameComponent.name = blockFamily.getDisplayName();
    ItemComponent item = builder.getComponent(ItemComponent.class);
    if (blockFamily.getArchetypeBlock().isStackable()) {
        item.stackId = "block:" + blockFamily.getURI().toString();
        item.stackCount = (byte) quantity;
    }
    BlockItemComponent blockItem = builder.getComponent(BlockItemComponent.class);
    blockItem.blockFamily = blockFamily;
    return builder;
}
Also used : DisplayNameComponent(org.terasology.logic.common.DisplayNameComponent) ItemComponent(org.terasology.logic.inventory.ItemComponent) LightComponent(org.terasology.rendering.logic.LightComponent) EntityBuilder(org.terasology.entitySystem.entity.EntityBuilder) LightComponent(org.terasology.rendering.logic.LightComponent) ItemComponent(org.terasology.logic.inventory.ItemComponent) Component(org.terasology.entitySystem.Component) DisplayNameComponent(org.terasology.logic.common.DisplayNameComponent) Prefab(org.terasology.entitySystem.prefab.Prefab)

Example 12 with DisplayNameComponent

use of org.terasology.logic.common.DisplayNameComponent in project Terasology by MovingBlocks.

the class AbstractClient method createEntity.

protected void createEntity(String preferredName, Color color, EntityManager entityManager) {
    // Create player entity
    clientEntity = entityManager.create("engine:client");
    // TODO: Send event for clientInfo creation, don't create here.
    EntityRef clientInfo = findClientEntityRef(entityManager);
    if (!clientInfo.exists()) {
        clientInfo = createClientInfoEntity(entityManager);
    }
    ClientInfoComponent clientInfoComp = clientInfo.getComponent(ClientInfoComponent.class);
    clientInfoComp.client = clientEntity;
    clientInfo.saveComponent(clientInfoComp);
    ClientComponent clientComponent = clientEntity.getComponent(ClientComponent.class);
    clientComponent.clientInfo = clientInfo;
    clientEntity.saveComponent(clientComponent);
    addOrSetColorComponent(clientInfo, color);
    DisplayNameComponent displayNameComponent = clientInfo.getComponent(DisplayNameComponent.class);
    if (displayNameComponent == null || !displayNameComponent.name.equals(preferredName)) {
        String bestAvailableName = findUniquePlayerName(preferredName, entityManager, clientInfo);
        addOrSetDisplayNameComponent(clientInfo, bestAvailableName);
    }
}
Also used : DisplayNameComponent(org.terasology.logic.common.DisplayNameComponent) ClientInfoComponent(org.terasology.network.ClientInfoComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) ClientComponent(org.terasology.network.ClientComponent)

Example 13 with DisplayNameComponent

use of org.terasology.logic.common.DisplayNameComponent in project Terasology by MovingBlocks.

the class FieldAccessBenchmark method setup.

@Override
public void setup() {
    i = 0;
    comp = new DisplayNameComponent();
    try {
        accessor = reflectFactory.createFieldAccessor(DisplayNameComponent.class, DisplayNameComponent.class.getField("description"));
    } catch (InaccessibleFieldException | NoSuchFieldException e) {
        logger.error("Failed to establish field accessor object", e);
    }
}
Also used : DisplayNameComponent(org.terasology.logic.common.DisplayNameComponent) InaccessibleFieldException(org.terasology.reflection.reflect.InaccessibleFieldException)

Example 14 with DisplayNameComponent

use of org.terasology.logic.common.DisplayNameComponent in project Terasology by MovingBlocks.

the class CharacterSystem method getDamageTypeName.

/**
 * Extracts the damage type name from a prefab. If the prefab has a {@link DisplayNameComponent}, it will be used.
 * Otherwise the damage type name is parsed, e.g. "engine:directDamage" will become "Direct Damage".
 * @param damageType The damage type prefab.
 * @return A readable name for the damage type.
 */
public String getDamageTypeName(Prefab damageType) {
    // Otherwise, the game will attempt to generate one from the name of that prefab
    if (damageType.hasComponent(DisplayNameComponent.class)) {
        DisplayNameComponent displayNameComponent = damageType.getComponent(DisplayNameComponent.class);
        return displayNameComponent.name;
    } else {
        logger.info(String.format("%s is missing a readable DisplayName", damageType.getName()));
        String damageTypeName = damageType.getName();
        // damageType.getName() returns a ResourceUrn String such as "engine:directDamage"
        // The following calls change the damage type to be more readable
        // For instance, "engine:directDamage" becomes "Direct Damage"
        damageTypeName = damageTypeName.replaceAll(".*:(.*)", "$1");
        damageTypeName = damageTypeName.replaceAll("([A-Z])", " $1");
        damageTypeName = Character.toUpperCase(damageTypeName.charAt(0)) + damageTypeName.substring(1);
        return damageTypeName;
    }
}
Also used : DisplayNameComponent(org.terasology.logic.common.DisplayNameComponent)

Example 15 with DisplayNameComponent

use of org.terasology.logic.common.DisplayNameComponent in project Terasology by MovingBlocks.

the class ServerCommands method shutdownServer.

@Command(shortDescription = "Shutdown the server", runOnServer = true, requiredPermission = PermissionManager.SERVER_MANAGEMENT_PERMISSION)
public String shutdownServer(@Sender EntityRef sender) {
    // TODO: verify permissions of sender
    EntityRef clientInfo = sender.getComponent(ClientComponent.class).clientInfo;
    DisplayNameComponent name = clientInfo.getComponent(DisplayNameComponent.class);
    logger.info("Shutdown triggered by {}", name.name);
    gameEngine.shutdown();
    return "Server shutdown triggered";
}
Also used : DisplayNameComponent(org.terasology.logic.common.DisplayNameComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) ClientComponent(org.terasology.network.ClientComponent) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Aggregations

DisplayNameComponent (org.terasology.logic.common.DisplayNameComponent)23 EntityRef (org.terasology.entitySystem.entity.EntityRef)17 ClientComponent (org.terasology.network.ClientComponent)13 Command (org.terasology.logic.console.commandSystem.annotations.Command)9 CharacterTeleportEvent (org.terasology.logic.characters.CharacterTeleportEvent)4 LocationComponent (org.terasology.logic.location.LocationComponent)4 Vector3f (org.terasology.math.geom.Vector3f)4 Component (org.terasology.entitySystem.Component)2 EntityBuilder (org.terasology.entitySystem.entity.EntityBuilder)2 Prefab (org.terasology.entitySystem.prefab.Prefab)2 ItemComponent (org.terasology.logic.inventory.ItemComponent)2 PlayerCharacterComponent (org.terasology.logic.players.PlayerCharacterComponent)2 ColorComponent (org.terasology.network.ColorComponent)2 LightComponent (org.terasology.rendering.logic.LightComponent)2 HashSet (java.util.HashSet)1 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)1 CharacterMovementComponent (org.terasology.logic.characters.CharacterMovementComponent)1 MovementMode (org.terasology.logic.characters.MovementMode)1 SetMovementModeEvent (org.terasology.logic.characters.events.SetMovementModeEvent)1 Client (org.terasology.network.Client)1