Search in sources :

Example 21 with Vector3d

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

the class EventsClient method onPlaySoundEvent.

@SubscribeEvent
public void onPlaySoundEvent(PlaySoundEvent event) {
    if (Minecraft.getMinecraft().world != null) {
        ISound sound = event.getSound();
        BlockPos pos = new BlockPos(sound.getXPosF(), sound.getYPosF(), sound.getZPosF());
        Optional<PhysicsObject> physicsObject = ValkyrienUtils.getPhysoManagingBlock(Minecraft.getMinecraft().world, pos);
        if (physicsObject.isPresent()) {
            Vector3d newSoundLocation = new Vector3d(sound.getXPosF(), sound.getYPosF(), sound.getZPosF());
            physicsObject.get().getShipTransformationManager().getCurrentTickTransform().transformPosition(newSoundLocation, TransformType.SUBSPACE_TO_GLOBAL);
            SoundFixWrapper soundFix = new SoundFixWrapper(sound, newSoundLocation);
            event.setResultSound(soundFix);
        }
    }
}
Also used : ISound(net.minecraft.client.audio.ISound) Vector3d(org.joml.Vector3d) BlockPos(net.minecraft.util.math.BlockPos) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject) SoundFixWrapper(org.valkyrienskies.mod.fixes.SoundFixWrapper) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 22 with Vector3d

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

the class EventsClient method onRenderTickEvent.

@SubscribeEvent
public void onRenderTickEvent(RenderTickEvent event) {
    final World world = Minecraft.getMinecraft().world;
    if (world == null) {
        // No ships to worry about.
        return;
    }
    double partialTicks = event.renderTickTime;
    if (Minecraft.getMinecraft().isGamePaused()) {
        partialTicks = Minecraft.getMinecraft().renderPartialTicksPaused;
    }
    if (event.phase == Phase.START) {
        lastPositionsMap.clear();
        for (PhysicsObject wrapper : ValkyrienUtils.getPhysosLoadedInWorld(world)) {
            wrapper.getShipTransformationManager().updateRenderTransform(partialTicks);
        }
        // variables so that Minecraft's interpolation code computes the correct value.
        for (final Entity entity : world.getLoadedEntityList()) {
            final EntityShipMovementData entityShipMovementData = ValkyrienUtils.getEntityShipMovementDataFor(entity);
            if (entityShipMovementData.getLastTouchedShip() != null && entityShipMovementData.getTicksSinceTouchedShip() < VSConfig.ticksToStickToShip) {
                final PhysicsObject shipPhysicsObject = ValkyrienUtils.getPhysObjWorld(world).getPhysObjectFromUUID(entityShipMovementData.getLastTouchedShip().getUuid());
                if (shipPhysicsObject == null) {
                    // This ship doesn't exist anymore, just remove it.
                    IDraggable.class.cast(entity).setEntityShipMovementData(entityShipMovementData.withLastTouchedShip(null));
                    continue;
                }
                final ShipTransform prevTickTransform = shipPhysicsObject.getPrevTickShipTransform();
                final ShipTransform shipRenderTransform = shipPhysicsObject.getShipTransformationManager().getRenderTransform();
                final Vector3dc entityAddedVelocity = entityShipMovementData.getAddedLinearVelocity();
                // The velocity the entity was moving without the added velocity from the ship
                final double entityMovementX = entity.posX - entityAddedVelocity.x() - entity.lastTickPosX;
                final double entityMovementY = entity.posY - entityAddedVelocity.y() - entity.lastTickPosY;
                final double entityMovementZ = entity.posZ - entityAddedVelocity.z() - entity.lastTickPosZ;
                // Compute the position the entity should be rendered at this frame
                final Vector3d entityShouldBeHere = new Vector3d(entity.lastTickPosX, entity.lastTickPosY, entity.lastTickPosZ);
                entityShouldBeHere.add(entityMovementX * partialTicks, entityMovementY * partialTicks, entityMovementZ * partialTicks);
                prevTickTransform.transformPosition(entityShouldBeHere, TransformType.GLOBAL_TO_SUBSPACE);
                shipRenderTransform.transformPosition(entityShouldBeHere, TransformType.SUBSPACE_TO_GLOBAL);
                // Save the entity lastTickPos in the map
                lastPositionsMap.put(entity, new Vector3d(entity.lastTickPosX, entity.lastTickPosY, entity.lastTickPosZ));
                // Then update lastTickPos such that Minecraft's interpolation code will render entity at entityShouldBeHere.
                entity.lastTickPosX = (entityShouldBeHere.x() - (entity.posX * partialTicks)) / (1 - partialTicks);
                entity.lastTickPosY = (entityShouldBeHere.y() - (entity.posY * partialTicks)) / (1 - partialTicks);
                entity.lastTickPosZ = (entityShouldBeHere.z() - (entity.posZ * partialTicks)) / (1 - partialTicks);
            }
        }
    // endregion
    } else {
        // Once the rendering code has finished we restore the lastTickPos variables to their old values.
        for (final Entity entity : world.getLoadedEntityList()) {
            if (lastPositionsMap.containsKey(entity)) {
                final Vector3dc entityLastPosition = lastPositionsMap.get(entity);
                entity.lastTickPosX = entityLastPosition.x();
                entity.lastTickPosY = entityLastPosition.y();
                entity.lastTickPosZ = entityLastPosition.z();
            }
        }
    }
}
Also used : EntityShipMovementData(org.valkyrienskies.mod.common.entity.EntityShipMovementData) Vector3dc(org.joml.Vector3dc) Entity(net.minecraft.entity.Entity) ShipTransform(org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform) Vector3d(org.joml.Vector3d) IDraggable(org.valkyrienskies.mod.common.ships.entity_interaction.IDraggable) IPhysObjectWorld(org.valkyrienskies.mod.common.ships.ship_world.IPhysObjectWorld) World(net.minecraft.world.World) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 23 with Vector3d

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

the class PhysObjectRenderManager method applyRenderTransform.

private void applyRenderTransform(double partialTicks, boolean inverse) {
    Vector3dc centerOfRotation = parent.getCenterCoord();
    Entity player = Objects.requireNonNull(Minecraft.getMinecraft().getRenderViewEntity());
    double p0 = player.lastTickPosX + (player.posX - player.lastTickPosX) * partialTicks;
    double p1 = player.lastTickPosY + (player.posY - player.lastTickPosY) * partialTicks;
    double p2 = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * partialTicks;
    ShipTransform renderTransform = parent.getShipTransformationManager().getRenderTransform();
    Vector3d renderPos = renderTransform.getSubspaceToGlobal().transformPosition(centerOfRotation, new Vector3d());
    // Offset pos is used to prevent floating point errors when rendering stuff thats very far away.
    double offsetX = offsetPos.getX() - centerOfRotation.x();
    double offsetY = offsetPos.getY() - centerOfRotation.y();
    double offsetZ = offsetPos.getZ() - centerOfRotation.z();
    if (inverse) {
        AxisAngle4d rotation = new AxisAngle4d().set(renderTransform.getGlobalToSubspace());
        GL11.glTranslated(-offsetX, -offsetY, -offsetZ);
        GL11.glRotated(Math.toDegrees(rotation.angle), rotation.x, rotation.y, rotation.z);
        GL11.glTranslated(p0 - renderPos.x, p1 - renderPos.y, p2 - renderPos.z);
    } else {
        AxisAngle4d rotation = new AxisAngle4d().set(renderTransform.getSubspaceToGlobal());
        GL11.glTranslated(-p0 + renderPos.x, -p1 + renderPos.y, -p2 + renderPos.z);
        GL11.glRotated(Math.toDegrees(rotation.angle), rotation.x, rotation.y, rotation.z);
        GL11.glTranslated(offsetX, offsetY, offsetZ);
    }
}
Also used : Vector3dc(org.joml.Vector3dc) Entity(net.minecraft.entity.Entity) ShipTransform(org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform) Vector3d(org.joml.Vector3d) AxisAngle4d(org.joml.AxisAngle4d)

Example 24 with Vector3d

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

the class EventsCommon method onExplosionStart.

@SubscribeEvent(priority = EventPriority.HIGHEST)
public static void onExplosionStart(ExplosionEvent.Start event) {
    // Only run on server side
    if (!event.getWorld().isRemote) {
        Explosion explosion = event.getExplosion();
        Vector3dc center = new Vector3d(explosion.x, explosion.y, explosion.z);
        Optional<PhysicsObject> optionalPhysicsObject = ValkyrienUtils.getPhysoManagingBlock(event.getWorld(), new BlockPos(event.getExplosion().getPosition()));
        if (optionalPhysicsObject.isPresent()) {
            return;
        }
        // Explosion radius
        float radius = explosion.size;
        AxisAlignedBB toCheck = new AxisAlignedBB(center.x() - radius, center.y() - radius, center.z() - radius, center.x() + radius, center.y() + radius, center.z() + radius);
        // Find nearby ships, we will check if the explosion effects them
        List<PhysicsObject> shipsNear = ((IHasShipManager) event.getWorld()).getManager().getPhysObjectsInAABB(toCheck);
        // Process the explosion on the nearby ships
        for (PhysicsObject ship : shipsNear) {
            Vector3d inLocal = new Vector3d(center);
            inLocal.mulPosition(ship.getShipTransform().getGlobalToSubspace());
            Explosion expl = new Explosion(event.getWorld(), explosion.exploder, inLocal.x, inLocal.y, inLocal.z, radius, explosion.causesFire, explosion.damagesTerrain);
            double waterRange = .6D;
            for (int x = (int) Math.floor(expl.x - waterRange); x <= Math.ceil(expl.x + waterRange); x++) {
                for (int y = (int) Math.floor(expl.y - waterRange); y <= Math.ceil(expl.y + waterRange); y++) {
                    for (int z = (int) Math.floor(expl.z - waterRange); z <= Math.ceil(expl.z + waterRange); z++) {
                        IBlockState state = event.getWorld().getBlockState(new BlockPos(x, y, z));
                        if (state.getBlock() instanceof BlockLiquid) {
                            return;
                        }
                    }
                }
            }
            expl.doExplosionA();
            event.getExplosion().affectedBlockPositions.addAll(expl.affectedBlockPositions);
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Explosion(net.minecraft.world.Explosion) IBlockState(net.minecraft.block.state.IBlockState) Vector3dc(org.joml.Vector3dc) BlockLiquid(net.minecraft.block.BlockLiquid) Vector3d(org.joml.Vector3d) BlockPos(net.minecraft.util.math.BlockPos) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 25 with Vector3d

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

the class BlockCaptainsChair method onBlockActivated.

@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
    if (!worldIn.isRemote) {
        Optional<PhysicsObject> physicsObject = ValkyrienUtils.getPhysoManagingBlock(worldIn, pos);
        if (physicsObject.isPresent()) {
            TileEntity tileEntity = worldIn.getTileEntity(pos);
            if (tileEntity instanceof TileEntityCaptainsChair) {
                Vector3d playerPos = new Vector3d(playerIn.posX, playerIn.posY, playerIn.posZ);
                physicsObject.get().getShipTransformationManager().getCurrentTickTransform().transformPosition(playerPos, TransformType.SUBSPACE_TO_GLOBAL);
                playerIn.posX = playerPos.x;
                playerIn.posY = playerPos.y;
                playerIn.posZ = playerPos.z;
                // Only mount the player if they're standing on the ship.
                final EntityShipMovementData entityShipMovementData = ValkyrienUtils.getEntityShipMovementDataFor(playerIn);
                if (entityShipMovementData.getTicksSinceTouchedShip() == 0 && (entityShipMovementData.getLastTouchedShip() == physicsObject.get().getShipData())) {
                    Vector3dc localMountPos = getPlayerMountOffset(state, pos);
                    ValkyrienUtils.fixEntityToShip(playerIn, localMountPos, physicsObject.get());
                }
                ((TileEntityCaptainsChair) tileEntity).setPilotEntity(playerIn);
                physicsObject.get().getShipTransformationManager().getCurrentTickTransform().transformPosition(playerPos, TransformType.GLOBAL_TO_SUBSPACE);
                playerIn.posX = playerPos.x;
                playerIn.posY = playerPos.y;
                playerIn.posZ = playerPos.z;
            }
        }
    }
    return true;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) EntityShipMovementData(org.valkyrienskies.mod.common.entity.EntityShipMovementData) Vector3dc(org.joml.Vector3dc) Vector3d(org.joml.Vector3d) TileEntityCaptainsChair(org.valkyrienskies.mod.common.tileentity.TileEntityCaptainsChair) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject)

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