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