use of org.terasology.engine.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class SectorUtil method getWatchedChunks.
/**
* Watched chunks are defined as the union of:
* <ul>
* <li>The chunk in which the {@link LocationComponent#getWorldPosition(Vector3f)} resides, if any</li>
* <li>The set of chunks in {@link SectorRegionComponent#chunks}, if any</li>
* </ul>
*
* @param entity the entity to query the watched chunks of
* @return the set of positions of this entity's watched chunks
*/
public static Set<Vector3i> getWatchedChunks(EntityRef entity) {
Set<Vector3i> chunks = new HashSet<>();
LocationComponent loc = entity.getComponent(LocationComponent.class);
Vector3f position = loc.getWorldPosition(new Vector3f());
if (position.isFinite()) {
chunks.add(Chunks.toChunkPos(position, new Vector3i()));
}
SectorRegionComponent regionComponent = entity.getComponent(SectorRegionComponent.class);
if (regionComponent != null) {
// potential leaky abstraction. component exposes its internal vectors
chunks.addAll(regionComponent.chunks);
}
return chunks;
}
use of org.terasology.engine.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class ParticleEmitterComponent method copyFrom.
@Override
public void copyFrom(ParticleEmitterComponent other) {
this.maxParticles = other.maxParticles;
this.particleCollision = other.particleCollision;
this.spawnRateMax = other.spawnRateMax;
this.spawnRateMin = other.spawnRateMin;
this.enabled = other.enabled;
this.lifeTime = other.lifeTime;
this.particleSpawnsLeft = other.particleSpawnsLeft;
this.destroyEntityWhenDead = other.destroyEntityWhenDead;
this.ownerEntity = other.ownerEntity;
this.particlePool = other.particlePool;
this.generatorFunctionMap.clear();
this.generatorFunctionMap.putAll(other.generatorFunctionMap);
this.affectorFunctionMap.clear();
this.affectorFunctionMap.putAll(other.affectorFunctionMap);
this.locationComponent = new LocationComponent();
// TODO check this
this.locationComponent.copyFrom(other.locationComponent);
this.nextEmission = other.nextEmission;
this.collisionUpdateIteration = other.collisionUpdateIteration;
}
use of org.terasology.engine.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class AbstractStorageManager method getEntitiesOfChunk.
protected Collection<EntityRef> getEntitiesOfChunk(Chunk chunk) {
List<EntityRef> entitiesToStore = Lists.newArrayList();
AABBfc aabb = chunk.getAABB();
for (EntityRef entity : getEntityManager().getEntitiesWith(LocationComponent.class)) {
if (!entity.getOwner().exists() && !entity.isAlwaysRelevant() && !entity.hasComponent(ClientComponent.class)) {
LocationComponent loc = entity.getComponent(LocationComponent.class);
if (loc == null) {
continue;
}
Vector3f pos = loc.getWorldPosition(new Vector3f());
if (pos.isFinite()) {
if (aabb.containsPoint(loc.getWorldPosition(new Vector3f()))) {
entitiesToStore.add(entity);
}
}
}
}
return entitiesToStore;
}
use of org.terasology.engine.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class NetClient method sendNewChunks.
private void sendNewChunks(NetData.NetMessage.Builder message) {
if (!readyChunks.isEmpty()) {
chunkSendCounter += chunkSendRate * NET_TICK_RATE * networkSystem.getBandwidthPerClient();
if (chunkSendCounter > 1.0f) {
chunkSendCounter -= 1.0f;
Vector3i center = new Vector3i();
LocationComponent loc = getEntity().getComponent(ClientComponent.class).character.getComponent(LocationComponent.class);
if (loc != null) {
Vector3f target = loc.getWorldPosition(new Vector3f());
if (target.isFinite()) {
// use center as temporary variable
center.set(target, RoundingMode.HALF_UP);
// update center to chunkPos
Chunks.toChunkPos(center, center);
}
}
Vector3i pos = null;
long distance = Integer.MAX_VALUE;
for (Vector3i chunkPos : readyChunks.keySet()) {
long chunkDistance = chunkPos.distanceSquared(center);
if (pos == null || chunkDistance < distance) {
pos = chunkPos;
distance = chunkDistance;
}
}
Chunk chunk = readyChunks.remove(pos);
relevantChunks.add(pos);
message.addChunkInfo(chunk.encode());
}
} else {
chunkSendCounter = 1.0f;
}
}
use of org.terasology.engine.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class CoreCommands method bowlingPrep.
@Command(shortDescription = "Sets up a typical bowling pin arrangement in front of the player. ", helpText = "Spawns the specific block in a regular bowling pin pattern, Throw something at it!", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String bowlingPrep(@Sender EntityRef sender, @CommandParam("blockName") String blockName) {
ClientComponent clientComponent = sender.getComponent(ClientComponent.class);
LocationComponent characterLocation = clientComponent.character.getComponent(LocationComponent.class);
Vector3f spawnPos = characterLocation.getWorldPosition(new Vector3f());
Vector3f offset = characterLocation.getWorldDirection(new Vector3f());
offset.mul(5);
spawnPos.add(offset);
BlockFamily block = blockManager.getBlockFamily(blockName);
if (block == null) {
return "Sorry, your block is not found";
}
BlockItemFactory blockItemFactory = new BlockItemFactory(entityManager);
Vector3f startPos = new Vector3f(spawnPos);
// delta x is the distance between the pins in the rows.
float deltax = 0.5f;
// delta z is the distance between the rows.
float deltaz = 1.0f;
// the height of the drop (to be modified to keep the bowlingPin upright)
float vectorY = 0.0f;
// rownumber loop is for selecting row
for (int rownumber = 0; rownumber < 4; rownumber++) {
// Spawn starting position for Rownumber
startPos.add(deltax * (4 - rownumber), vectorY, deltaz);
// pinPosx loop is for vectorx position of bowling pin in a particular row
for (int pinPosx = 0; pinPosx <= rownumber; pinPosx++) {
EntityRef blockItem = blockItemFactory.newInstance(block);
blockItem.send(new DropItemEvent(startPos));
if (pinPosx < rownumber) {
// drift of position in vector x coordinate, for the last pin stop drifting
startPos.add(2 * deltax, 0, 0);
}
}
// returns to start position
startPos.add(-deltax * (rownumber + 4), 0, 0);
}
return "prepared 10 " + blockName + " in a bowling pin pattern :)";
}
Aggregations