Search in sources :

Example 6 with EntityRef

use of org.terasology.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.

the class InspectionScreen method initialise.

@Override
public void initialise() {
    fullDescriptionLabel = find("fullDescriptionLabel", UIText.class);
    entityIdField = find("entityIdField", UIText.class);
    setEntityIdButton = find("setEntityIdButton", UIButton.class);
    setEntityIdButton.subscribe(widget -> {
        String text = entityIdField.getText();
        EntityRef interactionTarget = getInteractionTarget();
        InspectionToolComponent inspectorComponent = interactionTarget.getComponent(InspectionToolComponent.class);
        if (text.equals("this")) {
            inspectorComponent.inspectedEntity = interactionTarget;
        } else {
            try {
                int id1 = Integer.parseInt(text);
                inspectorComponent.inspectedEntity = CoreRegistry.get(EntityManager.class).getEntity(id1);
            } catch (NumberFormatException e) {
                fullDescriptionLabel.setText("Please specify a valid number");
            }
        }
        updateFields(interactionTarget);
    });
}
Also used : UIButton(org.terasology.rendering.nui.widgets.UIButton) InspectionToolComponent(org.terasology.logic.common.InspectionToolComponent) UIText(org.terasology.rendering.nui.widgets.UIText) EntityRef(org.terasology.entitySystem.entity.EntityRef)

Example 7 with EntityRef

use of org.terasology.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.

the class OnlinePlayersOverlay method determinePlayerAndPing.

private String determinePlayerAndPing(PingStockComponent pingStockComponent) {
    Iterable<EntityRef> allClients = entityManager.getEntitiesWith(ClientComponent.class);
    Map<EntityRef, Long> pingMap = pingStockComponent.getValues();
    StringBuilder sb = new StringBuilder();
    boolean first = true;
    for (EntityRef clientEntity : allClients) {
        if (!first) {
            sb.append("\n");
        }
        ClientComponent clientComp = clientEntity.getComponent(ClientComponent.class);
        sb.append(PlayerUtil.getColoredPlayerName(clientComp.clientInfo));
        sb.append(" ");
        Long pingValue = pingMap.get(clientEntity);
        if (pingValue == null) {
            sb.append("-");
        } else {
            sb.append(pingValue.toString());
            sb.append("ms");
        }
        first = false;
    }
    return sb.toString();
}
Also used : EntityRef(org.terasology.entitySystem.entity.EntityRef) ClientComponent(org.terasology.network.ClientComponent)

Example 8 with EntityRef

use of org.terasology.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.

the class BlockSelectionRenderSystem method renderOverlay.

@Override
public void renderOverlay() {
    for (EntityRef entity : entityManager.getEntitiesWith(BlockSelectionComponent.class)) {
        BlockSelectionComponent blockSelectionComponent = entity.getComponent(BlockSelectionComponent.class);
        if (blockSelectionComponent.shouldRender) {
            Texture texture = blockSelectionComponent.texture;
            if (null == texture) {
                texture = Assets.getTexture("engine:selection").get();
            }
            Vector2i textureDimensions = new Vector2i(texture.getWidth(), texture.getHeight());
            BlockSelectionRenderer selectionRenderer = cachedBlockSelectionRendererByTextureDimensionsMap.get(textureDimensions);
            if (null == selectionRenderer) {
                selectionRenderer = new BlockSelectionRenderer(texture);
                cachedBlockSelectionRendererByTextureDimensionsMap.put(textureDimensions, selectionRenderer);
            } else {
                selectionRenderer.setEffectsTexture(texture);
            }
            renderOverlayForOneBlockSelection(blockSelectionComponent, selectionRenderer);
        }
    }
}
Also used : BlockSelectionComponent(org.terasology.world.selection.BlockSelectionComponent) Vector2i(org.terasology.math.geom.Vector2i) EntityRef(org.terasology.entitySystem.entity.EntityRef) Texture(org.terasology.rendering.assets.texture.Texture)

Example 9 with EntityRef

use of org.terasology.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.

the class ClientViewDistanceSystem method onChangeViewDistanceChange.

public void onChangeViewDistanceChange() {
    ViewDistance viewDistance = config.getRendering().getViewDistance();
    if (worldRenderer != null) {
        worldRenderer.setViewDistance(viewDistance);
    }
    EntityRef clientEntity = localPlayer.getClientEntity();
    clientEntity.send(new ViewDistanceChangedEvent(viewDistance));
}
Also used : EntityRef(org.terasology.entitySystem.entity.EntityRef)

Example 10 with EntityRef

use of org.terasology.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.

the class CreatureKilledMetric method createTelemetryFieldToValue.

@Override
public Map<String, ?> createTelemetryFieldToValue() {
    localPlayer = CoreRegistry.get(LocalPlayer.class);
    EntityRef playerEntity = localPlayer.getCharacterEntity();
    if (playerEntity.hasComponent(GamePlayStatsComponent.class)) {
        GamePlayStatsComponent gamePlayStatsComponent = playerEntity.getComponent(GamePlayStatsComponent.class);
        telemetryFieldToValue.clear();
        telemetryFieldToValue.putAll(gamePlayStatsComponent.creatureKilled);
        return telemetryFieldToValue;
    } else {
        return telemetryFieldToValue;
    }
}
Also used : LocalPlayer(org.terasology.logic.players.LocalPlayer) GamePlayStatsComponent(org.terasology.telemetry.GamePlayStatsComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef)

Aggregations

EntityRef (org.terasology.entitySystem.entity.EntityRef)337 Test (org.junit.Test)106 ClientComponent (org.terasology.network.ClientComponent)49 LocationComponent (org.terasology.logic.location.LocationComponent)45 Vector3f (org.terasology.math.geom.Vector3f)44 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)36 Vector3i (org.terasology.math.geom.Vector3i)34 Command (org.terasology.logic.console.commandSystem.annotations.Command)28 StringComponent (org.terasology.entitySystem.stubs.StringComponent)26 NetworkComponent (org.terasology.network.NetworkComponent)21 EntityData (org.terasology.protobuf.EntityData)21 DisplayNameComponent (org.terasology.logic.common.DisplayNameComponent)17 Block (org.terasology.world.block.Block)16 Component (org.terasology.entitySystem.Component)15 EntityBuilder (org.terasology.entitySystem.entity.EntityBuilder)15 CharacterComponent (org.terasology.logic.characters.CharacterComponent)14 Quat4f (org.terasology.math.geom.Quat4f)14 BlockComponent (org.terasology.world.block.BlockComponent)13 Map (java.util.Map)11 LocalPlayer (org.terasology.logic.players.LocalPlayer)11