Search in sources :

Example 16 with BlockComponent

use of org.terasology.world.block.BlockComponent in project Terasology by MovingBlocks.

the class CameraTargetSystem method update.

public void update(float delta) {
    // Repair lost target
    // TODO: Improvements to temporary chunk handling will remove the need for this
    boolean lostTarget = false;
    updateTarget();
    if (!target.exists()) {
        targetBlockPos = null;
        lostTarget = true;
    }
    HitResult hitInfo = physics.rayTrace(new Vector3f(localPlayer.getViewPosition()), new Vector3f(localPlayer.getViewDirection()), targetDistance, filter);
    updateFocalDistance(hitInfo, delta);
    Vector3i newBlockPos = null;
    EntityRef newTarget = EntityRef.NULL;
    if (hitInfo.isHit()) {
        newTarget = hitInfo.getEntity();
        hitPosition = hitInfo.getHitPoint();
        hitNormal = hitInfo.getHitNormal();
        if (hitInfo.isWorldHit()) {
            newBlockPos = new Vector3i(hitInfo.getBlockPosition());
        }
    }
    if (!Objects.equal(target, newTarget) || lostTarget) {
        EntityRef oldTarget = target;
        oldTarget.send(new CameraOutEvent());
        newTarget.send(new CameraOverEvent());
        localPlayer.getCharacterEntity().send(new CameraTargetChangedEvent(oldTarget, newTarget));
        // Set isBlock to false if the hit-entity does not have a BlockComponent
        isBlock = !(isTargetAvailable() && !newTarget.hasComponent(BlockComponent.class));
    }
    target = newTarget;
    targetBlockPos = newBlockPos;
}
Also used : HitResult(org.terasology.physics.HitResult) BlockComponent(org.terasology.world.block.BlockComponent) Vector3f(org.terasology.math.geom.Vector3f) Vector3i(org.terasology.math.geom.Vector3i) EntityRef(org.terasology.entitySystem.entity.EntityRef)

Example 17 with BlockComponent

use of org.terasology.world.block.BlockComponent in project Terasology by MovingBlocks.

the class EntityCreateBenchmark method setup.

@Override
public void setup() {
    FastRandom rand = new FastRandom(0L);
    rawEntityData = Lists.newArrayList();
    for (int i = 0; i < 1000; ++i) {
        List<Component> entityData = Lists.newArrayList();
        if (rand.nextFloat() < 0.75f) {
            entityData.add(new LocationComponent());
        }
        if (rand.nextFloat() < 0.5f) {
            entityData.add(new MeshComponent());
        }
        if (rand.nextFloat() < 0.25f) {
            entityData.add(new BlockComponent());
        }
        rawEntityData.add(entityData);
    }
}
Also used : BlockComponent(org.terasology.world.block.BlockComponent) MeshComponent(org.terasology.rendering.logic.MeshComponent) FastRandom(org.terasology.utilities.random.FastRandom) MeshComponent(org.terasology.rendering.logic.MeshComponent) BlockComponent(org.terasology.world.block.BlockComponent) Component(org.terasology.entitySystem.Component) LocationComponent(org.terasology.logic.location.LocationComponent) LocationComponent(org.terasology.logic.location.LocationComponent)

Example 18 with BlockComponent

use of org.terasology.world.block.BlockComponent in project Terasology by MovingBlocks.

the class IterateSingleComponentBenchmark method setup.

@Override
public void setup() {
    FastRandom rand = new FastRandom(0L);
    rawEntityData = Lists.newArrayList();
    for (int i = 0; i < 1000; ++i) {
        List<Component> entityData = Lists.newArrayList();
        if (rand.nextFloat() < 0.75f) {
            entityData.add(new LocationComponent());
        }
        if (rand.nextFloat() < 0.5f) {
            entityData.add(new MeshComponent());
        }
        if (rand.nextFloat() < 0.25f) {
            entityData.add(new BlockComponent());
        }
        rawEntityData.add(entityData);
    }
    entityManager = new PojoEntityManager();
    for (List<Component> rawEntity : rawEntityData) {
        entityManager.create(rawEntity);
    }
}
Also used : BlockComponent(org.terasology.world.block.BlockComponent) MeshComponent(org.terasology.rendering.logic.MeshComponent) PojoEntityManager(org.terasology.entitySystem.entity.internal.PojoEntityManager) FastRandom(org.terasology.utilities.random.FastRandom) MeshComponent(org.terasology.rendering.logic.MeshComponent) BlockComponent(org.terasology.world.block.BlockComponent) Component(org.terasology.entitySystem.Component) LocationComponent(org.terasology.logic.location.LocationComponent) LocationComponent(org.terasology.logic.location.LocationComponent)

Example 19 with BlockComponent

use of org.terasology.world.block.BlockComponent in project Terasology by MovingBlocks.

the class EntityDestructionAuthoritySystem method recordDestroyed.

private void recordDestroyed(DestroyEvent event, EntityRef entityRef) {
    EntityRef instigator = event.getInstigator();
    if (instigator != null) {
        if (entityRef.hasComponent(BlockComponent.class)) {
            BlockComponent blockComponent = entityRef.getComponent(BlockComponent.class);
            String blockName = blockComponent.getBlock().getDisplayName();
            if (instigator.hasComponent(GamePlayStatsComponent.class)) {
                GamePlayStatsComponent gamePlayStatsComponent = instigator.getComponent(GamePlayStatsComponent.class);
                Map<String, Integer> blockDestroyedMap = gamePlayStatsComponent.blockDestroyedMap;
                if (blockDestroyedMap.containsKey(blockName)) {
                    blockDestroyedMap.put(blockName, blockDestroyedMap.get(blockName) + 1);
                } else {
                    blockDestroyedMap.put(blockName, 1);
                }
                instigator.saveComponent(gamePlayStatsComponent);
            } else {
                GamePlayStatsComponent gamePlayStatsComponent = new GamePlayStatsComponent();
                Map<String, Integer> blockDestroyedMap = gamePlayStatsComponent.blockDestroyedMap;
                blockDestroyedMap.put(blockName, 1);
                instigator.addOrSaveComponent(gamePlayStatsComponent);
            }
        } else if (entityRef.hasComponent(CharacterComponent.class)) {
            String creatureName = entityRef.getParentPrefab().getName();
            if (instigator.hasComponent(GamePlayStatsComponent.class)) {
                GamePlayStatsComponent gamePlayStatsComponent = instigator.getComponent(GamePlayStatsComponent.class);
                Map<String, Integer> creatureKilled = gamePlayStatsComponent.creatureKilled;
                if (creatureKilled.containsKey(creatureName)) {
                    creatureKilled.put(creatureName, creatureKilled.get(creatureName) + 1);
                } else {
                    creatureKilled.put(creatureName, 1);
                }
                instigator.saveComponent(gamePlayStatsComponent);
            } else {
                GamePlayStatsComponent gamePlayStatsComponent = new GamePlayStatsComponent();
                Map<String, Integer> creatureKilled = gamePlayStatsComponent.creatureKilled;
                creatureKilled.put(creatureName, 1);
                instigator.addOrSaveComponent(gamePlayStatsComponent);
            }
        }
    }
}
Also used : BlockComponent(org.terasology.world.block.BlockComponent) GamePlayStatsComponent(org.terasology.telemetry.GamePlayStatsComponent) CharacterComponent(org.terasology.logic.characters.CharacterComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) Map(java.util.Map)

Example 20 with BlockComponent

use of org.terasology.world.block.BlockComponent in project Terasology by MovingBlocks.

the class BlockDamageRenderer method renderOverlay.

@Override
public void renderOverlay() {
    if (blockSelectionRenderer == null) {
        Texture texture = Assets.getTextureRegion("core:blockdamageeffects#1").get().getTexture();
        blockSelectionRenderer = new BlockSelectionRenderer(texture);
    }
    // group the entities into what texture they will use so that there is less recreating meshes (changing a texture region on the BlockSelectionRenderer
    // will recreate the mesh to use the different UV coordinates).  Also this allows
    Multimap<Integer, Vector3i> groupedEntitiesByEffect = ArrayListMultimap.create();
    for (EntityRef entity : entityManager.getEntitiesWith(HealthComponent.class, BlockComponent.class)) {
        HealthComponent health = entity.getComponent(HealthComponent.class);
        if (health.currentHealth == health.maxHealth) {
            continue;
        }
        BlockComponent blockComponent = entity.getComponent(BlockComponent.class);
        groupedEntitiesByEffect.put(getEffectsNumber(health), blockComponent.getPosition());
    }
    for (EntityRef entity : entityManager.getEntitiesWith(BlockRegionComponent.class, HealthComponent.class)) {
        HealthComponent health = entity.getComponent(HealthComponent.class);
        if (health.currentHealth == health.maxHealth) {
            continue;
        }
        BlockRegionComponent blockRegion = entity.getComponent(BlockRegionComponent.class);
        for (Vector3i blockPos : blockRegion.region) {
            groupedEntitiesByEffect.put(getEffectsNumber(health), blockPos);
        }
    }
    // we know that the texture will be the same for each block effect,  just differnt UV coordinates.  Bind the texture already
    blockSelectionRenderer.beginRenderOverlay();
    for (Integer effectsNumber : groupedEntitiesByEffect.keySet()) {
        Optional<TextureRegionAsset> texture = Assets.getTextureRegion("core:blockdamageeffects#" + effectsNumber);
        if (texture.isPresent()) {
            blockSelectionRenderer.setEffectsTexture(texture.get());
            for (Vector3i position : groupedEntitiesByEffect.get(effectsNumber)) {
                blockSelectionRenderer.renderMark(position);
            }
        }
    }
    blockSelectionRenderer.endRenderOverlay();
}
Also used : BlockComponent(org.terasology.world.block.BlockComponent) BlockRegionComponent(org.terasology.world.block.regions.BlockRegionComponent) Vector3i(org.terasology.math.geom.Vector3i) BlockSelectionRenderer(org.terasology.rendering.world.selection.BlockSelectionRenderer) Texture(org.terasology.rendering.assets.texture.Texture) EntityRef(org.terasology.entitySystem.entity.EntityRef) TextureRegionAsset(org.terasology.rendering.assets.texture.TextureRegionAsset)

Aggregations

BlockComponent (org.terasology.world.block.BlockComponent)20 EntityRef (org.terasology.entitySystem.entity.EntityRef)11 Vector3i (org.terasology.math.geom.Vector3i)10 LocationComponent (org.terasology.logic.location.LocationComponent)9 NetworkComponent (org.terasology.network.NetworkComponent)7 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)6 Component (org.terasology.entitySystem.Component)4 Vector3f (org.terasology.math.geom.Vector3f)4 MeshComponent (org.terasology.rendering.logic.MeshComponent)4 Block (org.terasology.world.block.Block)4 BlockRegionComponent (org.terasology.world.block.regions.BlockRegionComponent)4 FastRandom (org.terasology.utilities.random.FastRandom)3 PlaySoundEvent (org.terasology.audio.events.PlaySoundEvent)2 EntityBuilder (org.terasology.entitySystem.entity.EntityBuilder)2 PojoEntityManager (org.terasology.entitySystem.entity.internal.PojoEntityManager)2 Side (org.terasology.math.Side)2 Client (org.terasology.network.Client)2 PlaceBlocks (org.terasology.world.block.entity.placement.PlaceBlocks)2 BlockFamily (org.terasology.world.block.family.BlockFamily)2 HashMap (java.util.HashMap)1