use of org.terasology.entitySystem.entity.EntityBuilder in project Terasology by MovingBlocks.
the class VisualCharacterSystemTest method setup.
@Before
public void setup() throws Exception {
this.system = new VisualCharacterSystem();
Context context = new ContextImpl();
this.localPlayer = Mockito.mock(LocalPlayer.class);
context.put(LocalPlayer.class, localPlayer);
Mockito.doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
return clientEntityReturnedByLocalPlayer;
}
}).when(localPlayer).getClientEntity();
this.entityManager = Mockito.mock(EntityManager.class);
Mockito.doReturn(Mockito.mock(EntityBuilder.class)).when(entityManager).newBuilder();
context.put(EntityManager.class, this.entityManager);
InjectionHelper.inject(system, context);
system.setCreateAndAttachVisualEntityStrategy((entityBuilder, characterEntity) -> Mockito.mock(EntityRef.class));
}
use of org.terasology.entitySystem.entity.EntityBuilder 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.entitySystem.entity.EntityBuilder in project Terasology by MovingBlocks.
the class PojoEntityManager method createEntityWithId.
@Override
public EntityRef createEntityWithId(long id, Iterable<Component> components) {
EntityBuilder builder = newBuilder();
builder.setId(id);
builder.addComponents(components);
return builder.build();
}
use of org.terasology.entitySystem.entity.EntityBuilder in project Terasology by MovingBlocks.
the class PojoEntityPool method createEntityWithId.
@Override
public EntityRef createEntityWithId(long id, Iterable<Component> components) {
EntityBuilder builder = newBuilder();
builder.setId(id);
builder.addComponents(components);
return builder.build();
}
use of org.terasology.entitySystem.entity.EntityBuilder in project Terasology by MovingBlocks.
the class PojoEntityPool method create.
private EntityRef create(Prefab prefab, Vector3f position, Quat4f rotation, boolean sendLifecycleEvents) {
EntityBuilder builder = newBuilder(prefab);
builder.setSendLifecycleEvents(sendLifecycleEvents);
LocationComponent loc = builder.getComponent(LocationComponent.class);
if (loc == null && (position != null || rotation != null)) {
loc = new LocationComponent();
builder.addComponent(loc);
}
if (position != null) {
loc.setWorldPosition(position);
}
if (rotation != null) {
loc.setWorldRotation(rotation);
}
return builder.build();
}
Aggregations