/** * @return The position at the center of the region */ public Vector3f center() { Vector3f result = min.toVector3f(); Vector3f halfSize = size.toVector3f(); halfSize.scale(0.5f); result.add(halfSize); return result; }
public AABB getBounds(Vector3i pos) { return bounds.move(pos.toVector3f()); }
@Override public AABB getAABB() { if (aabb == null) { Vector3f min = getChunkWorldOffset().toVector3f(); Vector3f max = ChunkConstants.CHUNK_SIZE.toVector3f(); max.add(min); aabb = AABB.createMinMax(min, max); } return aabb; }
private float score(Vector3i chunkPos) { Vector3f vec = chunkPos.toVector3f(); vec.sub(localPlayer.getPosition()); return vec.lengthSquared(); } }
@ReceiveEvent(components = {BlockComponent.class}) public void onBlockAltered(OnChangedBlock event, EntityRef entity) { physics.awakenArea(event.getBlockPosition().toVector3f(), 0.6f); }
private static float squaredDistanceToCamera(RenderableChunk chunk, Vector3f cameraPosition) { // For performance reasons, to avoid instantiating too many vectors in a frequently called method, // comments are in use instead of appropriately named vectors. Vector3f result = chunk.getPosition().toVector3f(); // chunk position in chunk coordinates result.add(CHUNK_CENTER_OFFSET); // chunk center in chunk coordinates result.x *= ChunkConstants.SIZE_X; // chunk center in world coordinates result.y *= ChunkConstants.SIZE_Y; result.z *= ChunkConstants.SIZE_Z; result.sub(cameraPosition); // camera to chunk vector return result.lengthSquared(); }
private void processDropping(EntityRef item, Vector3i location, float impulsePower) { item.send(new DropItemEvent(location.toVector3f())); item.send(new ImpulseEvent(random.nextVector3f(impulsePower))); }
private EntityRef createBlockEntity(Vector3i blockPosition, Block block) { EntityBuilder builder = entityManager.newBuilder(block.getPrefab().orElse(null)); builder.addComponent(new LocationComponent(blockPosition.toVector3f())); builder.addComponent(new BlockComponent(block, blockPosition)); boolean isTemporary = isTemporaryBlock(builder, block); if (!isTemporary && !builder.hasComponent(NetworkComponent.class)) { builder.addComponent(new NetworkComponent()); } EntityRef blockEntity; if (isTemporary) { blockEntity = builder.buildWithoutLifecycleEvents(); temporaryBlockEntities.add(blockEntity); } else { blockEntity = builder.build(); } blockEntityLookup.put(new Vector3i(blockPosition), blockEntity); return blockEntity; }
public static Side getSecondaryPlacementDirection(Vector3f direction, Vector3f normal) { Side surfaceDir = Side.inDirection(normal); Vector3f attachDir = surfaceDir.reverse().getVector3i().toVector3f(); Vector3f rawDirection = new Vector3f(direction); float dot = rawDirection.dot(attachDir); rawDirection.sub(new Vector3f(dot * attachDir.x, dot * attachDir.y, dot * attachDir.z)); return Side.inDirection(rawDirection.x, rawDirection.y, rawDirection.z).reverse(); }
@ReceiveEvent public void onDelayedExplosion(DelayedActionTriggeredEvent event, EntityRef entityRef, ExplosionActionComponent explosionActionComponent) { if (event.getActionId().equals(DELAYED_EXPLOSION_ACTION_ID)) { //check if the exploding entity is a block or not if (entityRef.hasComponent(BlockComponent.class)) { BlockComponent blockComponent = entityRef.getComponent(BlockComponent.class); // always destroy the block that caused the explosion worldProvider.setBlock(blockComponent.position, blockManager.getBlock(BlockManager.AIR_ID)); // create the explosion from the block's location doExplosion(explosionActionComponent, blockComponent.position.toVector3f(), entityRef); } else if (entityRef.hasComponent(LocationComponent.class)) { // get the position of the non-block entity to make it explode from there Vector3f position = entityRef.getComponent(LocationComponent.class).getWorldPosition(); // destroy the non-block entity entityRef.destroy(); // create the explosion from the non-block entity location doExplosion(explosionActionComponent, position, EntityRef.NULL); } } } }
final Vector3f chunkPosition = chunk.getPosition().toVector3f();
location.setLocalPosition(targetBlockPos.toVector3f());
final Vector3f chunkPosition = chunk.getPosition().toVector3f();
offset.sub(targetBlockComp.position.toVector3f()); Side offsetDir = Side.inDirection(offset); entity.removeComponent(MeshComponent.class); newDoor.addComponent(new BlockRegionComponent(Region3i.createBounded(bottomBlockPos, topBlockPos))); Vector3f doorCenter = bottomBlockPos.toVector3f(); doorCenter.y += 0.5f; newDoor.addComponent(new LocationComponent(doorCenter));
final Vector3f chunkPosition = chunk.getPosition().toVector3f();
final Vector3f chunkPosition = chunk.getPosition().toVector3f();
void doExplosion(ExplosionActionComponent explosionComp, Vector3f origin, EntityRef instigatingBlockEntity) { EntityBuilder builder = entityManager.newBuilder("core:smokeExplosion"); builder.getComponent(LocationComponent.class).setWorldPosition(origin); EntityRef smokeEntity = builder.build(); smokeEntity.send(new PlaySoundEvent(getRandomExplosionSound(), 1f)); Vector3i blockPos = new Vector3i(); for (int i = 0; i < explosionComp.maxRange; i++) { Vector3f direction = random.nextVector3f(1.0f); for (int j = 0; j < 4; j++) { Vector3f target = new Vector3f(origin); target.x += direction.x * j; target.y += direction.y * j; target.z += direction.z * j; blockPos.set((int) target.x, (int) target.y, (int) target.z); Block currentBlock = worldProvider.getBlock(blockPos); /* PHYSICS */ if (currentBlock.isDestructible()) { EntityRef blockEntity = blockEntityRegistry.getEntityAt(blockPos); // allow explosions to chain together, but do not chain on the instigating block if (!blockEntity.equals(instigatingBlockEntity) && blockEntity.hasComponent(ExplosionActionComponent.class)) { doExplosion(blockEntity.getComponent(ExplosionActionComponent.class), blockPos.toVector3f(), blockEntity); } else { blockEntity.send(new DoDamageEvent(explosionComp.damageAmount, explosionComp.damageType)); } } } } }
Vector3f climbDir3f = climbDir3i.toVector3f();
final Vector3f chunkPosition = chunk.getPosition().toVector3f();