use of org.terasology.entitySystem.Component in project Terasology by MovingBlocks.
the class ParticleUpdaterImplTest method getTestGeneratorsAndAffectors.
private Iterator<Component> getTestGeneratorsAndAffectors() {
Collection<Component> components = new LinkedList<>();
components.add(new EnergyRangeGeneratorComponent(0.5f, 1f));
components.add(new VelocityAffectorComponent());
EnergyRangeGeneratorFunction energyRangeGeneratorFunction = new EnergyRangeGeneratorFunction();
registeredGeneratorFunctions.put(((GeneratorFunction) energyRangeGeneratorFunction).getComponentClass(), energyRangeGeneratorFunction);
VelocityAffectorFunction velocityAffectorFunction = new VelocityAffectorFunction();
registeredAffectorFunctions.put(((AffectorFunction) velocityAffectorFunction).getComponentClass(), velocityAffectorFunction);
return components.iterator();
}
use of org.terasology.entitySystem.Component in project Terasology by MovingBlocks.
the class ParticleUpdaterImplTest method testEmitterConfiguration.
@Test
public void testEmitterConfiguration() {
EntityRef emitterEntity = mock(EntityRef.class);
Iterator<Component> componentIterator = getTestGeneratorsAndAffectors();
when(emitterEntity.iterateComponents()).thenReturn(() -> componentIterator);
ParticleEmitterComponent particleEmitterComponent = new ParticleEmitterComponent();
particleEmitterComponent.ownerEntity = emitterEntity;
when(emitterEntity.getComponent(ParticleEmitterComponent.class)).thenReturn(particleEmitterComponent);
particleUpdater.register(emitterEntity);
particleUpdater.configureEmitter(particleEmitterComponent, registeredAffectorFunctions, registeredGeneratorFunctions);
for (Component component : (Iterable<Component>) () -> componentIterator) {
if (registeredGeneratorFunctions.containsKey(component.getClass())) {
assertTrue(particleEmitterComponent.generatorFunctionMap.containsKey(component));
} else if (registeredGeneratorFunctions.containsKey(component.getClass())) {
assertTrue(particleEmitterComponent.generatorFunctionMap.containsKey(component));
}
}
}
use of org.terasology.entitySystem.Component in project Terasology by MovingBlocks.
the class ItemPickupAuthoritySystem method onDropItemEvent.
@ReceiveEvent
public void onDropItemEvent(DropItemEvent event, EntityRef itemEntity, ItemComponent itemComponent) {
for (Component component : itemComponent.pickupPrefab.iterateComponents()) {
Component componentCopy = library.getComponentLibrary().copy(component);
if (componentCopy instanceof LocationComponent) {
((LocationComponent) componentCopy).setWorldPosition(event.getPosition());
}
itemEntity.addOrSaveComponent(componentCopy);
}
if (!itemEntity.hasComponent(LocationComponent.class)) {
itemEntity.addComponent(new LocationComponent(event.getPosition()));
}
}
use of org.terasology.entitySystem.Component in project Terasology by MovingBlocks.
the class InventoryUtils method hasSameAttributes.
private static boolean hasSameAttributes(EntityRef from, EntityRef to) {
Set<Component> differentiatingComponentsFrom = new HashSet<>();
for (Component component : from.iterateComponents()) {
if (component instanceof ItemDifferentiating) {
differentiatingComponentsFrom.add(component);
}
}
Map<Class<?>, Component> differentiatingComponentsTo = new HashMap<>();
for (Component component : to.iterateComponents()) {
if (component instanceof ItemDifferentiating) {
differentiatingComponentsTo.put(component.getClass(), component);
}
}
if (differentiatingComponentsFrom.size() != differentiatingComponentsTo.size()) {
return false;
}
for (Component component : differentiatingComponentsFrom) {
Component componentInTarget = differentiatingComponentsTo.get(component.getClass());
if (componentInTarget == null) {
return false;
}
if (!component.equals(componentInTarget)) {
return false;
}
}
return true;
}
Aggregations