use of org.terasology.entitySystem.entity.EntityBuilder in project Terasology by MovingBlocks.
the class PojoEntityPool method create.
@Override
public EntityRef create(Iterable<Component> components, boolean sendLifecycleEvents) {
EntityBuilder builder = newBuilder();
builder.addComponents(components);
builder.setSendLifecycleEvents(sendLifecycleEvents);
return builder.build();
}
use of org.terasology.entitySystem.entity.EntityBuilder in project Terasology by MovingBlocks.
the class BehaviorNodeFactory method refreshPrefabs.
private void refreshPrefabs() {
Collection<Prefab> prefabs = prefabManager.listPrefabs(BehaviorNodeComponent.class);
if (prefabs.size() == 0) {
// called from main menu
List<String> nodes = Arrays.asList("counter", "timer", "loop", "lookup", "dynselector", "fail", "parallel", "playMusic", "playSound", "running", "selector", "setAnimation", "sequence", "succeed");
prefabs = Lists.newArrayList();
for (String node : nodes) {
prefabs.add(Assets.get(new ResourceUrn("engine:" + node), Prefab.class).orElse(null));
}
}
for (Prefab prefab : prefabs) {
EntityBuilder entityBuilder = entityManager.newBuilder(prefab);
entityBuilder.setPersistent(false);
EntityRef entityRef = entityBuilder.build();
BehaviorNodeComponent component = entityRef.getComponent(BehaviorNodeComponent.class);
addToCategory(component);
nodeComponents.add(component);
}
}
use of org.terasology.entitySystem.entity.EntityBuilder in project Terasology by MovingBlocks.
the class NetworkOwnershipTest method testClientSentInitialOnlyOnce.
@Test
public void testClientSentInitialOnlyOnce() {
EntityBuilder builder = entityManager.newBuilder();
NetworkComponent netComp = builder.addComponent(new NetworkComponent());
netComp.replicateMode = NetworkComponent.ReplicateMode.OWNER;
builder.setOwner(clientEntity);
EntityRef entity = builder.build();
networkSystem.registerNetworkEntity(entity);
connectClient();
networkSystem.updateOwnership(entity);
verify(client, times(1)).setNetInitial(entity.getComponent(NetworkComponent.class).getNetworkId());
}
use of org.terasology.entitySystem.entity.EntityBuilder in project Terasology by MovingBlocks.
the class VisualCharacterSystem method createVisualCharacterIfNotOwnCharacter.
void createVisualCharacterIfNotOwnCharacter(EntityRef characterEntity, VisualCharacterComponent visualCharacterComponent) {
boolean isCharacterOfLocalPlayer = characterEntity.getOwner().equals(localPlayer.getClientEntity());
if (isCharacterOfLocalPlayer) {
return;
}
CreateVisualCharacterEvent event = new CreateVisualCharacterEvent(entityManager.newBuilder());
characterEntity.send(event);
EntityBuilder entityBuilder = event.getVisualCharacterBuilder();
EntityRef visualCharacterEntity = createAndAttachVisualEntityStrategy.createAndAttachVisualEntity(entityBuilder, characterEntity);
visualCharacterComponent.visualCharacter = visualCharacterEntity;
characterEntity.saveComponent(visualCharacterComponent);
}
use of org.terasology.entitySystem.entity.EntityBuilder in project Terasology by MovingBlocks.
the class NameTagClientSystem method createOrUpdateNameTagFor.
private void createOrUpdateNameTagFor(EntityRef entity, NameTagComponent nameTagComponent) {
EntityRef nameTag = nameTagEntityToFloatingTextMap.get(entity);
Vector3f offset = new Vector3f(0, nameTagComponent.yOffset, 0);
if (nameTag != null) {
FloatingTextComponent floatingText = nameTag.getComponent(FloatingTextComponent.class);
floatingText.text = nameTagComponent.text;
floatingText.textColor = nameTagComponent.textColor;
floatingText.scale = nameTagComponent.scale;
nameTag.saveComponent(floatingText);
LocationComponent nameTagLoc = nameTag.getComponent(LocationComponent.class);
nameTagLoc.setLocalPosition(offset);
nameTag.saveComponent(nameTagLoc);
} else {
EntityBuilder nameTagBuilder = entityManager.newBuilder();
FloatingTextComponent floatingTextComponent = new FloatingTextComponent();
nameTagBuilder.addComponent(floatingTextComponent);
LocationComponent locationComponent = new LocationComponent();
nameTagBuilder.addComponent(locationComponent);
floatingTextComponent.text = nameTagComponent.text;
floatingTextComponent.textColor = nameTagComponent.textColor;
floatingTextComponent.scale = nameTagComponent.scale;
nameTagBuilder.setOwner(entity);
nameTagBuilder.setPersistent(false);
nameTag = nameTagBuilder.build();
nameTagEntityToFloatingTextMap.put(entity, nameTag);
Location.attachChild(entity, nameTag, offset, new Quat4f(1, 0, 0, 0));
}
}
Aggregations