Search in sources :

Example 46 with Component

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();
}
Also used : EnergyRangeGeneratorFunction(org.terasology.particles.functions.generators.EnergyRangeGeneratorFunction) VelocityAffectorFunction(org.terasology.particles.functions.affectors.VelocityAffectorFunction) EnergyRangeGeneratorComponent(org.terasology.particles.components.generators.EnergyRangeGeneratorComponent) EnergyRangeGeneratorComponent(org.terasology.particles.components.generators.EnergyRangeGeneratorComponent) ParticleEmitterComponent(org.terasology.particles.components.ParticleEmitterComponent) VelocityAffectorComponent(org.terasology.particles.components.affectors.VelocityAffectorComponent) Component(org.terasology.entitySystem.Component) LinkedList(java.util.LinkedList) VelocityAffectorComponent(org.terasology.particles.components.affectors.VelocityAffectorComponent)

Example 47 with Component

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));
        }
    }
}
Also used : EnergyRangeGeneratorComponent(org.terasology.particles.components.generators.EnergyRangeGeneratorComponent) ParticleEmitterComponent(org.terasology.particles.components.ParticleEmitterComponent) VelocityAffectorComponent(org.terasology.particles.components.affectors.VelocityAffectorComponent) Component(org.terasology.entitySystem.Component) EntityRef(org.terasology.entitySystem.entity.EntityRef) ParticleEmitterComponent(org.terasology.particles.components.ParticleEmitterComponent) Test(org.junit.Test)

Example 48 with 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()));
    }
}
Also used : LocationComponent(org.terasology.logic.location.LocationComponent) RigidBodyComponent(org.terasology.physics.components.RigidBodyComponent) OnAddedComponent(org.terasology.entitySystem.entity.lifecycleEvents.OnAddedComponent) Component(org.terasology.entitySystem.Component) BoxShapeComponent(org.terasology.physics.components.shapes.BoxShapeComponent) BlockItemComponent(org.terasology.world.block.items.BlockItemComponent) LocationComponent(org.terasology.logic.location.LocationComponent) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 49 with Component

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;
}
Also used : HashMap(java.util.HashMap) Component(org.terasology.entitySystem.Component) HashSet(java.util.HashSet)

Aggregations

Component (org.terasology.entitySystem.Component)49 EntityRef (org.terasology.entitySystem.entity.EntityRef)15 Prefab (org.terasology.entitySystem.prefab.Prefab)9 LocationComponent (org.terasology.logic.location.LocationComponent)9 EntityData (org.terasology.protobuf.EntityData)8 OnActivatedComponent (org.terasology.entitySystem.entity.lifecycleEvents.OnActivatedComponent)7 NetworkComponent (org.terasology.network.NetworkComponent)7 BlockComponent (org.terasology.world.block.BlockComponent)7 OnAddedComponent (org.terasology.entitySystem.entity.lifecycleEvents.OnAddedComponent)6 OnChangedComponent (org.terasology.entitySystem.entity.lifecycleEvents.OnChangedComponent)6 EntityInfoComponent (org.terasology.entitySystem.entity.internal.EntityInfoComponent)5 BeforeDeactivateComponent (org.terasology.entitySystem.entity.lifecycleEvents.BeforeDeactivateComponent)5 EntityBuilder (org.terasology.entitySystem.entity.EntityBuilder)4 ByteString (com.google.protobuf.ByteString)3 Test (org.junit.Test)3 BeforeRemoveComponent (org.terasology.entitySystem.entity.lifecycleEvents.BeforeRemoveComponent)3 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)3 SectorSimulationComponent (org.terasology.entitySystem.sectors.SectorSimulationComponent)3 ParticleEmitterComponent (org.terasology.particles.components.ParticleEmitterComponent)3 WorldConfigurator (org.terasology.world.generator.WorldConfigurator)3