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;
}
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);
}
}
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);
}
}
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);
}
}
}
}
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();
}
Aggregations