Search in sources :

Example 31 with Vector3dc

use of org.joml.Vector3dc in project chunkstories-core by Hugobros3.

the class EntityPlayer method onControllerInput.

@Override
public boolean onControllerInput(Input input, Controller controller) {
    // We are moving inventory bringup here !
    if (input.getName().equals("inventory") && world instanceof WorldClient) {
        if (creativeMode.get()) {
            ((WorldClient) getWorld()).getClient().openInventories(this.inventoryComponent.getInventory(), new InventoryLocalCreativeMenu(world));
        } else {
            ((WorldClient) getWorld()).getClient().openInventories(this.inventoryComponent.getInventory(), this.armor.getInventory());
        }
        return true;
    }
    Location blockLocation = this.getBlockLookingAt(true);
    double maxLen = 1024;
    if (blockLocation != null) {
        Vector3d diff = new Vector3d(blockLocation).sub(this.getLocation());
        // Vector3d dir = diff.clone().normalize();
        maxLen = diff.length();
    }
    Vector3d initialPosition = new Vector3d(getLocation());
    initialPosition.add(new Vector3d(0, eyePosition, 0));
    Vector3dc direction = getDirectionLookingAt();
    Iterator<Entity> i = world.collisionsManager().rayTraceEntities(initialPosition, direction, maxLen);
    while (i.hasNext()) {
        Entity e = i.next();
        if (e.handleInteraction(this, input))
            return true;
    }
    ItemPile itemSelected = getSelectedItemComponent().getSelectedItem();
    if (itemSelected != null) {
        // See if the item handles the interaction
        if (itemSelected.getItem().onControllerInput(this, itemSelected, input, controller))
            return true;
    }
    if (getWorld() instanceof WorldMaster) {
        // Creative mode features building and picking.
        if (this.getCreativeModeComponent().get()) {
            if (input.getName().equals("mouse.left")) {
                if (blockLocation != null) {
                    // Player events mod
                    if (controller instanceof Player) {
                        Player player = (Player) controller;
                        WorldCell cell = world.peekSafely(blockLocation);
                        FutureCell future = new FutureCell(cell);
                        future.setVoxel(this.getDefinition().store().parent().voxels().air());
                        future.setBlocklight(0);
                        future.setSunlight(0);
                        future.setMetaData(0);
                        PlayerVoxelModificationEvent event = new PlayerVoxelModificationEvent(cell, future, EntityCreative.CREATIVE_MODE, player);
                        // Anyone has objections ?
                        world.getGameContext().getPluginManager().fireEvent(event);
                        if (event.isCancelled())
                            return true;
                        Vector3d rnd = new Vector3d();
                        for (int k = 0; k < 40; k++) {
                            rnd.set(blockLocation);
                            rnd.add(Math.random() * 0.98, Math.random() * 0.98, Math.random() * 0.98);
                            world.getParticlesManager().spawnParticleAtPosition("voxel_frag", rnd);
                        }
                        world.getSoundManager().playSoundEffect("sounds/gameplay/voxel_remove.ogg", Mode.NORMAL, blockLocation, 1.0f, 1.0f);
                        try {
                            world.poke(future, this);
                        // world.poke((int)blockLocation.x, (int)blockLocation.y, (int)blockLocation.z, null, 0, 0, 0, this);
                        } catch (WorldException e) {
                        // Discard but maybe play some effect ?
                        }
                        return true;
                    }
                }
            } else if (input.getName().equals("mouse.middle")) {
                if (blockLocation != null) {
                    CellData ctx = this.getWorld().peekSafely(blockLocation);
                    if (!ctx.getVoxel().isAir()) {
                        // Spawn new itemPile in his inventory
                        ItemVoxel item = (ItemVoxel) world.getGameContext().getContent().items().getItemDefinition("item_voxel").newItem();
                        item.voxel = ctx.getVoxel();
                        item.voxelMeta = ctx.getMetaData();
                        ItemPile itemVoxel = new ItemPile(item);
                        this.getInventory().setItemPileAt(getSelectedItemComponent().getSelectedSlot(), 0, itemVoxel);
                        return true;
                    }
                }
            }
        }
    }
    // Then we check if the world minds being interacted with
    return world.handleInteraction(this, blockLocation, input);
}
Also used : Entity(io.xol.chunkstories.api.entity.Entity) Player(io.xol.chunkstories.api.player.Player) LocalPlayer(io.xol.chunkstories.api.client.LocalPlayer) ItemVoxel(io.xol.chunkstories.api.item.ItemVoxel) WorldCell(io.xol.chunkstories.api.world.World.WorldCell) WorldException(io.xol.chunkstories.api.exceptions.world.WorldException) WorldClient(io.xol.chunkstories.api.world.WorldClient) ItemPile(io.xol.chunkstories.api.item.inventory.ItemPile) CellData(io.xol.chunkstories.api.world.cell.CellData) Vector3dc(org.joml.Vector3dc) FutureCell(io.xol.chunkstories.api.world.cell.FutureCell) PlayerVoxelModificationEvent(io.xol.chunkstories.api.events.player.voxel.PlayerVoxelModificationEvent) Vector3d(org.joml.Vector3d) InventoryLocalCreativeMenu(io.xol.chunkstories.core.item.inventory.InventoryLocalCreativeMenu) WorldMaster(io.xol.chunkstories.api.world.WorldMaster) Location(io.xol.chunkstories.api.Location)

Example 32 with Vector3dc

use of org.joml.Vector3dc in project chunkstories-core by Hugobros3.

the class HitBoxImpl method lineIntersection.

/**
 * Tricky maths; transforms the inbound ray so the hitbox would be at 0.0.0 and axis-aligned
 */
public Vector3dc lineIntersection(Vector3dc lineStart, Vector3dc lineDirection) {
    Matrix4f fromAABBToWorld = new Matrix4f(entity.getAnimatedSkeleton().getBoneHierarchyTransformationMatrix(skeletonPart, System.currentTimeMillis() % 1000000));
    Matrix4f worldPositionTransformation = new Matrix4f();
    Location entityLoc = entity.getLocation();
    Vector3f pos = new Vector3f((float) entityLoc.x, (float) entityLoc.y, (float) entityLoc.z);
    worldPositionTransformation.translate(pos);
    // Creates from AABB space to worldspace
    worldPositionTransformation.mul(fromAABBToWorld, fromAABBToWorld);
    // Invert it.
    Matrix4f fromWorldToAABB = new Matrix4f();
    fromAABBToWorld.invert(fromWorldToAABB);
    // Transform line start into AABB space
    Vector4f lineStart4 = new Vector4f((float) lineStart.x(), (float) lineStart.y(), (float) lineStart.z(), 1.0f);
    Vector4f lineDirection4 = new Vector4f((float) lineDirection.x(), (float) lineDirection.y(), (float) lineDirection.z(), 0.0f);
    fromWorldToAABB.transform(lineStart4);
    fromWorldToAABB.transform(lineDirection4);
    Vector3d lineStartTransformed = new Vector3d(lineStart4.x(), lineStart4.y(), lineStart4.z());
    Vector3d lineDirectionTransformed = new Vector3d(lineDirection4.x(), lineDirection4.y(), lineDirection4.z());
    // Actual computation
    Vector3dc hitPoint = box.lineIntersection(lineStartTransformed, lineDirectionTransformed);
    if (hitPoint == null)
        return null;
    // Transform hitPoint back into world
    Vector4f hitPoint4 = new Vector4f((float) hitPoint.x(), (float) hitPoint.y(), (float) hitPoint.z(), 1.0f);
    fromAABBToWorld.transform(hitPoint4);
    return new Vector3d((double) (float) hitPoint4.x(), (double) (float) hitPoint4.y(), (double) (float) hitPoint4.z());
}
Also used : Vector3dc(org.joml.Vector3dc) Matrix4f(org.joml.Matrix4f) Vector4f(org.joml.Vector4f) Vector3d(org.joml.Vector3d) Vector3f(org.joml.Vector3f) Location(io.xol.chunkstories.api.Location)

Example 33 with Vector3dc

use of org.joml.Vector3dc in project chunkstories-core by Hugobros3.

the class EntityGroundItem method tick.

@Override
public void tick() {
    // this.moveWithCollisionRestrain(0, -0.05, 0);
    Vector3d velocity = velocityComponent.getVelocity();
    if (world instanceof WorldMaster) {
        Voxel voxelIn = world.peekSafely(positionComponent.getLocation()).getVoxel();
        boolean inWater = voxelIn.getDefinition().isLiquid();
        double terminalVelocity = inWater ? -0.25 : -0.5;
        if (velocity.y() > terminalVelocity && !this.isOnGround())
            velocity.y = (velocity.y() - 0.016);
        if (velocity.y() < terminalVelocity)
            velocity.y = (terminalVelocity);
        Vector3dc remainingToMove = moveWithCollisionRestrain(velocity.x(), velocity.y(), velocity.z());
        if (remainingToMove.y() < -0.02 && this.isOnGround()) {
            if (remainingToMove.y() < -0.01) {
                // Bounce
                double originalDownardsVelocity = velocity.y();
                double bounceFactor = 0.15;
                velocity.mul(bounceFactor);
                velocity.y = (-originalDownardsVelocity * bounceFactor);
            // world.getSoundManager().playSoundEffect("./sounds/dogez/weapon/grenades/grenade_bounce.ogg", Mode.NORMAL, getLocation(), 1, 1, 10, 35);
            } else
                velocity.mul(0d);
        }
        if (Math.abs(velocity.x()) < 0.02)
            velocity.x = (0.0);
        if (Math.abs(velocity.z()) < 0.02)
            velocity.z = (0.0);
        if (Math.abs(velocity.y()) < 0.01)
            velocity.y = (0.0);
        velocityComponent.setVelocity(velocity);
    }
    if (world instanceof WorldClient) {
        if (this.isOnGround()) {
            rotation += 1.0f;
            rotation %= 360;
        }
    }
    super.tick();
}
Also used : Vector3dc(org.joml.Vector3dc) Vector3d(org.joml.Vector3d) Voxel(io.xol.chunkstories.api.voxel.Voxel) WorldClient(io.xol.chunkstories.api.world.WorldClient) WorldMaster(io.xol.chunkstories.api.world.WorldMaster)

Example 34 with Vector3dc

use of org.joml.Vector3dc in project chunkstories-core by Hugobros3.

the class ShadowPass method render.

public void render(RenderingInterface renderingContext) {
    if (this.getShadowVisibility() == 0f)
        // No shadows at night :)
        return;
    GameWindow gameWindow = pipeline.getRenderingInterface().getWindow();
    // Resize the texture if needed
    int shadowMapTextureSize = renderingContext.getClient().getConfiguration().getIntOption("client.rendering.shadowsResolution");
    if (shadowDepthTexture.getWidth() != shadowMapTextureSize) {
        fbo.resize(shadowMapTextureSize, shadowMapTextureSize);
    }
    // The size of the shadow range depends on the shadowmap resolution
    int shadowRange = 128;
    if (shadowMapTextureSize > 1024)
        shadowRange = 192;
    else if (shadowMapTextureSize > 2048)
        shadowRange = 256;
    int shadowDepthRange = 200;
    // Builds the shadow matrix
    // MatrixHelper.getOrthographicMatrix(-shadowRange, shadowRange, -shadowRange, shadowRange, -shadowDepthRange, shadowDepthRange);
    Matrix4f depthProjectionMatrix = new Matrix4f().ortho(-shadowRange, shadowRange, -shadowRange, shadowRange, -shadowDepthRange, shadowDepthRange);
    Matrix4f depthViewMatrix = new Matrix4f().lookAt(skyRenderer.getSunPosition(), new Vector3f(0, 0, 0), new Vector3f(0, 1, 0));
    Matrix4f shadowMVP = new Matrix4f();
    depthProjectionMatrix.mul(depthViewMatrix, shadowMVP);
    // Matrix4f.mul(depthProjectionMatrix, depthViewMatrix, shadowMVP);
    shadowMatrix = new Matrix4f(shadowMVP);
    Vector3dc posd = renderingContext.getCamera().getCameraPosition();
    Vector3f pos = new Vector3f((float) posd.x(), (float) posd.y(), (float) posd.z());
    pos.negate();
    shadowMVP.translate(pos);
    // Set appropriate fixed function stuff
    renderingContext.setCullingMode(CullingMode.COUNTERCLOCKWISE);
    renderingContext.setBlendMode(BlendMode.DISABLED);
    renderingContext.setDepthTestMode(DepthTestMode.LESS_OR_EQUAL);
    // Bind relevant FBO and clear it
    renderingContext.getRenderTargetManager().setConfiguration(fbo);
    renderingContext.getRenderTargetManager().clearBoundRenderTargetZ(1.0f);
    Shader shadowsPassShader = renderingContext.useShader("shadows");
    shadowsPassShader.setUniform1f("animationTimer", worldRenderer.getAnimationTimer());
    shadowsPassShader.setUniformMatrix4f("depthMVP", shadowMVP);
    shadowsPassShader.setUniform1f("isUsingInstancedData", 0f);
    shadowsPassShader.setUniform1f("useVoxelCoordinates", 1f);
    Texture2D blocksAlbedoTexture = gameWindow.getClient().getContent().voxels().textures().getDiffuseAtlasTexture();
    renderingContext.bindAlbedoTexture(blocksAlbedoTexture);
    renderingContext.setObjectMatrix(null);
    // We render the world from that perspective
    // Hackish way of enabling the shader input for the fake "wind" effect vegetation can have
    shadowsPassShader.setUniform1f("allowForWavyStuff", 1);
    worldRenderer.getChunksRenderer().renderChunks(renderingContext);
    // In turn, disabling it while we do the entities
    shadowsPassShader.setUniform1f("allowForWavyStuff", 0);
    worldRenderer.getEntitiesRenderer().renderEntities(renderingContext);
}
Also used : GameWindow(io.xol.chunkstories.api.rendering.GameWindow) Vector3dc(org.joml.Vector3dc) Matrix4f(org.joml.Matrix4f) Texture2D(io.xol.chunkstories.api.rendering.textures.Texture2D) Vector3f(org.joml.Vector3f) Shader(io.xol.chunkstories.api.rendering.shader.Shader)

Example 35 with Vector3dc

use of org.joml.Vector3dc in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class MixinWorldClient method vs_showBarrierParticles.

private void vs_showBarrierParticles(int x, int y, int z, int offset, Random random, boolean holdingBarrier, BlockPos.MutableBlockPos pos, final List<PhysicsObject> nearbyShipObjects, final Vector3d temp0) {
    final int i = x + random.nextInt(offset) - random.nextInt(offset);
    final int j = y + random.nextInt(offset) - random.nextInt(offset);
    final int k = z + random.nextInt(offset) - random.nextInt(offset);
    pos.setPos(i, j, k);
    vs_displayTickPos(pos, holdingBarrier, random);
    for (final PhysicsObject physicsObject : nearbyShipObjects) {
        if (!aabbContains(physicsObject.getShipBB(), i, j, k)) {
            continue;
        }
        final Vector3dc posInShip = physicsObject.getShipTransformationManager().getRenderTransform().transformPositionNew(temp0.set(i + .5, j + .5, k + .5), TransformType.GLOBAL_TO_SUBSPACE);
        final double randomXOffset = random.nextDouble();
        final double randomYOffset = random.nextDouble();
        final double randomZOffset = random.nextDouble();
        pos.setPos(posInShip.x() + randomXOffset, posInShip.y() + randomYOffset, posInShip.z() + randomZOffset);
        vs_displayTickPos(pos, holdingBarrier, random);
    }
}
Also used : Vector3dc(org.joml.Vector3dc) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject)

Aggregations

Vector3dc (org.joml.Vector3dc)51 Vector3d (org.joml.Vector3d)33 ShipTransform (org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform)15 PhysicsObject (org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject)9 BlockPos (net.minecraft.util.math.BlockPos)8 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)7 Location (io.xol.chunkstories.api.Location)6 IBlockState (net.minecraft.block.state.IBlockState)6 World (net.minecraft.world.World)6 WorldMaster (io.xol.chunkstories.api.world.WorldMaster)5 EntityShipMovementData (org.valkyrienskies.mod.common.entity.EntityShipMovementData)5 Entity (io.xol.chunkstories.api.entity.Entity)4 CollisionBox (io.xol.chunkstories.api.physics.CollisionBox)4 WorldClient (io.xol.chunkstories.api.world.WorldClient)4 CellData (io.xol.chunkstories.api.world.cell.CellData)4 Nullable (javax.annotation.Nullable)4 EntityLiving (io.xol.chunkstories.api.entity.EntityLiving)3 HitBox (io.xol.chunkstories.api.entity.EntityLiving.HitBox)3 Voxel (io.xol.chunkstories.api.voxel.Voxel)3 Block (net.minecraft.block.Block)3