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;
}
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);
}
}
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);
}
}
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;
}
}
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";
}
Aggregations