Search in sources :

Example 26 with EntityRef

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

the class ReadWriteStorageManager method deactivatePlayer.

@Override
public void deactivatePlayer(Client client) {
    EntityRef character = client.getEntity().getComponent(ClientComponent.class).character;
    PlayerStoreBuilder playerStoreBuilder = createPlayerStore(client, character);
    EntityData.PlayerStore playerStore = playerStoreBuilder.build(getEntityManager());
    deactivateOrDestroyEntityRecursive(character);
    unloadedAndUnsavedPlayerMap.put(client.getId(), playerStore);
}
Also used : EntityData(org.terasology.protobuf.EntityData) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ClientComponent(org.terasology.engine.network.ClientComponent)

Example 27 with EntityRef

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

the class EntityAwareWorldProvider method setBlockRetainComponent.

@Override
@SafeVarargs
public final Block setBlockRetainComponent(Vector3ic position, Block type, Class<? extends Component>... components) {
    if (GameThread.isCurrentThread()) {
        EntityRef blockEntity = getBlockEntityAt(position);
        Block oldType = super.setBlock(position, type);
        if (oldType != null) {
            updateBlockEntity(blockEntity, position, oldType, type, false, Sets.newHashSet(components));
        }
        return oldType;
    }
    return null;
}
Also used : OnChangedBlock(org.terasology.engine.world.OnChangedBlock) Block(org.terasology.engine.world.block.Block) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef)

Example 28 with EntityRef

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

the class EntityAwareWorldProvider method setPermanentBlockEntity.

@Override
public EntityRef setPermanentBlockEntity(Vector3ic blockPosition, EntityRef blockEntity) {
    if (GameThread.isCurrentThread()) {
        EntityRef oldEntity = getExistingBlockEntityAt(blockPosition);
        blockEntityLookup.put(new Vector3i(blockPosition), blockEntity);
        temporaryBlockEntities.remove(blockEntity);
        return oldEntity;
    }
    logger.error("Attempted to set block entity off-thread");
    return EntityRef.NULL;
}
Also used : Vector3i(org.joml.Vector3i) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef)

Example 29 with EntityRef

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

the class EntityAwareWorldProvider method onActivateBlock.

@ReceiveEvent(components = BlockComponent.class)
public void onActivateBlock(OnActivatedComponent event, EntityRef entity) {
    BlockComponent block = entity.getComponent(BlockComponent.class);
    EntityRef oldEntity = blockEntityLookup.put(block.getPosition(new Vector3i()), entity);
    // If this is a client, then an existing block entity may exist. Destroy it.
    if (oldEntity != null && !Objects.equal(oldEntity, entity)) {
        oldEntity.destroy();
    }
}
Also used : BlockComponent(org.terasology.engine.world.block.BlockComponent) Vector3i(org.joml.Vector3i) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 30 with EntityRef

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

the class EntityAwareWorldProvider method createBlockEntity.

private EntityRef createBlockEntity(Vector3ic blockPosition, Block block) {
    EntityBuilder builder = entityManager.newBuilder(block.getPrefab().orElse(null));
    builder.addComponent(new LocationComponent(new Vector3f(blockPosition)));
    builder.addComponent(new BlockComponent(block, blockPosition));
    boolean isTemporary = isTemporaryBlock(builder, block);
    if (!isTemporary && !builder.hasComponent(NetworkComponent.class)) {
        builder.addComponent(new NetworkComponent());
    }
    EntityRef blockEntity;
    if (isTemporary) {
        blockEntity = builder.buildWithoutLifecycleEvents();
        temporaryBlockEntities.add(blockEntity);
    } else {
        blockEntity = builder.build();
    }
    blockEntityLookup.put(new Vector3i(blockPosition), blockEntity);
    return blockEntity;
}
Also used : BlockComponent(org.terasology.engine.world.block.BlockComponent) NetworkComponent(org.terasology.engine.network.NetworkComponent) Vector3f(org.joml.Vector3f) Vector3i(org.joml.Vector3i) EntityBuilder(org.terasology.engine.entitySystem.entity.EntityBuilder) LocationComponent(org.terasology.engine.logic.location.LocationComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef)

Aggregations

EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)298 Test (org.junit.jupiter.api.Test)88 ClientComponent (org.terasology.engine.network.ClientComponent)55 Vector3f (org.joml.Vector3f)51 LocationComponent (org.terasology.engine.logic.location.LocationComponent)44 Vector3i (org.joml.Vector3i)36 Command (org.terasology.engine.logic.console.commandSystem.annotations.Command)34 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)29 StringComponent (org.terasology.unittest.stubs.StringComponent)26 NetworkComponent (org.terasology.engine.network.NetworkComponent)23 EntityData (org.terasology.protobuf.EntityData)23 Quaternionf (org.joml.Quaternionf)19 DisplayNameComponent (org.terasology.engine.logic.common.DisplayNameComponent)19 Component (org.terasology.gestalt.entitysystem.component.Component)19 CharacterComponent (org.terasology.engine.logic.characters.CharacterComponent)15 Map (java.util.Map)14 EntityBuilder (org.terasology.engine.entitySystem.entity.EntityBuilder)13 BlockComponent (org.terasology.engine.world.block.BlockComponent)13 Block (org.terasology.engine.world.block.Block)11 Prefab (org.terasology.engine.entitySystem.prefab.Prefab)10