Search in sources :

Example 1 with Vector3d

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

the class EntityHumanoid method tick.

@Override
public void tick() {
    eyePosition = stance.get() == EntityHumanoidStance.CROUCHING ? 1.15 : 1.65;
    // Only  if we are allowed to
    boolean tick = false;
    if (this instanceof EntityControllable) {
        Controller controller = ((EntityControllable) this).getControllerComponent().getController();
        if (controller == null)
            tick = (getWorld() instanceof WorldMaster);
        else if (getWorld() instanceof WorldClient && ((WorldClient) getWorld()).getClient().getPlayer().equals(controller))
            tick = true;
    } else
        tick = (getWorld() instanceof WorldMaster);
    if (tick) {
        // The actual moment the jump takes effect
        // voxelIn != null && voxelIn.getType().isLiquid();
        boolean inWater = isInWater();
        if (jumpForce > 0.0 && (!justJumped || inWater)) {
            // Set the velocity
            getVelocityComponent().setVelocityY(jumpForce);
            justJumped = true;
            metersWalked = 0.0;
            jumpForce = 0.0;
        }
        // Set acceleration vector to wanted speed - actual speed
        if (isDead())
            targetVelocity = new Vector3d(0.0);
        acceleration = new Vector3d(targetVelocity.x() - getVelocityComponent().getVelocity().x(), 0, targetVelocity.z() - getVelocityComponent().getVelocity().z());
        // Limit maximal acceleration depending if we're on the groud or not, we accelerate 2x faster on ground
        double maxAcceleration = isOnGround() ? 0.010 : 0.005;
        if (inWater)
            maxAcceleration = 0.005;
        if (acceleration.length() > maxAcceleration) {
            acceleration.normalize();
            acceleration.mul(maxAcceleration);
        }
    }
    // Plays the walking sounds
    handleWalkingEtcSounds();
    // Tick : will move the entity, solve velocity/acceleration and so on
    super.tick();
}
Also used : Vector3d(org.joml.Vector3d) Controller(io.xol.chunkstories.api.entity.Controller) EntityControllable(io.xol.chunkstories.api.entity.interfaces.EntityControllable) WorldClient(io.xol.chunkstories.api.world.WorldClient) WorldMaster(io.xol.chunkstories.api.world.WorldMaster)

Example 2 with Vector3d

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

the class EntityPlayer method drawEntityOverlay.

@Override
public void drawEntityOverlay(RenderingInterface renderer) {
    // super.drawEntityOverlay(renderer);
    if (this.equals(((WorldClient) getWorld()).getClient().getPlayer().getControlledEntity())) {
        float scale = 2.0f;
        renderer.textures().getTexture("./textures/gui/hud/hud_survival.png").setLinearFiltering(false);
        renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(renderer.getWindow().getWidth() / 2 - 256 * 0.5f * scale, 64 + 64 + 16 - 32 * 0.5f * scale, 256 * scale, 32 * scale, 0, 32f / 256f, 1, 0, renderer.textures().getTexture("./textures/gui/hud/hud_survival.png"), false, true, null);
        // Health bar
        int horizontalBitsToDraw = (int) (8 + 118 * Math2.clamp(getHealth() / getMaxHealth(), 0.0, 1.0));
        renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(renderer.getWindow().getWidth() / 2 - 128 * scale, 64 + 64 + 16 - 32 * 0.5f * scale, horizontalBitsToDraw * scale, 32 * scale, 0, 64f / 256f, horizontalBitsToDraw / 256f, 32f / 256f, renderer.textures().getTexture("./textures/gui/hud/hud_survival.png"), false, true, new Vector4f(1.0f, 1.0f, 1.0f, 0.75f));
        // Food bar
        horizontalBitsToDraw = (int) (0 + 126 * Math2.clamp(getFoodLevel() / 100f, 0.0, 1.0));
        renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(renderer.getWindow().getWidth() / 2 + 0 * 128 * scale + 0, 64 + 64 + 16 - 32 * 0.5f * scale, horizontalBitsToDraw * scale, 32 * scale, 0.5f, 64f / 256f, 0.5f + horizontalBitsToDraw / 256f, 32f / 256f, renderer.textures().getTexture("./textures/gui/hud/hud_survival.png"), false, true, new Vector4f(1.0f, 1.0f, 1.0f, 0.75f));
        // If we're using an item that can render an overlay
        if (this.getSelectedItemComponent().getSelectedItem() != null) {
            ItemPile pile = this.getSelectedItemComponent().getSelectedItem();
            if (pile.getItem() instanceof ItemOverlay)
                ((ItemOverlay) pile.getItem()).drawItemOverlay(renderer, pile);
        }
        // We don't want to render our own tag do we ?
        return;
    }
    // Renders the nametag above the player heads
    Vector3d pos = getLocation();
    // don't render tags too far out
    if (pos.distance(renderer.getCamera().getCameraPosition()) > 32f)
        return;
    // Don't render a dead player tag
    if (this.getHealth() <= 0)
        return;
    Vector3fc posOnScreen = renderer.getCamera().transform3DCoordinate(new Vector3f((float) (double) pos.x(), (float) (double) pos.y() + 2.0f, (float) (double) pos.z()));
    float scale = posOnScreen.z();
    // + rotH;
    String txt = name.getName();
    float dekal = renderer.getFontRenderer().defaultFont().getWidth(txt) * 16 * scale;
    // System.out.println("dekal"+dekal);
    if (scale > 0)
        renderer.getFontRenderer().drawStringWithShadow(renderer.getFontRenderer().defaultFont(), posOnScreen.x() - dekal / 2, posOnScreen.y(), txt, 16 * scale, 16 * scale, new Vector4f(1, 1, 1, 1));
}
Also used : Vector3fc(org.joml.Vector3fc) Vector4f(org.joml.Vector4f) Vector3d(org.joml.Vector3d) ItemOverlay(io.xol.chunkstories.api.item.interfaces.ItemOverlay) Vector3f(org.joml.Vector3f) ItemPile(io.xol.chunkstories.api.item.inventory.ItemPile)

Example 3 with Vector3d

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

the class EntityPlayer method setupCamera.

@Override
public void setupCamera(RenderingInterface rd) {
    synchronized (this) {
        lastCameraLocation = getLocation();
        rd.getCamera().setCameraPosition(new Vector3d(positionComponent.getLocation().add(0.0, eyePosition, 0.0)));
        // camera.pos = lastCameraLocation.clone().negate();
        // camera.pos.add(0d, -eyePosition, 0d);
        rd.getCamera().setRotationX(this.getEntityRotationComponent().getVerticalRotation());
        rd.getCamera().setRotationY(this.getEntityRotationComponent().getHorizontalRotation());
        float modifier = 1.0f;
        if (this.getSelectedItemComponent().getSelectedItem() != null && this.getSelectedItemComponent().getSelectedItem().getItem() instanceof ItemZoom) {
            ItemZoom item = (ItemZoom) this.getSelectedItemComponent().getSelectedItem().getItem();
            modifier = 1.0f / item.getZoomFactor();
        }
        rd.getCamera().setFOV(modifier * (float) (rd.getClient().getConfiguration().getDoubleOption("client.video.fov") + ((getVelocityComponent().getVelocity().x() * getVelocityComponent().getVelocity().x() + getVelocityComponent().getVelocity().z() * getVelocityComponent().getVelocity().z()) > 0.07 * 0.07 ? ((getVelocityComponent().getVelocity().x() * getVelocityComponent().getVelocity().x() + getVelocityComponent().getVelocity().z() * getVelocityComponent().getVelocity().z()) - 0.07 * 0.07) * 500 : 0)));
    }
}
Also used : Vector3d(org.joml.Vector3d) ItemZoom(io.xol.chunkstories.api.item.interfaces.ItemZoom)

Example 4 with Vector3d

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

the class ZombieAI method tick.

public void tick() {
    super.tick();
    if (entity.isDead())
        return;
    if (attackEntityCooldown > 0)
        attackEntityCooldown--;
    // Find entities to attack
    if (!(this.currentTask instanceof AiTaskAttackEntity) && entity.stage().aggroRadius > 0.0 && attackEntityCooldown == 0) {
        // Only look for them once in 2s
        attackEntityCooldown = (int) (Math.random() * 60 * 2);
        for (Entity entityToLook : entity.getWorld().getEntitiesInBox(entity.getLocation(), new Vector3d(entity.stage().aggroRadius * 2f))) {
            float visibilityModifier = 1f;
            if (entityToLook instanceof EntityPlayer) {
                EntityPlayer player = (EntityPlayer) entityToLook;
                // Crouched players are 70% less visible
                if (player.stance.get().equals(EntityHumanoidStance.CROUCHING))
                    visibilityModifier -= 0.7f;
                // If the entity is sprinting
                if (player.getVelocityComponent().getVelocity().length() > 0.7)
                    visibilityModifier += 1.0f;
            }
            if (!entityToLook.equals(entity) && entityToLook.getLocation().distance(entity.getLocation()) * visibilityModifier <= entity.stage().aggroRadius && entityToLook instanceof EntityHumanoid && !((EntityHumanoid) entityToLook).isDead()) {
                // Check target is in set
                if (targetsTypes.contains(entityToLook.getClass())) {
                    // Play a borking sound
                    // .setPitch();
                    entity.getWorld().getSoundManager().playSoundEffect("sounds/entities/zombie/grunt.ogg", Mode.NORMAL, entity.getLocation(), (float) (1.5 + Math.random() * 0.2), 1.5f);
                    // .setPitch();
                    entity.getWorld().getSoundManager().playSoundEffect("sounds/entities/zombie/grunt.ogg", Mode.NORMAL, entity.getLocation(), (float) (1.5 + Math.random() * 0.2), 1.5f);
                    // Set new task
                    setAiTask(new AiTaskAttackEntity((EntityHumanoid) entityToLook, 10f, 15f, currentTask, entity.stage().attackCooldown, entity.stage().attackDamage));
                    return;
                }
            }
        }
    }
}
Also used : Entity(io.xol.chunkstories.api.entity.Entity) Vector3d(org.joml.Vector3d) EntityHumanoid(io.xol.chunkstories.core.entity.EntityHumanoid) EntityPlayer(io.xol.chunkstories.core.entity.EntityPlayer)

Example 5 with Vector3d

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

the class ItemFirearm method onControllerInput.

@Override
public boolean onControllerInput(Entity user, ItemPile pile, Input input, Controller controller) {
    // Don't do anything with the left mouse click
    if (input.getName().startsWith("mouse.")) {
        return true;
    }
    if (input.getName().equals("shootGun")) {
        if (user instanceof EntityLiving) {
            EntityLiving shooter = (EntityLiving) user;
            // Serverside checks
            // if (user.getWorld() instanceof WorldMaster)
            {
                // Is the reload cooldown done
                if (cooldownEnd > System.currentTimeMillis())
                    return false;
                // Do we have any bullets to shoot
                boolean bulletPresence = (user instanceof EntityCreative && ((EntityCreative) user).isCreativeMode()) || checkBullet(pile);
                if (!bulletPresence) {
                    // Dry.ogg
                    return true;
                } else if (!(user instanceof EntityCreative && ((EntityCreative) user).isCreativeMode())) {
                    consumeBullet(pile);
                }
            }
            // Jerk client view a bit
            if (shooter.getWorld() instanceof WorldClient) {
                EntityComponentRotation rot = ((EntityLiving) user).getEntityRotationComponent();
                rot.applyInpulse(shake * (Math.random() - 0.5) * 3.0, shake * -(Math.random() - 0.25) * 5.0);
            }
            // Play sounds
            if (controller != null) {
                controller.getSoundManager().playSoundEffect(this.soundName, Mode.NORMAL, user.getLocation(), 1.0f, 1.0f, 1.0f, (float) soundRange);
            }
            playAnimation();
            // Raytrace shot
            Vector3d eyeLocation = new Vector3d(shooter.getLocation());
            if (shooter instanceof EntityPlayer)
                eyeLocation.add(new Vector3d(0.0, ((EntityPlayer) shooter).eyePosition, 0.0));
            // For each shot
            for (int ss = 0; ss < shots; ss++) {
                Vector3d direction = new Vector3d(shooter.getDirectionLookingAt());
                direction.add(new Vector3d(Math.random() - 0.5, Math.random() - 0.5, Math.random() - 0.5).normalize().mul(accuracy / 100d));
                direction.normalize();
                // Find wall collision
                Location shotBlock = user.getWorld().collisionsManager().raytraceSolid(eyeLocation, direction, range);
                Vector3dc nearestLocation = null;
                // Loops to try and break blocks
                boolean brokeLastBlock = false;
                while (user.getWorld() instanceof WorldMaster && shotBlock != null) {
                    WorldCell peek = user.getWorld().peekSafely(shotBlock);
                    // int data = peek.getData();
                    Voxel voxel = peek.getVoxel();
                    brokeLastBlock = false;
                    if (!voxel.isAir() && voxel.getMaterial().resolveProperty("bulletBreakable") != null && voxel.getMaterial().resolveProperty("bulletBreakable").equals("true")) {
                        // TODO Spawn an event to check if it's okay
                        // Destroy it
                        peek.setVoxel(voxel.store().air());
                        brokeLastBlock = true;
                        for (int i = 0; i < 25; i++) {
                            Vector3d smashedVoxelParticleDirection = new Vector3d(direction);
                            smashedVoxelParticleDirection.mul(2.0);
                            smashedVoxelParticleDirection.add(Math.random() - 0.5, Math.random() - 0.5, Math.random() - 0.5);
                            smashedVoxelParticleDirection.normalize();
                            user.getWorld().getParticlesManager().spawnParticleAtPositionWithVelocity("voxel_frag", shotBlock, smashedVoxelParticleDirection);
                        }
                        user.getWorld().getSoundManager().playSoundEffect("sounds/environment/glass.ogg", Mode.NORMAL, shotBlock, (float) Math.random() * 0.2f + 0.9f, 1.0f);
                        // Re-raytrace the ray
                        shotBlock = user.getWorld().collisionsManager().raytraceSolid(eyeLocation, direction, range);
                    } else
                        break;
                }
                // Spawn decal and particles on block the bullet embedded itself in
                if (shotBlock != null && !brokeLastBlock) {
                    Location shotBlockOuter = user.getWorld().collisionsManager().raytraceSolidOuter(eyeLocation, direction, range);
                    if (shotBlockOuter != null) {
                        Vector3d normal = shotBlockOuter.sub(shotBlock);
                        double NbyI2x = 2.0 * direction.dot(normal);
                        Vector3d NxNbyI2x = new Vector3d(normal);
                        NxNbyI2x.mul(NbyI2x);
                        Vector3d reflected = new Vector3d(direction);
                        reflected.sub(NxNbyI2x);
                        // Vector3d.sub(direction, NxNbyI2x, reflected);
                        // shotBlock.setX(shotBlock.getX() + 1);
                        WorldCell peek = user.getWorld().peekSafely(shotBlock);
                        for (CollisionBox box : peek.getTranslatedCollisionBoxes()) {
                            Vector3dc thisLocation = box.lineIntersection(eyeLocation, direction);
                            if (thisLocation != null) {
                                if (nearestLocation == null || nearestLocation.distance(eyeLocation) > thisLocation.distance(eyeLocation))
                                    nearestLocation = thisLocation;
                            }
                        }
                        Vector3d particleSpawnPosition = new Vector3d(nearestLocation);
                        // Position adjustements so shot blocks always shoot proper particles
                        if (shotBlock.x() - particleSpawnPosition.x() <= -1.0)
                            particleSpawnPosition.add(-0.01, 0d, 0d);
                        if (shotBlock.y() - particleSpawnPosition.y() <= -1.0)
                            particleSpawnPosition.add(0d, -0.01, 0d);
                        if (shotBlock.z() - particleSpawnPosition.z() <= -1.0)
                            particleSpawnPosition.add(0d, 0d, -0.01);
                        for (int i = 0; i < 25; i++) {
                            Vector3d untouchedReflection = new Vector3d(reflected);
                            Vector3d random = new Vector3d(Math.random() * 2.0 - 1.0, Math.random() * 2.0 - 1.0, Math.random() * 2.0 - 1.0);
                            random.mul(0.5);
                            untouchedReflection.add(random);
                            untouchedReflection.normalize();
                            untouchedReflection.mul(0.25);
                            // Vector3d ppos = new Vector3d(particleSpawnPosition);
                            controller.getParticlesManager().spawnParticleAtPositionWithVelocity("voxel_frag", particleSpawnPosition, untouchedReflection);
                        }
                        controller.getSoundManager().playSoundEffect(peek.getVoxel().getMaterial().resolveProperty("landingSounds"), Mode.NORMAL, particleSpawnPosition, 1, 0.05f);
                        /*double bspeed = 5/60.0 * (1 + Math.random() * 3 * Math.random());
							Vector3d ppos = new Vector3d(reflected);
							ppos.normalize();
							ppos.scale(0.5);
							ppos.add(nearestLocation);
							WorldEffects.createFireball(shooter.getWorld(), ppos, 1f, damage*0.15*bspeed, (float) (0.0 + 0.05*damage));
							*/
                        controller.getDecalsManager().drawDecal(nearestLocation, normal.negate(), new Vector3d(0.5), "bullethole");
                    }
                }
                // Hitreg takes place on server bois
                if (shooter.getWorld() instanceof WorldMaster) {
                    // Iterate over each found entities
                    Iterator<Entity> shotEntities = user.getWorld().collisionsManager().rayTraceEntities(eyeLocation, direction, 256f);
                    while (shotEntities.hasNext()) {
                        Entity shotEntity = shotEntities.next();
                        // Don't shoot itself & only living things get shot
                        if (!shotEntity.equals(shooter) && shotEntity instanceof EntityLiving) {
                            // Get hit location
                            for (HitBox hitBox : ((EntityLiving) shotEntity).getHitBoxes()) {
                                Vector3dc hitPoint = hitBox.lineIntersection(eyeLocation, direction);
                                if (hitPoint == null)
                                    continue;
                                // System.out.println("shot" + hitBox.getName());
                                // Deal damage
                                ((EntityLiving) shotEntity).damage(pileAsDamageCause(pile), hitBox, (float) damage);
                                // Spawn blood particles
                                Vector3d bloodDir = direction.normalize().mul(0.75);
                                for (int i = 0; i < 120; i++) {
                                    Vector3d random = new Vector3d(Math.random() * 2.0 - 1.0, Math.random() * 2.0 - 1.0, Math.random() * 2.0 - 1.0);
                                    random.mul(0.25);
                                    random.add(bloodDir);
                                    shooter.getWorld().getParticlesManager().spawnParticleAtPositionWithVelocity("blood", hitPoint, random);
                                }
                                // Spawn blood on walls
                                if (nearestLocation != null)
                                    shooter.getWorld().getDecalsManager().drawDecal(nearestLocation, bloodDir, new Vector3d(Math.min(3, shots) * damage / 20f), "blood");
                            }
                        }
                    }
                }
            }
            controller.getParticlesManager().spawnParticleAtPosition("muzzle", eyeLocation);
            FirearmShotEvent event = new FirearmShotEvent(this, shooter, controller);
            shooter.getWorld().getGameContext().getPluginManager().fireEvent(event);
            return (shooter.getWorld() instanceof WorldMaster);
        }
    }
    return false;
}
Also used : EntityComponentRotation(io.xol.chunkstories.api.entity.components.EntityComponentRotation) Entity(io.xol.chunkstories.api.entity.Entity) HitBox(io.xol.chunkstories.api.entity.EntityLiving.HitBox) WorldCell(io.xol.chunkstories.api.world.World.WorldCell) EntityLiving(io.xol.chunkstories.api.entity.EntityLiving) EntityCreative(io.xol.chunkstories.api.entity.interfaces.EntityCreative) WorldClient(io.xol.chunkstories.api.world.WorldClient) Vector3dc(org.joml.Vector3dc) Vector3d(org.joml.Vector3d) Voxel(io.xol.chunkstories.api.voxel.Voxel) EntityPlayer(io.xol.chunkstories.core.entity.EntityPlayer) WorldMaster(io.xol.chunkstories.api.world.WorldMaster) Location(io.xol.chunkstories.api.Location) CollisionBox(io.xol.chunkstories.api.physics.CollisionBox)

Aggregations

Vector3d (org.joml.Vector3d)117 Vector3dc (org.joml.Vector3dc)33 PhysicsObject (org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject)20 BlockPos (net.minecraft.util.math.BlockPos)19 ShipTransform (org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform)18 Location (io.xol.chunkstories.api.Location)12 Entity (io.xol.chunkstories.api.entity.Entity)11 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)9 World (net.minecraft.world.World)9 ShipData (org.valkyrienskies.mod.common.ships.ShipData)9 WorldClient (io.xol.chunkstories.api.world.WorldClient)8 WorldMaster (io.xol.chunkstories.api.world.WorldMaster)8 EntityPlayer (net.minecraft.entity.player.EntityPlayer)8 EntityShipMovementData (org.valkyrienskies.mod.common.entity.EntityShipMovementData)7 EntityControllable (io.xol.chunkstories.api.entity.interfaces.EntityControllable)6 IBlockState (net.minecraft.block.state.IBlockState)6 Vec3d (net.minecraft.util.math.Vec3d)6 Vector3f (org.joml.Vector3f)6 EntityLiving (io.xol.chunkstories.api.entity.EntityLiving)5 CellData (io.xol.chunkstories.api.world.cell.CellData)5